OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 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.common.element.NumerotationAutoSQLElement;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
18
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
19
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
-
 
21
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement;
21
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
22
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel;
23
import org.openconcerto.erp.core.finance.accounting.model.LettrageModel;
23
import org.openconcerto.erp.model.ISQLCompteSelector;
24
import org.openconcerto.erp.model.ISQLCompteSelector;
24
import org.openconcerto.erp.rights.ComptaUserRight;
25
import org.openconcerto.erp.rights.ComptaUserRight;
-
 
26
import org.openconcerto.erp.utils.LowerCaseFormatFilter;
25
import org.openconcerto.erp.utils.UpperCaseFormatFilter;
27
import org.openconcerto.erp.utils.UpperCaseFormatFilter;
26
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.Configuration;
27
import org.openconcerto.sql.element.SQLElement;
29
import org.openconcerto.sql.element.SQLElement;
28
import org.openconcerto.sql.element.SQLElementDirectory;
30
import org.openconcerto.sql.element.SQLElementDirectory;
29
import org.openconcerto.sql.model.SQLBase;
31
import org.openconcerto.sql.model.SQLBase;
30
import org.openconcerto.sql.model.SQLRow;
32
import org.openconcerto.sql.model.SQLRow;
-
 
33
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
34
import org.openconcerto.sql.model.SQLRowListRSH;
31
import org.openconcerto.sql.model.SQLRowValues;
35
import org.openconcerto.sql.model.SQLRowValues;
-
 
36
import org.openconcerto.sql.model.SQLSelect;
32
import org.openconcerto.sql.model.SQLSystem;
37
import org.openconcerto.sql.model.SQLSystem;
33
import org.openconcerto.sql.model.SQLTable;
38
import org.openconcerto.sql.model.SQLTable;
-
 
39
import org.openconcerto.sql.model.UndefinedRowValuesCache;
34
import org.openconcerto.sql.model.Where;
40
import org.openconcerto.sql.model.Where;
35
import org.openconcerto.sql.request.ComboSQLRequest;
41
import org.openconcerto.sql.request.ComboSQLRequest;
36
import org.openconcerto.sql.users.rights.UserRightsManager;
42
import org.openconcerto.sql.users.rights.UserRightsManager;
-
 
43
import org.openconcerto.sql.view.EditFrame;
-
 
44
import org.openconcerto.sql.view.EditPanel.EditMode;
-
 
45
import org.openconcerto.sql.view.EditPanelListener;
37
import org.openconcerto.sql.view.list.IListe;
46
import org.openconcerto.sql.view.list.IListe;
-
 
47
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
48
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
49
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.FontUtils;
50
import org.openconcerto.ui.FontUtils;
40
import org.openconcerto.ui.JDate;
51
import org.openconcerto.ui.JDate;
41
import org.openconcerto.ui.TitledSeparator;
52
import org.openconcerto.ui.TitledSeparator;
42
import org.openconcerto.ui.warning.JLabelWarning;
53
import org.openconcerto.ui.warning.JLabelWarning;
-
 
54
import org.openconcerto.utils.ExceptionHandler;
-
 
55
import org.openconcerto.utils.ListMap;
43
import org.openconcerto.utils.text.DocumentFilterList;
56
import org.openconcerto.utils.text.DocumentFilterList;
44
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
57
import org.openconcerto.utils.text.DocumentFilterList.FilterType;
45
import org.openconcerto.utils.text.SimpleDocumentListener;
58
import org.openconcerto.utils.text.SimpleDocumentListener;
46
 
59
 
47
import java.awt.Color;
60
import java.awt.Color;
48
import java.awt.Component;
61
import java.awt.Component;
49
import java.awt.Dimension;
62
import java.awt.Dimension;
50
import java.awt.GridBagConstraints;
63
import java.awt.GridBagConstraints;
51
import java.awt.GridBagLayout;
64
import java.awt.GridBagLayout;
52
import java.awt.Insets;
65
import java.awt.Insets;
53
import java.awt.Window;
66
import java.awt.Window;
54
import java.awt.event.ActionEvent;
67
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
68
import java.awt.event.ActionListener;
56
import java.awt.event.KeyAdapter;
69
import java.awt.event.KeyAdapter;
57
import java.awt.event.KeyEvent;
70
import java.awt.event.KeyEvent;
58
import java.awt.event.MouseAdapter;
71
import java.awt.event.MouseAdapter;
59
import java.awt.event.MouseEvent;
72
import java.awt.event.MouseEvent;
60
import java.beans.PropertyChangeEvent;
73
import java.beans.PropertyChangeEvent;
61
import java.beans.PropertyChangeListener;
74
import java.beans.PropertyChangeListener;
62
import java.sql.SQLException;
75
import java.sql.SQLException;
63
import java.text.ParseException;
76
import java.text.ParseException;
64
import java.util.ArrayList;
77
import java.util.ArrayList;
65
import java.util.Date;
78
import java.util.Date;
-
 
79
import java.util.HashMap;
66
import java.util.List;
80
import java.util.List;
-
 
81
import java.util.Map;
-
 
82
import java.util.Map.Entry;
67
 
83
 
68
import javax.swing.AbstractAction;
84
import javax.swing.AbstractAction;
69
import javax.swing.BorderFactory;
85
import javax.swing.BorderFactory;
70
import javax.swing.ButtonGroup;
86
import javax.swing.ButtonGroup;
71
import javax.swing.JButton;
87
import javax.swing.JButton;
72
import javax.swing.JCheckBox;
88
import javax.swing.JCheckBox;
73
import javax.swing.JLabel;
89
import javax.swing.JLabel;
74
import javax.swing.JPanel;
90
import javax.swing.JPanel;
75
import javax.swing.JRadioButton;
91
import javax.swing.JRadioButton;
76
import javax.swing.JScrollPane;
92
import javax.swing.JScrollPane;
77
import javax.swing.JTable;
93
import javax.swing.JTable;
78
import javax.swing.JTextField;
94
import javax.swing.JTextField;
79
import javax.swing.SwingConstants;
95
import javax.swing.SwingConstants;
80
import javax.swing.SwingUtilities;
96
import javax.swing.SwingUtilities;
81
import javax.swing.event.DocumentEvent;
97
import javax.swing.event.DocumentEvent;
82
import javax.swing.text.AbstractDocument;
98
import javax.swing.text.AbstractDocument;
83
import javax.swing.text.MaskFormatter;
99
import javax.swing.text.MaskFormatter;
84
 
100
 
85
public class LettragePanel extends JPanel {
101
public class LettragePanel extends JPanel {
86
 
102
 
87
    private ListPanelEcritures ecriturePanel;
103
    private ListPanelEcritures ecriturePanel;
88
    private JTextField codeLettrage;
104
    private JTextField codeLettrage, codeLettragePartiel;
89
    private ISQLCompteSelector selCompte;
105
    private ISQLCompteSelector selCompte;
90
    private JCheckBox boxValidEcriture, boxAddSousCompte;
106
    private JCheckBox boxValidEcriture, boxAddSousCompte;
91
    private JPanel warningPanel, warningSolde;
107
    private JPanel warningPanel, warningSolde;
92
 
108
 
93
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
109
    private final SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
94
    private final SQLTable tableEcr = this.base.getTable("ECRITURE");
110
    private final SQLTable tableEcr = this.base.getTable("ECRITURE");
95
    private final SQLTable tableComptePCE = this.base.getTable("COMPTE_PCE");
111
    private final SQLTable tableComptePCE = this.base.getTable("COMPTE_PCE");
96
 
112
 
97
    private final static int allEcriture = 0;
113
    private final static int allEcriture = 0;
98
    private final static int ecritureLettree = 1;
114
    private final static int ecritureLettree = 1;
99
    private final static int ecritureNonLettree = 2;
115
    private final static int ecritureNonLettree = 2;
100
 
116
 
101
    private int modeSelect;
117
    private int modeSelect;
102
    private LettrageModel model;
118
    private LettrageModel model;
103
    private JButton buttonLettrer;
119
    private JButton buttonLettrer;
-
 
120
    private final JButton buttonRegler = new JButton("Régler");
104
    private JDate dateDeb, dateFin, dateLettrage;
121
    private JDate dateDeb, dateFin, dateLettrage;
105
 
122
 
106
    public LettragePanel() {
123
    public LettragePanel() {
107
        this(ComptePCESQLElement.getId("4"));
124
        this(ComptePCESQLElement.getId("4"));
108
    }
125
    }
109
 
126
 
110
    public LettragePanel(int idCompte) {
127
    public LettragePanel(int idCompte) {
111
        this.setLayout(new GridBagLayout());
128
        this.setLayout(new GridBagLayout());
112
        GridBagConstraints c = new DefaultGridBagConstraints();
129
        GridBagConstraints c = new DefaultGridBagConstraints();
113
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
130
        final SQLElementDirectory directory = Configuration.getInstance().getDirectory();
114
 
131
 
115
        this.modeSelect = allEcriture;
132
        this.modeSelect = allEcriture;
116
 
133
 
117
        // Selection du compte à lettrer
134
        // Selection du compte à lettrer
118
        JLabel labelPointageCompte = new JLabel("Lettrage du compte");
135
        JLabel labelPointageCompte = new JLabel("Lettrage du compte");
119
        labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);
136
        labelPointageCompte.setHorizontalAlignment(SwingConstants.RIGHT);
120
 
137
 
121
        this.add(labelPointageCompte, c);
138
        this.add(labelPointageCompte, c);
122
        this.selCompte = new ISQLCompteSelector();
139
        this.selCompte = new ISQLCompteSelector();
123
        SQLElement eltCpt = directory.getElement("COMPTE_PCE");
140
        SQLElement eltCpt = directory.getElement("COMPTE_PCE");
124
        final ComboSQLRequest createComboRequest = eltCpt.createComboRequest();
141
        final ComboSQLRequest createComboRequest = eltCpt.createComboRequest();
125
        String function = "REGEXP";
142
        String function = "REGEXP";
126
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
143
        if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) {
127
            function = "~";
144
            function = "~";
128
        }
145
        }
129
        createComboRequest.setWhere(new Where(eltCpt.getTable().getField("NUMERO"), function, "^4.*$"));
146
        createComboRequest.setWhere(new Where(eltCpt.getTable().getField("NUMERO"), function, "^4.*$"));
130
        this.selCompte.init(eltCpt, createComboRequest);
147
        this.selCompte.init(eltCpt, createComboRequest);
131
        this.selCompte.setValue(idCompte);
148
        this.selCompte.setValue(idCompte);
132
 
149
 
133
        c.gridx++;
150
        c.gridx++;
134
        c.weightx = 1;
151
        c.weightx = 1;
135
        c.gridwidth = GridBagConstraints.REMAINDER;
152
        c.gridwidth = GridBagConstraints.REMAINDER;
136
        this.add(this.selCompte, c);
153
        this.add(this.selCompte, c);
137
 
154
 
138
        c.gridwidth = 1;
155
        c.gridwidth = 1;
139
 
156
 
140
        // Gestion du lettrage
157
        // Gestion du lettrage
141
        c.insets = new Insets(2, 2, 1, 2);
158
        c.insets = new Insets(2, 2, 1, 2);
142
        TitledSeparator sepGestionLettrage = new TitledSeparator("Gestion du lettrage");
159
        TitledSeparator sepGestionLettrage = new TitledSeparator("Gestion du lettrage");
143
        c.fill = GridBagConstraints.HORIZONTAL;
160
        c.fill = GridBagConstraints.HORIZONTAL;
144
        c.gridy++;
161
        c.gridy++;
145
        c.gridx = 0;
162
        c.gridx = 0;
146
        c.gridwidth = GridBagConstraints.REMAINDER;
163
        c.gridwidth = GridBagConstraints.REMAINDER;
147
        this.add(sepGestionLettrage, c);
164
        this.add(sepGestionLettrage, c);
148
 
165
 
149
        // Code de lettrage
166
        // Code de lettrage
150
        JLabel labelCode = new JLabel("Code lettrage");
167
        JLabel labelCode = new JLabel("Code lettrage");
151
        labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
168
        labelCode.setHorizontalAlignment(SwingConstants.RIGHT);
152
        c.gridx = 0;
169
        c.gridx = 0;
153
        c.gridy++;
170
        c.gridy++;
154
        c.gridwidth = 1;
171
        c.gridwidth = 1;
155
        c.weightx = 0;
172
        c.weightx = 0;
156
        this.add(labelCode, c);
173
        this.add(labelCode, c);
157
 
174
 
158
        this.codeLettrage = new JTextField(10);
175
        this.codeLettrage = new JTextField(10);
159
        DocumentFilterList.add((AbstractDocument) this.codeLettrage.getDocument(), new UpperCaseFormatFilter(), FilterType.SIMPLE_FILTER);
176
        DocumentFilterList.add((AbstractDocument) this.codeLettrage.getDocument(), new UpperCaseFormatFilter(), FilterType.SIMPLE_FILTER);
160
        c.gridx++;
177
        c.gridx++;
161
        c.weightx = 1;
178
        c.weightx = 1;
162
        this.add(this.codeLettrage, c);
179
        this.add(this.codeLettrage, c);
163
        this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
180
        this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
164
 
181
 
-
 
182
        JLabel labelCodepartiel = new JLabel("Code lettrage partiel");
-
 
183
        labelCodepartiel.setHorizontalAlignment(SwingConstants.RIGHT);
-
 
184
        c.gridx++;
-
 
185
        c.gridwidth = 1;
-
 
186
        c.weightx = 0;
-
 
187
        this.add(labelCodepartiel, c);
-
 
188
 
-
 
189
        this.codeLettragePartiel = new JTextField(10);
-
 
190
        DocumentFilterList.add((AbstractDocument) this.codeLettragePartiel.getDocument(), new LowerCaseFormatFilter(), FilterType.SIMPLE_FILTER);
-
 
191
        c.gridx++;
-
 
192
        c.weightx = 1;
-
 
193
        this.add(this.codeLettragePartiel, c);
-
 
194
        this.codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
195
 
165
        // Warning si aucun code rentré
196
        // Warning si aucun code rentré
166
        createPanelWarning();
197
        createPanelWarning();
167
        c.gridwidth = GridBagConstraints.REMAINDER;
198
        c.gridwidth = GridBagConstraints.REMAINDER;
168
        c.weightx = 0;
199
        c.weightx = 0;
169
        c.gridx++;
200
        c.gridx++;
170
        this.add(this.warningPanel, c);
201
        this.add(this.warningPanel, c);
171
 
202
 
172
        // Date de lettrage
203
        // Date de lettrage
173
        JLabel labelDate = new JLabel("Date");
204
        JLabel labelDate = new JLabel("Date");
174
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
205
        labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
175
        c.gridx = 0;
206
        c.gridx = 0;
176
        c.gridy++;
207
        c.gridy++;
177
        c.weightx = 0;
208
        c.weightx = 0;
178
        c.gridwidth = 1;
209
        c.gridwidth = 1;
179
        this.add(labelDate, c);
210
        this.add(labelDate, c);
180
        this.dateLettrage = new JDate(true);
211
        this.dateLettrage = new JDate(true);
181
        c.gridx++;
212
        c.gridx++;
182
        this.add(this.dateLettrage, c);
213
        this.add(this.dateLettrage, c);
183
 
214
 
184
        // Warning si solde non nul
215
        // Warning si solde non nul
185
        c.gridx++;
216
        c.gridx++;
186
        createPanelWarningSolde();
217
        createPanelWarningSolde();
187
        c.gridwidth = GridBagConstraints.REMAINDER;
218
        c.gridwidth = GridBagConstraints.REMAINDER;
188
        c.weightx = 0;
219
        c.weightx = 0;
189
        this.add(this.warningSolde, c);
220
        this.add(this.warningSolde, c);
190
 
221
 
191
        c.gridwidth = 1;
222
        c.gridwidth = 1;
192
 
223
 
193
        TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
224
        TitledSeparator sepPeriode = new TitledSeparator("Filtre ");
194
        c.gridy++;
225
        c.gridy++;
195
        c.gridx = 0;
226
        c.gridx = 0;
196
        c.anchor = GridBagConstraints.WEST;
227
        c.anchor = GridBagConstraints.WEST;
197
        c.gridwidth = GridBagConstraints.REMAINDER;
228
        c.gridwidth = GridBagConstraints.REMAINDER;
198
        c.fill = GridBagConstraints.HORIZONTAL;
229
        c.fill = GridBagConstraints.HORIZONTAL;
199
        this.add(sepPeriode, c);
230
        this.add(sepPeriode, c);
200
 
231
 
201
        JPanel panelSelectEcritures = createPanelSelectionEcritures();
232
        JPanel panelSelectEcritures = createPanelSelectionEcritures();
202
        c.gridy++;
233
        c.gridy++;
203
        c.gridx = 0;
234
        c.gridx = 0;
204
        c.gridwidth = 1;
235
        c.gridwidth = 1;
205
        c.weightx = 0;
236
        c.weightx = 0;
206
 
237
 
207
        JLabel labelEcr = new JLabel("Ecritures");
238
        JLabel labelEcr = new JLabel("Ecritures");
208
        labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
239
        labelEcr.setHorizontalAlignment(SwingConstants.RIGHT);
209
        this.add(labelEcr, c);
240
        this.add(labelEcr, c);
210
        c.gridx++;
241
        c.gridx++;
211
        c.weightx = 1;
242
        c.weightx = 1;
212
        c.gridwidth = GridBagConstraints.REMAINDER;
243
        c.gridwidth = GridBagConstraints.REMAINDER;
213
        c.fill = GridBagConstraints.NONE;
244
        c.fill = GridBagConstraints.NONE;
214
        this.add(panelSelectEcritures, c);
245
        this.add(panelSelectEcritures, c);
215
 
246
 
216
        JPanel panelPeriode = new JPanel();
247
        JPanel panelPeriode = new JPanel();
217
        // Date de début
248
        // Date de début
218
        this.dateDeb = new JDate();
249
        this.dateDeb = new JDate();
219
        c.gridy++;
250
        c.gridy++;
220
        c.gridx = 0;
251
        c.gridx = 0;
221
        c.gridwidth = 1;
252
        c.gridwidth = 1;
222
        c.weightx = 0;
253
        c.weightx = 0;
223
        JLabel labelPerio = new JLabel("Période du ");
254
        JLabel labelPerio = new JLabel("Période du ");
224
        labelPerio.setHorizontalAlignment(SwingConstants.RIGHT);
255
        labelPerio.setHorizontalAlignment(SwingConstants.RIGHT);
225
        c.fill = GridBagConstraints.HORIZONTAL;
256
        c.fill = GridBagConstraints.HORIZONTAL;
226
        this.add(labelPerio, c);
257
        this.add(labelPerio, c);
227
 
258
 
228
        panelPeriode.add(this.dateDeb);
259
        panelPeriode.add(this.dateDeb);
229
        this.dateDeb.addValueListener(new PropertyChangeListener() {
260
        this.dateDeb.addValueListener(new PropertyChangeListener() {
230
            public void propertyChange(PropertyChangeEvent evt) {
261
            public void propertyChange(PropertyChangeEvent evt) {
231
                changeListRequest();
262
                changeListRequest();
232
            }
263
            }
233
        });
264
        });
234
 
265
 
235
        // Date de fin
266
        // Date de fin
236
        this.dateFin = new JDate(true);
267
        this.dateFin = new JDate(true);
237
        panelPeriode.add(new JLabel("au"));
268
        panelPeriode.add(new JLabel("au"));
238
        this.dateFin.addValueListener(new PropertyChangeListener() {
269
        this.dateFin.addValueListener(new PropertyChangeListener() {
239
            public void propertyChange(PropertyChangeEvent evt) {
270
            public void propertyChange(PropertyChangeEvent evt) {
240
                changeListRequest();
271
                changeListRequest();
241
            }
272
            }
242
        });
273
        });
243
 
274
 
244
        panelPeriode.add(this.dateFin);
275
        panelPeriode.add(this.dateFin);
245
        c.gridx++;
276
        c.gridx++;
246
        c.gridwidth = GridBagConstraints.REMAINDER;
277
        c.gridwidth = GridBagConstraints.REMAINDER;
247
        c.weightx = 1;
278
        c.weightx = 1;
248
        c.fill = GridBagConstraints.NONE;
279
        c.fill = GridBagConstraints.NONE;
249
        this.add(panelPeriode, c);
280
        this.add(panelPeriode, c);
250
 
281
 
251
        c.gridx = 0;
282
        c.gridx = 0;
252
        c.gridy++;
283
        c.gridy++;
253
        this.boxAddSousCompte = new JCheckBox("Ajouter les sous comptes");
284
        this.boxAddSousCompte = new JCheckBox("Ajouter les sous comptes");
254
        this.boxAddSousCompte.addActionListener(new ActionListener() {
285
        this.boxAddSousCompte.addActionListener(new ActionListener() {
255
            public void actionPerformed(ActionEvent e) {
286
            public void actionPerformed(ActionEvent e) {
256
                // TODO Auto-generated method stub
287
                // TODO Auto-generated method stub
257
                changeListRequest();
288
                changeListRequest();
258
            }
289
            }
259
        });
290
        });
260
 
291
 
261
        this.add(this.boxAddSousCompte, c);
292
        this.add(this.boxAddSousCompte, c);
262
 
293
 
263
        TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
294
        TitledSeparator sepEcriture = new TitledSeparator("Ecritures ");
264
        c.gridy++;
295
        c.gridy++;
265
        c.gridx = 0;
296
        c.gridx = 0;
266
        c.weightx = 1;
297
        c.weightx = 1;
267
        c.gridwidth = GridBagConstraints.REMAINDER;
298
        c.gridwidth = GridBagConstraints.REMAINDER;
268
        c.fill = GridBagConstraints.HORIZONTAL;
299
        c.fill = GridBagConstraints.HORIZONTAL;
269
        this.add(sepEcriture, c);
300
        this.add(sepEcriture, c);
270
 
301
 
271
        // Liste des ecritures
302
        // Liste des ecritures
272
        final EcritureSQLElement ecritureElem = directory.getElement(EcritureSQLElement.class);
303
        final EcritureSQLElement ecritureElem = directory.getElement(EcritureSQLElement.class);
273
        this.ecriturePanel = new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createLettrageTableSource()));
304
        this.ecriturePanel = new ListPanelEcritures(ecritureElem, new IListe(ecritureElem.createLettrageTableSource()));
274
        c.gridx = 0;
305
        c.gridx = 0;
275
        c.gridy++;
306
        c.gridy++;
276
        c.weighty = 1;
307
        c.weighty = 1;
277
        c.weightx = 1;
308
        c.weightx = 1;
278
        c.fill = GridBagConstraints.BOTH;
309
        c.fill = GridBagConstraints.BOTH;
279
        c.gridwidth = GridBagConstraints.REMAINDER;
310
        c.gridwidth = GridBagConstraints.REMAINDER;
280
        this.ecriturePanel.getListe().setPreferredSize(new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
311
        this.ecriturePanel.getListe().setPreferredSize(new Dimension(this.ecriturePanel.getListe().getPreferredSize().width, 200));
281
        this.add(this.ecriturePanel, c);
312
        this.add(this.ecriturePanel, c);
282
 
313
 
283
        // JTable Totaux
314
        // JTable Totaux
284
        c.gridy++;
315
        c.gridy++;
285
        c.gridx = 0;
316
        c.gridx = 0;
286
        c.weighty = 0;
317
        c.weighty = 0;
287
        c.weightx = 1;
318
        c.weightx = 1;
288
        c.fill = GridBagConstraints.BOTH;
319
        c.fill = GridBagConstraints.BOTH;
289
        c.gridwidth = 3;
320
        c.gridwidth = 3;
290
        c.gridheight = 3;
321
        c.gridheight = 3;
291
        this.model = new LettrageModel(this.selCompte.getSelectedId());
322
        this.model = new LettrageModel(this.selCompte.getSelectedId());
292
        JTable table = new JTable(this.model);
323
        JTable table = new JTable(this.model);
293
        table.setRowHeight(FontUtils.getPreferredRowHeight(table));
324
        table.setRowHeight(FontUtils.getPreferredRowHeight(table));
294
        // AlternateTableCellRenderer.setAllColumns(table);
325
        // AlternateTableCellRenderer.setAllColumns(table);
295
        for (int i = 0; i < table.getColumnCount(); i++) {
326
        for (int i = 0; i < table.getColumnCount(); i++) {
296
            // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
327
            // if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) ==
297
            // BigInteger.class) {
328
            // BigInteger.class) {
298
            table.getColumnModel().getColumn(i).setCellRenderer(new DeviseNiceTableCellRenderer());
329
            table.getColumnModel().getColumn(i).setCellRenderer(new DeviseNiceTableCellRenderer());
299
            // }
330
            // }
300
        }
331
        }
301
        JScrollPane sPane = new JScrollPane(table);
332
        JScrollPane sPane = new JScrollPane(table);
302
 
333
 
303
        // TODO Gerer la taille des colonnes
334
        // TODO Gerer la taille des colonnes
304
        Dimension d = new Dimension(table.getPreferredSize().width, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
335
        Dimension d = new Dimension(table.getPreferredSize().width, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 4);
305
        sPane.setPreferredSize(d);
336
        sPane.setPreferredSize(d);
306
        this.add(sPane, c);
337
        this.add(sPane, c);
307
 
338
 
308
        // Legende
339
        // Legende
309
        c.gridx = 4;
340
        c.gridx = 4;
310
        c.gridwidth = 1;
341
        c.gridwidth = 1;
311
        c.anchor = GridBagConstraints.EAST;
342
        c.anchor = GridBagConstraints.EAST;
312
        c.fill = GridBagConstraints.NONE;
343
        c.fill = GridBagConstraints.NONE;
313
        c.weightx = 0;
344
        c.weightx = 0;
314
        this.add(createPanelLegende(), c);
345
        this.add(createPanelLegende(), c);
315
 
346
 
316
        c.gridheight = 1;
347
        c.gridheight = 1;
317
        final JButton buttonDelettrer = new JButton("Délettrer");
348
        final JButton buttonDelettrer = new JButton("Délettrer");
318
        this.buttonLettrer = new JButton("Lettrer");
349
        this.buttonLettrer = new JButton("Lettrer");
319
        // Validation des ecritures pointées
350
        // Validation des ecritures pointées
320
        this.boxValidEcriture = new JCheckBox("Valider les écritures lettrées");
351
        this.boxValidEcriture = new JCheckBox("Valider les écritures lettrées");
321
        c.gridx++;
352
        c.gridx++;
322
        c.gridwidth = GridBagConstraints.REMAINDER;
353
        c.gridwidth = GridBagConstraints.REMAINDER;
323
        this.add(this.boxValidEcriture, c);
354
        this.add(this.boxValidEcriture, c);
324
 
355
 
325
        JPanel panelButton = new JPanel();
356
        JPanel panelButton = new JPanel();
-
 
357
        panelButton.add(this.buttonRegler, c);
326
 
358
 
327
        // Boutton lettrer
359
        // Boutton lettrer
328
 
360
 
329
        panelButton.add(this.buttonLettrer, c);
361
        panelButton.add(this.buttonLettrer, c);
330
 
362
 
331
        // Boutton Delettrer
363
        // Boutton Delettrer
332
 
364
 
333
        panelButton.add(buttonDelettrer, c);
365
        panelButton.add(buttonDelettrer, c);
334
 
366
 
335
        c.gridy++;
367
        c.gridy++;
336
        c.gridx = 5;
368
        c.gridx = 5;
337
        c.gridwidth = GridBagConstraints.REMAINDER;
369
        c.gridwidth = GridBagConstraints.REMAINDER;
338
        c.gridheight = 1;
370
        c.gridheight = 1;
339
        c.weightx = 1;
371
        c.weightx = 1;
340
        c.fill = GridBagConstraints.NONE;
372
        c.fill = GridBagConstraints.NONE;
341
        c.anchor = GridBagConstraints.EAST;
373
        c.anchor = GridBagConstraints.EAST;
342
        this.add(panelButton, c);
374
        this.add(panelButton, c);
343
 
375
 
344
        c.gridy++;
376
        c.gridy++;
345
        c.anchor = GridBagConstraints.SOUTHEAST;
377
        c.anchor = GridBagConstraints.SOUTHEAST;
346
        JButton buttonClose = new JButton("Fermer");
378
        JButton buttonClose = new JButton("Fermer");
347
        buttonClose.addActionListener(new ActionListener() {
379
        buttonClose.addActionListener(new ActionListener() {
348
 
380
 
349
            @Override
381
            @Override
350
            public void actionPerformed(ActionEvent e) {
382
            public void actionPerformed(ActionEvent e) {
351
                ((Window) SwingUtilities.getRoot((Component) e.getSource())).dispose();
383
                ((Window) SwingUtilities.getRoot((Component) e.getSource())).dispose();
352
 
384
 
353
            }
385
            }
354
        });
386
        });
355
        this.add(buttonClose, c);
387
        this.add(buttonClose, c);
356
        this.buttonLettrer.addActionListener(new ActionListener() {
388
        this.buttonLettrer.addActionListener(new ActionListener() {
357
            public void actionPerformed(ActionEvent e) {
389
            public void actionPerformed(ActionEvent e) {
358
 
-
 
-
 
390
                try {
359
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
391
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
392
                    actionLettrage(rowIndex, false);
-
 
393
                } catch (SQLException e1) {
-
 
394
                    ExceptionHandler.handle("Erreur de lettrage", e1);
-
 
395
                }
-
 
396
 
-
 
397
            }
-
 
398
        });
-
 
399
 
-
 
400
        this.buttonRegler.addActionListener(new ActionListener() {
-
 
401
            public void actionPerformed(ActionEvent e) {
-
 
402
 
-
 
403
                final List<SQLRowValues> res = LettragePanel.this.ecriturePanel.getListe().getSelectedRows();
-
 
404
 
-
 
405
                final SQLTable tableKm = LettragePanel.this.ecriturePanel.getListe().getSource().getPrimaryTable().getTable("SAISIE_KM");
-
 
406
                SQLRowValues rowValsKm = new SQLRowValues(tableKm);
-
 
407
                rowValsKm.put("DATE", new Date());
-
 
408
                rowValsKm.put("ID_JOURNAL", JournalSQLElement.BANQUES);
-
 
409
 
-
 
410
                long solde = LettragePanel.this.model.getSoldeSelection();
-
 
411
 
-
 
412
                final SQLTable tableKmItem = tableKm.getTable("SAISIE_KM_ELEMENT");
-
 
413
                List<String> pieces = new ArrayList<>();
-
 
414
 
-
 
415
                for (SQLRowValues sqlRowValues : res) {
-
 
416
                    SQLRowValues rowValsKmItemTiers = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem));
-
 
417
                    rowValsKmItemTiers.put("NUMERO", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO"));
-
 
418
                    rowValsKmItemTiers.put("NOM", sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NOM"));
-
 
419
                    final String pieceNom;
-
 
420
                    if (sqlRowValues.getString("NOM_PIECE").trim().length() > 0) {
-
 
421
                        pieceNom = sqlRowValues.getString("NOM_PIECE");
-
 
422
                    } else {
-
 
423
                        pieceNom = sqlRowValues.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM");
-
 
424
                    }
-
 
425
                    rowValsKmItemTiers.put("NOM_PIECE", pieceNom);
-
 
426
                    if (pieceNom != null && pieceNom.trim().length() > 0) {
-
 
427
                        pieces.add(pieceNom);
-
 
428
                    }
-
 
429
                    rowValsKmItemTiers.put("CREDIT", sqlRowValues.getLong("DEBIT"));
-
 
430
                    rowValsKmItemTiers.put("DEBIT", sqlRowValues.getLong("CREDIT"));
-
 
431
                    if (rowValsKmItemTiers.getTable().contains("MONTANT_ECHEANCE")) {
-
 
432
                        rowValsKmItemTiers.put("MONTANT_ECHEANCE", sqlRowValues.getLong("CREDIT"));
-
 
433
                    }
-
 
434
                    rowValsKmItemTiers.put("ID_SAISIE_KM", rowValsKm);
-
 
435
                }
-
 
436
 
-
 
437
                SQLRowValues rowValsKmItemBq = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(tableKmItem));
-
 
438
                boolean achat = solde < 0;
-
 
439
                // Compte bq
-
 
440
                int idPce = tableKm.getTable("TYPE_REGLEMENT").getRow(2).getInt("ID_COMPTE_PCE_" + (achat ? "FOURN" : "CLIENT"));
-
 
441
                if (idPce <= 1) {
-
 
442
                    try {
-
 
443
                        idPce = ComptePCESQLElement.getIdComptePceDefault("VenteCB");
-
 
444
                    } catch (Exception e1) {
-
 
445
                        // TODO Auto-generated catch block
-
 
446
                        e1.printStackTrace();
-
 
447
                    }
-
 
448
                }
-
 
449
                final SQLTable tableAccount = tableKmItem.getTable("COMPTE_PCE");
-
 
450
                SQLRow rowCptBq = tableAccount.getRow(idPce);
-
 
451
                rowValsKmItemBq.put("NUMERO", rowCptBq.getString("NUMERO"));
-
 
452
                rowValsKmItemBq.put("NOM", rowCptBq.getString("NOM"));
-
 
453
                if (!pieces.isEmpty()) {
-
 
454
                    StringBuilder build = new StringBuilder();
-
 
455
                    int nbPieces = pieces.size();
-
 
456
                    int i = 0;
-
 
457
                    for (String string : pieces) {
-
 
458
                        build.append(string);
-
 
459
                        i++;
-
 
460
                        if (i < nbPieces) {
-
 
461
                            build.append(", ");
-
 
462
                        }
-
 
463
 
-
 
464
                    }
-
 
465
                    rowValsKmItemBq.put("NOM_PIECE", build.toString());
-
 
466
                }
-
 
467
 
-
 
468
                if (solde > 0) {
-
 
469
                    rowValsKmItemBq.put("CREDIT", solde);
-
 
470
                    rowValsKmItemBq.put("DEBIT", 0L);
-
 
471
                } else {
-
 
472
                    rowValsKmItemBq.put("DEBIT", -solde);
-
 
473
                    rowValsKmItemBq.put("CREDIT", 0L);
-
 
474
                }
-
 
475
                rowValsKmItemBq.put("ID_SAISIE_KM", rowValsKm);
-
 
476
 
-
 
477
                EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("SAISIE_KM"), EditMode.CREATION);
-
 
478
                frame.getSQLComponent().select(rowValsKm);
-
 
479
                frame.setVisible(true);
-
 
480
                frame.addEditPanelListener(new EditPanelListener() {
-
 
481
 
-
 
482
                    @Override
-
 
483
                    public void modified() {
-
 
484
                        // TODO Auto-generated method stub
-
 
485
 
-
 
486
                    }
-
 
487
 
-
 
488
                    @Override
-
 
489
                    public void inserted(int id) {
-
 
490
                        List<SQLRow> rowsInserted = tableKm.getRow(id).getReferentRows(tableKmItem);
-
 
491
                        List<String> piece = new ArrayList<>();
-
 
492
                        List<SQLRowAccessor> rowsToLettre = new ArrayList<>();
-
 
493
                        long solde = 0;
-
 
494
                        for (SQLRowValues sqlRowValues : res) {
-
 
495
                            rowsToLettre.add(sqlRowValues);
-
 
496
                            final String nomPiece = sqlRowValues.getString("NOM_PIECE");
-
 
497
                            if (sqlRowValues.getForeign("ID_COMPTE_PCE").getString("NUMERO").startsWith("4") && nomPiece.trim().length() > 0) {
-
 
498
                                piece.add(nomPiece);
-
 
499
                            }
-
 
500
                            solde += sqlRowValues.getLong("DEBIT");
-
 
501
                            solde -= sqlRowValues.getLong("CREDIT");
-
 
502
                        }
-
 
503
 
-
 
504
                        for (SQLRow sqlRow : rowsInserted) {
-
 
505
                            SQLRow rowEcr = sqlRow.getForeign("ID_ECRITURE");
-
 
506
 
-
 
507
                            final String nomPiece = sqlRow.getString("NOM_PIECE");
-
 
508
                            if (rowEcr.getString("COMPTE_NUMERO").startsWith("4")) {
-
 
509
                                solde += rowEcr.getLong("DEBIT");
-
 
510
                                solde -= rowEcr.getLong("CREDIT");
-
 
511
                                if (nomPiece.trim().length() > 0) {
-
 
512
                                    piece.add(nomPiece);
-
 
513
                                }
-
 
514
                                rowsToLettre.add(rowEcr);
-
 
515
                            }
-
 
516
                        }
-
 
517
 
-
 
518
                        if (solde == 0) {
-
 
519
                            final String codeLettre = codeLettrage.getText().trim();
-
 
520
 
-
 
521
                            for (SQLRowAccessor row2 : rowsToLettre) {
-
 
522
 
-
 
523
                                SQLRowValues rowVals = new SQLRowValues(row2.getTable());
-
 
524
 
-
 
525
                                // Lettrage
-
 
526
                                // On lettre ou relettre la ligne avec le code saisi
-
 
527
                                if (codeLettre.length() > 0) {
-
 
528
                                    rowVals.put("LETTRAGE_PARTIEL", "");
-
 
529
                                    rowVals.put("LETTRAGE", codeLettre);
-
 
530
                                    rowVals.put("DATE_LETTRAGE", dateLettrage.getDate());
-
 
531
                                    try {
-
 
532
                                        rowVals.update(row2.getID());
-
 
533
                                    } catch (SQLException e1) {
-
 
534
 
-
 
535
                                        e1.printStackTrace();
-
 
536
                                    }
-
 
537
                                }
-
 
538
                            }
-
 
539
                            // Mise à jour du code de lettrage
-
 
540
                            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
541
                            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
542
                            rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
543
                            try {
-
 
544
                                rowVals.update();
-
 
545
                            } catch (SQLException e) {
-
 
546
                                e.printStackTrace();
-
 
547
                            }
-
 
548
                            codeLettrage.setText(getNextCodeLettrage());
-
 
549
 
-
 
550
                            model.updateTotauxCompte();
-
 
551
                        } else {
-
 
552
                            String codeLettreP = codeLettragePartiel.getText().trim();
-
 
553
                            String codeLettre = codeLettrage.getText().trim();
-
 
554
 
-
 
555
                            SQLSelect selEcr = new SQLSelect();
-
 
556
                            SQLTable tableEcr = tableKm.getTable("ECRITURE");
-
 
557
                            selEcr.addSelect(tableEcr.getKey());
-
 
558
                            selEcr.addSelect(tableEcr.getField("NOM_PIECE"));
-
 
559
                            selEcr.addSelect(tableEcr.getField("DEBIT"));
-
 
560
                            selEcr.addSelect(tableEcr.getField("CREDIT"));
-
 
561
                            selEcr.addSelect(tableEcr.getField("LETTRAGE"));
-
 
562
                            selEcr.addSelect(tableEcr.getField("LETTRAGE_PARTIEL"));
-
 
563
                            Where w2 = new Where(tableEcr.getField("NOM_PIECE"), piece);
-
 
564
                            w2 = w2.and(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "40%").or(new Where(tableEcr.getField("COMPTE_NUMERO"), "LIKE", "41%")));
-
 
565
                            w2 = w2.and(new Where(tableEcr.getField("DATE_LETTRAGE"), "=", (Object) null));
-
 
566
                            selEcr.setWhere(w2);
-
 
567
 
-
 
568
                            List<SQLRow> rows = SQLRowListRSH.execute(selEcr);
-
 
569
                            ListMap<String, SQLRow> mapPiece = new ListMap<>();
-
 
570
                            Map<String, Long> soldePiece = new HashMap<>();
-
 
571
                            for (SQLRow sqlRow : rows) {
-
 
572
                                String pieceName = sqlRow.getString("NOM_PIECE");
-
 
573
                                mapPiece.add(pieceName, sqlRow);
-
 
574
                                long soldeRow = sqlRow.getLong("DEBIT") - sqlRow.getLong("CREDIT");
-
 
575
                                if (soldePiece.containsKey(pieceName)) {
-
 
576
                                    soldePiece.put(pieceName, soldePiece.get(pieceName) + soldeRow);
-
 
577
                                } else {
-
 
578
                                    soldePiece.put(pieceName, soldeRow);
-
 
579
                                }
-
 
580
                            }
-
 
581
 
-
 
582
                            for (Entry<String, List<SQLRow>> entry : mapPiece.entrySet()) {
-
 
583
 
-
 
584
                                if (soldePiece.get(entry.getKey()) == 0) {
-
 
585
                                    try {
-
 
586
                                        for (SQLRow rowEcr : entry.getValue()) {
-
 
587
                                            SQLRowValues rowVals = rowEcr.createEmptyUpdateRow();
-
 
588
 
-
 
589
                                            // Lettrage
-
 
590
                                            // On lettre ou relettre la ligne avec le code saisi
-
 
591
                                            if (codeLettre.length() > 0) {
-
 
592
                                                rowVals.put("LETTRAGE_PARTIEL", "");
-
 
593
                                                rowVals.put("LETTRAGE", codeLettre);
-
 
594
                                                rowVals.put("DATE_LETTRAGE", dateLettrage.getDate());
-
 
595
                                                rowVals.update();
-
 
596
                                            }
-
 
597
                                        }
-
 
598
                                        // Mise à jour du code de lettrage
-
 
599
                                        SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
600
                                        SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
601
                                        rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
602
                                        rowVals.update();
-
 
603
 
-
 
604
                                        codeLettre = getNextCodeLettrage();
-
 
605
                                    } catch (SQLException e) {
-
 
606
                                        e.printStackTrace();
-
 
607
                                    }
-
 
608
                                } else {
-
 
609
                                    try {
-
 
610
                                        for (SQLRow rowEcr : entry.getValue()) {
-
 
611
                                            SQLRowValues rowVals = rowEcr.createEmptyUpdateRow();
-
 
612
 
-
 
613
                                            // Lettrage
-
 
614
                                            // On lettre ou relettre la ligne avec le code saisi
-
 
615
                                            if (codeLettreP.length() > 0) {
360
 
616
 
361
                // System.err.println("Action lettrage sur " + i);
617
                                                rowVals.put("LETTRAGE_PARTIEL", codeLettreP);
362
                actionLettrage(rowIndex);
618
                                                rowVals.update();
363
 
619
 
364
            }
620
                                            }
-
 
621
                                        }
-
 
622
                                        // Mise à jour du code de lettrage
-
 
623
                                        SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
-
 
624
                                        SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
625
                                        rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettreP);
-
 
626
                                        rowVals.update();
-
 
627
                                        codeLettreP = getNextCodeLettragePartiel();
-
 
628
                                    } catch (SQLException e) {
-
 
629
                                        e.printStackTrace();
-
 
630
                                    }
-
 
631
                                }
-
 
632
                            }
-
 
633
                            codeLettrage.setText(getNextCodeLettrage());
-
 
634
 
-
 
635
                            codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
636
                            model.updateTotauxCompte();
-
 
637
                        }
-
 
638
                    }
-
 
639
 
-
 
640
                    @Override
-
 
641
                    public void deleted() {
-
 
642
                        // TODO Auto-generated method stub
-
 
643
 
-
 
644
                    }
-
 
645
 
-
 
646
                    @Override
-
 
647
                    public void cancelled() {
-
 
648
                        // TODO Auto-generated method stub
-
 
649
 
-
 
650
                    }
-
 
651
                });
-
 
652
            }
365
        });
653
        });
366
 
654
 
367
        buttonDelettrer.addActionListener(new ActionListener() {
655
        buttonDelettrer.addActionListener(new ActionListener() {
368
            public void actionPerformed(ActionEvent e) {
656
            public void actionPerformed(ActionEvent e) {
369
 
657
 
370
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
658
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
371
                actionDelettrage(rowIndex);
659
                actionDelettrage(rowIndex, false);
372
            }
660
            }
373
        });
661
        });
374
 
662
 
375
        // Changement de compte
663
        // Changement de compte
376
        this.selCompte.addValueListener(new PropertyChangeListener() {
664
        this.selCompte.addValueListener(new PropertyChangeListener() {
377
            public void propertyChange(PropertyChangeEvent evt) {
665
            public void propertyChange(PropertyChangeEvent evt) {
378
 
666
 
379
                changeListRequest();
667
                changeListRequest();
380
            };
668
            };
381
        });
669
        });
382
 
670
 
383
        // Action Souris sur la IListe
671
        // Action Souris sur la IListe
384
 
672
 
385
        addActionMenuDroit();
673
        addActionMenuDroit();
386
        this.ecriturePanel.getListe().getJTable().addMouseListener(new MouseAdapter() {
674
        this.ecriturePanel.getListe().getJTable().addMouseListener(new MouseAdapter() {
387
 
675
 
388
            public void mouseReleased(MouseEvent e) {
676
            public void mouseReleased(MouseEvent e) {
389
                System.err.println("Mouse released");
677
                System.err.println("Mouse released");
390
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
678
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
391
                int[] idRows = new int[selectedRows.length];
679
                int[] idRows = new int[selectedRows.length];
392
                for (int i = 0; i < idRows.length; i++) {
680
                for (int i = 0; i < idRows.length; i++) {
393
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
681
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
394
                }
682
                }
395
 
683
 
396
                LettragePanel.this.model.updateSelection(idRows);
684
                LettragePanel.this.model.updateSelection(idRows);
397
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
685
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
398
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
686
                buttonDelettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
399
                LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
687
                LettragePanel.this.buttonLettrer.setEnabled(LettragePanel.this.model.getSoldeSelection() == 0);
-
 
688
                LettragePanel.this.buttonRegler.setEnabled(!LettragePanel.this.ecriturePanel.getListe().getSelectedRows().isEmpty());
400
            }
689
            }
401
        });
690
        });
402
 
691
 
403
        // action sur la IListe
692
        // action sur la IListe
404
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
693
        this.ecriturePanel.getListe().getJTable().addKeyListener(new KeyAdapter() {
405
            public void keyReleased(KeyEvent e) {
694
            public void keyReleased(KeyEvent e) {
406
 
695
 
407
                System.err.println("Key released");
696
                System.err.println("Key released");
408
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
697
                int[] selectedRows = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
409
                int[] idRows = new int[selectedRows.length];
698
                int[] idRows = new int[selectedRows.length];
410
                for (int i = 0; i < idRows.length; i++) {
699
                for (int i = 0; i < idRows.length; i++) {
411
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
700
                    idRows[i] = LettragePanel.this.ecriturePanel.getListe().idFromIndex(selectedRows[i]);
412
                }
701
                }
413
 
702
 
414
                LettragePanel.this.model.updateSelection(idRows);
703
                LettragePanel.this.model.updateSelection(idRows);
415
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
704
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
416
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
705
                LettragePanel.this.warningSolde.setVisible(LettragePanel.this.model.getSoldeSelection() != 0);
417
            }
706
            }
418
        });
707
        });
419
 
708
 
420
        // Gestion du code
709
        // Gestion du code
421
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
710
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
422
 
711
 
423
            @Override
712
            @Override
424
            public void update(DocumentEvent e) {
713
            public void update(DocumentEvent e) {
425
                // TODO Auto-generated method stub
714
                // TODO Auto-generated method stub
426
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
715
                LettragePanel.this.warningPanel.setVisible((LettragePanel.this.codeLettrage.getText().trim().length() == 0));
427
                LettragePanel.this.buttonLettrer.setEnabled((LettragePanel.this.codeLettrage.getText().trim().length() != 0));
716
                LettragePanel.this.buttonLettrer.setEnabled((LettragePanel.this.codeLettrage.getText().trim().length() != 0));
428
            }
717
            }
429
 
718
 
430
        });
719
        });
431
 
720
 
432
        changeListRequest();
721
        changeListRequest();
433
        this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
722
        this.warningPanel.setVisible((this.codeLettrage.getText().trim().length() == 0));
434
        this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
723
        this.buttonLettrer.setEnabled((this.codeLettrage.getText().trim().length() != 0));
435
    }
724
    }
436
 
725
 
-
 
726
    private String getNextCodeLettragePartiel() {
-
 
727
        return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettragePartiel();
-
 
728
    }
-
 
729
 
-
 
730
    private String getNextCodeLettrage() {
-
 
731
        return Configuration.getInstance().getDirectory().getElement(NumerotationAutoSQLElement.class).getNextCodeLettrage();
-
 
732
    }
-
 
733
 
437
    /* Menu clic Droit */
734
    /* Menu clic Droit */
438
    private void addActionMenuDroit() {
735
    private void addActionMenuDroit() {
439
        // JPopupMenu menu = new JPopupMenu();
736
        // JPopupMenu menu = new JPopupMenu();
440
 
737
 
441
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Voir la source") {
738
        PredicateRowAction action = new PredicateRowAction(new AbstractAction() {
442
            public void actionPerformed(ActionEvent e) {
739
            public void actionPerformed(ActionEvent e) {
443
 
740
 
444
                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
741
                SQLRow rowEcr = LettragePanel.this.ecriturePanel.getListe().fetchSelectedRow();
445
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
742
                MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT"));
446
            }
743
            }
447
        }, "financing.accouning.entries.source.show");
744
        }, false, "financing.accouning.entries.source.show");
-
 
745
        action.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
746
 
-
 
747
        this.ecriturePanel.getListe().addIListeAction(action);
448
 
748
 
449
        // if (this.codeLettrage.getText().trim().length() != 0) {
-
 
450
        final AbstractAction abstractAction = new AbstractAction() {
749
        final AbstractAction abstractAction = new AbstractAction() {
451
            public void actionPerformed(ActionEvent e) {
750
            public void actionPerformed(ActionEvent e) {
452
 
751
 
-
 
752
                try {
-
 
753
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
754
                    actionLettrage(rowIndex, false);
-
 
755
                } catch (SQLException e1) {
-
 
756
                    ExceptionHandler.handle("erreur de lettrage", e1);
-
 
757
                }
-
 
758
            }
-
 
759
        };
-
 
760
        PredicateRowAction actionLettre = new PredicateRowAction(abstractAction, false, "financing.accouning.entries.match");
-
 
761
        actionLettre.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
762
        this.ecriturePanel.getListe().addIListeAction(actionLettre);
-
 
763
 
-
 
764
        final AbstractAction abstractActionPartiel = new AbstractAction("Lettrage Partiel") {
-
 
765
            public void actionPerformed(ActionEvent e) {
-
 
766
 
-
 
767
                try {
453
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
768
                    int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
454
                actionLettrage(rowIndex);
769
                    actionLettrage(rowIndex, true);
-
 
770
                } catch (SQLException e1) {
-
 
771
                    ExceptionHandler.handle("erreur de lettrage", e1);
-
 
772
                }
455
            }
773
            }
456
        };
774
        };
457
        this.ecriturePanel.getListe().addRowAction(abstractAction, "financing.accouning.entries.match");
775
        PredicateRowAction actionLettreP = new PredicateRowAction(abstractActionPartiel, false, "financing.accouning.entries.match.partial");
-
 
776
        actionLettreP.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
-
 
777
        this.ecriturePanel.getListe().addIListeAction(actionLettreP);
-
 
778
 
458
        // }
779
        // }
459
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
780
        this.codeLettrage.getDocument().addDocumentListener(new SimpleDocumentListener() {
460
            @Override
781
            @Override
461
            public void update(DocumentEvent e) {
782
            public void update(DocumentEvent e) {
462
                abstractAction.setEnabled(LettragePanel.this.codeLettrage.getText().trim().length() > 0);
783
                abstractAction.setEnabled(LettragePanel.this.codeLettrage.getText().trim().length() > 0);
463
            }
784
            }
464
        });
785
        });
465
 
786
 
466
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer") {
787
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer") {
467
            public void actionPerformed(ActionEvent e) {
788
            public void actionPerformed(ActionEvent e) {
468
 
789
 
469
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
790
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
470
                actionDelettrage(rowIndex);
791
                actionDelettrage(rowIndex, false);
471
            }
792
            }
472
        }, "financing.accouning.entries.unmatch");
793
        }, "financing.accouning.entries.unmatch");
473
 
794
 
-
 
795
        this.ecriturePanel.getListe().addRowAction(new AbstractAction("Délettrer partiel") {
-
 
796
            public void actionPerformed(ActionEvent e) {
-
 
797
 
-
 
798
                int[] rowIndex = LettragePanel.this.ecriturePanel.getListe().getJTable().getSelectedRows();
-
 
799
                actionDelettrage(rowIndex, true);
-
 
800
            }
474
        // menu.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y);
801
        }, "financing.accouning.entries.unmatch.partial");
-
 
802
 
475
    }
803
    }
476
 
804
 
477
    /* Panel Warning no numero releve */
805
    /* Panel Warning no numero releve */
478
    private void createPanelWarning() {
806
    private void createPanelWarning() {
479
 
807
 
480
        this.warningPanel = new JPanel();
808
        this.warningPanel = new JPanel();
481
        this.warningPanel.setLayout(new GridBagLayout());
809
        this.warningPanel.setLayout(new GridBagLayout());
482
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
810
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
483
 
811
 
484
        GridBagConstraints c = new GridBagConstraints();
812
        GridBagConstraints c = new GridBagConstraints();
485
        c.anchor = GridBagConstraints.WEST;
813
        c.anchor = GridBagConstraints.WEST;
486
        c.fill = GridBagConstraints.NONE;
814
        c.fill = GridBagConstraints.NONE;
487
        c.gridheight = 1;
815
        c.gridheight = 1;
488
        c.gridwidth = 1;
816
        c.gridwidth = 1;
489
        c.gridx = 0;
817
        c.gridx = 0;
490
        c.gridy = 0;
818
        c.gridy = 0;
491
        c.weightx = 0;
819
        c.weightx = 0;
492
        c.weighty = 0;
820
        c.weighty = 0;
493
 
821
 
494
        final JLabel warningNoCodeImg = new JLabelWarning();
822
        final JLabel warningNoCodeImg = new JLabelWarning();
495
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
823
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
496
        this.warningPanel.add(warningNoCodeImg, c);
824
        this.warningPanel.add(warningNoCodeImg, c);
497
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le code de lettrage n'est pas saisi!");
825
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le code de lettrage n'est pas saisi!");
498
        c.gridx++;
826
        c.gridx++;
499
        this.warningPanel.add(warningNoCodeText, c);
827
        this.warningPanel.add(warningNoCodeText, c);
500
    }
828
    }
501
 
829
 
502
    /* Panel Warning solde invalide */
830
    /* Panel Warning solde invalide */
503
    private void createPanelWarningSolde() {
831
    private void createPanelWarningSolde() {
504
 
832
 
505
        this.warningSolde = new JPanel();
833
        this.warningSolde = new JPanel();
506
        this.warningSolde.setLayout(new GridBagLayout());
834
        this.warningSolde.setLayout(new GridBagLayout());
507
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
835
        // this.warningPanel.setBorder(BorderFactory.createTitledBorder("Warning"));
508
 
836
 
509
        GridBagConstraints c = new GridBagConstraints();
837
        GridBagConstraints c = new GridBagConstraints();
510
        c.anchor = GridBagConstraints.WEST;
838
        c.anchor = GridBagConstraints.WEST;
511
        c.fill = GridBagConstraints.NONE;
839
        c.fill = GridBagConstraints.NONE;
512
        c.gridheight = 1;
840
        c.gridheight = 1;
513
        c.gridwidth = 1;
841
        c.gridwidth = 1;
514
        c.gridx = 0;
842
        c.gridx = 0;
515
        c.gridy = 0;
843
        c.gridy = 0;
516
        c.weightx = 0;
844
        c.weightx = 0;
517
        c.weighty = 0;
845
        c.weighty = 0;
518
 
846
 
519
        final JLabel warningNoCodeImg = new JLabelWarning();
847
        final JLabel warningNoCodeImg = new JLabelWarning();
520
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
848
        warningNoCodeImg.setHorizontalAlignment(SwingConstants.RIGHT);
521
        this.warningSolde.add(warningNoCodeImg, c);
849
        this.warningSolde.add(warningNoCodeImg, c);
522
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le solde sélectionné n'est pas nul!");
850
        final JLabel warningNoCodeText = new JLabel("Impossible de lettrer tant que le solde sélectionné n'est pas nul!");
523
        c.gridx++;
851
        c.gridx++;
524
        this.warningSolde.add(warningNoCodeText, c);
852
        this.warningSolde.add(warningNoCodeText, c);
525
    }
853
    }
526
 
854
 
527
    // Lettre la ligne passée en parametre
855
    // Lettre la ligne passée en parametre
-
 
856
 
528
    private void actionLettrage(int[] rowIndex) {
857
    private void actionLettrage(int[] rowIndex, boolean partiel) throws SQLException {
-
 
858
 
-
 
859
        String codeLettre;
-
 
860
        if (partiel) {
-
 
861
            codeLettre = this.codeLettragePartiel.getText().trim();
-
 
862
        } else {
529
        String codeLettre = this.codeLettrage.getText().trim();
863
            codeLettre = this.codeLettrage.getText().trim();
-
 
864
        }
-
 
865
        // FIXME : transaction
530
 
866
 
531
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
867
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
532
 
868
 
533
        long solde = 0;
869
        long solde = 0;
534
        for (int i = 0; i < rowIndex.length; i++) {
870
        for (int i = 0; i < rowIndex.length; i++) {
535
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
871
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
536
            SQLRow row = this.tableEcr.getRow(id);
872
            SQLRow row = this.tableEcr.getRow(id);
537
            rowsSelected.add(row);
873
            rowsSelected.add(row);
538
 
874
 
539
            solde += ((Long) row.getObject("DEBIT")).longValue();
875
            solde += ((Long) row.getObject("DEBIT")).longValue();
540
            solde -= ((Long) row.getObject("CREDIT")).longValue();
876
            solde -= ((Long) row.getObject("CREDIT")).longValue();
541
        }
877
        }
542
 
878
 
543
        if (solde == 0) {
879
        if (partiel || solde == 0) {
544
 
880
 
545
            for (SQLRow row2 : rowsSelected) {
881
            for (SQLRow row2 : rowsSelected) {
546
 
882
 
547
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
883
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
548
 
884
 
549
                // Lettrage
885
                // Lettrage
550
                // On lettre ou relettre la ligne avec le code saisi
886
                // On lettre ou relettre la ligne avec le code saisi
551
                if (codeLettre.length() > 0) {
887
                if (codeLettre.length() > 0) {
552
 
888
 
553
                    // Si la ligne est en brouillard on valide le mouvement associé
889
                    // Si la ligne est en brouillard on valide le mouvement associé
554
                    if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
890
                    if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
555
                        EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
891
                        EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
556
                    }
892
                    }
557
 
893
 
-
 
894
                    if (partiel) {
-
 
895
                        rowVals.put("LETTRAGE_PARTIEL", codeLettre);
-
 
896
                    } else {
558
                    rowVals.put("LETTRAGE", codeLettre);
897
                        rowVals.put("LETTRAGE", codeLettre);
559
                    rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
898
                        rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
-
 
899
                    }
560
                    try {
900
                    try {
561
                        rowVals.update(row2.getID());
901
                        rowVals.update(row2.getID());
562
                    } catch (SQLException e1) {
902
                    } catch (SQLException e1) {
563
 
903
 
564
                        e1.printStackTrace();
904
                        e1.printStackTrace();
565
                    }
905
                    }
566
                }
906
                }
567
            }
907
            }
568
            // Mise à jour du code de lettrage
908
            // Mise à jour du code de lettrage
569
            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
909
            SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
570
            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
910
            SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
-
 
911
            if (partiel) {
-
 
912
                rowVals.put("CODE_LETTRAGE_PARTIEL", codeLettre);
-
 
913
            } else {
571
            rowVals.put("CODE_LETTRAGE", codeLettre);
914
                rowVals.put("CODE_LETTRAGE", codeLettre);
-
 
915
            }
572
            try {
916
            try {
573
                rowVals.update();
917
                rowVals.update();
574
            } catch (SQLException e) {
918
            } catch (SQLException e) {
575
                e.printStackTrace();
919
                e.printStackTrace();
576
            }
920
            }
577
            this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
921
            this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());
578
 
922
 
-
 
923
            if (partiel) {
-
 
924
                this.codeLettragePartiel.setText(getNextCodeLettragePartiel());
-
 
925
            } else {
-
 
926
                this.codeLettrage.setText(getNextCodeLettrage());
-
 
927
            }
-
 
928
 
579
            this.model.updateTotauxCompte();
929
            this.model.updateTotauxCompte();
580
        }
930
        }
581
    }
931
    }
582
 
932
 
583
    protected MaskFormatter createFormatter() {
933
    protected MaskFormatter createFormatter() {
584
        MaskFormatter formatter = null;
934
        MaskFormatter formatter = null;
585
        try {
935
        try {
586
            formatter = new MaskFormatter("UUU");
936
            formatter = new MaskFormatter("UUU");
587
        } catch (ParseException e) {
937
        } catch (ParseException e) {
588
            // TODO Auto-generated catch block
938
            // TODO Auto-generated catch block
589
            e.printStackTrace();
939
            e.printStackTrace();
590
        }
940
        }
591
        return formatter;
941
        return formatter;
592
    }
942
    }
593
 
943
 
594
    // Pointe la ligne passée en parametre
944
    // Pointe la ligne passée en parametre
595
    private void actionDelettrage(int[] rowIndex) {
945
    private void actionDelettrage(int[] rowIndex, boolean partiel) {
596
 
946
 
597
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
947
        List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);
598
 
948
 
599
        long solde = 0;
949
        long solde = 0;
600
        for (int i = 0; i < rowIndex.length; i++) {
950
        for (int i = 0; i < rowIndex.length; i++) {
601
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
951
            int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
602
            SQLRow row = this.tableEcr.getRow(id);
952
            SQLRow row = this.tableEcr.getRow(id);
603
            rowsSelected.add(row);
953
            rowsSelected.add(row);
604
 
954
 
605
            solde += ((Long) row.getObject("DEBIT")).longValue();
955
            solde += ((Long) row.getObject("DEBIT")).longValue();
606
            solde -= ((Long) row.getObject("CREDIT")).longValue();
956
            solde -= ((Long) row.getObject("CREDIT")).longValue();
607
        }
957
        }
608
 
958
 
609
        if (solde == 0) {
959
        if (partiel || solde == 0) {
610
            for (SQLRow row : rowsSelected) {
960
            for (SQLRow row : rowsSelected) {
611
 
961
 
612
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
962
                SQLRowValues rowVals = new SQLRowValues(this.tableEcr);
-
 
963
                if (partiel) {
-
 
964
                    // Dépointage
-
 
965
                    if (row.getString("LETTRAGE_PARTIEL").trim().length() != 0) {
613
 
966
 
-
 
967
                        rowVals.put("LETTRAGE_PARTIEL", "");
-
 
968
                        try {
-
 
969
                            rowVals.update(row.getID());
-
 
970
                        } catch (SQLException e1) {
-
 
971
                            e1.printStackTrace();
-
 
972
                        }
-
 
973
                    }
-
 
974
                } else {
614
                // Dépointage
975
                    // Dépointage
615
                if (row.getString("LETTRAGE").trim().length() != 0) {
976
                    if (row.getString("LETTRAGE").trim().length() != 0) {
616
 
977
 
617
                    rowVals.put("LETTRAGE", "");
978
                        rowVals.put("LETTRAGE", "");
618
                    rowVals.put("DATE_LETTRAGE", null);
979
                        rowVals.put("DATE_LETTRAGE", null);
619
                    try {
980
                        try {
620
                        rowVals.update(row.getID());
981
                            rowVals.update(row.getID());
621
                    } catch (SQLException e1) {
982
                        } catch (SQLException e1) {
622
                        e1.printStackTrace();
983
                            e1.printStackTrace();
623
                    }
984
                        }
-
 
985
                    }
624
                }
986
                }
625
            }
987
            }
626
        }
988
        }
627
        this.model.updateTotauxCompte();
989
        this.model.updateTotauxCompte();
628
    }
990
    }
629
 
991
 
630
    /*
992
    /*
631
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
993
     * MaJ de la requete pour remplir la IListe en fonction du compte sélectionner et du mode de
632
     * sélection
994
     * sélection
633
     */
995
     */
634
    private void changeListRequest() {
996
    private void changeListRequest() {
635
        Object idCpt = this.selCompte.getSelectedId();
997
        Object idCpt = this.selCompte.getSelectedId();
636
 
998
 
637
        SQLRow row = this.tableComptePCE.getRow(Integer.valueOf(idCpt.toString()));
999
        SQLRow row = this.tableComptePCE.getRow(Integer.valueOf(idCpt.toString()));
638
 
1000
 
639
        // filtre de selection
1001
        // filtre de selection
640
        Where w = new Where(this.tableEcr.getField("ID_COMPTE_PCE"), "=", this.tableComptePCE.getKey());
1002
        Where w = new Where(this.tableEcr.getField("ID_COMPTE_PCE"), "=", this.tableComptePCE.getKey());
641
 
1003
 
642
        if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
1004
        if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
643
            // TODO Show Restricted acces in UI
1005
            // TODO Show Restricted acces in UI
644
            w = w.and(new Where(this.tableEcr.getField("COMPTE_NUMERO"), "LIKE", "411%"));
1006
            w = w.and(new Where(this.tableEcr.getField("COMPTE_NUMERO"), "LIKE", "411%"));
645
        }
1007
        }
646
 
1008
 
647
        if (row != null) {
1009
        if (row != null) {
648
            String num = row.getString("NUMERO");
1010
            String num = row.getString("NUMERO");
649
            Where w2;
1011
            Where w2;
650
            if (this.boxAddSousCompte.isSelected()) {
1012
            if (this.boxAddSousCompte.isSelected()) {
651
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "LIKE", num + "%");
1013
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "LIKE", num + "%");
652
            } else {
1014
            } else {
653
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "=", num);
1015
                w2 = new Where(this.tableComptePCE.getField("NUMERO"), "=", num);
654
            }
1016
            }
655
            w = w.and(w2);
1017
            w = w.and(w2);
656
        } else {
1018
        } else {
657
            w = w.and(new Where(this.tableComptePCE.getKey(), "=", idCpt));
1019
            w = w.and(new Where(this.tableComptePCE.getKey(), "=", idCpt));
658
        }
1020
        }
659
 
1021
 
660
        if (this.tableEcr.getFields().contains("HIDE_LETTRAGE")) {
1022
        if (this.tableEcr.getFields().contains("HIDE_LETTRAGE")) {
661
            w = w.and(new Where(this.tableEcr.getField("HIDE_LETTRAGE"), "=", Boolean.FALSE));
1023
            w = w.and(new Where(this.tableEcr.getField("HIDE_LETTRAGE"), "=", Boolean.FALSE));
662
        }
1024
        }
663
 
1025
 
664
        // final Calendar cal = Calendar.getInstance();
1026
        // final Calendar cal = Calendar.getInstance();
665
        // cal.setTimeInMillis(this.rangeSlide.getValue(0));
1027
        // cal.setTimeInMillis(this.rangeSlide.getValue(0));
666
        //
1028
        //
667
        // Date dInf = cal.getTime();
1029
        // Date dInf = cal.getTime();
668
        // cal.setTimeInMillis(this.rangeSlide.getValue(1));
1030
        // cal.setTimeInMillis(this.rangeSlide.getValue(1));
669
        // Date dSup = cal.getTime();
1031
        // Date dSup = cal.getTime();
670
 
1032
 
671
        // w = w.and(new Where(this.tableEcr.getField("DATE"), dInf, dSup));
1033
        // w = w.and(new Where(this.tableEcr.getField("DATE"), dInf, dSup));
672
 
1034
 
673
        Date d1 = this.dateDeb.getValue();
1035
        Date d1 = this.dateDeb.getValue();
674
        Date d2 = this.dateFin.getValue();
1036
        Date d2 = this.dateFin.getValue();
675
 
1037
 
676
        if (d1 == null && d2 != null) {
1038
        if (d1 == null && d2 != null) {
677
            w = w.and(new Where(this.tableEcr.getField("DATE"), "<=", d2));
1039
            w = w.and(new Where(this.tableEcr.getField("DATE"), "<=", d2));
678
        } else {
1040
        } else {
679
            if (d1 != null && d2 == null) {
1041
            if (d1 != null && d2 == null) {
680
                w = w.and(new Where(this.tableEcr.getField("DATE"), ">=", d1));
1042
                w = w.and(new Where(this.tableEcr.getField("DATE"), ">=", d1));
681
            } else {
1043
            } else {
682
                if (d1 != null && d2 != null) {
1044
                if (d1 != null && d2 != null) {
683
                    w = w.and(new Where(this.tableEcr.getField("DATE"), d1, d2));
1045
                    w = w.and(new Where(this.tableEcr.getField("DATE"), d1, d2));
684
                }
1046
                }
685
            }
1047
            }
686
        }
1048
        }
687
 
1049
 
688
        if (this.modeSelect == ecritureLettree) {
1050
        if (this.modeSelect == ecritureLettree) {
689
            w = w.and(new Where(this.tableEcr.getField("LETTRAGE"), "!=", ""));
1051
            w = w.and(new Where(this.tableEcr.getField("LETTRAGE"), "!=", ""));
690
        } else {
1052
        } else {
691
            if (this.modeSelect == ecritureNonLettree) {
1053
            if (this.modeSelect == ecritureNonLettree) {
692
 
1054
 
693
                Where wLettre = new Where(this.tableEcr.getField("LETTRAGE"), "=", "");
1055
                Where wLettre = new Where(this.tableEcr.getField("LETTRAGE"), "=", "");
694
                String s = null;
1056
                String s = null;
695
                wLettre = wLettre.or(new Where(this.tableEcr.getField("LETTRAGE"), "=", s));
1057
                wLettre = wLettre.or(new Where(this.tableEcr.getField("LETTRAGE"), "=", s));
696
                w = w.and(wLettre);
1058
                w = w.and(wLettre);
697
            }
1059
            }
698
        }
1060
        }
699
 
1061
 
700
        this.ecriturePanel.getListe().getRequest().setWhere(w);
1062
        this.ecriturePanel.getListe().getRequest().setWhere(w);
701
        this.ecriturePanel.getListe().setModificationAllowed(false);
1063
        this.ecriturePanel.getListe().setModificationAllowed(false);
702
 
1064
 
703
        this.model.setIdCompte(Integer.parseInt(idCpt.toString()));
1065
        this.model.setIdCompte(Integer.parseInt(idCpt.toString()));
704
    }
1066
    }
705
 
1067
 
706
    /*
1068
    /*
707
     * Panel de sélection du mode d'affichage des ecritures
1069
     * Panel de sélection du mode d'affichage des ecritures
708
     */
1070
     */
709
    private JPanel createPanelSelectionEcritures() {
1071
    private JPanel createPanelSelectionEcritures() {
710
 
1072
 
711
        JPanel panelSelectEcritures = new JPanel();
1073
        JPanel panelSelectEcritures = new JPanel();
712
 
1074
 
713
        GridBagConstraints cPanel = new GridBagConstraints();
1075
        GridBagConstraints cPanel = new GridBagConstraints();
714
        cPanel.anchor = GridBagConstraints.NORTHWEST;
1076
        cPanel.anchor = GridBagConstraints.NORTHWEST;
715
        cPanel.fill = GridBagConstraints.HORIZONTAL;
1077
        cPanel.fill = GridBagConstraints.HORIZONTAL;
716
        cPanel.gridheight = 1;
1078
        cPanel.gridheight = 1;
717
        cPanel.gridwidth = 1;
1079
        cPanel.gridwidth = 1;
718
        cPanel.gridx = 0;
1080
        cPanel.gridx = 0;
719
        cPanel.gridy = 0;
1081
        cPanel.gridy = 0;
720
        cPanel.weightx = 0;
1082
        cPanel.weightx = 0;
721
        cPanel.weighty = 0;
1083
        cPanel.weighty = 0;
722
 
1084
 
723
        panelSelectEcritures.setLayout(new GridBagLayout());
1085
        panelSelectEcritures.setLayout(new GridBagLayout());
724
 
1086
 
725
        final JRadioButton buttonBoth = new JRadioButton("Toutes");
1087
        final JRadioButton buttonBoth = new JRadioButton("Toutes");
726
        panelSelectEcritures.add(buttonBoth, cPanel);
1088
        panelSelectEcritures.add(buttonBoth, cPanel);
727
        cPanel.gridx++;
1089
        cPanel.gridx++;
728
        final JRadioButton buttonNonLettre = new JRadioButton("Non lettrées");
1090
        final JRadioButton buttonNonLettre = new JRadioButton("Non lettrées");
729
        panelSelectEcritures.add(buttonNonLettre, cPanel);
1091
        panelSelectEcritures.add(buttonNonLettre, cPanel);
730
        cPanel.gridx++;
1092
        cPanel.gridx++;
731
        final JRadioButton buttonLettre = new JRadioButton("Lettrées");
1093
        final JRadioButton buttonLettre = new JRadioButton("Lettrées");
732
        panelSelectEcritures.add(buttonLettre, cPanel);
1094
        panelSelectEcritures.add(buttonLettre, cPanel);
733
 
1095
 
734
        ButtonGroup group = new ButtonGroup();
1096
        ButtonGroup group = new ButtonGroup();
735
        group.add(buttonBoth);
1097
        group.add(buttonBoth);
736
        group.add(buttonNonLettre);
1098
        group.add(buttonNonLettre);
737
        group.add(buttonLettre);
1099
        group.add(buttonLettre);
738
        buttonBoth.setSelected(true);
1100
        buttonBoth.setSelected(true);
739
 
1101
 
740
        buttonLettre.addActionListener(new ActionListener() {
1102
        buttonLettre.addActionListener(new ActionListener() {
741
            public void actionPerformed(ActionEvent e) {
1103
            public void actionPerformed(ActionEvent e) {
742
                if (buttonLettre.isSelected()) {
1104
                if (buttonLettre.isSelected()) {
743
                    LettragePanel.this.modeSelect = ecritureLettree;
1105
                    LettragePanel.this.modeSelect = ecritureLettree;
744
                    changeListRequest();
1106
                    changeListRequest();
745
                }
1107
                }
746
            }
1108
            }
747
        });
1109
        });
748
 
1110
 
749
        buttonNonLettre.addActionListener(new ActionListener() {
1111
        buttonNonLettre.addActionListener(new ActionListener() {
750
            public void actionPerformed(ActionEvent e) {
1112
            public void actionPerformed(ActionEvent e) {
751
                if (buttonNonLettre.isSelected()) {
1113
                if (buttonNonLettre.isSelected()) {
752
                    LettragePanel.this.modeSelect = ecritureNonLettree;
1114
                    LettragePanel.this.modeSelect = ecritureNonLettree;
753
                    changeListRequest();
1115
                    changeListRequest();
754
                }
1116
                }
755
            }
1117
            }
756
        });
1118
        });
757
 
1119
 
758
        buttonBoth.addActionListener(new ActionListener() {
1120
        buttonBoth.addActionListener(new ActionListener() {
759
            public void actionPerformed(ActionEvent e) {
1121
            public void actionPerformed(ActionEvent e) {
760
                if (buttonBoth.isSelected()) {
1122
                if (buttonBoth.isSelected()) {
761
                    LettragePanel.this.modeSelect = allEcriture;
1123
                    LettragePanel.this.modeSelect = allEcriture;
762
                    changeListRequest();
1124
                    changeListRequest();
763
                }
1125
                }
764
            }
1126
            }
765
        });
1127
        });
766
 
1128
 
767
        return panelSelectEcritures;
1129
        return panelSelectEcritures;
768
    }
1130
    }
769
 
1131
 
770
    /*
1132
    /*
771
     * Creation du panel de la legende
1133
     * Creation du panel de la legende
772
     */
1134
     */
773
    private JPanel createPanelLegende() {
1135
    private JPanel createPanelLegende() {
774
        JPanel panelLegende = new JPanel();
1136
        JPanel panelLegende = new JPanel();
775
 
1137
 
776
        GridBagConstraints c = new GridBagConstraints();
1138
        GridBagConstraints c = new GridBagConstraints();
777
        c.anchor = GridBagConstraints.NORTHWEST;
1139
        c.anchor = GridBagConstraints.NORTHWEST;
778
        c.fill = GridBagConstraints.HORIZONTAL;
1140
        c.fill = GridBagConstraints.HORIZONTAL;
779
        c.gridheight = 1;
1141
        c.gridheight = 1;
780
        c.gridwidth = 1;
1142
        c.gridwidth = 1;
781
        c.gridx = 0;
1143
        c.gridx = 0;
782
        c.gridy = GridBagConstraints.RELATIVE;
1144
        c.gridy = GridBagConstraints.RELATIVE;
783
        c.weightx = 0;
1145
        c.weightx = 0;
784
        c.weighty = 0;
1146
        c.weighty = 0;
785
        c.insets = new Insets(2, 0, 0, 0);
1147
        c.insets = new Insets(2, 0, 0, 0);
786
 
1148
 
787
        GridBagConstraints cPanel = new GridBagConstraints();
1149
        GridBagConstraints cPanel = new GridBagConstraints();
788
        cPanel.anchor = GridBagConstraints.NORTHWEST;
1150
        cPanel.anchor = GridBagConstraints.NORTHWEST;
789
        cPanel.fill = GridBagConstraints.HORIZONTAL;
1151
        cPanel.fill = GridBagConstraints.HORIZONTAL;
790
        cPanel.gridheight = 1;
1152
        cPanel.gridheight = 1;
791
        cPanel.gridwidth = 1;
1153
        cPanel.gridwidth = 1;
792
        cPanel.gridx = 0;
1154
        cPanel.gridx = 0;
793
        cPanel.gridy = GridBagConstraints.RELATIVE;
1155
        cPanel.gridy = GridBagConstraints.RELATIVE;
794
        cPanel.weightx = 0;
1156
        cPanel.weightx = 0;
795
        cPanel.weighty = 0;
1157
        cPanel.weighty = 0;
796
        cPanel.insets = new Insets(0, 0, 0, 0);
1158
        cPanel.insets = new Insets(0, 0, 0, 0);
797
 
1159
 
798
        panelLegende.setLayout(new GridBagLayout());
1160
        panelLegende.setLayout(new GridBagLayout());
799
        panelLegende.setBorder(BorderFactory.createTitledBorder("Légendes"));
1161
        panelLegende.setBorder(BorderFactory.createTitledBorder("Légendes"));
800
 
1162
 
801
        JPanel ecritureValidPanel = new JPanel();
1163
        JPanel ecritureValidPanel = new JPanel();
802
        ecritureValidPanel.setLayout(new GridBagLayout());
1164
        ecritureValidPanel.setLayout(new GridBagLayout());
803
        ecritureValidPanel.setBackground(Color.WHITE);
1165
        ecritureValidPanel.setBackground(Color.WHITE);
804
        ecritureValidPanel.add(new JLabel("Ecritures validées"), cPanel);
1166
        ecritureValidPanel.add(new JLabel("Ecritures validées"), cPanel);
805
        panelLegende.add(ecritureValidPanel, c);
1167
        panelLegende.add(ecritureValidPanel, c);
806
 
1168
 
807
        JPanel ecritureNonValidPanel = new JPanel();
1169
        JPanel ecritureNonValidPanel = new JPanel();
808
        ecritureNonValidPanel.setLayout(new GridBagLayout());
1170
        ecritureNonValidPanel.setLayout(new GridBagLayout());
809
        ecritureNonValidPanel.setBackground(PointageRenderer.getCouleurEcritureNonValide());
1171
        ecritureNonValidPanel.setBackground(PointageRenderer.getCouleurEcritureNonValide());
810
        ecritureNonValidPanel.add(new JLabel("Ecritures non validées"), cPanel);
1172
        ecritureNonValidPanel.add(new JLabel("Ecritures non validées"), cPanel);
811
        panelLegende.add(ecritureNonValidPanel, c);
1173
        panelLegende.add(ecritureNonValidPanel, c);
812
 
1174
 
813
        JPanel ecritureNonValidTodayPanel = new JPanel();
1175
        JPanel ecritureNonValidTodayPanel = new JPanel();
814
        ecritureNonValidTodayPanel.setLayout(new GridBagLayout());
1176
        ecritureNonValidTodayPanel.setLayout(new GridBagLayout());
815
        ecritureNonValidTodayPanel.setBackground(PointageRenderer.getCouleurEcritureToDay());
1177
        ecritureNonValidTodayPanel.setBackground(PointageRenderer.getCouleurEcritureToDay());
816
        ecritureNonValidTodayPanel.add(new JLabel("Ecritures non validées du jour"), cPanel);
1178
        ecritureNonValidTodayPanel.add(new JLabel("Ecritures non validées du jour"), cPanel);
817
        panelLegende.add(ecritureNonValidTodayPanel, c);
1179
        panelLegende.add(ecritureNonValidTodayPanel, c);
818
 
1180
 
819
        JPanel ecriturePointePanel = new JPanel();
1181
        JPanel ecriturePointePanel = new JPanel();
820
        ecriturePointePanel.setLayout(new GridBagLayout());
1182
        ecriturePointePanel.setLayout(new GridBagLayout());
821
        ecriturePointePanel.setBackground(PointageRenderer.getCouleurEcriturePointee());
1183
        ecriturePointePanel.setBackground(PointageRenderer.getCouleurEcriturePointee());
822
        ecriturePointePanel.add(new JLabel("Ecritures lettrées"), cPanel);
1184
        ecriturePointePanel.add(new JLabel("Ecritures lettrées"), cPanel);
823
        panelLegende.add(ecriturePointePanel, c);
1185
        panelLegende.add(ecriturePointePanel, c);
824
 
1186
 
825
        return panelLegende;
1187
        return panelLegende;
826
    }
1188
    }
827
}
1189
}