OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 180 Rev 182
Line 1... Line 1...
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-2019 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.
Line 29... Line 29...
29
import java.math.BigDecimal;
29
import java.math.BigDecimal;
30
import java.text.DateFormat;
30
import java.text.DateFormat;
31
import java.text.SimpleDateFormat;
31
import java.text.SimpleDateFormat;
32
import java.util.ArrayList;
32
import java.util.ArrayList;
33
import java.util.Calendar;
33
import java.util.Calendar;
-
 
34
import java.util.Collections;
-
 
35
import java.util.Comparator;
34
import java.util.Date;
36
import java.util.Date;
35
import java.util.HashMap;
37
import java.util.HashMap;
36
import java.util.List;
38
import java.util.List;
37
import java.util.Map;
39
import java.util.Map;
38
 
40
 
Line 57... Line 59...
57
 
59
 
58
    public String getDefaultTemplateId() {
60
    public String getDefaultTemplateId() {
59
        return "SituationCompte";
61
        return "SituationCompte";
60
    }
62
    }
61
 
63
 
62
    private Date d = null;
64
    private Date d;
63
 
65
 
64
    @Override
66
    @Override
65
    public String getName() {
67
    public String getName() {
66
        if (this.d == null) {
68
        if (this.d == null) {
67
            this.d = new Date();
69
            this.d = new Date();
Line 79... Line 81...
79
        Where w = new Where(echTable.getField("REGLE"), "=", Boolean.FALSE);
81
        Where w = new Where(echTable.getField("REGLE"), "=", Boolean.FALSE);
80
        w = w.and(new Where(echTable.getField("REG_COMPTA"), "=", Boolean.FALSE));
82
        w = w.and(new Where(echTable.getField("REG_COMPTA"), "=", Boolean.FALSE));
81
        w = w.and(new Where(echTable.getField("ID_CLIENT"), "=", row.getID()));
83
        w = w.and(new Where(echTable.getField("ID_CLIENT"), "=", row.getID()));
82
 
84
 
83
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
85
        SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowVals);
84
        fetcher.addSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
-
 
85
 
86
 
-
 
87
        List<SQLRowValues> result = fetcher.fetch(w);
-
 
88
        Collections.sort(result, new Comparator<SQLRowValues>() {
86
            @Override
89
            @Override
87
            public SQLSelect transformChecked(SQLSelect input) {
90
            public int compare(SQLRowValues o1, SQLRowValues o2) {
88
                input.addFieldOrder(echTable.getField("DATE"));
-
 
89
 
91
 
90
                return input;
92
                return o1.getDate("DATE").compareTo(o2.getDate("DATE"));
91
            }
93
            }
92
        }, 0);
94
        });
93
        List<SQLRowValues> result = fetcher.fetch(w);
-
 
94
 
95
 
95
        List<Map<String, Object>> listValues = new ArrayList<Map<String, Object>>();
96
        List<Map<String, Object>> listValues = new ArrayList<Map<String, Object>>();
96
        Map<Integer, String> styleValues = new HashMap<Integer, String>();
97
        Map<Integer, String> styleValues = new HashMap<Integer, String>();
97
        BigDecimal totalRegle = BigDecimal.ZERO;
98
        BigDecimal totalRegle = BigDecimal.ZERO;
98
        BigDecimal totalEch = BigDecimal.ZERO;
99
        BigDecimal totalEch = BigDecimal.ZERO;
Line 101... Line 102...
101
        for (SQLRowValues sqlRow : result) {
102
        for (SQLRowValues sqlRow : result) {
102
            Map<String, Object> mValues = new HashMap<String, Object>();
103
            Map<String, Object> mValues = new HashMap<String, Object>();
103
            final Calendar dateEch = sqlRow.getDate("DATE");
104
            final Calendar dateEch = sqlRow.getDate("DATE");
104
            mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
105
            mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
105
            final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT"));
106
            final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT"));
106
            mValues.put("DU", montantDu);
107
            mValues.put("DU", montantDu.movePointLeft(2));
107
 
108
 
108
            totalEch = totalEch.add(montantDu);
109
            totalEch = totalEch.add(montantDu);
109
 
110
 
110
            SQLRowAccessor rowFact = sqlRow.getNonEmptyForeign("ID_SAISIE_VENTE_FACTURE");
111
            SQLRowAccessor rowFact = sqlRow.getNonEmptyForeign("ID_SAISIE_VENTE_FACTURE");
111
            final BigDecimal regle;
112
            final BigDecimal regle;
Line 113... Line 114...
113
                mValues.put("PIECE", rowFact.getString("NUMERO"));
114
                mValues.put("PIECE", rowFact.getString("NUMERO"));
114
                mValues.put("LIBELLE", rowFact.getString("NOM"));
115
                mValues.put("LIBELLE", rowFact.getString("NOM"));
115
                mValues.put("DATE", dateFormat.format(rowFact.getDate("DATE").getTime()));
116
                mValues.put("DATE", dateFormat.format(rowFact.getDate("DATE").getTime()));
116
                final BigDecimal montantFact = new BigDecimal(rowFact.getLong("NET_A_PAYER"));
117
                final BigDecimal montantFact = new BigDecimal(rowFact.getLong("NET_A_PAYER"));
117
                regle = montantFact.subtract(montantDu);
118
                regle = montantFact.subtract(montantDu);
118
                mValues.put("DU", montantFact);
119
                mValues.put("DU", montantFact.movePointLeft(2));
119
                mValues.put("REGLE", montantFact.subtract(montantDu));
120
                mValues.put("REGLE", montantFact.subtract(montantDu).movePointLeft(2));
120
                mValues.put("SOLDE", montantDu);
121
                mValues.put("SOLDE", montantDu.movePointLeft(2));
121
 
122
 
122
            } else {
123
            } else {
123
                regle = BigDecimal.ZERO;
124
                regle = BigDecimal.ZERO;
124
                mValues.put("SOLDE", montantDu);
125
                mValues.put("SOLDE", montantDu.movePointLeft(2));
125
            }
126
            }
126
            if (dateEch.before(today)) {
127
            if (dateEch.before(today)) {
127
                totalEchPasse = totalEchPasse.add(montantDu);
128
                totalEchPasse = totalEchPasse.add(montantDu);
128
                styleValues.put(listValues.size(), "Normal");
129
                styleValues.put(listValues.size(), "Normal");
129
            } else {
130
            } else {
Line 164... Line 165...
164
            // listValues.add(mValuesEnc);
165
            // listValues.add(mValuesEnc);
165
            // }
166
            // }
166
 
167
 
167
        }
168
        }
168
 
169
 
-
 
170
 
-
 
171
        // Avoir
-
 
172
        final SQLTable avoirTable = echTable.getTable("AVOIR_CLIENT");
-
 
173
        SQLRowValues rowValsAvoir = new SQLRowValues(avoirTable);
-
 
174
        rowValsAvoir.putNulls("NUMERO", "MONTANT_TTC", "MONTANT_SOLDE", "MONTANT_RESTANT", "DATE", "NOM");
-
 
175
        Where wA = new Where(avoirTable.getField("SOLDE"), "=", Boolean.FALSE);
-
 
176
        wA = wA.and(new Where(avoirTable.getField("ID_CLIENT"), "=", row.getID()));
-
 
177
        wA = wA.and(new Where(avoirTable.getField("MONTANT_RESTANT"), ">", 0));
-
 
178
 
-
 
179
        SQLRowValuesListFetcher fetcherA = SQLRowValuesListFetcher.create(rowValsAvoir);
-
 
180
        List<SQLRowValues> resultA = fetcherA.fetch(wA);
-
 
181
        Collections.sort(resultA, new Comparator<SQLRowValues>() {
-
 
182
            @Override
-
 
183
            public int compare(SQLRowValues o1, SQLRowValues o2) {
-
 
184
 
-
 
185
                return o1.getDate("DATE").compareTo(o2.getDate("DATE"));
-
 
186
            }
-
 
187
        });
-
 
188
        if (!resultA.isEmpty()) {
-
 
189
            listValues.add(new HashMap<String, Object>());
-
 
190
        }
-
 
191
        for (SQLRowValues sqlRow : resultA) {
-
 
192
            Map<String, Object> mValues = new HashMap<String, Object>();
-
 
193
            final Calendar dateEch = sqlRow.getDate("DATE");
-
 
194
            mValues.put("DATE_ECHEANCE", dateFormat.format(dateEch.getTime()));
-
 
195
            final BigDecimal montantDu = new BigDecimal(sqlRow.getLong("MONTANT_RESTANT")).movePointLeft(2).negate();
-
 
196
            mValues.put("DU", montantDu);
-
 
197
 
-
 
198
            totalEch = totalEch.add(montantDu.movePointRight(2));
-
 
199
            totalEchPasse = totalEchPasse.add(montantDu.movePointRight(2));
-
 
200
            mValues.put("PIECE", sqlRow.getString("NUMERO"));
-
 
201
            mValues.put("LIBELLE", sqlRow.getString("NOM"));
-
 
202
            mValues.put("DATE", dateFormat.format(sqlRow.getDate("DATE").getTime()));
-
 
203
 
-
 
204
            styleValues.put(listValues.size(), "Normal");
-
 
205
 
-
 
206
            listValues.add(mValues);
-
 
207
 
-
 
208
        }
-
 
209
 
169
        SQLRow rowSoc = conf.getRowSociete();
210
        SQLRow rowSoc = this.conf.getRowSociete();
170
        SQLRow adrSoc = rowSoc.getForeign("ID_ADRESSE_COMMON");
211
        SQLRow adrSoc = rowSoc.getForeign("ID_ADRESSE_COMMON");
171
 
212
 
172
        Map<String, Object> sheetVals = new HashMap<String, Object>();
213
        Map<String, Object> sheetVals = new HashMap<String, Object>();
173
 
214
 
174
        sheetVals.put("TOTAL_REGLE", totalRegle);
215
        sheetVals.put("TOTAL_REGLE", totalRegle.movePointLeft(2));
175
        sheetVals.put("TOTAL_ECHEANCE", totalEch);
216
        sheetVals.put("TOTAL_ECHEANCE", totalEch.movePointLeft(2));
176
        sheetVals.put("TOTAL_FUTUR", totalEch.subtract(totalEchPasse));
217
        sheetVals.put("TOTAL_FUTUR", totalEch.subtract(totalEchPasse).movePointLeft(2));
177
        sheetVals.put("TOTAL_PASSE", totalEchPasse);
218
        sheetVals.put("TOTAL_PASSE", totalEchPasse.movePointLeft(2));
178
 
219
 
179
        sheetVals.put("NOM_CLIENT", row.getString("NOM"));
220
        sheetVals.put("NOM_CLIENT", row.getString("NOM"));
180
        sheetVals.put("DATE", new Date());
221
        sheetVals.put("DATE", dateFormat.format(new Date()));
181
        sheetVals.put("CODE_CLIENT", row.getString("CODE"));
222
        sheetVals.put("CODE_CLIENT", row.getString("CODE"));
182
        sheetVals.put("TELEPHONE", row.getString("TEL"));
223
        sheetVals.put("TELEPHONE", row.getString("TEL"));
183
        SQLRow rowAdrClient = row.getForeign("ID_ADRESSE");
224
        SQLRow rowAdrClient = row.getForeign("ID_ADRESSE");
184
        sheetVals.put("ADRESSE", rowAdrClient.getString("RUE"));
225
        sheetVals.put("ADRESSE", rowAdrClient.getString("RUE"));
185
        sheetVals.put("VILLE", rowAdrClient.getString("CODE_POSTAL") + " " + rowAdrClient.getString("VILLE"));
226
        sheetVals.put("VILLE", rowAdrClient.getString("CODE_POSTAL") + " " + rowAdrClient.getString("VILLE"));