OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 180 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 177
Line 21... Line 21...
21
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
21
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
22
import org.openconcerto.erp.core.sales.product.element.ArticleCodeClientTable;
22
import org.openconcerto.erp.core.sales.product.element.ArticleCodeClientTable;
23
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
23
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
24
import org.openconcerto.erp.core.sales.product.element.SupplierPriceListTable;
24
import org.openconcerto.erp.core.sales.product.element.SupplierPriceListTable;
25
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
25
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
-
 
26
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
26
import org.openconcerto.erp.core.sales.product.ui.ArticleCategorieComptableTable;
27
import org.openconcerto.erp.core.sales.product.ui.ArticleCategorieComptableTable;
27
import org.openconcerto.erp.core.sales.product.ui.ArticleDesignationTable;
28
import org.openconcerto.erp.core.sales.product.ui.ArticleDesignationTable;
28
import org.openconcerto.erp.core.sales.product.ui.ArticleTarifTable;
29
import org.openconcerto.erp.core.sales.product.ui.ArticleTarifTable;
29
import org.openconcerto.erp.core.sales.product.ui.ProductItemListTable;
30
import org.openconcerto.erp.core.sales.product.ui.ProductItemListTable;
30
import org.openconcerto.erp.core.sales.product.ui.ProductQtyPriceListTable;
31
import org.openconcerto.erp.core.sales.product.ui.ProductQtyPriceListTable;
31
import org.openconcerto.erp.core.sales.product.ui.RowValuesTableEditionPanel;
32
import org.openconcerto.erp.core.sales.product.ui.RowValuesTableEditionPanel;
32
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
-
 
33
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
33
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
34
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
-
 
35
import org.openconcerto.erp.model.ISQLCompteSelector;
34
import org.openconcerto.erp.model.ISQLCompteSelector;
36
import org.openconcerto.erp.preferences.DefaultNXProps;
35
import org.openconcerto.erp.preferences.DefaultNXProps;
37
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
36
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
38
import org.openconcerto.sql.Configuration;
37
import org.openconcerto.sql.Configuration;
39
import org.openconcerto.sql.element.BaseSQLComponent;
38
import org.openconcerto.sql.element.BaseSQLComponent;
Line 48... Line 47...
48
import org.openconcerto.sql.preferences.SQLPreferences;
47
import org.openconcerto.sql.preferences.SQLPreferences;
49
import org.openconcerto.sql.sqlobject.ElementComboBox;
48
import org.openconcerto.sql.sqlobject.ElementComboBox;
50
import org.openconcerto.sql.sqlobject.SQLTextCombo;
49
import org.openconcerto.sql.sqlobject.SQLTextCombo;
51
import org.openconcerto.ui.DefaultGridBagConstraints;
50
import org.openconcerto.ui.DefaultGridBagConstraints;
52
import org.openconcerto.ui.FormLayouter;
51
import org.openconcerto.ui.FormLayouter;
-
 
52
import org.openconcerto.ui.JDate;
53
import org.openconcerto.ui.TitledSeparator;
53
import org.openconcerto.ui.TitledSeparator;
54
import org.openconcerto.ui.component.ITextArea;
54
import org.openconcerto.ui.component.ITextArea;
55
import org.openconcerto.ui.preferences.DefaultProps;
55
import org.openconcerto.ui.preferences.DefaultProps;
56
import org.openconcerto.utils.DecimalUtils;
56
import org.openconcerto.utils.DecimalUtils;
57
import org.openconcerto.utils.ExceptionHandler;
57
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.StringUtils;
58
import org.openconcerto.utils.StringUtils;
-
 
59
import org.openconcerto.utils.Tuple2;
59
import org.openconcerto.utils.text.SimpleDocumentListener;
60
import org.openconcerto.utils.text.SimpleDocumentListener;
60
 
61
 
61
import java.awt.Component;
62
import java.awt.Component;
62
import java.awt.GridBagConstraints;
63
import java.awt.GridBagConstraints;
63
import java.awt.GridBagLayout;
64
import java.awt.GridBagLayout;
Line 67... Line 68...
67
import java.beans.PropertyChangeEvent;
68
import java.beans.PropertyChangeEvent;
68
import java.beans.PropertyChangeListener;
69
import java.beans.PropertyChangeListener;
69
import java.math.BigDecimal;
70
import java.math.BigDecimal;
70
import java.math.RoundingMode;
71
import java.math.RoundingMode;
71
import java.sql.SQLException;
72
import java.sql.SQLException;
72
import java.util.ArrayList;
-
 
73
import java.util.Date;
73
import java.util.Date;
74
import java.util.List;
74
import java.util.List;
75
 
75
 
76
import javax.swing.JButton;
76
import javax.swing.JButton;
77
import javax.swing.JCheckBox;
77
import javax.swing.JCheckBox;
Line 82... Line 82...
82
import javax.swing.JTabbedPane;
82
import javax.swing.JTabbedPane;
83
import javax.swing.JTextField;
83
import javax.swing.JTextField;
84
import javax.swing.SwingConstants;
84
import javax.swing.SwingConstants;
85
import javax.swing.event.DocumentEvent;
85
import javax.swing.event.DocumentEvent;
86
import javax.swing.event.DocumentListener;
86
import javax.swing.event.DocumentListener;
-
 
87
import javax.swing.event.TableModelEvent;
-
 
88
import javax.swing.event.TableModelListener;
87
 
89
 
88
public class ReferenceArticleSQLComponent extends BaseSQLComponent {
90
public class ReferenceArticleSQLComponent extends BaseSQLComponent {
89
 
91
 
90
    private JTextField textPVHT, textPVTTC, textPAHT;
92
    private JTextField textPVHT, textPVTTC, textPAHT;
91
    private JTextField textMetrique1VT, textMetrique1HA;
93
    private JTextField textMetrique1VT, textMetrique1HA;
Line 464... Line 466...
464
            public void propertyChange(PropertyChangeEvent evt) {
466
            public void propertyChange(PropertyChangeEvent evt) {
465
                System.err.println(ReferenceArticleSQLComponent.this.comboSelModeVente.getSelectedId());
467
                System.err.println(ReferenceArticleSQLComponent.this.comboSelModeVente.getSelectedId());
466
                selectModeVente(ReferenceArticleSQLComponent.this.comboSelModeVente.getSelectedId());
468
                selectModeVente(ReferenceArticleSQLComponent.this.comboSelModeVente.getSelectedId());
467
 
469
 
468
            }
470
            }
-
 
471
 
469
        };
472
        };
470
        setListenerModeVenteActive(true);
473
        setListenerModeVenteActive(true);
471
        this.comboSelModeVente.setValue(ReferenceArticleSQLElement.A_LA_PIECE);
474
        this.comboSelModeVente.setValue(ReferenceArticleSQLElement.A_LA_PIECE);
472
    }
475
    }
473
 
476
 
Line 496... Line 499...
496
        c.gridx++;
499
        c.gridx++;
497
        JTextField textTare = new JTextField(40);
500
        JTextField textTare = new JTextField(40);
498
        panel.add(textTare, c);
501
        panel.add(textTare, c);
499
        addView(textTare, "TARE");
502
        addView(textTare, "TARE");
500
 
503
 
-
 
504
        c.gridy++;
-
 
505
        c.gridx = 0;
-
 
506
        c.weightx = 0;
-
 
507
        JLabel labelDLC = new JLabel(getLabelFor("DLC"));
-
 
508
        panel.add(labelDLC, c);
-
 
509
        c.weightx = 1;
-
 
510
        c.gridx++;
-
 
511
        JDate dateDLC = new JDate();
-
 
512
        panel.add(dateDLC, c);
-
 
513
        addView(dateDLC, "DLC");
-
 
514
 
501
        c.weightx = 0;
515
        c.weightx = 0;
502
        c.gridy++;
516
        c.gridy++;
503
        c.gridx = 0;
517
        c.gridx = 0;
-
 
518
        if (getTable().contains("POIDS_COLIS_NET")) {
-
 
519
            JLabel labelPdsColis = new JLabel(getLabelFor("POIDS_COLIS_NET"));
-
 
520
            panel.add(labelPdsColis, c);
-
 
521
            c.weightx = 1;
-
 
522
            c.gridx++;
-
 
523
            JTextField textPdsColis = new JTextField(40);
-
 
524
            panel.add(textPdsColis, c);
-
 
525
            addView(textPdsColis, "POIDS_COLIS_NET");
-
 
526
            c.gridx++;
-
 
527
        }
-
 
528
 
504
        JLabel labelMasque = new JLabel(getLabelFor("MASQUE_CAISSE"));
529
        JLabel labelMasque = new JLabel(getLabelFor("MASQUE_CAISSE"));
505
        c.fill = GridBagConstraints.BOTH;
530
        c.fill = GridBagConstraints.BOTH;
506
        panel.add(labelMasque, c);
531
        panel.add(labelMasque, c);
507
        c.weightx = 1;
532
        c.weightx = 1;
508
        c.gridx++;
533
        c.gridx++;
Line 587... Line 612...
587
            c.weightx = 1;
612
            c.weightx = 1;
588
            c.gridx++;
613
            c.gridx++;
589
            panel.add(fieldColoris, c);
614
            panel.add(fieldColoris, c);
590
            this.addView(fieldColoris, "COLORIS");
615
            this.addView(fieldColoris, "COLORIS");
591
        }
616
        }
-
 
617
        JTextField fieldLongueur = new JTextField();
-
 
618
        c.gridy++;
-
 
619
        c.fill = GridBagConstraints.HORIZONTAL;
-
 
620
        c.weightx = 0;
-
 
621
        c.gridwidth = 1;
-
 
622
        panel.add(new JLabel(getLabelFor("LONGUEUR")), c);
-
 
623
 
-
 
624
        c.weightx = 1;
-
 
625
        c.gridx++;
-
 
626
        panel.add(fieldLongueur, c);
-
 
627
        this.addView(fieldLongueur, "LONGUEUR");
-
 
628
 
-
 
629
        JTextField fieldLargeur = new JTextField();
-
 
630
        c.gridx++;
-
 
631
        c.fill = GridBagConstraints.HORIZONTAL;
-
 
632
        c.weightx = 0;
-
 
633
        c.gridwidth = 1;
-
 
634
        panel.add(new JLabel(getLabelFor("LARGEUR")), c);
-
 
635
        c.weightx = 1;
-
 
636
        c.gridx++;
-
 
637
        panel.add(fieldLargeur, c);
-
 
638
        this.addView(fieldLargeur, "LARGEUR");
-
 
639
 
-
 
640
        JTextField fieldHauteur = new JTextField();
-
 
641
        c.gridy++;
-
 
642
        c.gridx = 0;
-
 
643
        c.fill = GridBagConstraints.HORIZONTAL;
-
 
644
        c.weightx = 0;
-
 
645
        c.gridwidth = 1;
-
 
646
        panel.add(new JLabel(getLabelFor("HAUTEUR")), c);
-
 
647
 
-
 
648
        c.weightx = 1;
-
 
649
        c.gridx++;
-
 
650
        panel.add(fieldHauteur, c);
-
 
651
        this.addView(fieldHauteur, "HAUTEUR");
-
 
652
 
592
        ITextArea area = new ITextArea();
653
        ITextArea area = new ITextArea();
593
        JLabel sep = new JLabel("Descriptif complet");
654
        JLabel sep = new JLabel("Descriptif complet");
594
        c.gridy++;
655
        c.gridy++;
595
        c.gridx = 0;
656
        c.gridx = 0;
596
        c.gridwidth = GridBagConstraints.REMAINDER;
657
        c.gridwidth = GridBagConstraints.REMAINDER;
Line 834... Line 895...
834
        this.addView(comboSelFournisseur, "ID_FOURNISSEUR");
895
        this.addView(comboSelFournisseur, "ID_FOURNISSEUR");
835
 
896
 
836
        SQLPreferences prefs = new SQLPreferences(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
897
        SQLPreferences prefs = new SQLPreferences(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
837
        final boolean supplierCode = prefs.getBoolean(GestionArticleGlobalPreferencePanel.SUPPLIER_PRODUCT_CODE, false);
898
        final boolean supplierCode = prefs.getBoolean(GestionArticleGlobalPreferencePanel.SUPPLIER_PRODUCT_CODE, false);
838
 
899
 
839
        if (getTable().getSchema().contains("CODE_FOURNISSEUR") && supplierCode) {
-
 
840
            this.rowValuesDefaultCodeFournisseur = new SQLRowValues(getTable().getTable("CODE_FOURNISSEUR"));
-
 
841
            this.codeFournisseurTable = new CodeFournisseurItemTable(this.rowValuesDefaultCodeFournisseur);
-
 
842
            c.gridy++;
-
 
843
            c.gridx = 0;
-
 
844
            c.gridwidth = 3;
-
 
845
            c.weighty = 1;
-
 
846
            c.weightx = 1;
-
 
847
            c.fill = GridBagConstraints.BOTH;
-
 
848
            panel.add(this.codeFournisseurTable, c);
-
 
849
            comboSelFournisseur.addValueListener(new PropertyChangeListener() {
-
 
850
 
-
 
851
                @Override
-
 
852
                public void propertyChange(PropertyChangeEvent evt) {
-
 
853
                    rowValuesDefaultCodeFournisseur.put("ID_FOURNISSEUR", comboSelFournisseur.getSelectedId());
-
 
854
                }
-
 
855
            });
-
 
856
        } else {
-
 
857
 
-
 
858
            // Tarif fournisseur
900
        // Tarif fournisseur
859
            c.gridy++;
901
        c.gridy++;
860
            c.gridx = 0;
902
        c.gridx = 0;
861
            c.gridwidth = GridBagConstraints.REMAINDER;
903
        c.gridwidth = GridBagConstraints.REMAINDER;
862
            TitledSeparator sep = new TitledSeparator("Tarifs fournisseurs");
904
        TitledSeparator sep = new TitledSeparator("Tarifs fournisseurs");
Line 931... Line 973...
931
                @Override
973
            @Override
932
                public void actionPerformed(ActionEvent e) {
974
            public void actionPerformed(ActionEvent e) {
933
                    tableFourSec.removeSelectedRow();
975
                tableFourSec.removeSelectedRow();
934
                }
976
            }
935
            });
977
        });
-
 
978
        if (getTable().getSchema().contains("CODE_FOURNISSEUR") && supplierCode) {
-
 
979
            c.gridy++;
-
 
980
            c.gridx = 0;
-
 
981
            c.gridwidth = GridBagConstraints.REMAINDER;
-
 
982
            TitledSeparator sepC = new TitledSeparator("Codes fournisseurs");
-
 
983
            panel.add(sepC, c);
-
 
984
 
-
 
985
            this.rowValuesDefaultCodeFournisseur = new SQLRowValues(getTable().getTable("CODE_FOURNISSEUR"));
-
 
986
            this.codeFournisseurTable = new CodeFournisseurItemTable(this.rowValuesDefaultCodeFournisseur);
-
 
987
            c.gridy++;
-
 
988
            c.gridx = 0;
-
 
989
            c.gridwidth = GridBagConstraints.REMAINDER;
-
 
990
            c.weighty = 1;
-
 
991
            c.weightx = 1;
-
 
992
            c.fill = GridBagConstraints.BOTH;
-
 
993
            panel.add(this.codeFournisseurTable, c);
-
 
994
            comboSelFournisseur.addValueListener(new PropertyChangeListener() {
-
 
995
 
-
 
996
                @Override
-
 
997
                public void propertyChange(PropertyChangeEvent evt) {
-
 
998
                    rowValuesDefaultCodeFournisseur.put("ID_FOURNISSEUR", comboSelFournisseur.getSelectedId());
-
 
999
                }
-
 
1000
            });
936
        }
1001
        }
937
        return panel;
1002
        return panel;
-
 
1003
 
938
    }
1004
    }
939
 
1005
 
940
    private JPanel createExportationPanel() {
1006
    private JPanel createExportationPanel() {
941
        JPanel panel = new JPanel(new GridBagLayout());
1007
        JPanel panel = new JPanel(new GridBagLayout());
942
        panel.setOpaque(false);
1008
        panel.setOpaque(false);
Line 1141... Line 1207...
1141
    private JPanel createBOMpanel() {
1207
    private JPanel createBOMpanel() {
1142
        JPanel panel = new JPanel(new GridBagLayout());
1208
        JPanel panel = new JPanel(new GridBagLayout());
1143
        panel.setOpaque(false);
1209
        panel.setOpaque(false);
1144
        GridBagConstraints c = new DefaultGridBagConstraints();
1210
        GridBagConstraints c = new DefaultGridBagConstraints();
1145
 
1211
 
-
 
1212
        final JCheckBox checkAutoPrice = new JCheckBox(getLabelFor("AUTO_PRIX_MIN_VENTE_NOMENCLATURE"));
-
 
1213
        panel.add(checkAutoPrice, c);
-
 
1214
        this.addView(checkAutoPrice, "AUTO_PRIX_MIN_VENTE_NOMENCLATURE");
-
 
1215
        c.gridx++;
-
 
1216
        final JCheckBox checkAutoPriceHA = new JCheckBox(getLabelFor("AUTO_PRIX_ACHAT_NOMENCLATURE"));
-
 
1217
        panel.add(checkAutoPriceHA, c);
-
 
1218
        this.addView(checkAutoPriceHA, "AUTO_PRIX_ACHAT_NOMENCLATURE");
-
 
1219
 
-
 
1220
        checkAutoPrice.addActionListener(new ActionListener() {
-
 
1221
 
-
 
1222
            @Override
-
 
1223
            public void actionPerformed(ActionEvent e) {
-
 
1224
                updatePricesNomenclature(checkAutoPrice, checkAutoPriceHA);
-
 
1225
            }
-
 
1226
        });
-
 
1227
        checkAutoPriceHA.addActionListener(new ActionListener() {
-
 
1228
 
-
 
1229
            @Override
-
 
1230
            public void actionPerformed(ActionEvent e) {
-
 
1231
                updatePricesNomenclature(checkAutoPrice, checkAutoPriceHA);
-
 
1232
            }
-
 
1233
        });
-
 
1234
 
1146
        c.gridwidth = GridBagConstraints.REMAINDER;
1235
        c.gridwidth = GridBagConstraints.REMAINDER;
1147
        c.fill = GridBagConstraints.BOTH;
1236
        c.fill = GridBagConstraints.BOTH;
1148
        c.weightx = 1;
1237
        c.weightx = 1;
1149
        c.weighty = 1;
1238
        c.weighty = 1;
1150
        c.gridx = 0;
1239
        c.gridx = 0;
-
 
1240
        c.gridy++;
1151
        c.fill = GridBagConstraints.BOTH;
1241
        c.fill = GridBagConstraints.BOTH;
1152
        this.tableBom.setOpaque(false);
1242
        this.tableBom.setOpaque(false);
1153
        panel.add(new RowValuesTableEditionPanel(this.tableBom), c);
1243
        panel.add(new RowValuesTableEditionPanel(this.tableBom), c);
-
 
1244
 
-
 
1245
        this.tableBom.getModel().addTableModelListener(new TableModelListener() {
-
 
1246
 
-
 
1247
            @Override
-
 
1248
            public void tableChanged(TableModelEvent e) {
-
 
1249
                updatePricesNomenclature(checkAutoPrice, checkAutoPriceHA);
-
 
1250
 
-
 
1251
            }
-
 
1252
 
-
 
1253
        });
1154
        return panel;
1254
        return panel;
-
 
1255
 
-
 
1256
    }
-
 
1257
 
-
 
1258
    private void updatePricesNomenclature(final JCheckBox checkAutoPrice, final JCheckBox checkAutoPriceHA) {
-
 
1259
        final Boolean vtAuto = checkAutoPrice.isSelected();
-
 
1260
        final Boolean haAuto = checkAutoPriceHA.isSelected();
-
 
1261
        if (vtAuto || haAuto) {
-
 
1262
            ProductHelper helper = new ProductHelper(getTable().getDBRoot());
-
 
1263
 
-
 
1264
            Tuple2<BigDecimal, BigDecimal> p = helper.getStandardBomPrices(tableBom.getRowValuesTable().getRowValuesTableModel().getCopyOfValues());
-
 
1265
            if (haAuto && p.get0() != null) {
-
 
1266
                textPAHT.setText(p.get0().toString());
-
 
1267
            }
-
 
1268
            if (vtAuto && p.get1() != null) {
-
 
1269
                textPVHT.setText(p.get1().toString());
-
 
1270
            }
-
 
1271
        }
1155
    }
1272
    }
1156
 
1273
 
1157
    private JPanel createTarifQtePanel() {
1274
    private JPanel createTarifQtePanel() {
1158
        JPanel panel = new JPanel(new GridBagLayout());
1275
        JPanel panel = new JPanel(new GridBagLayout());
1159
        panel.setOpaque(false);
1276
        panel.setOpaque(false);
Line 1561... Line 1678...
1561
    }
1678
    }
1562
 
1679
 
1563
    @Override
1680
    @Override
1564
    public void update() {
1681
    public void update() {
1565
        SQLRow row = this.getTable().getRow(this.getSelectedID());
1682
        SQLRow row = this.getTable().getRow(this.getSelectedID());
-
 
1683
        final int selectedID = getSelectedID();
1566
            super.update();
1684
            super.update();
1567
        this.tableTarifVente.updateField("ID_ARTICLE", getSelectedID());
1685
        this.tableTarifVente.updateField("ID_ARTICLE", selectedID);
1568
        this.tableCatComptable.updateField("ID_ARTICLE", getSelectedID());
1686
        this.tableCatComptable.updateField("ID_ARTICLE", selectedID);
1569
        this.tableFourSec.updateField("ID_ARTICLE", getSelectedID());
1687
        this.tableFourSec.updateField("ID_ARTICLE", selectedID);
1570
        this.tableTarifQteVente.updateField("ID_ARTICLE", getSelectedID());
1688
        this.tableTarifQteVente.updateField("ID_ARTICLE", selectedID);
1571
        if (this.tableBom != null) {
1689
        if (this.tableBom != null) {
1572
            this.tableBom.updateField("ID_ARTICLE_PARENT", getSelectedID());
1690
            this.tableBom.updateField("ID_ARTICLE_PARENT", selectedID);
1573
        }
1691
        }
1574
 
1692
 
1575
        this.tableDes.updateField("ID_ARTICLE", getSelectedID());
1693
        this.tableDes.updateField("ID_ARTICLE", selectedID);
1576
        this.tableCodeClient.updateField("ID_ARTICLE", getSelectedID());
1694
        this.tableCodeClient.updateField("ID_ARTICLE", selectedID);
1577
        if (this.codeFournisseurTable != null) {
1695
        if (this.codeFournisseurTable != null) {
1578
            this.codeFournisseurTable.updateField("ID_ARTICLE", getSelectedID());
1696
            this.codeFournisseurTable.updateField("ID_ARTICLE", selectedID);
1579
        }
1697
        }
1580
 
1698
 
1581
        ((ReferenceArticleSQLElement) getElement()).initStock(getSelectedID());
1699
        ((ReferenceArticleSQLElement) getElement()).initStock(selectedID);
1582
 
1700
 
1583
        SQLSelect sel = new SQLSelect();
1701
        SQLSelect sel = new SQLSelect();
1584
        SQLTable tableStock = getTable().getTable("STOCK");
1702
        SQLTable tableStock = getTable().getTable("STOCK");
1585
        sel.addSelect(tableStock.getKey());
1703
        sel.addSelect(tableStock.getKey());
1586
        Where w = new Where(tableStock.getField("ID_ARTICLE"), "=", getSelectedID()).and(new Where(tableStock.getField("ID_DEPOT_STOCK"), "=", row.getForeignID("ID_DEPOT_STOCK")));
1704
        Where w = new Where(tableStock.getField("ID_ARTICLE"), "=", selectedID).and(new Where(tableStock.getField("ID_DEPOT_STOCK"), "=", row.getForeignID("ID_DEPOT_STOCK")));
1587
        sel.setWhere(w);
1705
        sel.setWhere(w);
1588
 
1706
 
1589
        List<SQLRow> stock = SQLRowListRSH.execute(sel);
1707
        List<SQLRow> stock = SQLRowListRSH.execute(sel);
1590
        if (stock != null && stock.size() == 1) {
1708
        if (stock != null && stock.size() == 1) {
1591
            try {
1709
            try {
Line 1593... Line 1711...
1593
            } catch (SQLException e) {
1711
            } catch (SQLException e) {
1594
                ExceptionHandler.handle("Erreur lors de la mise à jour du stock principal", e);
1712
                ExceptionHandler.handle("Erreur lors de la mise à jour du stock principal", e);
1595
            }
1713
            }
1596
        }
1714
        }
1597
 
1715
 
-
 
1716
        Runnable r = new Runnable() {
-
 
1717
            @Override
-
 
1718
            public void run() {
-
 
1719
                SQLRow rowArticle = getTable().getRow(selectedID);
-
 
1720
                List<SQLRow> itemsRows = rowArticle.getReferentRows(getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE"));
-
 
1721
                for (SQLRow rowArticleItem : itemsRows) {
-
 
1722
                    SQLRow rowA = rowArticleItem.getForeign("ID_ARTICLE_PARENT");
-
 
1723
 
-
 
1724
                    if (rowA != null && !rowA.isUndefined()) {
-
 
1725
                        final Boolean vtAuto = rowA.getBoolean("AUTO_PRIX_MIN_VENTE_NOMENCLATURE");
-
 
1726
                        final Boolean haAuto = rowA.getBoolean("AUTO_PRIX_ACHAT_NOMENCLATURE");
-
 
1727
                        if (vtAuto || haAuto) {
-
 
1728
                            ProductHelper helper = new ProductHelper(rowA.getTable().getDBRoot());
-
 
1729
                            Tuple2<BigDecimal, BigDecimal> p = helper.getStandardBomPrices(rowA.getReferentRows(rowA.getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")));
-
 
1730
                            SQLRowValues rowVals = rowA.createEmptyUpdateRow();
-
 
1731
                            boolean up = false;
-
 
1732
                            if (vtAuto && p.get1() != null) {
-
 
1733
                                rowVals.put("PRIX_METRIQUE_VT_1", p.get1());
-
 
1734
                                rowVals.put("PV_HT", p.get1());
-
 
1735
                                float t = TaxeCache.getCache().getFirstTaxe().getFloat("TAUX");
-
 
1736
                                if (!rowA.isForeignEmpty("ID_TAXE")) {
-
 
1737
                                    t = TaxeCache.getCache().getTauxFromId(rowA.getForeignID("ID_TAXE"));
-
 
1738
                                }
-
 
1739
 
-
 
1740
                                rowVals.put("PV_TTC", p.get1().multiply(new BigDecimal(t).movePointLeft(2).add(BigDecimal.ONE)).setScale(2, RoundingMode.HALF_UP));
-
 
1741
                                up = true;
-
 
1742
                            }
-
 
1743
                            if (haAuto && p.get0() != null) {
-
 
1744
                                rowVals.put("PRIX_METRIQUE_HA_1", p.get0());
-
 
1745
                                rowVals.put("PA_HT", p.get0());
-
 
1746
                                up = true;
-
 
1747
                            }
-
 
1748
                            if (up) {
-
 
1749
                                try {
-
 
1750
                                    rowVals.commit();
-
 
1751
                                } catch (SQLException e) {
-
 
1752
                                    ExceptionHandler.handle("Erreur lors de la mise à jour des tarifs des nomenclatures", e);
-
 
1753
                                }
-
 
1754
                            }
-
 
1755
                        }
-
 
1756
                    }
-
 
1757
                }
-
 
1758
 
-
 
1759
            }
-
 
1760
        };
-
 
1761
        new Thread(r).run();
-
 
1762
        ReferenceArticleSQLElement.updateDateAchat(getTable(), getTable().getRow(selectedID));
-
 
1763
 
1598
    }
1764
    }
1599
 
1765
 
1600
    /**
1766
    /**
1601
     * Sélection d'un mode de vente pour l'article. Affiche les prix metriques requis et fixe les
1767
     * Sélection d'un mode de vente pour l'article. Affiche les prix metriques requis et fixe les
1602
     * valeurs.
1768
     * valeurs.
Line 1659... Line 1825...
1659
        this.tableCodeClient.updateField("ID_ARTICLE", id);
1825
        this.tableCodeClient.updateField("ID_ARTICLE", id);
1660
        if (this.codeFournisseurTable != null) {
1826
        if (this.codeFournisseurTable != null) {
1661
            this.codeFournisseurTable.updateField("ID_ARTICLE", id);
1827
            this.codeFournisseurTable.updateField("ID_ARTICLE", id);
1662
        }
1828
        }
1663
        ((ReferenceArticleSQLElement) getElement()).initStock(id);
1829
        ((ReferenceArticleSQLElement) getElement()).initStock(id);
-
 
1830
        ReferenceArticleSQLElement.updateDateAchat(getTable(), getTable().getRow(id));
1664
        return id;
1831
        return id;
1665
    }
1832
    }
1666
 
1833
 
1667
    @Override
1834
    @Override
1668
    protected SQLRowValues createDefaults() {
1835
    protected SQLRowValues createDefaults() {