BrightSide Workbench Full Report + Source Code
QuickDocument.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.document;
20 
21 import java.util.ArrayList;
22 import java.util.Date;
23 import org.turro.financials.contract.ContractCombobox;
24 import org.turro.financials.contract.ContractListbox;
25 import org.turro.financials.contract.logic.ContractWrapper;
26 import org.turro.financials.document.logic.DocumentWrapper;
27 import org.turro.financials.entity.Document;
28 import org.turro.financials.entity.DocumentLine;
29 import org.turro.financials.entity.DocumentWorkflow;
30 import org.turro.financials.linetype.LineTypePreferenceListbox;
31 import org.turro.financials.menu.FinancialsMenu;
32 import org.turro.financials.model.document.DocumentDefinitionWrapper;
33 import org.turro.zkoss.input.DateboxShort;
34 import org.turro.zkoss.input.ExpressionInput;
35 import org.turro.zul.frame.Framework;
36 import org.zkoss.zk.ui.Executions;
37 import org.zkoss.zk.ui.IdSpace;
38 import org.zkoss.zk.ui.event.Event;
39 import org.zkoss.zk.ui.event.Events;
40 import org.zkoss.zk.ui.ext.AfterCompose;
41 import org.zkoss.zk.ui.select.Selectors;
42 import org.zkoss.zk.ui.select.annotation.Listen;
43 import org.zkoss.zk.ui.select.annotation.Wire;
44 import org.zkoss.zul.Textbox;
45 import org.zkoss.zul.Window;
46 
51 public class QuickDocument extends Window implements IdSpace, AfterCompose {
52 
53  @Wire("#contract")
54  private ContractCombobox contract;
55  @Wire("#ctcDef")
56  private DocumentDefinitionListbox ctcDef;
57  @Wire("#store1")
58  private ContractListbox store1;
59  @Wire("#lineType1")
60  private LineTypePreferenceListbox lineType1;
61  @Wire("#docFlow")
62  private DocumentDefinitionListbox docFlow;
63  @Wire("#store2")
64  private ContractListbox store2;
65  @Wire("#lineType2")
66  private LineTypePreferenceListbox lineType2;
67  @Wire("#docDate")
68  private DateboxShort docDate;
69  @Wire("#docReceipt")
70  private DateboxShort docReceipt;
71  @Wire("#docNumber")
72  private Textbox docNumber;
73  @Wire("#docAmount")
74  private ExpressionInput docAmount;
75  @Wire("#docTax")
76  private ExpressionInput docTax;
77 
78  private final Date date;
79  private final Double amount;
80  private final String concept;
81 
82  @Listen("onChange = #contract")
83  public void onChangeContract() {
84  if(contract.getObjectValue() != null) {
85  ctcDef.updateContractDefinition(contract.getObjectValue().getContractDefinition());
86  ctcDef.setDisabled(false);
87  } else {
88  ctcDef.setDisabled(true);
89  }
90  }
91 
92  @Listen("onSelect = #ctcDef")
93  public void onSelectCtcDef() {
94  if(ctcDef.getObjectValue() != null) {
95  Document doc = new Document();
96  doc.setContract(contract.getObjectValue());
98  contract.getObjectValue().getFlowFor(doc);
100  contract.getObjectValue().getContractDefinition(),
101  ctcDef.getObjectValue()));
102  docFlow.setDisabled(false);
103  lineType1.setDocument(doc);
104  lineType1.setDisabled(false);
107  store1.setDisabled(false);
108  } else {
109  docFlow.setDisabled(true);
110  lineType1.setDisabled(true);
111  store1.setDisabled(true);
112  }
113  }
114 
115  @Listen("onSelect = #docFlow")
116  public void onSelectDocFlow() {
117  if(docFlow.getObjectValue() != null) {
118  Document doc = new Document();
119  doc.setContract(contract.getObjectValue());
120  doc.setDocumentDefinition(docFlow.getObjectValue());
121  lineType2.setDocument(doc);
122  lineType2.setDisabled(false);
125  store2.setDisabled(false);
126  } else {
127  lineType2.setDisabled(true);
128  store2.setDisabled(true);
129  }
130  }
131 
132  @Listen("onChange = #docDate")
133  public void onChangeDocDate() {
134  docReceipt.setValue(docDate.getValue());
135  }
136 
137  @Listen("onClick = #close")
138  public void onClickClose() {
139  Events.postEvent(new Event(Events.ON_CLOSE, this));
140  }
141 
142  @Listen("onClick = #create")
143  public void onClickCreate() {
144  Framework.setAttribute(this, "docTax", docTax.getNumber());
145  if(contract.getObjectValue() != null &&
146  ctcDef.getObjectValue() != null &&
147  lineType1.getObjectValue() != null &&
148  store1.getObjectValue() != null) {
149  Document doc = new Document();
150  doc.setContract(contract.getObjectValue());
151  doc.setCurrency(doc.getContract().getCurrency());
152  doc.setDocumentDate(docDate.getValue());
153  doc.setDocumentNumber(docNumber.getValue());
154  doc.setReceiptDate(docReceipt.getValue());
156  doc.setDraft(false);
157  DocumentLine nl = new DocumentLine();
158  nl.setConcept(concept);
159  nl.setDiscountMoney(0);
160  nl.setDiscountPerCent(0);
161  nl.setDocument(doc);
162  nl.setLineOrder(1);
163  nl.setLineType(lineType1.getObjectValue());
165  nl.setPrice(docAmount.getDoubleValue() / (1.0 + (docTax.getDoubleValue() / 100.0)));
166  nl.setProduct(null);
167  nl.setProductByContractor(null);
168  nl.setQuantity(0);
169  nl.setStore(store1.getObjectValue());
170  nl.setTax(docTax.getDoubleValue());
172  nl.setRetention(0);
173  doc.getDocumentLines().add(nl);
174  doc = new DocumentWrapper(doc).save(new ArrayList(doc.getDocumentLines()), null);
175  if(docFlow.getObjectValue() != null &&
176  lineType2.getObjectValue() != null &&
177  store2.getObjectValue() != null) {
178  Document expiry = new Document();
179  expiry.setDocumentDefinition(docFlow.getObjectValue());
183  expiry.flowFrom(doc, new DocumentWrapper(doc).getDocDescription(), dw);
184  expiry.setDocumentNumber(doc.getDocumentNumber() + "/1");
185  expiry.setDocumentDate(doc.getDocumentDate());
186  expiry.setReceiptDate(doc.getReceiptDate());
187  DocumentLine dl = expiry.getDocumentLines().iterator().next();
188  dl.setStore(store2.getObjectValue());
189  dl.setLineType(lineType2.getObjectValue());
190  new DocumentWrapper(expiry).save(new ArrayList(expiry.getDocumentLines()), null);
191  }
193  Events.postEvent(new Event(Events.ON_CLOSE, this));
194  }
195  }
196 
197  public QuickDocument(Date date, Double amount, String concept) {
198  this.date = date;
199  this.amount = amount;
200  this.concept = concept;
201  Executions.createComponents("/WEB-INF/_zul/bs/comps/document/quickDocument.zul", this, null);
202  Selectors.wireComponents(this, this, false);
203  Selectors.wireEventListeners(this, this);
204  }
205 
206  @Override
207  public void afterCompose() {
208  setClosable(true);
209  setBorder(true);
210  setWidth("600px");
211  ctcDef.setDisabled(true);
212  lineType1.setDisabled(true);
213  lineType2.setDisabled(true);
214  docFlow.setDisabled(true);
215  store1.setDisabled(true);
216  store2.setDisabled(true);
217  docDate.setValue(date);
218  docReceipt.setValue(date);
219  docTax.setValue((Double) Framework.getAttribute(this, "docTax"));
220  docAmount.setValue(amount);
221  }
222 
223 }
void updateContractDefinition(ContractDefinition contractDefinition)
QuickDocument(Date date, Double amount, String concept)
void setEquivalenceSurcharge(double equivalenceSurcharge)
void setContractPreference(ContractPreference contractPreference)
void setDiscountMoney(double discountMoney)
void setDiscountPerCent(double discountPerCent)
void setProductByContractor(ProductByContractor productByContractor)
void setAncestor(DocumentDefinition ancestor)
void setDescendant(DocumentDefinition descendant)
void setDocumentNumber(String documentNumber)
Definition: Document.java:192
void setDocumentDate(Date documentDate)
Definition: Document.java:163
void setContract(Contract contract)
Definition: Document.java:123
void setCurrency(Currency currency)
Definition: Document.java:135
Set< DocumentLine > getDocumentLines()
Definition: Document.java:180
void setDocumentDefinition(DocumentDefinition documentDefinition)
Definition: Document.java:175
void setReceiptDate(Date receiptDate)
Definition: Document.java:256
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
void flowFrom(Document doc, String header, DocumentWorkflow workflow)
Definition: Document.java:539
ContractPreference getContractPreference()
Definition: LineType.java:77
static Object getAttribute(Object object, String key)
Definition: Framework.java:207
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216