OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 80 Rev 156
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.finance.accounting.model;
14
 package org.openconcerto.erp.core.finance.accounting.model;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
17
import org.openconcerto.erp.core.finance.accounting.ui.PointagePanel;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.model.SQLBase;
19
import org.openconcerto.sql.model.SQLBase;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRow;
-
 
21
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLSelect;
22
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLTable;
23
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.Where;
24
import org.openconcerto.sql.model.Where;
-
 
25
import org.openconcerto.sql.view.list.IListe;
-
 
26
import org.openconcerto.sql.view.list.ITableModel;
23
 
27
 
-
 
28
import java.util.Date;
24
import java.util.List;
29
import java.util.List;
25
 
30
 
26
import javax.swing.SwingWorker;
31
import javax.swing.SwingWorker;
27
import javax.swing.table.AbstractTableModel;
32
import javax.swing.table.AbstractTableModel;
28
 
33
 
Line 30... Line 35...
30
 
35
 
31
public class PointageModel extends AbstractTableModel {
36
public class PointageModel extends AbstractTableModel {
32
 
37
 
33
    private String[] titresCol;
38
    private String[] titresCol;
34
    private String[] titresRow;
39
    private String[] titresRow;
35
 
-
 
-
 
40
    private PointagePanel panel;
36
    private long debitPointe, creditPointe, debitNonPointe, creditNonPointe, creditSelection, debitSelection;
41
    private long debitListe, creditListe, debitTotal, creditTotal, debitPointe, creditPointe, debitNonPointe, creditNonPointe, creditSelection, debitSelection;
37
 
42
 
38
    private static final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
43
    private static final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
39
    private static final SQLTable tableEcr = base.getTable("ECRITURE");
44
    private static final SQLTable tableEcr = base.getTable("ECRITURE");
40
    int idCpt;
45
    int idCpt;
41
 
46
 
42
    public PointageModel(int idCpt) {
47
    public PointageModel(int idCpt, PointagePanel panel) {
43
 
-
 
44
        this.creditNonPointe = 0;
48
        this.creditNonPointe = 0;
-
 
49
        this.creditTotal = 0;
45
        this.creditPointe = 0;
50
        this.creditPointe = 0;
46
        this.creditSelection = 0;
51
        this.creditSelection = 0;
47
 
52
 
-
 
53
        this.panel = panel;
-
 
54
 
48
        this.debitNonPointe = 0;
55
        this.debitNonPointe = 0;
49
        this.debitPointe = 0;
56
        this.debitPointe = 0;
-
 
57
        this.debitTotal = 0;
50
        this.debitSelection = 0;
58
        this.debitSelection = 0;
51
 
59
 
52
        this.idCpt = idCpt;
60
        this.idCpt = idCpt;
53
        this.titresCol = new String[6];
61
        this.titresCol = new String[6];
54
        this.titresCol[0] = "Totaux";
62
        this.titresCol[0] = "Totaux période";
55
        this.titresCol[1] = "Pointé";
63
        this.titresCol[1] = "Pointé";
56
        this.titresCol[2] = "Non Pointé";
64
        this.titresCol[2] = "Relevé courant";
57
        this.titresCol[3] = "Total";
65
        this.titresCol[3] = "Total";
58
 
66
 
59
        this.titresCol[4] = "Sélection";
67
        this.titresCol[4] = "Sélection";
60
        this.titresCol[5] = "Pointéé + sélection";
68
        this.titresCol[5] = "Liste";
61
 
69
 
62
        this.titresRow = new String[3];
70
        this.titresRow = new String[3];
63
        this.titresRow[0] = "Débit";
71
        this.titresRow[0] = "Débit";
64
        this.titresRow[1] = "Crédit";
72
        this.titresRow[1] = "Crédit";
65
        this.titresRow[2] = "Solde";
73
        this.titresRow[2] = "Solde";
Line 72... Line 80...
72
        updateTotauxCompte();
80
        updateTotauxCompte();
73
        updateSelection(null);
81
        updateSelection(null);
74
    }
82
    }
75
 
83
 
76
    public void updateSelection(int[] rowIndex) {
84
    public void updateSelection(int[] rowIndex) {
77
        System.err.println("Update Selection");
-
 
78
        this.creditSelection = 0;
85
        this.creditSelection = 0;
79
        this.debitSelection = 0;
86
        this.debitSelection = 0;
80
 
87
 
81
        if (rowIndex != null) {
88
        if (rowIndex != null) {
82
            for (int i = 0; i < rowIndex.length; i++) {
89
            for (int i = 0; i < rowIndex.length; i++) {
Line 99... Line 106...
99
            }
106
            }
100
        }
107
        }
101
        this.fireTableDataChanged();
108
        this.fireTableDataChanged();
102
    }
109
    }
103
 
110
 
-
 
111
    private SwingWorker<String, Object> workerUpdater;
-
 
112
 
104
    public void updateTotauxCompte() {
113
    public void updateTotauxCompte() {
-
 
114
        final Date deb = panel.getDateDeb();
-
 
115
        final Date fin = panel.getDateFin();
105
 
116
 
-
 
117
        if (workerUpdater != null) {
-
 
118
            workerUpdater.cancel(true);
-
 
119
        }
-
 
120
 
106
        new SwingWorker<String, Object>() {
121
        workerUpdater = new SwingWorker<String, Object>() {
107
 
122
 
108
            @Override
123
            @Override
109
            protected String doInBackground() throws Exception {
124
            protected String doInBackground() throws Exception {
110
 
125
 
111
                SQLSelect sel = new SQLSelect(base);
126
                SQLSelect sel = new SQLSelect();
112
                sel.addSelect(tableEcr.getField("CREDIT"), "SUM");
127
                sel.addSelect(tableEcr.getField("CREDIT"), "SUM");
113
                sel.addSelect(tableEcr.getField("DEBIT"), "SUM");
128
                sel.addSelect(tableEcr.getField("DEBIT"), "SUM");
114
 
129
 
115
                Where w = new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", PointageModel.this.idCpt);
130
                Where w = new Where(tableEcr.getField("ID_COMPTE_PCE"), "=", PointageModel.this.idCpt);
-
 
131
 
-
 
132
                if (deb != null && fin != null) {
-
 
133
                    w = w.and(new Where(tableEcr.getField("DATE"), deb, fin));
-
 
134
                } else if (deb != null) {
-
 
135
                    w = w.and(new Where(tableEcr.getField("DATE"), ">=", deb));
-
 
136
                } else if (fin != null) {
-
 
137
                    w = w.and(new Where(tableEcr.getField("DATE"), "<=", fin));
-
 
138
                }
116
                sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "!=", "")));
139
                sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "!=", "")));
117
 
140
 
118
                String reqPointee = sel.toString();
141
                String reqPointee = sel.toString();
119
 
142
 
120
                Object obPointee = base.getDataSource().execute(reqPointee, new ArrayListHandler());
143
                Object obPointee = base.getDataSource().execute(reqPointee, new ArrayListHandler());
121
 
144
 
122
                List myListPointee = (List) obPointee;
145
                List myListPointee = (List) obPointee;
123
 
146
 
124
                PointageModel.this.creditPointe = 0;
147
                PointageModel.this.creditPointe = 0;
125
                PointageModel.this.debitPointe = 0;
148
                PointageModel.this.debitPointe = 0;
126
                if (myListPointee.size() != 0) {
149
                if (!myListPointee.isEmpty()) {
127
 
150
 
128
                    for (int i = 0; i < myListPointee.size(); i++) {
151
                    for (int i = 0; i < myListPointee.size(); i++) {
129
                        Object[] objTmp = (Object[]) myListPointee.get(i);
152
                        Object[] objTmp = (Object[]) myListPointee.get(i);
130
 
153
 
131
                        if (objTmp[0] != null) {
154
                        if (objTmp[0] != null) {
Line 135... Line 158...
135
                            PointageModel.this.debitPointe += ((Number) objTmp[1]).longValue();
158
                            PointageModel.this.debitPointe += ((Number) objTmp[1]).longValue();
136
                        }
159
                        }
137
                    }
160
                    }
138
                }
161
                }
139
 
162
 
140
                sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "=", "")));
163
                sel.setWhere(w.and(new Where(tableEcr.getField("POINTEE"), "=", panel.getCodePointage())));
141
                String reqNotPointee = sel.toString();
164
                String reqReleveCourant = sel.toString();
142
 
165
 
143
                Object obNotPointee = base.getDataSource().execute(reqNotPointee, new ArrayListHandler());
166
                Object obReleveCourant = base.getDataSource().execute(reqReleveCourant, new ArrayListHandler());
144
 
167
 
145
                List myListNotPointee = (List) obNotPointee;
168
                List myListReleveCourant = (List) obReleveCourant;
146
 
169
 
147
                PointageModel.this.creditNonPointe = 0;
170
                PointageModel.this.creditNonPointe = 0;
148
                PointageModel.this.debitNonPointe = 0;
171
                PointageModel.this.debitNonPointe = 0;
149
                if (myListNotPointee.size() != 0) {
172
                if (!myListReleveCourant.isEmpty()) {
150
 
173
 
151
                    for (int i = 0; i < myListNotPointee.size(); i++) {
174
                    for (int i = 0; i < myListReleveCourant.size(); i++) {
152
                        Object[] objTmp = (Object[]) myListNotPointee.get(i);
175
                        Object[] objTmp = (Object[]) myListReleveCourant.get(i);
153
 
176
 
154
                        if (objTmp[0] != null) {
177
                        if (objTmp[0] != null) {
155
                            PointageModel.this.creditNonPointe += ((Number) objTmp[0]).longValue();
178
                            PointageModel.this.creditNonPointe += ((Number) objTmp[0]).longValue();
156
                        }
179
                        }
157
 
180
 
Line 159... Line 182...
159
                            PointageModel.this.debitNonPointe += ((Number) objTmp[1]).longValue();
182
                            PointageModel.this.debitNonPointe += ((Number) objTmp[1]).longValue();
160
                        }
183
                        }
161
                    }
184
                    }
162
                }
185
                }
163
 
186
 
-
 
187
                sel.setWhere(w);
-
 
188
                String reqReleveTotal = sel.toString();
-
 
189
 
-
 
190
                Object obReleveTotal = base.getDataSource().execute(reqReleveTotal, new ArrayListHandler());
-
 
191
 
-
 
192
                List myListReleveTotal = (List) obReleveTotal;
-
 
193
 
-
 
194
                PointageModel.this.creditTotal = 0;
-
 
195
                PointageModel.this.debitTotal = 0;
-
 
196
                if (!myListReleveTotal.isEmpty()) {
-
 
197
 
-
 
198
                    for (int i = 0; i < myListReleveTotal.size(); i++) {
-
 
199
                        Object[] objTmp = (Object[]) myListReleveTotal.get(i);
-
 
200
 
-
 
201
                        if (objTmp[0] != null) {
-
 
202
                            PointageModel.this.creditTotal += ((Number) objTmp[0]).longValue();
-
 
203
                        }
-
 
204
 
-
 
205
                        if (objTmp[1] != null) {
-
 
206
                            PointageModel.this.debitTotal += ((Number) objTmp[1]).longValue();
-
 
207
                        }
-
 
208
                    }
-
 
209
                }
-
 
210
 
-
 
211
                PointageModel.this.creditListe = 0;
-
 
212
                PointageModel.this.debitListe = 0;
-
 
213
                IListe listeEcr = panel.getEcriturePanel().getListe();
-
 
214
                for (int i = 0; i < listeEcr.getRowCount(); i++) {
-
 
215
 
-
 
216
                    final SQLRowValues rowAt = ITableModel.getLine(listeEcr.getModel(), i).getRow();
-
 
217
                    if (rowAt.getObject("CREDIT") != null) {
-
 
218
                        PointageModel.this.creditListe += rowAt.getLong("CREDIT");
-
 
219
                    }
-
 
220
 
-
 
221
                    if (rowAt.getObject("DEBIT") != null) {
-
 
222
                        PointageModel.this.debitListe += rowAt.getLong("DEBIT");
-
 
223
                    }
-
 
224
                }
-
 
225
 
164
                return null;
226
                return null;
165
            }
227
            }
166
 
228
 
167
            @Override
229
            @Override
168
            protected void done() {
230
            protected void done() {
169
 
231
 
-
 
232
                if (isCancelled()) {
-
 
233
                    return;
-
 
234
                }
170
                PointageModel.this.fireTableDataChanged();
235
                PointageModel.this.fireTableDataChanged();
171
            }
236
            }
-
 
237
        };
172
        }.execute();
238
        workerUpdater.execute();
173
 
239
 
174
    }
240
    }
175
 
241
 
-
 
242
    @Override
176
    public String getColumnName(int column) {
243
    public String getColumnName(int column) {
177
 
244
 
178
        return this.titresCol[column];
245
        return this.titresCol[column];
179
    }
246
    }
180
 
247
 
Line 203... Line 270...
203
            return this.titresRow[rowIndex];
270
            return this.titresRow[rowIndex];
204
        }
271
        }
205
 
272
 
206
        if (columnIndex == 1) {
273
        if (columnIndex == 1) {
207
            if (rowIndex == 0) {
274
            if (rowIndex == 0) {
208
                return new Long(this.debitPointe);
275
                return Long.valueOf(this.debitPointe);
209
            }
276
            }
210
            if (rowIndex == 1) {
277
            if (rowIndex == 1) {
211
                return new Long(this.creditPointe);
278
                return Long.valueOf(this.creditPointe);
212
            }
279
            }
213
            if (rowIndex == 2) {
280
            if (rowIndex == 2) {
214
                return new Long(this.debitPointe - this.creditPointe);
281
                return Long.valueOf(this.debitPointe - this.creditPointe);
215
            }
282
            }
216
        }
283
        }
217
 
284
 
218
        if (columnIndex == 2) {
285
        if (columnIndex == 2) {
219
            if (rowIndex == 0) {
286
            if (rowIndex == 0) {
220
                return new Long(this.debitNonPointe);
287
                return Long.valueOf(this.debitNonPointe);
221
            }
288
            }
222
            if (rowIndex == 1) {
289
            if (rowIndex == 1) {
223
                return new Long(this.creditNonPointe);
290
                return Long.valueOf(this.creditNonPointe);
224
            }
291
            }
225
            if (rowIndex == 2) {
292
            if (rowIndex == 2) {
226
                return new Long(this.debitNonPointe - this.creditNonPointe);
293
                return Long.valueOf(this.debitNonPointe - this.creditNonPointe);
227
            }
294
            }
228
        }
295
        }
229
 
296
 
230
        if (columnIndex == 3) {
297
        if (columnIndex == 3) {
231
            if (rowIndex == 0) {
298
            if (rowIndex == 0) {
232
                return new Long(this.debitNonPointe + this.debitPointe);
299
                return Long.valueOf(this.debitTotal);
233
            }
300
            }
234
            if (rowIndex == 1) {
301
            if (rowIndex == 1) {
235
                return new Long(this.creditNonPointe + this.creditPointe);
302
                return Long.valueOf(this.creditTotal);
236
            }
303
            }
237
            if (rowIndex == 2) {
304
            if (rowIndex == 2) {
238
                return new Long((this.debitNonPointe - this.creditNonPointe) + (this.debitPointe - this.creditPointe));
305
                return Long.valueOf(this.debitTotal - this.creditTotal);
239
            }
306
            }
240
        }
307
        }
241
 
308
 
242
        if (columnIndex == 4) {
309
        if (columnIndex == 4) {
243
            if (rowIndex == 0) {
310
            if (rowIndex == 0) {
244
                return new Long(this.debitSelection);
311
                return Long.valueOf(this.debitSelection);
245
            }
312
            }
246
            if (rowIndex == 1) {
313
            if (rowIndex == 1) {
247
                return new Long(this.creditSelection);
314
                return Long.valueOf(this.creditSelection);
248
            }
315
            }
249
            if (rowIndex == 2) {
316
            if (rowIndex == 2) {
250
                return new Long(this.debitSelection - this.creditSelection);
317
                return Long.valueOf(this.debitSelection - this.creditSelection);
251
            }
318
            }
252
        }
319
        }
253
 
320
 
254
        if (columnIndex == 5) {
321
        if (columnIndex == 5) {
255
            if (rowIndex == 0) {
322
            if (rowIndex == 0) {
256
                return new Long(this.debitSelection + this.debitPointe);
323
                return Long.valueOf(this.debitListe);
257
            }
324
            }
258
            if (rowIndex == 1) {
325
            if (rowIndex == 1) {
259
                return new Long(this.creditSelection + this.creditPointe);
326
                return Long.valueOf(this.creditListe);
260
            }
327
            }
261
            if (rowIndex == 2) {
328
            if (rowIndex == 2) {
262
                return new Long(this.debitSelection - this.creditSelection + this.debitPointe - this.creditPointe);
329
                return Long.valueOf(this.debitListe - this.creditListe);
263
            }
330
            }
264
        }
331
        }
265
 
332
 
266
        return null;
333
        return null;
267
    }
334
    }