OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 Rev 180
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
 package org.openconcerto.erp.core.finance.accounting.ui;
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
17
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
20
import org.openconcerto.erp.core.finance.accounting.model.SommeCompte;
20
import org.openconcerto.erp.core.finance.accounting.model.SommeCompte;
21
import org.openconcerto.erp.element.objet.Compte;
21
import org.openconcerto.erp.element.objet.Compte;
22
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
22
import org.openconcerto.erp.generationEcritures.GenerationMvtVirement;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.model.SQLBase;
24
import org.openconcerto.sql.model.SQLBase;
25
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLSelect;
28
import org.openconcerto.sql.model.SQLSystem;
28
import org.openconcerto.sql.model.SQLSystem;
29
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
31
import org.openconcerto.sql.utils.SQLUtils;
31
import org.openconcerto.sql.utils.SQLUtils;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.JDate;
33
import org.openconcerto.ui.JDate;
34
import org.openconcerto.ui.JLabelBold;
34
import org.openconcerto.ui.JLabelBold;
35
import org.openconcerto.utils.ExceptionHandler;
35
import org.openconcerto.utils.ExceptionHandler;
36
 
36
 
37
import java.awt.Component;
37
import java.awt.Component;
38
import java.awt.GridBagConstraints;
38
import java.awt.GridBagConstraints;
39
import java.awt.GridBagLayout;
39
import java.awt.GridBagLayout;
40
import java.awt.Insets;
40
import java.awt.Insets;
41
import java.awt.event.ActionEvent;
41
import java.awt.event.ActionEvent;
42
import java.awt.event.ActionListener;
42
import java.awt.event.ActionListener;
43
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeListener;
45
import java.sql.SQLException;
45
import java.sql.SQLException;
46
import java.text.DateFormat;
46
import java.text.DateFormat;
47
import java.text.SimpleDateFormat;
47
import java.text.SimpleDateFormat;
48
import java.util.Calendar;
48
import java.util.Calendar;
49
import java.util.Date;
49
import java.util.Date;
50
import java.util.HashMap;
50
import java.util.HashMap;
51
import java.util.List;
51
import java.util.List;
52
import java.util.Map;
52
import java.util.Map;
53
 
53
 
54
import javax.swing.JButton;
54
import javax.swing.JButton;
55
import javax.swing.JCheckBox;
55
import javax.swing.JCheckBox;
56
import javax.swing.JFrame;
56
import javax.swing.JFrame;
57
import javax.swing.JLabel;
57
import javax.swing.JLabel;
58
import javax.swing.JOptionPane;
58
import javax.swing.JOptionPane;
59
import javax.swing.JPanel;
59
import javax.swing.JPanel;
60
import javax.swing.JProgressBar;
60
import javax.swing.JProgressBar;
61
import javax.swing.SwingUtilities;
61
import javax.swing.SwingUtilities;
62
 
62
 
63
import org.apache.commons.dbutils.handlers.ArrayListHandler;
63
import org.apache.commons.dbutils.handlers.ArrayListHandler;
64
 
64
 
65
public class CloturePanel extends JPanel {
65
public class CloturePanel extends JPanel {
66
    private final JDate dateOuv = new JDate();
66
    private final JDate dateOuv = new JDate();
67
    private final JDate dateFerm = new JDate();
67
    private final JDate dateFerm = new JDate();
68
    private SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
68
    private SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
69
    private final SQLTable societe = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");
69
    private final SQLTable societe = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");
70
    private final SQLTable exercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON");
70
    private final SQLTable exercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON");
71
    private final SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
71
    private final SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
72
    private final SQLRow rowExercice = this.exercice.getRow(this.rowSociete.getInt("ID_EXERCICE_COMMON"));
72
    private final SQLRow rowExercice = this.exercice.getRow(this.rowSociete.getInt("ID_EXERCICE_COMMON"));
73
    private final Map<Object, Long> mRAN = new HashMap<Object, Long>();
73
    private final Map<Object, Long> mRAN = new HashMap<Object, Long>();
74
    private JButton valider = new JButton("Valider");
74
    private JButton valider = new JButton("Valider");
75
    private JButton annul = new JButton("Annuler");
75
    private JButton annul = new JButton("Annuler");
76
    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
76
    private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
77
    private JLabel opEnCours = new JLabel("Etat: en attente de validation");
77
    private JLabel opEnCours = new JLabel("Etat: en attente de validation");
78
    private JCheckBox boxValid = new JCheckBox("Je confirme avoir effectué toutes les opérations nécessaires.");
78
    private JCheckBox boxValid = new JCheckBox("Je confirme avoir effectué toutes les opérations nécessaires.");
79
 
79
 
80
    private JProgressBar bar = new JProgressBar(0, 4);
80
    private JProgressBar bar = new JProgressBar(0, 4);
81
 
81
 
82
    public CloturePanel() {
82
    public CloturePanel() {
83
        this.setLayout(new GridBagLayout());
83
        this.setLayout(new GridBagLayout());
84
        final GridBagConstraints c = new DefaultGridBagConstraints();
84
        final GridBagConstraints c = new DefaultGridBagConstraints();
85
        c.fill = GridBagConstraints.HORIZONTAL;
85
        c.fill = GridBagConstraints.HORIZONTAL;
86
        c.anchor = GridBagConstraints.WEST;
86
        c.anchor = GridBagConstraints.WEST;
87
        c.gridx = 0;
87
        c.gridx = 0;
88
        c.gridy = 0;
88
        c.gridy = 0;
89
        c.gridwidth = GridBagConstraints.REMAINDER;
89
        c.gridwidth = GridBagConstraints.REMAINDER;
90
        c.gridheight = 1;
90
        c.gridheight = 1;
91
        c.weightx = 0;
91
        c.weightx = 0;
92
        c.weighty = 0;
92
        c.weighty = 0;
93
 
93
 
94
        JLabel rappel = new JLabelBold("Opérations à effectuer avant de continuer: ");
94
        JLabel rappel = new JLabelBold("Opérations à effectuer avant de continuer: ");
95
        JLabel label = new JLabel("- report des charges et produits constatés d'avance");
95
        JLabel label = new JLabel("- report des charges et produits constatés d'avance");
96
        JLabel label2 = new JLabel("- report des charges à payer et produits à recevoir");
96
        JLabel label2 = new JLabel("- report des charges à payer et produits à recevoir");
97
        JLabel label3 = new JLabel("- impression du bilan, compte de résultat, grand livre, journaux et balance");
97
        JLabel label3 = new JLabel("- impression du bilan, compte de résultat, grand livre, journaux et balance");
98
        JLabel label5 = new JLabel("- génération les écritures comptables des payes");
98
        JLabel label5 = new JLabel("- génération des écritures comptables des payes");
99
        JLabel label4 = new JLabel("Il est préférable de réaliser une sauvegarde avant de continuer.");
99
        JLabel label4 = new JLabel("Il est préférable de réaliser une sauvegarde avant de continuer.");
100
 
100
 
101
        JLabel op = new JLabelBold("Opérations qui vont etre effectuées: ");
101
        JLabel op = new JLabelBold("Opérations qui vont etre effectuées: ");
102
        JLabel labelValid = new JLabel("- validation de toutes les écritures concernant la période de l'exercice.");
102
        JLabel labelValid = new JLabel("- validation de toutes les écritures concernant la période de l'exercice.");
103
        JLabel labelSoldeGestion = new JLabel("- soldes de tous les comptes de gestions 6* et 7*");
103
        JLabel labelSoldeGestion = new JLabel("- soldes de tous les comptes de gestions 6* et 7*");
104
        JLabel labelSoldeBilan = new JLabel("- soldes de tous les comptes de bilan");
104
        JLabel labelSoldeBilan = new JLabel("- soldes de tous les comptes de bilan");
105
        JLabel labelAN = new JLabel("- report des à nouveaux");
105
        JLabel labelAN = new JLabel("- report des à nouveaux");
106
 
106
 
107
        c.gridy = GridBagConstraints.RELATIVE;
107
        c.gridy = GridBagConstraints.RELATIVE;
108
        c.gridx = 0;
108
        c.gridx = 0;
109
 
109
 
110
        // Date de l'ancien exercice
110
        // Date de l'ancien exercice
111
        Calendar dDebut = this.rowExercice.getDate("DATE_DEB");
111
        Calendar dDebut = this.rowExercice.getDate("DATE_DEB");
112
        Calendar dFin = this.rowExercice.getDate("DATE_FIN");
112
        Calendar dFin = this.rowExercice.getDate("DATE_FIN");
113
        JLabel labelAncienExercice = new JLabel("Clôture de l'exercice du " + dateFormat.format(dDebut.getTime()) + " au " + dateFormat.format(dFin.getTime()));
113
        JLabel labelAncienExercice = new JLabel("Clôture de l'exercice du " + dateFormat.format(dDebut.getTime()) + " au " + dateFormat.format(dFin.getTime()));
114
        this.add(labelAncienExercice, c);
114
        this.add(labelAncienExercice, c);
115
        c.insets = new Insets(10, 2, 1, 2);
115
        c.insets = new Insets(10, 2, 1, 2);
116
        this.add(rappel, c);
116
        this.add(rappel, c);
117
        this.add(label, c);
117
        this.add(label, c);
118
        this.add(label2, c);
118
        this.add(label2, c);
119
        this.add(label3, c);
119
        this.add(label3, c);
120
        this.add(label5, c);
120
        this.add(label5, c);
121
        this.add(label4, c);
121
        this.add(label4, c);
122
 
122
 
123
        c.insets = new Insets(15, 2, 1, 2);
123
        c.insets = new Insets(15, 2, 1, 2);
124
        this.add(op, c);
124
        this.add(op, c);
125
 
125
 
126
        c.insets = new Insets(10, 2, 1, 2);
126
        c.insets = new Insets(10, 2, 1, 2);
127
        this.add(labelValid, c);
127
        this.add(labelValid, c);
128
        this.add(labelSoldeGestion, c);
128
        this.add(labelSoldeGestion, c);
129
        this.add(labelSoldeBilan, c);
129
        this.add(labelSoldeBilan, c);
130
        this.add(labelAN, c);
130
        this.add(labelAN, c);
131
 
131
 
132
        // Date du prochain exercice
132
        // Date du prochain exercice
133
        c.gridwidth = 1;
133
        c.gridwidth = 1;
134
        c.gridy = GridBagConstraints.RELATIVE;
134
        c.gridy = GridBagConstraints.RELATIVE;
135
        c.gridx = 0;
135
        c.gridx = 0;
136
        c.gridx = GridBagConstraints.RELATIVE;
136
        c.gridx = GridBagConstraints.RELATIVE;
137
        c.fill = GridBagConstraints.NONE;
137
        c.fill = GridBagConstraints.NONE;
138
 
138
 
139
        this.add(new JLabel("Date du nouvel exercice du "), c);
139
        this.add(new JLabel("Date du nouvel exercice du "), c);
140
 
140
 
141
        dDebut.set(Calendar.YEAR, dDebut.get(Calendar.YEAR) + 1);
141
        dDebut.set(Calendar.YEAR, dDebut.get(Calendar.YEAR) + 1);
142
        this.dateOuv.setValue(dDebut.getTime());
142
        this.dateOuv.setValue(dDebut.getTime());
143
        this.add(this.dateOuv, c);
143
        this.add(this.dateOuv, c);
144
        this.add(new JLabel("au"), c);
144
        this.add(new JLabel("au"), c);
145
        dFin.set(Calendar.YEAR, dFin.get(Calendar.YEAR) + 1);
145
        dFin.set(Calendar.YEAR, dFin.get(Calendar.YEAR) + 1);
146
        this.dateFerm.setValue(dFin.getTime());
146
        this.dateFerm.setValue(dFin.getTime());
147
        this.add(this.dateFerm, c);
147
        this.add(this.dateFerm, c);
148
 
148
 
149
        c.gridx = 0;
149
        c.gridx = 0;
150
        c.fill = GridBagConstraints.HORIZONTAL;
150
        c.fill = GridBagConstraints.HORIZONTAL;
151
        c.gridwidth = 2;
151
        c.gridwidth = 2;
152
        c.weightx = 1;
152
        c.weightx = 1;
153
        this.add(this.opEnCours, c);
153
        this.add(this.opEnCours, c);
154
 
154
 
155
        c.gridwidth = 4;
155
        c.gridwidth = 4;
156
        c.gridx = 0;
156
        c.gridx = 0;
157
        c.weightx = 1;
157
        c.weightx = 1;
158
        this.add(this.bar, c);
158
        this.add(this.bar, c);
159
 
159
 
160
        //
160
        //
161
        this.add(this.boxValid, c);
161
        this.add(this.boxValid, c);
162
 
162
 
163
        // Button
163
        // Button
164
        final JPanel buttonBar = new JPanel();
164
        final JPanel buttonBar = new JPanel();
165
        buttonBar.add(this.valider);
165
        buttonBar.add(this.valider);
166
        buttonBar.add(this.annul);
166
        buttonBar.add(this.annul);
167
 
167
 
168
        c.fill = GridBagConstraints.NONE;
168
        c.fill = GridBagConstraints.NONE;
169
        c.anchor = GridBagConstraints.EAST;
169
        c.anchor = GridBagConstraints.EAST;
170
        c.gridx = 0;
170
        c.gridx = 0;
171
        this.add(buttonBar, c);
171
        this.add(buttonBar, c);
172
 
172
 
173
        final PropertyChangeListener listener = new PropertyChangeListener() {
173
        final PropertyChangeListener listener = new PropertyChangeListener() {
174
            public void propertyChange(PropertyChangeEvent evt) {
174
            public void propertyChange(PropertyChangeEvent evt) {
175
                CloturePanel.this.valider.setEnabled(isDateValid());
175
                CloturePanel.this.valider.setEnabled(isDateValid());
176
            }
176
            }
177
        };
177
        };
178
        this.dateFerm.addValueListener(listener);
178
        this.dateFerm.addValueListener(listener);
179
        this.dateOuv.addValueListener(listener);
179
        this.dateOuv.addValueListener(listener);
180
 
180
 
181
        // TODO afficher le deroulement de etapes apres validation
181
        // TODO afficher le deroulement de etapes apres validation
182
 
182
 
183
        this.valider.addActionListener(new ActionListener() {
183
        this.valider.addActionListener(new ActionListener() {
184
            public void actionPerformed(ActionEvent e) {
184
            public void actionPerformed(ActionEvent e) {
185
 
185
 
186
                valider.setEnabled(false);
186
                valider.setEnabled(false);
187
                dateFerm.setEnabled(false);
187
                dateFerm.setEnabled(false);
188
                dateOuv.setEnabled(false);
188
                dateOuv.setEnabled(false);
189
 
189
 
190
                new Thread(new Runnable() {
190
                new Thread(new Runnable() {
191
                    public void run() {
191
                    public void run() {
192
                        try {
192
                        try {
193
                            clotureExercice();
193
                            clotureExercice();
194
                            SwingUtilities.invokeLater(new Runnable() {
194
                            SwingUtilities.invokeLater(new Runnable() {
195
                                public void run() {
195
                                public void run() {
196
                                    // show OK works fine
196
                                    // show OK works fine
197
                                    Component comp = SwingUtilities.getRoot(CloturePanel.this);
197
                                    Component comp = SwingUtilities.getRoot(CloturePanel.this);
198
                                    JOptionPane.showMessageDialog(CloturePanel.this, "Exercice clôturé", "Fin de la clôture", JOptionPane.INFORMATION_MESSAGE);
198
                                    JOptionPane.showMessageDialog(CloturePanel.this, "Exercice clôturé", "Fin de la clôture", JOptionPane.INFORMATION_MESSAGE);
199
                                    if (comp != null) {
199
                                    if (comp != null) {
200
                                        ((JFrame) comp).dispose();
200
                                        ((JFrame) comp).dispose();
201
                                    }
201
                                    }
202
                                }
202
                                }
203
                            });
203
                            });
204
                        } catch (Exception ex) {
204
                        } catch (Exception ex) {
205
                            ExceptionHandler.handle("Erreur lors de la clôture", ex);
205
                            ExceptionHandler.handle("Erreur lors de la clôture", ex);
206
                        }
206
                        }
207
                    }
207
                    }
208
                }).start();
208
                }).start();
209
 
209
 
210
            }
210
            }
211
        });
211
        });
212
 
212
 
213
        this.valider.setEnabled(isDateValid());
213
        this.valider.setEnabled(isDateValid());
214
 
214
 
215
        this.boxValid.addActionListener(new ActionListener() {
215
        this.boxValid.addActionListener(new ActionListener() {
216
 
216
 
217
            @Override
217
            @Override
218
            public void actionPerformed(ActionEvent e) {
218
            public void actionPerformed(ActionEvent e) {
219
                CloturePanel.this.valider.setEnabled(isDateValid());
219
                CloturePanel.this.valider.setEnabled(isDateValid());
220
            }
220
            }
221
        });
221
        });
222
 
222
 
223
        this.annul.addActionListener(new ActionListener() {
223
        this.annul.addActionListener(new ActionListener() {
224
            public void actionPerformed(ActionEvent e) {
224
            public void actionPerformed(ActionEvent e) {
225
 
225
 
226
                ((JFrame) SwingUtilities.getRoot(CloturePanel.this)).dispose();
226
                ((JFrame) SwingUtilities.getRoot(CloturePanel.this)).dispose();
227
            }
227
            }
228
        });
228
        });
229
    }
229
    }
230
 
230
 
231
    private boolean isDateValid() {
231
    private boolean isDateValid() {
232
        final Date d = (Date) this.rowExercice.getObject("DATE_FIN");
232
        final Date d = (Date) this.rowExercice.getObject("DATE_FIN");
233
        return this.boxValid.isSelected() && (((!this.dateFerm.isEmpty()) && (!this.dateOuv.isEmpty()) && (this.dateFerm.getValue().getTime() > this.dateOuv.getValue().getTime())
233
        return this.boxValid.isSelected() && (((!this.dateFerm.isEmpty()) && (!this.dateOuv.isEmpty()) && (this.dateFerm.getValue().getTime() > this.dateOuv.getValue().getTime())
234
                && (this.dateOuv.getValue().getTime() > d.getTime())));
234
                && (this.dateOuv.getValue().getTime() > d.getTime())));
235
    }
235
    }
236
 
236
 
237
    private final SQLTable tablePrefCompte = this.base.getTable("PREFS_COMPTE");
237
    private final SQLTable tablePrefCompte = this.base.getTable("PREFS_COMPTE");
238
 
238
 
239
    private void clotureExercice() throws SQLException {
239
    private void clotureExercice() throws SQLException {
240
 
240
 
241
        final SQLRow rowPrefCompte = this.tablePrefCompte.getRow(2);
241
        final SQLRow rowPrefCompte = this.tablePrefCompte.getRow(2);
242
        final int id_Compte_Bilan_Ouverture;
242
        final int id_Compte_Bilan_Ouverture;
243
        if (rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_O") <= 1) {
243
        if (rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_O") <= 1) {
244
            id_Compte_Bilan_Ouverture = ComptePCESQLElement.getId("890");
244
            id_Compte_Bilan_Ouverture = ComptePCESQLElement.getId("890");
245
        } else {
245
        } else {
246
            id_Compte_Bilan_Ouverture = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_O");
246
            id_Compte_Bilan_Ouverture = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_O");
247
        }
247
        }
248
 
248
 
249
        final int id_Compte_Bilan_Cloture;
249
        final int id_Compte_Bilan_Cloture;
250
        if (rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F") <= 1) {
250
        if (rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F") <= 1) {
251
            id_Compte_Bilan_Cloture = ComptePCESQLElement.getId("891");
251
            id_Compte_Bilan_Cloture = ComptePCESQLElement.getId("891");
252
        } else {
252
        } else {
253
            id_Compte_Bilan_Cloture = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F");
253
            id_Compte_Bilan_Cloture = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F");
254
        }
254
        }
255
 
255
 
256
        /*******************************************************************************************
256
        /*******************************************************************************************
257
         * Validation des écritures
257
         * Validation des écritures
258
         ******************************************************************************************/
258
         ******************************************************************************************/
259
        EcritureSQLElement.validationEcrituresBefore((Date) this.rowExercice.getObject("DATE_FIN"), true);
259
        EcritureSQLElement.validationEcrituresBefore((Date) this.rowExercice.getObject("DATE_FIN"), true);
260
 
260
 
261
        SQLUtils.executeAtomic(this.tablePrefCompte.getDBSystemRoot().getDataSource(), new SQLUtils.SQLFactory<Object>() {
261
        SQLUtils.executeAtomic(this.tablePrefCompte.getDBSystemRoot().getDataSource(), new SQLUtils.SQLFactory<Object>() {
262
            @Override
262
            @Override
263
            public Object create() throws SQLException {
263
            public Object create() throws SQLException {
264
 
264
 
265
                /*******************************************************************************************
265
                /*******************************************************************************************
266
                 * Solde des comptes de gestion 6* et 7* (génération du résultat)
266
                 * Solde des comptes de gestion 6* et 7* (génération du résultat)
267
                 ******************************************************************************************/
267
                 ******************************************************************************************/
268
                SwingUtilities.invokeLater(new Runnable() {
268
                SwingUtilities.invokeLater(new Runnable() {
269
                    public void run() {
269
                    public void run() {
270
                        CloturePanel.this.opEnCours.setText("En cours: solde des comptes 6 et 7");
270
                        CloturePanel.this.opEnCours.setText("En cours: solde des comptes 6 et 7");
271
                    }
271
                    }
272
                });
272
                });
273
                long time = new Date().getTime();
273
                long time = new Date().getTime();
274
                System.err.println("Start :: " + time);
274
                System.err.println("Start :: " + time);
275
                soldeCompte(false);
275
                soldeCompte(false);
276
 
276
 
277
                /*******************************************************************************************
277
                /*******************************************************************************************
278
                 * Solde des autres comptes (comptes de bilan)
278
                 * Solde des autres comptes (comptes de bilan)
279
                 ******************************************************************************************/
279
                 ******************************************************************************************/
280
                SwingUtilities.invokeLater(new Runnable() {
280
                SwingUtilities.invokeLater(new Runnable() {
281
                    public void run() {
281
                    public void run() {
282
                        CloturePanel.this.opEnCours.setText("En cours: solde des comptes autres que 6 et 7");
282
                        CloturePanel.this.opEnCours.setText("En cours: solde des comptes autres que 6 et 7");
283
                        CloturePanel.this.bar.setValue(1);
283
                        CloturePanel.this.bar.setValue(1);
284
                    }
284
                    }
285
                });
285
                });
286
                soldeCompte(true);
286
                soldeCompte(true);
287
 
287
 
288
                long time2 = new Date().getTime();
288
                long time2 = new Date().getTime();
289
                System.err.println("Stop :: " + time2);
289
                System.err.println("Stop :: " + time2);
290
                System.err.println("Time :: " + (time2 - time));
290
                System.err.println("Time :: " + (time2 - time));
291
 
291
 
292
                /*******************************************************************************************
292
                /*******************************************************************************************
293
                 * Reouverture des comptes de bilan
293
                 * Reouverture des comptes de bilan
294
                 ******************************************************************************************/
294
                 ******************************************************************************************/
295
                SwingUtilities.invokeLater(new Runnable() {
295
                SwingUtilities.invokeLater(new Runnable() {
296
                    public void run() {
296
                    public void run() {
297
                        CloturePanel.this.opEnCours.setText("En cours: report des à nouveaux");
297
                        CloturePanel.this.opEnCours.setText("En cours: report des à nouveaux");
298
                        CloturePanel.this.bar.setValue(2);
298
                        CloturePanel.this.bar.setValue(2);
299
                    }
299
                    }
300
                });
300
                });
301
                // transfert du compte bilan fermeture vers le compte bilan ouverture
301
                // transfert du compte bilan fermeture vers le compte bilan ouverture
302
                SQLTable ecritureTable = CloturePanel.this.base.getTable("ECRITURE");
302
                SQLTable ecritureTable = CloturePanel.this.base.getTable("ECRITURE");
303
                SQLTable compteTable = CloturePanel.this.base.getTable("COMPTE_PCE");
303
                SQLTable compteTable = CloturePanel.this.base.getTable("COMPTE_PCE");
304
                SQLSelect sel = new SQLSelect(CloturePanel.this.base);
304
                SQLSelect sel = new SQLSelect(CloturePanel.this.base);
305
 
305
 
306
                sel.addSelect(compteTable.getKey());
306
                sel.addSelect(compteTable.getKey());
307
                sel.addSelect(compteTable.getField("NUMERO"));
307
                sel.addSelect(compteTable.getField("NUMERO"));
308
                sel.addSelect(compteTable.getField("NOM"));
308
                sel.addSelect(compteTable.getField("NOM"));
309
                sel.addSelect(ecritureTable.getField("DEBIT"), "SUM");
309
                sel.addSelect(ecritureTable.getField("DEBIT"), "SUM");
310
                sel.addSelect(ecritureTable.getField("CREDIT"), "SUM");
310
                sel.addSelect(ecritureTable.getField("CREDIT"), "SUM");
311
 
311
 
312
                Where w = new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", id_Compte_Bilan_Cloture);
312
                Where w = new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", id_Compte_Bilan_Cloture);
313
                w = w.and(new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", compteTable.getKey()));
313
                w = w.and(new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", compteTable.getKey()));
314
                sel.setWhere(w);
314
                sel.setWhere(w);
315
 
315
 
316
                String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\", \"COMPTE_PCE\".\"NUMERO\", \"COMPTE_PCE\".\"NOM\" ORDER BY \"COMPTE_PCE\".\"NUMERO\"";
316
                String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\", \"COMPTE_PCE\".\"NUMERO\", \"COMPTE_PCE\".\"NOM\" ORDER BY \"COMPTE_PCE\".\"NUMERO\"";
317
                System.out.println(req);
317
                System.out.println(req);
318
 
318
 
319
                Object ob = CloturePanel.this.base.getDataSource().execute(req, new ArrayListHandler());
319
                Object ob = CloturePanel.this.base.getDataSource().execute(req, new ArrayListHandler());
320
 
320
 
321
                List myList = (List) ob;
321
                List myList = (List) ob;
322
 
322
 
323
                if (myList.size() != 0) {
323
                if (myList.size() != 0) {
324
                    GenerationMvtVirement gen = new GenerationMvtVirement(1, id_Compte_Bilan_Cloture, 0, 0, "Fermeture du compte ", CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(),
324
                    GenerationMvtVirement gen = new GenerationMvtVirement(1, id_Compte_Bilan_Cloture, 0, 0, "Fermeture du compte ", CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(),
325
                            JournalSQLElement.OD, "Fermeture des comptes");
325
                            JournalSQLElement.OD, "Fermeture des comptes");
326
                    gen.setFermeture(true);
326
                    gen.setFermeture(true);
327
                    for (int i = 0; i < myList.size(); i++) {
327
                    for (int i = 0; i < myList.size(); i++) {
328
 
328
 
329
                        Object[] objTmp = (Object[]) myList.get(i);
329
                        Object[] objTmp = (Object[]) myList.get(i);
330
                        Compte cptTmp = new Compte(((Number) objTmp[0]).intValue(), objTmp[1].toString(), objTmp[2].toString(), "", ((Number) objTmp[3]).longValue(), ((Number) objTmp[4]).longValue());
330
                        Compte cptTmp = new Compte(((Number) objTmp[0]).intValue(), objTmp[1].toString(), objTmp[2].toString(), "", ((Number) objTmp[3]).longValue(), ((Number) objTmp[4]).longValue());
331
                        // vecteurCompte.add(cptTmp);
331
                        // vecteurCompte.add(cptTmp);
332
 
332
 
333
                        long solde = cptTmp.getTotalDebit() - cptTmp.getTotalCredit();
333
                        long solde = cptTmp.getTotalDebit() - cptTmp.getTotalCredit();
334
 
334
 
335
                        if (solde != 0) {
335
                        if (solde != 0) {
336
                            if (solde > 0) {
336
                            if (solde > 0) {
337
                                gen.setValues(cptTmp.getId(), id_Compte_Bilan_Cloture, 0, Math.abs(solde), "Fermeture du compte " + cptTmp.getNumero(),
337
                                gen.setValues(cptTmp.getId(), id_Compte_Bilan_Cloture, 0, Math.abs(solde), "Fermeture du compte " + cptTmp.getNumero(),
338
                                        CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD, false);
338
                                        CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD, false);
339
 
339
 
340
                            } else {
340
                            } else {
341
                                gen.setValues(cptTmp.getId(), id_Compte_Bilan_Cloture, Math.abs(solde), 0, "Fermeture du compte " + cptTmp.getNumero(),
341
                                gen.setValues(cptTmp.getId(), id_Compte_Bilan_Cloture, Math.abs(solde), 0, "Fermeture du compte " + cptTmp.getNumero(),
342
                                        CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD, false);
342
                                        CloturePanel.this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD, false);
343
                            }
343
                            }
344
                            gen.genereMouvement();
344
                            gen.genereMouvement();
345
                        }
345
                        }
346
                    }
346
                    }
347
                }
347
                }
348
                /*******************************************************************************************
348
                /*******************************************************************************************
349
                 * Validation des écritures de clotures
349
                 * Validation des écritures de clotures
350
                 ******************************************************************************************/
350
                 ******************************************************************************************/
351
                SwingUtilities.invokeLater(new Runnable() {
351
                SwingUtilities.invokeLater(new Runnable() {
352
                    public void run() {
352
                    public void run() {
353
                        CloturePanel.this.opEnCours.setText("En cours: validation des écritures de l'exercice");
353
                        CloturePanel.this.opEnCours.setText("En cours: validation des écritures de l'exercice");
354
                        CloturePanel.this.bar.setValue(3);
354
                        CloturePanel.this.bar.setValue(3);
355
                    }
355
                    }
356
                });
356
                });
357
                EcritureSQLElement.validationEcrituresBefore((Date) CloturePanel.this.rowExercice.getObject("DATE_FIN"), true);
357
                EcritureSQLElement.validationEcrituresBefore((Date) CloturePanel.this.rowExercice.getObject("DATE_FIN"), true);
358
 
358
 
359
                // A nouveaux
359
                // A nouveaux
360
                Object[] compteAnouveau = CloturePanel.this.mRAN.keySet().toArray();
360
                Object[] compteAnouveau = CloturePanel.this.mRAN.keySet().toArray();
361
                int journalAN = JournalSQLElement.OD;
361
                int journalAN = JournalSQLElement.OD;
362
                if (rowPrefCompte.getObject("ID_JOURNAL_AN") != null && !rowPrefCompte.isForeignEmpty("ID_JOURNAL_AN")) {
362
                if (rowPrefCompte.getObject("ID_JOURNAL_AN") != null && !rowPrefCompte.isForeignEmpty("ID_JOURNAL_AN")) {
363
                    journalAN = rowPrefCompte.getForeignID("ID_JOURNAL_AN");
363
                    journalAN = rowPrefCompte.getForeignID("ID_JOURNAL_AN");
364
                }
364
                }
365
                GenerationMvtVirement genAnouveaux = new GenerationMvtVirement(id_Compte_Bilan_Ouverture, 1, 0, 0, "A nouveaux", CloturePanel.this.dateOuv.getValue(), journalAN, "A nouveaux");
365
                GenerationMvtVirement genAnouveaux = new GenerationMvtVirement(id_Compte_Bilan_Ouverture, 1, 0, 0, "A nouveaux", CloturePanel.this.dateOuv.getValue(), journalAN, "A nouveaux");
366
                genAnouveaux.setOuverture(true);
366
                genAnouveaux.setOuverture(true);
367
                for (int i = 0; i < CloturePanel.this.mRAN.keySet().size(); i++) {
367
                for (int i = 0; i < CloturePanel.this.mRAN.keySet().size(); i++) {
368
 
368
 
369
                    long solde = CloturePanel.this.mRAN.get(compteAnouveau[i]).longValue();
369
                    long solde = CloturePanel.this.mRAN.get(compteAnouveau[i]).longValue();
370
 
370
 
371
                    // if (solde != 0) {
371
                    // if (solde != 0) {
372
                    if (solde > 0) {
372
                    if (solde > 0) {
373
                        genAnouveaux.setValues(id_Compte_Bilan_Ouverture, Integer.parseInt(compteAnouveau[i].toString()), 0, Math.abs(solde), "A nouveaux", CloturePanel.this.dateOuv.getValue(),
373
                        genAnouveaux.setValues(id_Compte_Bilan_Ouverture, Integer.parseInt(compteAnouveau[i].toString()), 0, Math.abs(solde), "A nouveaux", CloturePanel.this.dateOuv.getValue(),
374
                                journalAN, false);
374
                                journalAN, false);
375
                    } else {
375
                    } else {
376
                        genAnouveaux.setValues(id_Compte_Bilan_Ouverture, Integer.parseInt(compteAnouveau[i].toString()), Math.abs(solde), 0, "A nouveaux", CloturePanel.this.dateOuv.getValue(),
376
                        genAnouveaux.setValues(id_Compte_Bilan_Ouverture, Integer.parseInt(compteAnouveau[i].toString()), Math.abs(solde), 0, "A nouveaux", CloturePanel.this.dateOuv.getValue(),
377
                                journalAN, false);
377
                                journalAN, false);
378
                    }
378
                    }
379
                    genAnouveaux.genereMouvement();
379
                    genAnouveaux.genereMouvement();
380
                    // }
380
                    // }
381
                }
381
                }
382
 
382
 
383
                // Fixé la nouvel date de l'exercice
383
                // Fixé la nouvel date de l'exercice
384
                SQLRowValues valsExercice = new SQLRowValues(CloturePanel.this.exercice);
384
                SQLRowValues valsExercice = new SQLRowValues(CloturePanel.this.exercice);
385
                valsExercice.put("CLOTURE", Boolean.TRUE);
385
                valsExercice.put("CLOTURE", Boolean.TRUE);
386
                valsExercice.update(CloturePanel.this.rowExercice.getID());
386
                valsExercice.update(CloturePanel.this.rowExercice.getID());
387
 
387
 
388
                // Creation d'un nouvel exercice
388
                // Creation d'un nouvel exercice
389
                valsExercice.put("CLOTURE", Boolean.FALSE);
389
                valsExercice.put("CLOTURE", Boolean.FALSE);
390
                valsExercice.put("DATE_DEB", new java.sql.Date(CloturePanel.this.dateOuv.getValue().getTime()));
390
                valsExercice.put("DATE_DEB", new java.sql.Date(CloturePanel.this.dateOuv.getValue().getTime()));
391
                valsExercice.put("DATE_FIN", new java.sql.Date(CloturePanel.this.dateFerm.getValue().getTime()));
391
                valsExercice.put("DATE_FIN", new java.sql.Date(CloturePanel.this.dateFerm.getValue().getTime()));
392
                valsExercice.put("ID_SOCIETE_COMMON", CloturePanel.this.rowSociete.getID());
392
                valsExercice.put("ID_SOCIETE_COMMON", CloturePanel.this.rowSociete.getID());
393
                SQLRow rowNewEx = valsExercice.insert();
393
                SQLRow rowNewEx = valsExercice.insert();
394
 
394
 
395
                // mise a jour de l'exercice de la societe
395
                // mise a jour de l'exercice de la societe
396
                SQLRowValues rowValsSociete = new SQLRowValues(CloturePanel.this.societe);
396
                SQLRowValues rowValsSociete = new SQLRowValues(CloturePanel.this.societe);
397
                rowValsSociete.put("ID_EXERCICE_COMMON", rowNewEx.getID());
397
                rowValsSociete.put("ID_EXERCICE_COMMON", rowNewEx.getID());
398
                rowValsSociete.update(CloturePanel.this.rowSociete.getID());
398
                rowValsSociete.update(CloturePanel.this.rowSociete.getID());
399
                // Recharge les informations de la societe pour pointer sur le nouvel exercice
399
                // Recharge les informations de la societe pour pointer sur le nouvel exercice
400
                ComptaPropsConfiguration.getInstanceCompta().getRowSociete().fetchValues();
400
                ComptaPropsConfiguration.getInstanceCompta().getRowSociete().fetchValues();
401
                SwingUtilities.invokeLater(new Runnable() {
401
                SwingUtilities.invokeLater(new Runnable() {
402
                    public void run() {
402
                    public void run() {
403
                        CloturePanel.this.bar.setValue(4);
403
                        CloturePanel.this.bar.setValue(4);
404
                        CloturePanel.this.opEnCours.setText("Etat: clôture terminée");
404
                        CloturePanel.this.opEnCours.setText("Etat: clôture terminée");
405
                    }
405
                    }
406
                });
406
                });
407
 
407
 
408
                return null;
408
                return null;
409
            }
409
            }
410
        });
410
        });
411
    }
411
    }
412
 
412
 
413
    private void soldeCompte(boolean compteBilan) throws SQLException {
413
    private void soldeCompte(boolean compteBilan) throws SQLException {
414
 
414
 
415
        String typeCompte;
415
        String typeCompte;
416
        int compteDest;
416
        int compteDest;
417
 
417
 
418
        SQLRow rowPrefCompte = this.tablePrefCompte.getRow(2);
418
        SQLRow rowPrefCompte = this.tablePrefCompte.getRow(2);
419
        if (compteBilan) {
419
        if (compteBilan) {
420
            typeCompte = "^[^6-8].*$";
420
            typeCompte = "^[^6-8].*$";
421
            compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F");
421
            compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_BILAN_F");
422
            if (compteDest <= 1) {
422
            if (compteDest <= 1) {
423
                compteDest = ComptePCESQLElement.getId("891", "Bilan de clôture");
423
                compteDest = ComptePCESQLElement.getId("891", "Bilan de clôture");
424
            }
424
            }
425
        } else {
425
        } else {
426
            SommeCompte s = new SommeCompte();
426
            SommeCompte s = new SommeCompte();
427
            long solde6 = s.soldeCompte(6, 6, true, this.rowExercice.getDate("DATE_DEB").getTime(), this.rowExercice.getDate("DATE_FIN").getTime());
427
            long solde6 = s.soldeCompte(6, 6, true, this.rowExercice.getDate("DATE_DEB").getTime(), this.rowExercice.getDate("DATE_FIN").getTime());
428
            long solde7 = s.soldeCompte(7, 7, true, this.rowExercice.getDate("DATE_DEB").getTime(), this.rowExercice.getDate("DATE_FIN").getTime());
428
            long solde7 = s.soldeCompte(7, 7, true, this.rowExercice.getDate("DATE_DEB").getTime(), this.rowExercice.getDate("DATE_FIN").getTime());
429
            long resultat = -solde7 - solde6;
429
            long resultat = -solde7 - solde6;
430
            System.err.println("Solde Résultat :::: " + solde7 + " __ " + solde6 + "__" + (solde7 - solde6));
430
            System.err.println("Solde Résultat :::: " + solde7 + " __ " + solde6 + "__" + (solde7 - solde6));
431
            typeCompte = "^(6|7).*$";
431
            typeCompte = "^(6|7).*$";
432
 
432
 
433
            if (resultat > 0) {
433
            if (resultat > 0) {
434
                compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_RESULTAT");
434
                compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_RESULTAT");
435
            } else {
435
            } else {
436
                compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_RESULTAT_PERTE");
436
                compteDest = rowPrefCompte.getInt("ID_COMPTE_PCE_RESULTAT_PERTE");
437
            }
437
            }
438
 
438
 
439
            if (compteDest <= 1) {
439
            if (compteDest <= 1) {
440
                if (resultat > 0) {
440
                if (resultat > 0) {
441
                    compteDest = ComptePCESQLElement.getId("120", "Résultat de l'exercice (bénéfice)");
441
                    compteDest = ComptePCESQLElement.getId("120", "Résultat de l'exercice (bénéfice)");
442
                } else {
442
                } else {
443
                    compteDest = ComptePCESQLElement.getId("129", "Résultat de l'exercice (perte)");
443
                    compteDest = ComptePCESQLElement.getId("129", "Résultat de l'exercice (perte)");
444
                }
444
                }
445
            }
445
            }
446
        }
446
        }
447
 
447
 
448
        // on récupére les comptes avec leurs totaux
448
        // on récupére les comptes avec leurs totaux
449
        SQLTable ecritureTable = this.base.getTable("ECRITURE");
449
        SQLTable ecritureTable = this.base.getTable("ECRITURE");
450
        SQLTable compteTable = this.base.getTable("COMPTE_PCE");
450
        SQLTable compteTable = this.base.getTable("COMPTE_PCE");
451
        SQLSelect sel = new SQLSelect(this.base);
451
        SQLSelect sel = new SQLSelect(this.base);
452
 
452
 
453
        sel.addSelect(compteTable.getKey());
453
        sel.addSelect(compteTable.getKey());
454
        sel.addSelect(compteTable.getField("NUMERO"));
454
        sel.addSelect(compteTable.getField("NUMERO"));
455
        sel.addSelect(compteTable.getField("NOM"));
455
        sel.addSelect(compteTable.getField("NOM"));
456
        sel.addSelect(ecritureTable.getField("DEBIT"), "SUM");
456
        sel.addSelect(ecritureTable.getField("DEBIT"), "SUM");
457
        sel.addSelect(ecritureTable.getField("CREDIT"), "SUM");
457
        sel.addSelect(ecritureTable.getField("CREDIT"), "SUM");
458
 
458
 
459
        Where w = new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", compteTable.getKey());
459
        Where w = new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", compteTable.getKey());
460
 
460
 
461
        String function = "REGEXP";
461
        String function = "REGEXP";
462
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
462
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
463
            // function = "SIMILAR TO";
463
            // function = "SIMILAR TO";
464
            // typeCompte = typeCompte.replace(".*", "%");
464
            // typeCompte = typeCompte.replace(".*", "%");
465
            function = "~";
465
            function = "~";
466
        }
466
        }
467
 
467
 
468
        Where w2 = new Where(compteTable.getField("NUMERO"), function, typeCompte);
468
        Where w2 = new Where(compteTable.getField("NUMERO"), function, typeCompte);
469
        Where w3 = new Where(ecritureTable.getField("DATE"), "<=", this.rowExercice.getObject("DATE_FIN"));
469
        Where w3 = new Where(ecritureTable.getField("DATE"), "<=", this.rowExercice.getObject("DATE_FIN"));
470
        sel.setWhere(w.and(w2).and(w3));
470
        sel.setWhere(w.and(w2).and(w3));
471
 
471
 
472
        String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\", \"COMPTE_PCE\".\"NUMERO\", \"COMPTE_PCE\".\"NOM\" ORDER BY \"COMPTE_PCE\".\"NUMERO\"";
472
        String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\", \"COMPTE_PCE\".\"NUMERO\", \"COMPTE_PCE\".\"NOM\" ORDER BY \"COMPTE_PCE\".\"NUMERO\"";
473
        System.err.println(req);
473
        System.err.println(req);
474
 
474
 
475
        Object ob = this.base.getDataSource().execute(req, new ArrayListHandler());
475
        Object ob = this.base.getDataSource().execute(req, new ArrayListHandler());
476
 
476
 
477
        List myList = (List) ob;
477
        List myList = (List) ob;
478
 
478
 
479
        if (myList != null && myList.size() != 0) {
479
        if (myList != null && myList.size() != 0) {
480
            boolean genSoldeNul = true;
480
            boolean genSoldeNul = true;
481
            if (rowPrefCompte.getObject("CREATE_NUL_SOLDE_ECR") != null) {
481
            if (rowPrefCompte.getObject("CREATE_NUL_SOLDE_ECR") != null) {
482
                genSoldeNul = rowPrefCompte.getBoolean("CREATE_NUL_SOLDE_ECR");
482
                genSoldeNul = rowPrefCompte.getBoolean("CREATE_NUL_SOLDE_ECR");
483
            }
483
            }
484
            GenerationMvtVirement genFerm = new GenerationMvtVirement(1, compteDest, 0, 0, "Fermeture du compte ", this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD,
484
            GenerationMvtVirement genFerm = new GenerationMvtVirement(1, compteDest, 0, 0, "Fermeture du compte ", this.rowExercice.getDate("DATE_FIN").getTime(), JournalSQLElement.OD,
485
                    "Fermeture des comptes");
485
                    "Fermeture des comptes");
486
            genFerm.setFermeture(true);
486
            genFerm.setFermeture(true);
487
            for (int i = 0; i < myList.size(); i++) {
487
            for (int i = 0; i < myList.size(); i++) {
488
 
488
 
489
                Object[] objTmp = (Object[]) myList.get(i);
489
                Object[] objTmp = (Object[]) myList.get(i);
490
                Compte cptTmp = new Compte(((Number) objTmp[0]).intValue(), objTmp[1].toString(), objTmp[2].toString(), "", ((Number) objTmp[3]).longValue(), ((Number) objTmp[4]).longValue());
490
                Compte cptTmp = new Compte(((Number) objTmp[0]).intValue(), objTmp[1].toString(), objTmp[2].toString(), "", ((Number) objTmp[3]).longValue(), ((Number) objTmp[4]).longValue());
491
 
491
 
492
                long solde = cptTmp.getTotalDebit() - cptTmp.getTotalCredit();
492
                long solde = cptTmp.getTotalDebit() - cptTmp.getTotalCredit();
493
 
493
 
494
                if (genSoldeNul || solde != 0) {
494
                if (genSoldeNul || solde != 0) {
495
                    if (compteBilan) {
495
                    if (compteBilan) {
496
                        this.mRAN.put(objTmp[0], Long.valueOf(solde));
496
                        this.mRAN.put(objTmp[0], Long.valueOf(solde));
497
                    }
497
                    }
498
 
498
 
499
                    if (solde > 0) {
499
                    if (solde > 0) {
500
                        genFerm.setValues(cptTmp.getId(), compteDest, 0, Math.abs(solde), "Fermeture du compte " + cptTmp.getNumero(), this.rowExercice.getDate("DATE_FIN").getTime(),
500
                        genFerm.setValues(cptTmp.getId(), compteDest, 0, Math.abs(solde), "Fermeture du compte " + cptTmp.getNumero(), this.rowExercice.getDate("DATE_FIN").getTime(),
501
                                JournalSQLElement.OD, false);
501
                                JournalSQLElement.OD, false);
502
                    } else {
502
                    } else {
503
 
503
 
504
                        genFerm.setValues(cptTmp.getId(), compteDest, Math.abs(solde), 0, "Fermeture du compte " + cptTmp.getNumero(), this.rowExercice.getDate("DATE_FIN").getTime(),
504
                        genFerm.setValues(cptTmp.getId(), compteDest, Math.abs(solde), 0, "Fermeture du compte " + cptTmp.getNumero(), this.rowExercice.getDate("DATE_FIN").getTime(),
505
                                JournalSQLElement.OD, false);
505
                                JournalSQLElement.OD, false);
506
                    }
506
                    }
507
                    genFerm.genereMouvement();
507
                    genFerm.genereMouvement();
508
                }
508
                }
509
            }
509
            }
510
            // }
510
            // }
511
        }
511
        }
512
    }
512
    }
513
}
513
}