19 package org.turro.financials.document.logic;
21 import java.util.Collection;
22 import java.util.List;
23 import org.turro.command.Command;
24 import org.turro.command.Context;
25 import org.turro.command.LabelControl;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.util.DecimalFormats;
28 import org.turro.elephant.util.Images;
29 import org.turro.elephant.util.Messages;
30 import org.turro.financials.batchof.BatchOfGrid;
31 import org.turro.financials.contract.ContractCombobox;
32 import org.turro.financials.contract.ContractInfo;
33 import org.turro.financials.db.FinancialsPU;
34 import org.turro.financials.document.DocumentDefinitionListbox;
35 import org.turro.financials.document.DocumentExpiriesGrid;
36 import org.turro.financials.document.DocumentLinesGrid;
37 import org.turro.financials.document.DocumentRegistersGrid;
38 import org.turro.financials.document.DocumentReport;
39 import org.turro.financials.document.DocumentSummaryGrid;
40 import org.turro.financials.document.contract.DocumentContractFlowListbox;
41 import org.turro.financials.document.process.DocumentProcessListbox;
42 import org.turro.financials.entity.Contract;
43 import org.turro.financials.entity.ContractFlow;
44 import org.turro.financials.entity.Document;
45 import org.turro.financials.entity.DocumentRelation;
46 import org.turro.financials.menu.FinancialsMenu;
47 import org.turro.financials.relation.RelationshipViewer;
48 import org.turro.i18n.I_;
49 import org.turro.jpa.composer.EntityComposer;
50 import org.turro.jpa.entity.DaoEntity;
51 import org.turro.math.Zero;
52 import org.turro.reflection.XMLSerializer;
53 import org.turro.util.PhraseBuilder;
54 import org.turro.zul.acceptance.AcceptanceButton;
55 import org.turro.zul.frame.Framework;
56 import org.zkoss.zk.ui.Component;
57 import org.zkoss.zk.ui.select.annotation.Listen;
58 import org.zkoss.zk.ui.select.annotation.Wire;
59 import org.zkoss.zul.Label;
60 import org.zkoss.zul.Row;
61 import org.zkoss.zul.Tab;
62 import org.zkoss.zul.Toolbarbutton;
80 private Toolbarbutton properties;
92 private Tab tabexpiries;
94 @Wire(
"#tabrelations")
95 private Tab tabrelations;
98 private Tab tabbatchof;
100 @Wire(
"#tabregister")
101 private Tab tabregister;
113 private Label tadvance;
116 private Label ladvance;
145 @Listen(
"onSelect = #tablines")
150 @Listen(
"onSelect = #tabexpiries")
155 updateExpiriesOptions();
158 @Listen(
"onSelect = #tabrelations")
163 @Listen(
"onSelect = #tabbatchof")
168 @Listen(
"onSelect = #tabregister")
173 @Listen(
"onSelect = #lbflow")
182 @Listen(
"onChange = #contract")
194 updateExpiriesOptions();
202 @Listen(
"onSelect = #lbCtcDef")
209 @Listen(
"onSelect = #docProcess")
216 @Listen(
"onClick = #properties")
221 public Object execute(Context context) {
227 updateExpiriesOptions();
233 @Listen(
"onChange = #lines")
238 @Listen(
"onChange = #relations")
244 @Listen(
"onClick = #clone")
250 @Listen(
"onClick = #copyLines")
256 @Listen(
"onClick = #pasteLines")
264 @Listen(
"onClick = #appendRow")
269 @Listen(
"onClick = #insertRow")
277 @Listen(
"onClick = #deleteRow")
294 entity.setDocumentDate(
new java.util.Date());
313 return super.beforeSave() && !acceptance.
isBlocked();
320 return super.beforeSave() && (acceptance ==
null || !acceptance.
isBlocked());
326 PhraseBuilder pb =
new PhraseBuilder();
329 if(wrongDate || batchs) {
337 pb.addWord(
I_.
get(
"Proceed anyway"));
350 PhraseBuilder pb =
new PhraseBuilder();
353 if(wrongDate || duplicates) {
358 pb.addWord(
I_.
get(
"Proceed anyway"));
378 return !
entity.isEmpty() && (
entity.getId() == 0) || super.shouldBeSaved();
385 acceptance.setVisible(
false);
386 entInf.setVisible(
false);
387 properties.setVisible(
false);
389 contract.setVisible(
false);
399 updateExpiriesOptions();
404 reportsend.setTooltiptext(
I_.
get(
"Send documents"));
417 private String expiriesXML =
"";
421 super.retrieveEntity();
423 if(dr.getDescendant().isValid()) {
424 expiriesXML +=
new XMLSerializer(dr.getDescendant()).data();
444 private void updateExpiriesOptions() {
448 tadvance.setVisible(
true);
449 ladvance.setVisible(
true);
452 tadvance.setVisible(
false);
453 ladvance.setVisible(
false);
455 Collection<ContractFlow> cfs =
entity.getContractFlows();
456 if(cfs ==
null || cfs.isEmpty()) {
457 tflow.setVisible(
false);
458 lbflow.setVisible(
false);
463 tflow.setVisible(
true);
464 lbflow.setVisible(
true);
void setEntity(Object entity)
boolean isInRole(String role)
static Application getApplication()
static String getImage(String image)
static Messages question()
Messages add(String word)
void setContract(Contract contract)
void setContractDefinition(ContractDefinition contractDefinition)
void updateContractDefinition(ContractDefinition contractDefinition)
Collection< DocumentRelation > getRelations()
void updateDocument(Document document)
void setGrid(DocumentLinesGrid grid)
void setDocument(Document document)
String getAttributeName()
void onDocumentDefinitionChange()
Document getEntityInstance(Long id)
DaoEntity getWrapperInstance(Component comp)
void changeContract(final Command command)
boolean checkSave(PhraseBuilder pb)
boolean checkBatchs(PhraseBuilder pb)
boolean checkDuplicates(PhraseBuilder pb)
void doProcess(Document document)
void setDocument(Document document)
void generateFlows(Document document)
void setPriorSavingValues(List< DocumentLine > lines, List< DocumentRelation > descendants)
static String get(String msg)
static boolean near(double value, int digits)
Collection< V > getCollection()
void insertInSelectedRow(Row row)
static Framework getCurrent()
void setSelectedLabel(String text)
void setSelectedTooltiptext(String text)