Commit 7c62cc6c by Tuomas Riihimäki

Bill list paginatino

1 parent a0a5e537
...@@ -27,11 +27,13 @@ import java.util.List; ...@@ -27,11 +27,13 @@ import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
import fi.codecrew.moya.bortal.views.BillSummary; import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.entitysearch.BillSearchQuery;
import fi.codecrew.moya.exceptions.BillException; import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave; import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.utilities.SearchResult;
@Local @Local
public interface BillBeanLocal { public interface BillBeanLocal {
...@@ -59,9 +61,13 @@ public interface BillBeanLocal { ...@@ -59,9 +61,13 @@ public interface BillBeanLocal {
List<Bill> find(EventUser user); List<Bill> find(EventUser user);
Bill expireBill(Bill bill); Bill expireBill(Bill bill);
Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave); Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave);
Bill addProductToBill(Bill bill, Product product, BigDecimal count); Bill addProductToBill(Bill bill, Product product, BigDecimal count);
SearchResult<Bill> findAll(BillSearchQuery q);
SearchResult<Bill> findUsers(BillSearchQuery q);
} }
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.entitysearch;
import java.util.Map;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.utilities.SearchQuery;
public class BillSearchQuery extends SearchQuery {
private static final long serialVersionUID = -522847840222858146L;
private final Map<String, Object> filters;
private EventUser user;
public BillSearchQuery(int first, int pageSize, String sortField, QuerySortOrder sort, Map<String, Object> filters) {
super((int) first / pageSize, pageSize, sortField, null, sort);
this.filters = filters;
}
public Map<String, Object> getFilters() {
return filters;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser user) {
this.user = user;
}
}
...@@ -30,39 +30,31 @@ import javax.annotation.security.DeclareRoles; ...@@ -30,39 +30,31 @@ import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.EJBAccessException; import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beanutil.PdfPrinter; import fi.codecrew.moya.beanutil.PdfPrinter;
import fi.codecrew.moya.bortal.views.BillSummary; import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.entitysearch.BillSearchQuery;
import fi.codecrew.moya.enums.apps.BillPermission; import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.enums.apps.ShopPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission; import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.exceptions.BillException; import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.exceptions.BillExceptionAlreadyPaid;
import fi.codecrew.moya.exceptions.BillExceptionNotEnoughtCredits;
import fi.codecrew.moya.facade.BillFacade; import fi.codecrew.moya.facade.BillFacade;
import fi.codecrew.moya.facade.BillLineFacade; import fi.codecrew.moya.facade.BillLineFacade;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.PlaceSlotFacade; import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.BillLine; import fi.codecrew.moya.model.BillLine;
import fi.codecrew.moya.model.Discount; import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave; import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.LanEvent; import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceSlot; import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag; import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.jpa.GenericFacade;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType; import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
...@@ -385,4 +377,21 @@ public class BillBean implements BillBeanLocal { ...@@ -385,4 +377,21 @@ public class BillBean implements BillBeanLocal {
return bill; return bill;
} }
@Override
@RolesAllowed(BillPermission.S_READ_ALL)
public SearchResult<Bill> findAll(BillSearchQuery q) {
return billFacade.find(q);
}
@RolesAllowed(BillPermission.S_VIEW_OWN)
public SearchResult<Bill> findUsers(BillSearchQuery q) {
if (q.getUser() == null) {
q.setUser(permbean.getCurrentUser());
} else if (!permbean.hasPermission(BillPermission.VIEW_OWN) && !permbean.isCurrentUser(q.getUser())) {
throw new EJBAccessException("Tried to fetch bills for wrong user");
}
return billFacade.find(q);
}
} }
...@@ -18,19 +18,38 @@ ...@@ -18,19 +18,38 @@
*/ */
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.metamodel.SingularAttribute;
import fi.codecrew.moya.model.Bill_; import fi.codecrew.moya.model.Bill_;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.entitysearch.BillSearchQuery;
import fi.codecrew.moya.facade.callbacks.OrderCallback;
import fi.codecrew.moya.facade.callbacks.bill.BillEventPredicate;
import fi.codecrew.moya.facade.callbacks.bill.BillFilterPredicate;
import fi.codecrew.moya.facade.callbacks.bill.BillOrderPredicate;
import fi.codecrew.moya.facade.callbacks.bill.BillUserPredicate;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.jpa.FacadeCallback;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -44,13 +63,6 @@ public class BillFacade extends IntegerPkGenericFacade<Bill> { ...@@ -44,13 +63,6 @@ public class BillFacade extends IntegerPkGenericFacade<Bill> {
} }
// @Override
// public void create(Bill entity) {
// super.create(entity);
// userfacade.evict(entity.getUser());
//
// }
public Integer getBiggestBillNumber() { public Integer getBiggestBillNumber() {
// SELECT max(b.billNumber) from Bill b where b.event = :event // SELECT max(b.billNumber) from Bill b where b.event = :event
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
...@@ -83,4 +95,17 @@ public class BillFacade extends IntegerPkGenericFacade<Bill> { ...@@ -83,4 +95,17 @@ public class BillFacade extends IntegerPkGenericFacade<Bill> {
} }
public SearchResult<Bill> find(BillSearchQuery queryParams) {
LanEvent event = eventbean.getCurrentEvent();
List<FacadeCallback<Bill>> callbacks = new ArrayList<>();
callbacks.add(new BillEventPredicate(event));
callbacks.add(new BillFilterPredicate(event, queryParams.getFilters()));
callbacks.add(new BillOrderPredicate(queryParams));
callbacks.add(new BillUserPredicate(queryParams.getUser()));
return super.searcher(queryParams, callbacks);
}
} }
...@@ -182,8 +182,8 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> { ...@@ -182,8 +182,8 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
} }
From<?, EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class); From<?, EventUser> listRoot = searchCallbacks(listCQuery, callbacks, EventUser.class, true);
From<?, EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class); From<?, EventUser> countRoot = searchCallbacks(countCQuery, callbacks, EventUser.class,false);
listCQuery.select(listRoot); listCQuery.select(listRoot);
countCQuery.select(cb.count(countRoot)); countCQuery.select(cb.count(countRoot));
......
...@@ -185,6 +185,10 @@ public class Bill extends GenericEntity { ...@@ -185,6 +185,10 @@ public class Bill extends GenericEntity {
return null; return null;
} }
public static Integer getBillnrFromReference(LanEvent event, Integer reference) {
return (reference / 10) - event.getReferenceNumberBase();
}
public Integer getReferenceNumber() public Integer getReferenceNumber()
{ {
return BillUtils.createReferenceNumber(getReferenceNumberBase()); return BillUtils.createReferenceNumber(getReferenceNumberBase());
......
...@@ -47,6 +47,10 @@ public class SearchQuery implements Serializable { ...@@ -47,6 +47,10 @@ public class SearchQuery implements Serializable {
this.sortDirection = direction; this.sortDirection = direction;
} }
public int getFirstElement() {
return page * pagesize;
}
public int getPage() { public int getPage() {
return page; return page;
} }
......
...@@ -21,6 +21,7 @@ package fi.codecrew.moya.utilities.jpa; ...@@ -21,6 +21,7 @@ package fi.codecrew.moya.utilities.jpa;
import java.io.Serializable; import java.io.Serializable;
public interface ModelInterface extends Serializable { public interface ModelInterface extends Serializable {
public static final String ID_COLUMN = "id";
Integer getId(); Integer getId();
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "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" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:bills="http://java.sun.com/jsf/composite/cditools/bills" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:bills="http://java.sun.com/jsf/composite/cditools/bills" xmlns:p="http://primefaces.org/ui">
xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
>
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" /> <f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{billListView.initUsersBills}" /> <f:event type="preRenderView" listener="#{billListView.initUsersBills}" />
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<bills:list /> <h:form id="billList" styleClass="moya_datatable3">
<p:outputPanel rendered="#{placeGroupView.useEticket}" >
<p:dataTable sortBy="#{user.sentDateTime}" sortOrder="descending" sortField="sentDate" paginator="true" lazy="true" rows="100" styleClass="bordertable" id="billList" value="#{billListView.lazyBillList}" var="bill"
rowStyleClass="#{bill.expired ? 'expired' : (bill.paidDate != null ? 'paid' : null)}" expandedRow="true">
<p:column >
<f:facet name="header">
<h:outputText value="${i18n['bill.sentDate']}" />
</f:facet>
<h:outputText value="#{bill.sentDateTime}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="${i18n['bill.id']}" />
</f:facet>
<h:outputText value="#{bill.id}" />
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="${i18n['bill.billNumber']}" />
</f:facet>
<h:outputText value="#{bill.billNumber}" />
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="${i18n['bill.referencenumber']}" />
</f:facet>
<h:outputText value="#{bill.referenceNumberBase}">
<f:converter binding="#{referenceNumberConverter}" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="${i18n['bill.totalPrice']}" />
</f:facet>
<h:outputText value="#{bill.totalPrice()}">
<f:convertNumber currencyCode="EUR" maxFractionDigits="2" minFractionDigits="2" type="currency" locale="#{sessionHandler.locale}" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="${i18n['bill.vat']}" />
</f:facet>
<h:outputText value="#{bill.totalVat()}">
<f:convertNumber currencyCode="EUR" maxFractionDigits="2" minFractionDigits="2" type="currency" locale="#{sessionHandler.locale}" />
</h:outputText>
</p:column>
<p:column rendered="#{(!bill.expired and sessionHandler.isEventBoolProperty('ALLOW_BILLING')) or billListView.canWriteBill}">
<ui:fragment>
<a href="#{request.contextPath}/PrintBill?billid=#{bill.id}" target="_blank">#{i18n['bill.printBill']}</a>
</ui:fragment>
</p:column>
<p:column>
<h:link outcome="/bill/showBill" value="#{i18n['bill.show']}">
<f:param name="billid" value="#{bill.id}" />
</h:link>
</p:column>
<p:rowExpansion>
<p:dataList value="#{bill.billLines}" var="line">
<h:outputText value="#{line.name}" />:
<h:outputText value="#{line.quantity}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="0" />
</h:outputText>
</p:dataList>
</p:rowExpansion>
</p:dataTable>
</h:form>
<p:outputPanel rendered="#{placeGroupView.useEticket}">
<p> <p>
<p:button outcome="/place/myEtickets" value="#{i18n['placegroup.showEticket']}" /> <p:button outcome="/place/myEtickets" value="#{i18n['placegroup.showEticket']}" />
</p> </p>
</p:outputPanel> </p:outputPanel>
<br /><br /> <br />
<br />
</ui:define> </ui:define>
</ui:composition> </ui:composition>
</h:body> </h:body>
......
<?xml version='1.0' encoding='UTF-8' ?> <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core">
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface> <composite:interface>
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:outputText rendered="#{billListView.bills.rowCount le 0}"
value="#{i18n['bills.noBills']}" />
<h:form rendered="#{billListView.canWriteBill}"> <h:form rendered="#{billListView.canWriteBill}">
<p:commandButton ajax="false" <p:commandButton ajax="false" action="#{billListView.showPayButtonsAction()}" value="#{i18n['bill.showPayButtons']}" />
action="#{billListView.showPayButtonsAction()}"
value="#{i18n['bill.showPayButtons']}" />
</h:form> </h:form>
<h:form rendered="#{billListView.bills.rowCount gt 0}" id="billList" styleClass="moya_datatable3"> <h:form id="billList" styleClass="moya_datatable3">
<p:dataTable styleClass="bordertable" id="billList" <p:dataTable sortBy="#{user.sentDateTime}" sortOrder="descending" sortField="sentDate" paginator="true" lazy="true" rows="100" styleClass="bordertable" id="billList" value="#{billListView.lazyBillList}" var="bill"
value="#{billListView.bills}" var="bill" rowStyleClass="#{bill.expired ? 'expired' : (bill.paidDate != null ? 'paid' : null)}" >
rowStyleClass="#{bill.expired ? 'expired' : (bill.paidDate != null ? 'paid' : null)}"
expandedRow="true">
<p:column style="width:16px"
rendered="#{billListView.bills.rowCount lt 20}">
<p:rowToggler /> <p:column rendered="#{billListView.canWriteBill}" id="payerCol" field="payer" filterBy="#{bill.user.user.id}" sortBy="#{bill.user.user.id}">
</p:column>
<p:column rendered="#{billListView.canWriteBill}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['bill.payer']}" /> <h:outputText value="#{i18n['bill.payer']}" />
</f:facet> </f:facet>
<h:link rendered="#{billListView.canWriteBill}" outcome="/useradmin/edit" value="#{bill.user.user.login} #{bill.addr1}"> <h:link rendered="#{billListView.canWriteBill}" outcome="/useradmin/edit" value="#{bill.user.user.login} #{bill.addr1}">
<f:param name="userid" value="#{bill.user.user.id}" /> <f:param name="userid" value="#{bill.user.user.id}" />
</h:link> </h:link>
<h:outputText rendered="#{not billListView.canWriteBill}" <h:outputText rendered="#{not billListView.canWriteBill}" value="#{bill.addr1}" />
value="#{bill.addr1}" />
</p:column> </p:column>
<p:column>
<p:column field="sentDate" filterBy="#{bill.sentDateTime}" sortBy="#{bill.sentDateTime}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.sentDate']}" /> <h:outputText value="${i18n['bill.sentDate']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.sentDateTime}"> <h:outputText value="#{bill.sentDateTime}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column>
<p:column field="id" filterBy="#{bill.id}" sortBy="#{bill.id}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.id']}" /> <h:outputText value="${i18n['bill.id']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.id}" /> <h:outputText value="#{bill.id}" />
</p:column> </p:column>
<p:column> <p:column field="billNumber" filterBy="#{bill.billNumber}" sortBy="#{bill.billNumber}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.billNumber']}" /> <h:outputText value="${i18n['bill.billNumber']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.billNumber}" /> <h:outputText value="#{bill.billNumber}" />
</p:column> </p:column>
<p:column rendered="#{billListView.canWriteBill}">
<p:column rendered="#{billListView.canWriteBill}" field="referenceNumber" filterBy="#{bill.billNumber}" sortBy="#{bill.billNumber}">
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['bill.referencenumber']}" /> <h:outputText value="${i18n['bill.referencenumber']}" />
</f:facet> </f:facet>
...@@ -85,9 +72,7 @@ ...@@ -85,9 +72,7 @@
<h:outputText value="${i18n['bill.totalPrice']}" /> <h:outputText value="${i18n['bill.totalPrice']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.totalPrice()}"> <h:outputText value="#{bill.totalPrice()}">
<f:convertNumber currencyCode="EUR" maxFractionDigits="2" <f:convertNumber currencyCode="EUR" maxFractionDigits="2" minFractionDigits="2" type="currency" locale="#{sessionHandler.locale}" />
minFractionDigits="2" type="currency"
locale="#{sessionHandler.locale}" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column> <p:column>
...@@ -95,17 +80,13 @@ ...@@ -95,17 +80,13 @@
<h:outputText value="${i18n['bill.vat']}" /> <h:outputText value="${i18n['bill.vat']}" />
</f:facet> </f:facet>
<h:outputText value="#{bill.totalVat()}"> <h:outputText value="#{bill.totalVat()}">
<f:convertNumber currencyCode="EUR" maxFractionDigits="2" <f:convertNumber currencyCode="EUR" maxFractionDigits="2" minFractionDigits="2" type="currency" locale="#{sessionHandler.locale}" />
minFractionDigits="2" type="currency"
locale="#{sessionHandler.locale}" />
</h:outputText> </h:outputText>
</p:column> </p:column>
<p:column <p:column rendered="#{(!bill.expired and sessionHandler.isEventBoolProperty('ALLOW_BILLING')) or billListView.canWriteBill}">
rendered="#{(!bill.expired and sessionHandler.isEventBoolProperty('ALLOW_BILLING')) or billListView.canWriteBill}">
<ui:fragment> <ui:fragment>
<a href="#{request.contextPath}/PrintBill?billid=#{bill.id}" <a href="#{request.contextPath}/PrintBill?billid=#{bill.id}" target="_blank">#{i18n['bill.printBill']}</a>
target="_blank">#{i18n['bill.printBill']}</a>
</ui:fragment> </ui:fragment>
</p:column> </p:column>
<p:column> <p:column>
...@@ -119,59 +100,53 @@ ...@@ -119,59 +100,53 @@
</h:link> </h:link>
</p:column> </p:column>
<p:column rendered="#{billListView.canWriteBill}"> <p:column rendered="#{billListView.canWriteBill}">
<p:commandButton update="billList" onerror="location.reload(true)" <p:commandButton update="billList" onerror="location.reload(true)" rendered="#{bill.paidDate == null and billListView.showPayButtons}" action="#{billListView.markPaid()}" value="#{i18n['bill.markPaid']}" />
rendered="#{bill.paidDate == null and billListView.showPayButtons}" <h:outputText rendered="#{bill.paidDate != null}" value="#{i18n['bill.isPaid']}" />
action="#{billListView.markPaid()}" <h:outputText rendered="#{bill.paidDate == null and !billListView.showPayButtons}" value="#{i18n['bill.isNotPaid']}" />
value="#{i18n['bill.markPaid']}" />
<h:outputText rendered="#{bill.paidDate != null}"
value="#{i18n['bill.isPaid']}" />
<h:outputText
rendered="#{bill.paidDate == null and !billListView.showPayButtons}"
value="#{i18n['bill.isNotPaid']}" />
</p:column> </p:column>
<p:column rendered="#{!billListView.canWriteBill}"> <p:column rendered="#{!billListView.canWriteBill}">
<h:outputText rendered="#{bill.paidDate != null}" <h:outputText rendered="#{bill.paidDate != null}" value="#{i18n['bill.isPaid']}" />
value="#{i18n['bill.isPaid']}" /> <h:outputText rendered="#{bill.paidDate == null}" value="#{i18n['bill.isNotPaid']}" />
<h:outputText rendered="#{bill.paidDate == null}"
value="#{i18n['bill.isNotPaid']}" />
</p:column> </p:column>
<p:column rendered="#{billListView.canWriteBill and not empty billListView.paytrailMerchantId}"> <p:column rendered="#{billListView.canWriteBill and not empty billListView.paytrailMerchantId}">
<button onclick="showPaymentstatus('#{bill.id}'); return false;"><h:outputText value="#{i18n['bill.checkPaytrail']}" /></button> <button onclick="showPaymentstatus('#{bill.id}'); return false;">
<h:outputText value="#{i18n['bill.checkPaytrail']}" />
</button>
</p:column>
<p:column>
<p:commandButton update=":billlist:billList:payerPanel" oncomplete="PF('carOP').show('#{component.clientId}')" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{bill}" target="#{billListView.selectedBill}" />
</p:commandButton>
</p:column> </p:column>
</p:dataTable>
<p:rowExpansion rendered="#{billListView.bills.rowCount lt 20}"> <p:overlayPanel id="payerPanel" widgetVar="carOP">
<p:dataList value="#{bill.billLines}" var="line"> <p:dataList value="#{billListView.selectedBill.billLines}" var="line">
<h:outputText value="#{line.name}" />: <h:outputText value="#{line.name}" />:
<h:outputText value="#{line.quantity}"> <h:outputText value="#{line.quantity}">
<f:convertNumber minFractionDigits="0" maxFractionDigits="0" /> <f:convertNumber minFractionDigits="0" maxFractionDigits="2" />
</h:outputText> </h:outputText>
</p:dataList> </p:dataList>
</p:rowExpansion> </p:overlayPanel>
</h:form>
</p:dataTable>
</h:form>
<form id="paymentcheckform" target="_blank" action="https://payment.paytrail.com/check-payment" method="post"> <form id="paymentcheckform" target="_blank" action="https://payment.paytrail.com/check-payment" method="post">
<input name="MERCHANT_ID" type="hidden" value="#{billListView.paytrailMerchantId}" /> <input name="MERCHANT_ID" type="hidden" value="#{billListView.paytrailMerchantId}" /> <input id="paymentordernr" name="ORDER_NUMBER" type="hidden" value="" /> <input id="paymentauthcode" name="AUTHCODE" type="hidden" value="" /> <input name="VERSION"
<input id="paymentordernr" name="ORDER_NUMBER" type="hidden" value="" /> type="hidden" value="2" />
<input id="paymentauthcode" name="AUTHCODE" type="hidden" value="" />
<input name="VERSION" type="hidden" value="2" />
</form> </form>
<script type="text/javascript" > <script type="text/javascript">
function showPaymentstatus(id) { function showPaymentstatus(id) {
$("#paymentordernr").val(id); $("#paymentordernr").val(id);
$("#paymentauthcode").val(authcodes[id]); $("#paymentauthcode").val(authcodes[id]);
$("#paymentcheckform").submit(); $("#paymentcheckform").submit();
return false; return false;
} }
var authcodes ={}; var authcodes = {};
<ui:repeat var="ac" value="#{billListView.paytrailAuthcodes}"> <ui:repeat var="ac" value="#{billListView.paytrailAuthcodes}">
<h:outputText value="authcodes['#{ac.key}'] ='#{ac.value}';" /> <h:outputText value="authcodes['#{ac.key}'] ='#{ac.value}';" />
</ui:repeat> </ui:repeat>
</script> </script>
......
<?xml version='1.0' encoding='UTF-8' ?> <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite" <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui" xmlns:tools="http://java.sun.com/jsf/composite/tools"> xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui" xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface> <composite:interface>
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" /> <h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<p:dataTable id="user" value="#{userSearchView.userModel}" styleClass="moya_datatable4" rows="100" var="wra" paginator="true" lazy="true"> <p:dataTable id="user" value="#{userSearchView.userModel}" styleClass="moya_datatable4" rows="100" var="wra" paginator="true" lazy="true" sortBy="sentDate" sortOrder="descending">
<p:column sortBy="#{wra.user.nick}" headerText="#{i18n['user.nick']}"> <p:column sortBy="#{wra.user.nick}" headerText="#{i18n['user.nick']}">
<h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" /> <h:outputText value="#{(empty wra.user.nick)?'----':wra.user.nick}" />
......
...@@ -20,7 +20,6 @@ package fi.codecrew.moya.web.cdiview.shop; ...@@ -20,7 +20,6 @@ package fi.codecrew.moya.web.cdiview.shop;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -31,17 +30,26 @@ import javax.enterprise.context.ConversationScoped; ...@@ -31,17 +30,26 @@ import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.management.RuntimeErrorException;
import org.primefaces.model.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BillBeanLocal; import fi.codecrew.moya.beans.BillBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.VerkkomaksutFiBeanLocal; import fi.codecrew.moya.beans.VerkkomaksutFiBeanLocal;
import fi.codecrew.moya.bortal.views.BillSummary; import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.entitysearch.BillSearchQuery;
import fi.codecrew.moya.enums.apps.BillPermission; import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.exceptions.BillException; import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.model.Bill; import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.web.annotations.SelectedUser; import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.helpers.LazyEntityDataModel;
@Named @Named
@ConversationScoped @ConversationScoped
...@@ -56,11 +64,14 @@ public class BillListView extends GenericCDIView { ...@@ -56,11 +64,14 @@ public class BillListView extends GenericCDIView {
@SelectedUser @SelectedUser
private transient EventUser user; private transient EventUser user;
private Bill selectedBill;
@EJB @EJB
private transient BillBeanLocal billbean; private transient BillBeanLocal billbean;
@EJB
private EventBeanLocal eventbean;
private transient ListDataModel<Bill> bills; // private transient ListDataModel<Bill> bills;
//
private boolean writeBill; private boolean writeBill;
private ArrayList<BillSummary> billsummary; private ArrayList<BillSummary> billsummary;
...@@ -83,16 +94,23 @@ public class BillListView extends GenericCDIView { ...@@ -83,16 +94,23 @@ public class BillListView extends GenericCDIView {
private Map<Integer, String> paytrailAuthcodes; private Map<Integer, String> paytrailAuthcodes;
private LazyBillDataModel lazyBillList;
private static final Logger logger = LoggerFactory.getLogger(BillListView.class);
public void initAllBills() { public void initAllBills() {
if (super.requirePermissions(BillPermission.READ_ALL)) { if (super.requirePermissions(BillPermission.READ_ALL) && lazyBillList == null) {
beginConversation(); beginConversation();
List<Bill> billList = billbean.findAll(); logger.info("Initializing lazyList");
bills = new ListDataModel<Bill>(billList); lazyBillList = new LazyBillDataModel(true);
writeBill = permbean.hasPermission(BillPermission.WRITE_ALL);
if (paytrailBean.isSvmEnabled()) { // List<Bill> billList = billbean.findAll();
setPaytrailMerchantId(paytrailBean.getMerchantId()); // bills = new ListDataModel<Bill>(billList);
paytrailAuthcodes = paytrailBean.getAuthcodeForBills(billList); // writeBill = permbean.hasPermission(BillPermission.WRITE_ALL);
} // if (paytrailBean.isSvmEnabled()) {
// setPaytrailMerchantId(paytrailBean.getMerchantId());
// paytrailAuthcodes = paytrailBean.getAuthcodeForBills(billList);
// }
} }
} }
...@@ -120,7 +138,9 @@ public class BillListView extends GenericCDIView { ...@@ -120,7 +138,9 @@ public class BillListView extends GenericCDIView {
public void initUsersBills() { public void initUsersBills() {
if (requirePermissions(BillPermission.VIEW_OWN, permbean.isLoggedIn())) { if (requirePermissions(BillPermission.VIEW_OWN, permbean.isLoggedIn())) {
beginConversation(); beginConversation();
bills = new ListDataModel<Bill>(billbean.find(user)); lazyBillList = new LazyBillDataModel(false);
// bills = new ListDataModel<Bill>(billbean.find(user));
writeBill = permbean.hasPermission(BillPermission.WRITE_ALL); writeBill = permbean.hasPermission(BillPermission.WRITE_ALL);
} }
...@@ -130,7 +150,8 @@ public class BillListView extends GenericCDIView { ...@@ -130,7 +150,8 @@ public class BillListView extends GenericCDIView {
if (permbean.hasPermission(BillPermission.WRITE_ALL)) { if (permbean.hasPermission(BillPermission.WRITE_ALL)) {
try { try {
billbean.markPaid(bills.getRowData(), Calendar.getInstance(), false); Bill bill = lazyBillList.getRowData();
billbean.markPaid(bill, Calendar.getInstance(), false);
} catch (BillException x) { } catch (BillException x) {
throw new RuntimeException(x); throw new RuntimeException(x);
} }
...@@ -142,15 +163,15 @@ public class BillListView extends GenericCDIView { ...@@ -142,15 +163,15 @@ public class BillListView extends GenericCDIView {
return null; return null;
} }
public void setBills(ListDataModel<Bill> bills) { // public void setBills(ListDataModel<Bill> bills) {
this.bills = bills; // this.bills = bills;
} // }
//
public ListDataModel<Bill> getBills() { // public ListDataModel<Bill> getBills() {
//
return bills; // return bills;
} // }
//
public boolean isCanWriteBill() { public boolean isCanWriteBill() {
return writeBill; return writeBill;
} }
...@@ -183,4 +204,65 @@ public class BillListView extends GenericCDIView { ...@@ -183,4 +204,65 @@ public class BillListView extends GenericCDIView {
this.paytrailMerchantId = paytrailMerchantId; this.paytrailMerchantId = paytrailMerchantId;
} }
public LazyBillDataModel getLazyBillList() {
return lazyBillList;
}
public void setLazyBillList(LazyBillDataModel lazyBillList) {
this.lazyBillList = lazyBillList;
}
public Bill getSelectedBill() {
return selectedBill;
}
public void setSelectedBill(Bill selectedBill) {
this.selectedBill = selectedBill;
}
public class LazyBillDataModel extends LazyEntityDataModel<Bill> {
private static final long serialVersionUID = -7870775597332505494L;
private final boolean allBills;
private EventUser user;
public LazyBillDataModel(boolean allBills) {
this.allBills = allBills;
}
@Override
public List<Bill> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
logger.info("Loading with {}, {}", first, pageSize);
QuerySortOrder sort = QuerySortOrder.UNSORTED;
switch (sortOrder) {
case ASCENDING:
sort = QuerySortOrder.ASCENDING;
break;
case DESCENDING:
sort = QuerySortOrder.DESCENDING;
break;
case UNSORTED:
default:
sort = QuerySortOrder.UNSORTED;
break;
}
BillSearchQuery q = new BillSearchQuery(first, pageSize, sortField, sort, filters);
q.setUser(user);
SearchResult<Bill> ret;
if (allBills) {
ret = billbean.findAll(q);
} else {
ret = billbean.findUsers(q);
}
this.setRowCount((int) ret.getResultcount());
return ret.getResults();
}
@Override
protected Bill findEntity(Integer id) {
return billbean.findById(id);
}
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!