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 182
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-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.finance.payment.component;
14
 package org.openconcerto.erp.core.finance.payment.component;
15
 
15
 
16
import org.openconcerto.erp.config.Log;
16
import org.openconcerto.erp.config.Log;
17
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
17
import org.openconcerto.erp.core.common.element.BanqueSQLElement;
18
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
18
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement;
19
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
19
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement;
20
import org.openconcerto.erp.model.BanqueModifiedListener;
20
import org.openconcerto.erp.model.BanqueModifiedListener;
21
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.BaseSQLComponent;
22
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.element.SQLElement;
23
import org.openconcerto.sql.model.SQLBackgroundTableCache;
23
import org.openconcerto.sql.model.SQLBackgroundTableCache;
24
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.Where;
26
import org.openconcerto.sql.model.Where;
27
import org.openconcerto.sql.request.ComboSQLRequest;
27
import org.openconcerto.sql.request.ComboSQLRequest;
28
import org.openconcerto.sql.sqlobject.ElementComboBox;
28
import org.openconcerto.sql.sqlobject.ElementComboBox;
29
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
29
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
30
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
30
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
31
import org.openconcerto.sql.sqlobject.SQLTextCombo;
31
import org.openconcerto.sql.sqlobject.SQLTextCombo;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.JDate;
33
import org.openconcerto.ui.JDate;
34
import org.openconcerto.ui.component.ITextCombo;
34
import org.openconcerto.ui.component.ITextCombo;
35
import org.openconcerto.utils.CollectionUtils;
35
import org.openconcerto.utils.CollectionUtils;
36
 
36
 
37
import java.awt.Dimension;
37
import java.awt.Dimension;
38
import java.awt.GridBagConstraints;
38
import java.awt.GridBagConstraints;
39
import java.awt.GridBagLayout;
39
import java.awt.GridBagLayout;
40
import java.awt.event.ItemEvent;
40
import java.awt.event.ItemEvent;
41
import java.awt.event.ItemListener;
41
import java.awt.event.ItemListener;
42
import java.beans.PropertyChangeEvent;
42
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeListener;
43
import java.beans.PropertyChangeListener;
44
import java.util.Date;
44
import java.util.Date;
45
import java.util.HashMap;
45
import java.util.HashMap;
46
import java.util.Map;
46
import java.util.Map;
47
import java.util.Set;
47
import java.util.Set;
48
 
48
 
49
import javax.swing.ButtonGroup;
49
import javax.swing.ButtonGroup;
50
import javax.swing.JCheckBox;
50
import javax.swing.JCheckBox;
51
import javax.swing.JLabel;
51
import javax.swing.JLabel;
52
import javax.swing.JPanel;
52
import javax.swing.JPanel;
53
import javax.swing.JRadioButton;
53
import javax.swing.JRadioButton;
54
import javax.swing.JTextField;
54
import javax.swing.JTextField;
55
import javax.swing.event.EventListenerList;
55
import javax.swing.event.EventListenerList;
56
 
56
 
57
public class ModeDeReglementSQLComponent extends BaseSQLComponent {
57
public class ModeDeReglementSQLComponent extends BaseSQLComponent {
58
 
58
 
59
    static private enum Mode {
59
    static private enum Mode {
60
        ECHEANCE, CHEQUE, VIREMENT
60
        ECHEANCE, CHEQUE, VIREMENT
61
    }
61
    }
62
 
62
 
63
    static public final int MONTH_END = 31;
63
    static public final int MONTH_END = 31;
64
    static public final int AT_INVOICE_DATE = 0;
64
    static public final int AT_INVOICE_DATE = 0;
65
 
65
 
66
    private final ElementComboBox boxBanque = new ElementComboBox(true, 20);
66
    private final ElementComboBox boxBanque = new ElementComboBox(true, 20);
67
    private final JPanel panelBanque = new JPanel(new GridBagLayout());
67
    private final JPanel panelBanque = new JPanel(new GridBagLayout());
68
    private final JPanel panelEcheance = new JPanel(new GridBagLayout());
68
    private final JPanel panelEcheance = new JPanel(new GridBagLayout());
69
    private final EventListenerList banqueModifiedListenerList = new EventListenerList();
69
    private final EventListenerList banqueModifiedListenerList = new EventListenerList();
70
    private final SQLRequestComboBox comboTypeReglement = new SQLRequestComboBox();
70
    private final SQLRequestComboBox comboTypeReglement = new SQLRequestComboBox();
71
    private ITextCombo comboA;
71
    private ITextCombo comboA;
72
    private final ITextCombo comboLe = new SQLTextCombo();
72
    private final ITextCombo comboLe = new SQLTextCombo();
73
    private final SQLSearchableTextCombo comboBanque = new SQLSearchableTextCombo();
73
    private final SQLSearchableTextCombo comboBanque = new SQLSearchableTextCombo();
74
    private final JRadioButton buttonFinMois = new JRadioButton("fin de mois");
74
    private final JRadioButton buttonFinMois = new JRadioButton("fin de mois");
75
    private final JRadioButton buttonDateFacture = new JRadioButton("date de facturation");
75
    private final JRadioButton buttonDateFacture = new JRadioButton("date de facturation");
76
    private final JRadioButton buttonLe = new JRadioButton("le");
76
    private final JRadioButton buttonLe = new JRadioButton("le");
77
    private final JCheckBox checkboxComptant = new JCheckBox("Comptant");
77
    private final JCheckBox checkboxComptant = new JCheckBox("Comptant");
78
    private final JDate dateDepot = new JDate(false);
78
    private final JDate dateDepot = new JDate(false);
79
    private final JDate dateVirt = new JDate(false);
79
    private final JDate dateVirt = new JDate(false);
80
    private final JDate dateCheque = new JDate(false);
80
    private final JDate dateCheque = new JDate(false);
81
    private final JTextField numeroChq = new JTextField();
81
    private final JTextField numeroChq = new JTextField();
82
    private final JTextField nom = new JTextField(30);
82
    private final JTextField nom = new JTextField(30);
83
    private JPanel panelActive = null;
83
    private JPanel panelActive = null;
84
    private final Map<Mode, JPanel> m = new HashMap<Mode, JPanel>();
84
    private final Map<Mode, JPanel> m = new HashMap<Mode, JPanel>();
85
 
85
 
86
    private int rowIdMode;
86
    private int rowIdMode;
87
 
87
 
88
    private void setComponentModeEnabled(final SQLRow rowTypeRegl) {
88
    private void setComponentModeEnabled(final SQLRow rowTypeRegl) {
89
 
89
 
90
        if (rowTypeRegl != null && this.rowIdMode != rowTypeRegl.getID()) {
90
        if (rowTypeRegl != null && this.rowIdMode != rowTypeRegl.getID()) {
91
            this.rowIdMode = rowTypeRegl.getID();
91
            this.rowIdMode = rowTypeRegl.getID();
92
            System.err.println("ModeDeReglementNGSQLComponent.setComponentModeEnabled() " + this.rowIdMode);
92
            System.err.println("ModeDeReglementNGSQLComponent.setComponentModeEnabled() " + this.rowIdMode);
93
        } else {
93
        } else {
94
 
94
 
95
            return;
95
            return;
96
        }
96
        }
97
 
97
 
98
        final ButtonGroup group = new ButtonGroup();
98
        final ButtonGroup group = new ButtonGroup();
99
        group.add(this.buttonFinMois);
99
        group.add(this.buttonFinMois);
100
        group.add(this.buttonDateFacture);
100
        group.add(this.buttonDateFacture);
101
        group.add(this.buttonLe);
101
        group.add(this.buttonLe);
102
 
102
 
103
        final Boolean forceLater = rowTypeRegl.getBoolean("ECHEANCE");
103
        final Boolean forceLater = rowTypeRegl.getBoolean("ECHEANCE");
104
        final Boolean forceNow = rowTypeRegl.getBoolean("COMPTANT");
104
        final Boolean forceNow = rowTypeRegl.getBoolean("COMPTANT");
105
        if (forceLater && forceNow)
105
        if (forceLater && forceNow)
106
            Log.get().warning("Force opposite for " + rowTypeRegl);
106
            Log.get().warning("Force opposite for " + rowTypeRegl);
107
 
107
 
108
        this.allowEditable(this.getView(this.checkboxComptant), !forceLater && !forceNow);
108
        this.allowEditable(this.getView(this.checkboxComptant), !forceLater && !forceNow);
109
 
109
 
110
        if (forceLater) {
110
        if (forceLater) {
111
            this.checkboxComptant.setSelected(false);
111
            this.checkboxComptant.setSelected(false);
112
        }
112
        }
113
        if (forceNow) {
113
        if (forceNow) {
114
            this.checkboxComptant.setSelected(true);
114
            this.checkboxComptant.setSelected(true);
115
        }
115
        }
116
 
116
 
117
        updatePanel();
117
        updatePanel();
118
    }
118
    }
119
 
119
 
120
    public ModeDeReglementSQLComponent(final SQLElement elt) {
120
    public ModeDeReglementSQLComponent(final SQLElement elt) {
121
        super(elt);
121
        super(elt);
122
    }
122
    }
123
 
123
 
124
    // private
124
    // private
125
    private final JPanel infosCheque = new JPanel(new GridBagLayout());
125
    private final JPanel infosCheque = new JPanel(new GridBagLayout());
126
    private final JPanel infosVirt = new JPanel(new GridBagLayout());
126
    private final JPanel infosVirt = new JPanel(new GridBagLayout());
127
 
127
 
128
    @Override
128
    @Override
129
    protected Set<String> createRequiredNames() {
129
    protected Set<String> createRequiredNames() {
130
        return CollectionUtils.createSet("ID_TYPE_REGLEMENT");
130
        return CollectionUtils.createSet("ID_TYPE_REGLEMENT");
131
    }
131
    }
132
 
132
 
133
    @Override
133
    @Override
134
    public void addViews() {
134
    public void addViews() {
135
 
135
 
136
        this.setLayout(new GridBagLayout());
136
        this.setLayout(new GridBagLayout());
137
 
137
 
138
        final GridBagConstraints c = new DefaultGridBagConstraints();
138
        final GridBagConstraints c = new DefaultGridBagConstraints();
139
 
139
 
140
        c.fill = GridBagConstraints.NONE;
140
        c.fill = GridBagConstraints.NONE;
141
        c.anchor = GridBagConstraints.WEST;
141
        c.anchor = GridBagConstraints.WEST;
142
 
142
 
143
        /*******************************************************************************************
143
        /*******************************************************************************************
144
         * SELECTION DU MODE DE REGLEMENT
144
         * SELECTION DU MODE DE REGLEMENT
145
         ******************************************************************************************/
145
         ******************************************************************************************/
146
        this.comboA = new SQLTextCombo(false);
146
        this.comboA = new SQLTextCombo(false);
147
 
147
 
148
        final GridBagConstraints cB = new DefaultGridBagConstraints();
148
        final GridBagConstraints cB = new DefaultGridBagConstraints();
149
        this.panelBanque.setOpaque(false);
149
        this.panelBanque.setOpaque(false);
150
        this.panelBanque.add(new JLabel(getLabelFor("ID_" + BanqueSQLElement.TABLENAME)), cB);
150
        this.panelBanque.add(new JLabel(getLabelFor("ID_" + BanqueSQLElement.TABLENAME)), cB);
151
        cB.weightx = 1;
151
        cB.weightx = 1;
152
        cB.gridx++;
152
        cB.gridx++;
153
        this.panelBanque.add(this.boxBanque, cB);
153
        this.panelBanque.add(this.boxBanque, cB);
154
        c.gridwidth = GridBagConstraints.REMAINDER;
154
        c.gridwidth = GridBagConstraints.REMAINDER;
155
        c.weightx = 1;
155
        c.weightx = 1;
156
        c.fill = GridBagConstraints.HORIZONTAL;
156
        c.fill = GridBagConstraints.HORIZONTAL;
157
        this.add(this.panelBanque, c);
157
        this.add(this.panelBanque, c);
158
 
158
 
159
        c.gridwidth = 1;
159
        c.gridwidth = 1;
160
        c.weightx = 0;
160
        c.weightx = 0;
161
        c.fill = GridBagConstraints.NONE;
161
        c.fill = GridBagConstraints.NONE;
162
        c.gridy++;
162
        c.gridy++;
163
        c.gridheight = 1;
163
        c.gridheight = 1;
164
        this.add(new JLabel("Règlement par"), c);
164
        this.add(new JLabel("Règlement par"), c);
165
 
165
 
166
        this.comboTypeReglement.setPreferredSize(new Dimension(80, new JTextField().getPreferredSize().height));
166
        this.comboTypeReglement.setPreferredSize(new Dimension(80, new JTextField().getPreferredSize().height));
167
        DefaultGridBagConstraints.lockMinimumSize(this.comboTypeReglement);
167
        DefaultGridBagConstraints.lockMinimumSize(this.comboTypeReglement);
168
        c.gridx++;
168
        c.gridx++;
169
        c.fill = GridBagConstraints.HORIZONTAL;
169
        c.fill = GridBagConstraints.HORIZONTAL;
170
        this.add(this.comboTypeReglement, c);
170
        this.add(this.comboTypeReglement, c);
171
        c.gridheight = 1;
171
        c.gridheight = 1;
172
        // Mode de règlement
172
        // Mode de règlement
173
        c.gridx++;
173
        c.gridx++;
174
        DefaultGridBagConstraints.lockMinimumSize(this.checkboxComptant);
174
        DefaultGridBagConstraints.lockMinimumSize(this.checkboxComptant);
175
        this.checkboxComptant.setOpaque(false);
175
        this.checkboxComptant.setOpaque(false);
176
        this.add(this.checkboxComptant, c);
176
        this.add(this.checkboxComptant, c);
177
 
177
 
178
        // Infos sur le reglement, depend du type de reglement et du comptant oui/non
178
        // Infos sur le reglement, depend du type de reglement et du comptant oui/non
179
        c.gridy++;
179
        c.gridy++;
180
        c.gridx = 0;
180
        c.gridx = 0;
181
        c.weightx = 1;
181
        c.weightx = 1;
182
        c.gridwidth = 3;
182
        c.gridwidth = 3;
183
        c.fill = GridBagConstraints.HORIZONTAL;
183
        c.fill = GridBagConstraints.HORIZONTAL;
184
        c.gridheight = GridBagConstraints.REMAINDER;
184
        c.gridheight = GridBagConstraints.REMAINDER;
185
        createPanelChequeComptant();
185
        createPanelChequeComptant();
186
        this.add(this.infosCheque, c);
186
        this.add(this.infosCheque, c);
187
        createPanelVirementComptant();
187
        createPanelVirementComptant();
188
        this.add(this.infosVirt, c);
188
        this.add(this.infosVirt, c);
189
        createPanelEcheance();
189
        createPanelEcheance();
190
        this.add(this.panelEcheance, c);
190
        this.add(this.panelEcheance, c);
191
 
191
 
192
        this.addView(this.comboTypeReglement, "ID_TYPE_REGLEMENT");
192
        this.addView(this.comboTypeReglement, "ID_TYPE_REGLEMENT");
193
        this.addView(this.checkboxComptant, "COMPTANT");
193
        this.addView(this.checkboxComptant, "COMPTANT");
194
 
194
 
195
        // cheque
195
        // cheque
196
        this.addSQLObject(this.comboBanque, "ETS");
196
        this.addSQLObject(this.comboBanque, "ETS");
197
        this.addSQLObject(this.numeroChq, "NUMERO");
197
        this.addSQLObject(this.numeroChq, "NUMERO");
198
        this.addSQLObject(this.dateCheque, "DATE");
198
        this.addSQLObject(this.dateCheque, "DATE");
199
        this.addSQLObject(this.dateDepot, "DATE_DEPOT");
199
        this.addSQLObject(this.dateDepot, "DATE_DEPOT");
200
 
200
 
201
        // virement
201
        // virement
202
        this.addSQLObject(this.nom, "NOM");
202
        this.addSQLObject(this.nom, "NOM");
203
        this.addSQLObject(this.dateVirt, "DATE_VIREMENT");
203
        this.addSQLObject(this.dateVirt, "DATE_VIREMENT");
204
 
204
 
205
        this.addRequiredSQLObject(this.comboA, "AJOURS");
205
        this.addRequiredSQLObject(this.comboA, "AJOURS");
206
        this.addSQLObject(this.buttonDateFacture, "DATE_FACTURE");
206
        this.addSQLObject(this.buttonDateFacture, "DATE_FACTURE");
207
        this.addSQLObject(this.buttonFinMois, "FIN_MOIS");
207
        this.addSQLObject(this.buttonFinMois, "FIN_MOIS");
208
        this.addRequiredSQLObject(this.comboLe, "LENJOUR");
208
        this.addRequiredSQLObject(this.comboLe, "LENJOUR");
209
 
209
 
210
        // Listeners
210
        // Listeners
211
 
211
 
212
        this.addSQLObject(this.boxBanque, "ID_" + BanqueSQLElement.TABLENAME);
212
        this.addSQLObject(this.boxBanque, "ID_" + BanqueSQLElement.TABLENAME);
213
        this.boxBanque.setButtonsVisible(false);
213
        this.boxBanque.setButtonsVisible(false);
214
        this.boxBanque.setOpaque(false);
214
        this.boxBanque.setOpaque(false);
215
        this.boxBanque.addModelListener("wantedID", new PropertyChangeListener() {
215
        this.boxBanque.addModelListener("wantedID", new PropertyChangeListener() {
216
            @Override
216
            @Override
217
            public void propertyChange(final PropertyChangeEvent evt) {
217
            public void propertyChange(final PropertyChangeEvent evt) {
218
                final Integer i = ModeDeReglementSQLComponent.this.boxBanque.getWantedID();
218
                final Integer i = ModeDeReglementSQLComponent.this.boxBanque.getWantedID();
219
                final int value = (i == null) ? -1 : Integer.valueOf(i);
219
                final int value = (i == null) ? -1 : Integer.valueOf(i);
220
                fireBanqueIdChange(value);
220
                fireBanqueIdChange(value);
221
            }
221
            }
222
        });
222
        });
223
 
223
 
224
        this.comboTypeReglement.addValueListener(new PropertyChangeListener() {
224
        this.comboTypeReglement.addValueListener(new PropertyChangeListener() {
225
 
225
 
226
            @Override
226
            @Override
227
            public void propertyChange(final PropertyChangeEvent evt) {
227
            public void propertyChange(final PropertyChangeEvent evt) {
228
                final Integer id = ModeDeReglementSQLComponent.this.comboTypeReglement.getValue();
228
                final Integer id = ModeDeReglementSQLComponent.this.comboTypeReglement.getValue();
229
                if (id != null && id > 1) {
229
                if (id != null && id > 1) {
230
 
230
 
231
                    final SQLRow ligneTypeReg = SQLBackgroundTableCache.getInstance().getCacheForTable(getTable().getBase().getTable("TYPE_REGLEMENT")).getRowFromId(id);
231
                    final SQLRow ligneTypeReg = SQLBackgroundTableCache.getInstance().getCacheForTable(getTable().getBase().getTable("TYPE_REGLEMENT")).getRowFromId(id);
232
                    setComponentModeEnabled(ligneTypeReg);
232
                    setComponentModeEnabled(ligneTypeReg);
233
                }
233
                }
234
            }
234
            }
235
        });
235
        });
236
 
236
 
237
        this.buttonLe.addItemListener(new ItemListener() {
237
        this.buttonLe.addItemListener(new ItemListener() {
238
            @Override
238
            @Override
239
            public void itemStateChanged(final ItemEvent e) {
239
            public void itemStateChanged(final ItemEvent e) {
240
                allowEditable(getView(ModeDeReglementSQLComponent.this.comboLe), e.getStateChange() == ItemEvent.SELECTED && !ModeDeReglementSQLComponent.this.checkboxComptant.isSelected());
240
                allowEditable(getView(ModeDeReglementSQLComponent.this.comboLe), e.getStateChange() == ItemEvent.SELECTED && !ModeDeReglementSQLComponent.this.checkboxComptant.isSelected());
241
            }
241
            }
242
        });
242
        });
243
        // initial value
243
        // initial value
244
        this.allowEditable(this.getView(this.comboLe), false);
244
        this.allowEditable(this.getView(this.comboLe), false);
245
 
245
 
246
        this.buttonFinMois.addItemListener(new ItemListener() {
246
        this.buttonFinMois.addItemListener(new ItemListener() {
247
            @Override
247
            @Override
248
            public void itemStateChanged(final ItemEvent e) {
248
            public void itemStateChanged(final ItemEvent e) {
249
                // System.err.println("Fin de mois");
249
                // System.err.println("Fin de mois");
250
                if (e.getStateChange() == ItemEvent.SELECTED) {
250
                if (e.getStateChange() == ItemEvent.SELECTED) {
251
                    ModeDeReglementSQLComponent.this.comboLe.setValue(String.valueOf(MONTH_END));
251
                    ModeDeReglementSQLComponent.this.comboLe.setValue(String.valueOf(MONTH_END));
252
                }
252
                }
253
            }
253
            }
254
        });
254
        });
255
 
255
 
256
        this.buttonDateFacture.addItemListener(new ItemListener() {
256
        this.buttonDateFacture.addItemListener(new ItemListener() {
257
            @Override
257
            @Override
258
            public void itemStateChanged(final ItemEvent e) {
258
            public void itemStateChanged(final ItemEvent e) {
259
                // System.err.println("Date de facturation");
259
                // System.err.println("Date de facturation");
260
                if (e.getStateChange() == ItemEvent.SELECTED) {
260
                if (e.getStateChange() == ItemEvent.SELECTED) {
261
                    ModeDeReglementSQLComponent.this.comboLe.setValue(String.valueOf(AT_INVOICE_DATE));
261
                    ModeDeReglementSQLComponent.this.comboLe.setValue(String.valueOf(AT_INVOICE_DATE));
262
                }
262
                }
263
            }
263
            }
264
        });
264
        });
265
 
265
 
266
        this.getView(this.comboLe).addValueListener(new PropertyChangeListener() {
266
        this.getView(this.comboLe).addValueListener(new PropertyChangeListener() {
267
            @Override
267
            @Override
268
            public void propertyChange(PropertyChangeEvent evt) {
268
            public void propertyChange(PropertyChangeEvent evt) {
269
                final Number newVal = (Number) evt.getNewValue();
269
                final Number newVal = (Number) evt.getNewValue();
270
                if (newVal != null && newVal.intValue() != AT_INVOICE_DATE && newVal.intValue() != MONTH_END) {
270
                if (newVal != null && newVal.intValue() != AT_INVOICE_DATE && newVal.intValue() != MONTH_END) {
271
                    ModeDeReglementSQLComponent.this.buttonLe.setSelected(true);
271
                    ModeDeReglementSQLComponent.this.buttonLe.setSelected(true);
272
                }
272
                }
273
            }
273
            }
274
        });
274
        });
275
 
275
 
276
        this.checkboxComptant.addItemListener(new ItemListener() {
276
        this.checkboxComptant.addItemListener(new ItemListener() {
277
            @Override
277
            @Override
278
            public void itemStateChanged(final ItemEvent e) {
278
            public void itemStateChanged(final ItemEvent e) {
279
                setEcheanceEnabled(e.getStateChange() == ItemEvent.DESELECTED);
279
                setEcheanceEnabled(e.getStateChange() == ItemEvent.DESELECTED);
280
            }
280
            }
281
        });
281
        });
282
    }
282
    }
283
 
283
 
284
    public void addDateCompListener(JDate dateParent) {
284
    public void addDateCompListener(JDate dateParent) {
285
        dateParent.addPropertyChangeListener(new PropertyChangeListener() {
285
        dateParent.addPropertyChangeListener(new PropertyChangeListener() {
286
 
286
 
287
            @Override
287
            @Override
288
            public void propertyChange(PropertyChangeEvent evt) {
288
            public void propertyChange(PropertyChangeEvent evt) {
289
                ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
289
                ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
290
                refreshDatePrev();
290
                refreshDatePrev();
291
            }
291
            }
292
        });
292
        });
293
        dateParent.addValueListener(new PropertyChangeListener() {
293
        dateParent.addValueListener(new PropertyChangeListener() {
294
 
294
 
295
            @Override
295
            @Override
296
            public void propertyChange(PropertyChangeEvent evt) {
296
            public void propertyChange(PropertyChangeEvent evt) {
297
                ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
297
                ModeDeReglementSQLComponent.this.currentDate = dateParent.getValue();
298
                refreshDatePrev();
298
                refreshDatePrev();
299
            }
299
            }
300
        });
300
        });
301
    }
301
    }
302
 
302
 
303
    private void refreshDatePrev() {
303
    private void refreshDatePrev() {
304
        if (this.currentDate != null) {
304
        if (this.currentDate != null) {
305
            int aJ = this.comboA.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboA.getValue());
305
            int aJ = this.comboA.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboA.getValue());
306
            int nJ = this.comboLe.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboLe.getValue());
306
            int nJ = this.comboLe.getValue().trim().length() == 0 ? 0 : Integer.valueOf(this.comboLe.getValue());
307
            Date d = ModeDeReglementSQLElement.calculDate(aJ, nJ, this.currentDate);
307
            Date d = ModeDeReglementSQLElement.calculDate(aJ, nJ, this.currentDate);
308
            this.datePrev.setDate(d);
308
            this.datePrev.setDate(d);
309
        } else {
309
        } else {
310
            this.datePrev.setDate(null);
310
            this.datePrev.setDate(null);
311
        }
311
        }
312
    }
312
    }
313
 
313
 
314
    private JDate datePrev = new JDate();
314
    private JDate datePrev = new JDate();
315
    private Date currentDate = null;
315
    private Date currentDate = null;
316
 
316
 
317
    private void createPanelEcheance() {
317
    private void createPanelEcheance() {
318
 
318
 
319
        final GridBagConstraints c = new DefaultGridBagConstraints();
319
        final GridBagConstraints c = new DefaultGridBagConstraints();
320
        c.fill = GridBagConstraints.NONE;
320
        c.fill = GridBagConstraints.NONE;
321
        this.panelEcheance.setOpaque(false);
321
        this.panelEcheance.setOpaque(false);
322
        this.panelEcheance.add(new JLabel("A"), c);
322
        this.panelEcheance.add(new JLabel("A"), c);
323
        c.gridx++;
323
        c.gridx++;
324
        c.gridwidth = 1;
324
        c.gridwidth = 1;
325
        this.comboA.setMinimumSize(new Dimension(60, this.comboA.getMinimumSize().height));
325
        this.comboA.setMinimumSize(new Dimension(80, this.comboA.getMinimumSize().height));
326
        this.comboA.setPreferredSize(new Dimension(60, this.comboA.getMinimumSize().height));
326
        this.comboA.setPreferredSize(new Dimension(80, this.comboA.getMinimumSize().height));
327
        this.comboA.setMaximumSize(new Dimension(60, this.comboA.getMinimumSize().height));
327
        this.comboA.setMaximumSize(new Dimension(80, this.comboA.getMinimumSize().height));
328
        this.comboA.addValueListener(new PropertyChangeListener() {
328
        this.comboA.addValueListener(new PropertyChangeListener() {
329
 
329
 
330
            @Override
330
            @Override
331
            public void propertyChange(PropertyChangeEvent evt) {
331
            public void propertyChange(PropertyChangeEvent evt) {
332
                refreshDatePrev();
332
                refreshDatePrev();
333
            }
333
            }
334
        });
334
        });
335
        this.panelEcheance.add(this.comboA, c);
335
        this.panelEcheance.add(this.comboA, c);
336
        c.gridx += 1;
336
        c.gridx += 1;
337
        c.gridwidth = 1;
337
        c.gridwidth = 1;
338
        this.panelEcheance.add(new JLabel("jours,"), c);
338
        this.panelEcheance.add(new JLabel("jours,"), c);
339
        c.gridx++;
339
        c.gridx++;
340
        c.weightx = 1;
340
        c.weightx = 1;
341
        c.gridwidth = 2;
341
        c.gridwidth = 2;
342
        c.fill = GridBagConstraints.HORIZONTAL;
342
        c.fill = GridBagConstraints.HORIZONTAL;
343
        this.buttonDateFacture.setOpaque(false);
343
        this.buttonDateFacture.setOpaque(false);
344
        this.panelEcheance.add(this.buttonDateFacture, c);
344
        this.panelEcheance.add(this.buttonDateFacture, c);
345
 
345
 
346
        c.gridy++;
346
        c.gridy++;
347
        c.gridx = 0;
347
        c.gridx = 0;
348
        c.weightx = 1;
348
        c.weightx = 1;
349
        c.gridwidth = 1;
349
        c.gridwidth = 1;
350
        // ((BaseSQLComponent)((ElementSQLObject)getSQLParent()).getSQLParent()).getView("DATE");
350
        // ((BaseSQLComponent)((ElementSQLObject)getSQLParent()).getSQLParent()).getView("DATE");
351
        this.panelEcheance.add(new JLabel("Soit le"), c);
351
        this.panelEcheance.add(new JLabel("Soit le"), c);
352
        c.gridx++;
352
        c.gridx++;
353
        c.gridwidth = 1;
353
        c.gridwidth = 1;
354
        this.datePrev.setEnabled(false);
354
        this.datePrev.setEnabled(false);
355
        this.panelEcheance.add(this.datePrev, c);
355
        this.panelEcheance.add(this.datePrev, c);
356
 
356
 
357
        // c.gridy++;
357
        // c.gridy++;
358
        c.gridwidth = 2;
358
        c.gridwidth = 2;
359
        c.gridx = 3;
359
        c.gridx = 3;
360
        c.weightx = 0;
360
        c.weightx = 0;
361
        c.fill = GridBagConstraints.NONE;
361
        c.fill = GridBagConstraints.NONE;
362
        this.buttonFinMois.setOpaque(false);
362
        this.buttonFinMois.setOpaque(false);
363
        this.panelEcheance.add(this.buttonFinMois, c);
363
        this.panelEcheance.add(this.buttonFinMois, c);
364
        c.gridy++;
364
        c.gridy++;
365
        c.gridwidth = 1;
365
        c.gridwidth = 1;
366
        this.buttonLe.setOpaque(false);
366
        this.buttonLe.setOpaque(false);
367
        this.panelEcheance.add(this.buttonLe, c);
367
        this.panelEcheance.add(this.buttonLe, c);
368
 
368
 
369
        c.gridx++;
369
        c.gridx++;
370
        this.comboLe.setMinimumSize(new Dimension(60, this.comboLe.getMinimumSize().height));
370
        this.comboLe.setMinimumSize(new Dimension(80, this.comboLe.getMinimumSize().height));
371
        this.comboLe.setPreferredSize(new Dimension(60, this.comboLe.getMinimumSize().height));
371
        this.comboLe.setPreferredSize(new Dimension(80, this.comboLe.getMinimumSize().height));
372
        this.comboLe.setMaximumSize(new Dimension(60, this.comboLe.getMinimumSize().height));
372
        this.comboLe.setMaximumSize(new Dimension(80, this.comboLe.getMinimumSize().height));
373
        this.comboLe.addValueListener(new PropertyChangeListener() {
373
        this.comboLe.addValueListener(new PropertyChangeListener() {
374
 
374
 
375
            @Override
375
            @Override
376
            public void propertyChange(PropertyChangeEvent evt) {
376
            public void propertyChange(PropertyChangeEvent evt) {
377
                refreshDatePrev();
377
                refreshDatePrev();
378
            }
378
            }
379
        });
379
        });
380
        this.panelEcheance.add(this.comboLe, c);
380
        this.panelEcheance.add(this.comboLe, c);
381
        this.panelActive = this.panelEcheance;
381
        this.panelActive = this.panelEcheance;
382
        this.m.put(Mode.ECHEANCE, this.panelEcheance);
382
        this.m.put(Mode.ECHEANCE, this.panelEcheance);
383
 
383
 
384
        DefaultGridBagConstraints.lockMinimumSize(this.panelEcheance);
384
        DefaultGridBagConstraints.lockMinimumSize(this.panelEcheance);
385
 
385
 
386
    }
386
    }
387
 
387
 
388
    public void createPanelChequeComptant() {
388
    public void createPanelChequeComptant() {
389
        // this.infosCheque.setBorder(BorderFactory.createTitledBorder("Informations Chèque"));
389
        // this.infosCheque.setBorder(BorderFactory.createTitledBorder("Informations Chèque"));
390
        final GridBagConstraints cCheque = new DefaultGridBagConstraints();
390
        final GridBagConstraints cCheque = new DefaultGridBagConstraints();
391
        this.infosCheque.add(new JLabel("Banque"), cCheque);
391
        this.infosCheque.add(new JLabel("Banque"), cCheque);
392
        cCheque.gridx++;
392
        cCheque.gridx++;
393
 
393
 
394
        this.infosCheque.add(this.comboBanque, cCheque);
394
        this.infosCheque.add(this.comboBanque, cCheque);
395
        cCheque.gridx++;
395
        cCheque.gridx++;
396
        this.infosCheque.add(new JLabel("N°"), cCheque);
396
        this.infosCheque.add(new JLabel("N°"), cCheque);
397
        cCheque.gridx++;
397
        cCheque.gridx++;
398
        DefaultGridBagConstraints.lockMinimumSize(this.numeroChq);
398
        DefaultGridBagConstraints.lockMinimumSize(this.numeroChq);
399
        this.infosCheque.add(this.numeroChq, cCheque);
399
        this.infosCheque.add(this.numeroChq, cCheque);
400
        cCheque.gridy++;
400
        cCheque.gridy++;
401
        cCheque.gridx = 0;
401
        cCheque.gridx = 0;
402
        this.infosCheque.add(new JLabel("Daté du"), cCheque);
402
        this.infosCheque.add(new JLabel("Daté du"), cCheque);
403
        cCheque.gridx++;
403
        cCheque.gridx++;
404
 
404
 
405
        this.infosCheque.add(this.dateCheque, cCheque);
405
        this.infosCheque.add(this.dateCheque, cCheque);
406
 
406
 
407
        final JLabel labelDepot = new JLabel("A déposer après le");
407
        final JLabel labelDepot = new JLabel("A déposer après le");
408
        cCheque.gridx++;
408
        cCheque.gridx++;
409
        DefaultGridBagConstraints.lockMinimumSize(this.infosCheque);
409
        DefaultGridBagConstraints.lockMinimumSize(this.infosCheque);
410
        this.infosCheque.add(labelDepot, cCheque);
410
        this.infosCheque.add(labelDepot, cCheque);
411
 
411
 
412
        cCheque.gridx++;
412
        cCheque.gridx++;
413
        this.infosCheque.add(this.dateDepot, cCheque);
413
        this.infosCheque.add(this.dateDepot, cCheque);
414
        this.m.put(Mode.CHEQUE, this.infosCheque);
414
        this.m.put(Mode.CHEQUE, this.infosCheque);
415
        this.infosCheque.setVisible(false);
415
        this.infosCheque.setVisible(false);
416
        this.infosCheque.setOpaque(false);
416
        this.infosCheque.setOpaque(false);
417
        DefaultGridBagConstraints.lockMinimumSize(this.infosCheque);
417
        DefaultGridBagConstraints.lockMinimumSize(this.infosCheque);
418
    }
418
    }
419
 
419
 
420
    public void createPanelVirementComptant() {
420
    public void createPanelVirementComptant() {
421
        // this.infosVirt.setBorder(BorderFactory.createTitledBorder("Informations Virement"));
421
        // this.infosVirt.setBorder(BorderFactory.createTitledBorder("Informations Virement"));
422
        final GridBagConstraints cCheque = new DefaultGridBagConstraints();
422
        final GridBagConstraints cCheque = new DefaultGridBagConstraints();
423
        cCheque.weightx = 1;
423
        cCheque.weightx = 1;
424
        this.infosVirt.add(new JLabel("Libellé"), cCheque);
424
        this.infosVirt.add(new JLabel("Libellé"), cCheque);
425
        cCheque.gridx++;
425
        cCheque.gridx++;
426
 
426
 
427
        this.infosVirt.add(this.nom, cCheque);
427
        this.infosVirt.add(this.nom, cCheque);
428
        cCheque.gridy++;
428
        cCheque.gridy++;
429
        cCheque.gridx = 0;
429
        cCheque.gridx = 0;
430
        cCheque.fill = GridBagConstraints.NONE;
430
        cCheque.fill = GridBagConstraints.NONE;
431
        cCheque.weightx = 0;
431
        cCheque.weightx = 0;
432
        this.infosVirt.add(new JLabel("Daté du"), cCheque);
432
        this.infosVirt.add(new JLabel("Daté du"), cCheque);
433
        cCheque.gridx++;
433
        cCheque.gridx++;
434
 
434
 
435
        this.infosVirt.add(this.dateVirt, cCheque);
435
        this.infosVirt.add(this.dateVirt, cCheque);
436
        this.m.put(Mode.VIREMENT, this.infosVirt);
436
        this.m.put(Mode.VIREMENT, this.infosVirt);
437
        this.infosVirt.setVisible(false);
437
        this.infosVirt.setVisible(false);
438
        DefaultGridBagConstraints.lockMinimumSize(this.infosVirt);
438
        DefaultGridBagConstraints.lockMinimumSize(this.infosVirt);
439
    }
439
    }
440
 
440
 
441
    private void updatePanel() {
441
    private void updatePanel() {
442
        final Integer typeReglt = this.comboTypeReglement.getValue();
442
        final Integer typeReglt = this.comboTypeReglement.getValue();
443
        if (typeReglt == null)
443
        if (typeReglt == null)
444
            return;
444
            return;
445
        final boolean comptant = this.checkboxComptant.isSelected();
445
        final boolean comptant = this.checkboxComptant.isSelected();
446
 
446
 
447
        final Mode mode;
447
        final Mode mode;
448
        if (comptant && typeReglt == TypeReglementSQLElement.CHEQUE) {
448
        if (comptant && typeReglt == TypeReglementSQLElement.CHEQUE) {
449
            mode = Mode.CHEQUE;
449
            mode = Mode.CHEQUE;
450
        } else if (comptant && typeReglt == TypeReglementSQLElement.TRAITE) {
450
        } else if (comptant && typeReglt == TypeReglementSQLElement.TRAITE) {
451
            mode = Mode.VIREMENT;
451
            mode = Mode.VIREMENT;
452
        } else {
452
        } else {
453
            mode = Mode.ECHEANCE;
453
            mode = Mode.ECHEANCE;
454
        }
454
        }
455
        replacePanel(mode);
455
        replacePanel(mode);
456
    }
456
    }
457
 
457
 
458
    private void replacePanel(final Mode mode) {
458
    private void replacePanel(final Mode mode) {
459
        final JPanel panel = this.m.get(mode);
459
        final JPanel panel = this.m.get(mode);
460
        if (panel != this.panelActive) {
460
        if (panel != this.panelActive) {
461
            // System.err.println("replace panel " + mode);
461
            // System.err.println("replace panel " + mode);
462
            this.panelActive.setVisible(false);
462
            this.panelActive.setVisible(false);
463
            panel.setVisible(true);
463
            panel.setVisible(true);
464
            this.panelActive = panel;
464
            this.panelActive = panel;
465
        }
465
        }
466
    }
466
    }
467
 
467
 
468
    private void fireBanqueIdChange(final int id) {
468
    private void fireBanqueIdChange(final int id) {
469
        final BanqueModifiedListener[] l = this.banqueModifiedListenerList.getListeners(BanqueModifiedListener.class);
469
        final BanqueModifiedListener[] l = this.banqueModifiedListenerList.getListeners(BanqueModifiedListener.class);
470
        for (final BanqueModifiedListener banqueModifiedListener : l) {
470
        for (final BanqueModifiedListener banqueModifiedListener : l) {
471
            banqueModifiedListener.idChange(id);
471
            banqueModifiedListener.idChange(id);
472
        }
472
        }
473
    }
473
    }
474
 
474
 
475
    // Active/Desactive le panel pour specifie la date d'echeance
475
    // Active/Desactive le panel pour specifie la date d'echeance
476
    private void setEcheanceEnabled(final boolean b) {
476
    private void setEcheanceEnabled(final boolean b) {
477
        // System.err.println("set echeance to " + b);
477
        // System.err.println("set echeance to " + b);
478
        this.allowEditable(this.getView(this.comboA), b);
478
        this.allowEditable(this.getView(this.comboA), b);
479
        this.allowEditable(this.getView(this.comboLe), b && this.buttonLe.isSelected());
479
        this.allowEditable(this.getView(this.comboLe), b && this.buttonLe.isSelected());
480
        this.allowEditable(this.getView(this.buttonFinMois), b);
480
        this.allowEditable(this.getView(this.buttonFinMois), b);
481
        this.allowEditable(this.getView(this.buttonDateFacture), b);
481
        this.allowEditable(this.getView(this.buttonDateFacture), b);
482
        this.buttonLe.setEnabled(b);
482
        this.buttonLe.setEnabled(b);
483
        if (!b) {
483
        if (!b) {
484
            this.comboA.setValue("0");
484
            this.comboA.setValue("0");
485
            this.buttonDateFacture.setSelected(true);
485
            this.buttonDateFacture.setSelected(true);
486
        } else {
486
        } else {
487
            // TODO factor with createDefaults()
487
            // TODO factor with createDefaults()
488
            this.comboA.setValue("30");
488
            this.comboA.setValue("30");
489
            this.buttonFinMois.setSelected(true);
489
            this.buttonFinMois.setSelected(true);
490
        }
490
        }
491
 
491
 
492
        updatePanel();
492
        updatePanel();
493
    }
493
    }
494
 
494
 
495
    // ATTN sometimes overwritten by ModeReglementDefautPrefPanel.getDefaultRow(true);
495
    // ATTN sometimes overwritten by ModeReglementDefautPrefPanel.getDefaultRow(true);
496
    @Override
496
    @Override
497
    protected SQLRowValues createDefaults() {
497
    protected SQLRowValues createDefaults() {
498
        final SQLRowValues vals = new SQLRowValues(getTable());
498
        final SQLRowValues vals = new SQLRowValues(getTable());
499
        vals.put("COMPTANT", Boolean.FALSE);
499
        vals.put("COMPTANT", Boolean.FALSE);
500
        vals.put("AJOURS", 30);
500
        vals.put("AJOURS", 30);
501
        vals.put("FIN_MOIS", Boolean.TRUE);
501
        vals.put("FIN_MOIS", Boolean.TRUE);
502
        return vals;
502
        return vals;
503
    }
503
    }
504
 
504
 
505
    public void setWhereBanque(final Where w) {
505
    public void setWhereBanque(final Where w) {
506
        if (this.boxBanque != null && this.boxBanque.isShowing()) {
506
        if (this.boxBanque != null && this.boxBanque.isShowing()) {
507
            final ComboSQLRequest request = this.boxBanque.getRequest();
507
            final ComboSQLRequest request = this.boxBanque.getRequest();
508
            if (request != null) {
508
            if (request != null) {
509
                request.setWhere(w);
509
                request.setWhere(w);
510
                this.boxBanque.fillCombo();
510
                this.boxBanque.fillCombo();
511
            }
511
            }
512
        }
512
        }
513
    }
513
    }
514
 
514
 
515
    public void setSelectedIdBanque(final int id) {
515
    public void setSelectedIdBanque(final int id) {
516
        this.boxBanque.setValue(id);
516
        this.boxBanque.setValue(id);
517
    }
517
    }
518
 
518
 
519
    public int getSelectedIdBanque() {
519
    public int getSelectedIdBanque() {
520
        return this.boxBanque.getSelectedId();
520
        return this.boxBanque.getSelectedId();
521
    }
521
    }
522
 
522
 
523
    public void addBanqueModifiedListener(final BanqueModifiedListener e) {
523
    public void addBanqueModifiedListener(final BanqueModifiedListener e) {
524
        this.banqueModifiedListenerList.add(BanqueModifiedListener.class, e);
524
        this.banqueModifiedListenerList.add(BanqueModifiedListener.class, e);
525
    }
525
    }
526
}
526
}