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.payment.component;
14
 package org.openconcerto.erp.core.finance.payment.component;
15
 
15
 
16
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
16
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
17
import org.openconcerto.erp.core.common.ui.DeviseField;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
19
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
19
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement;
20
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
20
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable;
21
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
21
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
22
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.BaseSQLComponent;
23
import org.openconcerto.sql.element.BaseSQLComponent;
24
import org.openconcerto.sql.element.ElementSQLObject;
24
import org.openconcerto.sql.element.ElementSQLObject;
25
import org.openconcerto.sql.element.SQLComponent;
25
import org.openconcerto.sql.element.SQLComponent;
26
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.element.SQLElement;
27
import org.openconcerto.sql.model.SQLInjector;
27
import org.openconcerto.sql.model.SQLInjector;
28
import org.openconcerto.sql.model.SQLRow;
28
import org.openconcerto.sql.model.SQLRow;
29
import org.openconcerto.sql.model.SQLRowAccessor;
29
import org.openconcerto.sql.model.SQLRowAccessor;
30
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.SQLRowValues;
-
 
31
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
31
import org.openconcerto.sql.model.SQLTable;
32
import org.openconcerto.sql.model.SQLTable;
-
 
33
import org.openconcerto.sql.model.Where;
32
import org.openconcerto.sql.sqlobject.ElementComboBox;
34
import org.openconcerto.sql.sqlobject.ElementComboBox;
33
import org.openconcerto.sql.view.list.RowValuesTableModel;
35
import org.openconcerto.sql.view.list.RowValuesTableModel;
34
import org.openconcerto.ui.DefaultGridBagConstraints;
36
import org.openconcerto.ui.DefaultGridBagConstraints;
35
import org.openconcerto.ui.JDate;
37
import org.openconcerto.ui.JDate;
36
import org.openconcerto.ui.JLabelBold;
38
import org.openconcerto.ui.JLabelBold;
37
import org.openconcerto.ui.warning.JLabelWarning;
39
import org.openconcerto.ui.warning.JLabelWarning;
38
import org.openconcerto.utils.ExceptionHandler;
40
import org.openconcerto.utils.ExceptionHandler;
39
import org.openconcerto.utils.GestionDevise;
41
import org.openconcerto.utils.GestionDevise;
40
import org.openconcerto.utils.text.SimpleDocumentListener;
42
import org.openconcerto.utils.text.SimpleDocumentListener;
41
 
43
 
42
import java.awt.GridBagConstraints;
44
import java.awt.GridBagConstraints;
43
import java.awt.GridBagLayout;
45
import java.awt.GridBagLayout;
44
import java.awt.Insets;
46
import java.awt.Insets;
45
import java.sql.SQLException;
47
import java.sql.SQLException;
46
import java.util.Calendar;
48
import java.util.Calendar;
47
import java.util.Collections;
49
import java.util.Collections;
48
import java.util.Comparator;
50
import java.util.Comparator;
49
import java.util.List;
51
import java.util.List;
50
 
52
 
51
import javax.swing.JCheckBox;
53
import javax.swing.JCheckBox;
52
import javax.swing.JLabel;
54
import javax.swing.JLabel;
53
import javax.swing.JTextField;
55
import javax.swing.JTextField;
54
import javax.swing.SwingConstants;
56
import javax.swing.SwingConstants;
55
import javax.swing.event.DocumentEvent;
57
import javax.swing.event.DocumentEvent;
56
import javax.swing.event.TableModelEvent;
58
import javax.swing.event.TableModelEvent;
57
import javax.swing.event.TableModelListener;
59
import javax.swing.event.TableModelListener;
58
 
60
 
59
public class EncaisserMontantSQLComponent extends BaseSQLComponent {
61
public class EncaisserMontantSQLComponent extends BaseSQLComponent {
60
 
62
 
61
    private EncaisseMontantTable table = new EncaisseMontantTable();
63
    private EncaisseMontantTable table = new EncaisseMontantTable();
62
 
64
 
63
    private JTextField nom = new JTextField();
65
    private JTextField nom = new JTextField();
64
    private DeviseField montant = new DeviseField(10);
66
    private DeviseField montant = new DeviseField(10);
65
    private JLabel labelWarning = new JLabelWarning("Le montant est trop élevé!");
67
    private JLabel labelWarning = new JLabelWarning("Le montant est trop élevé!");
66
 
68
 
67
    private JDate date;
69
    private JDate date;
68
    private ElementSQLObject eltModeRegl;
70
    private ElementSQLObject eltModeRegl;
69
 
71
 
70
    final TableModelListener tableListener = new TableModelListener() {
72
    final TableModelListener tableListener = new TableModelListener() {
71
 
73
 
72
        @Override
74
        @Override
73
        public void tableChanged(TableModelEvent e) {
75
        public void tableChanged(TableModelEvent e) {
74
            final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
76
            final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
75
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
77
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())) {
76
 
78
 
77
                final int rowCount = model.getRowCount();
79
                final int rowCount = model.getRowCount();
78
                long total = 0;
80
                long total = 0;
79
                for (int i = 0; i < rowCount; i++) {
81
                for (int i = 0; i < rowCount; i++) {
80
                    Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
82
                    Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantElement()));
81
                    if (nHT != null) {
83
                    if (nHT != null) {
82
                        total += nHT.longValue();
84
                        total += nHT.longValue();
83
                    }
85
                    }
84
                }
86
                }
85
 
87
 
86
                montant.getDocument().removeDocumentListener(listenerMontant);
88
                montant.getDocument().removeDocumentListener(listenerMontant);
87
                montant.setText(GestionDevise.currencyToString(total));
89
                montant.setText(GestionDevise.currencyToString(total));
88
                montant.getDocument().addDocumentListener(listenerMontant);
90
                montant.getDocument().addDocumentListener(listenerMontant);
89
                // Selection du mode de reglement
91
                // Selection du mode de reglement
90
                if (getMode() == SQLComponent.Mode.INSERTION) {
92
                if (getMode() == SQLComponent.Mode.INSERTION) {
91
                    if (rowCount >= 1) {
93
                    if (rowCount >= 1) {
92
 
94
 
93
                        MouvementSQLElement element = getElement().getDirectory().getElement(MouvementSQLElement.class);
95
                        MouvementSQLElement element = getElement().getDirectory().getElement(MouvementSQLElement.class);
94
                        SQLRowValues row1 = model.getRowValuesAt(0);
96
                        SQLRowValues row1 = model.getRowValuesAt(0);
95
                        if (row1.getObject("ID_MOUVEMENT_ECHEANCE") != null && !row1.isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
97
                        if (row1.getObject("ID_MOUVEMENT_ECHEANCE") != null && !row1.isForeignEmpty("ID_MOUVEMENT_ECHEANCE")) {
96
                            final int idScr = element.getSourceId(row1.getForeignID("ID_MOUVEMENT_ECHEANCE"));
98
                            final int idScr = element.getSourceId(row1.getForeignID("ID_MOUVEMENT_ECHEANCE"));
97
                            SQLTable tableMvt = element.getTable();
99
                            SQLTable tableMvt = element.getTable();
98
                            if (idScr > 1) {
100
                            if (idScr > 1) {
99
                                SQLRow rowMvt = tableMvt.getRow(idScr);
101
                                SQLRow rowMvt = tableMvt.getRow(idScr);
100
                                String source = rowMvt.getString("SOURCE");
102
                                String source = rowMvt.getString("SOURCE");
101
                                int idSource = rowMvt.getInt("IDSOURCE");
103
                                int idSource = rowMvt.getInt("IDSOURCE");
102
                                SQLElement eltSource = element.getDirectory().getElement(source);
104
                                SQLElement eltSource = element.getDirectory().getElement(source);
103
                                if (eltSource != null) {
105
                                if (eltSource != null) {
104
                                    SQLRow rowSource = eltSource.getTable().getRow(idSource);
106
                                    SQLRow rowSource = eltSource.getTable().getRow(idSource);
105
 
107
 
106
                                    if (rowSource != null) {
108
                                    if (rowSource != null) {
107
                                        SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
109
                                        SQLRow rowModeRegl = rowSource.getForeignRow("ID_MODE_REGLEMENT");
108
                                        if (rowModeRegl != null) {
110
                                        if (rowModeRegl != null) {
109
                                            System.err.println("Set mode de règlement");
111
                                            System.err.println("Set mode de règlement");
110
                                            int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
112
                                            int idTypeRegl = rowModeRegl.getInt("ID_TYPE_REGLEMENT");
111
                                            SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
113
                                            SQLTable tableModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT").getTable();
112
                                            SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
114
                                            SQLRowValues rowVals = new SQLRowValues(tableModeRegl);
113
                                            rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
115
                                            rowVals.put("ID_TYPE_REGLEMENT", idTypeRegl);
114
                                            rowVals.put("COMPTANT", Boolean.TRUE);
116
                                            rowVals.put("COMPTANT", Boolean.TRUE);
115
                                            rowVals.put("AJOURS", 0);
117
                                            rowVals.put("AJOURS", 0);
116
                                            rowVals.put("LENJOUR", 0);
118
                                            rowVals.put("LENJOUR", 0);
117
                                            rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
119
                                            rowVals.put("ID_" + BanqueSQLElement.TABLENAME, rowModeRegl.getInt("ID_" + BanqueSQLElement.TABLENAME));
118
                                            eltModeRegl.setValue(rowVals);
120
                                            eltModeRegl.setValue(rowVals);
119
                                        }
121
                                        }
120
                                    }
122
                                    }
121
                                }
123
                                }
122
                            }
124
                            }
123
                        }
125
                        }
124
                    }
126
                    }
125
                }
127
                }
126
 
128
 
127
            }
129
            }
128
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())
130
            if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == model.getColumnIndexForElement(table.getMontantElement())
129
                    || e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
131
                    || e.getColumn() == model.getColumnIndexForElement(table.getMontantAReglerElement())) {
130
                updateWarning();
132
                updateWarning();
131
            }
133
            }
132
        }
134
        }
133
    };
135
    };
134
 
136
 
135
    final SimpleDocumentListener listenerMontant = new SimpleDocumentListener() {
137
    final SimpleDocumentListener listenerMontant = new SimpleDocumentListener() {
136
 
138
 
137
        @Override
139
        @Override
138
        public void update(DocumentEvent e) {
140
        public void update(DocumentEvent e) {
139
            table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
141
            table.getRowValuesTable().getRowValuesTableModel().removeTableModelListener(tableListener);
140
            updateMontant(montant.getText());
142
            updateMontant(montant.getText());
141
            table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
143
            table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
142
            updateWarning();
144
            updateWarning();
143
 
145
 
144
        }
146
        }
145
    };
147
    };
146
 
148
 
147
    public EncaisserMontantSQLComponent(SQLElement elt) {
149
    public EncaisserMontantSQLComponent(SQLElement elt) {
148
        super(elt);
150
        super(elt);
149
    }
151
    }
150
 
152
 
151
    @Override
153
    @Override
152
    public void addViews() {
154
    public void addViews() {
153
        this.setLayout(new GridBagLayout());
155
        this.setLayout(new GridBagLayout());
154
 
156
 
155
        final GridBagConstraints c = new DefaultGridBagConstraints();
157
        final GridBagConstraints c = new DefaultGridBagConstraints();
156
 
158
 
157
        c.gridwidth = GridBagConstraints.REMAINDER;
159
        c.gridwidth = GridBagConstraints.REMAINDER;
158
        c.weightx = 1;
160
        c.weightx = 1;
159
        this.add(new JLabelBold("Echéances"), c);
161
        this.add(new JLabelBold("Echéances"), c);
160
        c.gridy++;
162
        c.gridy++;
161
        c.weighty = 1;
163
        c.weighty = 1;
162
        c.fill = GridBagConstraints.BOTH;
164
        c.fill = GridBagConstraints.BOTH;
163
        this.add(this.table, c);
165
        this.add(this.table, c);
164
        c.fill = GridBagConstraints.HORIZONTAL;
166
        c.fill = GridBagConstraints.HORIZONTAL;
165
        c.gridwidth = 1;
167
        c.gridwidth = 1;
166
        c.gridy++;
168
        c.gridy++;
167
        c.weighty = 0;
169
        c.weighty = 0;
168
 
170
 
169
        // Client
171
        // Client
170
        final ElementComboBox comboClient = new ElementComboBox(true, 25);
172
        final ElementComboBox comboClient = new ElementComboBox(true, 25);
171
        c.gridx = 0;
173
        c.gridx = 0;
172
        c.gridy++;
174
        c.gridy++;
173
        c.weightx = 0;
175
        c.weightx = 0;
174
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
176
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
175
 
177
 
176
        c.gridx++;
178
        c.gridx++;
177
        c.weightx = 1;
179
        c.weightx = 1;
178
        c.gridwidth = 1;
180
        c.gridwidth = 1;
179
        this.add(comboClient, c);
181
        this.add(comboClient, c);
180
        c.gridwidth = 1;
182
        c.gridwidth = 1;
181
 
183
 
182
        // Date
184
        // Date
183
        this.date = new JDate(true);
185
        this.date = new JDate(true);
184
        c.gridx = GridBagConstraints.RELATIVE;
186
        c.gridx = GridBagConstraints.RELATIVE;
185
        c.weightx = 0;
187
        c.weightx = 0;
186
        c.gridwidth = 1;
188
        c.gridwidth = 1;
187
        this.add(new JLabel("Date"), c);
189
        this.add(new JLabel("Date"), c);
188
        // c.gridx++;
190
        // c.gridx++;
189
        c.weightx = 0;
191
        c.weightx = 0;
190
        this.add(this.date, c);
192
        this.add(this.date, c);
191
 
193
 
192
        this.addSQLObject(comboClient, "ID_CLIENT");
194
        this.addSQLObject(comboClient, "ID_CLIENT");
193
 
195
 
194
        final ElementComboBox comboD = new ElementComboBox();
196
        final ElementComboBox comboD = new ElementComboBox();
195
        this.addSQLObject(comboD, "ID_DEVIS");
197
        this.addSQLObject(comboD, "ID_DEVIS");
196
 
198
 
197
        // Nom
199
        // Nom
198
        c.gridy++;
200
        c.gridy++;
199
        c.gridx = 0;
201
        c.gridx = 0;
200
        final JLabel label = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
202
        final JLabel label = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
201
        c.weightx = 0;
203
        c.weightx = 0;
202
        this.add(label, c);
204
        this.add(label, c);
203
        c.gridx++;
205
        c.gridx++;
204
        c.weightx = 1;
206
        c.weightx = 1;
205
        c.gridwidth = 2;
207
        c.gridwidth = 2;
206
        this.add(this.nom, c);
208
        this.add(this.nom, c);
207
        c.gridx += 2;
209
        c.gridx += 2;
208
        c.gridwidth = GridBagConstraints.REMAINDER;
210
        c.gridwidth = GridBagConstraints.REMAINDER;
209
        JCheckBox box = new JCheckBox(getLabelFor("ACOMPTE"));
211
        JCheckBox box = new JCheckBox(getLabelFor("ACOMPTE"));
210
        box.setEnabled(false);
212
        box.setEnabled(false);
211
        this.add(box, c);
213
        this.add(box, c);
212
        addView(box, "ACOMPTE");
214
        addView(box, "ACOMPTE");
213
 
215
 
214
        // Montant
216
        // Montant
215
        c.gridwidth = 1;
217
        c.gridwidth = 1;
216
        c.gridy++;
218
        c.gridy++;
217
        c.gridx = 0;
219
        c.gridx = 0;
218
        c.weightx = 0;
220
        c.weightx = 0;
219
        this.add(new JLabel("Montant encaissé", SwingConstants.RIGHT), c);
221
        this.add(new JLabel("Montant encaissé", SwingConstants.RIGHT), c);
220
 
222
 
221
        c.gridx++;
223
        c.gridx++;
222
        c.gridwidth = 3;
224
        c.gridwidth = 3;
223
        c.weightx = 1;
225
        c.weightx = 1;
224
        c.fill = GridBagConstraints.NONE;
226
        c.fill = GridBagConstraints.NONE;
225
        this.add(this.montant, c);
227
        this.add(this.montant, c);
226
 
228
 
227
        // Warning
229
        // Warning
228
        c.gridx++;
230
        c.gridx++;
229
        c.weightx = 0;
231
        c.weightx = 0;
230
        c.gridwidth = GridBagConstraints.REMAINDER;
232
        c.gridwidth = GridBagConstraints.REMAINDER;
231
        this.labelWarning.setHorizontalAlignment(SwingConstants.RIGHT);
233
        this.labelWarning.setHorizontalAlignment(SwingConstants.RIGHT);
232
        this.add(this.labelWarning, c);
234
        this.add(this.labelWarning, c);
233
 
235
 
234
        /***********************************************************************************
236
        /***********************************************************************************
235
         * * MODE DE REGLEMENT
237
         * * MODE DE REGLEMENT
236
         **********************************************************************************/
238
         **********************************************************************************/
237
        c.fill = GridBagConstraints.HORIZONTAL;
239
        c.fill = GridBagConstraints.HORIZONTAL;
238
        c.gridwidth = GridBagConstraints.REMAINDER;
240
        c.gridwidth = GridBagConstraints.REMAINDER;
239
        c.gridx = 0;
241
        c.gridx = 0;
240
        c.gridy++;
242
        c.gridy++;
241
        c.weightx = 1;
243
        c.weightx = 1;
242
        final JLabelBold sep = new JLabelBold("Mode de règlement");
244
        final JLabelBold sep = new JLabelBold("Mode de règlement");
243
        c.insets = new Insets(10, 2, 1, 2);
245
        c.insets = new Insets(10, 2, 1, 2);
244
        this.add(sep, c);
246
        this.add(sep, c);
245
        c.insets = new Insets(2, 2, 1, 2);
247
        c.insets = new Insets(2, 2, 1, 2);
246
 
248
 
247
        c.gridx = 0;
249
        c.gridx = 0;
248
        c.gridy++;
250
        c.gridy++;
249
        c.gridwidth = GridBagConstraints.REMAINDER;
251
        c.gridwidth = GridBagConstraints.REMAINDER;
250
        this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
252
        this.addView("ID_MODE_REGLEMENT", BaseSQLComponent.REQ + ";" + BaseSQLComponent.DEC + ";" + BaseSQLComponent.SEP);
251
        this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
253
        this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
252
        this.add(this.eltModeRegl, c);
254
        this.add(this.eltModeRegl, c);
253
        ModeDeReglementSQLComponent modeReglComp;
255
        ModeDeReglementSQLComponent modeReglComp;
254
 
256
 
255
        modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
257
        modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild();
256
        modeReglComp.addDateCompListener(this.date);
258
        modeReglComp.addDateCompListener(this.date);
257
        this.addRequiredSQLObject(this.date, "DATE");
259
        this.addRequiredSQLObject(this.date, "DATE");
258
        this.addRequiredSQLObject(this.montant, "MONTANT");
260
        this.addRequiredSQLObject(this.montant, "MONTANT");
259
 
261
 
260
        this.addSQLObject(this.nom, "NOM");
262
        this.addSQLObject(this.nom, "NOM");
261
 
263
 
262
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
264
        this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS");
263
        this.addSQLObject(new JTextField(), "TIERS");
265
        this.addSQLObject(new JTextField(), "TIERS");
264
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
266
        DefaultGridBagConstraints.lockMinimumSize(this.montant);
265
 
267
 
266
        this.montant.getDocument().addDocumentListener(listenerMontant);
268
        this.montant.getDocument().addDocumentListener(listenerMontant);
267
        this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
269
        this.table.getRowValuesTable().getRowValuesTableModel().addTableModelListener(tableListener);
268
 
270
 
269
    }
271
    }
270
 
272
 
271
    private void updateMontant(String s) {
273
    private void updateMontant(String s) {
272
 
274
 
273
        long total = 0;
275
        long total = 0;
274
        if (s.trim().length() > 0) {
276
        if (s.trim().length() > 0) {
275
            total = GestionDevise.parseLongCurrency(s);
277
            total = GestionDevise.parseLongCurrency(s);
276
        }
278
        }
277
        final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
279
        final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
278
 
280
 
279
        final int rowCount = model.getRowCount();
281
        final int rowCount = model.getRowCount();
280
        for (int i = 0; i < rowCount; i++) {
282
        for (int i = 0; i < rowCount; i++) {
281
            Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantAReglerElement()));
283
            Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantAReglerElement()));
282
            Long value = Long.valueOf(0);
284
            Long value = Long.valueOf(0);
283
            if (i < rowCount - 1) {
285
            if (i < rowCount - 1) {
284
                if (nHT.longValue() <= total) {
286
                if (nHT.longValue() <= total) {
285
                    value = nHT.longValue();
287
                    value = nHT.longValue();
286
                } else {
288
                } else {
287
                    value = total;
289
                    value = total;
288
                }
290
                }
289
            } else {
291
            } else {
290
                value = total;
292
                value = total;
291
            }
293
            }
292
            model.putValue(value, i, "MONTANT_REGLE");
294
            model.putValue(value, i, "MONTANT_REGLE");
293
            total = total - value;
295
            total = total - value;
294
        }
296
        }
295
    }
297
    }
296
 
298
 
297
    @Override
299
    @Override
298
    public void select(SQLRowAccessor r) {
300
    public void select(SQLRowAccessor r) {
299
        super.select(r);
301
        super.select(r);
300
        if (r != null && r.getID() > 1) {
302
        if (r != null && r.getID() > 1) {
301
            this.table.insertFrom("ID_ENCAISSER_MONTANT", r.getID());
303
            this.table.insertFrom("ID_ENCAISSER_MONTANT", r.getID());
302
        } else if (r != null && r instanceof SQLRowValues) {
304
        } else if (r != null && r instanceof SQLRowValues) {
303
            this.table.insertFrom((SQLRowValues) r);
305
            this.table.insertFrom((SQLRowValues) r);
304
 
306
 
305
        }
307
        }
306
    }
308
    }
307
 
309
 
308
    @Override
310
    @Override
309
    public int insert(SQLRow order) {
311
    public int insert(SQLRow order) {
310
 
312
 
311
        int id = super.insert(order);
313
        int id = super.insert(order);
312
        this.table.updateField("ID_ENCAISSER_MONTANT", id);
314
        this.table.updateField("ID_ENCAISSER_MONTANT", id);
313
 
315
 
314
        System.out.println("Génération des ecritures du reglement");
316
        System.out.println("Génération des ecritures du reglement");
315
        SQLRow row = getTable().getRow(id);
317
        SQLRow row = getTable().getRow(id);
-
 
318
        try {
-
 
319
            ((EncaisserMontantSQLElement) getElement()).regleFacture(row, null, false);
-
 
320
        } catch (Exception e) {
-
 
321
            ExceptionHandler.handle("Erreur de génération des écritures", e);
-
 
322
        }
-
 
323
        return id;
-
 
324
    }
-
 
325
 
-
 
326
    @Override
-
 
327
    public void update() {
-
 
328
 
-
 
329
        int id = getSelectedID();
-
 
330
        SQLRowValues rowValsFetcValues = new SQLRowValues(getTable());
-
 
331
        rowValsFetcValues.putRowValues("ID_MOUVEMENT").putNulls("ID","SOURCE","IDSOURCE");
-
 
332
        SQLRowValues rowValsFetcValuesItem = new SQLRowValues(getTable().getTable("ENCAISSER_MONTANT_ELEMENT"));
-
 
333
        rowValsFetcValuesItem.put("ID_ENCAISSER_MONTANT", rowValsFetcValues).putNulls("MONTANT_REGLE");
-
 
334
        rowValsFetcValuesItem.putRowValues("ID_ECHEANCE_CLIENT").putNulls("MONTANT", "REGLE");
-
 
335
        List<SQLRowValues> oldEch = SQLRowValuesListFetcher.create(rowValsFetcValues).fetch(new Where(getTable().getKey(), "=", id));
-
 
336
        super.update();
-
 
337
        this.table.updateField("ID_ENCAISSER_MONTANT", id);
-
 
338
 
-
 
339
        System.out.println("Génération des ecritures du reglement");
-
 
340
        SQLRow row = getTable().getRow(id);
316
 
341
 
317
        try {
342
        try {
318
            ((EncaisserMontantSQLElement) getElement()).regleFacture(row);
343
            ((EncaisserMontantSQLElement) getElement()).regleFacture(row, oldEch.get(0), true);
319
        } catch (Exception e) {
344
        } catch (Exception e) {
320
            ExceptionHandler.handle("Erreur de génération des écritures", e);
345
            ExceptionHandler.handle("Erreur de génération des écritures", e);
321
        }
346
        }
322
 
347
 
323
        return id;
-
 
324
    }
348
    }
325
 
349
 
326
    @Override
350
    @Override
327
    protected SQLRowValues createDefaults() {
351
    protected SQLRowValues createDefaults() {
328
        SQLRowValues vals = new SQLRowValues(this.getTable());
352
        SQLRowValues vals = new SQLRowValues(this.getTable());
329
        SQLRowAccessor r;
353
        SQLRowAccessor r;
330
        this.table.getModel().clearRows();
354
        this.table.getModel().clearRows();
331
        try {
355
        try {
332
            r = ModeReglementDefautPrefPanel.getDefaultRow(false);
356
            r = ModeReglementDefautPrefPanel.getDefaultRow(false);
333
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
357
            SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
334
            if (r.getID() > 1) {
358
            if (r.getID() > 1) {
335
                SQLRowValues rowVals = eltModeReglement.createCopy(r.getID());
359
                SQLRowValues rowVals = eltModeReglement.createCopy(r.getID());
336
                vals.put("ID_MODE_REGLEMENT", rowVals);
360
                vals.put("ID_MODE_REGLEMENT", rowVals);
337
            }
361
            }
338
        } catch (SQLException e) {
362
        } catch (SQLException e) {
339
            System.err.println("Impossible de sélectionner le mode de règlement par défaut du client.");
363
            System.err.println("Impossible de sélectionner le mode de règlement par défaut du client.");
340
            e.printStackTrace();
364
            e.printStackTrace();
341
        }
365
        }
342
        return vals;
366
        return vals;
343
    }
367
    }
344
 
368
 
345
    // test si le montant est correct par rapport à l'echeance selectionnée
369
    // test si le montant est correct par rapport à l'echeance selectionnée
346
    private final void updateWarning() {
370
    private final void updateWarning() {
347
 
371
 
348
        long montantValue = 0;
372
        long montantValue = 0;
349
 
373
 
350
        if (this.table.getRowValuesTable().getRowCount() == 0) {
374
        if (this.table.getRowValuesTable().getRowCount() == 0) {
351
            this.labelWarning.setVisible(false);
375
            this.labelWarning.setVisible(false);
352
            return;
376
            return;
353
        }
377
        }
354
 
378
 
355
        try {
379
        try {
356
            if (this.montant.getText().trim().length() != 0) {
380
            if (this.montant.getText().trim().length() != 0) {
357
                montantValue = GestionDevise.parseLongCurrency(this.montant.getText().trim());
381
                montantValue = GestionDevise.parseLongCurrency(this.montant.getText().trim());
358
            }
382
            }
359
        } catch (NumberFormatException e) {
383
        } catch (NumberFormatException e) {
360
            System.err.println("format float incorrect " + e);
384
            System.err.println("format float incorrect " + e);
361
            e.printStackTrace();
385
            e.printStackTrace();
362
        }
386
        }
363
 
387
 
364
        final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
388
        final RowValuesTableModel model = table.getRowValuesTable().getRowValuesTableModel();
365
 
389
 
366
        final int rowCount = model.getRowCount();
390
        final int rowCount = model.getRowCount();
367
        long total = 0;
391
        long total = 0;
368
        for (int i = 0; i < rowCount; i++) {
392
        for (int i = 0; i < rowCount; i++) {
369
            Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantAReglerElement()));
393
            Number nHT = (Number) model.getValueAt(i, model.getColumnIndexForElement(table.getMontantAReglerElement()));
370
            total += nHT.longValue();
394
            total += nHT.longValue();
371
        }
395
        }
372
 
396
 
373
        this.labelWarning.setVisible(montantValue <= 0 || montantValue > total);
397
        this.labelWarning.setVisible(montantValue <= 0 || montantValue > total);
374
    }
398
    }
375
 
399
 
376
    public void loadEcheancesFromRows(List<SQLRow> rows) {
400
    public void loadEcheancesFromRows(List<SQLRow> rows) {
377
 
401
 
378
        Collections.sort(rows, new Comparator<SQLRow>() {
402
        Collections.sort(rows, new Comparator<SQLRow>() {
379
            @Override
403
            @Override
380
            public int compare(SQLRow o1, SQLRow o2) {
404
            public int compare(SQLRow o1, SQLRow o2) {
381
                Calendar c1 = o1.getDate("DATE");
405
                Calendar c1 = o1.getDate("DATE");
382
                Calendar c2 = o2.getDate("DATE");
406
                Calendar c2 = o2.getDate("DATE");
383
                if (c1 == null) {
407
                if (c1 == null) {
384
                    return -1;
408
                    return -1;
385
                }
409
                }
386
                if (c2 == null) {
410
                if (c2 == null) {
387
                    return 1;
411
                    return 1;
388
                }
412
                }
389
                if (c1.getTime().before(c2.getTime())) {
413
                if (c1.getTime().before(c2.getTime())) {
390
                    return -1;
414
                    return -1;
391
                } else {
415
                } else {
392
                    return 1;
416
                    return 1;
393
                }
417
                }
394
            }
418
            }
395
        });
419
        });
396
 
420
 
397
        SQLTable tableEch = Configuration.getInstance().getDirectory().getElement("ECHEANCE_CLIENT").getTable();
421
        SQLTable tableEch = Configuration.getInstance().getDirectory().getElement("ECHEANCE_CLIENT").getTable();
398
        SQLTable tableEnc = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT_ELEMENT").getTable();
422
        SQLTable tableEnc = Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT_ELEMENT").getTable();
399
        SQLInjector inj = SQLInjector.getInjector(tableEch, tableEnc);
423
        SQLInjector inj = SQLInjector.getInjector(tableEch, tableEnc);
400
        for (SQLRow row : rows) {
424
        for (SQLRow row : rows) {
401
 
425
 
402
            SQLRowValues rowVals = inj.createRowValuesFrom(row.getID());
426
            SQLRowValues rowVals = inj.createRowValuesFrom(row.getID());
403
            rowVals.put("MONTANT_REGLE", rowVals.getObject("MONTANT_A_REGLER"));
427
            rowVals.put("MONTANT_REGLE", rowVals.getObject("MONTANT_A_REGLER"));
404
            table.getModel().addRow(rowVals);
428
            table.getModel().addRow(rowVals);
405
            int rowIndex = table.getModel().getRowCount() - 1;
429
            int rowIndex = table.getModel().getRowCount() - 1;
406
            table.getModel().fireTableModelModified(rowIndex);
430
            table.getModel().fireTableModelModified(rowIndex);
407
        }
431
        }
408
        this.table.getModel().fireTableDataChanged();
432
        this.table.getModel().fireTableDataChanged();
409
        this.table.repaint();
433
        this.table.repaint();
410
 
434
 
411
    }
435
    }
412
 
436
 
413
}
437
}