18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.generationDoc;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
|
|
|
17 |
import org.openconcerto.sql.Configuration;
|
|
|
18 |
import org.openconcerto.sql.element.SQLElement;
|
80 |
ilm |
19 |
import org.openconcerto.sql.model.SQLField;
|
18 |
ilm |
20 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
80 |
ilm |
22 |
import org.openconcerto.sql.model.SQLSelect;
|
18 |
ilm |
23 |
import org.openconcerto.sql.model.SQLTable;
|
80 |
ilm |
24 |
import org.openconcerto.sql.model.Where;
|
18 |
ilm |
25 |
import org.openconcerto.utils.GestionDevise;
|
|
|
26 |
|
|
|
27 |
import java.text.DateFormat;
|
|
|
28 |
import java.text.SimpleDateFormat;
|
|
|
29 |
import java.util.ArrayList;
|
|
|
30 |
import java.util.Collection;
|
|
|
31 |
import java.util.Date;
|
|
|
32 |
import java.util.List;
|
|
|
33 |
|
132 |
ilm |
34 |
import org.jdom2.Attribute;
|
|
|
35 |
import org.jdom2.Element;
|
18 |
ilm |
36 |
|
|
|
37 |
public class OOXMLElement {
|
|
|
38 |
protected Element elt;
|
|
|
39 |
protected SQLElement sqlElt;
|
|
|
40 |
protected int id;
|
63 |
ilm |
41 |
protected SQLRowAccessor row;
|
19 |
ilm |
42 |
protected SQLRow rowLanguage;
|
63 |
ilm |
43 |
protected OOXMLCache cache;
|
18 |
ilm |
44 |
|
63 |
ilm |
45 |
public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRow rowLanguage, OOXMLCache cache) {
|
|
|
46 |
this(elt, sqlElt, id, null, rowLanguage, cache);
|
|
|
47 |
|
18 |
ilm |
48 |
}
|
|
|
49 |
|
63 |
ilm |
50 |
public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRowAccessor row, SQLRow rowLanguage, OOXMLCache cache) {
|
18 |
ilm |
51 |
this.elt = elt;
|
|
|
52 |
this.sqlElt = sqlElt;
|
|
|
53 |
this.id = id;
|
|
|
54 |
this.row = row;
|
19 |
ilm |
55 |
this.rowLanguage = rowLanguage;
|
63 |
ilm |
56 |
this.cache = cache;
|
18 |
ilm |
57 |
}
|
|
|
58 |
|
|
|
59 |
public Object getValue() {
|
|
|
60 |
Object res = "";
|
|
|
61 |
|
63 |
ilm |
62 |
final String type = this.elt.getAttributeValue("type");
|
|
|
63 |
SpreadSheetCellValueProvider provider = SpreadSheetCellValueProviderManager.get(type);
|
|
|
64 |
if (provider != null) {
|
|
|
65 |
final SpreadSheetCellValueContext context = new SpreadSheetCellValueContext(this.row);
|
|
|
66 |
List<Attribute> attrs = this.elt.getAttributes();
|
|
|
67 |
for (Attribute attr : attrs) {
|
|
|
68 |
context.put(attr.getName(), attr.getValue());
|
|
|
69 |
}
|
67 |
ilm |
70 |
res = provider.getValue(context);
|
|
|
71 |
} else
|
18 |
ilm |
72 |
|
63 |
ilm |
73 |
if (type.equalsIgnoreCase("TotalHTTable")) {
|
67 |
ilm |
74 |
res = getTotalHTTable(row);
|
80 |
ilm |
75 |
} else if (type.equalsIgnoreCase("sql.function")) {
|
|
|
76 |
String field = this.elt.getAttributeValue("field");
|
|
|
77 |
String table = this.elt.getAttributeValue("table");
|
|
|
78 |
String function = this.elt.getAttributeValue("function");
|
|
|
79 |
SQLTable referentTable = this.row.getTable().getTable(table);
|
|
|
80 |
return getFromSQLFunction(referentTable.getField(field), function);
|
67 |
ilm |
81 |
} else if (type.equalsIgnoreCase("DateEcheance")) {
|
18 |
ilm |
82 |
int idModeReglement = row.getInt("ID_MODE_REGLEMENT");
|
|
|
83 |
Date d = (Date) row.getObject("DATE");
|
67 |
ilm |
84 |
res = getDateEcheance(idModeReglement, d, this.elt.getAttributeValue("datePattern"));
|
|
|
85 |
} else {
|
18 |
ilm |
86 |
|
67 |
ilm |
87 |
final List<Element> eltFields = this.elt.getChildren("field");
|
18 |
ilm |
88 |
|
73 |
ilm |
89 |
if (eltFields != null && !eltFields.isEmpty()) {
|
67 |
ilm |
90 |
if (eltFields.size() > 1) {
|
|
|
91 |
String result = "";
|
|
|
92 |
for (Element eltField : eltFields) {
|
18 |
ilm |
93 |
|
67 |
ilm |
94 |
OOXMLField field = new OOXMLField(eltField, this.row, this.sqlElt, this.id, this.rowLanguage, cache);
|
18 |
ilm |
95 |
|
67 |
ilm |
96 |
Object value = field.getValue();
|
|
|
97 |
if (value != null) {
|
|
|
98 |
result += value.toString() + " ";
|
|
|
99 |
}
|
18 |
ilm |
100 |
}
|
67 |
ilm |
101 |
res = result;
|
|
|
102 |
} else {
|
|
|
103 |
OOXMLField field = new OOXMLField(eltFields.get(0), this.row, this.sqlElt, this.id, this.rowLanguage, cache);
|
|
|
104 |
res = field.getValue();
|
18 |
ilm |
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|
67 |
ilm |
108 |
|
|
|
109 |
// Liste des valeurs à ne pas afficher
|
|
|
110 |
List<String> listOfExcludedValues = null;
|
|
|
111 |
|
|
|
112 |
List<Element> excludeValue = this.elt.getChildren("exclude");
|
|
|
113 |
if (excludeValue != null && excludeValue.size() > 0) {
|
|
|
114 |
|
|
|
115 |
listOfExcludedValues = new ArrayList<String>();
|
|
|
116 |
|
|
|
117 |
for (Element element : excludeValue) {
|
|
|
118 |
String attributeValue = element.getAttributeValue("value");
|
|
|
119 |
listOfExcludedValues.add(attributeValue);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
if (res != null && listOfExcludedValues != null && listOfExcludedValues.contains(res.toString())) {
|
|
|
124 |
res = null;
|
|
|
125 |
}
|
|
|
126 |
|
132 |
ilm |
127 |
final String k = this.elt.getAttributeValue("removeBreakLine");
|
|
|
128 |
boolean rmBreakLines = (k == null) ? false : k.equalsIgnoreCase("true");
|
|
|
129 |
if (rmBreakLines) {
|
|
|
130 |
res = (res == null ? res : res.toString().replaceAll("\n", ","));
|
|
|
131 |
}
|
18 |
ilm |
132 |
return res;
|
|
|
133 |
}
|
|
|
134 |
|
80 |
ilm |
135 |
private Object getFromSQLFunction(SQLField field, String function) {
|
|
|
136 |
SQLSelect sel = new SQLSelect();
|
|
|
137 |
sel.addSelect(field, function);
|
|
|
138 |
Where w = new Where(field.getTable().getField("ID_" + this.row.getTable().getName()), "=", this.row.getID());
|
|
|
139 |
sel.setWhere(w);
|
|
|
140 |
return Configuration.getInstance().getBase().getDataSource().executeScalar(sel.asString());
|
|
|
141 |
}
|
18 |
ilm |
142 |
|
80 |
ilm |
143 |
|
132 |
ilm |
144 |
public DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
18 |
ilm |
145 |
|
|
|
146 |
protected String getStringProposition(SQLRowAccessor rowProp) {
|
|
|
147 |
|
|
|
148 |
return "Notre proposition " + rowProp.getString("NUMERO") + " du " + format.format(rowProp.getObject("DATE"));
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
public Double getTotalHTTable(SQLRowAccessor rowFact) {
|
|
|
153 |
|
|
|
154 |
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
155 |
Collection<? extends SQLRowAccessor> set = rowFact.getReferentRows(tableElt);
|
|
|
156 |
long total = 0;
|
|
|
157 |
for (SQLRowAccessor row : set) {
|
|
|
158 |
total += row.getLong("T_PV_HT");
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
return new Double(GestionDevise.currencyToString(total, false));
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* Calcul la date d'échéance d'un élément par rapport au mode de reglement et à la date
|
|
|
167 |
* d'émission
|
|
|
168 |
*
|
|
|
169 |
* @param idModeRegl
|
|
|
170 |
* @param currentDate
|
61 |
ilm |
171 |
* @return la date d'échéance au format dd/MM/yy si datePattern !=null sinon une Date
|
18 |
ilm |
172 |
*/
|
61 |
ilm |
173 |
protected Object getDateEcheance(int idModeRegl, Date currentDate, String datePattern) {
|
18 |
ilm |
174 |
SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
|
|
|
175 |
SQLRow row = eltModeRegl.getTable().getRow(idModeRegl);
|
|
|
176 |
int aJ = row.getInt("AJOURS");
|
|
|
177 |
int nJ = row.getInt("LENJOUR");
|
|
|
178 |
if (aJ + nJ == 0) {
|
|
|
179 |
if (row.getBoolean("DATE_FACTURE")) {
|
|
|
180 |
return Configuration.getInstance().getTranslator().getLabelFor(row.getTable().getField("DATE_FACTURE"));
|
|
|
181 |
} else {
|
|
|
182 |
return " ";
|
|
|
183 |
}
|
|
|
184 |
}
|
61 |
ilm |
185 |
Date calculDate = ModeDeReglementSQLElement.calculDate(aJ, nJ, currentDate);
|
|
|
186 |
if (datePattern != null && datePattern.trim().length() > 0) {
|
|
|
187 |
final DateFormat format2 = new SimpleDateFormat(datePattern);
|
|
|
188 |
return format2.format(calculDate);
|
|
|
189 |
} else {
|
|
|
190 |
return calculDate;
|
|
|
191 |
}
|
18 |
ilm |
192 |
}
|
|
|
193 |
|
|
|
194 |
public boolean isTypeReplace() {
|
|
|
195 |
// remplacement d'un pattern contenu dans la cellule
|
|
|
196 |
return this.elt.getAttributeValue("type").equalsIgnoreCase("Replace");
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public String getReplacePattern() {
|
|
|
200 |
return this.elt.getAttributeValue("replacePattern");
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public boolean isMultilineAuto() {
|
|
|
204 |
// gestion manuel du multiligne
|
|
|
205 |
final String multiLineValue = this.elt.getAttributeValue("controleMultiline");
|
|
|
206 |
return (multiLineValue == null) ? true : !multiLineValue.equalsIgnoreCase("false");
|
|
|
207 |
}
|
|
|
208 |
|
132 |
ilm |
209 |
public boolean isKeepingEmptyLines() {
|
|
|
210 |
// gestion manuel du multiligne
|
|
|
211 |
final String k = this.elt.getAttributeValue("keepEmptyLines");
|
|
|
212 |
return (k == null) ? false : k.equalsIgnoreCase("true");
|
|
|
213 |
}
|
|
|
214 |
|
18 |
ilm |
215 |
}
|