180 |
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.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;
|
|
|
34 |
import java.util.Date;
|
|
|
35 |
import java.util.HashMap;
|
|
|
36 |
import java.util.List;
|
|
|
37 |
import java.util.Map;
|
|
|
38 |
|
|
|
39 |
public class SituationCompteXmlSheet extends AbstractListeSheetXml {
|
|
|
40 |
|
|
|
41 |
private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
|
|
|
42 |
private SQLElement eltEch;
|
|
|
43 |
private SQLElement eltVf;
|
|
|
44 |
private ComptaPropsConfiguration conf;
|
|
|
45 |
|
|
|
46 |
public SituationCompteXmlSheet(ComptaPropsConfiguration conf, SQLRow rowClient) {
|
|
|
47 |
super(rowClient);
|
|
|
48 |
this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter");
|
|
|
49 |
this.eltEch = conf.getDirectory().getElement("ECHEANCE_CLIENT");
|
|
|
50 |
this.conf = conf;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
@Override
|
|
|
54 |
protected String getStoragePathP() {
|
|
|
55 |
return "Autres";
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public String getDefaultTemplateId() {
|
|
|
59 |
return "SituationCompte";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
private Date d = null;
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public String getName() {
|
|
|
66 |
if (this.d == null) {
|
|
|
67 |
this.d = new Date();
|
|
|
68 |
}
|
|
|
69 |
return "SituationCompte-" + this.d.getTime();
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
protected void createListeValues() {
|
|
|
73 |
|
|
|
74 |
// On récupére les échéances en cours
|
|
|
75 |
final SQLTable echTable = eltEch.getTable();
|
|
|
76 |
SQLRowValues rowVals = new SQLRowValues(echTable);
|
|
|
77 |
rowVals.putNulls("DATE", "MONTANT");
|
|
|
78 |
rowVals.putRowValues("ID_SAISIE_VENTE_FACTURE").putNulls("NUMERO", "NET_A_PAYER", "DATE", "NOM");
|
|
|
79 |
Where w = new Where(echTable.getField("REGLE"), "=", Boolean.FALSE);
|
|
|
80 |
w = w.and(new Where(echTable.getField("REG_COMPTA"), "=", Boolean.FALSE));
|
|
|
81 |
w = w.and(new Where(echTable.getField("ID_CLIENT"), "=", row.getID()));
|
|
|
82 |
|
|
|
83 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
|
|
|
84 |
fetcher.addSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
88 |
input.addFieldOrder(echTable.getField("DATE"));
|
|
|
89 |
|
|
|
90 |
return input;
|
|
|
91 |
}
|
|
|
92 |
}, 0);
|
|
|
93 |
List<SQLRowValues> result = fetcher.fetch(w);
|
|
|
94 |
|
|
|
95 |
List<Map<String, Object>> listValues = new ArrayList<Map<String, Object>>();
|
|
|
96 |
Map<Integer, String> styleValues = new HashMap<Integer, String>();
|
|
|
97 |
BigDecimal totalRegle = BigDecimal.ZERO;
|
|
|
98 |
BigDecimal totalEch = BigDecimal.ZERO;
|
|
|
99 |
BigDecimal totalEchPasse = BigDecimal.ZERO;
|
|
|
100 |
Calendar today = Calendar.getInstance();
|
|
|
101 |
for (SQLRowValues sqlRow : result) {
|
|
|
102 |
Map<String, Object> mValues = new HashMap<String, Object>();
|
|
|
103 |
final Calendar dateEch = sqlRow.getDate("DATE");
|
|
|
104 |
mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
|
|
|
105 |
final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT"));
|
|
|
106 |
mValues.put("DU", montantDu);
|
|
|
107 |
|
|
|
108 |
totalEch = totalEch.add(montantDu);
|
|
|
109 |
|
|
|
110 |
SQLRowAccessor rowFact = sqlRow.getNonEmptyForeign("ID_SAISIE_VENTE_FACTURE");
|
|
|
111 |
final BigDecimal regle;
|
|
|
112 |
if (rowFact != null) {
|
|
|
113 |
mValues.put("PIECE", rowFact.getString("NUMERO"));
|
|
|
114 |
mValues.put("LIBELLE", rowFact.getString("NOM"));
|
|
|
115 |
mValues.put("DATE", dateFormat.format(rowFact.getDate("DATE").getTime()));
|
|
|
116 |
final BigDecimal montantFact = new BigDecimal(rowFact.getLong("NET_A_PAYER"));
|
|
|
117 |
regle = montantFact.subtract(montantDu);
|
|
|
118 |
mValues.put("DU", montantFact);
|
|
|
119 |
mValues.put("REGLE", montantFact.subtract(montantDu));
|
|
|
120 |
mValues.put("SOLDE", montantDu);
|
|
|
121 |
|
|
|
122 |
} else {
|
|
|
123 |
regle = BigDecimal.ZERO;
|
|
|
124 |
mValues.put("SOLDE", montantDu);
|
|
|
125 |
}
|
|
|
126 |
if (dateEch.before(today)) {
|
|
|
127 |
totalEchPasse = totalEchPasse.add(montantDu);
|
|
|
128 |
styleValues.put(listValues.size(), "Normal");
|
|
|
129 |
} else {
|
|
|
130 |
styleValues.put(listValues.size(), "Titre 1");
|
|
|
131 |
}
|
|
|
132 |
totalRegle = totalRegle.add(regle);
|
|
|
133 |
|
|
|
134 |
// SQLRow rowClient = sqlRow.getForeignRow("ID_CLIENT");
|
|
|
135 |
|
|
|
136 |
listValues.add(mValues);
|
|
|
137 |
|
|
|
138 |
// List<SQLRow> enc = sqlRow.getReferentRows(eltEncElt.getTable());
|
|
|
139 |
//
|
|
|
140 |
// for (SQLRow sqlRow2 : enc) {
|
|
|
141 |
// Map<String, Object> mValuesEnc = new HashMap<String, Object>();
|
|
|
142 |
// SQLRow rowEnc = sqlRow2.getForeignRow("ID_ENCAISSER_MONTANT");
|
|
|
143 |
// SQLRow rowMdr = rowEnc.getForeignRow("ID_MODE_REGLEMENT");
|
|
|
144 |
// mValuesEnc.put("NUMERO_FACTURE", "");
|
|
|
145 |
// mValuesEnc.put("REFERENCE", rowMdr.getString("NOM"));
|
|
|
146 |
// mValuesEnc.put("DATE", dateFormat.format(rowEnc.getDate("DATE").getTime()));
|
|
|
147 |
// mValuesEnc.put("NOM_CLIENT", "");
|
|
|
148 |
// mValuesEnc.put("CODE_CLIENT", "");
|
|
|
149 |
// mValuesEnc.put("TELEPHONE", "");
|
|
|
150 |
// mValuesEnc.put("MODE_REGLEMENT",
|
|
|
151 |
// rowMdr.getForeignRow("ID_TYPE_REGLEMENT").getString("NOM"));
|
|
|
152 |
// mValuesEnc.put("MONTANT",
|
|
|
153 |
// GestionDevise.currencyToString(sqlRow2.getLong("MONTANT_REGLE")));
|
|
|
154 |
// styleValues.put(listValues.size(), "Titre 1");
|
|
|
155 |
// listValues.add(mValuesEnc);
|
|
|
156 |
//
|
|
|
157 |
// }
|
|
|
158 |
// if (enc != null && enc.size() > 0) {
|
|
|
159 |
// Map<String, Object> mValuesEnc = new HashMap<String, Object>();
|
|
|
160 |
// mValuesEnc.put("DATE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
|
|
|
161 |
// mValuesEnc.put("MODE_REGLEMENT", "Restant à régler");
|
|
|
162 |
// mValuesEnc.put("MONTANT", GestionDevise.currencyToString(sqlRow.getLong("MONTANT")));
|
|
|
163 |
// styleValues.put(listValues.size(), "Titre 1");
|
|
|
164 |
// listValues.add(mValuesEnc);
|
|
|
165 |
// }
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
SQLRow rowSoc = conf.getRowSociete();
|
|
|
170 |
SQLRow adrSoc = rowSoc.getForeign("ID_ADRESSE_COMMON");
|
|
|
171 |
|
|
|
172 |
Map<String, Object> sheetVals = new HashMap<String, Object>();
|
|
|
173 |
|
|
|
174 |
sheetVals.put("TOTAL_REGLE", totalRegle);
|
|
|
175 |
sheetVals.put("TOTAL_ECHEANCE", totalEch);
|
|
|
176 |
sheetVals.put("TOTAL_FUTUR", totalEch.subtract(totalEchPasse));
|
|
|
177 |
sheetVals.put("TOTAL_PASSE", totalEchPasse);
|
|
|
178 |
|
|
|
179 |
sheetVals.put("NOM_CLIENT", row.getString("NOM"));
|
|
|
180 |
sheetVals.put("DATE", new Date());
|
|
|
181 |
sheetVals.put("CODE_CLIENT", row.getString("CODE"));
|
|
|
182 |
sheetVals.put("TELEPHONE", row.getString("TEL"));
|
|
|
183 |
SQLRow rowAdrClient = row.getForeign("ID_ADRESSE");
|
|
|
184 |
sheetVals.put("ADRESSE", rowAdrClient.getString("RUE"));
|
|
|
185 |
sheetVals.put("VILLE", rowAdrClient.getString("CODE_POSTAL") + " " + rowAdrClient.getString("VILLE"));
|
|
|
186 |
|
|
|
187 |
sheetVals.put("SOCIETE_NOM", rowSoc.getString("NOM"));
|
|
|
188 |
sheetVals.put("SOCIETE_TEL", rowSoc.getString("NUM_TEL"));
|
|
|
189 |
sheetVals.put("SOCIETE_SIRET", rowSoc.getString("NUM_SIRET"));
|
|
|
190 |
sheetVals.put("SOCIETE_APE", rowSoc.getString("NUM_APE"));
|
|
|
191 |
sheetVals.put("SOCIETE_NII", rowSoc.getString("NUM_NII"));
|
|
|
192 |
sheetVals.put("SOCIETE_BIC", rowSoc.getString("BIC"));
|
|
|
193 |
sheetVals.put("SOCIETE_IBAN", rowSoc.getString("IBAN"));
|
|
|
194 |
sheetVals.put("SOCIETE_MAIL", rowSoc.getString("MAIL"));
|
|
|
195 |
|
|
|
196 |
sheetVals.put("SOCIETE_ADRESSE", adrSoc.getString("RUE"));
|
|
|
197 |
sheetVals.put("SOCIETE_VILLE", adrSoc.getString("CODE_POSTAL") + " " + adrSoc.getString("VILLE"));
|
|
|
198 |
this.mapAllSheetValues.put(0, sheetVals);
|
|
|
199 |
this.listAllSheetValues.put(0, listValues);
|
|
|
200 |
this.styleAllSheetValues.put(0, styleValues);
|
|
|
201 |
|
|
|
202 |
}
|
|
|
203 |
}
|