Commit 8d71ba5f by Tuukka Kivilahti

Merge branch 'dependant-products' into 'master'

Add product dependecy possibility

This allows products do depend on other products, ie you must buy
computerplace to buy vip lounge entrances

See merge request !364
2 parents b70320be 9c07bb3c
...@@ -93,4 +93,6 @@ public interface ProductBeanLocal { ...@@ -93,4 +93,6 @@ public interface ProductBeanLocal {
void deleteProductOptionGroup(ProductOptionGroup group); void deleteProductOptionGroup(ProductOptionGroup group);
Product reload(Product product); Product reload(Product product);
Product delete(ProductDependency dep);
} }
...@@ -425,6 +425,7 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -425,6 +425,7 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE discounts ADD COLUMN sort INTEGER NOT NULL default 10;" "ALTER TABLE discounts ADD COLUMN sort INTEGER NOT NULL default 10;"
}); });
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"CREATE TABLE map_queue_rules (id SERIAL NOT NULL, meta json, reserving_size INTEGER, default_timeout_min INTEGER, minium_slots_in_queue INTEGER, map_id INTEGER NOT NULL , PRIMARY KEY (id))", "CREATE TABLE map_queue_rules (id SERIAL NOT NULL, meta json, reserving_size INTEGER, default_timeout_min INTEGER, minium_slots_in_queue INTEGER, map_id INTEGER NOT NULL , PRIMARY KEY (id))",
"ALTER TABLE map_queue_rules ADD CONSTRAINT FK_map_queue_rules_map_id FOREIGN KEY (map_id) REFERENCES maps (id)", "ALTER TABLE map_queue_rules ADD CONSTRAINT FK_map_queue_rules_map_id FOREIGN KEY (map_id) REFERENCES maps (id)",
...@@ -434,8 +435,11 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -434,8 +435,11 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE map_queue_rules ADD COLUMN biggest_first BOOLEAN default false", "ALTER TABLE map_queue_rules ADD COLUMN biggest_first BOOLEAN default false",
}); });
dbUpdates.add(new String[]{
"CREATE TABLE product_dependencies (id SERIAL NOT NULL, dependency_type TEXT NOT NULL, meta json, multiplier DECIMAL(24,6) NOT NULL, priority INTEGER NOT NULL, dependant_id INTEGER NOT NULL, supporter_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE product_dependencies ADD CONSTRAINT FK_product_dependencies_dependant_id FOREIGN KEY (dependant_id) REFERENCES products (id)",
"ALTER TABLE product_dependencies ADD CONSTRAINT FK_product_dependencies_supporter_id FOREIGN KEY (supporter_id) REFERENCES products (id)",
});
} }
......
...@@ -660,5 +660,12 @@ public class ProductBean implements ProductBeanLocal { ...@@ -660,5 +660,12 @@ public class ProductBean implements ProductBeanLocal {
return productFacade.reload(product); return productFacade.reload(product);
} }
@Override
public Product delete(ProductDependency dep) {
Product prod = productFacade.reload(dep.getDependant());
prod.getProductDependencies().remove(dep);
return prod;
}
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -151,6 +152,10 @@ public class Product extends GenericEntity { ...@@ -151,6 +152,10 @@ public class Product extends GenericEntity {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product") @OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
private List<ProductOptionGroup> productOptionGroups; private List<ProductOptionGroup> productOptionGroups;
@OneToMany(cascade = CascadeType.ALL, mappedBy ="dependant")
@PrivateOwned
@OrderBy("priority")
private List<ProductDependency> productDependencies = new ArrayList<>();
public Product() { public Product() {
super(); super();
...@@ -436,4 +441,12 @@ public class Product extends GenericEntity { ...@@ -436,4 +441,12 @@ public class Product extends GenericEntity {
public void setMinBuyCount(int minBuyCount) { public void setMinBuyCount(int minBuyCount) {
this.minBuyCount = minBuyCount; this.minBuyCount = minBuyCount;
} }
public List<ProductDependency> getProductDependencies() {
return productDependencies;
}
public void setProductDependencies(List<ProductDependency> productDependencies) {
this.productDependencies = productDependencies;
}
} }
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
@Entity
@Table(name = "product_dependencies")
public class ProductDependency extends GenericEntity {
public static final String DEPENDANT_COLUMN = "dependant_id" ;
private static final BigDecimal SCALE6_ONE = BigDecimal.ONE.setScale(6, RoundingMode.HALF_UP);
public static enum DependencyType {
// Dependant product can be bought maximum of supported product number of times
MAX_SUPPORTED_COUNT,
;
public String getI18nKey() {
return "product.dependency." + name();
}
}
@Enumerated(EnumType.STRING)
@Column(nullable = false, name="dependency_type")
private DependencyType dependencyType;
// Order, in which dependencies will be parsed
@Column(nullable = false, name="priority")
private int priority = 1000;
@Column(name = "multiplier", nullable = false, precision = 24, scale = 6)
private BigDecimal multiplier = SCALE6_ONE;
@ManyToOne
@JoinColumn(nullable = false, name=DEPENDANT_COLUMN)
private Product dependant;
// product which is required when purhchasing the dependant product
@ManyToOne
@JoinColumn(nullable = false, name="supporter_id")
private Product supporter;
public DependencyType getDependencyType() {
return dependencyType;
}
public void setDependencyType(DependencyType dependencyType) {
this.dependencyType = dependencyType;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public Product getDependant() {
return dependant;
}
public void setDependant(Product dependant) {
this.dependant = dependant;
}
public Product getSupporter() {
return supporter;
}
public void setSupporter(Product supporter) {
this.supporter = supporter;
}
public BigDecimal getMultiplier() {
return multiplier;
}
public void setMultiplier(BigDecimal multiplier) {
this.multiplier = multiplier;
}
}
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<!-- <h:outputScript target="head" library="script" name="shopscript.js" /> --> <!-- <h:outputScript target="head" library="script" name="shopscript.js" /> -->
<h:outputScript library="primefaces" name="jquery/jquery.js" /> <h:outputScript library="primefaces" name="jquery/jquery.js" />
<p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" id="billcart" value="#{cc.attrs.items}" var="cart" expandedRow="true"> <p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" id="billcart" value="#{cc.attrs.items}" var="cart" expandedRow="#{cart.count > 0}">
<p:column style="width:16px"> <p:column style="width:16px">
<p:rowToggler rendered="#{cart.product.containsProductOptionGroups}" /> <p:rowToggler rendered="#{cart.product.containsProductOptionGroups}" />
</p:column> </p:column>
......
...@@ -274,6 +274,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -274,6 +274,7 @@ public class ProductShopView extends GenericCDIView {
} }
} }
// Update all other items
for (ProductShopItem n : shoppingcart) { for (ProductShopItem n : shoppingcart) {
BigDecimal l = limits.get(n.getProduct().getId()); BigDecimal l = limits.get(n.getProduct().getId());
if (l != null) { if (l != null) {
...@@ -283,6 +284,11 @@ public class ProductShopView extends GenericCDIView { ...@@ -283,6 +284,11 @@ public class ProductShopView extends GenericCDIView {
psiHelper.updateProductShopItemLimit(n, l); psiHelper.updateProductShopItemLimit(n, l);
} }
//Update product dependencies last...
for (ProductShopItem n : shoppingcart) {
n.updateProductDependencies(shoppingcart);
}
} }
public String removeBought() { public String removeBought() {
......
...@@ -61,9 +61,11 @@ public class ProductView extends GenericCDIView { ...@@ -61,9 +61,11 @@ public class ProductView extends GenericCDIView {
private ListDataModel<ProductLimitation> productLimits; private ListDataModel<ProductLimitation> productLimits;
private ListDataModel<ProductOptionGroup> productOptionGroups; private ListDataModel<ProductOptionGroup> productOptionGroups;
private ListDataModel<ProductDependency> productDependencies;
private ProductOption productOption = null; private ProductOption productOption = null;
private ProductDependency dependency = new ProductDependency();
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ProductView.class); private static final Logger logger = LoggerFactory.getLogger(ProductView.class);
...@@ -76,6 +78,29 @@ public class ProductView extends GenericCDIView { ...@@ -76,6 +78,29 @@ public class ProductView extends GenericCDIView {
} }
} }
public List<Product> getProducts(){
return prodbean.getProducts();
}
public void createProductDependency(){
product.getProductDependencies().add(dependency);
dependency.setDependant(product);
dependency = new ProductDependency();
product = prodbean.mergeChanges(product);
productDependencies = null;
}
public void deleteProductDependency(){
ProductDependency dep = getProductDependencies().getRowData();
product = prodbean.delete(dep);
productDependencies = null;
}
public ProductDependency.DependencyType[] getDependencyTypes(){
return ProductDependency.DependencyType.values();
}
public void initCreateView() { public void initCreateView() {
if (super.requirePermissions(ShopPermission.MANAGE_PRODUCTS)) { if (super.requirePermissions(ShopPermission.MANAGE_PRODUCTS)) {
setProduct(new Product(eventbean.getCurrentEvent())); setProduct(new Product(eventbean.getCurrentEvent()));
...@@ -270,4 +295,19 @@ public class ProductView extends GenericCDIView { ...@@ -270,4 +295,19 @@ public class ProductView extends GenericCDIView {
if(option != null) if(option != null)
productOptionGroup.setDefaultOption(option); productOptionGroup.setDefaultOption(option);
} }
public ProductDependency getDependency() {
return dependency;
}
public void setDependency(ProductDependency dependency) {
this.dependency = dependency;
}
public ListDataModel<ProductDependency> getProductDependencies(){
if(productDependencies == null && product != null){
productDependencies = new ListDataModel<>(product.getProductDependencies());
}
return productDependencies;
}
} }
...@@ -315,4 +315,23 @@ public class ProductShopItem { ...@@ -315,4 +315,23 @@ public class ProductShopItem {
} }
public void updateProductDependencies(ListDataModel<ProductShopItem> shoppingcart) {
if (product.getProductDependencies() == null || product.getProductDependencies().isEmpty()) {
return;
}
BigDecimal limitCnt = BigDecimal.ZERO;
for (ProductDependency dep : product.getProductDependencies()) {
for (ProductShopItem item : shoppingcart) {
if (dep.getSupporter().equals(item.getProduct())) {
limitCnt = limitCnt.add(item.getCount());
break;
}
}
}
if (limitCnt.compareTo(count) < 0) {
this.count = limitCnt;
}
setLimit(limitCnt);
}
} }
...@@ -1589,3 +1589,11 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time ...@@ -1589,3 +1589,11 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time
mapView.reserveTimeLeft=Time to reserve places mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page) queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
product.dependency.add=Add product dependency
product.dependency.create=Create
product.dependency.supporter=Depended product
product.dependency.type=Dependency type
product.dependency.priority=Priority
productDependency.delete=Delete
product.dependency.multiplier=Multiplier
product.dependency.MAX_SUPPORTED_COUNT=Only up to same number of products can be bought
...@@ -1867,3 +1867,11 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time ...@@ -1867,3 +1867,11 @@ reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has time
mapView.reserveTimeLeft=Time to reserve places mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page) queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
product.dependency.add=Add product dependency
product.dependency.create=Create
product.dependency.supporter=Depended product
product.dependency.type=Dependency type
product.dependency.priority=Priority
productDependency.delete=Delete
product.dependency.multiplier=Multiplier
product.dependency.MAX_SUPPORTED_COUNT=Only up to same number of products can be bought
...@@ -1854,3 +1854,11 @@ reservequeue.reservingTimeIsUpAlert=Sinulle varattu varausauka on kulunut loppuu ...@@ -1854,3 +1854,11 @@ reservequeue.reservingTimeIsUpAlert=Sinulle varattu varausauka on kulunut loppuu
mapView.reserveTimeLeft=Aikaa varata paikkasi mapView.reserveTimeLeft=Aikaa varata paikkasi
queuemgmt.queueEnabled=Varausjono ON k\u00E4yt\u00F6ss\u00E4 queuemgmt.queueEnabled=Varausjono ON k\u00E4yt\u00F6ss\u00E4
queuemgmt.queueDisabled=K\u00E4ytt\u00E4j\u00E4jono EI OLE k\u00E4yt\u00F6ss\u00E4 (ota k\u00E4yttoon tapahtuman tiedot -sivulta) queuemgmt.queueDisabled=K\u00E4ytt\u00E4j\u00E4jono EI OLE k\u00E4yt\u00F6ss\u00E4 (ota k\u00E4yttoon tapahtuman tiedot -sivulta)
product.dependency.add=Lis\u00E4\u00E4 tuoteriippuvuus
product.dependency.create=Luo uusi
product.dependency.supporter=Tuote josta on riippuvuus
product.dependency.type=Riippuvuuden tyyppi
product.dependency.priority=Prioriteetti
productDependency.delete=Poista
product.dependency.multiplier=Kerroin
product.dependency.MAX_SUPPORTED_COUNT=Tuotteita voi ostaa enint\u00E4\u00E4n saman m\u00E4\u00E4r\u00E4n
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!