Commit 311dcf23 by Tuomas Riihimäki

Merge branch 'master' of codecrew.fi:bortal

2 parents 7a8c9d73 07afd425
......@@ -200,7 +200,7 @@ public class BillBean implements BillBeanLocal {
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL,
SpecialPermission.S_VERKKOMAKSU_CHECK })
public void markPaid(Bill bill, Calendar when) {
public Bill markPaid(Bill bill, Calendar when) {
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
throw new EJBException("Bill already marked paid!");
......@@ -255,17 +255,20 @@ public class BillBean implements BillBeanLocal {
utilbean.sendMail(msg);
eventUserFacade.flush();
eventUserFacade.evict(bill.getUser());
return bill;
}
@Override
@RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL })
public void createBill(Bill bill) {
public Bill createBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to create bill for user ");
throw new EJBAccessException("Could not create bill for another user");
}
billFacade.create(bill);
generateBillNumber(bill);
return bill;
}
@RolesAllowed({ BillPermission.S_WRITE_ALL })
......
......@@ -26,11 +26,11 @@ public interface BillBeanLocal {
Collection<BillSummary> getBillLineSummary();
void markPaid(Bill bill, Calendar when);
Bill markPaid(Bill bill, Calendar when);
void getPdfBillStream(Bill bill, OutputStream ostream);
void createBill(Bill bill);
Bill createBill(Bill bill);
Bill save(Bill bill);
......
......@@ -229,5 +229,9 @@ public class AccountEvent extends GenericEntity {
public void setDeliveredCount(BigDecimal deliveredCount) {
this.deliveredCount = deliveredCount;
}
public boolean isDelivered() {
return (delivered != null);
}
}
......@@ -160,6 +160,10 @@ public class Bill extends GenericEntity {
}
return total;
}
public BigDecimal getTotalPrice() {
return this.totalPrice();
}
/**
* Commodity function to calculate the total price of the bill.
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
......@@ -25,14 +23,14 @@
</ui:define>
<ui:define name="content">
<p:dataTable styleClass="bordertable"
value="#{foodWaveView.unpaidBills}" var="bill_line">
<h:form>
<p:dataTable styleClass="bordertable" value="#{foodWaveView.billLines}" var="bill_line">
<f:facet name="header">
${i18n['foodWave.billLines']}
</f:facet>
<h:outputLabel value="#{i18n['foodWave.billLines']}" />
</f:facet>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['billLine.time']}" />
<h:outputLabel value="#{i18n['billLine.time']}" />
</f:facet>
<h:outputText value="#{bill_line.bill.sentDate.getTime()}">
<f:convertDateTime pattern="hh:mm d/M/yy" />
......@@ -40,40 +38,66 @@
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['billLine.quantity']}" />
<h:outputLabel value="#{i18n['billLine.quantity']}" />
</f:facet>
<h:outputText value="#{bill_line.quantity}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['billLine.product']}" />
<h:outputLabel value="#{i18n['billLine.product']}" />
</f:facet>
<h:outputText value="#{bill_line.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['billLine.eventuser']}" />
<h:outputLabel id="name" value="#{i18n['billLine.eventuser']}" />
</f:facet>
<h:link outcome="/useradmin/edit"
value="#{bill_line.bill.user.wholeName}">
<f:param name="userid" value="#{bill_line.bill.user.id}" />
</h:link>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="#{i18n['billLine.nick']}" />
</f:facet>
<h:link outcome="/useradmin/edit"
value="#{bill_line.bill.user.nick}">
<f:param name="userid" value="#{bill_line.bill.user.id}" />
</h:link>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['billLine.price']}" />
<h:outputLabel value="#{i18n['billLine.price']}" />
</f:facet>
<h:outputText value="#{bill_line.linePrice}" />
</p:column>
</p:dataTable>
<br/>
<br/>
<p:column>
<f:facet name="header">
<h:outputLabel value="#{i18n['bill.totalprice']}" />
</f:facet>
<h:outputText value="#{bill_line.bill.totalPrice}" />
</p:column>
<p:column>
<h:commandButton value="#{i18n['bill.markPaid']}" action="#{foodWaveView.markBillPaid}" />
</p:column>
<!--
<p:column>
<h:commandButton value="#{i18n['bill.remove']}" action="foodWaveView.markBillRemoved" />
</p:column> -->
<p:dataTable styleClass="bordertable"
value="#{foodWaveView.accountEventLines}" var="acc_lines">
</p:dataTable>
<br />
<br />
<h1><h:outputLabel value="#{i18n['foodwave.orders']" /></h1>
<p:dataTable styleClass="bordertable" value="#{foodWaveView.accountEventLines}" var="acc_lines">
<f:facet name="header">
${i18n['foodWave.accountevents']}
</f:facet>
<h:outputLabel value="#{i18n['foodWave.accountevents']}" />
</f:facet>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['acc_lines.time']}" />
......@@ -92,7 +116,7 @@
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['acc_line.product']}" />
</f:facet>
<h:outputText value="#{acc_line.product}" />
<h:outputText value="#{acc_line.product.name}" />
</p:column>
<p:column>
<f:facet name="header">
......@@ -105,13 +129,23 @@
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['acc_line.price']}" />
<h:outputLabel id="name" value="${i18n['acc_line.nick']}" />
</f:facet>
<h:link outcome="/useradmin/edit"
value="#{acc_line.user.nick}">
<f:param name="userid" value="#{acc_line.user.id}" />
</h:link>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel id="name" value="${i18n['accountEvent.delivered']}" />
</f:facet>
<h:outputText value="#{acc_line.total}" />
<h:outputText rendered="#{acc_line.delivered}" value="#{i18n['accountEvent.delivered']}" />
<h:commandButton rendered="#{not acc_line.delivered}" value=#{i18n['accountEvent.deliver']} action="#{foodWaveView.deliverAccountEvent}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
......
......@@ -3,7 +3,6 @@ package fi.insomnia.bortal.web.cdiview.shop;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
......@@ -13,11 +12,15 @@ import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
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.ProductBeanLocal;
import fi.insomnia.bortal.enums.apps.BillPermission;
import fi.insomnia.bortal.enums.apps.ShopPermission;
import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.BillLine;
import fi.insomnia.bortal.model.FoodWave;
import fi.insomnia.bortal.model.FoodWaveTemplate;
......@@ -42,6 +45,11 @@ public class FoodWaveView extends GenericCDIView {
private EventBeanLocal eventbean;
@EJB
private ProductBeanLocal productbeanlocal;
@EJB
private BillBeanLocal billbean;
@EJB
private AccountEventBeanLocal accountEventBean;
private FoodWave selectedFoodWave = null;
......@@ -49,7 +57,7 @@ public class FoodWaveView extends GenericCDIView {
private Product currentProduct;
private ListDataModel<BillLine> billLines;
private List<BillLine> unpaidBills;
// private List<BillLine> unpaidBills;
private Integer foodWaveId;
private ListDataModel<AccountEvent> accountEventLines;
......@@ -162,21 +170,47 @@ public class FoodWaveView extends GenericCDIView {
// ListDataModel<FoodWave>(foodWaveBean.getEventFoodWaves());
// }
public String markBillPaid() {
if (permbean.hasPermission(BillPermission.WRITE_ALL) && getBillLines().isRowAvailable()) {
Bill b = getBillLines().getRowData().getBill();
b = getBillbean().markPaid(b, Calendar.getInstance());
}
return null;
}
public String deliverAccountEvent() {
if (getAccountEventLines().isRowAvailable()) {
AccountEvent e = getAccountEventLines().getRowData();
e.setDelivered(Calendar.getInstance());
e = accountEventBean.merge(e);
}
return null;
}
public void initFoodWaveOrderList() {
if (super.requirePermissions(ShopPermission.MANAGE_FOODWAVES) && selectedFoodWave == null) {
selectedFoodWave = foodWaveBean.findFoodwave(foodWaveId);
billLines = new ListDataModel<BillLine>(selectedFoodWave.getBillLines());
this.setAccountEventLines(new ListDataModel<AccountEvent>(selectedFoodWave.getAccountEvents()));
List<BillLine> tmpLines = new ArrayList<BillLine>();
for (BillLine line : selectedFoodWave.getBillLines()) {
if (!line.getBill().isPaid()) {
tmpLines.add(line);
}
}
setBillLines(new ListDataModel<BillLine>(tmpLines));
setUnpaidBills(new ArrayList<BillLine>());
Iterator<BillLine> biterator = billLines.iterator();
while (biterator.hasNext()) {
BillLine unpaidBill = biterator.next();
if (unpaidBill.getBill().isPaid())
this.getUnpaidBills().add(unpaidBill);
}
setAccountEventLines(new ListDataModel<AccountEvent>(selectedFoodWave.getAccountEvents()));
super.beginConversation();
}
......@@ -261,13 +295,19 @@ public class FoodWaveView extends GenericCDIView {
public void setAccountEventLines(ListDataModel<AccountEvent> accountEventLines) {
this.accountEventLines = accountEventLines;
}
/*
* public List<BillLine> getUnpaidBills() { return unpaidBills; }
*
* public void setUnpaidBills(List<BillLine> unpaidBills) { this.unpaidBills
* = unpaidBills; }
*/
public List<BillLine> getUnpaidBills() {
return unpaidBills;
public BillBeanLocal getBillbean() {
return billbean;
}
public void setUnpaidBills(List<BillLine> unpaidBills) {
this.unpaidBills = unpaidBills;
public void setBillbean(BillBeanLocal billbean) {
this.billbean = billbean;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!