18 package org.turro.financials.document;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.string.Strings;
24 import org.turro.collections.CollectionUtil;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.financials.contract.ContractListbox;
27 import org.turro.financials.contract.logic.ContractWrapper;
28 import org.turro.financials.document.logic.DocumentDefinitionWrapper;
29 import org.turro.financials.entity.*;
30 import org.turro.financials.linetype.LineTypePreferenceListbox;
31 import org.turro.financials.model.contract.ContractUsualSet;
32 import org.turro.financials.model.document.DocumentDefinitionUsualSet;
33 import org.turro.financials.model.document.SingleLineDocumentWrapper;
34 import org.turro.financials.model.product.ProductWrapper;
35 import org.turro.financials.product.ProductByContractorCombobox;
36 import org.turro.financials.product.ProductCombobox;
37 import org.turro.i18n.I_;
38 import org.turro.usual.UsualUsages;
39 import org.turro.zkoss.grid.CollectionGrid;
40 import org.turro.zkoss.grid.EditableCell;
41 import org.turro.zkoss.grid.EditableColumn;
42 import org.zkoss.zk.ui.HtmlBasedComponent;
43 import org.zkoss.zk.ui.event.Event;
44 import org.zkoss.zk.ui.event.Events;
45 import org.zkoss.zul.Row;
54 private Collection<DocumentDefinition> expiryDefinitions;
55 private final Map<DocumentDefinition, Contract> lastStoreMap =
new HashMap<>();
57 private final Map<Long, Collection<Contract>> storeMap =
new HashMap<>();
65 ArrayList<DocumentRelation> list =
new ArrayList<>();
67 list.add(sldw.getRelation());
77 this.document = document;
80 private void updateDocument() {
82 if(document ==
null || document.
getContract() ==
null) {
87 expiryDefinitions =
new DocumentDefinitionUsualSet(expiryDefinitions, document.
getUsualPath() +
"df:");
88 Iterator<DocumentDefinition> it = expiryDefinitions.iterator();
89 while (it.hasNext()) {
95 if(stores.isEmpty()) {
104 storeMap.put(dd.
getId(), stores);
105 lastStoreMap.put(dd, CollectionUtil.from(stores).first());
106 if(lastDocDef ==
null) {
114 Events.postEvent(
new Event(Events.ON_CHANGE,
this));
125 super.afterCompose();
131 if(value ==
null && expiryDefinitions !=
null && !expiryDefinitions.isEmpty()) {
151 return v !=
null && v.
isValid();
156 if(expiryDefinitions !=
null && !expiryDefinitions.isEmpty()) {
161 }
catch (ClassNotFoundException ex) {
167 super.afterCompose();
175 }
else if(value instanceof
Product) {
181 }
else if(value instanceof
LineType) {
184 }
else if(value instanceof
Contract) {
188 return super.formatCell(editableCell, value);
203 ddl.setMold(
"select");
224 ltl.setMold(
"select");
235 slb.setMold(
"select");
248 sldw.
setPrice(getCurrentDifference());
250 return super.createEditor(editableCell);
253 return super.createEditor(editableCell);
258 super.cellChanged(editableCell, value);
269 }
else if(value instanceof
Contract) {
275 private void addColumns() throws ClassNotFoundException {
276 int fractionDigits = document.
getCurrency().getDefaultFractionDigits();
277 if(expiryDefinitions.size() > 1) {
279 "expiryDefinition",
null, 0,
false,
false).setWidth(
"280px");
282 "documentDate",
null, 0,
true,
false).setWidth(
"100px");
283 addColumn(I_.get(
"Number"), String.class,
284 "documentNumber",
null, 0,
false,
false).setWidth(
"100px");
288 if(ProductWrapper.hasAvailableContractorProducts(document.
getContract())) {
290 "productByContractor",
null, 0,
false,
false).setHflex(
"10");
293 if(ProductWrapper.hasAvailableProducts()) {
295 "product",
null, 0,
false,
false).setHflex(
"10");
299 addColumn(I_.get(
"Concept"), String.class,
300 "concept",
null, 0,
false,
false).setHflex(
"10");
303 "quantity",
null, 3,
false,
false).setHflex(
"3");
306 "price",
null, fractionDigits,
false,
false).setHflex(
"4");
309 "discountMoney",
null, fractionDigits,
false,
false).setHflex(
"2");
312 "discountPerCent",
null, 0,
false,
false).setHflex(
"2");
315 "tax",
null, 2,
false,
false).setHflex(
"2");
318 "subtotal",
null, fractionDigits,
false,
true).setHflex(
"4");
323 "store",
null, 0,
false,
false).setHflex(
"5");
327 "lineType",
null, 0,
false,
false).setHflex(
"5");
331 private Collection<RelatedColumn> getDocumentColumns() {
332 return expiryDefinitions.iterator().next().getDocumentColumns();
335 private Double getCurrentDifference() {
337 for(SingleLineDocumentWrapper sldw :
getValues()) {
338 total += sldw.getTotal();
static String logMsg(String msg)
void setObjectValue(String value)
void setDocumentDefinition(DocumentDefinition documentDefinition)
boolean isValid(SingleLineDocumentWrapper v)
void initiateRow(Row row, SingleLineDocumentWrapper value)
boolean deleteRow(Row row)
void cellChanged(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
Collection< DocumentRelation > getRelations()
String formatCell(EditableCell editableCell, Object value)
void setDocument(Document document)
String getPartialDescription()
boolean isUseContractorCode()
RegisterView getForcedView()
Set< DocumentRelation > getDescendants()
String getDocumentNumber()
Set< DocumentRelation > getUpdatedDescendants()
DocumentDefinition getDocumentDefinition()
String getContractorCode()
String getProductCodeStr()
void addAdvanceIfNeeded(RegisterView view, Collection< Contract > contracts)
static void clearInactives(Collection< Contract > contracts)
Collection< DocumentDefinition > getExpiryDefinitions(DocumentDefinition source)
Collection< Contract > getRelatedStores(Contract contract)
static Collection< SingleLineDocumentWrapper > adapt(Document source, Collection< DocumentRelation > relations)
void setStore(Contract store)
void setLineType(LineType lineType)
void setPrice(double price)
DocumentDefinition getExpiryDefinition()
void setDocumentNumber(String documentNumber)
void setExpiryDefinition(DocumentDefinition expiryDefinition)
static String get(String msg)
static String getMostUsedvalue(String path)
void setCollection(Collection< V > collection)
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)
void setReadOnly(boolean readOnly)