OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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