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.supplychain.order.component;
|
|
|
15 |
|
63 |
ilm |
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
18 |
ilm |
17 |
import org.openconcerto.erp.core.common.ui.DeviseField;
|
|
|
18 |
import org.openconcerto.erp.core.common.ui.MontantPanel;
|
|
|
19 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement;
|
|
|
20 |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement;
|
80 |
ilm |
21 |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
|
18 |
ilm |
22 |
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieAchat;
|
|
|
23 |
import org.openconcerto.erp.model.ISQLCompteSelector;
|
|
|
24 |
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel;
|
|
|
25 |
import org.openconcerto.sql.Configuration;
|
|
|
26 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
27 |
import org.openconcerto.sql.element.ElementSQLObject;
|
|
|
28 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
29 |
import org.openconcerto.sql.model.SQLBackgroundTableCache;
|
|
|
30 |
import org.openconcerto.sql.model.SQLInjector;
|
|
|
31 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
32 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
33 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
34 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
35 |
import org.openconcerto.sql.model.Where;
|
|
|
36 |
import org.openconcerto.sql.sqlobject.ElementComboBox;
|
|
|
37 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
|
|
38 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
25 |
ilm |
39 |
import org.openconcerto.ui.FormLayouter;
|
18 |
ilm |
40 |
import org.openconcerto.ui.JDate;
|
|
|
41 |
import org.openconcerto.ui.TitledSeparator;
|
|
|
42 |
import org.openconcerto.ui.component.ITextArea;
|
21 |
ilm |
43 |
import org.openconcerto.utils.checks.ValidState;
|
18 |
ilm |
44 |
import org.openconcerto.utils.text.SimpleDocumentListener;
|
|
|
45 |
|
|
|
46 |
import java.awt.GridBagConstraints;
|
|
|
47 |
import java.awt.GridBagLayout;
|
|
|
48 |
import java.awt.Insets;
|
|
|
49 |
import java.beans.PropertyChangeEvent;
|
|
|
50 |
import java.beans.PropertyChangeListener;
|
|
|
51 |
import java.sql.SQLException;
|
80 |
ilm |
52 |
import java.util.HashSet;
|
|
|
53 |
import java.util.Set;
|
18 |
ilm |
54 |
|
|
|
55 |
import javax.swing.JCheckBox;
|
|
|
56 |
import javax.swing.JLabel;
|
|
|
57 |
import javax.swing.JOptionPane;
|
|
|
58 |
import javax.swing.JPanel;
|
|
|
59 |
import javax.swing.JScrollPane;
|
|
|
60 |
import javax.swing.JTextField;
|
|
|
61 |
import javax.swing.SwingConstants;
|
|
|
62 |
import javax.swing.event.DocumentEvent;
|
|
|
63 |
|
|
|
64 |
public class SaisieAchatSQLComponent extends BaseSQLComponent {
|
|
|
65 |
|
|
|
66 |
public SaisieAchatSQLComponent(SQLElement element) {
|
|
|
67 |
super(element);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private JTextField textNumeroFacture;
|
|
|
71 |
private JTextField textNumeroCmd;
|
|
|
72 |
private JTextField textSource, textIdSource;
|
|
|
73 |
|
|
|
74 |
private DeviseField fieldMontantRegle = new DeviseField();
|
61 |
ilm |
75 |
final ISQLCompteSelector compteSel = new ISQLCompteSelector();
|
18 |
ilm |
76 |
|
|
|
77 |
private JCheckBox checkImmo;
|
80 |
ilm |
78 |
|
18 |
ilm |
79 |
private MontantPanel montant;
|
|
|
80 |
private ElementComboBox nomFournisseur;
|
|
|
81 |
private ElementComboBox comboAvoir;
|
61 |
ilm |
82 |
protected ElementSQLObject eltModeRegl;
|
80 |
ilm |
83 |
|
18 |
ilm |
84 |
private PropertyChangeListener listenerModeReglDefaut = new PropertyChangeListener() {
|
|
|
85 |
|
|
|
86 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
87 |
|
73 |
ilm |
88 |
SQLRow rowFourn = SaisieAchatSQLComponent.this.nomFournisseur.getRequest().getPrimaryTable().getRow(nomFournisseur.getWantedID());
|
18 |
ilm |
89 |
|
61 |
ilm |
90 |
if (!isFilling() && rowFourn != null && !rowFourn.isUndefined()) {
|
18 |
ilm |
91 |
SaisieAchatSQLComponent.this.montant.setUE(rowFourn.getBoolean("UE"));
|
|
|
92 |
|
61 |
ilm |
93 |
SQLRow rowCharge = rowFourn.getForeign("ID_COMPTE_PCE_CHARGE");
|
|
|
94 |
if (rowCharge != null && !rowCharge.isUndefined()) {
|
|
|
95 |
compteSel.setValue(rowCharge);
|
18 |
ilm |
96 |
}
|
80 |
ilm |
97 |
|
61 |
ilm |
98 |
int idModeRegl = rowFourn.getInt("ID_MODE_REGLEMENT");
|
|
|
99 |
if (idModeRegl > 1 && SaisieAchatSQLComponent.this.eltModeRegl != null && getMode() == Mode.INSERTION) {
|
|
|
100 |
SQLElement sqlEltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
|
|
|
101 |
SQLRow rowModeRegl = sqlEltModeRegl.getTable().getRow(idModeRegl);
|
|
|
102 |
SQLRowValues rowVals = rowModeRegl.createUpdateRow();
|
|
|
103 |
rowVals.clearPrimaryKeys();
|
|
|
104 |
SaisieAchatSQLComponent.this.eltModeRegl.setValue(rowVals);
|
|
|
105 |
System.err.println("Select Mode regl " + idModeRegl);
|
|
|
106 |
}
|
|
|
107 |
// }
|
18 |
ilm |
108 |
}
|
80 |
ilm |
109 |
|
18 |
ilm |
110 |
}
|
|
|
111 |
|
|
|
112 |
};
|
|
|
113 |
|
|
|
114 |
public void addViews() {
|
|
|
115 |
this.setLayout(new GridBagLayout());
|
|
|
116 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
117 |
|
|
|
118 |
// Source de la saisie --> Commande, BR
|
|
|
119 |
this.textIdSource = new JTextField();
|
|
|
120 |
this.textSource = new JTextField();
|
|
|
121 |
|
|
|
122 |
/*******************************************************************************************
|
|
|
123 |
* * RENSEIGNEMENTS
|
|
|
124 |
******************************************************************************************/
|
|
|
125 |
|
|
|
126 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
127 |
c.gridheight = 1;
|
|
|
128 |
|
|
|
129 |
c.gridy++;
|
|
|
130 |
c.gridwidth = 1;
|
|
|
131 |
c.gridx = 0;
|
|
|
132 |
|
|
|
133 |
// libellé
|
|
|
134 |
JLabel labelLibelle = new JLabel("Achat de ");
|
|
|
135 |
SQLTextCombo textLibelle = new SQLTextCombo();
|
|
|
136 |
c.weightx = 0;
|
|
|
137 |
labelLibelle.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
138 |
this.add(labelLibelle, c);
|
|
|
139 |
c.gridx++;
|
|
|
140 |
c.weightx = 1;
|
|
|
141 |
c.fill = GridBagConstraints.BOTH;
|
41 |
ilm |
142 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
18 |
ilm |
143 |
this.add(textLibelle, c);
|
|
|
144 |
|
41 |
ilm |
145 |
// Champ Module
|
|
|
146 |
c.gridx = 0;
|
|
|
147 |
c.gridy++;
|
|
|
148 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
63 |
ilm |
149 |
final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
|
41 |
ilm |
150 |
this.setAdditionalFieldsPanel(new FormLayouter(addP, 1));
|
|
|
151 |
this.add(addP, c);
|
18 |
ilm |
152 |
|
41 |
ilm |
153 |
c.gridy++;
|
|
|
154 |
c.gridwidth = 1;
|
18 |
ilm |
155 |
|
|
|
156 |
// Fournisseurs
|
|
|
157 |
c.gridy++;
|
|
|
158 |
c.gridx = 0;
|
|
|
159 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
160 |
c.weightx = 0;
|
|
|
161 |
|
|
|
162 |
this.add(new JLabel("Fournisseur", SwingConstants.RIGHT), c);
|
|
|
163 |
c.gridx++;
|
|
|
164 |
|
|
|
165 |
c.gridwidth = 4;
|
|
|
166 |
c.weightx = 1;
|
|
|
167 |
c.weighty = 0;
|
|
|
168 |
c.fill = GridBagConstraints.NONE;
|
|
|
169 |
this.nomFournisseur = new ElementComboBox();
|
|
|
170 |
this.add(this.nomFournisseur, c);
|
|
|
171 |
|
|
|
172 |
// Ligne 3 : Compte de charges
|
|
|
173 |
c.gridy++;
|
|
|
174 |
c.weightx = 0;
|
|
|
175 |
c.gridx = 0;
|
|
|
176 |
c.fill = GridBagConstraints.HORIZONTAL;
|
61 |
ilm |
177 |
c.gridwidth = 1;
|
|
|
178 |
this.add(new JLabel(getLabelFor("ID_COMPTE_PCE"), SwingConstants.RIGHT), c);
|
18 |
ilm |
179 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
180 |
c.gridx++;
|
|
|
181 |
c.weightx = 1;
|
|
|
182 |
this.add(compteSel, c);
|
|
|
183 |
|
|
|
184 |
c.gridwidth = 1;
|
|
|
185 |
c.weightx = 0;
|
|
|
186 |
c.gridx = 0;
|
|
|
187 |
c.gridy++;
|
|
|
188 |
c.gridwidth = 1;
|
61 |
ilm |
189 |
this.add(new JLabel(getLabelFor("NUMERO_FACTURE"), SwingConstants.RIGHT), c);
|
18 |
ilm |
190 |
|
|
|
191 |
this.textNumeroFacture = new JTextField(16);
|
|
|
192 |
DefaultGridBagConstraints.lockMinimumSize(textNumeroFacture);
|
|
|
193 |
c.gridx = 1;
|
|
|
194 |
c.gridwidth = 1;
|
|
|
195 |
this.add(this.textNumeroFacture, c);
|
|
|
196 |
|
41 |
ilm |
197 |
// Date
|
|
|
198 |
|
|
|
199 |
c.gridx++;
|
|
|
200 |
c.weightx = 0;
|
|
|
201 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
202 |
this.add(new JLabel("Date"), c);
|
|
|
203 |
c.gridx++;
|
|
|
204 |
c.weightx = 1;
|
80 |
ilm |
205 |
JDate dateSaisie = new JDate();
|
41 |
ilm |
206 |
c.fill = GridBagConstraints.NONE;
|
|
|
207 |
|
|
|
208 |
this.add(dateSaisie, c);
|
|
|
209 |
|
18 |
ilm |
210 |
c.gridx = 0;
|
|
|
211 |
c.gridy++;
|
61 |
ilm |
212 |
c.fill = GridBagConstraints.HORIZONTAL;
|
18 |
ilm |
213 |
c.gridwidth = 1;
|
80 |
ilm |
214 |
|
61 |
ilm |
215 |
this.add(new JLabel(getLabelFor("NUMERO_COMMANDE"), SwingConstants.RIGHT), c);
|
18 |
ilm |
216 |
|
|
|
217 |
this.textNumeroCmd = new JTextField(16);
|
|
|
218 |
c.gridx = 1;
|
|
|
219 |
c.gridwidth = 1;
|
|
|
220 |
DefaultGridBagConstraints.lockMinimumSize(textNumeroCmd);
|
|
|
221 |
this.add(this.textNumeroCmd, c);
|
|
|
222 |
|
|
|
223 |
c.gridx++;
|
|
|
224 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
225 |
c.weightx = 1;
|
|
|
226 |
c.anchor = GridBagConstraints.EAST;
|
|
|
227 |
this.checkImmo = new JCheckBox(getLabelFor("IMMO"));
|
|
|
228 |
this.add(this.checkImmo, c);
|
|
|
229 |
c.anchor = GridBagConstraints.WEST;
|
|
|
230 |
|
|
|
231 |
// MONTANT
|
|
|
232 |
c.gridx = 0;
|
|
|
233 |
c.gridy++;
|
80 |
ilm |
234 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
235 |
c.gridwidth = 1;
|
|
|
236 |
c.weightx = 0;
|
|
|
237 |
this.add(new JLabel("Montant", SwingConstants.RIGHT), c);
|
18 |
ilm |
238 |
|
80 |
ilm |
239 |
c.gridx = 1;
|
|
|
240 |
c.gridwidth = 3;
|
18 |
ilm |
241 |
c.weightx = 1;
|
|
|
242 |
c.anchor = GridBagConstraints.WEST;
|
|
|
243 |
c.fill = GridBagConstraints.NONE;
|
|
|
244 |
this.montant = new MontantPanel();
|
|
|
245 |
this.add(this.montant, c);
|
|
|
246 |
|
|
|
247 |
// Avoir
|
|
|
248 |
JPanel panelAvoir = new JPanel();
|
|
|
249 |
this.comboAvoir = new ElementComboBox(true);
|
80 |
ilm |
250 |
|
18 |
ilm |
251 |
this.comboAvoir.setAddIconVisible(false);
|
|
|
252 |
panelAvoir.add(this.comboAvoir);
|
|
|
253 |
|
83 |
ilm |
254 |
panelAvoir.add(new JLabel("Montant à régler"));
|
18 |
ilm |
255 |
panelAvoir.add(this.fieldMontantRegle);
|
|
|
256 |
this.fieldMontantRegle.setEditable(false);
|
|
|
257 |
c.gridx = 0;
|
|
|
258 |
c.gridy++;
|
80 |
ilm |
259 |
c.gridwidth = 1;
|
|
|
260 |
c.weightx = 0;
|
|
|
261 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
262 |
this.add(new JLabel(getLabelFor("ID_AVOIR_FOURNISSEUR"), SwingConstants.RIGHT), c);
|
|
|
263 |
c.gridx++;
|
18 |
ilm |
264 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
265 |
c.fill = GridBagConstraints.NONE;
|
|
|
266 |
this.add(panelAvoir, c);
|
|
|
267 |
|
|
|
268 |
/*******************************************************************************************
|
|
|
269 |
* * MODE DE REGLEMENT
|
|
|
270 |
******************************************************************************************/
|
|
|
271 |
|
|
|
272 |
// Mode de règlement
|
|
|
273 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
274 |
c.gridx = 0;
|
|
|
275 |
c.gridy++;
|
|
|
276 |
c.insets = new Insets(10, 2, 1, 2);
|
|
|
277 |
c.fill = GridBagConstraints.HORIZONTAL;
|
80 |
ilm |
278 |
TitledSeparator sep = new TitledSeparator("Mode de règlement");
|
18 |
ilm |
279 |
|
|
|
280 |
this.add(sep, c);
|
|
|
281 |
|
|
|
282 |
c.insets = new Insets(2, 2, 1, 2);
|
|
|
283 |
|
|
|
284 |
c.gridx = 0;
|
|
|
285 |
c.gridy++;
|
|
|
286 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
287 |
this.addView("ID_MODE_REGLEMENT", REQ + ";" + DEC + ";" + SEP);
|
|
|
288 |
this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
|
|
|
289 |
this.add(this.eltModeRegl, c);
|
|
|
290 |
|
|
|
291 |
/*******************************************************************************************
|
|
|
292 |
* * INFORMATIONS COMPLEMENTAIRES
|
|
|
293 |
******************************************************************************************/
|
|
|
294 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
295 |
c.gridx = 0;
|
|
|
296 |
c.gridy++;
|
|
|
297 |
sep = new TitledSeparator("Informations complémentaires");
|
|
|
298 |
c.insets = new Insets(10, 2, 1, 2);
|
|
|
299 |
this.add(sep, c);
|
|
|
300 |
c.insets = new Insets(2, 2, 1, 2);
|
|
|
301 |
|
|
|
302 |
c.gridx = 0;
|
|
|
303 |
c.gridy++;
|
|
|
304 |
c.gridheight = GridBagConstraints.REMAINDER;
|
|
|
305 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
306 |
c.weighty = 1;
|
|
|
307 |
c.weightx = 1;
|
|
|
308 |
c.fill = GridBagConstraints.BOTH;
|
|
|
309 |
ITextArea textInfos = new ITextArea(4, 4);
|
|
|
310 |
|
|
|
311 |
JScrollPane scrollPane = new JScrollPane(textInfos);
|
|
|
312 |
DefaultGridBagConstraints.lockMinimumSize(scrollPane);
|
|
|
313 |
|
|
|
314 |
this.add(textInfos, c);
|
|
|
315 |
|
|
|
316 |
this.addSQLObject(textInfos, "INFOS");
|
|
|
317 |
this.addRequiredSQLObject(dateSaisie, "DATE");
|
|
|
318 |
this.addRequiredSQLObject(this.nomFournisseur, "ID_FOURNISSEUR");
|
|
|
319 |
this.addRequiredSQLObject(this.montant.getChoixTaxe(), "ID_TAXE");
|
|
|
320 |
this.addRequiredSQLObject(this.montant.getMontantTTC(), "MONTANT_TTC");
|
|
|
321 |
this.addRequiredSQLObject(this.montant.getMontantHT(), "MONTANT_HT");
|
|
|
322 |
this.addRequiredSQLObject(this.montant.getMontantTVA(), "MONTANT_TVA");
|
|
|
323 |
this.addSQLObject(textLibelle, "NOM");
|
|
|
324 |
this.addSQLObject(this.textNumeroFacture, "NUMERO_FACTURE");
|
|
|
325 |
this.addSQLObject(this.textNumeroCmd, "NUMERO_COMMANDE");
|
|
|
326 |
this.addSQLObject(this.textIdSource, "IDSOURCE");
|
|
|
327 |
this.addSQLObject(this.textSource, "SOURCE");
|
|
|
328 |
this.addRequiredSQLObject(compteSel, "ID_COMPTE_PCE");
|
|
|
329 |
this.addSQLObject(this.comboAvoir, "ID_AVOIR_FOURNISSEUR");
|
|
|
330 |
this.addSQLObject(this.checkImmo, "IMMO");
|
|
|
331 |
|
177 |
ilm |
332 |
this.montant.setChoixTaxe(TaxeCache.getCache().getFirstTaxeAchat().getID());
|
18 |
ilm |
333 |
|
73 |
ilm |
334 |
this.nomFournisseur.addModelListener("wantedID", this.listenerModeReglDefaut);
|
18 |
ilm |
335 |
|
|
|
336 |
this.montant.getMontantTTC().getDocument().addDocumentListener(new SimpleDocumentListener() {
|
|
|
337 |
@Override
|
|
|
338 |
public void update(DocumentEvent e) {
|
|
|
339 |
refreshText();
|
|
|
340 |
}
|
|
|
341 |
});
|
|
|
342 |
|
180 |
ilm |
343 |
this.comboAvoir.addModelListener("wantedID", new PropertyChangeListener() {
|
18 |
ilm |
344 |
@Override
|
|
|
345 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
346 |
refreshText();
|
|
|
347 |
}
|
|
|
348 |
});
|
|
|
349 |
|
|
|
350 |
final SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR").getTable();
|
|
|
351 |
this.nomFournisseur.addValueListener(new PropertyChangeListener() {
|
|
|
352 |
@Override
|
|
|
353 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
354 |
|
|
|
355 |
Where w = new Where(tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
|
|
|
356 |
if (SaisieAchatSQLComponent.this.nomFournisseur.isEmpty()) {
|
|
|
357 |
w.and(new Where(getTable().getBase().getTable("AVOIR_FOURNISSEUR").getField("ID_FOURNISSEUR"), "=", -1));
|
|
|
358 |
} else {
|
|
|
359 |
w.and(new Where(getTable().getBase().getTable("AVOIR_FOURNISSEUR").getField("ID_FOURNISSEUR"), "=", SaisieAchatSQLComponent.this.nomFournisseur.getValue()));
|
|
|
360 |
}
|
|
|
361 |
if (getSelectedID() > 1) {
|
|
|
362 |
SQLRow row = getTable().getRow(getSelectedID());
|
|
|
363 |
w = w.or(new Where(getTable().getBase().getTable("AVOIR_FOURNISSEUR").getKey(), "=", row.getInt("ID_AVOIR_FOURNISSEUR")));
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
SaisieAchatSQLComponent.this.comboAvoir.getRequest().setWhere(null);
|
|
|
367 |
SaisieAchatSQLComponent.this.comboAvoir.getRequest().setWhere(w);
|
|
|
368 |
SaisieAchatSQLComponent.this.comboAvoir.fillCombo();
|
|
|
369 |
}
|
|
|
370 |
});
|
|
|
371 |
|
|
|
372 |
Where w = new Where(tableAvoir.getField("SOLDE"), "=", Boolean.FALSE);
|
|
|
373 |
this.comboAvoir.getRequest().setWhere(w);
|
|
|
374 |
this.comboAvoir.fillCombo();
|
|
|
375 |
|
|
|
376 |
// Lock UI
|
|
|
377 |
DefaultGridBagConstraints.lockMinimumSize(nomFournisseur);
|
|
|
378 |
DefaultGridBagConstraints.lockMinimumSize(panelAvoir);
|
|
|
379 |
DefaultGridBagConstraints.lockMinimumSize(montant);
|
|
|
380 |
DefaultGridBagConstraints.lockMaximumSize(montant);
|
|
|
381 |
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
@Override
|
21 |
ilm |
385 |
public ValidState getValidState() {
|
|
|
386 |
ValidState result = super.getValidState();
|
|
|
387 |
if (result.isValid()) {
|
73 |
ilm |
388 |
if (this.montant.getMontantTTC() != null && this.montant.getMontantTTC().getValue() != null) {
|
18 |
ilm |
389 |
|
73 |
ilm |
390 |
long l = this.montant.getMontantTTC().getValue();
|
18 |
ilm |
391 |
|
21 |
ilm |
392 |
if (this.comboAvoir != null && !this.comboAvoir.isEmpty() && this.comboAvoir.getSelectedId() > 1) {
|
|
|
393 |
SQLElement eltAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR");
|
|
|
394 |
SQLRow rowAvoir = eltAvoir.getTable().getRow(this.comboAvoir.getSelectedId());
|
|
|
395 |
l -= ((Number) rowAvoir.getObject("MONTANT_TTC")).longValue();
|
|
|
396 |
}
|
|
|
397 |
if (l < 0) {
|
|
|
398 |
result = new ValidState(false, "Le montant est négatif");
|
|
|
399 |
}
|
18 |
ilm |
400 |
}
|
|
|
401 |
}
|
21 |
ilm |
402 |
return result;
|
18 |
ilm |
403 |
}
|
|
|
404 |
|
|
|
405 |
/***********************************************************************************************
|
|
|
406 |
* * GENERATION DU MOUVEMENT ET DES ECRITURES ASSOCIEES A L'INSERTION
|
|
|
407 |
**********************************************************************************************/
|
|
|
408 |
public int insert(SQLRow order) {
|
|
|
409 |
final int id = super.insert(order);
|
|
|
410 |
|
|
|
411 |
// on solde l'avoir
|
|
|
412 |
if (this.comboAvoir.getSelectedId() > 1) {
|
|
|
413 |
SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR").getTable();
|
|
|
414 |
SQLRow rowAvoir = tableAvoir.getRow(this.comboAvoir.getSelectedId());
|
|
|
415 |
SQLRowValues rowVals = rowAvoir.createEmptyUpdateRow();
|
|
|
416 |
rowVals.put("SOLDE", Boolean.TRUE);
|
|
|
417 |
try {
|
|
|
418 |
rowVals.update();
|
|
|
419 |
} catch (SQLException e) {
|
|
|
420 |
e.printStackTrace();
|
|
|
421 |
}
|
|
|
422 |
}
|
94 |
ilm |
423 |
new Thread(new GenerationMvtSaisieAchat(getTable().getRow(id))).start();
|
18 |
ilm |
424 |
return id;
|
|
|
425 |
}
|
|
|
426 |
|
80 |
ilm |
427 |
@Override
|
|
|
428 |
public Set<String> getPartialResetNames() {
|
|
|
429 |
Set<String> s = new HashSet<String>();
|
|
|
430 |
s.addAll(super.getPartialResetNames());
|
|
|
431 |
s.add("INFOS");
|
|
|
432 |
s.add("NUMERO_FACTURE");
|
|
|
433 |
s.add("NUMERO_COMMANDE");
|
|
|
434 |
s.add("MONTANT_HT");
|
|
|
435 |
return s;
|
|
|
436 |
}
|
|
|
437 |
|
18 |
ilm |
438 |
public void select(SQLRowAccessor r) {
|
|
|
439 |
|
|
|
440 |
// FIXME probleme selection du mode de reglement par defaut -> l'id est celui du défaut dans
|
|
|
441 |
// la saisie
|
|
|
442 |
|
|
|
443 |
super.select(r);
|
|
|
444 |
|
|
|
445 |
if (r != null) {
|
|
|
446 |
System.err.println(r);
|
|
|
447 |
this.montant.calculMontant();
|
|
|
448 |
Object idF = r.getObject("ID_FOURNISSEUR");
|
|
|
449 |
System.err.println("Founisseur " + idF);
|
|
|
450 |
if (idF != null) {
|
|
|
451 |
int idSeleted = Integer.valueOf(idF.toString());
|
|
|
452 |
|
|
|
453 |
if (idSeleted > 1) {
|
|
|
454 |
SQLElement fournisseur = Configuration.getInstance().getDirectory().getElement("FOURNISSEUR");
|
|
|
455 |
SQLRow rowFourn = fournisseur.getTable().getRow(idSeleted);
|
|
|
456 |
this.montant.setUE(rowFourn.getBoolean("UE"));
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
System.out.println("select id Saisie Achat " + r.getID());
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
final SQLTable tablePrefCompte = getTable().getTable("PREFS_COMPTE");
|
|
|
464 |
|
|
|
465 |
@Override
|
|
|
466 |
protected SQLRowValues createDefaults() {
|
|
|
467 |
SQLRowValues vals = new SQLRowValues(this.getTable());
|
|
|
468 |
SQLRow r;
|
|
|
469 |
|
|
|
470 |
try {
|
|
|
471 |
r = ModeReglementDefautPrefPanel.getDefaultRow(false);
|
|
|
472 |
SQLElement eltModeReglement = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT");
|
|
|
473 |
|
|
|
474 |
if (r.getID() > 1) {
|
|
|
475 |
SQLRowValues rowVals = eltModeReglement.createCopy(r, null);
|
|
|
476 |
System.err.println("Primary Keys " + rowVals.getID());
|
|
|
477 |
rowVals.clearPrimaryKeys();
|
|
|
478 |
System.err.println(rowVals.getInt("ID_TYPE_REGLEMENT"));
|
|
|
479 |
vals.put("ID_MODE_REGLEMENT", rowVals);
|
|
|
480 |
}
|
|
|
481 |
} catch (SQLException e) {
|
|
|
482 |
System.err.println("Impossible de sélectionner le mode de règlement par défaut du client.");
|
|
|
483 |
e.printStackTrace();
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
// Select Compte charge par defaut
|
|
|
487 |
|
|
|
488 |
final SQLRow rowPrefsCompte = SQLBackgroundTableCache.getInstance().getCacheForTable(tablePrefCompte).getRowFromId(2);
|
|
|
489 |
// compte Achat
|
|
|
490 |
int idCompteAchat = rowPrefsCompte.getInt("ID_COMPTE_PCE_ACHAT");
|
|
|
491 |
if (idCompteAchat <= 1) {
|
|
|
492 |
try {
|
|
|
493 |
idCompteAchat = ComptePCESQLElement.getIdComptePceDefault("Achats");
|
|
|
494 |
} catch (Exception e) {
|
|
|
495 |
e.printStackTrace();
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
vals.put("ID_COMPTE_PCE", idCompteAchat);
|
177 |
ilm |
499 |
vals.put("ID_TAXE", TaxeCache.getCache().getFirstTaxeAchat().getID());
|
80 |
ilm |
500 |
|
18 |
ilm |
501 |
return vals;
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
public void update() {
|
|
|
505 |
if (JOptionPane.showConfirmDialog(this, "Attention en modifiant cette facture, vous supprimerez les chéques et les échéances associés. Continuer?", "Modification de facture",
|
|
|
506 |
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
|
|
507 |
super.update();
|
|
|
508 |
|
|
|
509 |
// on solde l'avoir
|
|
|
510 |
if (this.comboAvoir.getSelectedId() > 1) {
|
|
|
511 |
SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR").getTable();
|
|
|
512 |
SQLRow rowAvoir = tableAvoir.getRow(this.comboAvoir.getSelectedId());
|
|
|
513 |
SQLRowValues rowVals = rowAvoir.createEmptyUpdateRow();
|
|
|
514 |
rowVals.put("SOLDE", Boolean.TRUE);
|
|
|
515 |
try {
|
|
|
516 |
rowVals.update();
|
|
|
517 |
} catch (SQLException e) {
|
|
|
518 |
e.printStackTrace();
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
SQLRow row = getTable().getRow(this.getSelectedID());
|
|
|
523 |
int idMvt = row.getInt("ID_MOUVEMENT");
|
|
|
524 |
System.err.println("__________***************** UPDATE" + idMvt);
|
|
|
525 |
|
|
|
526 |
// on supprime tout ce qui est lié à la facture
|
|
|
527 |
EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE");
|
|
|
528 |
eltEcr.archiveMouvementProfondeur(idMvt, false);
|
|
|
529 |
|
|
|
530 |
// regenere les ecritures
|
142 |
ilm |
531 |
new Thread(new GenerationMvtSaisieAchat(row)).start();
|
18 |
ilm |
532 |
}
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
private void refreshText() {
|
73 |
ilm |
536 |
Number n = this.montant.getMontantTTC().getValue();
|
180 |
ilm |
537 |
if (this.comboAvoir.getWantedID() > 1) {
|
18 |
ilm |
538 |
SQLTable tableAvoir = Configuration.getInstance().getDirectory().getElement("AVOIR_FOURNISSEUR").getTable();
|
|
|
539 |
if (n != null) {
|
|
|
540 |
long ttc = n.longValue();
|
180 |
ilm |
541 |
SQLRow rowAvoir = tableAvoir.getRow(this.comboAvoir.getWantedID());
|
18 |
ilm |
542 |
long totalAvoir = ((Number) rowAvoir.getObject("MONTANT_TTC")).longValue();
|
73 |
ilm |
543 |
this.fieldMontantRegle.setValue(ttc - totalAvoir);
|
18 |
ilm |
544 |
} else {
|
73 |
ilm |
545 |
this.fieldMontantRegle.setValue(0l);
|
18 |
ilm |
546 |
}
|
|
|
547 |
} else {
|
|
|
548 |
if (n != null) {
|
73 |
ilm |
549 |
this.fieldMontantRegle.setValue(n.longValue());
|
18 |
ilm |
550 |
} else {
|
73 |
ilm |
551 |
this.fieldMontantRegle.setValue(0l);
|
18 |
ilm |
552 |
}
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
public final void loadCommande(int id) {
|
|
|
557 |
loadFromTable("COMMANDE", id);
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
public final void loadBonReception(int id) {
|
|
|
561 |
loadFromTable("BON_RECEPTION", id);
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
private final void loadFromTable(final String tableName, final int id) {
|
|
|
565 |
// Mise à jour des totaux
|
41 |
ilm |
566 |
// this.montant.setEnabled(false);
|
|
|
567 |
// this.montant.getChoixTaxe().setVisible(false);
|
18 |
ilm |
568 |
if (id > 1) {
|
|
|
569 |
final SQLElement eltCommande = Configuration.getInstance().getDirectory().getElement(tableName);
|
|
|
570 |
final SQLInjector injector = SQLInjector.getInjector(eltCommande.getTable(), this.getTable());
|
142 |
ilm |
571 |
final SQLRowValues createRowValuesFrom = injector.createRowValuesFrom(id);
|
|
|
572 |
final SQLRowAccessor foreignFourn = createRowValuesFrom.getForeign("ID_FOURNISSEUR");
|
|
|
573 |
if (foreignFourn != null && !foreignFourn.isUndefined()) {
|
|
|
574 |
SQLRowAccessor rowCharge = foreignFourn.getForeign("ID_COMPTE_PCE_CHARGE");
|
|
|
575 |
if (rowCharge != null && !rowCharge.isUndefined()) {
|
|
|
576 |
createRowValuesFrom.put("ID_COMPTE_PCE", rowCharge.getID());
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
this.select(createRowValuesFrom);
|
18 |
ilm |
580 |
}
|
|
|
581 |
}
|
65 |
ilm |
582 |
|
18 |
ilm |
583 |
}
|