OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 177 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.account;
14
 package org.openconcerto.erp.core.sales.account;
15
 
15
 
16
import org.openconcerto.erp.core.common.component.TransfertGroupSQLComponent;
16
import org.openconcerto.erp.core.common.component.TransfertGroupSQLComponent;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
17
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
18
import org.openconcerto.erp.core.common.ui.AbstractArticleItemTable;
18
import org.openconcerto.erp.core.common.ui.AbstractArticleItemTable;
19
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable.TypeCalcul;
19
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable.TypeCalcul;
20
import org.openconcerto.erp.core.common.ui.Acompte;
20
import org.openconcerto.erp.core.common.ui.Acompte;
21
import org.openconcerto.erp.core.common.ui.AcompteField;
21
import org.openconcerto.erp.core.common.ui.AcompteField;
22
import org.openconcerto.erp.core.common.ui.AcompteRowItemView;
22
import org.openconcerto.erp.core.common.ui.AcompteRowItemView;
23
import org.openconcerto.erp.core.common.ui.DeviseField;
23
import org.openconcerto.erp.core.common.ui.DeviseField;
24
import org.openconcerto.erp.core.common.ui.TotalPanel;
24
import org.openconcerto.erp.core.common.ui.TotalPanel;
25
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType;
25
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType;
26
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
26
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
27
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
27
import org.openconcerto.erp.core.sales.invoice.element.SaisieVenteFactureSQLElement;
28
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
28
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet;
29
import org.openconcerto.erp.core.sales.invoice.ui.FactureSituationItemTable;
29
import org.openconcerto.erp.core.sales.invoice.ui.FactureSituationItemTable;
30
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
30
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture;
31
import org.openconcerto.erp.panel.PanelOOSQLComponent;
31
import org.openconcerto.erp.panel.PanelOOSQLComponent;
32
import org.openconcerto.sql.Configuration;
32
import org.openconcerto.sql.Configuration;
33
import org.openconcerto.sql.element.ElementSQLObject;
33
import org.openconcerto.sql.element.ElementSQLObject;
34
import org.openconcerto.sql.element.GlobalMapper;
34
import org.openconcerto.sql.element.GlobalMapper;
35
import org.openconcerto.sql.element.SQLElement;
35
import org.openconcerto.sql.element.SQLElement;
36
import org.openconcerto.sql.model.SQLRow;
36
import org.openconcerto.sql.model.SQLRow;
37
import org.openconcerto.sql.model.SQLRowAccessor;
37
import org.openconcerto.sql.model.SQLRowAccessor;
38
import org.openconcerto.sql.model.SQLRowValues;
38
import org.openconcerto.sql.model.SQLRowValues;
39
import org.openconcerto.sql.model.SQLTable;
39
import org.openconcerto.sql.model.SQLTable;
40
import org.openconcerto.sql.model.Where;
40
import org.openconcerto.sql.model.Where;
41
import org.openconcerto.sql.sqlobject.ElementComboBox;
41
import org.openconcerto.sql.sqlobject.ElementComboBox;
42
import org.openconcerto.sql.sqlobject.JUniqueTextField;
42
import org.openconcerto.sql.sqlobject.JUniqueTextField;
43
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
43
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
44
import org.openconcerto.sql.view.EditFrame;
44
import org.openconcerto.sql.view.EditFrame;
45
import org.openconcerto.sql.view.list.RowValuesTable;
45
import org.openconcerto.sql.view.list.RowValuesTable;
46
import org.openconcerto.sql.view.list.SQLTableElement;
46
import org.openconcerto.sql.view.list.SQLTableElement;
47
import org.openconcerto.ui.JDate;
47
import org.openconcerto.ui.JDate;
48
import org.openconcerto.ui.component.ITextArea;
48
import org.openconcerto.ui.component.ITextArea;
49
import org.openconcerto.ui.group.Group;
49
import org.openconcerto.ui.group.Group;
50
import org.openconcerto.utils.ExceptionHandler;
50
import org.openconcerto.utils.ExceptionHandler;
51
import org.openconcerto.utils.text.SimpleDocumentListener;
51
import org.openconcerto.utils.text.SimpleDocumentListener;
52
 
52
 
53
import java.awt.Component;
53
import java.awt.Component;
54
import java.beans.PropertyChangeEvent;
54
import java.beans.PropertyChangeEvent;
55
import java.beans.PropertyChangeListener;
55
import java.beans.PropertyChangeListener;
56
import java.math.BigDecimal;
56
import java.math.BigDecimal;
57
import java.sql.SQLException;
57
import java.sql.SQLException;
58
import java.util.Date;
58
import java.util.Date;
59
import java.util.HashSet;
59
import java.util.HashSet;
60
import java.util.Set;
60
import java.util.Set;
61
 
61
 
62
import javax.swing.JCheckBox;
62
import javax.swing.JCheckBox;
63
import javax.swing.JComponent;
63
import javax.swing.JComponent;
64
import javax.swing.JLabel;
64
import javax.swing.JLabel;
65
import javax.swing.JOptionPane;
65
import javax.swing.JOptionPane;
66
import javax.swing.JTextField;
66
import javax.swing.JTextField;
67
import javax.swing.SwingConstants;
67
import javax.swing.SwingConstants;
68
import javax.swing.SwingUtilities;
68
import javax.swing.SwingUtilities;
69
import javax.swing.event.DocumentEvent;
69
import javax.swing.event.DocumentEvent;
70
import javax.swing.event.TableModelEvent;
70
import javax.swing.event.TableModelEvent;
71
import javax.swing.event.TableModelListener;
71
import javax.swing.event.TableModelListener;
72
 
72
 
73
public class VenteFactureSituationSQLComponent extends TransfertGroupSQLComponent {
73
public class VenteFactureSituationSQLComponent extends TransfertGroupSQLComponent {
74
    public static final String ID = "sales.invoice.partial";
74
    public static final String ID = "sales.invoice.partial";
75
 
75
 
76
    private PanelOOSQLComponent panelOO;
76
    private PanelOOSQLComponent panelOO;
77
 
77
 
78
    public VenteFactureSituationSQLComponent(SQLElement element) {
78
    public VenteFactureSituationSQLComponent(SQLElement element) {
79
        super(element, (Group) GlobalMapper.getInstance().get(ID));
79
        super(element, (Group) GlobalMapper.getInstance().get(ID));
80
    }
80
    }
81
 
81
 
82
    public VenteFactureSituationSQLComponent(SQLElement element, Group p) {
82
    public VenteFactureSituationSQLComponent(SQLElement element, Group p) {
83
        super(element, p);
83
        super(element, p);
84
    }
84
    }
85
 
85
 
86
    @Override
86
    @Override
87
    protected Set<String> createRequiredNames() {
87
    protected Set<String> createRequiredNames() {
88
        final Set<String> s = new HashSet<String>(1);
88
        final Set<String> s = new HashSet<String>(1);
89
        s.add("ID_CLIENT");
89
        s.add("ID_CLIENT");
90
        s.add("ID_COMMERCIAL");
90
        s.add("ID_COMMERCIAL");
91
        s.add("NUMERO");
91
        s.add("NUMERO");
92
        s.add("DATE");
92
        s.add("DATE");
93
        s.add("MONTANT_FACTURABLE");
93
        s.add("MONTANT_FACTURABLE");
94
        s.add("ID_MODE_REGLEMENT");
94
        s.add("ID_MODE_REGLEMENT");
95
        return s;
95
        return s;
96
    }
96
    }
97
 
97
 
98
    @Override
98
    @Override
99
    protected RowValuesTable getRowValuesTable() {
99
    protected RowValuesTable getRowValuesTable() {
100
 
100
 
101
        return ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).getRowValuesTable();
101
        return ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).getRowValuesTable();
102
    }
102
    }
103
 
103
 
104
    JCheckBox box = new JCheckBox("partial");
104
    JCheckBox box = new JCheckBox("partial");
105
 
105
 
106
    @Override
106
    @Override
107
    public void select(SQLRowAccessor r) {
107
    public void select(SQLRowAccessor r) {
108
        super.select(r);
108
        super.select(r);
109
        final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
109
        final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
110
        totalRemise.setEditable(false);
110
        totalRemise.setEditable(false);
111
        totalRemise.setEnabled(false);
111
        totalRemise.setEnabled(false);
112
    }
112
    }
113
 
113
 
114
    @Override
114
    @Override
115
    protected void addViews() {
115
    protected void addViews() {
116
 
116
 
117
        super.addViews();
117
        super.addViews();
118
 
118
 
119
        box.setSelected(true);
119
        box.setSelected(true);
120
        this.addView(box, "PARTIAL", REQ);
120
        this.addView(box, "PARTIAL", REQ);
121
 
121
 
122
        final DeviseField totalHT = (DeviseField) getEditor("T_HT");
122
        final DeviseField totalHT = (DeviseField) getEditor("T_HT");
123
        final DeviseField totalService = (DeviseField) getEditor("T_SERVICE");
123
        final DeviseField totalService = (DeviseField) getEditor("T_SERVICE");
124
        final DeviseField totalSupply = (DeviseField) getEditor("T_HA");
124
        final DeviseField totalSupply = (DeviseField) getEditor("T_HA");
125
        final DeviseField totalDevise = (DeviseField) getEditor("T_DEVISE");
125
        final DeviseField totalDevise = (DeviseField) getEditor("T_DEVISE");
126
        final JTextField totalWeight = (JTextField) getEditor("T_POIDS");
126
        final JTextField totalWeight = (JTextField) getEditor("T_POIDS");
127
        final DeviseField totalTTC = (DeviseField) getEditor("T_TTC");
127
        final DeviseField totalTTC = (DeviseField) getEditor("T_TTC");
128
        final DeviseField totalTVA = (DeviseField) getEditor("T_TVA");
128
        final DeviseField totalTVA = (DeviseField) getEditor("T_TVA");
129
        final DeviseField totalEco = (DeviseField) getEditor("T_ECO_CONTRIBUTION");
129
        final DeviseField totalEco = (DeviseField) getEditor("T_ECO_CONTRIBUTION");
130
        final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
130
        final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
131
        totalRemise.setEditable(false);
131
        totalRemise.setEditable(false);
132
        totalRemise.setEnabled(false);
132
        totalRemise.setEnabled(false);
133
        final DeviseField totalPORT = (DeviseField) getEditor("PORT_HT");
133
        final DeviseField totalPORT = (DeviseField) getEditor("PORT_HT");
134
        this.addView(totalPORT, "PORT_HT");
134
        this.addView(totalPORT, "PORT_HT");
135
        this.addView(totalTVA, "T_TVA");
135
        this.addView(totalTVA, "T_TVA");
136
        this.addView(totalTTC, "T_TTC");
136
        this.addView(totalTTC, "T_TTC");
137
        this.addView(totalEco, "T_ECO_CONTRIBUTION");
137
        this.addView(totalEco, "T_ECO_CONTRIBUTION");
138
        this.addView(totalWeight, "T_POIDS");
138
        this.addView(totalWeight, "T_POIDS");
139
        this.addView(totalDevise, "T_DEVISE");
139
        this.addView(totalDevise, "T_DEVISE");
140
        this.addView(totalSupply, "T_HA");
140
        this.addView(totalSupply, "T_HA");
141
        this.addView(totalService, "T_SERVICE");
141
        this.addView(totalService, "T_SERVICE");
142
        this.addView(totalHT, "T_HT");
142
        this.addView(totalHT, "T_HT");
143
 
143
 
144
        final DeviseField fieldNet = new DeviseField();
144
        final DeviseField fieldNet = new DeviseField();
145
        this.addView(fieldNet, "NET_A_PAYER");
145
        this.addView(fieldNet, "NET_A_PAYER");
146
        totalTTC.getDocument().addDocumentListener(new SimpleDocumentListener() {
146
        totalTTC.getDocument().addDocumentListener(new SimpleDocumentListener() {
147
 
147
 
148
            @Override
148
            @Override
149
            public void update(DocumentEvent e) {
149
            public void update(DocumentEvent e) {
150
                fieldNet.setText(totalTTC.getText());
150
                fieldNet.setText(totalTTC.getText());
151
            }
151
            }
152
        });
152
        });
153
 
153
 
154
        final SQLRequestComboBox sqlRequestComboBoxAdr = (SQLRequestComboBox) getEditor("ID_ADRESSE");
154
        final SQLRequestComboBox sqlRequestComboBoxAdr = (SQLRequestComboBox) getEditor("ID_ADRESSE");
155
        final SQLRequestComboBox sqlRequestComboBoxAdrL = (SQLRequestComboBox) getEditor("ID_ADRESSE_LIVRAISON");
155
        final SQLRequestComboBox sqlRequestComboBoxAdrL = (SQLRequestComboBox) getEditor("ID_ADRESSE_LIVRAISON");
156
 
156
 
157
        final SQLRequestComboBox sqlRequestComboBox = (SQLRequestComboBox) getEditor("sales.invoice.customer");
157
        final SQLRequestComboBox sqlRequestComboBox = (SQLRequestComboBox) getEditor("sales.invoice.customer");
158
        final FactureSituationItemTable table = ((FactureSituationItemTable) getEditor("sales.invoice.partial.items.list"));
158
        final FactureSituationItemTable table = ((FactureSituationItemTable) getEditor("sales.invoice.partial.items.list"));
159
        final TotalPanel total = ((TotalPanel) getEditor("sales.invoice.partial.total.amount"));
159
        final TotalPanel total = ((TotalPanel) getEditor("sales.invoice.partial.total.amount"));
160
 
160
 
161
        sqlRequestComboBox.addModelListener("wantedID", new PropertyChangeListener() {
161
        sqlRequestComboBox.addModelListener("wantedID", new PropertyChangeListener() {
162
 
162
 
163
            @Override
163
            @Override
164
            public void propertyChange(PropertyChangeEvent evt) {
164
            public void propertyChange(PropertyChangeEvent evt) {
165
 
165
 
166
                int wantedID = sqlRequestComboBox.getWantedID();
166
                int wantedID = sqlRequestComboBox.getWantedID();
167
 
167
 
168
                if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
168
                if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
169
 
169
 
170
                    sqlRequestComboBoxAdr.getRequest().setWhere(new Where(getTable().getTable("ADRESSE").getField("ID_CLIENT"), "=", wantedID)
170
                    sqlRequestComboBoxAdr.getRequest().setWhere(new Where(getTable().getTable("ADRESSE").getField("ID_CLIENT"), "=", wantedID)
171
                            .and(new Where(getTable().getTable("ADRESSE").getField("TYPE"), "=", AdresseType.Invoice.getId())));
171
                            .and(new Where(getTable().getTable("ADRESSE").getField("TYPE"), "=", AdresseType.Invoice.getId())));
172
                    sqlRequestComboBoxAdrL.getRequest().setWhere(new Where(getTable().getTable("ADRESSE").getField("ID_CLIENT"), "=", wantedID)
172
                    sqlRequestComboBoxAdrL.getRequest().setWhere(new Where(getTable().getTable("ADRESSE").getField("ID_CLIENT"), "=", wantedID)
173
                            .and(new Where(getTable().getTable("ADRESSE").getField("TYPE"), "=", AdresseType.Delivery.getId())));
173
                            .and(new Where(getTable().getTable("ADRESSE").getField("TYPE"), "=", AdresseType.Delivery.getId())));
174
                    SQLRow rowCli = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
174
                    SQLRow rowCli = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
175
                    if (rowCli.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowCli.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
175
                    if (rowCli.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowCli.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
176
                        total.setCategorieComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
176
                        total.setCategorieComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
177
                        table.setRowCatComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
177
                        table.setRowCatComptable(rowCli.getForeign("ID_CATEGORIE_COMPTABLE"));
178
                    } else {
178
                    } else {
179
                        total.setCategorieComptable(null);
179
                        total.setCategorieComptable(null);
180
                        table.setRowCatComptable(null);
180
                        table.setRowCatComptable(null);
181
                    }
181
                    }
182
                } else {
182
                } else {
183
                    sqlRequestComboBoxAdr.getRequest().setWhere(Where.FALSE);
183
                    sqlRequestComboBoxAdr.getRequest().setWhere(Where.FALSE);
184
                    sqlRequestComboBoxAdrL.getRequest().setWhere(Where.FALSE);
184
                    sqlRequestComboBoxAdrL.getRequest().setWhere(Where.FALSE);
185
                    total.setCategorieComptable(null);
185
                    total.setCategorieComptable(null);
186
                    table.setRowCatComptable(null);
186
                    table.setRowCatComptable(null);
187
                }
187
                }
188
 
188
 
189
                SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
189
                SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
190
                final SQLRow client = sqlRequestComboBox.getSelectedRow();
190
                final SQLRow client = sqlRequestComboBox.getSelectedRow();
191
                if (client != null && !client.isUndefined()) {
191
                if (client != null && !client.isUndefined()) {
192
                    int idModeRegl = client.getInt("ID_MODE_REGLEMENT");
192
                    int idModeRegl = client.getInt("ID_MODE_REGLEMENT");
193
                    if (idModeRegl > 1) {
193
                    if (idModeRegl > 1) {
194
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
194
                        SQLRow rowModeRegl = sqleltModeRegl.getTable().getRow(idModeRegl);
195
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
195
                        SQLRowValues rowValsModeRegl = rowModeRegl.createUpdateRow();
196
                        rowValsModeRegl.clearPrimaryKeys();
196
                        rowValsModeRegl.clearPrimaryKeys();
197
                        ((ElementSQLObject) getEditor("ID_MODE_REGLEMENT")).setValue(rowValsModeRegl);
197
                        ((ElementSQLObject) getEditor("ID_MODE_REGLEMENT")).setValue(rowValsModeRegl);
198
                    }
198
                    }
199
                }
199
                }
200
 
200
 
201
            }
201
            }
202
        });
202
        });
203
        sqlRequestComboBox.setEnabled(false);
203
        sqlRequestComboBox.setEnabled(false);
204
 
204
 
205
        final AcompteField acompteField = ((AcompteField) getEditor("sales.invoice.partial.amount"));
205
        final AcompteField acompteField = ((AcompteField) getEditor("sales.invoice.partial.amount"));
206
        listenerAcompteField = new SimpleDocumentListener() {
206
        listenerAcompteField = new SimpleDocumentListener() {
207
 
207
 
208
            @Override
208
            @Override
209
            public void update(DocumentEvent e) {
209
            public void update(DocumentEvent e) {
-
 
210
                if (!isFilling()) {
210
                Acompte a = acompteField.getValue();
211
                    Acompte a = acompteField.getValue();
211
                table.calculPourcentage(a, TypeCalcul.CALCUL_FACTURABLE);
212
                    table.calculPourcentage(a, TypeCalcul.CALCUL_FACTURABLE);
212
            }
213
                }
-
 
214
            }
213
 
215
 
214
        };
216
        };
215
        acompteField.getDocument().addDocumentListener(listenerAcompteField);
217
        acompteField.getDocument().addDocumentListener(listenerAcompteField);
216
 
218
 
217
        listenerTable = new TableModelListener() {
219
        listenerTable = new TableModelListener() {
218
 
220
 
219
            @Override
221
            @Override
220
            public void tableChanged(TableModelEvent e) {
222
            public void tableChanged(TableModelEvent e) {
221
                acompteField.getDocument().removeDocumentListener(listenerAcompteField);
223
                acompteField.getDocument().removeDocumentListener(listenerAcompteField);
222
                if (e.getColumn() == table.getModel().getColumnForField("POURCENT_FACTURABLE")) {
224
                if (e.getColumn() == table.getModel().getColumnForField("POURCENT_FACTURABLE")) {
223
                    Acompte a = new Acompte(null, table.getTotalHT(TypeCalcul.CALCUL_MONTANT_TOTAL));
225
                    Acompte a = new Acompte(null, table.getTotalHT(TypeCalcul.CALCUL_MONTANT_TOTAL));
224
                    acompteField.setValue(a);
226
                    acompteField.setValue(a);
225
 
227
 
226
                }
228
                }
227
                acompteField.getDocument().addDocumentListener(listenerAcompteField);
229
                acompteField.getDocument().addDocumentListener(listenerAcompteField);
228
            }
230
            }
229
 
231
 
230
        };
232
        };
231
        table.getRowValuesTable().getModel().addTableModelListener(listenerTable);
233
        table.getRowValuesTable().getModel().addTableModelListener(listenerTable);
232
        total.addValueListener(new PropertyChangeListener() {
234
        total.addValueListener(new PropertyChangeListener() {
233
 
235
 
234
            @Override
236
            @Override
235
            public void propertyChange(PropertyChangeEvent evt) {
237
            public void propertyChange(PropertyChangeEvent evt) {
236
                acompteField.setTotal(new BigDecimal(total.getTotalHT()).movePointLeft(2));
238
                acompteField.setTotal(new BigDecimal(total.getTotalHT()).movePointLeft(2));
237
 
239
 
238
            }
240
            }
239
        });
241
        });
240
 
242
 
241
    }
243
    }
242
 
244
 
243
    private SimpleDocumentListener listenerAcompteField;
245
    private SimpleDocumentListener listenerAcompteField;
244
    private TableModelListener listenerTable;
246
    private TableModelListener listenerTable;
245
 
247
 
246
    @Override
248
    @Override
247
    public JComponent getLabel(String id) {
249
    public JComponent getLabel(String id) {
248
        if (id.equals("sales.invoice.partial.amount")) {
250
        if (id.equals("sales.invoice.partial.amount")) {
249
            final JLabel jLabel = new JLabel("Montant HT (ou %) à facturer");
251
            final JLabel jLabel = new JLabel("Montant HT (ou %) à facturer");
250
            jLabel.setHorizontalAlignment(SwingConstants.RIGHT);
252
            jLabel.setHorizontalAlignment(SwingConstants.RIGHT);
251
            return jLabel;
253
            return jLabel;
252
        } else if (id.equals("panel.oo")) {
254
        } else if (id.equals("panel.oo")) {
253
            return new JLabel();
255
            return new JLabel();
254
        } else if (id.equals("sales.invoice.partial.total.amount")) {
256
        } else if (id.equals("sales.invoice.partial.total.amount")) {
255
            return new JLabel();
257
            return new JLabel();
256
        } else {
258
        } else {
257
            return super.getLabel(id);
259
            return super.getLabel(id);
258
        }
260
        }
259
    }
261
    }
260
 
262
 
261
    JUniqueTextField numberField;
263
    JUniqueTextField numberField;
262
 
264
 
263
    @Override
265
    @Override
264
    public JComponent createEditor(String id) {
266
    public JComponent createEditor(String id) {
265
 
267
 
266
        if (id.equals("sales.invoice.number")) {
268
        if (id.equals("sales.invoice.number")) {
267
            this.numberField = new JUniqueTextField(20) {
269
            this.numberField = new JUniqueTextField(20) {
268
                @Override
270
                @Override
269
                public String getAutoRefreshNumber() {
271
                public String getAutoRefreshNumber() {
270
                    if (getMode() == Mode.INSERTION) {
272
                    if (getMode() == Mode.INSERTION) {
271
                        return NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), ((JDate) getEditor("DATE")).getDate());
273
                        return NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), ((JDate) getEditor("DATE")).getDate());
272
                    } else {
274
                    } else {
273
                        return null;
275
                        return null;
274
                    }
276
                    }
275
                }
277
                }
276
            };
278
            };
277
            return this.numberField;
279
            return this.numberField;
278
        } else if (id.equals("panel.oo")) {
280
        } else if (id.equals("panel.oo")) {
279
            this.panelOO = new PanelOOSQLComponent(this);
281
            this.panelOO = new PanelOOSQLComponent(this);
280
            return this.panelOO;
282
            return this.panelOO;
281
        } else if (id.equals("INFOS")) {
283
        } else if (id.equals("INFOS")) {
282
            final ITextArea jTextArea = new ITextArea();
284
            final ITextArea jTextArea = new ITextArea();
283
            jTextArea.setFont(new JLabel().getFont());
285
            jTextArea.setFont(new JLabel().getFont());
284
            return jTextArea;
286
            return jTextArea;
285
        } else if (id.equals("sales.invoice.partial.items.list")) {
287
        } else if (id.equals("sales.invoice.partial.items.list")) {
286
            return new FactureSituationItemTable();
288
            return new FactureSituationItemTable();
287
        } else if (id.equals("DATE")) {
289
        } else if (id.equals("DATE")) {
288
            return new JDate(true);
290
            return new JDate(true);
289
        } else if (id.equals("T_POIDS")) {
291
        } else if (id.equals("T_POIDS")) {
290
            return new JTextField();
292
            return new JTextField();
291
        } else if (id.equals("sales.invoice.partial.total.amount")) {
293
        } else if (id.equals("sales.invoice.partial.total.amount")) {
292
            final AbstractArticleItemTable items = (AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list");
294
            final AbstractArticleItemTable items = (AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list");
293
            // Set only VAT Editable
295
            // Set only VAT Editable
294
            for (int i = 0; i < items.getRowValuesTable().getColumnModel().getColumnCount(false); i++) {
296
            for (int i = 0; i < items.getRowValuesTable().getColumnModel().getColumnCount(false); i++) {
295
                final SQLTableElement sqlTableElementAt = items.getRowValuesTable().getRowValuesTableModel().getSQLTableElementAt(i);
297
                final SQLTableElement sqlTableElementAt = items.getRowValuesTable().getRowValuesTableModel().getSQLTableElementAt(i);
296
                if (sqlTableElementAt.getField() != null && (sqlTableElementAt.getField().getName().equalsIgnoreCase("ID_STYLE")
298
                if (sqlTableElementAt.getField() != null && (sqlTableElementAt.getField().getName().equalsIgnoreCase("ID_STYLE")
297
                        || sqlTableElementAt.getField().getName().equalsIgnoreCase("POURCENT_FACTURABLE") || sqlTableElementAt.getField().getName().equalsIgnoreCase("ID_TAXE"))) {
299
                        || sqlTableElementAt.getField().getName().equalsIgnoreCase("POURCENT_FACTURABLE") || sqlTableElementAt.getField().getName().equalsIgnoreCase("ID_TAXE"))) {
298
                    sqlTableElementAt.setEditable(true);
300
                    sqlTableElementAt.setEditable(true);
299
                } else {
301
                } else {
300
                    sqlTableElementAt.setEditable(false);
302
                    sqlTableElementAt.setEditable(false);
301
                }
303
                }
302
            }
304
            }
303
 
305
 
304
            final DeviseField totalHT = (DeviseField) getEditor("T_HT");
306
            final DeviseField totalHT = (DeviseField) getEditor("T_HT");
305
            final DeviseField totalEco = (DeviseField) getEditor("T_ECO_CONTRIBUTION");
307
            final DeviseField totalEco = (DeviseField) getEditor("T_ECO_CONTRIBUTION");
306
            final DeviseField totalService = (DeviseField) getEditor("T_SERVICE");
308
            final DeviseField totalService = (DeviseField) getEditor("T_SERVICE");
307
            final DeviseField totalSupply = (DeviseField) getEditor("T_HA");
309
            final DeviseField totalSupply = (DeviseField) getEditor("T_HA");
308
            final DeviseField totalDevise = (DeviseField) getEditor("T_DEVISE");
310
            final DeviseField totalDevise = (DeviseField) getEditor("T_DEVISE");
309
            final JTextField totalWeight = (JTextField) getEditor("T_POIDS");
311
            final JTextField totalWeight = (JTextField) getEditor("T_POIDS");
310
            final DeviseField totalTTC = (DeviseField) getEditor("T_TTC");
312
            final DeviseField totalTTC = (DeviseField) getEditor("T_TTC");
311
            final DeviseField totalTVA = (DeviseField) getEditor("T_TVA");
313
            final DeviseField totalTVA = (DeviseField) getEditor("T_TVA");
312
            final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
314
            final DeviseField totalRemise = (DeviseField) getEditor("REMISE_HT");
313
            totalRemise.setEditable(false);
315
            totalRemise.setEditable(false);
314
            totalRemise.setEnabled(false);
316
            totalRemise.setEnabled(false);
315
            final AcompteField acompte = (AcompteField) getEditor("sales.invoice.partial.amount");
317
            final AcompteField acompte = (AcompteField) getEditor("sales.invoice.partial.amount");
316
            final DeviseField totalPORT = (DeviseField) getEditor("PORT_HT");
318
            final DeviseField totalPORT = (DeviseField) getEditor("PORT_HT");
317
            final SQLRequestComboBox taxePort = (SQLRequestComboBox) getEditor("ID_TAXE_PORT");
319
            final SQLRequestComboBox taxePort = (SQLRequestComboBox) getEditor("ID_TAXE_PORT");
318
            return new TotalPanel(items, totalEco, totalHT, totalTVA, totalTTC, totalPORT, totalRemise, totalService, totalSupply, totalDevise, totalWeight, null, taxePort, acompte);
320
            return new TotalPanel(items, totalEco, totalHT, totalTVA, totalTTC, totalPORT, totalRemise, totalService, totalSupply, totalDevise, totalWeight, null, taxePort, acompte);
319
        } else if (id.startsWith("T_")) {
321
        } else if (id.startsWith("T_")) {
320
            return new DeviseField();
322
            return new DeviseField();
321
        } else if (id.equals("REMISE_HT") || id.equals("PORT_HT")) {
323
        } else if (id.equals("REMISE_HT") || id.equals("PORT_HT")) {
322
            DeviseField fieldD = new DeviseField();
324
            DeviseField fieldD = new DeviseField();
323
            fieldD.setEditable(false);
325
            fieldD.setEditable(false);
324
            fieldD.setEnabled(false);
326
            fieldD.setEnabled(false);
325
            return fieldD;
327
            return fieldD;
326
        } else if (id.startsWith("ID_ADRESSE")) {
328
        } else if (id.startsWith("ID_ADRESSE")) {
327
            ElementComboBox comboAdrF = new ElementComboBox();
329
            ElementComboBox comboAdrF = new ElementComboBox();
328
            comboAdrF.setButtonsVisible(false);
330
            comboAdrF.setButtonsVisible(false);
329
            final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
331
            final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
330
            comboAdrF.init(adrElement, adrElement.getComboRequest(true));
332
            comboAdrF.init(adrElement, adrElement.getComboRequest(true));
331
            comboAdrF.getRequest().setWhere(Where.FALSE);
333
            comboAdrF.getRequest().setWhere(Where.FALSE);
332
            return comboAdrF;
334
            return comboAdrF;
333
        } else if (id.equals("sales.invoice.partial.amount")) {
335
        } else if (id.equals("sales.invoice.partial.amount")) {
334
            return new AcompteField();
336
            return new AcompteField();
335
        }
337
        }
336
        return super.createEditor(id);
338
        return super.createEditor(id);
337
    }
339
    }
338
 
340
 
339
    private final SQLTable tableNum = getElement().getTable().getTable("NUMEROTATION_AUTO");
341
    private final SQLTable tableNum = getElement().getTable().getTable("NUMEROTATION_AUTO");
340
 
342
 
341
    @Override
343
    @Override
342
    public int insert(SQLRow order) {
344
    public int insert(SQLRow order) {
343
 
345
 
344
        int idSaisieVF = SQLRow.NONEXISTANT_ID;
346
        int idSaisieVF = SQLRow.NONEXISTANT_ID;
345
 
347
 
346
        int attempt = 0;
348
        int attempt = 0;
347
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
349
        // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
348
        if (!this.numberField.checkValidation(false)) {
350
        if (!this.numberField.checkValidation(false)) {
349
            while (attempt < JUniqueTextField.RETRY_COUNT) {
351
            while (attempt < JUniqueTextField.RETRY_COUNT) {
350
                String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), ((JDate) getEditor("DATE")).getDate());
352
                String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), ((JDate) getEditor("DATE")).getDate());
351
                this.numberField.setText(num);
353
                this.numberField.setText(num);
352
                attempt++;
354
                attempt++;
353
                if (this.numberField.checkValidation(false)) {
355
                if (this.numberField.checkValidation(false)) {
354
                    System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
356
                    System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
355
                    break;
357
                    break;
356
                }
358
                }
357
                try {
359
                try {
358
                    Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
360
                    Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
359
                } catch (InterruptedException e) {
361
                } catch (InterruptedException e) {
360
                    e.printStackTrace();
362
                    e.printStackTrace();
361
                }
363
                }
362
            }
364
            }
363
        }
365
        }
364
        final String num = this.numberField.getText();
366
        final String num = this.numberField.getText();
365
        if (attempt == JUniqueTextField.RETRY_COUNT) {
367
        if (attempt == JUniqueTextField.RETRY_COUNT) {
366
            idSaisieVF = getSelectedID();
368
            idSaisieVF = getSelectedID();
367
            ExceptionHandler.handle("Impossible d'ajouter, numéro de facture existant.");
369
            ExceptionHandler.handle("Impossible d'ajouter, numéro de facture existant.");
368
            final Object root = SwingUtilities.getRoot(this);
370
            final Object root = SwingUtilities.getRoot(this);
369
            if (root instanceof EditFrame) {
371
            if (root instanceof EditFrame) {
370
                final EditFrame frame = (EditFrame) root;
372
                final EditFrame frame = (EditFrame) root;
371
                frame.getPanel().setAlwaysVisible(true);
373
                frame.getPanel().setAlwaysVisible(true);
372
            }
374
            }
373
        } else {
375
        } else {
374
            idSaisieVF = super.insert(order);
376
            idSaisieVF = super.insert(order);
375
            SQLRow rowFacture = getTable().getRow(idSaisieVF);
377
            SQLRow rowFacture = getTable().getRow(idSaisieVF);
376
            // incrémentation du numéro auto
378
            // incrémentation du numéro auto
377
            if (NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, rowFacture.getDate("DATE").getTime()).equalsIgnoreCase(this.numberField.getText().trim())) {
379
            if (NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, rowFacture.getDate("DATE").getTime()).equalsIgnoreCase(this.numberField.getText().trim())) {
378
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
380
                SQLRowValues rowVals = new SQLRowValues(this.tableNum);
379
 
381
 
380
                String labelNumberFor = NumerotationAutoSQLElement.getLabelNumberFor(SaisieVenteFactureSQLElement.class);
382
                String labelNumberFor = NumerotationAutoSQLElement.getLabelNumberFor(SaisieVenteFactureSQLElement.class);
381
                int val = this.tableNum.getRow(2).getInt(labelNumberFor);
383
                int val = this.tableNum.getRow(2).getInt(labelNumberFor);
382
                val++;
384
                val++;
383
                rowVals.put(labelNumberFor, Integer.valueOf(val));
385
                rowVals.put(labelNumberFor, Integer.valueOf(val));
384
                try {
386
                try {
385
                    rowVals.update(2);
387
                    rowVals.update(2);
386
                } catch (SQLException e1) {
388
                } catch (SQLException e1) {
387
                    e1.printStackTrace();
389
                    e1.printStackTrace();
388
                }
390
                }
389
            }
391
            }
390
            ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).updateField("ID_SAISIE_VENTE_FACTURE", idSaisieVF);
392
            ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).updateField("ID_SAISIE_VENTE_FACTURE", idSaisieVF);
391
 
393
 
392
            new GenerationMvtSaisieVenteFacture(idSaisieVF);
394
            new GenerationMvtSaisieVenteFacture(idSaisieVF);
393
 
395
 
394
            try {
396
            try {
395
                VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
397
                VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
396
                sheet.createDocument();
398
                sheet.createDocument();
397
                sheet.showPrintAndExport(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
399
                sheet.showPrintAndExport(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
398
            } catch (Exception e) {
400
            } catch (Exception e) {
399
                ExceptionHandler.handle("Une erreur est survenue lors de la création du document.", e);
401
                ExceptionHandler.handle("Une erreur est survenue lors de la création du document.", e);
400
            }
402
            }
401
            if (attempt > 0) {
403
            if (attempt > 0) {
402
                SwingUtilities.invokeLater(new Runnable() {
404
                SwingUtilities.invokeLater(new Runnable() {
403
                    public void run() {
405
                    public void run() {
404
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
406
                        JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
405
                    }
407
                    }
406
                });
408
                });
407
            }
409
            }
408
        }
410
        }
409
        return idSaisieVF;
411
        return idSaisieVF;
410
    }
412
    }
411
 
413
 
412
    @Override
414
    @Override
413
    public void update() {
415
    public void update() {
414
 
416
 
415
        int id = getSelectedID();
417
        int id = getSelectedID();
416
        super.update();
418
        super.update();
417
        final SQLRow rowFacture = getTable().getRow(id);
419
        final SQLRow rowFacture = getTable().getRow(id);
418
        ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).updateField("ID_SAISIE_VENTE_FACTURE", id);
420
        ((AbstractArticleItemTable) getEditor("sales.invoice.partial.items.list")).updateField("ID_SAISIE_VENTE_FACTURE", id);
419
 
421
 
420
        int idMvt = rowFacture.getInt("ID_MOUVEMENT");
422
        int idMvt = rowFacture.getInt("ID_MOUVEMENT");
421
        // on supprime tout ce qui est lié à la facture
423
        // on supprime tout ce qui est lié à la facture
422
        System.err.println("Archivage des fils");
424
        System.err.println("Archivage des fils");
423
        EcritureSQLElement eltEcr = (EcritureSQLElement) getDirectory().getElement("ECRITURE");
425
        EcritureSQLElement eltEcr = (EcritureSQLElement) getDirectory().getElement("ECRITURE");
424
        eltEcr.archiveMouvementProfondeur(idMvt, false);
426
        eltEcr.archiveMouvementProfondeur(idMvt, false);
425
        new GenerationMvtSaisieVenteFacture(id);
427
        new GenerationMvtSaisieVenteFacture(id);
426
        try {
428
        try {
427
            VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
429
            VenteFactureXmlSheet sheet = new VenteFactureXmlSheet(rowFacture);
428
            sheet.createDocument();
430
            sheet.createDocument();
429
            sheet.showPrintAndExport(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
431
            sheet.showPrintAndExport(this.panelOO.isVisualisationSelected(), this.panelOO.isImpressionSelected(), true);
430
        } catch (Exception e) {
432
        } catch (Exception e) {
431
            ExceptionHandler.handle("Une erreur est survenue lors de la création du document.", e);
433
            ExceptionHandler.handle("Une erreur est survenue lors de la création du document.", e);
432
        }
434
        }
433
    }
435
    }
434
 
436
 
435
    @Override
437
    @Override
436
    protected SQLRowValues createDefaults() {
438
    protected SQLRowValues createDefaults() {
437
        SQLRowValues rowVals = new SQLRowValues(getTable());
439
        SQLRowValues rowVals = new SQLRowValues(getTable());
438
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, new Date()));
440
        rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, new Date()));
439
        rowVals.put("PARTIAL", Boolean.TRUE);
441
        rowVals.put("PARTIAL", Boolean.TRUE);
440
        return rowVals;
442
        return rowVals;
441
    }
443
    }
442
 
444
 
443
    @Override
445
    @Override
444
    public Component addView(JComponent comp, String id) {
446
    public Component addView(JComponent comp, String id) {
445
        if (id.equals("sales.invoice.partial.amount")) {
447
        if (id.equals("sales.invoice.partial.amount")) {
446
            return super.addView(new AcompteRowItemView((AcompteField) comp), "MONTANT_FACTURABLE,POURCENT_FACTURABLE", REQ);
448
            return super.addView(new AcompteRowItemView((AcompteField) comp), "MONTANT_FACTURABLE,POURCENT_FACTURABLE", REQ);
447
        } else {
449
        } else {
448
            return super.addView(comp, id);
450
            return super.addView(comp, id);
449
        }
451
        }
450
    }
452
    }
451
}
453
}