OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 180
Line 11... Line 11...
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
 package org.openconcerto.erp.core.sales.invoice.report;
14
 package org.openconcerto.erp.core.sales.invoice.report;
15
 
15
 
-
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
17
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
16
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
18
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml;
17
import org.openconcerto.erp.preferences.PrinterNXProps;
-
 
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRow;
21
import org.openconcerto.sql.model.SQLRowListRSH;
22
import org.openconcerto.sql.model.SQLRowListRSH;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
24
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
24
import org.openconcerto.sql.model.SQLSelect;
25
import org.openconcerto.sql.model.SQLSelect;
25
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.model.SQLTable;
-
 
27
import org.openconcerto.sql.model.TableRef;
-
 
28
import org.openconcerto.sql.model.Where;
-
 
29
import org.openconcerto.utils.cc.ITransformer;
26
 
30
 
27
import java.math.BigDecimal;
31
import java.math.BigDecimal;
28
import java.text.DateFormat;
32
import java.text.DateFormat;
29
import java.text.SimpleDateFormat;
33
import java.text.SimpleDateFormat;
30
import java.util.ArrayList;
34
import java.util.ArrayList;
-
 
35
import java.util.Collection;
31
import java.util.Collections;
36
import java.util.Collections;
32
import java.util.Comparator;
37
import java.util.Comparator;
33
import java.util.Date;
38
import java.util.Date;
34
import java.util.HashMap;
39
import java.util.HashMap;
35
import java.util.List;
40
import java.util.List;
Line 40... Line 45...
40
 
45
 
41
    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
46
    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
42
 
47
 
43
    public static final String TEMPLATE_ID = "EtatStocks";
48
    public static final String TEMPLATE_ID = "EtatStocks";
44
    public static final String TEMPLATE_PROPERTY_NAME = DEFAULT_PROPERTY_NAME;
49
    public static final String TEMPLATE_PROPERTY_NAME = DEFAULT_PROPERTY_NAME;
45
 
-
 
-
 
50
    private int intIDDepot = DepotStockSQLElement.DEFAULT_ID;
-
 
51
    private boolean bTousLesDepots = false;
46
    private Date date;
52
    private Date date;
47
    private SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
53
    private SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
48
    private SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
54
    private SQLElement eltStock = Configuration.getInstance().getDirectory().getElement("STOCK");
49
 
55
 
50
    public ReportingStockXmlSheet(boolean fournisseur) {
56
    public ReportingStockXmlSheet(ComptaPropsConfiguration conf, Integer intIDDepot, boolean bTousLesDepots) {
-
 
57
        this.eltArticle = conf.getDirectory().getElement("ARTICLE");
-
 
58
        this.eltStock = conf.getDirectory().getElement("STOCK");
-
 
59
        if (intIDDepot != null) {
-
 
60
            this.intIDDepot = intIDDepot;
51
        super();
61
        }
52
        this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter");
62
        this.bTousLesDepots = bTousLesDepots;
53
 
-
 
54
    }
63
    }
55
 
64
 
56
    @Override
65
    @Override
57
    public String getStoragePathP() {
66
    public String getStoragePathP() {
58
        return "Autres";
67
        return "Autres";
Line 71... Line 80...
71
        return "EtatStocks" + this.date.getTime();
80
        return "EtatStocks" + this.date.getTime();
72
    }
81
    }
73
 
82
 
74
    protected void createListeValues() {
83
    protected void createListeValues() {
75
 
84
 
76
        final SQLTable tableArt = eltArticle.getTable();
85
        final SQLTable tableArt = this.eltArticle.getTable();
77
        SQLRowValues rowVals = new SQLRowValues(tableArt);
86
        SQLRowValues rowvArticle = new SQLRowValues(tableArt);
78
        rowVals.put("ID_FOURNISSEUR", null);
87
        rowvArticle.put("ID_FOURNISSEUR", null);
79
        rowVals.put("ID_FAMILLE_ARTICLE", null);
88
        rowvArticle.put("ID_FAMILLE_ARTICLE", null);
80
        rowVals.put("CODE", null);
89
        rowvArticle.put("CODE", null);
81
        rowVals.put("NOM", null);
90
        rowvArticle.put("NOM", null);
82
        rowVals.put("PA_HT", null);
91
        rowvArticle.put("PA_HT", null);
83
        rowVals.put("PV_HT", null);
92
        rowvArticle.put("PV_HT", null);
-
 
93
 
-
 
94
        SQLRowValues rowvStock = new SQLRowValues(this.eltStock.getTable());
84
        rowVals.putRowValues("ID_STOCK").putNulls("QTE_REEL");
95
        rowvStock.put("QTE_REEL", null).put("ID_ARTICLE", rowvArticle);
-
 
96
 
-
 
97
        SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowvArticle);
-
 
98
 
-
 
99
        if (!this.bTousLesDepots) {
-
 
100
            fetch.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
101
                @Override
-
 
102
                public SQLSelect transformChecked(SQLSelect input) {
-
 
103
                    TableRef join = input.getAlias(ReportingStockXmlSheet.this.eltArticle.getTable().getTable("STOCK"));
-
 
104
 
-
 
105
                    input.setWhere(new Where(join.getField("ID_DEPOT_STOCK"), "=", ReportingStockXmlSheet.this.intIDDepot));
-
 
106
                    System.out.println(input.toString());
-
 
107
                    return input;
-
 
108
                }
-
 
109
            });
-
 
110
        }
85
 
111
 
86
        SQLRowValuesListFetcher fetch = SQLRowValuesListFetcher.create(rowVals);
-
 
87
        List<SQLRowValues> values = fetch.fetch();
112
        List<SQLRowValues> values = fetch.fetch();
88
 
113
 
89
        final SQLTable tableF = tableArt.getTable("FAMILLE_ARTICLE");
114
        final SQLTable tableF = tableArt.getTable("FAMILLE_ARTICLE");
90
        SQLSelect selFam = new SQLSelect();
115
        SQLSelect selFam = new SQLSelect();
91
        selFam.addSelect(tableF.getKey());
116
        selFam.addSelect(tableF.getKey());
Line 117... Line 142...
117
            }
142
            }
118
        });
143
        });
119
        Line lineTotal = new Line("Total", "", BigDecimal.ZERO, 0F);
144
        Line lineTotal = new Line("Total", "", BigDecimal.ZERO, 0F);
120
        final HashMap<Integer, String> style = new HashMap<Integer, String>();
145
        final HashMap<Integer, String> style = new HashMap<Integer, String>();
121
        for (SQLRowValues vals : values) {
146
        for (SQLRowValues vals : values) {
-
 
147
            Collection<SQLRowValues> stocks = vals.getReferentRows(this.eltStock.getTable());
-
 
148
            Float qte = 0f;
-
 
149
            for (SQLRowValues stock : stocks) {
122
            Float qte = vals.getForeign("ID_STOCK").getFloat("QTE_REEL");
150
                qte += stock.getFloat("QTE_REEL");
-
 
151
            }
123
            BigDecimal ha = BigDecimal.ZERO;
152
            BigDecimal ha = BigDecimal.ZERO;
124
            if (qte > 0) {
153
            if (qte > 0) {
125
                final BigDecimal puHA = vals.getBigDecimal("PA_HT");
154
                final BigDecimal puHA = vals.getBigDecimal("PA_HT");
126
                ha = puHA.multiply(new BigDecimal(qte));
155
                ha = puHA.multiply(new BigDecimal(qte));
127
 
156
 
Line 211... Line 240...
211
 
240
 
212
        listValues.add(lineTotal.getMapXMLSheet());
241
        listValues.add(lineTotal.getMapXMLSheet());
213
        style.put(style.keySet().size(), "Titre 1");
242
        style.put(style.keySet().size(), "Titre 1");
214
 
243
 
215
        final Map<String, Object> valuesSheet = new HashMap<String, Object>();
244
        final Map<String, Object> valuesSheet = new HashMap<String, Object>();
216
        valuesSheet.put("DATE", "Au " + dateFormat.format(new Date()));
245
        valuesSheet.put("DATE", "Au " + this.dateFormat.format(new Date()));
217
        //
246
        //
218
        this.listAllSheetValues.put(0, listValues);
247
        this.listAllSheetValues.put(0, listValues);
219
 
248
 
220
        this.styleAllSheetValues.put(0, style);
249
        this.styleAllSheetValues.put(0, style);
221
        this.mapAllSheetValues.put(0, valuesSheet);
250
        this.mapAllSheetValues.put(0, valuesSheet);
Line 237... Line 266...
237
            this.puHA = puHA;
266
            this.puHA = puHA;
238
            this.qte = qte;
267
            this.qte = qte;
239
        }
268
        }
240
 
269
 
241
        public Float getQte() {
270
        public Float getQte() {
242
            return qte;
271
            return this.qte;
243
        }
272
        }
244
 
273
 
245
        public String getCodeArt() {
274
        public String getCodeArt() {
246
            return codeArt;
275
            return this.codeArt;
247
        }
276
        }
248
 
277
 
249
        public BigDecimal getPuHA() {
278
        public BigDecimal getPuHA() {
250
            return puHA;
279
            return this.puHA;
251
        }
280
        }
252
 
281
 
253
        public String getNomArt() {
282
        public String getNomArt() {
254
            return nomArt;
283
            return this.nomArt;
255
        }
284
        }
256
 
285
 
257
        public BigDecimal getTotalHA() {
286
        public BigDecimal getTotalHA() {
258
            return totalHA;
287
            return this.totalHA;
259
        }
288
        }
260
 
289
 
261
        public void add(Line l) {
290
        public void add(Line l) {
262
            this.totalHA = this.totalHA.add(l.getTotalHA());
291
            this.totalHA = this.totalHA.add(l.getTotalHA());
263
            if (l.getQte() > 0) {
292
            if (l.getQte() > 0) {