OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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