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;
|
|
|
19 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
21 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
22 |
import org.openconcerto.sql.users.UserManager;
|
|
|
23 |
import org.openconcerto.utils.GestionDevise;
|
|
|
24 |
|
|
|
25 |
import java.text.DateFormat;
|
|
|
26 |
import java.text.SimpleDateFormat;
|
|
|
27 |
import java.util.ArrayList;
|
|
|
28 |
import java.util.Collection;
|
|
|
29 |
import java.util.Date;
|
|
|
30 |
import java.util.List;
|
|
|
31 |
|
|
|
32 |
import org.jdom.Element;
|
|
|
33 |
|
|
|
34 |
public class OOXMLElement {
|
|
|
35 |
protected Element elt;
|
|
|
36 |
protected SQLElement sqlElt;
|
|
|
37 |
protected int id;
|
|
|
38 |
protected SQLRowAccessor row = null;
|
19 |
ilm |
39 |
protected SQLRow rowLanguage;
|
18 |
ilm |
40 |
|
19 |
ilm |
41 |
public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRow rowLanguage) {
|
18 |
ilm |
42 |
this.elt = elt;
|
|
|
43 |
this.sqlElt = sqlElt;
|
|
|
44 |
this.id = id;
|
19 |
ilm |
45 |
this.rowLanguage = rowLanguage;
|
18 |
ilm |
46 |
}
|
|
|
47 |
|
19 |
ilm |
48 |
public OOXMLElement(Element elt, SQLElement sqlElt, int id, SQLRowAccessor row, SQLRow rowLanguage) {
|
18 |
ilm |
49 |
this.elt = elt;
|
|
|
50 |
this.sqlElt = sqlElt;
|
|
|
51 |
this.id = id;
|
|
|
52 |
this.row = row;
|
19 |
ilm |
53 |
this.rowLanguage = rowLanguage;
|
18 |
ilm |
54 |
}
|
|
|
55 |
|
|
|
56 |
public Object getValue() {
|
|
|
57 |
Object res = "";
|
|
|
58 |
|
|
|
59 |
final String attributeValue = this.elt.getAttributeValue("type");
|
|
|
60 |
|
|
|
61 |
if (attributeValue.equalsIgnoreCase("InitialesUtilisateur")) {
|
|
|
62 |
return getInitialesUser();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
if (attributeValue.equalsIgnoreCase("InitialesUtilisateurModif")) {
|
|
|
66 |
return getInitialesUserModify();
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
if (attributeValue.equalsIgnoreCase("InitialesUtilisateurCreate")) {
|
|
|
70 |
return getInitialesUserCreate();
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
if (attributeValue.equalsIgnoreCase("TotalHTTable")) {
|
|
|
74 |
return getTotalHTTable(row);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
if (attributeValue.equalsIgnoreCase("DateEcheance")) {
|
|
|
78 |
int idModeReglement = row.getInt("ID_MODE_REGLEMENT");
|
|
|
79 |
Date d = (Date) row.getObject("DATE");
|
61 |
ilm |
80 |
return getDateEcheance(idModeReglement, d, this.elt.getAttributeValue("DatePattern"));
|
18 |
ilm |
81 |
}
|
|
|
82 |
|
|
|
83 |
final List<Element> eltFields = this.elt.getChildren("field");
|
|
|
84 |
|
|
|
85 |
if (eltFields != null) {
|
|
|
86 |
if (eltFields.size() > 1) {
|
|
|
87 |
String result = "";
|
|
|
88 |
for (Element eltField : eltFields) {
|
|
|
89 |
|
19 |
ilm |
90 |
OOXMLField field = new OOXMLField(eltField, this.row, this.sqlElt, this.id, this.rowLanguage);
|
18 |
ilm |
91 |
|
|
|
92 |
Object value = field.getValue();
|
|
|
93 |
if (value != null) {
|
|
|
94 |
result += value.toString() + " ";
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
res = result;
|
|
|
98 |
} else {
|
19 |
ilm |
99 |
OOXMLField field = new OOXMLField(eltFields.get(0), this.row, this.sqlElt, this.id, this.rowLanguage);
|
18 |
ilm |
100 |
res = field.getValue();
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
return res;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
private String getInitialesUserModify() {
|
|
|
107 |
|
|
|
108 |
SQLRowAccessor rowUser = this.row.getForeign("ID_USER_COMMON_MODIFY");
|
|
|
109 |
String s = rowUser.getString("NOM");
|
|
|
110 |
String s2 = rowUser.getString("PRENOM");
|
|
|
111 |
|
|
|
112 |
StringBuffer result = new StringBuffer(4);
|
|
|
113 |
if (s2 != null && s2.trim().length() > 0) {
|
|
|
114 |
result.append(s2.charAt(0));
|
|
|
115 |
}
|
|
|
116 |
if (s != null && s.trim().length() > 0) {
|
|
|
117 |
result.append(s.charAt(0));
|
|
|
118 |
}
|
|
|
119 |
return result.toString();
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
private String getInitialesUserCreate() {
|
|
|
123 |
SQLRowAccessor rowUser = this.row.getForeign("ID_USER_COMMON_CREATE");
|
|
|
124 |
String s = rowUser.getString("NOM");
|
|
|
125 |
String s2 = rowUser.getString("PRENOM");
|
|
|
126 |
|
|
|
127 |
StringBuffer result = new StringBuffer(4);
|
|
|
128 |
if (s2 != null && s2.trim().length() > 0) {
|
|
|
129 |
result.append(s2.charAt(0));
|
|
|
130 |
}
|
|
|
131 |
if (s != null && s.trim().length() > 0) {
|
|
|
132 |
result.append(s.charAt(0));
|
|
|
133 |
}
|
|
|
134 |
return result.toString();
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
private String getInitialesUser() {
|
|
|
138 |
|
|
|
139 |
String s = UserManager.getInstance().getCurrentUser().getLastName();
|
|
|
140 |
String s2 = UserManager.getInstance().getCurrentUser().getName();
|
|
|
141 |
|
|
|
142 |
StringBuffer result = new StringBuffer(4);
|
|
|
143 |
if (s2 != null && s2.trim().length() > 0) {
|
|
|
144 |
result.append(s2.charAt(0));
|
|
|
145 |
}
|
|
|
146 |
if (s != null && s.trim().length() > 0) {
|
|
|
147 |
result.append(s.charAt(0));
|
|
|
148 |
}
|
|
|
149 |
return result.toString();
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
public static DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
154 |
|
|
|
155 |
protected String getStringProposition(SQLRowAccessor rowProp) {
|
|
|
156 |
|
|
|
157 |
return "Notre proposition " + rowProp.getString("NUMERO") + " du " + format.format(rowProp.getObject("DATE"));
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
public Double getTotalHTTable(SQLRowAccessor rowFact) {
|
|
|
162 |
|
|
|
163 |
SQLTable tableElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
164 |
Collection<? extends SQLRowAccessor> set = rowFact.getReferentRows(tableElt);
|
|
|
165 |
long total = 0;
|
|
|
166 |
for (SQLRowAccessor row : set) {
|
|
|
167 |
total += row.getLong("T_PV_HT");
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
return new Double(GestionDevise.currencyToString(total, false));
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
/**
|
|
|
175 |
* Calcul la date d'échéance d'un élément par rapport au mode de reglement et à la date
|
|
|
176 |
* d'émission
|
|
|
177 |
*
|
|
|
178 |
* @param idModeRegl
|
|
|
179 |
* @param currentDate
|
61 |
ilm |
180 |
* @return la date d'échéance au format dd/MM/yy si datePattern !=null sinon une Date
|
18 |
ilm |
181 |
*/
|
61 |
ilm |
182 |
protected Object getDateEcheance(int idModeRegl, Date currentDate, String datePattern) {
|
18 |
ilm |
183 |
SQLElement eltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
|
|
|
184 |
SQLRow row = eltModeRegl.getTable().getRow(idModeRegl);
|
|
|
185 |
int aJ = row.getInt("AJOURS");
|
|
|
186 |
int nJ = row.getInt("LENJOUR");
|
|
|
187 |
if (aJ + nJ == 0) {
|
|
|
188 |
if (row.getBoolean("DATE_FACTURE")) {
|
|
|
189 |
return Configuration.getInstance().getTranslator().getLabelFor(row.getTable().getField("DATE_FACTURE"));
|
|
|
190 |
} else {
|
|
|
191 |
return " ";
|
|
|
192 |
}
|
|
|
193 |
}
|
61 |
ilm |
194 |
Date calculDate = ModeDeReglementSQLElement.calculDate(aJ, nJ, currentDate);
|
|
|
195 |
if (datePattern != null && datePattern.trim().length() > 0) {
|
|
|
196 |
final DateFormat format2 = new SimpleDateFormat(datePattern);
|
|
|
197 |
return format2.format(calculDate);
|
|
|
198 |
} else {
|
|
|
199 |
return calculDate;
|
|
|
200 |
}
|
18 |
ilm |
201 |
}
|
|
|
202 |
|
|
|
203 |
public boolean isTypeReplace() {
|
|
|
204 |
// remplacement d'un pattern contenu dans la cellule
|
|
|
205 |
return this.elt.getAttributeValue("type").equalsIgnoreCase("Replace");
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
public String getReplacePattern() {
|
|
|
209 |
return this.elt.getAttributeValue("replacePattern");
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
public boolean isMultilineAuto() {
|
|
|
213 |
// gestion manuel du multiligne
|
|
|
214 |
final String multiLineValue = this.elt.getAttributeValue("controleMultiline");
|
|
|
215 |
return (multiLineValue == null) ? true : !multiLineValue.equalsIgnoreCase("false");
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
}
|