18 package org.turro.financials.portfolio;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.TreeSet;
27 import org.turro.command.Command;
28 import org.turro.command.Context;
29 import org.turro.elephant.zkoss.Modal;
30 import org.turro.elephant.zkoss.ModalWindow;
31 import org.turro.financials.document.logic.DocumentWrapper;
32 import org.turro.financials.entity.Contract;
33 import org.turro.financials.entity.Document;
34 import org.turro.financials.entity.DocumentDefinition;
35 import org.turro.financials.entity.DocumentLine;
36 import org.turro.financials.menu.FinancialsMenu;
37 import org.zkoss.zul.Grid;
45 private boolean wasCancelled =
false;
51 Boolean direction =
null;
52 List<PortfolioAction> list =
new ArrayList<>();
54 public void doIt(Grid grid) {
59 documentDefinition =
null;
61 list =
new ArrayList<>();
63 Iterator<PortfolioAction> it = iterator();
83 private void doNext(
final Iterator<PortfolioAction> it) {
86 processList(
new Command() {
88 public Object execute(Context context) {
114 private boolean isBreak(PortfolioAction pa) {
115 if(contract !=
null && contract.
getId() != pa.getDocument().getContract().getId() && (po ==
null || po.
isStopOnContract())) {
118 if(direction !=
null && !direction.equals(pa.isForward())) {
121 if(documentDefinition !=
null && documentDefinition.
getId() != pa.getDocumentDefinition().getId()) {
127 private void processList(
final Command command) {
128 if(list.isEmpty() || wasCancelled)
return;
130 final Date now =
new Date();
132 HashMap args =
new HashMap();
133 Collection<Document> docs = getDocuments(list);
134 args.put(
"portfolioDocs", docs);
135 args.put(
"portfolioOptions",
new PortfolioOptions(documentDefinition, contract));
136 portForm = Modal.getModal(
"/WEB-INF/_zul/financials/document/portfolioAction.zul",
null, args);
137 Modal.doModal(portForm,
new Command() {
139 public Object execute(Context context) {
140 processResult(portForm.
getResult(), portForm, list, now);
143 if(command !=
null) command.execute(context);
148 processResult(1, portForm, list, now);
153 private boolean processResult(
int result, ModalWindow portForm, List<PortfolioAction> list, Date now) {
157 }
else if (result == 1) {
159 po = (PortfolioOptions) portForm.getResultValue();
165 for(PortfolioAction pa : list) {
171 nd.flowFrom(pa.getDocument(),
new DocumentWrapper(pa.getDocument()).getDocDescription(), pa.getWorkflow());
172 nd.setDocumentNumber(pa.getDocument().getDocumentNumber() +
"/1");
174 nd.backFrom(pa.getDocument(),
new DocumentWrapper(pa.getDocument()).getDocDescription(), pa.getWorkflow());
175 nd.setDocumentNumber(pa.getDocument().getDocumentNumber() +
"\\1");
178 nd.setDocumentDate(now);
179 nd.setReceiptDate(now);
181 nd.setDocumentDate(po.
getDate());
182 nd.setReceiptDate(po.
getDate());
185 for(DocumentLine dl : nd.getDocumentLines()) {
191 new DocumentWrapper(nd).save(
new ArrayList(nd.getDocumentLines()),
null);
193 FinancialsMenu.showDocument(nd);
196 pa.getRow().detach();
200 new DocumentWrapper(nd).save(
new ArrayList(nd.getDocumentLines()),
null);
202 FinancialsMenu.showDocument(nd);
210 private Collection<Document> getDocuments(List<PortfolioAction> list) {
211 ArrayList<Document> docs =
new ArrayList<>();
212 for(PortfolioAction pa : list) {
213 docs.add(pa.getDocument());
DocumentDefinition getDocumentDefinition()
boolean isStopOnContract()
boolean isConciliateRegister()