180 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
180 |
ilm |
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.core.sales.invoice.report;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
17 |
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
|
|
|
18 |
import org.openconcerto.erp.preferences.PrinterNXProps;
|
|
|
19 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
20 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
21 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
22 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
23 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
|
|
24 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
25 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
26 |
import org.openconcerto.sql.model.Where;
|
|
|
27 |
import org.openconcerto.utils.cc.ITransformer;
|
|
|
28 |
|
|
|
29 |
import java.math.BigDecimal;
|
|
|
30 |
import java.text.DateFormat;
|
|
|
31 |
import java.text.SimpleDateFormat;
|
|
|
32 |
import java.util.ArrayList;
|
|
|
33 |
import java.util.Calendar;
|
182 |
ilm |
34 |
import java.util.Collections;
|
|
|
35 |
import java.util.Comparator;
|
180 |
ilm |
36 |
import java.util.Date;
|
|
|
37 |
import java.util.HashMap;
|
|
|
38 |
import java.util.List;
|
|
|
39 |
import java.util.Map;
|
|
|
40 |
|
|
|
41 |
public class SituationCompteXmlSheet extends AbstractListeSheetXml {
|
|
|
42 |
|
|
|
43 |
private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
|
|
|
44 |
private SQLElement eltEch;
|
|
|
45 |
private SQLElement eltVf;
|
|
|
46 |
private ComptaPropsConfiguration conf;
|
|
|
47 |
|
|
|
48 |
public SituationCompteXmlSheet(ComptaPropsConfiguration conf, SQLRow rowClient) {
|
|
|
49 |
super(rowClient);
|
|
|
50 |
this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter");
|
|
|
51 |
this.eltEch = conf.getDirectory().getElement("ECHEANCE_CLIENT");
|
|
|
52 |
this.conf = conf;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@Override
|
|
|
56 |
protected String getStoragePathP() {
|
|
|
57 |
return "Autres";
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public String getDefaultTemplateId() {
|
|
|
61 |
return "SituationCompte";
|
|
|
62 |
}
|
|
|
63 |
|
182 |
ilm |
64 |
private Date d;
|
180 |
ilm |
65 |
|
|
|
66 |
@Override
|
|
|
67 |
public String getName() {
|
|
|
68 |
if (this.d == null) {
|
|
|
69 |
this.d = new Date();
|
|
|
70 |
}
|
|
|
71 |
return "SituationCompte-" + this.d.getTime();
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
protected void createListeValues() {
|
|
|
75 |
|
|
|
76 |
// On récupére les échéances en cours
|
|
|
77 |
final SQLTable echTable = eltEch.getTable();
|
|
|
78 |
SQLRowValues rowVals = new SQLRowValues(echTable);
|
|
|
79 |
rowVals.putNulls("DATE", "MONTANT");
|
|
|
80 |
rowVals.putRowValues("ID_SAISIE_VENTE_FACTURE").putNulls("NUMERO", "NET_A_PAYER", "DATE", "NOM");
|
|
|
81 |
Where w = new Where(echTable.getField("REGLE"), "=", Boolean.FALSE);
|
|
|
82 |
w = w.and(new Where(echTable.getField("REG_COMPTA"), "=", Boolean.FALSE));
|
|
|
83 |
w = w.and(new Where(echTable.getField("ID_CLIENT"), "=", row.getID()));
|
|
|
84 |
|
|
|
85 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
|
|
|
86 |
|
182 |
ilm |
87 |
List<SQLRowValues> result = fetcher.fetch(w);
|
|
|
88 |
Collections.sort(result, new Comparator<SQLRowValues>() {
|
180 |
ilm |
89 |
@Override
|
182 |
ilm |
90 |
public int compare(SQLRowValues o1, SQLRowValues o2) {
|
180 |
ilm |
91 |
|
182 |
ilm |
92 |
return o1.getDate("DATE").compareTo(o2.getDate("DATE"));
|
180 |
ilm |
93 |
}
|
182 |
ilm |
94 |
});
|
180 |
ilm |
95 |
|
|
|
96 |
List<Map<String, Object>> listValues = new ArrayList<Map<String, Object>>();
|
|
|
97 |
Map<Integer, String> styleValues = new HashMap<Integer, String>();
|
|
|
98 |
BigDecimal totalRegle = BigDecimal.ZERO;
|
|
|
99 |
BigDecimal totalEch = BigDecimal.ZERO;
|
|
|
100 |
BigDecimal totalEchPasse = BigDecimal.ZERO;
|
|
|
101 |
Calendar today = Calendar.getInstance();
|
|
|
102 |
for (SQLRowValues sqlRow : result) {
|
|
|
103 |
Map<String, Object> mValues = new HashMap<String, Object>();
|
|
|
104 |
final Calendar dateEch = sqlRow.getDate("DATE");
|
|
|
105 |
mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
|
|
|
106 |
final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT"));
|
182 |
ilm |
107 |
mValues.put("DU", montantDu.movePointLeft(2));
|
180 |
ilm |
108 |
|
|
|
109 |
totalEch = totalEch.add(montantDu);
|
|
|
110 |
|
|
|
111 |
SQLRowAccessor rowFact = sqlRow.getNonEmptyForeign("ID_SAISIE_VENTE_FACTURE");
|
|
|
112 |
final BigDecimal regle;
|
|
|
113 |
if (rowFact != null) {
|
|
|
114 |
mValues.put("PIECE", rowFact.getString("NUMERO"));
|
|
|
115 |
mValues.put("LIBELLE", rowFact.getString("NOM"));
|
|
|
116 |
mValues.put("DATE", dateFormat.format(rowFact.getDate("DATE").getTime()));
|
|
|
117 |
final BigDecimal montantFact = new BigDecimal(rowFact.getLong("NET_A_PAYER"));
|
|
|
118 |
regle = montantFact.subtract(montantDu);
|
182 |
ilm |
119 |
mValues.put("DU", montantFact.movePointLeft(2));
|
|
|
120 |
mValues.put("REGLE", montantFact.subtract(montantDu).movePointLeft(2));
|
|
|
121 |
mValues.put("SOLDE", montantDu.movePointLeft(2));
|
180 |
ilm |
122 |
|
|
|
123 |
} else {
|
|
|
124 |
regle = BigDecimal.ZERO;
|
182 |
ilm |
125 |
mValues.put("SOLDE", montantDu.movePointLeft(2));
|
180 |
ilm |
126 |
}
|
|
|
127 |
if (dateEch.before(today)) {
|
|
|
128 |
totalEchPasse = totalEchPasse.add(montantDu);
|
|
|
129 |
styleValues.put(listValues.size(), "Normal");
|
|
|
130 |
} else {
|
|
|
131 |
styleValues.put(listValues.size(), "Titre 1");
|
|
|
132 |
}
|
|
|
133 |
totalRegle = totalRegle.add(regle);
|
|
|
134 |
|
|
|
135 |
// SQLRow rowClient = sqlRow.getForeignRow("ID_CLIENT");
|
|
|
136 |
|
|
|
137 |
listValues.add(mValues);
|
|
|
138 |
|
|
|
139 |
// List<SQLRow> enc = sqlRow.getReferentRows(eltEncElt.getTable());
|
|
|
140 |
//
|
|
|
141 |
// for (SQLRow sqlRow2 : enc) {
|
|
|
142 |
// Map<String, Object> mValuesEnc = new HashMap<String, Object>();
|
|
|
143 |
// SQLRow rowEnc = sqlRow2.getForeignRow("ID_ENCAISSER_MONTANT");
|
|
|
144 |
// SQLRow rowMdr = rowEnc.getForeignRow("ID_MODE_REGLEMENT");
|
|
|
145 |
// mValuesEnc.put("NUMERO_FACTURE", "");
|
|
|
146 |
// mValuesEnc.put("REFERENCE", rowMdr.getString("NOM"));
|
|
|
147 |
// mValuesEnc.put("DATE", dateFormat.format(rowEnc.getDate("DATE").getTime()));
|
|
|
148 |
// mValuesEnc.put("NOM_CLIENT", "");
|
|
|
149 |
// mValuesEnc.put("CODE_CLIENT", "");
|
|
|
150 |
// mValuesEnc.put("TELEPHONE", "");
|
|
|
151 |
// mValuesEnc.put("MODE_REGLEMENT",
|
|
|
152 |
// rowMdr.getForeignRow("ID_TYPE_REGLEMENT").getString("NOM"));
|
|
|
153 |
// mValuesEnc.put("MONTANT",
|
|
|
154 |
// GestionDevise.currencyToString(sqlRow2.getLong("MONTANT_REGLE")));
|
|
|
155 |
// styleValues.put(listValues.size(), "Titre 1");
|
|
|
156 |
// listValues.add(mValuesEnc);
|
|
|
157 |
//
|
|
|
158 |
// }
|
|
|
159 |
// if (enc != null && enc.size() > 0) {
|
|
|
160 |
// Map<String, Object> mValuesEnc = new HashMap<String, Object>();
|
|
|
161 |
// mValuesEnc.put("DATE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
|
|
|
162 |
// mValuesEnc.put("MODE_REGLEMENT", "Restant à régler");
|
|
|
163 |
// mValuesEnc.put("MONTANT", GestionDevise.currencyToString(sqlRow.getLong("MONTANT")));
|
|
|
164 |
// styleValues.put(listValues.size(), "Titre 1");
|
|
|
165 |
// listValues.add(mValuesEnc);
|
|
|
166 |
// }
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
|
182 |
ilm |
170 |
|
|
|
171 |
// Avoir
|
|
|
172 |
final SQLTable avoirTable = echTable.getTable("AVOIR_CLIENT");
|
|
|
173 |
SQLRowValues rowValsAvoir = new SQLRowValues(avoirTable);
|
|
|
174 |
rowValsAvoir.putNulls("NUMERO", "MONTANT_TTC", "MONTANT_SOLDE", "MONTANT_RESTANT", "DATE", "NOM");
|
|
|
175 |
Where wA = new Where(avoirTable.getField("SOLDE"), "=", Boolean.FALSE);
|
|
|
176 |
wA = wA.and(new Where(avoirTable.getField("ID_CLIENT"), "=", row.getID()));
|
|
|
177 |
wA = wA.and(new Where(avoirTable.getField("MONTANT_RESTANT"), ">", 0));
|
|
|
178 |
|
|
|
179 |
SQLRowValuesListFetcher fetcherA = SQLRowValuesListFetcher.create(rowValsAvoir);
|
|
|
180 |
List<SQLRowValues> resultA = fetcherA.fetch(wA);
|
|
|
181 |
Collections.sort(resultA, new Comparator<SQLRowValues>() {
|
|
|
182 |
@Override
|
|
|
183 |
public int compare(SQLRowValues o1, SQLRowValues o2) {
|
|
|
184 |
|
|
|
185 |
return o1.getDate("DATE").compareTo(o2.getDate("DATE"));
|
|
|
186 |
}
|
|
|
187 |
});
|
|
|
188 |
if (!resultA.isEmpty()) {
|
|
|
189 |
listValues.add(new HashMap<String, Object>());
|
|
|
190 |
}
|
|
|
191 |
for (SQLRowValues sqlRow : resultA) {
|
|
|
192 |
Map<String, Object> mValues = new HashMap<String, Object>();
|
|
|
193 |
final Calendar dateEch = sqlRow.getDate("DATE");
|
|
|
194 |
mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
|
|
|
195 |
final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT_RESTANT")).movePointLeft(2).negate();
|
|
|
196 |
mValues.put("DU", montantDu);
|
|
|
197 |
|
|
|
198 |
totalEch = totalEch.add(montantDu.movePointRight(2));
|
|
|
199 |
totalEchPasse = totalEchPasse.add(montantDu.movePointRight(2));
|
|
|
200 |
mValues.put("PIECE", sqlRow.getString("NUMERO"));
|
|
|
201 |
mValues.put("LIBELLE", sqlRow.getString("NOM"));
|
|
|
202 |
mValues.put("DATE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
|
|
|
203 |
|
|
|
204 |
styleValues.put(listValues.size(), "Normal");
|
|
|
205 |
|
|
|
206 |
listValues.add(mValues);
|
|
|
207 |
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
SQLRow rowSoc = this.conf.getRowSociete();
|
180 |
ilm |
211 |
SQLRow adrSoc = rowSoc.getForeign("ID_ADRESSE_COMMON");
|
|
|
212 |
|
|
|
213 |
Map<String, Object> sheetVals = new HashMap<String, Object>();
|
|
|
214 |
|
182 |
ilm |
215 |
sheetVals.put("TOTAL_REGLE", totalRegle.movePointLeft(2));
|
|
|
216 |
sheetVals.put("TOTAL_ECHEANCE", totalEch.movePointLeft(2));
|
|
|
217 |
sheetVals.put("TOTAL_FUTUR", totalEch.subtract(totalEchPasse).movePointLeft(2));
|
|
|
218 |
sheetVals.put("TOTAL_PASSE", totalEchPasse.movePointLeft(2));
|
180 |
ilm |
219 |
|
|
|
220 |
sheetVals.put("NOM_CLIENT", row.getString("NOM"));
|
182 |
ilm |
221 |
sheetVals.put("DATE", dateFormat.format(new Date()));
|
180 |
ilm |
222 |
sheetVals.put("CODE_CLIENT", row.getString("CODE"));
|
|
|
223 |
sheetVals.put("TELEPHONE", row.getString("TEL"));
|
|
|
224 |
SQLRow rowAdrClient = row.getForeign("ID_ADRESSE");
|
|
|
225 |
sheetVals.put("ADRESSE", rowAdrClient.getString("RUE"));
|
|
|
226 |
sheetVals.put("VILLE", rowAdrClient.getString("CODE_POSTAL") + " " + rowAdrClient.getString("VILLE"));
|
|
|
227 |
|
|
|
228 |
sheetVals.put("SOCIETE_NOM", rowSoc.getString("NOM"));
|
|
|
229 |
sheetVals.put("SOCIETE_TEL", rowSoc.getString("NUM_TEL"));
|
|
|
230 |
sheetVals.put("SOCIETE_SIRET", rowSoc.getString("NUM_SIRET"));
|
|
|
231 |
sheetVals.put("SOCIETE_APE", rowSoc.getString("NUM_APE"));
|
|
|
232 |
sheetVals.put("SOCIETE_NII", rowSoc.getString("NUM_NII"));
|
|
|
233 |
sheetVals.put("SOCIETE_BIC", rowSoc.getString("BIC"));
|
|
|
234 |
sheetVals.put("SOCIETE_IBAN", rowSoc.getString("IBAN"));
|
|
|
235 |
sheetVals.put("SOCIETE_MAIL", rowSoc.getString("MAIL"));
|
|
|
236 |
|
|
|
237 |
sheetVals.put("SOCIETE_ADRESSE", adrSoc.getString("RUE"));
|
|
|
238 |
sheetVals.put("SOCIETE_VILLE", adrSoc.getString("CODE_POSTAL") + " " + adrSoc.getString("VILLE"));
|
|
|
239 |
this.mapAllSheetValues.put(0, sheetVals);
|
|
|
240 |
this.listAllSheetValues.put(0, listValues);
|
|
|
241 |
this.styleAllSheetValues.put(0, styleValues);
|
|
|
242 |
|
|
|
243 |
}
|
|
|
244 |
}
|