OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
83 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.product.component;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.ui.CodeFournisseurItemTable;
19
import org.openconcerto.erp.core.common.ui.TotalPanel;
93 ilm 20
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
83 ilm 21
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
22
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
23
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
24
import org.openconcerto.erp.model.ISQLCompteSelector;
25
import org.openconcerto.erp.preferences.DefaultNXProps;
26
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
27
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.element.BaseSQLComponent;
29
import org.openconcerto.sql.element.SQLElement;
30
import org.openconcerto.sql.model.SQLRow;
31
import org.openconcerto.sql.model.SQLRowAccessor;
32
import org.openconcerto.sql.model.SQLRowListRSH;
33
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.model.SQLSelect;
35
import org.openconcerto.sql.model.Where;
36
import org.openconcerto.sql.preferences.SQLPreferences;
37
import org.openconcerto.sql.sqlobject.ElementComboBox;
38
import org.openconcerto.ui.DefaultGridBagConstraints;
39
import org.openconcerto.ui.FormLayouter;
40
import org.openconcerto.ui.component.ITextArea;
41
import org.openconcerto.ui.preferences.DefaultProps;
90 ilm 42
import org.openconcerto.utils.DecimalUtils;
83 ilm 43
import org.openconcerto.utils.StringUtils;
44
import org.openconcerto.utils.text.SimpleDocumentListener;
45
 
46
import java.awt.Component;
47
import java.awt.GridBagConstraints;
48
import java.awt.GridBagLayout;
49
import java.awt.Insets;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import java.beans.PropertyChangeEvent;
53
import java.beans.PropertyChangeListener;
54
import java.math.BigDecimal;
55
import java.math.RoundingMode;
56
import java.sql.SQLException;
93 ilm 57
import java.util.Date;
83 ilm 58
import java.util.List;
59
 
60
import javax.swing.JButton;
61
import javax.swing.JCheckBox;
62
import javax.swing.JLabel;
63
import javax.swing.JPanel;
64
import javax.swing.JSeparator;
65
import javax.swing.JTabbedPane;
66
import javax.swing.JTextField;
67
import javax.swing.SwingConstants;
68
import javax.swing.event.DocumentEvent;
69
import javax.swing.event.DocumentListener;
70
 
71
public class ArticleFournisseurSQLComponent extends BaseSQLComponent {
72
 
73
    private JTextField textPVHT, textPVTTC, textPAHT;
74
    private JTextField textMetrique1VT, textMetrique1HA;
75
 
76
    private final JCheckBox boxService = new JCheckBox(getLabelFor("SERVICE"));
77
    private final JCheckBox checkObs = new JCheckBox(getLabelFor("OBSOLETE"));
78
    private JTextField textNom, textCode;
79
    private JTextField textPoids;
80
    private JTextField textValMetrique1, textValMetrique2, textValMetrique3;
81
    private DocumentListener htDocListener, ttcDocListener, detailsListener;
82
    private PropertyChangeListener propertyChangeListener;
83
    private PropertyChangeListener taxeListener;
84
    private final ElementComboBox comboSelTaxe = new ElementComboBox(false, 10);
85
    private final ElementComboBox comboSelModeVente = new ElementComboBox(false, 25);
86
    private JLabel labelMetriqueHA1 = new JLabel(getLabelFor("PRIX_METRIQUE_HA_1"), SwingConstants.RIGHT);
87
    private JLabel labelMetriqueVT1 = new JLabel(getLabelFor("PRIX_METRIQUE_VT_1"), SwingConstants.RIGHT);
88
 
89
    private final JTextField textMarge = new JTextField(15);
90
 
91
    private DocumentListener pieceHAArticle = new DocumentListener() {
92
 
93
        public void changedUpdate(DocumentEvent arg0) {
94
            ArticleFournisseurSQLComponent.this.textMetrique1HA.setText(ArticleFournisseurSQLComponent.this.textPAHT.getText());
95
        }
96
 
97
        public void insertUpdate(DocumentEvent arg0) {
98
            ArticleFournisseurSQLComponent.this.textMetrique1HA.setText(ArticleFournisseurSQLComponent.this.textPAHT.getText());
99
        }
100
 
101
        public void removeUpdate(DocumentEvent arg0) {
102
            ArticleFournisseurSQLComponent.this.textMetrique1HA.setText(ArticleFournisseurSQLComponent.this.textPAHT.getText());
103
        }
104
 
105
    };
106
    private DocumentListener pieceVTArticle = new DocumentListener() {
107
 
108
        public void changedUpdate(DocumentEvent arg0) {
109
            ArticleFournisseurSQLComponent.this.textMetrique1VT.setText(ArticleFournisseurSQLComponent.this.textPVHT.getText());
110
        }
111
 
112
        public void insertUpdate(DocumentEvent arg0) {
113
            ArticleFournisseurSQLComponent.this.textMetrique1VT.setText(ArticleFournisseurSQLComponent.this.textPVHT.getText());
114
        }
115
 
116
        public void removeUpdate(DocumentEvent arg0) {
117
            ArticleFournisseurSQLComponent.this.textMetrique1VT.setText(ArticleFournisseurSQLComponent.this.textPVHT.getText());
118
        }
119
 
120
    };
121
 
122
    private DocumentListener listenerMargeTextMarge = new SimpleDocumentListener() {
123
        @Override
124
        public void update(DocumentEvent e) {
125
            ArticleFournisseurSQLComponent.this.textPVHT.getDocument().removeDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextVT);
126
            updateVtFromMarge();
127
            ArticleFournisseurSQLComponent.this.textPVHT.getDocument().addDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextVT);
128
        }
129
 
130
    };
131
 
132
    private DocumentListener listenerMargeTextVT = new SimpleDocumentListener() {
133
        @Override
134
        public void update(DocumentEvent e) {
135
            ArticleFournisseurSQLComponent.this.textMarge.getDocument().removeDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextMarge);
136
            if (ArticleFournisseurSQLComponent.this.textPVHT.getText().trim().length() > 0 && ArticleFournisseurSQLComponent.this.textPAHT.getText().trim().length() > 0) {
137
                final BigDecimal vt = StringUtils.getBigDecimalFromUserText(ArticleFournisseurSQLComponent.this.textPVHT.getText());
138
                final BigDecimal ha = StringUtils.getBigDecimalFromUserText(ArticleFournisseurSQLComponent.this.textPAHT.getText());
139
 
140
                if (vt != null && ha != null) {
141
                    if (vt.signum() != 0 && ha.signum() != 0) {
142
                        BigDecimal margeHT = vt.subtract(ha);
143
 
144
                        BigDecimal value;
145
 
146
                        if (DefaultNXProps.getInstance().getBooleanValue(TotalPanel.MARGE_MARQUE, false)) {
147
                            if (vt.compareTo(BigDecimal.ZERO) > 0) {
90 ilm 148
                                value = margeHT.divide(vt, DecimalUtils.HIGH_PRECISION).multiply(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION);
83 ilm 149
                            } else {
150
                                value = BigDecimal.ZERO;
151
                            }
152
                        } else {
90 ilm 153
                            value = margeHT.divide(ha, DecimalUtils.HIGH_PRECISION).multiply(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION);
83 ilm 154
                        }
155
 
156
                        if (value.compareTo(BigDecimal.ZERO) > 0) {
157
                            ArticleFournisseurSQLComponent.this.textMarge.setText(value.setScale(6, RoundingMode.HALF_UP).toString());
158
                        } else {
159
                            ArticleFournisseurSQLComponent.this.textMarge.setText("0");
160
                        }
161
                    }
162
                }
163
            }
164
            ArticleFournisseurSQLComponent.this.textMarge.getDocument().addDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextMarge);
165
        }
166
    };
167
 
168
    private DocumentListener listenerMargeTextHA = new SimpleDocumentListener() {
169
        @Override
170
        public void update(DocumentEvent e) {
171
            ArticleFournisseurSQLComponent.this.textPVHT.getDocument().removeDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextVT);
172
            updateVtFromMarge();
173
            ArticleFournisseurSQLComponent.this.textPVHT.getDocument().addDocumentListener(ArticleFournisseurSQLComponent.this.listenerMargeTextVT);
174
        }
175
    };
176
 
177
    private void updateVtFromMarge() {
178
        if (this.textPAHT.getText().trim().length() > 0) {
179
 
180
            BigDecimal ha = StringUtils.getBigDecimalFromUserText(this.textPAHT.getText());
181
            if (ha != null && this.textMarge.getText().trim().length() > 0) {
182
 
183
                BigDecimal d = StringUtils.getBigDecimalFromUserText(this.textMarge.getText());
184
                if (DefaultNXProps.getInstance().getBooleanValue(TotalPanel.MARGE_MARQUE, false)) {
90 ilm 185
                    final BigDecimal e = BigDecimal.ONE.subtract(d.divide(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION));
83 ilm 186
                    if (e.signum() == 0) {
187
                        this.textPVHT.setText("0");
188
                    } else {
90 ilm 189
                        this.textPVHT.setText(ha.divide(e, DecimalUtils.HIGH_PRECISION).setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
83 ilm 190
                    }
191
                } else {
90 ilm 192
                    BigDecimal result = ha.multiply(d.divide(BigDecimal.valueOf(100), DecimalUtils.HIGH_PRECISION).add(BigDecimal.ONE));
83 ilm 193
                    this.textPVHT.setText(result.setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
194
                }
195
            }
196
        }
197
    }
198
 
199
    public ArticleFournisseurSQLComponent(SQLElement elt) {
200
        super(elt);
201
    }
202
 
203
    @Override
204
    public void select(SQLRowAccessor r) {
205
        super.select(r);
206
        if (r != null && r.getID() > getTable().getUndefinedID()) {
207
            this.checkObs.setVisible(true);
208
            if (this.codeFournisseurTable != null) {
209
                this.codeFournisseurTable.insertFrom("ID_ARTICLE", r.getID());
210
            }
211
        }
212
    }
213
 
214
    public void addViews() {
215
        this.setLayout(new GridBagLayout());
216
        final GridBagConstraints c = new DefaultGridBagConstraints();
217
 
218
        this.textPVHT = new JTextField(15);
219
        this.textPVTTC = new JTextField(15);
220
        this.textPAHT = new JTextField(15);
221
        this.textPVHT.getDocument().addDocumentListener(this.listenerMargeTextVT);
222
 
223
        // Init metrique devise field
224
        this.textMetrique1HA = new JTextField(15);
225
        this.textMetrique1VT = new JTextField(15);
226
 
227
        // init metrique value field
228
        this.textValMetrique1 = new JTextField(15);
229
        this.textValMetrique2 = new JTextField(15);
230
        this.textValMetrique3 = new JTextField(15);
231
 
232
        this.textCode = new JTextField();
233
        this.textNom = new JTextField();
234
        this.textPoids = new JTextField(6);
235
 
236
        // Code
237
        JLabel codelabel = new JLabel(getLabelFor("CODE"));
238
        codelabel.setHorizontalAlignment(SwingConstants.RIGHT);
239
        DefaultGridBagConstraints.lockMinimumSize(codelabel);
240
        this.add(codelabel, c);
241
        c.gridx++;
242
        c.weightx = 1;
243
        DefaultGridBagConstraints.lockMinimumSize(textCode);
244
        this.add(this.textCode, c);
245
 
246
        // Famille
247
        c.gridx++;
248
        c.gridwidth = 1;
249
        c.weightx = 0;
250
        JLabel labelFamille = new JLabel(getLabelFor("ID_FAMILLE_ARTICLE_FOURNISSEUR"));
251
        labelFamille.setHorizontalAlignment(SwingConstants.RIGHT);
252
        DefaultGridBagConstraints.lockMinimumSize(labelFamille);
253
        this.add(labelFamille, c);
254
        c.gridx++;
255
        c.weightx = 1;
256
        c.gridwidth = 1;
257
        final ElementComboBox comboSelFamille = new ElementComboBox(false, 25);
258
        this.addSQLObject(comboSelFamille, "ID_FAMILLE_ARTICLE_FOURNISSEUR");
259
        DefaultGridBagConstraints.lockMinimumSize(comboSelFamille);
260
        this.add(comboSelFamille, c);
261
 
262
        // Nom
263
        c.gridy++;
264
        c.gridx = 0;
265
        c.weightx = 0;
266
        JLabel labelNom = new JLabel(getLabelFor("NOM"));
267
        labelNom.setHorizontalAlignment(SwingConstants.RIGHT);
268
        DefaultGridBagConstraints.lockMinimumSize(labelNom);
269
        this.add(labelNom, c);
270
        c.gridx++;
271
        c.weightx = 1;
272
        DefaultGridBagConstraints.lockMinimumSize(textNom);
273
        this.add(this.textNom, c);
274
 
275
        // Code barre
276
        c.gridx++;
277
        c.weightx = 0;
278
        JLabel labelCodeBarre = new JLabel(getLabelFor("CODE_BARRE"));
279
        labelCodeBarre.setHorizontalAlignment(SwingConstants.RIGHT);
280
        DefaultGridBagConstraints.lockMinimumSize(labelCodeBarre);
281
        this.add(labelCodeBarre, c);
282
        c.gridx++;
283
        c.weightx = 1;
284
        JTextField fieldCodeBarre = new JTextField();
285
        DefaultGridBagConstraints.lockMinimumSize(fieldCodeBarre);
286
        this.add(fieldCodeBarre, c);
287
        this.addView(fieldCodeBarre, "CODE_BARRE");
288
 
289
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
290
        // Gestion des unités de vente
291
        final boolean gestionUV = prefs.getBoolean(GestionArticleGlobalPreferencePanel.UNITE_VENTE, true);
292
        if (gestionUV) {
293
            c.gridy++;
294
            c.gridx = 0;
295
            c.weightx = 0;
296
            this.add(new JLabel(getLabelFor("ID_UNITE_VENTE"), SwingConstants.RIGHT), c);
297
            c.gridx++;
298
            c.weightx = 1;
299
            c.fill = GridBagConstraints.NONE;
300
            ElementComboBox boxUnite = new ElementComboBox();
301
            DefaultGridBagConstraints.lockMinimumSize(boxUnite);
302
            this.add(boxUnite, c);
303
            this.addView(boxUnite, "ID_UNITE_VENTE");
304
            c.fill = GridBagConstraints.HORIZONTAL;
305
        }
306
        DefaultProps props = DefaultNXProps.getInstance();
307
 
308
        // Article détaillé
309
        String modeVente = props.getStringProperty("ArticleModeVenteAvance");
310
        Boolean bModeVente = Boolean.valueOf(modeVente);
311
        boolean modeVenteAvance = (bModeVente == null || bModeVente.booleanValue());
312
 
313
        if (modeVenteAvance) {
314
            addModeVenteAvance(c);
315
        }
316
 
317
        getMontantPanel(c, props);
318
 
319
        // Champ Module
320
        c.gridx = 0;
321
        c.gridy++;
322
        c.gridwidth = GridBagConstraints.REMAINDER;
323
        final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
324
        this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
325
        this.add(addP, c);
326
 
327
        JTabbedPane pane = new JTabbedPane();
328
        c.gridy++;
329
        c.weightx = 1;
330
        c.weighty = 1;
331
 
332
        pane.add("Tarifs de vente", createTarifPanel());
333
        pane.add("Exportation", createExportationPanel());
334
        pane.add("Achat", createAchatPanel());
335
        pane.add("Stock", createStockPanel());
336
        pane.add("Descriptif", createDescriptifPanel());
337
        pane.add("Désignations multilingues", createDesignationPanel());
338
        pane.add("Comptabilité", createComptaPanel());
339
        pane.add(getLabelFor("INFOS"), createInfosPanel());
340
 
341
        c.fill = GridBagConstraints.BOTH;
342
        this.add(pane, c);
343
 
344
        this.addSQLObject(this.textMetrique1HA, "PRIX_METRIQUE_HA_1");
345
        this.addSQLObject(this.textMetrique1VT, "PRIX_METRIQUE_VT_1");
346
        this.addSQLObject(this.textValMetrique1, "VALEUR_METRIQUE_1");
347
        this.addSQLObject(this.textValMetrique2, "VALEUR_METRIQUE_2");
348
        this.addSQLObject(this.textValMetrique3, "VALEUR_METRIQUE_3");
349
        this.addSQLObject(this.comboSelModeVente, "ID_MODE_VENTE_ARTICLE");
350
        this.addSQLObject(this.boxService, "SERVICE");
351
 
352
        this.addRequiredSQLObject(this.textNom, "NOM");
353
        this.addRequiredSQLObject(this.textCode, "CODE");
354
 
355
        this.addSQLObject(this.textPoids, "POIDS");
356
 
357
        this.comboSelTaxe.setButtonsVisible(false);
358
        this.propertyChangeListener = new PropertyChangeListener() {
359
 
360
            public void propertyChange(PropertyChangeEvent evt) {
361
                System.err.println(ArticleFournisseurSQLComponent.this.comboSelModeVente.getSelectedId());
362
                selectModeVente(ArticleFournisseurSQLComponent.this.comboSelModeVente.getSelectedId());
363
 
364
            }
365
        };
366
        setListenerModeVenteActive(true);
367
        this.comboSelModeVente.setValue(ReferenceArticleSQLElement.A_LA_PIECE);
368
    }
369
 
370
    private Component createInfosPanel() {
371
        JPanel panel = new JPanel(new GridBagLayout());
372
        panel.setOpaque(false);
373
        GridBagConstraints c = new DefaultGridBagConstraints();
374
 
375
        c.weightx = 1;
376
        c.weighty = 1;
377
        ITextArea infos = new ITextArea();
378
        c.fill = GridBagConstraints.BOTH;
379
        panel.add(infos, c);
380
 
381
        this.addSQLObject(infos, "INFOS");
382
 
383
        return panel;
384
    }
385
 
386
    private Component createDescriptifPanel() {
387
        JPanel panel = new JPanel(new GridBagLayout());
388
        panel.setOpaque(false);
389
        GridBagConstraints c = new DefaultGridBagConstraints();
390
 
391
        // Obsolete
392
        c.fill = GridBagConstraints.NONE;
393
        c.gridwidth = GridBagConstraints.REMAINDER;
394
        c.weightx = 1;
395
        this.checkObs.setOpaque(false);
396
        panel.add(this.checkObs, c);
397
 
398
        this.checkObs.setVisible(false);
399
        this.addView(this.checkObs, "OBSOLETE");
400
 
401
        if (getTable().getFieldsName().contains("COLORIS")) {
402
            JTextField fieldColoris = new JTextField();
403
            c.gridy++;
404
            c.fill = GridBagConstraints.HORIZONTAL;
405
            c.weightx = 0;
406
            c.gridwidth = 1;
407
            panel.add(new JLabel(getLabelFor("COLORIS")), c);
408
 
409
            c.weightx = 1;
410
            c.gridx++;
411
            panel.add(fieldColoris, c);
412
            this.addView(fieldColoris, "COLORIS");
413
        }
414
        ITextArea area = new ITextArea();
415
        JLabel sep = new JLabel("Descriptif complet");
416
        c.gridy++;
417
        c.gridx = 0;
418
        c.gridwidth = GridBagConstraints.REMAINDER;
419
        c.fill = GridBagConstraints.HORIZONTAL;
420
        panel.add(sep, c);
421
 
422
        c.gridy++;
423
        c.weighty = 1;
424
        c.fill = GridBagConstraints.BOTH;
425
        panel.add(area, c);
426
        this.addView(area, "DESCRIPTIF");
427
        return panel;
428
    }
429
 
430
    private Component createDesignationPanel() {
431
        JPanel panel = new JPanel(new GridBagLayout());
432
        panel.setOpaque(false);
433
        GridBagConstraints c = new DefaultGridBagConstraints();
434
 
435
        // Ajout des
436
        c.gridwidth = 1;
437
        c.weightx = 0;
438
        c.gridy++;
439
        c.gridx = 0;
440
        panel.add(new JLabel("Ajouter une désignation "), c);
441
 
442
        final ElementComboBox boxDes = new ElementComboBox();
443
        boxDes.init(Configuration.getInstance().getDirectory().getElement("LANGUE"));
444
 
445
        c.gridx++;
446
        panel.add(boxDes, c);
447
 
448
        c.fill = GridBagConstraints.NONE;
449
        c.gridx++;
450
        JButton buttonAjouterDes = new JButton("Ajouter");
451
        buttonAjouterDes.setOpaque(false);
452
        panel.add(buttonAjouterDes, c);
453
        c.gridx++;
454
        JButton buttonSupprimerDes = new JButton("Supprimer");
455
        buttonSupprimerDes.setOpaque(false);
456
        panel.add(buttonSupprimerDes, c);
457
 
458
        c.gridy++;
459
        c.gridx = 0;
460
        c.gridwidth = GridBagConstraints.REMAINDER;
461
        c.fill = GridBagConstraints.BOTH;
462
        c.weighty = 1;
463
        c.weightx = 1;
464
 
465
        return panel;
466
    }
467
 
468
    private Component createStockPanel() {
469
        JPanel panel = new JPanel(new GridBagLayout());
470
        panel.setOpaque(false);
471
        GridBagConstraints c = new DefaultGridBagConstraints();
93 ilm 472
 
473
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
142 ilm 474
        boolean gestionStockMin = prefs.getBoolean(GestionArticleGlobalPreferencePanel.WARNING_STOCK_MIN, true);
83 ilm 475
        c.gridx = 0;
476
        c.gridy++;
477
 
478
        final JCheckBox boxStock = new JCheckBox(getLabelFor("GESTION_STOCK"));
479
        boxStock.setOpaque(false);
480
        panel.add(boxStock, c);
481
        this.addView(boxStock, "GESTION_STOCK");
482
 
483
        final JTextField fieldQteMin = new JTextField();
484
        final JTextField fieldQteAchat = new JTextField();
485
        boxStock.addActionListener(new ActionListener() {
486
 
487
            @Override
488
            public void actionPerformed(ActionEvent e) {
489
                fieldQteMin.setEnabled(boxStock.isSelected());
490
                fieldQteAchat.setEnabled(boxStock.isSelected());
491
            }
492
        });
493
 
494
        c.gridwidth = 1;
495
        if (gestionStockMin) {
496
            c.gridx = 0;
497
            c.gridy++;
498
            c.weightx = 0;
499
            panel.add(new JLabel(getLabelFor("QTE_ACHAT")), c);
500
            c.gridx++;
501
            c.weightx = 1;
502
            panel.add(fieldQteAchat, c);
503
            this.addView(fieldQteAchat, "QTE_ACHAT");
504
        }
505
 
506
        c.gridy++;
507
        c.weighty = 1;
508
        c.weightx = 1;
509
        c.fill = GridBagConstraints.BOTH;
510
        final JPanel spacer = new JPanel();
511
        spacer.setOpaque(false);
512
        panel.add(spacer, c);
513
        return panel;
514
    }
515
 
516
    private Component createComptaPanel() {
517
        JPanel panel = new JPanel(new GridBagLayout());
518
        panel.setOpaque(false);
519
        GridBagConstraints c = new DefaultGridBagConstraints();
520
        c.gridwidth = 1;
521
        c.weighty = 0;
522
        c.weightx = 0;
523
        ISQLCompteSelector sel = new ISQLCompteSelector();
524
        c.fill = GridBagConstraints.BOTH;
525
        panel.add(new JLabel(getLabelFor("ID_COMPTE_PCE")), c);
526
        c.gridx++;
527
        c.weightx = 1;
528
        panel.add(sel, c);
529
        this.addView(sel, "ID_COMPTE_PCE");
530
 
531
        c.gridwidth = 1;
532
        c.gridy++;
533
        c.weighty = 0;
534
        c.gridx = 0;
535
        c.weightx = 0;
536
        ISQLCompteSelector selAchat = new ISQLCompteSelector();
537
        c.fill = GridBagConstraints.BOTH;
538
        panel.add(new JLabel(getLabelFor("ID_COMPTE_PCE_ACHAT")), c);
539
        c.gridx++;
540
        c.weightx = 1;
541
        panel.add(selAchat, c);
542
        this.addView(selAchat, "ID_COMPTE_PCE_ACHAT");
543
 
544
        c.gridy++;
545
        c.weighty = 1;
546
        c.weightx = 1;
547
        c.fill = GridBagConstraints.BOTH;
548
        final JPanel spacer = new JPanel();
549
        spacer.setOpaque(false);
550
        panel.add(spacer, c);
551
        return panel;
552
    }
553
 
554
    private SQLRowValues rowValuesDefaultCodeFournisseur;
555
    private CodeFournisseurItemTable codeFournisseurTable;
556
 
557
    private Component createAchatPanel() {
558
        JPanel panel = new JPanel(new GridBagLayout());
559
        panel.setOpaque(false);
560
        GridBagConstraints c = new DefaultGridBagConstraints();
561
        // Fournisseur
562
        c.gridy++;
563
        c.gridx = 0;
564
        c.gridwidth = 1;
565
        c.weightx = 0;
566
        JLabel labelFournisseur = new JLabel(getLabelFor("ID_FOURNISSEUR"));
567
        labelFournisseur.setHorizontalAlignment(SwingConstants.RIGHT);
568
        panel.add(labelFournisseur, c);
569
        c.gridx++;
570
        c.weightx = 1;
571
        c.gridwidth = 2;
572
        final ElementComboBox comboSelFournisseur = new ElementComboBox(false, 25);
573
        panel.add(comboSelFournisseur, c);
574
        this.addView(comboSelFournisseur, "ID_FOURNISSEUR");
575
 
576
        SQLPreferences prefs = new SQLPreferences(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
577
        final boolean supplierCode = prefs.getBoolean(GestionArticleGlobalPreferencePanel.SUPPLIER_PRODUCT_CODE, false);
578
 
579
        if (getTable().getSchema().contains("CODE_FOURNISSEUR") && supplierCode) {
580
            this.rowValuesDefaultCodeFournisseur = new SQLRowValues(getTable().getTable("CODE_FOURNISSEUR"));
581
            this.codeFournisseurTable = new CodeFournisseurItemTable(this.rowValuesDefaultCodeFournisseur);
582
            c.gridy++;
583
            c.gridx = 0;
584
            c.gridwidth = 3;
585
            c.weighty = 1;
586
            c.weightx = 1;
587
            c.fill = GridBagConstraints.BOTH;
588
            panel.add(this.codeFournisseurTable, c);
589
            comboSelFournisseur.addValueListener(new PropertyChangeListener() {
590
 
591
                @Override
592
                public void propertyChange(PropertyChangeEvent evt) {
593
                    rowValuesDefaultCodeFournisseur.put("ID_FOURNISSEUR", comboSelFournisseur.getSelectedId());
594
                }
595
            });
596
        } else {
597
            c.gridy++;
598
            c.weighty = 1;
599
            c.weightx = 1;
600
            c.fill = GridBagConstraints.BOTH;
601
            final JPanel spacer = new JPanel();
602
            spacer.setOpaque(false);
603
            panel.add(spacer, c);
604
        }
605
        return panel;
606
    }
607
 
608
    private JPanel createExportationPanel() {
609
        JPanel panel = new JPanel(new GridBagLayout());
610
        panel.setOpaque(false);
611
        GridBagConstraints c = new DefaultGridBagConstraints();
612
        // Code douanier
613
        c.gridx = 0;
614
        c.weightx = 0;
615
        c.gridy++;
616
        c.gridwidth = 1;
617
        JLabel labelCodeD = new JLabel(getLabelFor("CODE_DOUANIER"));
618
        labelCodeD.setHorizontalAlignment(SwingConstants.RIGHT);
619
        panel.add(labelCodeD, c);
620
 
621
        c.gridx++;
622
        JTextField fieldCodeDouanier = new JTextField();
623
        c.weightx = 1;
624
        panel.add(fieldCodeDouanier, c);
625
        this.addView(fieldCodeDouanier, "CODE_DOUANIER");
626
 
627
        // Pays d'origine
628
        c.gridx++;
629
        c.weightx = 0;
630
        JLabel labelPays = new JLabel(getLabelFor("ID_PAYS"));
631
        labelPays.setHorizontalAlignment(SwingConstants.RIGHT);
632
        panel.add(labelPays, c);
633
        c.gridx++;
634
        c.weightx = 1;
635
        final ElementComboBox comboSelPays = new ElementComboBox(false);
636
        panel.add(comboSelPays, c);
637
        this.addView(comboSelPays, "ID_PAYS");
638
        c.gridy++;
639
        c.weighty = 1;
640
        c.weightx = 1;
641
        c.fill = GridBagConstraints.BOTH;
642
        final JPanel spacer = new JPanel();
643
        spacer.setOpaque(false);
644
        panel.add(spacer, c);
645
        return panel;
646
    }
647
 
648
    private JPanel createTarifPanel() {
649
        JPanel panel = new JPanel(new GridBagLayout());
650
        panel.setOpaque(false);
651
        GridBagConstraints c = new DefaultGridBagConstraints();
652
 
653
        // Ajout tarif
654
        c.gridwidth = 1;
655
        c.weightx = 0;
656
        c.gridy++;
657
        c.gridx = 0;
658
        panel.add(new JLabel("Ajouter le tarif "), c);
659
 
660
        return panel;
661
    }
662
 
663
    protected void getMontantPanel(final GridBagConstraints c, DefaultProps props) {
664
        c.gridx = 0;
665
        c.gridy++;
666
        c.gridwidth = 1;
667
        // PA devise
668
        JPanel pDevise = new JPanel(new GridBagLayout());
669
        GridBagConstraints cDevise = new DefaultGridBagConstraints();
670
        cDevise.insets = new Insets(0, 0, 0, 4);
671
        c.weightx = 0;
672
        c.fill = GridBagConstraints.HORIZONTAL;
673
        this.add(new JLabel("Devise du fournisseur"), c);
674
        final ElementComboBox boxDevise = new ElementComboBox(true, 15);
675
        cDevise.gridx++;
676
        cDevise.weightx = 1;
677
        pDevise.add(boxDevise, cDevise);
678
        this.addView(boxDevise, "ID_DEVISE_HA");
679
        DefaultGridBagConstraints.lockMinimumSize(boxDevise);
680
 
681
        cDevise.weightx = 0;
682
        cDevise.gridx++;
683
        pDevise.add(new JLabel("Prix d'achat devise"), cDevise);
684
        final JTextField fieldHAD = new JTextField(15);
685
        cDevise.weightx = 1;
686
        cDevise.gridx++;
687
        pDevise.add(fieldHAD, cDevise);
688
        this.addView(fieldHAD, "PA_DEVISE");
689
        DefaultGridBagConstraints.lockMinimumSize(fieldHAD);
690
 
691
        c.gridx++;
692
        c.gridwidth = GridBagConstraints.REMAINDER;
693
        c.anchor = GridBagConstraints.WEST;
694
        c.weightx = 1;
695
        c.fill = GridBagConstraints.NONE;
696
        this.add(pDevise, c);
697
        fieldHAD.getDocument().addDocumentListener(new SimpleDocumentListener() {
698
 
699
            @Override
700
            public void update(DocumentEvent e) {
701
 
702
                if (!isFilling() && boxDevise != null && boxDevise.getSelectedRow() != null && !boxDevise.getSelectedRow().isUndefined()) {
703
                    BigDecimal ha = StringUtils.getBigDecimalFromUserText(fieldHAD.getText());
704
                    if (ha == null) {
705
                        ha = BigDecimal.ZERO;
706
                    }
707
 
93 ilm 708
                    final String devCode = boxDevise.getSelectedRow().getString("CODE");
709
                    CurrencyConverter c = new CurrencyConverter();
710
                    textPAHT.setText(c.convert(ha, devCode, c.getCompanyCurrencyCode(), new Date(), true).setScale(getTable().getField("PA_DEVISE").getType().getDecimalDigits(), RoundingMode.HALF_UP)
711
                            .toString());
83 ilm 712
                }
713
            }
714
        });
715
 
716
        // PA
717
        JPanel p = new JPanel(new GridBagLayout());
718
        GridBagConstraints cAchat = new DefaultGridBagConstraints();
719
        cAchat.insets = new Insets(0, 0, 0, 4);
720
        c.gridx = 0;
721
        c.gridy++;
722
        c.weightx = 0;
723
        c.gridwidth = 1;
724
        c.fill = GridBagConstraints.HORIZONTAL;
725
        this.add(new JLabel(getLabelFor("PA_HT"), SwingConstants.RIGHT), c);
726
        cAchat.gridx++;
727
        cAchat.weightx = 1;
728
        p.add(this.textPAHT, cAchat);
729
        this.textPAHT.getDocument().addDocumentListener(this.listenerMargeTextHA);
730
 
731
        // Marge
732
        cAchat.gridx++;
733
        cAchat.weightx = 0;
734
        p.add(new JLabel("Marge"), cAchat);
735
        cAchat.weightx = 1;
736
        cAchat.gridx++;
737
        p.add(this.textMarge, cAchat);
738
        this.textMarge.getDocument().addDocumentListener(this.listenerMargeTextMarge);
739
        cAchat.gridx++;
740
        cAchat.weightx = 0;
741
        p.add(new JLabel("%           "), cAchat);
742
 
743
        // Poids
744
        JLabel labelPds = new JLabel(getLabelFor("POIDS"));
745
        cAchat.gridx++;
746
        cAchat.weightx = 0;
747
        p.add(labelPds, cAchat);
748
        labelPds.setHorizontalAlignment(SwingConstants.RIGHT);
749
        cAchat.weightx = 1;
750
        cAchat.gridx++;
751
        p.add(this.textPoids, cAchat);
752
        DefaultGridBagConstraints.lockMinimumSize(this.textPoids);
753
 
754
        // Service
755
        String sService = props.getStringProperty("ArticleService");
756
        Boolean bService = Boolean.valueOf(sService);
757
        if (bService != null && bService.booleanValue()) {
758
            cAchat.gridx++;
759
            cAchat.weightx = 0;
760
            p.add(this.boxService, cAchat);
761
        }
762
 
763
        c.gridx++;
764
        c.gridwidth = GridBagConstraints.REMAINDER;
765
        c.anchor = GridBagConstraints.WEST;
766
        c.weightx = 1;
767
        c.fill = GridBagConstraints.NONE;
768
 
769
        this.add(p, c);
770
 
771
        // PV HT
772
        c.gridx = 0;
773
        c.gridy++;
774
 
775
        JPanel p2 = new JPanel(new GridBagLayout());
776
        GridBagConstraints cVT = new DefaultGridBagConstraints();
777
        cVT.insets = new Insets(0, 0, 0, 4);
778
 
779
        c.weightx = 0;
780
        c.fill = GridBagConstraints.HORIZONTAL;
781
        c.gridwidth = 1;
782
        this.add(new JLabel(getLabelFor("PV_HT"), SwingConstants.RIGHT), c);
783
        cVT.gridx++;
784
        cVT.weightx = 1;
785
 
786
        p2.add(this.textPVHT, cVT);
787
 
788
        // Taxe
789
        JLabel labelTaxe = new JLabel(getLabelFor("ID_TAXE"));
790
        cVT.gridx++;
791
        cVT.weightx = 0;
792
        p2.add(labelTaxe, cVT);
793
        labelTaxe.setHorizontalAlignment(SwingConstants.RIGHT);
794
        cVT.gridx++;
795
        // cVT.weightx = 1;
796
 
797
        p2.add(this.comboSelTaxe, cVT);
798
 
799
        // PV_TTC
800
        cVT.gridx++;
801
        cVT.weightx = 0;
802
        p2.add(new JLabel(getLabelFor("PV_TTC")), cVT);
803
        cVT.gridx++;
804
        cVT.weightx = 1;
805
        p2.add(this.textPVTTC, cVT);
806
        c.gridx = 1;
807
 
808
        c.gridwidth = GridBagConstraints.REMAINDER;
809
        c.anchor = GridBagConstraints.WEST;
810
        c.weightx = 1;
811
        c.fill = GridBagConstraints.NONE;
812
        this.add(p2, c);
813
 
814
        this.addRequiredSQLObject(this.textPAHT, "PA_HT");
815
        this.addRequiredSQLObject(this.textPVHT, "PV_HT");
816
        DefaultGridBagConstraints.lockMinimumSize(this.textPVHT);
817
        this.addRequiredSQLObject(this.comboSelTaxe, "ID_TAXE");
818
        DefaultGridBagConstraints.lockMinimumSize(this.comboSelTaxe);
819
        DefaultGridBagConstraints.lockMaximumSize(this.comboSelTaxe);
820
        this.addRequiredSQLObject(this.textPVTTC, "PV_TTC");
821
        DefaultGridBagConstraints.lockMinimumSize(this.textPVTTC);
822
        DefaultGridBagConstraints.lockMinimumSize(this.textPAHT);
823
        DefaultGridBagConstraints.lockMinimumSize(this.textMarge);
824
        this.ttcDocListener = new DocumentListener() {
825
            public void changedUpdate(DocumentEvent e) {
826
                setTextHT();
827
            }
828
 
829
            public void insertUpdate(DocumentEvent e) {
830
                setTextHT();
831
            }
832
 
833
            public void removeUpdate(DocumentEvent e) {
834
                setTextHT();
835
            }
836
        };
837
 
838
        this.htDocListener = new DocumentListener() {
839
            public void changedUpdate(DocumentEvent e) {
840
                setTextTTC();
841
            }
842
 
843
            public void insertUpdate(DocumentEvent e) {
844
                setTextTTC();
845
            }
846
 
847
            public void removeUpdate(DocumentEvent e) {
848
                setTextTTC();
849
            }
850
 
851
        };
852
 
853
        this.detailsListener = new SimpleDocumentListener() {
854
 
855
            @Override
856
            public void update(DocumentEvent e) {
857
                updatePiece();
858
            }
859
 
860
        };
861
 
862
        this.taxeListener = new PropertyChangeListener() {
863
 
864
            public void propertyChange(PropertyChangeEvent evt) {
865
                if (ArticleFournisseurSQLComponent.this.textPVHT.getText().trim().length() > 0) {
866
                    setTextTTC();
867
                } else {
868
                    setTextHT();
869
                }
870
            }
871
        };
872
        this.textPVHT.getDocument().addDocumentListener(this.htDocListener);
873
        this.textPVTTC.getDocument().addDocumentListener(this.ttcDocListener);
874
        this.comboSelTaxe.addValueListener(this.taxeListener);
875
 
876
        this.textMetrique1HA.getDocument().addDocumentListener(this.detailsListener);
877
        this.textMetrique1VT.getDocument().addDocumentListener(this.detailsListener);
878
 
879
        this.textValMetrique1.getDocument().addDocumentListener(this.detailsListener);
880
        this.textValMetrique2.getDocument().addDocumentListener(this.detailsListener);
881
        this.textValMetrique3.getDocument().addDocumentListener(this.detailsListener);
882
 
883
    }
884
 
885
    private void setListenerModeVenteActive(boolean b) {
886
        if (b) {
887
            this.comboSelModeVente.addValueListener(this.propertyChangeListener);
888
        } else {
889
            this.comboSelModeVente.removePropertyChangeListener(this.propertyChangeListener);
890
        }
891
    }
892
 
893
    /**
894
     * @param c
895
     * @param props
896
     */
897
    private void addModeVenteAvance(GridBagConstraints c) {
898
        DefaultProps props = DefaultNXProps.getInstance();
899
        JSeparator sep = new JSeparator();
900
        JLabel labelDetails = new JLabel("Article détaillé", SwingConstants.RIGHT);
901
        c.gridx = 0;
902
        c.gridy++;
903
        c.weightx = 0;
904
        this.add(labelDetails, c);
905
        c.gridx++;
906
        c.gridwidth = GridBagConstraints.REMAINDER;
907
        c.fill = GridBagConstraints.HORIZONTAL;
908
        c.weightx = 1;
909
        this.add(sep, c);
910
 
911
        // Mode de vente
912
        c.gridwidth = 1;
913
        c.weightx = 0;
914
        c.gridx = 0;
915
        c.gridy++;
916
        this.add(new JLabel(getLabelFor("ID_MODE_VENTE_ARTICLE"), SwingConstants.RIGHT), c);
917
        c.weightx = 1;
918
        c.gridx++;
919
        this.add(this.comboSelModeVente, c);
920
 
921
        // Prix metrique
922
        c.gridx = 0;
923
        c.weightx = 0;
924
        c.gridy++;
925
        this.add(this.labelMetriqueHA1, c);
926
        c.gridx++;
927
        c.weightx = 1;
928
        this.add(this.textMetrique1HA, c);
929
 
930
        c.gridx++;
931
        c.weightx = 0;
932
        this.add(this.labelMetriqueVT1, c);
933
        c.gridx++;
934
        c.weightx = 1;
935
        this.add(this.textMetrique1VT, c);
936
 
937
        // Metrique 1
938
        c.weightx = 0;
939
        JLabel labelMetrique1 = new JLabel(getLabelFor("VALEUR_METRIQUE_1"), SwingConstants.RIGHT);
940
        c.gridx = 0;
941
        c.gridy++;
942
        this.add(labelMetrique1, c);
943
        c.gridx++;
944
        c.weightx = 1;
945
        this.add(this.textValMetrique1, c);
946
        c.gridx++;
947
        c.weightx = 0;
948
 
949
        Boolean bMetrique1 = Boolean.valueOf(props.getStringProperty("ArticleLongueur"));
950
        labelMetrique1.setVisible(bMetrique1 == null || bMetrique1.booleanValue());
951
        this.textValMetrique1.setVisible(bMetrique1 == null || bMetrique1.booleanValue());
952
 
953
        // Metrique 2
954
        JLabel labelMetrique2 = new JLabel(getLabelFor("VALEUR_METRIQUE_2"), SwingConstants.RIGHT);
955
        c.gridx = 0;
956
        c.gridy++;
957
        c.weightx = 0;
958
        this.add(labelMetrique2, c);
959
        c.gridx++;
960
        c.weightx = 1;
961
        this.add(this.textValMetrique2, c);
962
        c.gridx++;
963
        c.weightx = 0;
964
 
965
        Boolean bMetrique2 = Boolean.valueOf(props.getStringProperty("ArticleLargeur"));
966
        labelMetrique2.setVisible(bMetrique2 == null || bMetrique2.booleanValue());
967
        this.textValMetrique2.setVisible(bMetrique2 == null || bMetrique2.booleanValue());
968
 
969
        // Metrique 3
970
        JLabel labelMetrique3 = new JLabel(getLabelFor("VALEUR_METRIQUE_3"), SwingConstants.RIGHT);
971
        c.gridx = 0;
972
        c.gridy++;
973
        c.weightx = 0;
974
        this.add(labelMetrique3, c);
975
        c.gridx++;
976
        c.weightx = 1;
977
        this.add(this.textValMetrique3, c);
978
        c.gridx++;
979
 
980
        Boolean bMetrique3 = Boolean.valueOf(props.getStringProperty("ArticlePoids"));
981
        labelMetrique3.setVisible(bMetrique3 == null || bMetrique3.booleanValue());
982
        this.textValMetrique3.setVisible(bMetrique3 == null || bMetrique3.booleanValue());
983
 
984
        // Article détaillé
985
        JSeparator sep2 = new JSeparator();
986
        JLabel labelPiece = new JLabel("Article pièce", SwingConstants.RIGHT);
987
        c.gridx = 0;
988
        c.gridy++;
989
        c.weightx = 0;
990
        this.add(labelPiece, c);
991
        c.gridx++;
992
        c.gridwidth = GridBagConstraints.REMAINDER;
993
        c.fill = GridBagConstraints.HORIZONTAL;
994
        c.weightx = 1;
995
        this.add(sep2, c);
996
 
997
    }
998
 
999
    @Override
1000
    public void update() {
1001
            super.update();
1002
        if (this.codeFournisseurTable != null) {
1003
            this.codeFournisseurTable.updateField("ID_ARTICLE", getSelectedID());
1004
        }
1005
    }
1006
 
1007
    /**
1008
     * Sélection d'un mode de vente pour l'article. Affiche les prix metriques requis et fixe les
1009
     * valeurs.
1010
     *
1011
     * @param id id du mode de vente
1012
     */
1013
    private void selectModeVente(int id) {
1014
 
1015
        this.labelMetriqueHA1.setEnabled(true);
1016
        this.labelMetriqueVT1.setEnabled(true);
1017
        this.textMetrique1HA.setEnabled(true);
1018
        this.textMetrique1VT.setEnabled(true);
1019
 
1020
        this.textPAHT.getDocument().removeDocumentListener(this.pieceHAArticle);
1021
        this.textPVHT.getDocument().removeDocumentListener(this.pieceVTArticle);
1022
 
1023
        switch (id) {
1024
        case ReferenceArticleSQLElement.AU_METRE_CARRE:
1025
            this.labelMetriqueHA1.setText("Prix d'achat HT au mètre carré");
1026
            this.labelMetriqueVT1.setText("Prix de vente HT au mètre carré");
1027
            break;
1028
        case ReferenceArticleSQLElement.AU_METRE_LARGEUR:
1029
        case ReferenceArticleSQLElement.AU_METRE_LONGUEUR:
1030
            this.labelMetriqueHA1.setText("Prix d'achat HT au mètre");
1031
            this.labelMetriqueVT1.setText("Prix de vente HT au mètre");
1032
            break;
1033
 
1034
        case ReferenceArticleSQLElement.AU_POID_METRECARRE:
1035
            this.labelMetriqueHA1.setText("Prix d'achat HT au kilo");
1036
            this.labelMetriqueVT1.setText("Prix de vente HT au kilo");
1037
            break;
1038
        case -1:
1039
            // No break need to enable the listener
1040
        default:
1041
            this.labelMetriqueHA1.setEnabled(false);
1042
            this.labelMetriqueVT1.setEnabled(false);
1043
            this.textMetrique1HA.setEnabled(false);
1044
            this.textMetrique1VT.setEnabled(false);
1045
 
1046
            this.textMetrique1HA.setText(this.textPAHT.getText().trim());
1047
            this.textMetrique1VT.setText(this.textPVHT.getText().trim());
1048
            this.textPAHT.getDocument().addDocumentListener(this.pieceHAArticle);
1049
            this.textPVHT.getDocument().addDocumentListener(this.pieceVTArticle);
1050
            break;
1051
        }
1052
    }
1053
 
1054
    @Override
1055
    public int insert(SQLRow order) {
1056
        int id = super.insert(order);
1057
        if (this.codeFournisseurTable != null) {
1058
            this.codeFournisseurTable.updateField("ID_ARTICLE", id);
1059
        }
1060
        return id;
1061
    }
1062
 
1063
    @Override
1064
    protected SQLRowValues createDefaults() {
1065
        SQLRowValues rowVals = new SQLRowValues(getTable());
1066
 
1067
        SQLRow row = getTable().getRow(getTable().getUndefinedID());
1068
 
1069
        rowVals.put("ID_TAXE", row.getInt("ID_TAXE"));
1070
        rowVals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE);
1071
        rowVals.put("ID_MODE_VENTE_ARTICLE", ReferenceArticleSQLElement.A_LA_PIECE);
1072
        selectModeVente(ReferenceArticleSQLElement.A_LA_PIECE);
1073
        rowVals.put("VALEUR_METRIQUE_1", Float.valueOf("1.0"));
1074
        rowVals.put("PA_HT", BigDecimal.ZERO);
1075
        rowVals.put("POIDS", Float.valueOf(0));
1076
 
1077
        return rowVals;
1078
    }
1079
 
1080
    private void setTextHT() {
1081
        this.textPVHT.getDocument().removeDocumentListener(this.htDocListener);
1082
        final BigDecimal ttc = StringUtils.getBigDecimalFromUserText(this.textPVTTC.getText());
1083
        if (ttc != null) {
1084
            int id = this.comboSelTaxe.getSelectedId();
1085
            if (id > 1) {
1086
                Float resultTaux = TaxeCache.getCache().getTauxFromId(id);
1087
                float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue() / 100.0F;
90 ilm 1088
                this.textPVHT.setText(ttc.divide(BigDecimal.valueOf(taux).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION)
83 ilm 1089
                        .setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
1090
            }
1091
        }
1092
        this.textPVHT.getDocument().addDocumentListener(this.htDocListener);
1093
    }
1094
 
1095
    private void setTextTTC() {
1096
        this.textPVTTC.getDocument().removeDocumentListener(this.ttcDocListener);
1097
        final BigDecimal ht = StringUtils.getBigDecimalFromUserText(this.textPVHT.getText());
1098
        if (ht != null) {
1099
            int id = this.comboSelTaxe.getSelectedId();
1100
            if (id > 1) {
1101
                final Float resultTaux = TaxeCache.getCache().getTauxFromId(id);
1102
                final float taux = (resultTaux == null) ? 0.0F : resultTaux.floatValue() / 100.0F;
90 ilm 1103
                this.textPVTTC.setText(ht.multiply(BigDecimal.valueOf(taux).add(BigDecimal.ONE), DecimalUtils.HIGH_PRECISION)
83 ilm 1104
                        .setScale(getTable().getField("PV_TTC").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
1105
            }
1106
        }
1107
        this.textPVTTC.getDocument().addDocumentListener(this.ttcDocListener);
1108
    }
1109
 
1110
    /**
1111
     * calcul du prix achat et vente ainsi que le poids total pour la piece
1112
     */
1113
    private void updatePiece() {
1114
        if (this.comboSelModeVente.getSelectedId() > 1 && this.comboSelModeVente.getSelectedId() != ReferenceArticleSQLElement.A_LA_PIECE) {
1115
            SQLRowValues rowVals = getDetailsRowValues();
1116
            float poidsTot = ReferenceArticleSQLElement.getPoidsFromDetails(rowVals);
1117
            this.textPoids.setText(String.valueOf(poidsTot));
1118
            this.textPAHT.setText(ReferenceArticleSQLElement.getPrixHAFromDetails(rowVals).setScale(getTable().getField("PA_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
1119
            this.textPVHT.setText(ReferenceArticleSQLElement.getPrixVTFromDetails(rowVals).setScale(getTable().getField("PV_HT").getType().getDecimalDigits(), RoundingMode.HALF_UP).toString());
1120
        }
1121
    }
1122
 
1123
    public int getSelectedTaxe() {
1124
        return this.comboSelTaxe.getSelectedId();
1125
    }
1126
 
1127
    public SQLRowValues getDetailsRowValues() {
1128
        final SQLRowValues rowVals = new SQLRowValues(getTable());
1129
 
1130
        BigDecimal pAchat = StringUtils.getBigDecimalFromUserText(this.textMetrique1HA.getText());
1131
        if (pAchat == null) {
1132
            pAchat = BigDecimal.ZERO;
1133
        }
1134
        rowVals.put("PRIX_METRIQUE_HA_1", pAchat);
1135
 
1136
        BigDecimal pVente = StringUtils.getBigDecimalFromUserText(this.textMetrique1VT.getText());
1137
        if (pVente == null) {
1138
            pVente = BigDecimal.ZERO;
1139
        }
1140
        rowVals.put("PRIX_METRIQUE_VT_1", pVente);
1141
        put(rowVals, this.textValMetrique1);
1142
        put(rowVals, this.textValMetrique2);
1143
        put(rowVals, this.textValMetrique3);
1144
        rowVals.put("ID_MODE_VENTE_ARTICLE", this.comboSelModeVente.getSelectedId());
1145
 
1146
        return rowVals;
1147
    }
1148
 
1149
    private void put(SQLRowValues rowVals, JTextField comp) {
1150
        Float f = (comp.getText() == null || comp.getText().trim().length() == 0) ? 0.0F : Float.valueOf(comp.getText());
1151
        rowVals.put(this.getView(comp).getField().getName(), f);
1152
    }
1153
 
1154
}