18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.order.component;
|
|
|
15 |
|
28 |
ilm |
16 |
import static org.openconcerto.utils.CollectionUtils.createSet;
|
142 |
ilm |
17 |
|
18 |
ilm |
18 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
19 |
import org.openconcerto.erp.core.common.component.TransfertBaseSQLComponent;
|
63 |
ilm |
20 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
ilm |
21 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement;
|
|
|
22 |
import org.openconcerto.erp.core.common.ui.DeviseField;
|
|
|
23 |
import org.openconcerto.erp.core.common.ui.TotalPanel;
|
93 |
ilm |
24 |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AddressChoiceUI;
|
|
|
25 |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType;
|
174 |
ilm |
26 |
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI;
|
93 |
ilm |
27 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
180 |
ilm |
28 |
import org.openconcerto.erp.core.sales.order.element.CommandeClientSQLElement;
|
18 |
ilm |
29 |
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
|
|
|
30 |
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable;
|
93 |
ilm |
31 |
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
|
|
|
32 |
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClientComboBox;
|
|
|
33 |
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeRowItemView;
|
144 |
ilm |
34 |
import org.openconcerto.erp.core.supplychain.order.table.ChiffrageCommandeTable;
|
|
|
35 |
import org.openconcerto.erp.core.supplychain.order.table.FacturationCommandeTable;
|
83 |
ilm |
36 |
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater;
|
93 |
ilm |
37 |
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate;
|
83 |
ilm |
38 |
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel;
|
21 |
ilm |
39 |
import org.openconcerto.erp.panel.PanelOOSQLComponent;
|
93 |
ilm |
40 |
import org.openconcerto.erp.preferences.GestionClientPreferencePanel;
|
|
|
41 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
|
|
|
42 |
import org.openconcerto.erp.utils.TM;
|
18 |
ilm |
43 |
import org.openconcerto.sql.Configuration;
|
|
|
44 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
45 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
|
|
46 |
import org.openconcerto.sql.model.SQLInjector;
|
|
|
47 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
48 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
49 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
50 |
import org.openconcerto.sql.model.SQLTable;
|
93 |
ilm |
51 |
import org.openconcerto.sql.model.Where;
|
|
|
52 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
18 |
ilm |
53 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
|
|
54 |
import org.openconcerto.sql.sqlobject.JUniqueTextField;
|
93 |
ilm |
55 |
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
|
18 |
ilm |
56 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
|
|
57 |
import org.openconcerto.sql.users.UserManager;
|
|
|
58 |
import org.openconcerto.sql.view.EditFrame;
|
73 |
ilm |
59 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
18 |
ilm |
60 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
25 |
ilm |
61 |
import org.openconcerto.ui.FormLayouter;
|
18 |
ilm |
62 |
import org.openconcerto.ui.JDate;
|
|
|
63 |
import org.openconcerto.ui.TitledSeparator;
|
|
|
64 |
import org.openconcerto.ui.component.ITextArea;
|
|
|
65 |
import org.openconcerto.utils.ExceptionHandler;
|
|
|
66 |
|
|
|
67 |
import java.awt.Color;
|
|
|
68 |
import java.awt.GridBagConstraints;
|
|
|
69 |
import java.awt.GridBagLayout;
|
19 |
ilm |
70 |
import java.beans.PropertyChangeEvent;
|
|
|
71 |
import java.beans.PropertyChangeListener;
|
18 |
ilm |
72 |
import java.sql.SQLException;
|
28 |
ilm |
73 |
import java.util.Date;
|
142 |
ilm |
74 |
import java.util.HashSet;
|
180 |
ilm |
75 |
import java.util.List;
|
142 |
ilm |
76 |
import java.util.Set;
|
18 |
ilm |
77 |
|
|
|
78 |
import javax.swing.JLabel;
|
19 |
ilm |
79 |
import javax.swing.JOptionPane;
|
18 |
ilm |
80 |
import javax.swing.JPanel;
|
|
|
81 |
import javax.swing.JScrollPane;
|
144 |
ilm |
82 |
import javax.swing.JTabbedPane;
|
18 |
ilm |
83 |
import javax.swing.JTextField;
|
|
|
84 |
import javax.swing.SwingConstants;
|
|
|
85 |
import javax.swing.SwingUtilities;
|
|
|
86 |
import javax.swing.event.DocumentEvent;
|
|
|
87 |
import javax.swing.event.DocumentListener;
|
|
|
88 |
import javax.swing.event.TableModelEvent;
|
|
|
89 |
import javax.swing.event.TableModelListener;
|
|
|
90 |
|
|
|
91 |
public class CommandeClientSQLComponent extends TransfertBaseSQLComponent {
|
|
|
92 |
|
|
|
93 |
private CommandeClientItemTable table;
|
144 |
ilm |
94 |
private FacturationCommandeTable tableFacturationItem;
|
|
|
95 |
private ChiffrageCommandeTable tableChiffrageItem;
|
18 |
ilm |
96 |
private JUniqueTextField numeroUniqueCommande;
|
|
|
97 |
private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO");
|
|
|
98 |
private final ITextArea infos = new ITextArea(3, 3);
|
|
|
99 |
private ElementComboBox comboCommercial, comboDevis, comboClient;
|
21 |
ilm |
100 |
private PanelOOSQLComponent panelOO;
|
93 |
ilm |
101 |
final JDate dateCommande = new JDate(true);
|
|
|
102 |
private final boolean displayDpt;
|
|
|
103 |
private final ElementComboBox comboDpt = new ElementComboBox();
|
18 |
ilm |
104 |
|
|
|
105 |
private final SQLTextCombo textObjet = new SQLTextCombo();
|
|
|
106 |
|
|
|
107 |
public CommandeClientSQLComponent() {
|
|
|
108 |
super(Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT"));
|
93 |
ilm |
109 |
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
|
|
110 |
this.displayDpt = prefs.getBoolean(GestionClientPreferencePanel.DISPLAY_CLIENT_DPT, false);
|
18 |
ilm |
111 |
}
|
|
|
112 |
|
73 |
ilm |
113 |
public RowValuesTable getRowValuesTable() {
|
|
|
114 |
return this.table.getRowValuesTable();
|
41 |
ilm |
115 |
}
|
|
|
116 |
|
18 |
ilm |
117 |
public void addViews() {
|
|
|
118 |
this.setLayout(new GridBagLayout());
|
|
|
119 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
120 |
|
|
|
121 |
// Numero du commande
|
|
|
122 |
c.gridx = 0;
|
|
|
123 |
this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
|
|
|
124 |
|
142 |
ilm |
125 |
this.numeroUniqueCommande = new JUniqueTextField(16) {
|
|
|
126 |
@Override
|
|
|
127 |
public String getAutoRefreshNumber() {
|
|
|
128 |
if (getMode() == Mode.INSERTION) {
|
|
|
129 |
return NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), dateCommande.getDate());
|
|
|
130 |
} else {
|
|
|
131 |
return null;
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
};
|
18 |
ilm |
135 |
c.fill = GridBagConstraints.NONE;
|
|
|
136 |
c.gridx++;
|
|
|
137 |
c.weightx = 1;
|
|
|
138 |
this.add(this.numeroUniqueCommande, c);
|
|
|
139 |
|
|
|
140 |
// Date
|
|
|
141 |
JLabel labelDate = new JLabel(getLabelFor("DATE"));
|
|
|
142 |
labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
143 |
c.gridx = 2;
|
|
|
144 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
145 |
c.weightx = 0;
|
|
|
146 |
this.add(labelDate, c);
|
|
|
147 |
|
|
|
148 |
c.gridx++;
|
|
|
149 |
c.fill = GridBagConstraints.NONE;
|
|
|
150 |
this.add(dateCommande, c);
|
93 |
ilm |
151 |
dateCommande.addValueListener(new PropertyChangeListener() {
|
18 |
ilm |
152 |
|
93 |
ilm |
153 |
@Override
|
|
|
154 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
155 |
if (!isFilling() && dateCommande.getValue() != null) {
|
|
|
156 |
table.setDateDevise(dateCommande.getValue());
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
});
|
|
|
160 |
|
28 |
ilm |
161 |
// Champ Module
|
|
|
162 |
c.gridx = 0;
|
|
|
163 |
c.gridy++;
|
|
|
164 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
63 |
ilm |
165 |
final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
|
28 |
ilm |
166 |
|
|
|
167 |
this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
|
|
|
168 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
169 |
c.weightx = 1;
|
|
|
170 |
this.add(addP, c);
|
|
|
171 |
|
|
|
172 |
c.gridy++;
|
|
|
173 |
c.gridwidth = 1;
|
|
|
174 |
|
|
|
175 |
this.comboDevis = new ElementComboBox();
|
|
|
176 |
|
18 |
ilm |
177 |
// Reference
|
|
|
178 |
c.gridx = 0;
|
|
|
179 |
c.gridy++;
|
|
|
180 |
c.gridwidth = 1;
|
|
|
181 |
c.gridwidth = 1;
|
|
|
182 |
c.gridheight = 1;
|
|
|
183 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
184 |
|
|
|
185 |
JLabel labelObjet = new JLabel(getLabelFor("NOM"));
|
|
|
186 |
labelObjet.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
187 |
c.weightx = 0;
|
|
|
188 |
this.add(labelObjet, c);
|
|
|
189 |
|
|
|
190 |
c.gridx++;
|
|
|
191 |
c.weightx = 1;
|
|
|
192 |
c.fill = GridBagConstraints.BOTH;
|
|
|
193 |
this.add(this.textObjet, c);
|
|
|
194 |
|
|
|
195 |
String field;
|
|
|
196 |
field = "ID_COMMERCIAL";
|
|
|
197 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
198 |
// Commercial
|
|
|
199 |
JLabel labelCommercial = new JLabel(getLabelFor(field));
|
|
|
200 |
labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
201 |
|
|
|
202 |
c.gridx++;
|
|
|
203 |
c.weightx = 0;
|
|
|
204 |
this.add(labelCommercial, c);
|
|
|
205 |
|
|
|
206 |
this.comboCommercial = new ElementComboBox(false, 25);
|
|
|
207 |
this.comboCommercial.setListIconVisible(false);
|
|
|
208 |
c.gridx++;
|
|
|
209 |
c.fill = GridBagConstraints.NONE;
|
|
|
210 |
c.weightx = 1;
|
|
|
211 |
this.add(this.comboCommercial, c);
|
|
|
212 |
addRequiredSQLObject(this.comboCommercial, field);
|
|
|
213 |
|
|
|
214 |
// Ligne 3: Client
|
|
|
215 |
c.gridx = 0;
|
|
|
216 |
c.gridy++;
|
|
|
217 |
c.weightx = 0;
|
|
|
218 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
219 |
this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
|
|
|
220 |
|
|
|
221 |
this.comboClient = new ElementComboBox();
|
93 |
ilm |
222 |
c.gridx++;
|
|
|
223 |
c.gridwidth = 1;
|
18 |
ilm |
224 |
c.weightx = 1;
|
|
|
225 |
c.weighty = 0;
|
|
|
226 |
c.fill = GridBagConstraints.NONE;
|
|
|
227 |
this.add(this.comboClient, c);
|
19 |
ilm |
228 |
final ElementComboBox boxTarif = new ElementComboBox();
|
|
|
229 |
this.comboClient.addValueListener(new PropertyChangeListener() {
|
18 |
ilm |
230 |
|
19 |
ilm |
231 |
@Override
|
|
|
232 |
public void propertyChange(PropertyChangeEvent evt) {
|
28 |
ilm |
233 |
if (!isFilling() && comboClient.getValue() != null) {
|
19 |
ilm |
234 |
Integer id = comboClient.getValue();
|
|
|
235 |
|
|
|
236 |
if (id > 1) {
|
|
|
237 |
|
|
|
238 |
SQLRow row = comboClient.getElement().getTable().getRow(id);
|
|
|
239 |
if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) {
|
|
|
240 |
|
|
|
241 |
SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
|
|
|
242 |
if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID())
|
93 |
ilm |
243 |
&& JOptionPane.showConfirmDialog(null, TM.tr("apply.associated.pricelist.to.customer")) == JOptionPane.YES_OPTION) {
|
19 |
ilm |
244 |
boxTarif.setValue(foreignRow.getID());
|
|
|
245 |
// SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
|
|
|
246 |
// true);
|
|
|
247 |
} else {
|
|
|
248 |
boxTarif.setValue(foreignRow.getID());
|
|
|
249 |
}
|
|
|
250 |
// SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
|
|
|
251 |
// if (foreignRow.isUndefined() &&
|
|
|
252 |
// !row.getForeignRow("ID_DEVISE").isUndefined()) {
|
|
|
253 |
// SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
|
|
|
254 |
// rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
|
|
|
255 |
// foreignRow = rowValsD;
|
|
|
256 |
//
|
|
|
257 |
// }
|
|
|
258 |
// table.setTarif(foreignRow, true);
|
|
|
259 |
}
|
180 |
ilm |
260 |
table.setClient(row, !isFilling());
|
174 |
ilm |
261 |
|
|
|
262 |
} else {
|
|
|
263 |
if (!isFilling()) {
|
|
|
264 |
table.setClient(null, true);
|
|
|
265 |
}
|
19 |
ilm |
266 |
}
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
});
|
93 |
ilm |
271 |
addRequiredSQLObject(this.comboClient, "ID_CLIENT");
|
|
|
272 |
|
|
|
273 |
if (this.displayDpt) {
|
|
|
274 |
c.gridx++;
|
|
|
275 |
c.gridwidth = 1;
|
|
|
276 |
final JLabel labelDpt = new JLabel(getLabelFor("ID_CLIENT_DEPARTEMENT"));
|
|
|
277 |
labelDpt.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
278 |
c.weightx = 0;
|
|
|
279 |
c.gridwidth = 1;
|
|
|
280 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
281 |
this.add(labelDpt, c);
|
|
|
282 |
|
|
|
283 |
c.gridx++;
|
|
|
284 |
c.gridwidth = 1;
|
|
|
285 |
c.weightx = 0;
|
|
|
286 |
c.weighty = 0;
|
|
|
287 |
c.fill = GridBagConstraints.NONE;
|
|
|
288 |
this.add(this.comboDpt, c);
|
|
|
289 |
DefaultGridBagConstraints.lockMinimumSize(this.comboDpt);
|
|
|
290 |
addSQLObject(this.comboDpt, "ID_CLIENT_DEPARTEMENT");
|
|
|
291 |
|
|
|
292 |
comboClient.addModelListener("wantedID", new PropertyChangeListener() {
|
|
|
293 |
|
|
|
294 |
@Override
|
|
|
295 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
296 |
int wantedID = comboClient.getWantedID();
|
|
|
297 |
|
|
|
298 |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
|
|
|
299 |
final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
|
|
|
300 |
comboDpt.getRequest().setWhere(new Where(comboDpt.getRequest().getPrimaryTable().getField("ID_CLIENT"), "=", rowClient.getID()));
|
|
|
301 |
} else {
|
|
|
302 |
comboDpt.getRequest().setWhere(null);
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
});
|
|
|
306 |
|
|
|
307 |
}
|
|
|
308 |
if (getTable().contains("ID_CONTACT")) {
|
|
|
309 |
// Contact Client
|
|
|
310 |
c.gridx = 0;
|
|
|
311 |
c.gridy++;
|
|
|
312 |
c.gridwidth = 1;
|
|
|
313 |
final JLabel labelContact = new JLabel(getLabelFor("ID_CONTACT"));
|
|
|
314 |
labelContact.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
315 |
c.weightx = 0;
|
|
|
316 |
c.gridwidth = 1;
|
|
|
317 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
318 |
this.add(labelContact, c);
|
|
|
319 |
|
|
|
320 |
final ElementComboBox comboContact = new ElementComboBox();
|
|
|
321 |
c.gridx++;
|
|
|
322 |
c.gridwidth = 1;
|
|
|
323 |
c.weightx = 0;
|
|
|
324 |
c.weighty = 0;
|
|
|
325 |
c.fill = GridBagConstraints.NONE;
|
|
|
326 |
this.add(comboContact, c);
|
|
|
327 |
final SQLElement contactElement = getElement().getForeignElement("ID_CONTACT");
|
|
|
328 |
comboContact.init(contactElement, contactElement.getComboRequest(true));
|
|
|
329 |
comboContact.getRequest().setWhere(Where.FALSE);
|
|
|
330 |
DefaultGridBagConstraints.lockMinimumSize(comboContact);
|
|
|
331 |
this.addView(comboContact, "ID_CONTACT");
|
|
|
332 |
comboClient.addModelListener("wantedID", new PropertyChangeListener() {
|
|
|
333 |
|
|
|
334 |
@Override
|
|
|
335 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
336 |
int wantedID = comboClient.getWantedID();
|
|
|
337 |
System.err.println("SET WHERE ID_CLIENT = " + wantedID);
|
|
|
338 |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
|
|
|
339 |
|
|
|
340 |
final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID);
|
144 |
ilm |
341 |
|
156 |
ilm |
342 |
if (rowClient.getObject("ID_CATEGORIE_COMPTABLE") != null && !rowClient.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) {
|
|
|
343 |
table.setRowCatComptable(rowClient.getForeign("ID_CATEGORIE_COMPTABLE"));
|
|
|
344 |
} else {
|
|
|
345 |
table.setRowCatComptable(null);
|
|
|
346 |
}
|
|
|
347 |
|
94 |
ilm |
348 |
if (!rowClient.isForeignEmpty("ID_COMMERCIAL")) {
|
|
|
349 |
comboCommercial.setValue(rowClient.getForeignID("ID_COMMERCIAL"));
|
|
|
350 |
}
|
93 |
ilm |
351 |
int idClient = rowClient.getID();
|
|
|
352 |
comboContact.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_CLIENT"), "=", idClient));
|
|
|
353 |
} else {
|
156 |
ilm |
354 |
table.setRowCatComptable(null);
|
93 |
ilm |
355 |
comboContact.getRequest().setWhere(Where.FALSE);
|
|
|
356 |
// DevisSQLComponent.this.table.setTarif(null, false);
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
});
|
|
|
360 |
|
142 |
ilm |
361 |
if (getTable().contains("DATE_LIVRAISON_PREV")) {
|
|
|
362 |
// Date
|
|
|
363 |
JLabel labelDatePrev = new JLabel(getLabelFor("DATE_LIVRAISON_PREV"));
|
|
|
364 |
labelDatePrev.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
365 |
c.gridx = 2;
|
|
|
366 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
367 |
c.weightx = 0;
|
|
|
368 |
this.add(labelDatePrev, c);
|
|
|
369 |
|
|
|
370 |
c.gridx++;
|
|
|
371 |
c.fill = GridBagConstraints.NONE;
|
|
|
372 |
JDate datePrev = new JDate();
|
|
|
373 |
this.add(datePrev, c);
|
|
|
374 |
this.addView(datePrev, "DATE_LIVRAISON_PREV");
|
|
|
375 |
}
|
|
|
376 |
|
93 |
ilm |
377 |
}
|
94 |
ilm |
378 |
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot());
|
|
|
379 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ADDRESS_SPEC, true)) {
|
93 |
ilm |
380 |
|
94 |
ilm |
381 |
final SQLElement adrElement = getElement().getForeignElement("ID_ADRESSE");
|
|
|
382 |
final AddressChoiceUI addressUI = new AddressChoiceUI();
|
|
|
383 |
addressUI.addToUI(this, c);
|
|
|
384 |
comboClient.addModelListener("wantedID", new PropertyChangeListener() {
|
93 |
ilm |
385 |
|
94 |
ilm |
386 |
@Override
|
|
|
387 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
388 |
int wantedID = comboClient.getWantedID();
|
|
|
389 |
System.err.println("SET WHERE ID_CLIENT = " + wantedID);
|
|
|
390 |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
|
|
|
391 |
|
132 |
ilm |
392 |
addressUI.getComboAdrF().getRequest().setWhere(
|
|
|
393 |
new Where(adrElement.getTable().getField("ID_CLIENT"), "=", wantedID).and(new Where(adrElement.getTable().getField("TYPE"), "=", AdresseType.Invoice.getId())));
|
|
|
394 |
addressUI.getComboAdrL().getRequest().setWhere(
|
|
|
395 |
new Where(adrElement.getTable().getField("ID_CLIENT"), "=", wantedID).and(new Where(adrElement.getTable().getField("TYPE"), "=", AdresseType.Delivery.getId())));
|
94 |
ilm |
396 |
} else {
|
|
|
397 |
addressUI.getComboAdrF().getRequest().setWhere(Where.FALSE);
|
|
|
398 |
addressUI.getComboAdrL().getRequest().setWhere(Where.FALSE);
|
|
|
399 |
}
|
93 |
ilm |
400 |
}
|
94 |
ilm |
401 |
});
|
|
|
402 |
}
|
93 |
ilm |
403 |
|
174 |
ilm |
404 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) {
|
|
|
405 |
// cat spe
|
|
|
406 |
final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI();
|
|
|
407 |
catUI.addToUI(this, c);
|
|
|
408 |
catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() {
|
|
|
409 |
|
|
|
410 |
@Override
|
|
|
411 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
412 |
int wantedID = catUI.getCombo().getWantedID();
|
|
|
413 |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) {
|
|
|
414 |
table.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID));
|
|
|
415 |
} else {
|
|
|
416 |
table.setRowCatComptable(null);
|
|
|
417 |
}
|
|
|
418 |
}
|
|
|
419 |
});
|
|
|
420 |
}
|
|
|
421 |
|
93 |
ilm |
422 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ORDER_PACKAGING_MANAGEMENT, true)) {
|
|
|
423 |
// Emballage
|
|
|
424 |
c.gridy++;
|
|
|
425 |
c.gridx = 0;
|
|
|
426 |
c.weightx = 0;
|
|
|
427 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
428 |
this.add(new JLabel(getLabelFor("EMBALLAGE"), SwingConstants.RIGHT), c);
|
|
|
429 |
|
|
|
430 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
431 |
c.gridx++;
|
|
|
432 |
c.weightx = 1;
|
|
|
433 |
SQLTextCombo fieldEmballage = new SQLTextCombo();
|
|
|
434 |
this.add(fieldEmballage, c);
|
|
|
435 |
this.addView(fieldEmballage, "EMBALLAGE");
|
|
|
436 |
|
|
|
437 |
// N° Exp
|
|
|
438 |
JLabel labelNumExp = new JLabel(getLabelFor("NUMERO_EXPEDITION"));
|
|
|
439 |
labelNumExp.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
440 |
c.gridx = 2;
|
|
|
441 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
442 |
c.weightx = 0;
|
|
|
443 |
this.add(labelNumExp, c);
|
|
|
444 |
|
|
|
445 |
JTextField fieldNumExp = new JTextField();
|
|
|
446 |
c.gridx++;
|
|
|
447 |
c.weightx = 1;
|
|
|
448 |
this.add(fieldNumExp, c);
|
|
|
449 |
this.addView(fieldNumExp, "NUMERO_EXPEDITION");
|
|
|
450 |
|
|
|
451 |
// expedition
|
|
|
452 |
|
|
|
453 |
c.gridy++;
|
|
|
454 |
c.gridx = 0;
|
|
|
455 |
c.weightx = 0;
|
|
|
456 |
c.weighty = 0;
|
|
|
457 |
c.gridwidth = 1;
|
|
|
458 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
459 |
this.add(new JLabel(getLabelFor("TYPE_EXPEDITION"), SwingConstants.RIGHT), c);
|
|
|
460 |
c.gridx++;
|
|
|
461 |
c.gridwidth = 1;
|
|
|
462 |
c.weightx = 1;
|
|
|
463 |
c.fill = GridBagConstraints.NONE;
|
|
|
464 |
SQLTextCombo tTypeExpedition = new SQLTextCombo();
|
|
|
465 |
this.add(tTypeExpedition, c);
|
|
|
466 |
this.addView(tTypeExpedition, "TYPE_EXPEDITION");
|
|
|
467 |
|
|
|
468 |
// Etat
|
|
|
469 |
final JLabel labelEtat = new JLabel(getLabelFor("ETAT_COMMANDE"), SwingConstants.RIGHT);
|
|
|
470 |
c.gridx++;
|
|
|
471 |
c.weightx = 0;
|
|
|
472 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
473 |
this.add(labelEtat, c);
|
|
|
474 |
final EtatCommandeClientComboBox comboEtat = new EtatCommandeClientComboBox();
|
|
|
475 |
c.gridx++;
|
|
|
476 |
c.fill = GridBagConstraints.NONE;
|
|
|
477 |
c.weightx = 1;
|
|
|
478 |
this.add(comboEtat, c);
|
|
|
479 |
addView(new EtatCommandeRowItemView(comboEtat), "ETAT_COMMANDE", REQ);
|
|
|
480 |
}
|
19 |
ilm |
481 |
// tarif
|
|
|
482 |
if (this.getTable().getFieldsName().contains("ID_TARIF")) {
|
|
|
483 |
// TARIF
|
93 |
ilm |
484 |
c.fill = GridBagConstraints.HORIZONTAL;
|
19 |
ilm |
485 |
c.gridy++;
|
|
|
486 |
c.gridx = 0;
|
|
|
487 |
c.weightx = 0;
|
|
|
488 |
c.weighty = 0;
|
|
|
489 |
c.gridwidth = 1;
|
93 |
ilm |
490 |
this.add(new JLabel(getLabelFor("ID_TARIF"), SwingConstants.RIGHT), c);
|
19 |
ilm |
491 |
c.gridx++;
|
93 |
ilm |
492 |
c.gridwidth = 1;
|
19 |
ilm |
493 |
|
|
|
494 |
c.weightx = 1;
|
|
|
495 |
this.add(boxTarif, c);
|
|
|
496 |
this.addView(boxTarif, "ID_TARIF");
|
73 |
ilm |
497 |
boxTarif.addModelListener("wantedID", new PropertyChangeListener() {
|
19 |
ilm |
498 |
|
|
|
499 |
@Override
|
|
|
500 |
public void propertyChange(PropertyChangeEvent evt) {
|
73 |
ilm |
501 |
SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID());
|
|
|
502 |
table.setTarif(selectedRow, false);
|
19 |
ilm |
503 |
}
|
|
|
504 |
});
|
144 |
ilm |
505 |
if (getTable().contains("DATE_LIVRAISON_REELLE")) {
|
|
|
506 |
// Date
|
|
|
507 |
JLabel labelDatePrev = new JLabel(getLabelFor("DATE_LIVRAISON_REELLE"));
|
|
|
508 |
labelDatePrev.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
509 |
c.gridx++;
|
|
|
510 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
511 |
c.weightx = 0;
|
|
|
512 |
this.add(labelDatePrev, c);
|
|
|
513 |
|
|
|
514 |
c.gridx++;
|
|
|
515 |
c.fill = GridBagConstraints.NONE;
|
|
|
516 |
JDate datePrev = new JDate();
|
|
|
517 |
this.add(datePrev, c);
|
|
|
518 |
this.addView(datePrev, "DATE_LIVRAISON_REELLE");
|
|
|
519 |
}
|
19 |
ilm |
520 |
}
|
142 |
ilm |
521 |
if (this.getTable().getFieldsName().contains("ACOMPTE_COMMANDE")) {
|
|
|
522 |
// ACOMPTE
|
|
|
523 |
c.gridy += (this.getTable().getFieldsName().contains("ID_TARIF") ? 0 : 1);
|
|
|
524 |
c.gridx += (this.getTable().getFieldsName().contains("ID_TARIF") ? 1 : 2);
|
|
|
525 |
c.weightx = 0;
|
|
|
526 |
c.weighty = 0;
|
|
|
527 |
c.gridwidth = 1;
|
|
|
528 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
529 |
this.add(new JLabel(getLabelFor("ACOMPTE_COMMANDE"), SwingConstants.RIGHT), c);
|
|
|
530 |
c.gridx++;
|
|
|
531 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
532 |
c.fill = GridBagConstraints.NONE;
|
|
|
533 |
c.weightx = 1;
|
|
|
534 |
JTextField acompteCmd = new JTextField(15);
|
|
|
535 |
DefaultGridBagConstraints.lockMinimumSize(acompteCmd);
|
|
|
536 |
this.add(acompteCmd, c);
|
|
|
537 |
this.addView(acompteCmd, "ACOMPTE_COMMANDE");
|
|
|
538 |
}
|
19 |
ilm |
539 |
|
18 |
ilm |
540 |
// Table d'élément
|
|
|
541 |
this.table = new CommandeClientItemTable();
|
144 |
ilm |
542 |
JTabbedPane pane = new JTabbedPane();
|
18 |
ilm |
543 |
c.fill = GridBagConstraints.BOTH;
|
|
|
544 |
c.gridy++;
|
|
|
545 |
c.gridx = 0;
|
|
|
546 |
c.weightx = 1;
|
|
|
547 |
c.weighty = 1;
|
|
|
548 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
144 |
ilm |
549 |
pane.add("Eléments", this.table);
|
|
|
550 |
this.tableFacturationItem = new FacturationCommandeTable(this);
|
|
|
551 |
pane.add("Facturation", this.tableFacturationItem);
|
|
|
552 |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CHIFFRAGE_COMMANDE_CLIENT, false)) {
|
|
|
553 |
this.tableChiffrageItem = new ChiffrageCommandeTable(this);
|
180 |
ilm |
554 |
this.tableChiffrageItem.getRowValuesTable().setEditable(((CommandeClientSQLElement) getElement()).isChiffrageEditableInUI());
|
144 |
ilm |
555 |
pane.add("Chiffrage", this.tableChiffrageItem);
|
|
|
556 |
}
|
180 |
ilm |
557 |
if (this.getTable().contains("INFOS_DEVIS")) {
|
|
|
558 |
JPanel panelInfosDevis = new JPanel(new GridBagLayout());
|
|
|
559 |
DefaultGridBagConstraints cI = new DefaultGridBagConstraints();
|
|
|
560 |
cI.weightx = 1;
|
|
|
561 |
cI.weighty = 1;
|
|
|
562 |
cI.fill = GridBagConstraints.BOTH;
|
|
|
563 |
ITextArea infosDevis = new ITextArea();
|
|
|
564 |
panelInfosDevis.add(new JScrollPane(infosDevis), cI);
|
|
|
565 |
this.addView(infosDevis, "INFOS_DEVIS");
|
|
|
566 |
pane.add("Informations devis", panelInfosDevis);
|
|
|
567 |
}
|
144 |
ilm |
568 |
this.add(pane, c);
|
18 |
ilm |
569 |
|
93 |
ilm |
570 |
DeviseField textPortHT = new DeviseField(5);
|
18 |
ilm |
571 |
DeviseField textRemiseHT = new DeviseField();
|
|
|
572 |
|
93 |
ilm |
573 |
// Total
|
|
|
574 |
DeviseField fieldHT = new DeviseField();
|
|
|
575 |
DeviseField fieldTVA = new DeviseField();
|
|
|
576 |
DeviseField fieldTTC = new DeviseField();
|
|
|
577 |
DeviseField fieldDevise = new DeviseField();
|
|
|
578 |
DeviseField fieldService = new DeviseField();
|
|
|
579 |
DeviseField fieldHA = new DeviseField();
|
142 |
ilm |
580 |
DeviseField fieldEco = new DeviseField();
|
93 |
ilm |
581 |
fieldHT.setOpaque(false);
|
|
|
582 |
fieldHA.setOpaque(false);
|
|
|
583 |
fieldTVA.setOpaque(false);
|
|
|
584 |
fieldTTC.setOpaque(false);
|
|
|
585 |
fieldService.setOpaque(false);
|
|
|
586 |
addSQLObject(fieldDevise, "T_DEVISE");
|
142 |
ilm |
587 |
addSQLObject(fieldEco, "T_ECO_CONTRIBUTION");
|
93 |
ilm |
588 |
addRequiredSQLObject(fieldHT, "T_HT");
|
|
|
589 |
addRequiredSQLObject(fieldTVA, "T_TVA");
|
|
|
590 |
addRequiredSQLObject(fieldTTC, "T_TTC");
|
|
|
591 |
addRequiredSQLObject(fieldService, "T_SERVICE");
|
|
|
592 |
if (getTable().contains("PREBILAN")) {
|
|
|
593 |
addSQLObject(fieldHA, "PREBILAN");
|
|
|
594 |
} else if (getTable().contains("T_HA")) {
|
94 |
ilm |
595 |
this.allowEditable("T_HA", false);
|
93 |
ilm |
596 |
addSQLObject(fieldHA, "T_HA");
|
|
|
597 |
}
|
94 |
ilm |
598 |
// Disable
|
142 |
ilm |
599 |
this.allowEditable("T_ECO_CONTRIBUTION", false);
|
94 |
ilm |
600 |
this.allowEditable("T_HT", false);
|
|
|
601 |
this.allowEditable("T_TVA", false);
|
|
|
602 |
this.allowEditable("T_TTC", false);
|
|
|
603 |
this.allowEditable("T_SERVICE", false);
|
93 |
ilm |
604 |
|
|
|
605 |
JTextField poids = new JTextField();
|
|
|
606 |
SQLRequestComboBox boxTaxePort = new SQLRequestComboBox(false, 8);
|
156 |
ilm |
607 |
|
93 |
ilm |
608 |
// addSQLObject(poids, "T_POIDS");
|
142 |
ilm |
609 |
final TotalPanel totalTTC = new TotalPanel(this.table, fieldEco, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null,
|
|
|
610 |
(getTable().contains("ID_TAXE_PORT") ? boxTaxePort : null), null);
|
93 |
ilm |
611 |
|
18 |
ilm |
612 |
// INfos
|
|
|
613 |
c.gridx = 0;
|
|
|
614 |
c.gridy++;
|
|
|
615 |
c.gridheight = 1;
|
|
|
616 |
c.weighty = 0;
|
|
|
617 |
c.weightx = 1;
|
|
|
618 |
c.anchor = GridBagConstraints.WEST;
|
|
|
619 |
c.gridwidth = 2;
|
|
|
620 |
this.add(new TitledSeparator(getLabelFor("INFOS")), c);
|
|
|
621 |
|
|
|
622 |
c.gridy++;
|
|
|
623 |
c.weightx = 1;
|
|
|
624 |
c.weighty = 0;
|
|
|
625 |
c.fill = GridBagConstraints.BOTH;
|
|
|
626 |
final JScrollPane scrollPane = new JScrollPane(this.infos);
|
|
|
627 |
scrollPane.setBorder(null);
|
|
|
628 |
this.add(scrollPane, c);
|
|
|
629 |
|
|
|
630 |
// Poids
|
|
|
631 |
|
|
|
632 |
final JTextField textPoidsTotal = new JTextField(8);
|
93 |
ilm |
633 |
JPanel panel = new JPanel(new GridBagLayout());
|
|
|
634 |
GridBagConstraints cFrais = new DefaultGridBagConstraints();
|
|
|
635 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
636 |
panel.add(new JLabel(getLabelFor("T_POIDS"), JTextField.RIGHT), cFrais);
|
|
|
637 |
textPoidsTotal.setEnabled(false);
|
|
|
638 |
textPoidsTotal.setDisabledTextColor(Color.BLACK);
|
|
|
639 |
cFrais.gridx++;
|
|
|
640 |
panel.add(textPoidsTotal, cFrais);
|
18 |
ilm |
641 |
|
93 |
ilm |
642 |
panel.setOpaque(false);
|
18 |
ilm |
643 |
|
93 |
ilm |
644 |
DefaultGridBagConstraints.lockMinimumSize(textPortHT);
|
|
|
645 |
addSQLObject(textPortHT, "PORT_HT");
|
|
|
646 |
DefaultGridBagConstraints.lockMinimumSize(textRemiseHT);
|
|
|
647 |
addSQLObject(textRemiseHT, "REMISE_HT");
|
18 |
ilm |
648 |
|
93 |
ilm |
649 |
// Frais de port
|
18 |
ilm |
650 |
|
93 |
ilm |
651 |
if (getTable().contains("ID_TAXE_PORT")) {
|
18 |
ilm |
652 |
|
93 |
ilm |
653 |
JLabel labelPortHT = new JLabel(getLabelFor("PORT_HT"));
|
|
|
654 |
labelPortHT.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
655 |
cFrais.gridx = 0;
|
|
|
656 |
cFrais.gridy++;
|
|
|
657 |
panel.add(labelPortHT, cFrais);
|
|
|
658 |
cFrais.gridx++;
|
|
|
659 |
panel.add(textPortHT, cFrais);
|
|
|
660 |
|
|
|
661 |
JLabel labelTaxeHT = new JLabel(getLabelFor("ID_TAXE_PORT"));
|
|
|
662 |
labelTaxeHT.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
663 |
cFrais.gridx = 0;
|
|
|
664 |
cFrais.gridy++;
|
|
|
665 |
panel.add(labelTaxeHT, cFrais);
|
|
|
666 |
cFrais.gridx++;
|
|
|
667 |
panel.add(boxTaxePort, cFrais);
|
|
|
668 |
this.addView(boxTaxePort, "ID_TAXE_PORT", REQ);
|
|
|
669 |
|
|
|
670 |
boxTaxePort.addValueListener(new PropertyChangeListener() {
|
|
|
671 |
|
|
|
672 |
@Override
|
|
|
673 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
674 |
totalTTC.updateTotal();
|
|
|
675 |
}
|
|
|
676 |
});
|
61 |
ilm |
677 |
}
|
|
|
678 |
|
93 |
ilm |
679 |
// Remise
|
|
|
680 |
JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT"));
|
|
|
681 |
labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
682 |
cFrais.gridy++;
|
|
|
683 |
cFrais.gridx = 0;
|
|
|
684 |
panel.add(labelRemiseHT, cFrais);
|
|
|
685 |
cFrais.gridx++;
|
|
|
686 |
panel.add(textRemiseHT, cFrais);
|
18 |
ilm |
687 |
|
93 |
ilm |
688 |
c.gridx = 2;
|
|
|
689 |
c.weightx = 0;
|
|
|
690 |
c.weighty = 0;
|
|
|
691 |
c.gridwidth = 1;
|
|
|
692 |
c.fill = GridBagConstraints.NONE;
|
|
|
693 |
c.anchor = GridBagConstraints.NORTHEAST;
|
|
|
694 |
DefaultGridBagConstraints.lockMinimumSize(panel);
|
|
|
695 |
this.add(panel, c);
|
|
|
696 |
|
18 |
ilm |
697 |
c.gridx = GridBagConstraints.RELATIVE;
|
|
|
698 |
c.gridy--;
|
|
|
699 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
700 |
c.gridheight = 2;
|
|
|
701 |
c.anchor = GridBagConstraints.NORTHEAST;
|
|
|
702 |
c.fill = GridBagConstraints.NONE;
|
|
|
703 |
c.weighty = 0;
|
|
|
704 |
|
|
|
705 |
this.add(totalTTC, c);
|
|
|
706 |
|
21 |
ilm |
707 |
this.panelOO = new PanelOOSQLComponent(this);
|
18 |
ilm |
708 |
c.gridwidth = 1;
|
61 |
ilm |
709 |
c.fill = GridBagConstraints.NONE;
|
18 |
ilm |
710 |
c.anchor = GridBagConstraints.EAST;
|
|
|
711 |
c.gridx = 0;
|
|
|
712 |
c.gridy += 3;
|
|
|
713 |
c.weightx = 0;
|
|
|
714 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
21 |
ilm |
715 |
this.add(this.panelOO, c);
|
18 |
ilm |
716 |
|
|
|
717 |
textPortHT.getDocument().addDocumentListener(new DocumentListener() {
|
|
|
718 |
public void changedUpdate(DocumentEvent e) {
|
|
|
719 |
totalTTC.updateTotal();
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
public void removeUpdate(DocumentEvent e) {
|
|
|
723 |
totalTTC.updateTotal();
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
public void insertUpdate(DocumentEvent e) {
|
|
|
727 |
totalTTC.updateTotal();
|
|
|
728 |
}
|
|
|
729 |
});
|
|
|
730 |
|
|
|
731 |
textRemiseHT.getDocument().addDocumentListener(new DocumentListener() {
|
|
|
732 |
public void changedUpdate(DocumentEvent e) {
|
|
|
733 |
totalTTC.updateTotal();
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
public void removeUpdate(DocumentEvent e) {
|
|
|
737 |
totalTTC.updateTotal();
|
|
|
738 |
}
|
|
|
739 |
|
|
|
740 |
public void insertUpdate(DocumentEvent e) {
|
|
|
741 |
totalTTC.updateTotal();
|
|
|
742 |
}
|
|
|
743 |
});
|
|
|
744 |
|
|
|
745 |
addSQLObject(this.textObjet, "NOM");
|
|
|
746 |
addSQLObject(textPoidsTotal, "T_POIDS");
|
|
|
747 |
addRequiredSQLObject(dateCommande, "DATE");
|
|
|
748 |
// addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS");
|
|
|
749 |
addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO");
|
|
|
750 |
addSQLObject(this.infos, "INFOS");
|
|
|
751 |
addSQLObject(this.comboDevis, "ID_DEVIS");
|
|
|
752 |
|
90 |
ilm |
753 |
this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
|
18 |
ilm |
754 |
|
|
|
755 |
this.table.getModel().addTableModelListener(new TableModelListener() {
|
|
|
756 |
|
|
|
757 |
public void tableChanged(TableModelEvent e) {
|
|
|
758 |
textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal()));
|
|
|
759 |
}
|
|
|
760 |
});
|
180 |
ilm |
761 |
|
|
|
762 |
this.addView(this.table.getRowValuesTable(), "");
|
18 |
ilm |
763 |
DefaultGridBagConstraints.lockMinimumSize(comboClient);
|
|
|
764 |
DefaultGridBagConstraints.lockMinimumSize(comboCommercial);
|
|
|
765 |
DefaultGridBagConstraints.lockMinimumSize(comboDevis);
|
|
|
766 |
DefaultGridBagConstraints.lockMinimumSize(totalTTC);
|
|
|
767 |
DefaultGridBagConstraints.lockMaximumSize(totalTTC);
|
|
|
768 |
DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande);
|
|
|
769 |
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
public int insert(SQLRow order) {
|
25 |
ilm |
773 |
final int idCommande;
|
142 |
ilm |
774 |
|
|
|
775 |
int attempt = 0;
|
18 |
ilm |
776 |
// on verifie qu'un devis du meme numero n'a pas été inséré entre temps
|
142 |
ilm |
777 |
if (!this.numeroUniqueCommande.checkValidation(false)) {
|
|
|
778 |
while (attempt < JUniqueTextField.RETRY_COUNT) {
|
|
|
779 |
String num = NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), dateCommande.getDate());
|
|
|
780 |
this.numeroUniqueCommande.setText(num);
|
|
|
781 |
attempt++;
|
|
|
782 |
if (this.numeroUniqueCommande.checkValidation(false)) {
|
|
|
783 |
System.err.println("ATEMPT " + attempt + " SUCCESS WITH NUMERO " + num);
|
|
|
784 |
break;
|
|
|
785 |
}
|
|
|
786 |
try {
|
|
|
787 |
Thread.sleep(JUniqueTextField.SLEEP_WAIT_MS);
|
|
|
788 |
} catch (InterruptedException e) {
|
|
|
789 |
e.printStackTrace();
|
|
|
790 |
}
|
|
|
791 |
}
|
|
|
792 |
}
|
|
|
793 |
final String num = this.numeroUniqueCommande.getText();
|
|
|
794 |
if (attempt == JUniqueTextField.RETRY_COUNT) {
|
|
|
795 |
idCommande = getSelectedID();
|
|
|
796 |
ExceptionHandler.handle("Impossible d'ajouter, numéro de commande existant.");
|
|
|
797 |
final Object root = SwingUtilities.getRoot(this);
|
|
|
798 |
if (root instanceof EditFrame) {
|
|
|
799 |
final EditFrame frame = (EditFrame) root;
|
|
|
800 |
frame.getPanel().setAlwaysVisible(true);
|
|
|
801 |
}
|
|
|
802 |
} else {
|
18 |
ilm |
803 |
idCommande = super.insert(order);
|
|
|
804 |
this.table.updateField("ID_COMMANDE_CLIENT", idCommande);
|
144 |
ilm |
805 |
this.tableFacturationItem.updateField("ID_COMMANDE_CLIENT", idCommande);
|
|
|
806 |
if (this.tableChiffrageItem != null) {
|
|
|
807 |
this.tableChiffrageItem.updateField("ID_COMMANDE_CLIENT", idCommande);
|
|
|
808 |
}
|
83 |
ilm |
809 |
try {
|
|
|
810 |
updateStock(idCommande);
|
|
|
811 |
} catch (SQLException e1) {
|
|
|
812 |
ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
|
|
|
813 |
}
|
18 |
ilm |
814 |
// Création des articles
|
|
|
815 |
this.table.createArticle(idCommande, this.getElement());
|
|
|
816 |
// generation du document
|
|
|
817 |
|
25 |
ilm |
818 |
try {
|
|
|
819 |
CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(getTable().getRow(idCommande));
|
|
|
820 |
sheet.createDocumentAsynchronous();
|
|
|
821 |
sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
|
|
|
822 |
} catch (Exception e) {
|
|
|
823 |
ExceptionHandler.handle("Impossible de créer la commande", e);
|
|
|
824 |
}
|
|
|
825 |
|
18 |
ilm |
826 |
// incrémentation du numéro auto
|
90 |
ilm |
827 |
if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()).equalsIgnoreCase(this.numeroUniqueCommande.getText().trim())) {
|
18 |
ilm |
828 |
SQLRowValues rowVals = new SQLRowValues(this.tableNum);
|
|
|
829 |
int val = this.tableNum.getRow(2).getInt("COMMANDE_CLIENT_START");
|
|
|
830 |
val++;
|
|
|
831 |
rowVals.put("COMMANDE_CLIENT_START", new Integer(val));
|
|
|
832 |
|
|
|
833 |
try {
|
|
|
834 |
rowVals.update(2);
|
|
|
835 |
} catch (SQLException e) {
|
|
|
836 |
e.printStackTrace();
|
|
|
837 |
}
|
|
|
838 |
}
|
142 |
ilm |
839 |
if (attempt > 0) {
|
|
|
840 |
SwingUtilities.invokeLater(new Runnable() {
|
|
|
841 |
public void run() {
|
|
|
842 |
JOptionPane.showMessageDialog(null, "Le numéro a été actualisé en " + num);
|
|
|
843 |
}
|
|
|
844 |
});
|
18 |
ilm |
845 |
}
|
|
|
846 |
}
|
|
|
847 |
|
|
|
848 |
return idCommande;
|
|
|
849 |
}
|
|
|
850 |
|
|
|
851 |
@Override
|
142 |
ilm |
852 |
public Set<String> getPartialResetNames() {
|
|
|
853 |
Set<String> s = new HashSet<String>();
|
|
|
854 |
s.add("NOM");
|
|
|
855 |
s.add("NUMERO");
|
|
|
856 |
s.add("INFOS");
|
|
|
857 |
s.add("ID_CLIENT");
|
|
|
858 |
if (getTable().contains("ACOMPTE_COMMANDE")) {
|
|
|
859 |
s.add("ACOMPTE_COMMANDE");
|
|
|
860 |
}
|
|
|
861 |
return s;
|
|
|
862 |
}
|
|
|
863 |
|
|
|
864 |
@Override
|
18 |
ilm |
865 |
public void select(SQLRowAccessor r) {
|
28 |
ilm |
866 |
if (r == null || r.getIDNumber() == null)
|
|
|
867 |
super.select(r);
|
|
|
868 |
else {
|
|
|
869 |
System.err.println(r);
|
132 |
ilm |
870 |
final SQLRowValues rVals = r.asRowValues().deepCopy();
|
28 |
ilm |
871 |
final SQLRowValues vals = new SQLRowValues(r.getTable());
|
|
|
872 |
vals.load(rVals, createSet("ID_CLIENT"));
|
|
|
873 |
vals.setID(rVals.getID());
|
|
|
874 |
System.err.println("Select CLIENT");
|
|
|
875 |
super.select(vals);
|
|
|
876 |
rVals.remove("ID_CLIENT");
|
|
|
877 |
super.select(rVals);
|
|
|
878 |
}
|
18 |
ilm |
879 |
if (r != null) {
|
177 |
ilm |
880 |
this.table.getRowValuesTable().insertFrom(r);
|
|
|
881 |
this.tableFacturationItem.getRowValuesTable().insertFrom(r);
|
144 |
ilm |
882 |
if (this.tableChiffrageItem != null) {
|
177 |
ilm |
883 |
this.tableChiffrageItem.getRowValuesTable().insertFrom(r);
|
144 |
ilm |
884 |
}
|
18 |
ilm |
885 |
}
|
|
|
886 |
// this.radioEtat.setVisible(r.getID() > 1);
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
@Override
|
|
|
890 |
public void update() {
|
|
|
891 |
|
|
|
892 |
if (!this.numeroUniqueCommande.checkValidation()) {
|
|
|
893 |
ExceptionHandler.handle("Impossible d'ajouter, numéro de commande client existant.");
|
|
|
894 |
Object root = SwingUtilities.getRoot(this);
|
|
|
895 |
if (root instanceof EditFrame) {
|
|
|
896 |
EditFrame frame = (EditFrame) root;
|
|
|
897 |
frame.getPanel().setAlwaysVisible(true);
|
|
|
898 |
}
|
|
|
899 |
return;
|
|
|
900 |
}
|
|
|
901 |
super.update();
|
83 |
ilm |
902 |
final int id = getSelectedID();
|
|
|
903 |
this.table.updateField("ID_COMMANDE_CLIENT", id);
|
144 |
ilm |
904 |
this.tableFacturationItem.updateField("ID_COMMANDE_CLIENT", id);
|
|
|
905 |
if (this.tableChiffrageItem != null) {
|
|
|
906 |
this.tableChiffrageItem.updateField("ID_COMMANDE_CLIENT", id);
|
|
|
907 |
}
|
83 |
ilm |
908 |
this.table.createArticle(id, this.getElement());
|
18 |
ilm |
909 |
|
83 |
ilm |
910 |
final SQLRow row = getTable().getRow(id);
|
|
|
911 |
try {
|
|
|
912 |
updateStock(id);
|
|
|
913 |
} catch (SQLException e1) {
|
|
|
914 |
ExceptionHandler.handle("Erreur lors de la mise à du stock!", e1);
|
|
|
915 |
}
|
|
|
916 |
|
18 |
ilm |
917 |
// generation du document
|
25 |
ilm |
918 |
try {
|
83 |
ilm |
919 |
CommandeClientXmlSheet sheet = new CommandeClientXmlSheet(row);
|
25 |
ilm |
920 |
sheet.createDocumentAsynchronous();
|
|
|
921 |
sheet.showPrintAndExportAsynchronous(CommandeClientSQLComponent.this.panelOO.isVisualisationSelected(), CommandeClientSQLComponent.this.panelOO.isImpressionSelected(), true);
|
|
|
922 |
} catch (Exception e) {
|
|
|
923 |
ExceptionHandler.handle("Impossible de créer la commande", e);
|
|
|
924 |
}
|
|
|
925 |
|
18 |
ilm |
926 |
}
|
|
|
927 |
|
83 |
ilm |
928 |
protected String getLibelleStock(SQLRowAccessor row, SQLRowAccessor rowElt) {
|
|
|
929 |
return "Commande client N°" + row.getString("NUMERO");
|
|
|
930 |
}
|
|
|
931 |
|
|
|
932 |
/**
|
|
|
933 |
* Mise à jour des stocks pour chaque article composant la facture
|
|
|
934 |
*
|
|
|
935 |
* @throws SQLException
|
|
|
936 |
*/
|
|
|
937 |
private void updateStock(int id) throws SQLException {
|
|
|
938 |
|
|
|
939 |
SQLRow row = getTable().getRow(id);
|
|
|
940 |
StockItemsUpdater stockUpdater = new StockItemsUpdater(new StockLabel() {
|
|
|
941 |
@Override
|
|
|
942 |
public String getLabel(SQLRowAccessor rowOrigin, SQLRowAccessor rowElt) {
|
|
|
943 |
return getLibelleStock(rowOrigin, rowElt);
|
|
|
944 |
}
|
93 |
ilm |
945 |
}, row, row.getReferentRows(getTable().getTable("COMMANDE_CLIENT_ELEMENT")), TypeStockUpdate.VIRTUAL_DELIVER);
|
83 |
ilm |
946 |
|
|
|
947 |
stockUpdater.update();
|
|
|
948 |
}
|
|
|
949 |
|
18 |
ilm |
950 |
public void setDefaults() {
|
|
|
951 |
this.resetValue();
|
90 |
ilm |
952 |
this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
|
18 |
ilm |
953 |
this.table.getModel().clearRows();
|
|
|
954 |
}
|
|
|
955 |
|
|
|
956 |
/**
|
|
|
957 |
* Création d'une commande à partir d'un devis
|
|
|
958 |
*
|
|
|
959 |
* @param idDevis
|
|
|
960 |
*
|
|
|
961 |
*/
|
|
|
962 |
public void loadDevis(int idDevis) {
|
|
|
963 |
|
|
|
964 |
SQLElement devis = Configuration.getInstance().getDirectory().getElement("DEVIS");
|
|
|
965 |
SQLElement devisElt = Configuration.getInstance().getDirectory().getElement("DEVIS_ELEMENT");
|
|
|
966 |
|
|
|
967 |
if (idDevis > 1) {
|
|
|
968 |
SQLInjector injector = SQLInjector.getInjector(devis.getTable(), this.getTable());
|
19 |
ilm |
969 |
SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(idDevis);
|
|
|
970 |
SQLRow rowDevis = devis.getTable().getRow(idDevis);
|
|
|
971 |
|
|
|
972 |
String string = rowDevis.getString("OBJET");
|
|
|
973 |
createRowValuesFrom.put("NOM", string + (string.trim().length() == 0 ? "" : ",") + rowDevis.getString("NUMERO"));
|
|
|
974 |
this.select(createRowValuesFrom);
|
18 |
ilm |
975 |
}
|
|
|
976 |
|
|
|
977 |
loadItem(this.table, devis, idDevis, devisElt);
|
|
|
978 |
}
|
|
|
979 |
|
|
|
980 |
@Override
|
|
|
981 |
protected SQLRowValues createDefaults() {
|
|
|
982 |
SQLRowValues rowVals = new SQLRowValues(getTable());
|
|
|
983 |
rowVals.put("T_POIDS", 0.0F);
|
90 |
ilm |
984 |
rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(getElement().getClass(), new Date()));
|
18 |
ilm |
985 |
// User
|
|
|
986 |
// SQLSelect sel = new SQLSelect(Configuration.getInstance().getBase());
|
|
|
987 |
SQLElement eltComm = Configuration.getInstance().getDirectory().getElement("COMMERCIAL");
|
|
|
988 |
int idUser = UserManager.getInstance().getCurrentUser().getId();
|
|
|
989 |
//
|
|
|
990 |
// sel.addSelect(eltComm.getTable().getKey());
|
|
|
991 |
// sel.setWhere(new Where(eltComm.getTable().getField("ID_USER_COMMON"), "=", idUser));
|
|
|
992 |
// List<SQLRow> rowsComm = (List<SQLRow>)
|
|
|
993 |
// Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new
|
|
|
994 |
// SQLRowListRSH(eltComm.getTable()));
|
|
|
995 |
SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(eltComm.getTable()).getFirstRowContains(idUser, eltComm.getTable().getField("ID_USER_COMMON"));
|
|
|
996 |
|
|
|
997 |
if (rowsComm != null) {
|
|
|
998 |
rowVals.put("ID_COMMERCIAL", rowsComm.getID());
|
|
|
999 |
}
|
93 |
ilm |
1000 |
if (getTable().contains("ETAT_COMMANDE")) {
|
|
|
1001 |
rowVals.put("ETAT_COMMANDE", EtatCommandeClient.A_PREPARER.getId());
|
|
|
1002 |
}
|
|
|
1003 |
if (getTable().contains("ID_TAXE_PORT")) {
|
|
|
1004 |
SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
|
|
|
1005 |
rowVals.put("ID_TAXE_PORT", taxeDefault.getID());
|
|
|
1006 |
}
|
|
|
1007 |
|
156 |
ilm |
1008 |
if (getTable().contains("ID_TAXE_FRAIS_DOCUMENT")) {
|
|
|
1009 |
SQLRow taxeDefault = TaxeCache.getCache().getFirstTaxe();
|
|
|
1010 |
rowVals.put("ID_TAXE_FRAIS_DOCUMENT", taxeDefault.getID());
|
|
|
1011 |
}
|
|
|
1012 |
|
18 |
ilm |
1013 |
return rowVals;
|
|
|
1014 |
}
|
93 |
ilm |
1015 |
|
|
|
1016 |
@Override
|
|
|
1017 |
protected void refreshAfterSelect(SQLRowAccessor r) {
|
|
|
1018 |
if (this.dateCommande.getValue() != null && r.getObject("DATE") != null) {
|
|
|
1019 |
this.table.setDateDevise(r.getDate("DATE").getTime());
|
|
|
1020 |
}
|
|
|
1021 |
}
|
180 |
ilm |
1022 |
|
|
|
1023 |
/**
|
|
|
1024 |
* Création d'une commande à partir d'un devis existant
|
|
|
1025 |
*
|
|
|
1026 |
* @param idCommande
|
|
|
1027 |
*
|
|
|
1028 |
*/
|
|
|
1029 |
public void loadCommandeExistant(final int idCommande) {
|
|
|
1030 |
|
|
|
1031 |
final SQLElement commande =getElement();
|
|
|
1032 |
final SQLElement commandeElt = getElement().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
|
|
|
1033 |
|
|
|
1034 |
// On duplique la commande
|
|
|
1035 |
if (idCommande > 1) {
|
|
|
1036 |
final SQLRow row = getTable().getRow(idCommande);
|
|
|
1037 |
final SQLRowValues rowVals = new SQLRowValues(getTable());
|
|
|
1038 |
rowVals.put("ID_CLIENT", row.getInt("ID_CLIENT"));
|
|
|
1039 |
if (row.getObject("ID_TARIF") != null && !row.isForeignEmpty("ID_TARIF")) {
|
|
|
1040 |
rowVals.put("ID_TARIF", row.getInt("ID_TARIF"));
|
|
|
1041 |
}
|
|
|
1042 |
rowVals.put("NUMERO", NumerotationAutoSQLElement.getNextNumero(getElement().getClass()));
|
|
|
1043 |
|
|
|
1044 |
this.select(rowVals);
|
|
|
1045 |
}
|
|
|
1046 |
|
|
|
1047 |
// On duplique les elements des commandes
|
|
|
1048 |
final List<SQLRow> myListItem = getTable().getRow(idCommande).getReferentRows(commandeElt.getTable());
|
|
|
1049 |
|
|
|
1050 |
if (myListItem.size() != 0) {
|
|
|
1051 |
this.table.getModel().clearRows();
|
|
|
1052 |
|
|
|
1053 |
for (final SQLRow rowElt : myListItem) {
|
|
|
1054 |
|
|
|
1055 |
final SQLRowValues rowVals = rowElt.createUpdateRow();
|
|
|
1056 |
rowVals.clearPrimaryKeys();
|
|
|
1057 |
this.table.getModel().addRow(rowVals);
|
|
|
1058 |
final int rowIndex = this.table.getModel().getRowCount() - 1;
|
|
|
1059 |
this.table.getModel().fireTableModelModified(rowIndex);
|
|
|
1060 |
}
|
|
|
1061 |
} else {
|
|
|
1062 |
this.table.getModel().clearRows();
|
|
|
1063 |
}
|
|
|
1064 |
this.table.getModel().fireTableDataChanged();
|
|
|
1065 |
this.table.repaint();
|
|
|
1066 |
}
|
|
|
1067 |
|
18 |
ilm |
1068 |
}
|