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 {
|
|
|
86 |
private final String code, nom;
|
|
|
87 |
private BigDecimal percentTaxe, totalBase, qte;
|
|
|
88 |
|
|
|
89 |
public TaxeComplRecap(String code, String nom, BigDecimal percentTaxe) {
|
|
|
90 |
this.code = code;
|
|
|
91 |
this.nom = nom;
|
|
|
92 |
this.qte = BigDecimal.ZERO;
|
|
|
93 |
this.percentTaxe = percentTaxe;
|
|
|
94 |
this.totalBase = BigDecimal.ZERO;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public void cumul(BigDecimal qte, BigDecimal total) {
|
|
|
98 |
this.qte = qte.add(this.qte);
|
|
|
99 |
this.totalBase = total.add(this.totalBase);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public String getCode() {
|
|
|
103 |
return code;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public String getNom() {
|
|
|
107 |
return nom;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public BigDecimal getQte() {
|
|
|
111 |
return qte;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public BigDecimal getPercentTaxe() {
|
|
|
115 |
return percentTaxe;
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
public BigDecimal getTotalBase() {
|
|
|
120 |
return totalBase;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
public BigDecimal getTotalTaxe() {
|
|
|
124 |
return this.totalBase.multiply(this.percentTaxe.movePointLeft(2)).setScale(2, RoundingMode.HALF_UP);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public BigDecimal getTotalBaseHT() {
|
|
|
128 |
return this.totalBase.subtract(getTotalTaxe());
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private void fillSynthese() {
|
|
|
133 |
final SQLTable tableVF = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE");
|
|
|
134 |
final SQLTable tableVFElt = Configuration.getInstance().getRoot().findTable("SAISIE_VENTE_FACTURE_ELEMENT");
|
|
|
135 |
|
|
|
136 |
SQLRowValues rowvalsVF = new SQLRowValues(tableVF);
|
|
|
137 |
rowvalsVF.put("NUMERO", null);
|
|
|
138 |
rowvalsVF.put("DATE", null);
|
|
|
139 |
|
|
|
140 |
SQLRowValues rowvalsVFElt = new SQLRowValues(tableVFElt);
|
|
|
141 |
rowvalsVFElt.put("ID_SAISIE_VENTE_FACTURE", rowvalsVF);
|
|
|
142 |
rowvalsVFElt.put("T_PV_HT", null);
|
|
|
143 |
rowvalsVFElt.put("QTE", null);
|
|
|
144 |
rowvalsVFElt.put("QTE_UNITAIRE", null);
|
|
|
145 |
rowvalsVFElt.putRowValues("ID_ARTICLE").putRowValues("ID_TAXE_COMPLEMENTAIRE").putNulls("CODE", "NOM", "POURCENT");
|
|
|
146 |
|
|
|
147 |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowvalsVFElt);
|
|
|
148 |
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
149 |
|
|
|
150 |
@Override
|
|
|
151 |
public SQLSelect transformChecked(SQLSelect input) {
|
|
|
152 |
Where w = new Where(input.getAlias(tableVF).getField("DATE"), dateD, dateF);
|
|
|
153 |
input.setWhere(w);
|
|
|
154 |
return input;
|
|
|
155 |
}
|
|
|
156 |
});
|
|
|
157 |
|
|
|
158 |
Map<Integer, TaxeComplRecap> recap = new HashMap<Integer, ReportingTaxeComplementaireSheetXML.TaxeComplRecap>();
|
|
|
159 |
List<SQLRowValues> results = fetcher.fetch();
|
|
|
160 |
for (SQLRowValues sqlRowValues : results) {
|
|
|
161 |
TaxeComplRecap r;
|
|
|
162 |
if (sqlRowValues.getForeign("ID_ARTICLE") != null && !sqlRowValues.isForeignEmpty("ID_ARTICLE")) {
|
|
|
163 |
final SQLRowAccessor foreignArt = sqlRowValues.getForeign("ID_ARTICLE");
|
|
|
164 |
if (foreignArt.getForeign("ID_TAXE_COMPLEMENTAIRE") != null && !foreignArt.isForeignEmpty("ID_TAXE_COMPLEMENTAIRE")) {
|
|
|
165 |
final SQLRowAccessor foreignTaxeCompl = foreignArt.getForeign("ID_TAXE_COMPLEMENTAIRE");
|
|
|
166 |
if (recap.containsKey(foreignTaxeCompl.getID())) {
|
|
|
167 |
r = recap.get(foreignTaxeCompl.getID());
|
|
|
168 |
} else {
|
|
|
169 |
r = new TaxeComplRecap(foreignTaxeCompl.getString("CODE"), foreignTaxeCompl.getString("NOM"), foreignTaxeCompl.getBigDecimal("POURCENT"));
|
|
|
170 |
recap.put(foreignTaxeCompl.getID(), r);
|
|
|
171 |
}
|
|
|
172 |
r.cumul(sqlRowValues.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRowValues.getInt("QTE"))), sqlRowValues.getBigDecimal("T_PV_HT"));
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
|
|
|
178 |
this.listAllSheetValues.put(0, values);
|
|
|
179 |
Map<Integer, String> style = new HashMap<Integer, String>();
|
|
|
180 |
this.styleAllSheetValues.put(0, style);
|
|
|
181 |
|
|
|
182 |
BigDecimal totalBaseHT = BigDecimal.ZERO;
|
|
|
183 |
BigDecimal totalTaxe = BigDecimal.ZERO;
|
|
|
184 |
BigDecimal qteTotal = BigDecimal.ZERO;
|
|
|
185 |
|
|
|
186 |
for (TaxeComplRecap item : recap.values()) {
|
|
|
187 |
Map<String, Object> vals = new HashMap<String, Object>();
|
|
|
188 |
|
|
|
189 |
vals.put("CODE", item.getCode());
|
|
|
190 |
vals.put("NOM", item.getNom());
|
|
|
191 |
vals.put("QTE", item.getQte());
|
|
|
192 |
vals.put("POURCENT", item.getPercentTaxe());
|
|
|
193 |
vals.put("TOTAL_BASE", item.getTotalBaseHT());
|
|
|
194 |
vals.put("TOTAL_TAXE", item.getTotalTaxe());
|
|
|
195 |
style.put(values.size(), "Normal");
|
|
|
196 |
totalBaseHT = totalBaseHT.add(item.getTotalBaseHT());
|
|
|
197 |
totalTaxe = totalTaxe.add(item.getTotalTaxe());
|
|
|
198 |
qteTotal = qteTotal.add(item.getQte());
|
|
|
199 |
values.add(vals);
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
203 |
Map<String, Object> vals = new HashMap<String, Object>();
|
|
|
204 |
vals.put("DATE_DEB", this.dateD);
|
|
|
205 |
vals.put("DATE_FIN", this.dateF);
|
|
|
206 |
vals.put("PERIODE", "Période du " + format.format(this.dateD) + " au " + format.format(this.dateF));
|
|
|
207 |
vals.put("TOTAL_TAXE", totalTaxe);
|
|
|
208 |
vals.put("TOTAL_BASE", totalBaseHT);
|
|
|
209 |
vals.put("TOTAL_QTE", qteTotal);
|
|
|
210 |
this.mapAllSheetValues.put(0, vals);
|
|
|
211 |
// style.put(values.size(), "Titre 1");
|
|
|
212 |
}
|
|
|
213 |
}
|