OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 174
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.ui.DeviseCellEditor;
17
import org.openconcerto.erp.core.common.ui.DeviseCellEditor;
18
import org.openconcerto.erp.core.common.ui.MultiLineTableCellEditor;
18
import org.openconcerto.erp.core.common.ui.MultiLineTableCellEditor;
19
import org.openconcerto.erp.core.common.ui.RowValuesMultiLineEditTable;
19
import org.openconcerto.erp.core.common.ui.RowValuesMultiLineEditTable;
20
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
20
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
21
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm;
21
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm;
22
import org.openconcerto.erp.preferences.DefaultNXProps;
22
import org.openconcerto.erp.preferences.DefaultNXProps;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
-
 
24
import org.openconcerto.sql.TM;
24
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.element.SQLElement;
25
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLRow;
26
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowAccessor;
27
import org.openconcerto.sql.model.SQLRowValues;
28
import org.openconcerto.sql.model.SQLRowValues;
28
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.SQLTable;
29
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.sqlobject.ITextWithCompletion;
31
import org.openconcerto.sql.sqlobject.ITextWithCompletion;
31
import org.openconcerto.sql.view.list.AutoCompletionManager;
32
import org.openconcerto.sql.view.list.AutoCompletionManager;
32
import org.openconcerto.sql.view.list.RowValuesTable;
33
import org.openconcerto.sql.view.list.RowValuesTable;
33
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
34
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
34
import org.openconcerto.sql.view.list.RowValuesTableModel;
35
import org.openconcerto.sql.view.list.RowValuesTableModel;
35
import org.openconcerto.sql.view.list.SQLTableElement;
36
import org.openconcerto.sql.view.list.SQLTableElement;
36
import org.openconcerto.sql.view.list.TextTableCellEditorWithCompletion;
37
import org.openconcerto.sql.view.list.TextTableCellEditorWithCompletion;
37
import org.openconcerto.sql.view.list.ValidStateChecker;
38
import org.openconcerto.sql.view.list.ValidStateChecker;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.DefaultGridBagConstraints;
-
 
40
import org.openconcerto.ui.JComponentUtils;
39
import org.openconcerto.ui.RangedIntegerTableCellEditor;
41
import org.openconcerto.ui.RangedIntegerTableCellEditor;
40
import org.openconcerto.utils.DecimalUtils;
42
import org.openconcerto.utils.DecimalUtils;
41
import org.openconcerto.utils.GestionDevise;
43
import org.openconcerto.utils.GestionDevise;
42
import org.openconcerto.utils.Tuple2;
44
import org.openconcerto.utils.Tuple2;
43
import org.openconcerto.utils.checks.ValidState;
45
import org.openconcerto.utils.checks.ValidState;
44
 
46
 
45
import java.awt.GridBagConstraints;
47
import java.awt.GridBagConstraints;
46
import java.awt.GridBagLayout;
48
import java.awt.GridBagLayout;
47
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionEvent;
-
 
50
import java.awt.event.ActionListener;
48
import java.awt.event.KeyEvent;
51
import java.awt.event.KeyEvent;
49
import java.awt.event.KeyListener;
52
import java.awt.event.KeyListener;
50
import java.awt.event.MouseEvent;
53
import java.awt.event.MouseEvent;
51
import java.awt.event.MouseListener;
54
import java.awt.event.MouseListener;
52
import java.beans.PropertyChangeEvent;
55
import java.beans.PropertyChangeEvent;
53
import java.beans.PropertyChangeListener;
56
import java.beans.PropertyChangeListener;
54
import java.math.BigDecimal;
57
import java.math.BigDecimal;
55
import java.math.RoundingMode;
58
import java.math.RoundingMode;
56
import java.sql.SQLException;
59
import java.sql.SQLException;
-
 
60
import java.util.Arrays;
57
import java.util.Calendar;
61
import java.util.Calendar;
58
import java.util.Collection;
62
import java.util.Collection;
59
import java.util.Date;
63
import java.util.Date;
60
import java.util.List;
64
import java.util.List;
61
import java.util.Vector;
65
import java.util.Vector;
62
 
66
 
63
import javax.swing.AbstractAction;
67
import javax.swing.AbstractAction;
64
import javax.swing.BorderFactory;
68
import javax.swing.BorderFactory;
-
 
69
import javax.swing.JButton;
65
import javax.swing.JCheckBox;
70
import javax.swing.JCheckBox;
66
import javax.swing.JLabel;
71
import javax.swing.JLabel;
67
import javax.swing.JOptionPane;
72
import javax.swing.JOptionPane;
68
import javax.swing.JPanel;
73
import javax.swing.JPanel;
69
import javax.swing.JPopupMenu;
74
import javax.swing.JPopupMenu;
70
import javax.swing.JScrollPane;
75
import javax.swing.JScrollPane;
71
import javax.swing.JTextField;
76
import javax.swing.JTextField;
72
import javax.swing.SwingConstants;
77
import javax.swing.SwingConstants;
73
import javax.swing.SwingUtilities;
78
import javax.swing.SwingUtilities;
74
import javax.swing.ToolTipManager;
79
import javax.swing.ToolTipManager;
75
import javax.swing.event.CellEditorListener;
80
import javax.swing.event.CellEditorListener;
76
import javax.swing.event.ChangeEvent;
81
import javax.swing.event.ChangeEvent;
77
import javax.swing.event.TableModelEvent;
82
import javax.swing.event.TableModelEvent;
78
import javax.swing.event.TableModelListener;
83
import javax.swing.event.TableModelListener;
79
 
84
 
80
public class SaisieJournalItemTable extends JPanel implements MouseListener {
85
public class SaisieJournalItemTable extends JPanel implements MouseListener {
81
 
86
 
82
    private final RowValuesTable table;
87
    private final RowValuesTable table;
83
    private final SQLTableElement debit;
88
    private final SQLTableElement debit;
84
    private final SQLTableElement credit;
89
    private final SQLTableElement credit;
85
    private JLabel labelTotalDebit;
90
    private JLabel labelTotalDebit;
86
    private JLabel labelTotalCredit;
91
    private JLabel labelTotalCredit;
87
    private JLabel labelTotalSolde;
92
    private JLabel labelTotalSolde;
88
    private final SQLTableElement tableElementNumeroCompte;
93
    private final SQLTableElement tableElementNumeroCompte;
89
    private final CompteRowValuesRenderer numeroCompteRenderer = new CompteRowValuesRenderer();
94
    private final CompteRowValuesRenderer numeroCompteRenderer = new CompteRowValuesRenderer();
90
    private final DeviseKmRowValuesRenderer deviseRenderer = new DeviseKmRowValuesRenderer();
95
    private final DeviseKmRowValuesRenderer deviseRenderer = new DeviseKmRowValuesRenderer();
91
    final RangedIntegerTableCellEditor rangedIntegerTableCellEditor = new RangedIntegerTableCellEditor(1, 31);
96
    final RangedIntegerTableCellEditor rangedIntegerTableCellEditor = new RangedIntegerTableCellEditor(1, 31);
92
    private final RowValuesTableControlPanel controlPanel;
97
    private final RowValuesTableControlPanel controlPanel;
93
 
98
 
94
    private SaisieJournalPanel panel;
99
    private SaisieJournalPanel panel;
95
    private final JCheckBox boxAutoInsert;
100
    private final JCheckBox boxAutoInsert;
96
    private boolean hideAnalytique = false;
101
    private boolean hideAnalytique = false;
97
 
102
 
98
    public SaisieJournalItemTable(final SQLRowValues defaultRowVals, JCheckBox boxAutoInsert, final JTextField textField) {
103
    public SaisieJournalItemTable(final SQLRowValues defaultRowVals, JCheckBox boxAutoInsert, final JTextField textField) {
99
        setLayout(new GridBagLayout());
104
        setLayout(new GridBagLayout());
100
        this.boxAutoInsert = boxAutoInsert;
105
        this.boxAutoInsert = boxAutoInsert;
101
        final GridBagConstraints c = new DefaultGridBagConstraints();
106
        final GridBagConstraints c = new DefaultGridBagConstraints();
102
        c.weightx = 1;
107
        c.weightx = 1;
103
 
108
 
104
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_KM_ELEMENT");
109
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_KM_ELEMENT");
105
 
110
 
106
        // TODO Obligation de choisir un compte correct
111
        // TODO Obligation de choisir un compte correct
107
        final List<SQLTableElement> list = new Vector<SQLTableElement>();
112
        final List<SQLTableElement> list = new Vector<SQLTableElement>();
108
        final SQLTable tableElement = elt.getTable();
113
        final SQLTable tableElement = elt.getTable();
109
        final SQLTableElement tableElementJour = new SQLTableElement(tableElement.getField("JOUR"), Integer.class, rangedIntegerTableCellEditor) {
114
        final SQLTableElement tableElementJour = new SQLTableElement(tableElement.getField("JOUR"), Integer.class, rangedIntegerTableCellEditor) {
110
            @Override
115
            @Override
111
            public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
116
            public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
112
 
117
 
113
                return super.isCellEditable(vals, rowIndex, columnIndex) && rowIndex == 0;
118
                return super.isCellEditable(vals, rowIndex, columnIndex) && rowIndex == 0;
114
            }
119
            }
115
 
120
 
116
            @Override
121
            @Override
117
            protected Object getDefaultNullValue() {
122
            protected Object getDefaultNullValue() {
118
                return 1;
123
                return 1;
119
            }
124
            }
120
 
125
 
121
        };
126
        };
122
 
127
 
123
        list.add(tableElementJour);
128
        list.add(tableElementJour);
124
 
129
 
125
        this.tableElementNumeroCompte = new SQLTableElement(tableElement.getField("NUMERO"));
130
        this.tableElementNumeroCompte = new SQLTableElement(tableElement.getField("NUMERO"));
126
        list.add(this.tableElementNumeroCompte);
131
        list.add(this.tableElementNumeroCompte);
127
 
132
 
128
        final SQLTableElement tableElementNomCompte = new SQLTableElement(tableElement.getField("NOM"));
133
        final SQLTableElement tableElementNomCompte = new SQLTableElement(tableElement.getField("NOM"));
129
        list.add(tableElementNomCompte);
134
        list.add(tableElementNomCompte);
130
 
135
 
131
        final SQLTableElement tableElementNomPiece = new SQLTableElement(tableElement.getField("NOM_PIECE"));
136
        final SQLTableElement tableElementNomPiece = new SQLTableElement(tableElement.getField("NOM_PIECE"));
132
        list.add(tableElementNomPiece);
137
        list.add(tableElementNomPiece);
133
 
138
 
134
        final SQLTableElement tableElementNomEcriture = new SQLTableElement(tableElement.getField("NOM_ECRITURE"));
139
        final SQLTableElement tableElementNomEcriture = new SQLTableElement(tableElement.getField("NOM_ECRITURE"));
135
        list.add(tableElementNomEcriture);
140
        list.add(tableElementNomEcriture);
136
 
141
 
137
        //
142
        //
138
        DeviseCellEditor deviseDebitEditor = new DeviseCellEditor();
143
        DeviseCellEditor deviseDebitEditor = new DeviseCellEditor();
139
        DeviseCellEditor deviseCreditEditor = new DeviseCellEditor();
144
        DeviseCellEditor deviseCreditEditor = new DeviseCellEditor();
140
        this.debit = new SQLTableElement(tableElement.getField("DEBIT"), Long.class, deviseDebitEditor);
145
        this.debit = new SQLTableElement(tableElement.getField("DEBIT"), Long.class, deviseDebitEditor);
141
        list.add(this.debit);
146
        list.add(this.debit);
142
        this.credit = new SQLTableElement(tableElement.getField("CREDIT"), Long.class, deviseCreditEditor);
147
        this.credit = new SQLTableElement(tableElement.getField("CREDIT"), Long.class, deviseCreditEditor);
143
        list.add(this.credit);
148
        list.add(this.credit);
144
        this.hideAnalytique = DefaultNXProps.getInstance().getBooleanValue("HideAnalytique");
149
        this.hideAnalytique = DefaultNXProps.getInstance().getBooleanValue("HideAnalytique");
145
        if (!this.hideAnalytique) {
150
        if (!this.hideAnalytique) {
146
            final AnalytiqueItemTable analytiqueAssocTable = new AnalytiqueItemTable(true, new AbstractAction() {
151
            final AnalytiqueItemTable analytiqueAssocTable = new AnalytiqueItemTable(true, new AbstractAction() {
147
 
152
 
148
                @Override
153
                @Override
149
                public void actionPerformed(ActionEvent e) {
154
                public void actionPerformed(ActionEvent e) {
150
                    montantValid(defaultRowVals, true, textField);
155
                    montantValid(defaultRowVals, true, textField);
151
                }
156
                }
152
            });
157
            });
153
            final MultiLineTableCellEditor multiLineTableCellEditor = new MultiLineTableCellEditor((RowValuesMultiLineEditTable) analytiqueAssocTable.getTable(), analytiqueAssocTable);
158
            final MultiLineTableCellEditor multiLineTableCellEditor = new MultiLineTableCellEditor((RowValuesMultiLineEditTable) analytiqueAssocTable.getTable(), analytiqueAssocTable);
154
 
159
 
155
            SQLTableElement eltPourcentAnalytique = new SQLTableElement(tableElement.getField("ANALYTIQUE"), String.class, multiLineTableCellEditor) {
160
            SQLTableElement eltPourcentAnalytique = new SQLTableElement(tableElement.getField("ANALYTIQUE"), String.class, multiLineTableCellEditor) {
156
                public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
161
                public boolean isCellEditable(SQLRowValues vals, int rowIndex, int columnIndex) {
157
                    return vals.getString("NUMERO") != null && (vals.getString("NUMERO").startsWith("6") || vals.getString("NUMERO").startsWith("7"));
162
                    return vals.getString("NUMERO") != null && (vals.getString("NUMERO").startsWith("6") || vals.getString("NUMERO").startsWith("7"));
158
                };
163
                };
159
            };
164
            };
160
            list.add(eltPourcentAnalytique);
165
            list.add(eltPourcentAnalytique);
161
        }
166
        }
162
 
167
 
163
        final RowValuesTableModel model = new RowValuesTableModel(elt, list, tableElement.getField("NUMERO"), false, defaultRowVals) {
168
        final RowValuesTableModel model = new RowValuesTableModel(elt, list, tableElement.getField("NUMERO"), false, defaultRowVals) {
164
            @Override
169
            @Override
165
            public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) {
170
            public void setValueAt(final Object aValue, final int rowIndex, final int columnIndex) {
166
                super.setValueAt(aValue, rowIndex, columnIndex);
171
                super.setValueAt(aValue, rowIndex, columnIndex);
167
 
172
 
168
                final int debitIndex = getColumnIndexForElement(SaisieJournalItemTable.this.debit);
173
                final int debitIndex = getColumnIndexForElement(SaisieJournalItemTable.this.debit);
169
                final int creditIndex = getColumnIndexForElement(SaisieJournalItemTable.this.credit);
174
                final int creditIndex = getColumnIndexForElement(SaisieJournalItemTable.this.credit);
170
 
175
 
171
                // float debitVal = ((Float) model.getValueAt(rowIndex, debitIndex);
176
                // float debitVal = ((Float) model.getValueAt(rowIndex, debitIndex);
172
 
177
 
173
                if (debitIndex == columnIndex && ((Long) aValue).longValue() != 0 && ((Long) getValueAt(rowIndex, creditIndex)).longValue() != 0) {
178
                if (debitIndex == columnIndex && ((Long) aValue).longValue() != 0 && ((Long) getValueAt(rowIndex, creditIndex)).longValue() != 0) {
174
                    setValueAt(Long.valueOf(0), rowIndex, creditIndex);
179
                    setValueAt(Long.valueOf(0), rowIndex, creditIndex);
175
                } else {
180
                } else {
176
                    if (creditIndex == columnIndex && ((Long) aValue).longValue() != 0 && ((Long) getValueAt(rowIndex, debitIndex)).longValue() != 0) {
181
                    if (creditIndex == columnIndex && ((Long) aValue).longValue() != 0 && ((Long) getValueAt(rowIndex, debitIndex)).longValue() != 0) {
177
                        setValueAt(Long.valueOf(0), rowIndex, debitIndex);
182
                        setValueAt(Long.valueOf(0), rowIndex, debitIndex);
178
                    }
183
                    }
179
                }
184
                }
180
            }
185
            }
181
        };
186
        };
182
 
187
 
183
        this.table = new RowValuesTable(model, null);
188
        this.table = new RowValuesTable(model, null);
184
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
189
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
185
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
190
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
186
 
191
 
187
        tableElementNomEcriture.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
192
        tableElementNomEcriture.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
188
 
193
 
189
            @Override
194
            @Override
190
            public void editingStopped(ChangeEvent e) {
195
            public void editingStopped(ChangeEvent e) {
191
                e.getSource();
196
                e.getSource();
192
                int row = table.getSelectedRow();
197
                int row = table.getSelectedRow();
193
                int col = 4;
198
                int col = 4;
194
                if (table.getValueAt(row, col) != null) {
199
                if (table.getValueAt(row, col) != null) {
195
                    defaultRowVals.put("NOM_ECRITURE", table.getValueAt(row, col));
200
                    defaultRowVals.put("NOM_ECRITURE", table.getValueAt(row, col));
196
                }
201
                }
197
                // defaultRowVals.put
202
                // defaultRowVals.put
198
            }
203
            }
199
 
204
 
200
            @Override
205
            @Override
201
            public void editingCanceled(ChangeEvent e) {
206
            public void editingCanceled(ChangeEvent e) {
202
                // TODO Auto-generated method stub
207
                // TODO Auto-generated method stub
203
 
208
 
204
            }
209
            }
205
        });
210
        });
206
        tableElementNomPiece.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
211
        tableElementNomPiece.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
207
 
212
 
208
            @Override
213
            @Override
209
            public void editingStopped(ChangeEvent e) {
214
            public void editingStopped(ChangeEvent e) {
210
                e.getSource();
215
                e.getSource();
211
                int row = table.getSelectedRow();
216
                int row = table.getSelectedRow();
212
                int col = 3;
217
                int col = 3;
213
                if (table.getValueAt(row, col) != null) {
218
                if (table.getValueAt(row, col) != null) {
214
                    defaultRowVals.put("NOM_PIECE", table.getValueAt(row, col));
219
                    defaultRowVals.put("NOM_PIECE", table.getValueAt(row, col));
215
                }
220
                }
216
                // defaultRowVals.put
221
                // defaultRowVals.put
217
            }
222
            }
218
 
223
 
219
            @Override
224
            @Override
220
            public void editingCanceled(ChangeEvent e) {
225
            public void editingCanceled(ChangeEvent e) {
221
                // TODO Auto-generated method stub
226
                // TODO Auto-generated method stub
222
 
227
 
223
            }
228
            }
224
        });
229
        });
225
 
230
 
226
        tableElementJour.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
231
        tableElementJour.getTableCellEditor(table).addCellEditorListener(new CellEditorListener() {
227
 
232
 
228
            @Override
233
            @Override
229
            public void editingStopped(ChangeEvent e) {
234
            public void editingStopped(ChangeEvent e) {
230
                final Object valueAt = table.getValueAt(0, 0);
235
                final Object valueAt = table.getValueAt(0, 0);
231
                defaultRowVals.put("JOUR", valueAt);
236
                defaultRowVals.put("JOUR", valueAt);
232
                if (table.getRowCount() > 1) {
237
                if (table.getRowCount() > 1) {
233
                    for (int i = 1; i < table.getRowCount(); i++) {
238
                    for (int i = 1; i < table.getRowCount(); i++) {
234
                        table.getRowValuesTableModel().putValue(valueAt, i, "JOUR");
239
                        table.getRowValuesTableModel().putValue(valueAt, i, "JOUR");
235
                    }
240
                    }
236
                }
241
                }
237
            }
242
            }
238
 
243
 
239
            @Override
244
            @Override
240
            public void editingCanceled(ChangeEvent e) {
245
            public void editingCanceled(ChangeEvent e) {
241
                // TODO Auto-generated method stub
246
                // TODO Auto-generated method stub
242
 
247
 
243
            }
248
            }
244
        });
249
        });
245
        ;
250
        ;
246
 
251
 
247
        final KeyListener keyListenerContrepartie = new KeyListener() {
252
        final KeyListener keyListenerContrepartie = new KeyListener() {
248
 
253
 
249
            @Override
254
            @Override
250
            public void keyTyped(KeyEvent e) {
255
            public void keyTyped(KeyEvent e) {
251
 
256
 
252
            }
257
            }
253
 
258
 
254
            @Override
259
            @Override
255
            public void keyReleased(KeyEvent e) {
260
            public void keyReleased(KeyEvent e) {
256
 
261
 
257
            }
262
            }
258
 
263
 
259
            @Override
264
            @Override
260
            public void keyPressed(KeyEvent e) {
265
            public void keyPressed(KeyEvent e) {
261
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
266
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
262
                    montantValid(defaultRowVals, false, textField);
267
                    montantValid(defaultRowVals, false, textField);
263
                }
268
                }
264
            }
269
            }
265
        };
270
        };
266
        deviseCreditEditor.addKeyListener(keyListenerContrepartie);
271
        deviseCreditEditor.addKeyListener(keyListenerContrepartie);
267
        deviseDebitEditor.addKeyListener(keyListenerContrepartie);
272
        deviseDebitEditor.addKeyListener(keyListenerContrepartie);
268
 
273
 
269
        // Autocompletion
274
        // Autocompletion
270
        final AutoCompletionManager m = new AutoCompletionManager(this.tableElementNumeroCompte,
275
        final AutoCompletionManager m = new AutoCompletionManager(this.tableElementNumeroCompte,
271
                ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("COMPTE_PCE.NUMERO"), this.table, this.table.getRowValuesTableModel(),
276
                ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("COMPTE_PCE.NUMERO"), this.table, this.table.getRowValuesTableModel(),
272
                ITextWithCompletion.MODE_STARTWITH, true, false, new ValidStateChecker() {
277
                ITextWithCompletion.MODE_STARTWITH, true, false, new ValidStateChecker() {
273
 
278
 
274
                    ComptePCESQLElement elt = Configuration.getInstance().getDirectory().getElement(ComptePCESQLElement.class);
279
                    ComptePCESQLElement elt = Configuration.getInstance().getDirectory().getElement(ComptePCESQLElement.class);
275
 
280
 
276
                    @Override
281
                    @Override
277
                    public ValidState getValidState(Object o) {
282
                    public ValidState getValidState(Object o) {
278
                        if (o != null) {
283
                        if (o != null) {
279
                            return elt.getCompteNumeroValidState(o.toString());
284
                            return elt.getCompteNumeroValidState(o.toString());
280
                        }
285
                        }
281
                        return super.getValidState(o);
286
                        return super.getValidState(o);
282
                    }
287
                    }
283
                });
288
                });
284
        m.fill("NOM", "NOM");
289
        m.fill("NOM", "NOM");
285
        m.setFillWithField("NUMERO");
290
        m.setFillWithField("NUMERO");
286
        final Where w = new Where(elt.getTable().getTable("COMPTE_PCE").getField("OBSOLETE"), "=", Boolean.FALSE);
291
        final Where w = new Where(elt.getTable().getTable("COMPTE_PCE").getField("OBSOLETE"), "=", Boolean.FALSE);
287
        m.setWhere(w);
292
        m.setWhere(w);
288
 
293
 
289
        // FIXME erreur fill numero
294
        // FIXME erreur fill numero
290
        final AutoCompletionManager m2 = new AutoCompletionManager(tableElementNomCompte, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("COMPTE_PCE.NOM"),
295
        final AutoCompletionManager m2 = new AutoCompletionManager(tableElementNomCompte, ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete().getField("COMPTE_PCE.NOM"),
291
                this.table, this.table.getRowValuesTableModel(), ITextWithCompletion.MODE_CONTAINS, true);
296
                this.table, this.table.getRowValuesTableModel(), ITextWithCompletion.MODE_CONTAINS, true);
292
        m2.fill("NUMERO", "NUMERO");
297
        m2.fill("NUMERO", "NUMERO");
293
        m2.setFillWithField("NOM");
298
        m2.setFillWithField("NOM");
294
        m2.setWhere(w);
299
        m2.setWhere(w);
295
 
300
 
296
        TextTableCellEditorWithCompletion t = (TextTableCellEditorWithCompletion) this.tableElementNumeroCompte.getTableCellEditor(this.table);
301
        TextTableCellEditorWithCompletion t = (TextTableCellEditorWithCompletion) this.tableElementNumeroCompte.getTableCellEditor(this.table);
297
 
302
 
-
 
303
        JButton buttonClone = new JButton(TM.tr("duplicateLine"));
-
 
304
        buttonClone.addActionListener(new ActionListener() {
-
 
305
            public void actionPerformed(ActionEvent event) {
-
 
306
                cloneLine(table.getSelectedRow());
-
 
307
            }
-
 
308
        });
-
 
309
        buttonClone.setEnabled(false);
-
 
310
        c.gridx++;
-
 
311
        JComponentUtils.setMinimumWidth(buttonClone, 95);
-
 
312
 
298
        this.controlPanel = new RowValuesTableControlPanel(this.table);
313
        this.controlPanel = new RowValuesTableControlPanel(this.table, Arrays.asList(buttonClone));
-
 
314
        this.controlPanel.setVisibleButtonClone(false);
299
        controlPanel.setButtonAjouterEnabled(false);
315
        this.controlPanel.setButtonAjouterEnabled(false);
300
        this.add(controlPanel, c);
316
        this.add(this.controlPanel, c);
301
 
317
 
302
        c.gridy++;
318
        c.gridy++;
303
        c.fill = GridBagConstraints.BOTH;
319
        c.fill = GridBagConstraints.BOTH;
304
        c.weightx = 1;
320
        c.weightx = 1;
305
        c.weighty = 1;
321
        c.weighty = 1;
306
        this.add(new JScrollPane(this.table), c);
322
        this.add(new JScrollPane(this.table), c);
307
 
323
 
308
        this.tableElementNumeroCompte.setRenderer(this.numeroCompteRenderer);
324
        this.tableElementNumeroCompte.setRenderer(this.numeroCompteRenderer);
309
        this.debit.setRenderer(this.deviseRenderer);
325
        this.debit.setRenderer(this.deviseRenderer);
310
        this.credit.setRenderer(this.deviseRenderer);
326
        this.credit.setRenderer(this.deviseRenderer);
311
 
327
 
312
        this.table.addMouseListener(this);
328
        this.table.addMouseListener(this);
313
        this.table.getModel().addTableModelListener(new TableModelListener() {
329
        this.table.getModel().addTableModelListener(new TableModelListener() {
314
 
330
 
315
            @Override
331
            @Override
316
            public void tableChanged(TableModelEvent e) {
332
            public void tableChanged(TableModelEvent e) {
317
                // Sélectionne automatiquement la ligne ajoutée
333
                // Sélectionne automatiquement la ligne ajoutée
318
                if (e.getType() == TableModelEvent.INSERT) {
334
                if (e.getType() == TableModelEvent.INSERT) {
319
                    if (table.getRowCount() == 1) {
335
                    if (table.getRowCount() == 1) {
320
                        editCellAt(e.getFirstRow(), 0);
336
                        editCellAt(e.getFirstRow(), 0);
321
                    } else {
337
                    } else {
322
                        editCellAt(e.getFirstRow(), 1);
338
                        editCellAt(e.getFirstRow(), 1);
323
                    }
339
                    }
324
                }
340
                }
325
                refreshTotal();
341
                refreshTotal();
326
            }
342
            }
327
        });
343
        });
328
 
344
 
329
        // Initialisation du panel des Totaux
345
        // Initialisation du panel des Totaux
330
        this.labelTotalCredit = new JLabel("0.00", SwingConstants.RIGHT);
346
        this.labelTotalCredit = new JLabel("0.00", SwingConstants.RIGHT);
331
        this.labelTotalDebit = new JLabel("0.00", SwingConstants.RIGHT);
347
        this.labelTotalDebit = new JLabel("0.00", SwingConstants.RIGHT);
332
        this.labelTotalSolde = new JLabel("0.00", SwingConstants.RIGHT);
348
        this.labelTotalSolde = new JLabel("0.00", SwingConstants.RIGHT);
333
        JPanel panelTotal = new JPanel();
349
        JPanel panelTotal = new JPanel();
334
        panelTotal.setLayout(new GridBagLayout());
350
        panelTotal.setLayout(new GridBagLayout());
335
        panelTotal.setBorder(BorderFactory.createTitledBorder("Totaux"));
351
        panelTotal.setBorder(BorderFactory.createTitledBorder("Totaux"));
336
        final GridBagConstraints cc = new DefaultGridBagConstraints();
352
        final GridBagConstraints cc = new DefaultGridBagConstraints();
337
        cc.anchor = GridBagConstraints.EAST;
353
        cc.anchor = GridBagConstraints.EAST;
338
 
354
 
339
        // Total Debit
355
        // Total Debit
340
        cc.fill = GridBagConstraints.NONE;
356
        cc.fill = GridBagConstraints.NONE;
341
        panelTotal.add(new JLabel("Débit"), cc);
357
        panelTotal.add(new JLabel("Débit"), cc);
342
        cc.fill = GridBagConstraints.HORIZONTAL;
358
        cc.fill = GridBagConstraints.HORIZONTAL;
343
        cc.gridx++;
359
        cc.gridx++;
344
        cc.weightx = 1;
360
        cc.weightx = 1;
345
 
361
 
346
        panelTotal.add(this.labelTotalDebit, cc);
362
        panelTotal.add(this.labelTotalDebit, cc);
347
 
363
 
348
        // Total Credit
364
        // Total Credit
349
        cc.gridy++;
365
        cc.gridy++;
350
        cc.gridx = 0;
366
        cc.gridx = 0;
351
        cc.weightx = 0;
367
        cc.weightx = 0;
352
        cc.fill = GridBagConstraints.NONE;
368
        cc.fill = GridBagConstraints.NONE;
353
        panelTotal.add(new JLabel("Crédit"), cc);
369
        panelTotal.add(new JLabel("Crédit"), cc);
354
        cc.weightx = 1;
370
        cc.weightx = 1;
355
        cc.gridx++;
371
        cc.gridx++;
356
        cc.fill = GridBagConstraints.HORIZONTAL;
372
        cc.fill = GridBagConstraints.HORIZONTAL;
357
        panelTotal.add(this.labelTotalCredit, cc);
373
        panelTotal.add(this.labelTotalCredit, cc);
358
 
374
 
359
        // Total Credit
375
        // Total Credit
360
        cc.gridy++;
376
        cc.gridy++;
361
        cc.gridx = 0;
377
        cc.gridx = 0;
362
        cc.weightx = 0;
378
        cc.weightx = 0;
363
        cc.fill = GridBagConstraints.NONE;
379
        cc.fill = GridBagConstraints.NONE;
364
        panelTotal.add(new JLabel("Solde"), cc);
380
        panelTotal.add(new JLabel("Solde"), cc);
365
        cc.weightx = 1;
381
        cc.weightx = 1;
366
        cc.gridx++;
382
        cc.gridx++;
367
        cc.fill = GridBagConstraints.HORIZONTAL;
383
        cc.fill = GridBagConstraints.HORIZONTAL;
368
        panelTotal.add(this.labelTotalSolde, cc);
384
        panelTotal.add(this.labelTotalSolde, cc);
369
 
385
 
370
        c.gridy++;
386
        c.gridy++;
371
        c.fill = GridBagConstraints.NONE;
387
        c.fill = GridBagConstraints.NONE;
372
        c.anchor = GridBagConstraints.EAST;
388
        c.anchor = GridBagConstraints.EAST;
373
        c.weightx = 1;
389
        c.weightx = 1;
374
        c.weighty = 0;
390
        c.weighty = 0;
375
        this.add(panelTotal, c);
391
        this.add(panelTotal, c);
376
    }
392
    }
377
 
393
 
378
    public void setPanel(final SaisieJournalPanel panel) {
394
    public void setPanel(final SaisieJournalPanel panel) {
379
        this.panel = panel;
395
        this.panel = panel;
380
 
396
 
381
        final PropertyChangeListener lActiveAddButton = new PropertyChangeListener() {
397
        final PropertyChangeListener lActiveAddButton = new PropertyChangeListener() {
382
            @Override
398
            @Override
383
            public void propertyChange(PropertyChangeEvent evt) {
399
            public void propertyChange(PropertyChangeEvent evt) {
384
                controlPanel.setButtonAjouterEnabled(!panel.getBoxJournal().isEmpty() && !panel.getBoxMois().isEmpty());
400
                controlPanel.setButtonAjouterEnabled(!panel.getBoxJournal().isEmpty() && !panel.getBoxMois().isEmpty());
385
            }
401
            }
386
        };
402
        };
387
        panel.getBoxJournal().addModelListener("wantedID", lActiveAddButton);
403
        panel.getBoxJournal().addModelListener("wantedID", lActiveAddButton);
388
        panel.getBoxMois().addModelListener("wantedID", lActiveAddButton);
404
        panel.getBoxMois().addModelListener("wantedID", lActiveAddButton);
389
 
405
 
390
        final PropertyChangeListener l = new PropertyChangeListener() {
406
        final PropertyChangeListener l = new PropertyChangeListener() {
391
 
407
 
392
            @Override
408
            @Override
393
            public void propertyChange(PropertyChangeEvent evt) {
409
            public void propertyChange(PropertyChangeEvent evt) {
394
                if (!SaisieJournalItemTable.this.panel.boxMois.isEmpty()) {
410
                if (!SaisieJournalItemTable.this.panel.boxMois.isEmpty()) {
395
                    final SQLRow selectedRow = SaisieJournalItemTable.this.panel.boxMois.getSelectedRow();
411
                    final SQLRow selectedRow = SaisieJournalItemTable.this.panel.boxMois.getSelectedRow();
396
                    if (selectedRow != null && !selectedRow.isUndefined()) {
412
                    if (selectedRow != null && !selectedRow.isUndefined()) {
397
                        Calendar c = Calendar.getInstance();
413
                        Calendar c = Calendar.getInstance();
398
                        c.set(Calendar.DAY_OF_MONTH, 1);
414
                        c.set(Calendar.DAY_OF_MONTH, 1);
399
                        c.set(Calendar.YEAR, (Integer) SaisieJournalItemTable.this.panel.spin.getValue());
415
                        c.set(Calendar.YEAR, (Integer) SaisieJournalItemTable.this.panel.spin.getValue());
400
                        c.set(Calendar.MONTH, SaisieJournalItemTable.this.panel.getSelectedMonth());
416
                        c.set(Calendar.MONTH, SaisieJournalItemTable.this.panel.getSelectedMonth());
401
                        rangedIntegerTableCellEditor.setMax(c.getActualMaximum(Calendar.DAY_OF_MONTH));
417
                        rangedIntegerTableCellEditor.setMax(c.getActualMaximum(Calendar.DAY_OF_MONTH));
402
                    }
418
                    }
403
                }
419
                }
404
            }
420
            }
405
 
421
 
406
        };
422
        };
407
        panel.boxMois.addModelListener("wantedID", l);
423
        panel.boxMois.addModelListener("wantedID", l);
408
 
424
 
409
    }
425
    }
410
 
426
 
411
    public void refreshTotal() {
427
    public void refreshTotal() {
412
 
428
 
413
        long totalD = 0L;
429
        long totalD = 0L;
414
        long totalC = 0L;
430
        long totalC = 0L;
415
 
431
 
416
        for (int i = 0; i < table.getRowCount(); i++) {
432
        for (int i = 0; i < table.getRowCount(); i++) {
417
            Long c = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("DEBIT"));
433
            Long c = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("DEBIT"));
418
            Long d = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("CREDIT"));
434
            Long d = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("CREDIT"));
419
            if (c != null) {
435
            if (c != null) {
420
                totalC += c;
436
                totalC += c;
421
            }
437
            }
422
            if (d != null) {
438
            if (d != null) {
423
                totalD += d;
439
                totalD += d;
424
            }
440
            }
425
 
441
 
426
        }
442
        }
427
        this.labelTotalCredit.setText(GestionDevise.currencyToString(totalC));
443
        this.labelTotalCredit.setText(GestionDevise.currencyToString(totalC));
428
        this.labelTotalDebit.setText(GestionDevise.currencyToString(totalD));
444
        this.labelTotalDebit.setText(GestionDevise.currencyToString(totalD));
429
        this.labelTotalSolde.setText(GestionDevise.currencyToString(totalD - totalC));
445
        this.labelTotalSolde.setText(GestionDevise.currencyToString(totalD - totalC));
430
 
446
 
431
    }
447
    }
432
 
448
 
433
    public boolean isSaisieValid() {
449
    public boolean isSaisieValid() {
434
        // Check if partie double
450
        // Check if partie double
435
 
451
 
436
        long totalD = 0L;
452
        long totalD = 0L;
437
        long totalC = 0L;
453
        long totalC = 0L;
438
        boolean cptOK = true;
454
        boolean cptOK = true;
439
        String lib = null;
455
        String lib = null;
440
        for (int i = 0; i < table.getRowCount(); i++) {
456
        for (int i = 0; i < table.getRowCount(); i++) {
441
            Long c = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("DEBIT"));
457
            Long c = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("DEBIT"));
442
            Long d = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("CREDIT"));
458
            Long d = (Long) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("CREDIT"));
443
            if (c != null) {
459
            if (c != null) {
444
                totalC += c;
460
                totalC += c;
445
            }
461
            }
446
            if (d != null) {
462
            if (d != null) {
447
                totalD += d;
463
                totalD += d;
448
            }
464
            }
449
            if (lib == null) {
465
            if (lib == null) {
450
                lib = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NOM"));
466
                lib = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NOM"));
451
            }
467
            }
452
            String cptNUmber = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NUMERO"));
468
            String cptNUmber = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NUMERO"));
453
            cptOK = cptOK && cptNUmber != null && ComptePCESQLElement.isExist(cptNUmber);
469
            cptOK = cptOK && cptNUmber != null && ComptePCESQLElement.isExist(cptNUmber);
454
        }
470
        }
455
        return totalD + totalC != 0 && totalD == totalC && cptOK;
471
        return totalD + totalC != 0 && totalD == totalC && cptOK;
456
    }
472
    }
457
 
473
 
458
    private Tuple2<Date, String> getDateAndLabelFromSaisie() {
474
    private Tuple2<Date, String> getDateAndLabelFromSaisie() {
459
        int day = 1;
475
        int day = 1;
460
        String lib = null;
476
        String lib = null;
461
 
477
 
462
        for (int i = 0; i < table.getRowCount(); i++) {
478
        for (int i = 0; i < table.getRowCount(); i++) {
463
            day = (Integer) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("JOUR"));
479
            day = (Integer) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("JOUR"));
464
            if (lib == null) {
480
            if (lib == null) {
465
                lib = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NOM"));
481
                lib = (String) table.getRowValuesTableModel().getValueAt(i, table.getRowValuesTableModel().getColumnForField("NOM"));
466
            }
482
            }
467
        }
483
        }
468
        // Create saisieKM
484
        // Create saisieKM
469
        Calendar c = Calendar.getInstance();
485
        Calendar c = Calendar.getInstance();
470
        c.set(Calendar.YEAR, SaisieJournalItemTable.this.panel.getSelectedYear());
486
        c.set(Calendar.YEAR, SaisieJournalItemTable.this.panel.getSelectedYear());
471
        c.set(Calendar.MONTH, SaisieJournalItemTable.this.panel.getSelectedMonth());
487
        c.set(Calendar.MONTH, SaisieJournalItemTable.this.panel.getSelectedMonth());
472
        c.set(Calendar.DAY_OF_MONTH, day);
488
        c.set(Calendar.DAY_OF_MONTH, day);
473
        return Tuple2.create(c.getTime(), lib);
489
        return Tuple2.create(c.getTime(), lib);
474
    }
490
    }
475
 
491
 
476
    public void montantValid(final SQLRowValues defaultRowVals, final boolean fromAnalytique, final JTextField textPiece) {
492
    public void montantValid(final SQLRowValues defaultRowVals, final boolean fromAnalytique, final JTextField textPiece) {
477
        System.err.println("Enter");
493
        System.err.println("Enter");
478
        final SQLRowValues vals = SaisieJournalItemTable.this.table.getSelectedRowValues();
494
        final SQLRowValues vals = SaisieJournalItemTable.this.table.getSelectedRowValues();
479
        final int selectedRow = SaisieJournalItemTable.this.table.getSelectedRow();
495
        final int selectedRow = SaisieJournalItemTable.this.table.getSelectedRow();
480
        SwingUtilities.invokeLater(new Runnable() {
496
        SwingUtilities.invokeLater(new Runnable() {
481
            public void run() {
497
            public void run() {
482
 
498
 
483
                if (boxAutoInsert.isSelected() && isSaisieValid()) {
499
                if (boxAutoInsert.isSelected() && isSaisieValid()) {
484
                    if (SaisieJournalItemTable.this.panel.getSelectedJournal() == SQLRow.NONEXISTANT_ID || SaisieJournalItemTable.this.panel.getSelectedMonth() == -1) {
500
                    if (SaisieJournalItemTable.this.panel.getSelectedJournal() == SQLRow.NONEXISTANT_ID || SaisieJournalItemTable.this.panel.getSelectedMonth() == -1) {
485
                        JOptionPane.showMessageDialog(SaisieJournalItemTable.this.panel, "Impossible de créer la saisie si aucun journal ou aucun mois n'est sélectionné!");
501
                        JOptionPane.showMessageDialog(SaisieJournalItemTable.this.panel, "Impossible de créer la saisie si aucun journal ou aucun mois n'est sélectionné!");
486
                    } else {
502
                    } else {
487
                        createSaisie(defaultRowVals, textPiece);
503
                        createSaisie(defaultRowVals, textPiece);
488
                    }
504
                    }
489
                } else {
505
                } else {
490
                    if (!fromAnalytique && !hideAnalytique && vals.getString("NUMERO") != null && (vals.getString("NUMERO").startsWith("6") || vals.getString("NUMERO").startsWith("7"))) {
506
                    if (!fromAnalytique && !hideAnalytique && vals.getString("NUMERO") != null && (vals.getString("NUMERO").startsWith("6") || vals.getString("NUMERO").startsWith("7"))) {
491
 
507
 
492
                        // Update montant
508
                        // Update montant
493
                        Collection<SQLRowValues> rowsLinked = vals.getReferentRows(vals.getTable().getTable("ASSOCIATION_ANALYTIQUE"));
509
                        Collection<SQLRowValues> rowsLinked = vals.getReferentRows(vals.getTable().getTable("ASSOCIATION_ANALYTIQUE"));
494
                        long montant = vals.getLong("DEBIT") - vals.getLong("CREDIT");
510
                        long montant = vals.getLong("DEBIT") - vals.getLong("CREDIT");
495
                        for (SQLRowValues sqlRowValues : rowsLinked) {
511
                        for (SQLRowValues sqlRowValues : rowsLinked) {
496
                            sqlRowValues.put("MONTANT", sqlRowValues.getBigDecimal("POURCENT").movePointLeft(2).multiply(new BigDecimal(montant), DecimalUtils.HIGH_PRECISION)
512
                            sqlRowValues.put("MONTANT", sqlRowValues.getBigDecimal("POURCENT").movePointLeft(2).multiply(new BigDecimal(montant), DecimalUtils.HIGH_PRECISION)
497
                                    .setScale(0, RoundingMode.HALF_UP).longValue());
513
                                    .setScale(0, RoundingMode.HALF_UP).longValue());
498
                        }
514
                        }
499
 
515
 
500
                        editCellAt(selectedRow, table.getRowValuesTableModel().getColumnForField("ANALYTIQUE"));
516
                        editCellAt(selectedRow, table.getRowValuesTableModel().getColumnForField("ANALYTIQUE"));
501
                    } else {
517
                    } else {
502
 
518
 
503
                        long l = getContrepartie();
519
                        long l = getContrepartie();
504
                        SQLRowValues rowVals = new SQLRowValues(defaultRowVals);
520
                        SQLRowValues rowVals = new SQLRowValues(defaultRowVals);
505
                        if (l > 0) {
521
                        if (l > 0) {
506
                            rowVals.put("DEBIT", 0L);
522
                            rowVals.put("DEBIT", 0L);
507
                            rowVals.put("CREDIT", l);
523
                            rowVals.put("CREDIT", l);
508
                        } else {
524
                        } else {
509
                            rowVals.put("DEBIT", -l);
525
                            rowVals.put("DEBIT", -l);
510
                            rowVals.put("CREDIT", 0L);
526
                            rowVals.put("CREDIT", 0L);
511
                        }
527
                        }
512
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().addRow(rowVals);
528
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().addRow(rowVals);
513
                    }
529
                    }
514
                }
530
                }
515
 
531
 
516
            }
532
            }
517
        });
533
        });
518
 
534
 
519
    }
535
    }
520
 
536
 
521
    public synchronized void createSaisie(final SQLRowValues defaultRowVals, JTextField pieceText) {
537
    public synchronized void createSaisie(final SQLRowValues defaultRowVals, JTextField pieceText) {
522
 
538
 
523
        Tuple2<Date, String> t = getDateAndLabelFromSaisie();
539
        Tuple2<Date, String> t = getDateAndLabelFromSaisie();
524
        final Date d = t.get0();
540
        final Date d = t.get0();
525
        String pieceLabel = pieceText.getText();
541
        String pieceLabel = pieceText.getText();
526
        final String lib = pieceLabel == null || pieceLabel.trim().length() == 0 ? t.get1() : pieceLabel;
542
        final String lib = pieceLabel == null || pieceLabel.trim().length() == 0 ? t.get1() : pieceLabel;
527
 
543
 
528
        // Create saisieKM
544
        // Create saisieKM
529
        SQLRowValues rowVAlsKM = new SQLRowValues(SaisieJournalItemTable.this.table.getRowValuesTableModel().getSQLElement().getTable().getForeignTable("ID_SAISIE_KM"));
545
        SQLRowValues rowVAlsKM = new SQLRowValues(SaisieJournalItemTable.this.table.getRowValuesTableModel().getSQLElement().getTable().getForeignTable("ID_SAISIE_KM"));
530
 
546
 
531
        rowVAlsKM.put("DATE", d);
547
        rowVAlsKM.put("DATE", d);
532
        rowVAlsKM.put("NOM", lib);
548
        rowVAlsKM.put("NOM", lib);
533
        rowVAlsKM.put("ID_JOURNAL", SaisieJournalItemTable.this.panel.getSelectedJournal());
549
        rowVAlsKM.put("ID_JOURNAL", SaisieJournalItemTable.this.panel.getSelectedJournal());
534
        int id;
550
        int id;
535
        try {
551
        try {
536
            id = rowVAlsKM.insert().getID();
552
            id = rowVAlsKM.insert().getID();
537
 
553
 
538
            table.updateField("ID_SAISIE_KM", id);
554
            table.updateField("ID_SAISIE_KM", id);
539
            table.clear();
555
            table.clear();
540
            GenerationMvtSaisieKm gen = new GenerationMvtSaisieKm(id);
556
            GenerationMvtSaisieKm gen = new GenerationMvtSaisieKm(id);
541
            int idMvt = gen.genereMouvement();
557
            int idMvt = gen.genereMouvement();
542
 
558
 
543
            // maj de l'id du mouvement correspondant
559
            // maj de l'id du mouvement correspondant
544
            SQLRowValues rowValsKMMvt = new SQLRowValues(SaisieJournalItemTable.this.table.getRowValuesTableModel().getSQLElement().getTable().getForeignTable("ID_SAISIE_KM"));
560
            SQLRowValues rowValsKMMvt = new SQLRowValues(SaisieJournalItemTable.this.table.getRowValuesTableModel().getSQLElement().getTable().getForeignTable("ID_SAISIE_KM"));
545
            rowValsKMMvt.put("ID_MOUVEMENT", new Integer(idMvt));
561
            rowValsKMMvt.put("ID_MOUVEMENT", new Integer(idMvt));
546
            rowValsKMMvt.update(id);
562
            rowValsKMMvt.update(id);
547
 
563
 
548
            defaultRowVals.put("NOM_PIECE", "");
564
            defaultRowVals.put("NOM_PIECE", "");
549
            defaultRowVals.put("NOM_ECRITURE", "");
565
            defaultRowVals.put("NOM_ECRITURE", "");
550
            table.getRowValuesTableModel().addNewRow();
566
            table.getRowValuesTableModel().addNewRow();
551
            pieceText.setText("");
567
            pieceText.setText("");
552
        } catch (SQLException e) {
568
        } catch (SQLException e) {
553
            e.printStackTrace();
569
            e.printStackTrace();
554
        }
570
        }
555
 
571
 
556
    }
572
    }
557
 
573
 
558
    public void updateField(final String field, final int id) {
574
    public void updateField(final String field, final int id) {
559
        this.table.updateField(field, id);
575
        this.table.updateField(field, id);
560
    }
576
    }
561
 
577
 
562
    public void insertFrom(final String field, final int id) {
578
    public void insertFrom(final String field, final int id) {
563
        this.table.insertFrom(field, id);
579
        this.table.insertFrom(field, id);
564
    }
580
    }
565
 
581
 
566
    public void insertFrom(final SQLRowAccessor row) {
582
    public void insertFrom(final SQLRowAccessor row) {
567
        this.table.insertFrom(row);
583
        this.table.insertFrom(row);
568
    }
584
    }
569
 
585
 
570
    public RowValuesTableModel getModel() {
586
    public RowValuesTableModel getModel() {
571
        return this.table.getRowValuesTableModel();
587
        return this.table.getRowValuesTableModel();
572
    }
588
    }
573
 
589
 
574
    public SQLTableElement getCreditElement() {
590
    public SQLTableElement getCreditElement() {
575
        return this.credit;
591
        return this.credit;
576
    }
592
    }
577
 
593
 
578
    public SQLTableElement getDebitElement() {
594
    public SQLTableElement getDebitElement() {
579
        return this.debit;
595
        return this.debit;
580
    }
596
    }
581
 
597
 
582
    public SQLTableElement getNumeroCompteElement() {
598
    public SQLTableElement getNumeroCompteElement() {
583
        return this.tableElementNumeroCompte;
599
        return this.tableElementNumeroCompte;
584
    }
600
    }
585
 
601
 
586
    public void setCreateAutoActive(final boolean b) {
602
    public void setCreateAutoActive(final boolean b) {
587
        this.numeroCompteRenderer.setCreateActive(b);
603
        this.numeroCompteRenderer.setCreateActive(b);
588
        this.table.revalidate();
604
        this.table.revalidate();
589
        this.table.repaint();
605
        this.table.repaint();
590
    }
606
    }
591
 
607
 
592
    public void setRowDeviseValidAt(final boolean b, final int index) {
608
    public void setRowDeviseValidAt(final boolean b, final int index) {
593
        this.deviseRenderer.setValid(b, index);
609
        this.deviseRenderer.setValid(b, index);
594
 
610
 
595
    }
611
    }
596
 
612
 
597
    public void editCellAt(final int row, final int column) {
613
    public void editCellAt(final int row, final int column) {
598
        assert SwingUtilities.isEventDispatchThread();
614
        assert SwingUtilities.isEventDispatchThread();
599
        this.table.setColumnSelectionInterval(column, column);
615
        this.table.setColumnSelectionInterval(column, column);
600
        this.table.setRowSelectionInterval(row, row);
616
        this.table.setRowSelectionInterval(row, row);
601
        this.table.editCellAt(row, column);
617
        this.table.editCellAt(row, column);
602
    }
618
    }
603
 
619
 
604
    private long getContrepartie() {
620
    private long getContrepartie() {
605
        assert SwingUtilities.isEventDispatchThread();
621
        assert SwingUtilities.isEventDispatchThread();
606
        long totalCred = 0;
622
        long totalCred = 0;
607
        long totalDeb = 0;
623
        long totalDeb = 0;
608
        final RowValuesTableModel model = this.table.getRowValuesTableModel();
624
        final RowValuesTableModel model = this.table.getRowValuesTableModel();
609
        final int creditIndex = model.getColumnIndexForElement(getCreditElement());
625
        final int creditIndex = model.getColumnIndexForElement(getCreditElement());
610
        final int debitIndex = model.getColumnIndexForElement(getDebitElement());
626
        final int debitIndex = model.getColumnIndexForElement(getDebitElement());
611
        for (int i = 0; i < this.table.getRowCount(); i++) {
627
        for (int i = 0; i < this.table.getRowCount(); i++) {
612
            if (model.isRowValid(i)) {
628
            if (model.isRowValid(i)) {
613
                final Long fTc = (Long) model.getValueAt(i, creditIndex);
629
                final Long fTc = (Long) model.getValueAt(i, creditIndex);
614
                if (fTc != null) {
630
                if (fTc != null) {
615
                    totalCred += fTc.longValue();
631
                    totalCred += fTc.longValue();
616
                }
632
                }
617
                final Long fTd = (Long) model.getValueAt(i, debitIndex);
633
                final Long fTd = (Long) model.getValueAt(i, debitIndex);
618
                if (fTd != null) {
634
                if (fTd != null) {
619
                    totalDeb += fTd.longValue();
635
                    totalDeb += fTd.longValue();
620
                }
636
                }
621
            }
637
            }
622
        }
638
        }
623
        return totalDeb - totalCred;
639
        return totalDeb - totalCred;
624
    }
640
    }
625
 
641
 
626
    private long getSoldeRow(final int index) {
642
    private long getSoldeRow(final int index) {
627
        assert SwingUtilities.isEventDispatchThread();
643
        assert SwingUtilities.isEventDispatchThread();
628
        if (index >= 0 && index < this.table.getRowCount()) {
644
        if (index >= 0 && index < this.table.getRowCount()) {
629
            final SQLRowValues rowVals = this.table.getRowValuesTableModel().getRowValuesAt(index);
645
            final SQLRowValues rowVals = this.table.getRowValuesTableModel().getRowValuesAt(index);
630
            return rowVals.getLong("DEBIT") - rowVals.getLong("CREDIT");
646
            return rowVals.getLong("DEBIT") - rowVals.getLong("CREDIT");
631
        } else {
647
        } else {
632
            return 0;
648
            return 0;
633
        }
649
        }
634
    }
650
    }
635
 
651
 
636
    public void fillEmptyEntryLabel(String previousText, String text) {
652
    public void fillEmptyEntryLabel(String previousText, String text) {
637
        assert SwingUtilities.isEventDispatchThread();
653
        assert SwingUtilities.isEventDispatchThread();
638
        if (text == null)
654
        if (text == null)
639
            return;
655
            return;
640
        RowValuesTableModel model = table.getRowValuesTableModel();
656
        RowValuesTableModel model = table.getRowValuesTableModel();
641
        int size = model.getRowCount();
657
        int size = model.getRowCount();
642
        for (int i = 0; i < size; i++) {
658
        for (int i = 0; i < size; i++) {
643
            SQLRowValues r = model.getRowValuesAt(i);
659
            SQLRowValues r = model.getRowValuesAt(i);
644
            if (r.getString("NOM_ECRITURE") == null || r.getString("NOM_ECRITURE").trim().isEmpty() || r.getString("NOM_ECRITURE").trim().equals(previousText)) {
660
            if (r.getString("NOM_ECRITURE") == null || r.getString("NOM_ECRITURE").trim().isEmpty() || r.getString("NOM_ECRITURE").trim().equals(previousText)) {
645
                r.put("NOM_ECRITURE", text);
661
                r.put("NOM_ECRITURE", text);
646
            }
662
            }
647
        }
663
        }
648
        model.fireTableDataChanged();
664
        model.fireTableDataChanged();
649
    }
665
    }
650
 
666
 
651
    public void mousePressed(final MouseEvent e) {
667
    public void mousePressed(final MouseEvent e) {
652
        final int rowSel = this.table.getSelectedRow();
668
        final int rowSel = this.table.getSelectedRow();
653
        if (e.getButton() == MouseEvent.BUTTON3 && rowSel >= 0 && rowSel < this.table.getRowCount()) {
669
        if (e.getButton() == MouseEvent.BUTTON3 && rowSel >= 0 && rowSel < this.table.getRowCount()) {
654
            final JPopupMenu menuDroit = new JPopupMenu();
670
            final JPopupMenu menuDroit = new JPopupMenu();
655
 
671
 
656
            menuDroit.add(new AbstractAction("Contrepartie") {
672
            menuDroit.add(new AbstractAction("Contrepartie") {
657
                public void actionPerformed(final ActionEvent ev) {
673
                public void actionPerformed(final ActionEvent ev) {
658
 
674
 
659
                    long l = getContrepartie();
675
                    long l = getContrepartie();
660
                    if (SaisieJournalItemTable.this.table.getRowValuesTableModel().isRowValid(rowSel)) {
676
                    if (SaisieJournalItemTable.this.table.getRowValuesTableModel().isRowValid(rowSel)) {
661
                        l += getSoldeRow(rowSel);
677
                        l += getSoldeRow(rowSel);
662
                    }
678
                    }
663
 
679
 
664
                    if (l > 0) {
680
                    if (l > 0) {
665
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(Long.valueOf(0), rowSel, "DEBIT");
681
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(Long.valueOf(0), rowSel, "DEBIT");
666
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(l, rowSel, "CREDIT");
682
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(l, rowSel, "CREDIT");
667
                    } else {
683
                    } else {
668
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(Long.valueOf(0), rowSel, "CREDIT");
684
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(Long.valueOf(0), rowSel, "CREDIT");
669
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(-l, rowSel, "DEBIT");
685
                        SaisieJournalItemTable.this.table.getRowValuesTableModel().putValue(-l, rowSel, "DEBIT");
670
                    }
686
                    }
671
                }
687
                }
672
            });
688
            });
673
            menuDroit.pack();
689
            menuDroit.pack();
674
            menuDroit.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
690
            menuDroit.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
675
            menuDroit.setVisible(true);
691
            menuDroit.setVisible(true);
676
        }
692
        }
677
    }
693
    }
678
 
694
 
679
    public void mouseReleased(final MouseEvent e) {
695
    public void mouseReleased(final MouseEvent e) {
680
    }
696
    }
681
 
697
 
682
    public void mouseClicked(final MouseEvent e) {
698
    public void mouseClicked(final MouseEvent e) {
683
    }
699
    }
684
 
700
 
685
    public void mouseEntered(final MouseEvent e) {
701
    public void mouseEntered(final MouseEvent e) {
686
    }
702
    }
687
 
703
 
688
    public void mouseExited(final MouseEvent e) {
704
    public void mouseExited(final MouseEvent e) {
689
    }
705
    }
690
 
706
 
-
 
707
    private void cloneLine(int row) {
-
 
708
        if (row < 0) {
-
 
709
            System.err.println("RowValuesTableControlPanel.cloneLine() wrong selected line, index = " + row);
-
 
710
            Thread.dumpStack();
-
 
711
            return;
-
 
712
        }
-
 
713
        SQLRowValues rowVals = this.table.getRowValuesTableModel().getRowValuesAt(row);
-
 
714
 
-
 
715
        SQLRowValues rowValsBis = rowVals.deepCopy();
-
 
716
        rowValsBis.clearPrimaryKeys();
-
 
717
        rowValsBis.put(rowValsBis.getTable().getOrderField().getName(), null);
-
 
718
 
-
 
719
        this.table.getRowValuesTableModel().getSQLElement().clearPrivateFields(rowValsBis);
-
 
720
        rowValsBis.putEmptyLink("ID_ECRITURE");
-
 
721
        for (String elt : this.table.getClearCloneTableElement()) {
-
 
722
            if (rowValsBis.getTable().getFieldsName().contains(elt)) {
-
 
723
                rowValsBis.putEmptyLink(elt);
-
 
724
            }
-
 
725
        }
-
 
726
 
-
 
727
        this.table.getRowValuesTableModel().addRow(rowValsBis);
-
 
728
    }
691
}
729
}