lol, dunno what

1 parent d6e5b3f7
...@@ -336,6 +336,10 @@ public class Bill extends GenericEntity { ...@@ -336,6 +336,10 @@ public class Bill extends GenericEntity {
} }
public void addProduct(Product product, BigDecimal count) { public void addProduct(Product product, BigDecimal count) {
this.addProduct(product, count, null);
}
public void addProduct(Product product, BigDecimal count, FoodWave foodwave) {
// If bill number > 0 bill has been sent and extra privileges are needed // If bill number > 0 bill has been sent and extra privileges are needed
// to modify. // to modify.
// if (!iscurrent || billnr != null) { // if (!iscurrent || billnr != null) {
...@@ -346,7 +350,7 @@ public class Bill extends GenericEntity { ...@@ -346,7 +350,7 @@ public class Bill extends GenericEntity {
if (this.billLines == null) { if (this.billLines == null) {
billLines = new ArrayList<BillLine>(); billLines = new ArrayList<BillLine>();
} }
this.getBillLines().add(new BillLine(this, product, count)); this.getBillLines().add(new BillLine(this, product, count, foodwave));
for (Discount disc : product.getActiveDiscounts(count, sentDate)) { for (Discount disc : product.getActiveDiscounts(count, sentDate)) {
......
...@@ -102,7 +102,12 @@ public class BillLine extends GenericEntity { ...@@ -102,7 +102,12 @@ public class BillLine extends GenericEntity {
super(); super();
} }
public BillLine(Bill bill2, Product product, BigDecimal count) { public BillLine(Bill bill2, Product product, BigDecimal count) {
this(bill2, product, count, null);
}
public BillLine(Bill bill2, Product product, BigDecimal count, FoodWave foodwave) {
super(); super();
this.bill = bill2; this.bill = bill2;
this.lineProduct = product; this.lineProduct = product;
...@@ -111,8 +116,20 @@ public class BillLine extends GenericEntity { ...@@ -111,8 +116,20 @@ public class BillLine extends GenericEntity {
this.setQuantity(count); this.setQuantity(count);
this.setUnitPrice(product.getPrice().abs()); this.setUnitPrice(product.getPrice().abs());
this.setVat(product.getVat()); this.setVat(product.getVat());
this.setFoodwave(foodwave);
} }
/**
* Discounttia luotaessa lasketaan productin hinnasta jokin kiva miinuspuolinen rivi discountin mukaan?
*
* Kommentteja plz!
*
* @param bill2
* @param product
* @param disc
* @param count
*/
public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) { public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) {
super(); super();
this.bill = bill2; this.bill = bill2;
......
...@@ -85,7 +85,13 @@ ...@@ -85,7 +85,13 @@
</h:dataTable> </h:dataTable>
<h:commandButton action="#{foodWaveFoodView.buyFromCounter}" value="#{i18n['foodshop.buyFromCounter']}" /> <h:commandButton action="#{foodWaveFoodView.buyFromCounter}" value="#{i18n['foodshop.buyFromCounter']}" >
</h:commandButton>
<h:commandButton action="#{foodWaveFoodView.buyFromInternet}" value="#{i18n['foodshop.buyFromInternet']}" >
</h:commandButton>
</h:form> </h:form>
......
...@@ -10,10 +10,12 @@ import javax.inject.Inject; ...@@ -10,10 +10,12 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import fi.insomnia.bortal.beans.AccountEventBeanLocal; import fi.insomnia.bortal.beans.AccountEventBeanLocal;
import fi.insomnia.bortal.beans.BillBeanLocal;
import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.beans.FoodWaveBeanLocal; import fi.insomnia.bortal.beans.FoodWaveBeanLocal;
import fi.insomnia.bortal.beans.ProductBeanLocal; import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.enums.apps.ShopPermission; import fi.insomnia.bortal.enums.apps.ShopPermission;
import fi.insomnia.bortal.model.AccountEvent; import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.EventUser; import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.FoodWave; import fi.insomnia.bortal.model.FoodWave;
import fi.insomnia.bortal.model.Product; import fi.insomnia.bortal.model.Product;
...@@ -34,8 +36,14 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -34,8 +36,14 @@ public class FoodWaveFoodView extends GenericCDIView {
private FoodWaveBeanLocal foodWaveBean; private FoodWaveBeanLocal foodWaveBean;
@EJB @EJB
EventBeanLocal eventBean;
@EJB
private AccountEventBeanLocal accountEventBean; private AccountEventBeanLocal accountEventBean;
@EJB
private BillBeanLocal billBean;
private FoodWave foodWave = null; private FoodWave foodWave = null;
@EJB @EJB
...@@ -45,6 +53,9 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -45,6 +53,9 @@ public class FoodWaveFoodView extends GenericCDIView {
@SelectedUser @SelectedUser
private EventUser user; private EventUser user;
@Inject
private BillEditView billEditView;
private Integer foodwaveid = 0; private Integer foodwaveid = 0;
private ListDataModel<Product> products; private ListDataModel<Product> products;
...@@ -95,34 +106,6 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -95,34 +106,6 @@ public class FoodWaveFoodView extends GenericCDIView {
this.foodWave = foodWave; this.foodWave = foodWave;
} }
////////////////////////////////////////////
/*
public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS)
&& getShoppingcart() == null) {
setShoppingcart(new ListDataModel<ProductShopItem>(
ProductShopItem.productList(productBean
.listUserShoppableProducts())));
updateCartLimits(null);
logger.debug("Initialized billing shoppingcart to {}", getShoppingcart());
this.beginConversation();
}
}*/
/*
public void initShopView() {
setShoppingcart(new ListDataModel<ProductShopItem>(
ProductShopItem.productGTList( getFoodWave().getTemplate().getProducts() )));
this.beginConversation();
}
*/
public String add(Integer count) { public String add(Integer count) {
ProductShopItem item = getShoppingcart().getRowData(); ProductShopItem item = getShoppingcart().getRowData();
item.setCount(item.getCount().add(BigDecimal.valueOf(count))); item.setCount(item.getCount().add(BigDecimal.valueOf(count)));
...@@ -140,16 +123,6 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -140,16 +123,6 @@ public class FoodWaveFoodView extends GenericCDIView {
return add(-1); return add(-1);
} }
/*
public BigDecimal getAccountBalance() {
BigDecimal ret = user.getAccountBalance();
ret = ret.add(getCash());
ret = ret.subtract(getTotalPrice());
return ret;
}*/
public BigDecimal getTotalPrice() { public BigDecimal getTotalPrice() {
BigDecimal ret = BigDecimal.ZERO; BigDecimal ret = BigDecimal.ZERO;
for (ProductShopItem cart : getShoppingcart()) { for (ProductShopItem cart : getShoppingcart()) {
...@@ -158,73 +131,48 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -158,73 +131,48 @@ public class FoodWaveFoodView extends GenericCDIView {
return ret; return ret;
} }
/*
public String commitBillCart() {
if (!productsInCart()) {
super.addFaceMessage("productshop.noItemsInCart");
return null;
}
Bill bill = new Bill(eventbean.getCurrentEvent(), user);
bill.setOurReference(eventbean.getCurrentEvent().getName());
for (ProductShopItem shopitem : getShoppingcart()) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
bill.addProduct(shopitem.getProduct(), shopitem.getCount());
}
}
billbean.createBill(bill);
addFaceMessage("productshop.billCreated");
cash = BigDecimal.ZERO;
setShoppingcart(null);
billEditView.setBill(bill);
return "showCreatedBill";
}*/
/** /**
* When we buy stuff from counter, we actually just create accountevents with zero price, * Just create bills, they are nice
* and add them to foodWave. * <insert picture of bill gates here>
*
* @return * @return
*/ */
public String buyFromCounter() { public Bill createBillFromShoppingcart() {
Bill bill = new Bill(eventBean.getCurrentEvent(), user);
bill.setOurReference(eventBean.getCurrentEvent().getName());
for (ProductShopItem shopitem : getShoppingcart()) { for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) { if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
AccountEvent ae = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), user); bill.addProduct(shopitem.getProduct(), shopitem.getCount(), getFoodWave());
ae.setUnitPrice(new BigDecimal(0));
ae.setFoodWave(foodWave);
accountEventBean.merge(ae);
} }
} }
billBean.createBill(bill);
return "/foodWave/ThanksForOrderingFromCounter."; return bill;
} }
public String buyFromCounter() {
createBillFromShoppingcart();
public String commitShoppingCart() { return "/foodwave/ThanksForOrderingFromCounter";
/* EventUser retuser = null;
for (ProductShopItem shopitem : getShoppingcart()) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), user).getUser();
} }
public String buyFromInternet() {
Bill bill = createBillFromShoppingcart();
if(bill != null) {
getBillEditView().setBillid(bill.getId());
return "/bill/showBill?faces-redirect=true&IncludeViewParams=true";
} }
if (cash != null && cash.compareTo(BigDecimal.ZERO) != 0) {
Product credProd = productBean.findCreditProduct();
retuser = productBean.createAccountEvent(credProd, cash, user).getUser();
}
if (user != null) {
user = retuser;
}
setShoppingcart(null);
cash = BigDecimal.ZERO;*/
return null; return null;
} }
public void setUser(EventUser user) { public void setUser(EventUser user) {
this.user = user; this.user = user;
} }
...@@ -252,37 +200,19 @@ public class FoodWaveFoodView extends GenericCDIView { ...@@ -252,37 +200,19 @@ public class FoodWaveFoodView extends GenericCDIView {
} }
/*
public BillListView getBillListView() {
return billListView;
}
public void setBillListView(BillListView billListView) {
this.billListView = billListView;
}
public BigDecimal getCash() { public BillEditView getBillEditView() {
if (payInstant) { return billEditView;
cash = getTotalPrice();
logger.info("Getting instantcash as {}", cash);
}
if (cash == null) {
cash = BigDecimal.ZERO;
}
return cash;
} }
public void setCash(BigDecimal cash) {
this.cash = cash;
}
public boolean isHasLimits() {
return hasLimits;
}
public void setHasLimits(boolean hasLimits) {
this.hasLimits = hasLimits; public void setBillEditView(BillEditView billEditView) {
this.billEditView = billEditView;
} }
*/
} }
...@@ -209,7 +209,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -209,7 +209,7 @@ public class ProductShopView extends GenericCDIView {
Product credProd = productBean.findCreditProduct(); Product credProd = productBean.findCreditProduct();
retuser = productBean.createAccountEvent(credProd, cash, user).getUser(); retuser = productBean.createAccountEvent(credProd, cash, user).getUser();
} }
if (user != null) { if (retuser != null) {
user = retuser; user = retuser;
} }
shoppingcart = null; shoppingcart = null;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!