144 |
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 |
/*
|
|
|
15 |
* Créé le 19 nov. 2012
|
|
|
16 |
*/
|
|
|
17 |
package org.openconcerto.erp.generationDoc.gestcomm;
|
|
|
18 |
|
|
|
19 |
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
|
|
|
20 |
import org.openconcerto.sql.Configuration;
|
|
|
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.math.RoundingMode;
|
|
|
31 |
import java.text.SimpleDateFormat;
|
|
|
32 |
import java.util.ArrayList;
|
|
|
33 |
import java.util.Date;
|
|
|
34 |
import java.util.HashMap;
|
|
|
35 |
import java.util.List;
|
|
|
36 |
import java.util.Map;
|
|
|
37 |
|
|
|
38 |
public class ReportingTaxeComplementaireSheetXML extends AbstractListeSheetXml {
|
|
|
39 |
|
|
|
40 |
public static final String TEMPLATE_ID = "ReportingTaxeComplementaire";
|
|
|
41 |
public static final String TEMPLATE_PROPERTY_NAME = DEFAULT_PROPERTY_NAME;
|
|
|
42 |
private Date date;
|
|
|
43 |
|
|
|
44 |
private Date dateD, dateF;
|
|
|
45 |
|
|
|
46 |
public ReportingTaxeComplementaireSheetXML(Date debut, Date fin) {
|
|
|
47 |
super();
|
|
|
48 |
|
|
|
49 |
this.dateD = debut;
|
|
|
50 |
this.dateF = fin;
|
|
|
51 |
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
|
|
55 |
public String getStoragePathP() {
|
|
|
56 |
return "Autres";
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Override
|
|
|
60 |
public String getDefaultTemplateId() {
|
|
|
61 |
return TEMPLATE_ID;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public String getName() {
|
|
|
66 |
if (this.date == null) {
|
|
|
67 |
this.date = new Date();
|
|
|
68 |
}
|
|
|
69 |
return "ReportingTaxeCompl" + this.date.getTime();
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@Override
|
|
|
73 |
protected void createListeValues() {
|
|
|
74 |
|
|
|
75 |
this.mapAllSheetValues = new HashMap<Integer, Map<String, Object>>();
|
|
|
76 |
this.listAllSheetValues = new HashMap<Integer, List<Map<String, Object>>>();
|
|
|
77 |
this.styleAllSheetValues = new HashMap<Integer, Map<Integer, String>>();
|
|
|
78 |
|
|
|
79 |
fillSynthese();
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
private static SQLTable tableVF = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE").getTable();
|
|
|
84 |
|
|
|
85 |
class TaxeComplRecap {
|
156 |
ilm |
86 |
private final String code, nom, numeroCptProduit, numeroCpt;
|
144 |
ilm |
87 |
private BigDecimal percentTaxe, totalBase, qte;
|
|
|
88 |
|
156 |
ilm |
89 |
public TaxeComplRecap(SQLRowAccessor foreignTaxeCompl) {
|
|
|
90 |
this.code = foreignTaxeCompl.getString("CODE");
|
|
|
91 |
this.nom = foreignTaxeCompl.getString("NOM");
|
144 |
ilm |
92 |
this.qte = BigDecimal.ZERO;
|
156 |
ilm |
93 |
this.percentTaxe = foreignTaxeCompl.getBigDecimal("POURCENT");
|
144 |
ilm |
94 |
this.totalBase = BigDecimal.ZERO;
|
156 |
ilm |
95 |
if (foreignTaxeCompl.getObject("ID_COMPTE_PCE") != null && !foreignTaxeCompl.isForeignEmpty("ID_COMPTE_PCE")) {
|
|
|
96 |
this.numeroCpt = foreignTaxeCompl.getForeign("ID_COMPTE_PCE").getString("NUMERO");
|
|
|
97 |
} else {
|
|
|
98 |
this.numeroCpt = "";
|
|
|
99 |
}
|
|
|
100 |
if (foreignTaxeCompl.getObject("ID_COMPTE_PCE_PRODUITS") != null && !foreignTaxeCompl.isForeignEmpty("ID_COMPTE_PCE_PRODUITS")) {
|
|
|
101 |
this.numeroCptProduit = foreignTaxeCompl.getForeign("ID_COMPTE_PCE_PRODUITS").getString("NUMERO");
|
|
|
102 |
} else {
|
|
|
103 |
this.numeroCptProduit = "";
|
|
|
104 |
}
|
144 |
ilm |
105 |
}
|
|
|
106 |
|
|
|
107 |
public void cumul(BigDecimal qte, BigDecimal total) {
|
|
|
108 |
this.qte = qte.add(this.qte);
|
|
|
109 |
this.totalBase = total.add(this.totalBase);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public String getCode() {
|
|
|
113 |
return code;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public String getNom() {
|
|
|
117 |
return nom;
|
|
|
118 |
}
|
|
|
119 |
|
156 |
ilm |
120 |
public String getNumeroCpt() {
|
|
|
121 |
return numeroCpt;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public String getNumeroCptProduit() {
|
|
|
125 |
return numeroCptProduit;
|
|
|
126 |
}
|
|
|
127 |
|
144 |
ilm |
128 |
public BigDecimal getQte() {
|
|
|
129 |
return qte;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public BigDecimal getPercentTaxe() {
|
|
|
133 |
return percentTaxe;
|
|
|
134 |
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public BigDecimal getTotalBase() {
|
|
|
138 |
return totalBase;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
public BigDecimal getTotalTaxe() {
|
|
|
142 |
return this.totalBase.multiply(this.percentTaxe.movePointLeft(2)).setScale(2, RoundingMode.HALF_UP);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public BigDecimal getTotalBaseHT() {
|
|
|
146 |
return this.totalBase.subtract(getTotalTaxe());
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
private void fillSynthese() {
|
|
|
151 |
final SQLTable tableVF = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE");
|
|
|
152 |
final SQLTable tableVFElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
153 |
|
|
|
154 |
SQLRowValues rowvalsVF = new SQLRowValues(tableVF);
|
|
|
155 |
rowvalsVF.put("NUMERO", null);
|
|
|
156 |
rowvalsVF.put("DATE", null);
|
|
|
157 |
|
|
|
158 |
SQLRowValues rowvalsVFElt = new SQLRowValues(tableVFElt);
|
|
|
159 |
rowvalsVFElt.put("ID_SAISIE_VENTE_FACTURE", rowvalsVF);
|
|
|
160 |
rowvalsVFElt.put("T_PV_HT", null);
|
|
|
161 |
rowvalsVFElt.put("QTE", null);
|
|
|
162 |
rowvalsVFElt.put("QTE_UNITAIRE", null);
|
156 |
ilm |
163 |
final SQLRowValues rowValsTaxeCompl = rowvalsVFElt.putRowValues("ID_ARTICLE").putRowValues("ID_TAXE_COMPLEMENTAIRE");
|
|
|
164 |
rowValsTaxeCompl.putNulls("CODE", "NOM", "POURCENT");
|
|
|
165 |
rowValsTaxeCompl.putRowValues("ID_COMPTE_PCE_PRODUITS").putNulls("NUMERO", "NOM");
|
|
|
166 |
rowValsTaxeCompl.putRowValues("ID_COMPTE_PCE").putNulls("NUMERO", "NOM");
|
144 |
ilm |
167 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowvalsVFElt);
|
|
|
168 |
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
169 |
|
|
|
170 |
@Override
|
|
|
171 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
172 |
Where w = new Where(input.getAlias(tableVF).getField("DATE"), dateD, dateF);
|
|
|
173 |
input.setWhere(w);
|
|
|
174 |
return input;
|
|
|
175 |
}
|
|
|
176 |
});
|
|
|
177 |
|
|
|
178 |
Map<Integer, TaxeComplRecap> recap = new HashMap<Integer, ReportingTaxeComplementaireSheetXML.TaxeComplRecap>();
|
|
|
179 |
List<SQLRowValues> results = fetcher.fetch();
|
|
|
180 |
for (SQLRowValues sqlRowValues : results) {
|
|
|
181 |
TaxeComplRecap r;
|
|
|
182 |
if (sqlRowValues.getForeign("ID_ARTICLE") != null && !sqlRowValues.isForeignEmpty("ID_ARTICLE")) {
|
|
|
183 |
final SQLRowAccessor foreignArt = sqlRowValues.getForeign("ID_ARTICLE");
|
|
|
184 |
if (foreignArt.getForeign("ID_TAXE_COMPLEMENTAIRE") != null && !foreignArt.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE")) {
|
|
|
185 |
final SQLRowAccessor foreignTaxeCompl = foreignArt.getForeign("ID_TAXE_COMPLEMENTAIRE");
|
|
|
186 |
if (recap.containsKey(foreignTaxeCompl.getID())) {
|
|
|
187 |
r = recap.get(foreignTaxeCompl.getID());
|
|
|
188 |
} else {
|
156 |
ilm |
189 |
r = new TaxeComplRecap(foreignTaxeCompl);
|
144 |
ilm |
190 |
recap.put(foreignTaxeCompl.getID(), r);
|
|
|
191 |
}
|
|
|
192 |
r.cumul(sqlRowValues.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRowValues.getInt("QTE"))), sqlRowValues.getBigDecimal("T_PV_HT"));
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
|
|
|
198 |
this.listAllSheetValues.put(0, values);
|
|
|
199 |
Map<Integer, String> style = new HashMap<Integer, String>();
|
|
|
200 |
this.styleAllSheetValues.put(0, style);
|
|
|
201 |
|
|
|
202 |
BigDecimal totalBaseHT = BigDecimal.ZERO;
|
|
|
203 |
BigDecimal totalTaxe = BigDecimal.ZERO;
|
|
|
204 |
BigDecimal qteTotal = BigDecimal.ZERO;
|
|
|
205 |
|
|
|
206 |
for (TaxeComplRecap item : recap.values()) {
|
|
|
207 |
Map<String, Object> vals = new HashMap<String, Object>();
|
|
|
208 |
|
156 |
ilm |
209 |
vals.put("COMPTE_NUMERO", item.getNumeroCpt());
|
|
|
210 |
vals.put("COMPTE_PRODUIT_NUMERO", item.getNumeroCptProduit());
|
|
|
211 |
|
144 |
ilm |
212 |
vals.put("CODE", item.getCode());
|
|
|
213 |
vals.put("NOM", item.getNom());
|
|
|
214 |
vals.put("QTE", item.getQte());
|
|
|
215 |
vals.put("POURCENT", item.getPercentTaxe());
|
|
|
216 |
vals.put("TOTAL_BASE", item.getTotalBaseHT());
|
|
|
217 |
vals.put("TOTAL_TAXE", item.getTotalTaxe());
|
|
|
218 |
style.put(values.size(), "Normal");
|
|
|
219 |
totalBaseHT = totalBaseHT.add(item.getTotalBaseHT());
|
|
|
220 |
totalTaxe = totalTaxe.add(item.getTotalTaxe());
|
|
|
221 |
qteTotal = qteTotal.add(item.getQte());
|
|
|
222 |
values.add(vals);
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
226 |
Map<String, Object> vals = new HashMap<String, Object>();
|
|
|
227 |
vals.put("DATE_DEB", this.dateD);
|
|
|
228 |
vals.put("DATE_FIN", this.dateF);
|
|
|
229 |
vals.put("PERIODE", "Période du " + format.format(this.dateD) + " au " + format.format(this.dateF));
|
|
|
230 |
vals.put("TOTAL_TAXE", totalTaxe);
|
|
|
231 |
vals.put("TOTAL_BASE", totalBaseHT);
|
|
|
232 |
vals.put("TOTAL_QTE", qteTotal);
|
|
|
233 |
this.mapAllSheetValues.put(0, vals);
|
|
|
234 |
// style.put(values.size(), "Titre 1");
|
|
|
235 |
}
|
|
|
236 |
}
|