18 package org.turro.financials.document.logic;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.amic.util.date.CheckDate;
27 import org.turro.command.Command;
28 import org.turro.command.Context;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.util.DateFormats;
31 import org.turro.elephant.util.DecimalFormats;
32 import org.turro.elephant.zkoss.Modal;
33 import org.turro.elephant.zkoss.ModalWindow;
34 import org.turro.financials.contract.ContractCombobox;
35 import org.turro.financials.contract.logic.ContractWrapper;
36 import org.turro.financials.db.FinancialsPU;
37 import org.turro.financials.document.action.CloneDocumentAction;
38 import org.turro.financials.entity.*;
39 import org.turro.financials.model.business.CompanyWrapper;
40 import org.turro.financials.model.document.SimpleDocumentLineList;
41 import org.turro.i18n.I_;
42 import org.turro.jpa.Dao;
43 import org.turro.plugin.dossier.IDossier;
44 import org.turro.plugin.dossier.IIssue;
45 import org.turro.plugin.scheduler.ScheduledEdit;
46 import org.turro.util.PhraseBuilder;
47 import org.turro.zkoss.dialog.InputDialog;
48 import org.turro.zkoss.dialog.InputField;
49 import org.turro.zkoss.input.CollectionListbox;
50 import org.turro.zkoss.layout.GridLayout;
51 import org.turro.zul.frame.Framework;
52 import org.zkoss.zk.ui.HtmlBasedComponent;
53 import org.zkoss.zul.Checkbox;
70 return I_.
get(
"Document");
75 pb.addWord(
I_.
get(
"Closing date"));
83 pb.addWord(
I_.
get(
"Closing date"));
95 if(!batchOfs.isEmpty()) {
96 pb.addWord(
I_.
get(
"Can't delete") +
":\n\n");
98 pb.addWord(
new DocumentWrapper(b.getBatch()).getFullDescription() +
"\n");
106 return entity.getDocumentDefinition().getName() +
": " +
107 (
entity.getForcedView() ==
null ?
"" :
"(" +
entity.getForcedView().getName() +
") ") +
108 entity.getDocumentNumber() +
" " +
119 return entity.getContract().getFullDescription() +
"\n" +
122 }
catch(Exception ex) {
132 new InputField(
"Contract", null, null, 0) {
134 protected HtmlBasedComponent createEditor() {
135 ContractCombobox ccb = new ContractCombobox();
136 ccb.setOnlyActive(true);
137 ccb.setDocumentDefinition(entity.getDocumentDefinition());
138 ccb.setObjectValue(entity.getContract());
144 public Object execute(Context context) {
146 if(fields.length > 0) {
148 if(
"Contract".
equals(f.getLabel())) {
149 context.put(
"contract", f.getValue());
150 if(command !=
null) command.execute(context);
162 Context ctx =
new Context();
163 ctx.put(
"entity", entity);
165 }
catch (Exception ex) {
183 List<Document> docs = dao.getResultList(
184 "select doc from Document as doc " +
185 "where doc.documentNumber = ? " +
186 "and doc.documentDefinition = ? " +
187 "and doc.contract = ? " +
188 "and year(doc.documentDate) = ? " +
191 entity.getDocumentNumber(),
192 entity.getDocumentDefinition(),
193 entity.getContract(),
194 new CheckDate(entity.getDocumentDate()).getYear(),
197 if(!docs.isEmpty()) {
198 pb.addWord(
I_.
get(
"Posible duplicates, save anyway?"));
212 HashMap args =
new HashMap();
213 List<Document> list = getRelatedAncestor(documentDefinition);
214 args.put(
"relatedDoc", list);
215 args.put(
"mode",
"descendant");
219 public Object execute(Context context) {
222 addRelation(doc,
true, rels.
getResult(), getSuitableWorkflow(documentDefinition));
224 if(command !=
null) command.execute(
null);
232 HashMap args =
new HashMap();
233 List<Document> list = getRelatedDescendant(documentDefinition);
234 args.put(
"relatedDoc", list);
235 args.put(
"mode",
"ancestor");
239 public Object execute(Context context) {
242 addRelation(doc,
false, rels.
getResult(), getSuitableWorkflow(documentDefinition));
244 if(command !=
null) command.execute(
null);
256 entity.getAncestors().add(rel);
259 entity.appendLines(relDoc,
new DocumentWrapper(relDoc).getDocDescription(), dw);
260 }
else if(mode == 3) {
262 entity.appendAmounts(relDoc,
new DocumentWrapper(relDoc).getDocDescription(), dw);
267 entity.getDescendants().add(rel);
284 if(entity.getId() > 0) {
297 private Checkbox draft =
null;
304 protected String convertToString(String v) {
308 actions.setMold(
"select");
309 actions.
setCollection(Arrays.asList(
new String[] { I_.get(
"Clone document") }));
311 if(data.contains(
":clone")) {
318 draft =
new Checkbox(
I_.
get(
"Draft"));
319 draft.setChecked(data ==
null || data.contains(
":draft"));
327 String data =
"action";
331 if(draft.isChecked()) {
static String logMsg(String msg)
static int doModal(String file)
static ModalWindow getModal(String file)
static String getObjectPath(Object object)
Object execute(Context context)
void changeContract(final Command command)
boolean checkSave(PhraseBuilder pb)
String getDataEditorValue()
String getFullDescription()
boolean checkBatchs(PhraseBuilder pb)
DocumentWorkflow getSuitableWorkflow(DocumentDefinition docDef)
boolean checkDuplicates(PhraseBuilder pb)
Object getDataEditor(String data)
String getDocDescription()
DocumentWrapper(Document document)
void relateAncestors(final DocumentDefinition documentDefinition, final Command command)
void relateDescendants(final DocumentDefinition documentDefinition, final Command command)
static Collection< BatchOf > getFrom(Document document)
Set< DocumentWorkflow > getDocumentWorkflows()
void setDescendant(Document descendant)
void setAncestor(Document ancestor)
DocumentDefinition getDescendant()
ContractDefinition getContractDefinition()
DocumentDefinition getAncestor()
static boolean isValidDate(Date date)
static Date getCompanyClosingDate()
void addLines(Document document)
static String get(String msg)
boolean equals(Object obj)
GridLayout addComponent(HtmlBasedComponent comp)
GridLayout addCaption(String label)
static FrameClipboard getClipboard()
static Framework getCurrent()
void setDescription(String description)
void setPath(String path)