Commit 53977e2a by Tuukka Kivilahti

autoproduct for bill

1 parent a392afcb
......@@ -263,6 +263,25 @@ public class BillBean implements BillBeanLocal {
loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to create bill for user: ", bill.getUser());
throw new EJBAccessException("Could not create bill for another user");
}
// if there is autoproducts, check that they exists in bill
for(Product product : productBean.listUserShoppableProducts()) {
if(product.isUsershopAutoproduct()) {
boolean containsAutoproduct = false;
for(BillLine line : bill.getBillLines()) {
if(line.getLineProduct().equals(product) && line.getQuantity().compareTo(BigDecimal.ONE) >= 0) {
containsAutoproduct = true;
}
}
if(!containsAutoproduct) {
BillLine line = new BillLine(bill, product, BigDecimal.ONE);
bill.getBillLines().add(line);
}
}
}
billFacade.create(bill);
generateBillNumber(bill);
createPlaceslots(bill);
......
......@@ -360,4 +360,9 @@ public class Product extends GenericEntity {
this.licenseTargets = licenseTargets;
}
public boolean isUsershopAutoproduct() {
return getProductFlags().contains(ProductFlag.USERSHOP_AUTOPRODUCT);
}
}
......@@ -54,7 +54,13 @@ public enum ProductFlag {
/**
* Käyttäjän itse kaupasta ostettavissa oleva tuote.
*/
USER_SHOPPABLE;
USER_SHOPPABLE,
/**
* Tuote joka lisätään jokaisen käyttäjäkaupasta tehtyyn tilaukseen automaattisesti
*/
USERSHOP_AUTOPRODUCT
;
private static final String KEY_PREFIX = "productFlag.";
private final String key;
......@@ -65,7 +71,6 @@ public enum ProductFlag {
public String getI18nkey()
{
return key;
}
......
......@@ -23,8 +23,7 @@
<!-- <h:outputScript target="head" library="script" name="shopscript.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">
<p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" id="billcart" value="#{cc.attrs.items}" var="cart">
<p:column>
<f:facet name="header">
<h:outputText id="name" value="${i18n['shop.product.name']}" />
......@@ -45,20 +44,26 @@
<h:outputText id="count" value="${i18n['product.cart.count']}" />
</f:facet>
<h:commandButton action="#{productShopView.addMinusOne}"
value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" />
</h:commandButton>
<p:inputText size="2" id="cartcount" escape="false"
value="#{cart.count}">
<f:ajax render="@form"
listener="#{productShopView.countChangeListener}" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</p:inputText>
<h:commandButton action="#{productShopView.addOne}"
value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" />
</h:commandButton>
<p:outputPanel rendered="#{cart.product.usershopAutoproduct}">
<h:outputText value="#{cart.count}" />
</p:outputPanel>
<p:outputPanel rendered="#{!cart.product.usershopAutoproduct}">
<h:commandButton action="#{productShopView.addMinusOne}"
value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" />
</h:commandButton>
<p:inputText size="2" id="cartcount" escape="false"
value="#{cart.count}">
<f:ajax render="@form"
listener="#{productShopView.countChangeListener}" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</p:inputText>
<h:commandButton action="#{productShopView.addOne}"
value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" />
</h:commandButton>
</p:outputPanel>
</p:column>
<p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header">
......@@ -84,7 +89,7 @@
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="${i18n['product.totalPrice']}" />
<h:outputText value="#{i18n['product.totalPrice']}" />
</f:facet>
<h:outputText id="total" value="#{cart.price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" currencyCode="EUR" type="currency" locale="#{sessionHandler.locale}" />
......
......@@ -120,9 +120,13 @@ public class ProductShopView extends GenericCDIView {
}
public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
&& shoppingcart == null) {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts(), userView.getSelectedUser()));
for(ProductShopItem item : shoppingcart) {
psiHelper.updateProductShopItemCount(item);
}
updateCartLimits(null);
logger.debug("Initialized billing shoppingcart to {}", shoppingcart);
this.beginConversation();
......
......@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.web.helper.ProductShopItemHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -92,10 +94,23 @@ public class ProductShopItem {
return ret;
}
/**
* NOTE: Remember to update count with ProductShopItemHelper afther calling this function
* (this logic really need's to be rewritten)
*
* @param products
* @param user
* @return
*/
public static List<ProductShopItem> productList(List<Product> products, EventUser user) {
List<ProductShopItem> ret = new ArrayList<>();
for (Product prod : products) {
ret.add(new ProductShopItem(prod, user));
ProductShopItem i = new ProductShopItem(prod, user);
if(prod.getProductFlags().contains(ProductFlag.USERSHOP_AUTOPRODUCT)) {
i.setCount(BigDecimal.ONE);
}
ret.add(i);
}
return ret;
......
......@@ -468,3 +468,6 @@ usercart.showoverview = Vie tarkastusn\u00E4kym\u00E4\u00E4n
viewlectures.title = Kurssit ja luennot
yes = Kyll\u00E4
productFlag.USERSHOP_AUTOPRODUCT=Tuote lis\u00E4t\u00E4\u00E4n k\u00E4ytt\u00E4j\u00E4n tilaukseen
acc_line.eventuser=
mapView.productcount.productcount=
......@@ -1674,3 +1674,4 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start
yes = Yes
productFlag.USERSHOP_AUTOPRODUCT=Product will be added to user order
......@@ -1656,3 +1656,4 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni
voting.create.voteStart = \u00C4\u00E4nestys auki
yes = Kyll\u00E4
productFlag.USERSHOP_AUTOPRODUCT=Tuote lis\u00E4t\u00E4\u00E4n k\u00E4ytt\u00E4j\u00E4n tilaukseen
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!