OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 142 Rev 156
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.erp.core.sales.product.element;
14
 package org.openconcerto.erp.core.sales.product.element;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.ui.PanelFrame;
-
 
19
import org.openconcerto.erp.core.edm.AttachmentAction;
18
import org.openconcerto.erp.core.edm.AttachmentAction;
20
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
19
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
-
 
20
import org.openconcerto.erp.core.reports.history.ui.HistoriqueArticleFrame;
21
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
21
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
22
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
22
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
-
 
23
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater;
-
 
24
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
-
 
25
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
23
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
26
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
24
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
27
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
25
import org.openconcerto.erp.preferences.DefaultNXProps;
28
import org.openconcerto.erp.preferences.DefaultNXProps;
26
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
29
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
27
import org.openconcerto.sql.Configuration;
30
import org.openconcerto.sql.Configuration;
Line 35... Line 38...
35
import org.openconcerto.sql.model.SQLSelect;
38
import org.openconcerto.sql.model.SQLSelect;
36
import org.openconcerto.sql.model.SQLTable;
39
import org.openconcerto.sql.model.SQLTable;
37
import org.openconcerto.sql.model.Where;
40
import org.openconcerto.sql.model.Where;
38
import org.openconcerto.sql.model.graph.Path;
41
import org.openconcerto.sql.model.graph.Path;
39
import org.openconcerto.sql.preferences.SQLPreferences;
42
import org.openconcerto.sql.preferences.SQLPreferences;
-
 
43
import org.openconcerto.sql.request.ComboSQLRequest;
40
import org.openconcerto.sql.view.EditFrame;
44
import org.openconcerto.sql.view.EditFrame;
41
import org.openconcerto.sql.view.EditPanel.EditMode;
45
import org.openconcerto.sql.view.EditPanel.EditMode;
42
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
46
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
43
import org.openconcerto.sql.view.list.IListe;
47
import org.openconcerto.sql.view.list.IListe;
44
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
48
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
45
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
49
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
46
import org.openconcerto.sql.view.list.SQLTableModelColumn;
50
import org.openconcerto.sql.view.list.SQLTableModelColumn;
47
import org.openconcerto.sql.view.list.SQLTableModelSource;
51
import org.openconcerto.sql.view.list.SQLTableModelSource;
48
import org.openconcerto.ui.FrameUtil;
52
import org.openconcerto.ui.FrameUtil;
-
 
53
import org.openconcerto.ui.PanelFrame;
49
import org.openconcerto.utils.CollectionUtils;
54
import org.openconcerto.utils.CollectionUtils;
50
import org.openconcerto.utils.DecimalUtils;
55
import org.openconcerto.utils.DecimalUtils;
-
 
56
import org.openconcerto.utils.ExceptionHandler;
51
import org.openconcerto.utils.ListMap;
57
import org.openconcerto.utils.ListMap;
52
 
58
 
53
import java.awt.event.ActionEvent;
59
import java.awt.event.ActionEvent;
54
import java.math.BigDecimal;
60
import java.math.BigDecimal;
55
import java.sql.SQLException;
61
import java.sql.SQLException;
56
import java.util.ArrayList;
62
import java.util.ArrayList;
57
import java.util.Collection;
63
import java.util.Collection;
-
 
64
import java.util.HashMap;
58
import java.util.List;
65
import java.util.List;
-
 
66
import java.util.Map;
59
import java.util.Set;
67
import java.util.Set;
60
 
68
 
61
import javax.swing.AbstractAction;
69
import javax.swing.AbstractAction;
62
 
70
 
63
import org.apache.commons.dbutils.handlers.ArrayListHandler;
71
import org.apache.commons.dbutils.handlers.ArrayListHandler;
Line 68... Line 76...
68
    public static final int AU_POID_METRECARRE = 4;
76
    public static final int AU_POID_METRECARRE = 4;
69
    public static final int A_LA_PIECE = 5;
77
    public static final int A_LA_PIECE = 5;
70
    public static final int AU_METRE_LARGEUR = 6;
78
    public static final int AU_METRE_LARGEUR = 6;
71
    private static final int PRIX_HA = 1;
79
    private static final int PRIX_HA = 1;
72
    private static final int PRIX_VT = 2;
80
    private static final int PRIX_VT = 2;
73
    protected final PredicateRowAction stock;
81
    protected PredicateRowAction stock;
74
 
82
 
75
    public static final String[] CONDITIONS = new String[] { "CFR", "CIF", "CPT", "DAT", "DDP", "DDU", "EXW", "FCA", "FOB" };
83
    public static final String[] CONDITIONS = new String[] { "CFR", "CIF", "CPT", "DAT", "DDP", "DDU", "EXW", "FCA", "FOB" };
76
 
84
 
77
    public ReferenceArticleSQLElement() {
85
    public ReferenceArticleSQLElement() {
78
        super("ARTICLE", "un article", "articles");
86
        super("ARTICLE", "un article", "articles");
Line 81... Line 89...
81
        this.stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
89
        this.stock = new PredicateRowAction(new AbstractAction("Mettre à jour les stocks") {
82
 
90
 
83
            @Override
91
            @Override
84
            public void actionPerformed(ActionEvent e) {
92
            public void actionPerformed(ActionEvent e) {
85
 
93
 
-
 
94
                final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows();
-
 
95
                List<SQLRowAccessor> l = new ArrayList<SQLRowAccessor>();
-
 
96
                for (SQLRowValues sqlRowValues : selectedRows) {
-
 
97
                    l.add(sqlRowValues.asRow().getForeign("ID_STOCK"));
-
 
98
                }
-
 
99
 
86
                PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), IListe.get(e).getSelectedRows()), "Mise à jour des stocks");
100
                PanelFrame p = new PanelFrame(new InventairePanel(IListe.get(e), l), "Mise à jour des stocks");
87
                FrameUtil.show(p);
101
                FrameUtil.show(p);
88
 
102
 
89
            }
103
            }
90
        }, true, false);
104
        }, true, false);
91
        stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
105
        stock.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
92
        getRowActions().add(stock);
106
        getRowActions().add(stock);
93
 
107
 
-
 
108
        PredicateRowAction history = new PredicateRowAction(new AbstractAction("Historique") {
-
 
109
 
-
 
110
            @Override
-
 
111
            public void actionPerformed(ActionEvent e) {
-
 
112
                HistoriqueArticleFrame frame = new HistoriqueArticleFrame(ReferenceArticleSQLElement.this);
-
 
113
                frame.selectId(IListe.get(e).getSelectedId());
-
 
114
                frame.setVisible(true);
-
 
115
            }
-
 
116
        }, false, true);
-
 
117
        history.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
118
        getRowActions().add(history);
-
 
119
 
94
        PredicateRowAction clone = new PredicateRowAction(new AbstractAction("Dupliquer") {
120
        PredicateRowAction clone = new PredicateRowAction(new AbstractAction("Dupliquer") {
95
 
121
 
96
            @Override
122
            @Override
97
            public void actionPerformed(ActionEvent e) {
123
            public void actionPerformed(ActionEvent e) {
98
 
124
 
Line 110... Line 136...
110
        clone.setPredicate(IListeEvent.getSingleSelectionPredicate());
136
        clone.setPredicate(IListeEvent.getSingleSelectionPredicate());
111
        getRowActions().add(clone);
137
        getRowActions().add(clone);
112
 
138
 
113
        PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
139
        PredicateRowAction actionAttachment = new PredicateRowAction(new AttachmentAction().getAction(), true);
114
        actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
140
        actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate());
-
 
141
 
115
        getRowActions().add(actionAttachment);
142
        getRowActions().add(actionAttachment);
116
    }
143
    }
117
 
144
 
118
    @Override
145
    @Override
119
    protected synchronized void _initTableSource(final SQLTableModelSource source) {
146
    protected synchronized void _initTableSource(final SQLTableModelSource source) {
Line 190... Line 217...
190
            l.add("ID_TAXE");
217
            l.add("ID_TAXE");
191
        l.add("PV_TTC");
218
        l.add("PV_TTC");
192
        l.add("ID_FAMILLE_ARTICLE");
219
        l.add("ID_FAMILLE_ARTICLE");
193
        l.add("ID_FOURNISSEUR");
220
        l.add("ID_FOURNISSEUR");
194
        l.add("SKU");
221
        l.add("SKU");
-
 
222
 
-
 
223
        // if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
195
        l.add("ID_STOCK");
224
        l.add("ID_STOCK");
-
 
225
        // }
196
        String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
226
        String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
197
        Boolean b = Boolean.valueOf(val);
227
        Boolean b = Boolean.valueOf(val);
198
        if (b != null && b.booleanValue()) {
228
        if (b != null && b.booleanValue()) {
199
            l.add("SERVICE");
229
            l.add("SERVICE");
200
        }
230
        }
Line 206... Line 236...
206
        final ListMap<String, String> res = new ListMap<String, String>();
236
        final ListMap<String, String> res = new ListMap<String, String>();
207
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
237
        SQLPreferences prefs = new SQLPreferences(getTable().getDBRoot());
208
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
238
        if (prefs.getBoolean(GestionArticleGlobalPreferencePanel.SHOW_PRODUCT_BAR_CODE, false)) {
209
            res.add(null, "CODE_BARRE");
239
            res.add(null, "CODE_BARRE");
210
        }
240
        }
211
        res.addAll(null, "NOM", "ID_FAMILLE_ARTICLE");
241
        res.addAll(null, "CODE", "NOM", "ID_FAMILLE_ARTICLE");
212
        return res;
242
        return res;
213
    }
243
    }
214
 
244
 
215
    protected List<String> getComboFields() {
245
    protected List<String> getComboFields() {
216
        final List<String> l = new ArrayList<String>();
246
        final List<String> l = new ArrayList<String>();
Line 382... Line 412...
382
 
412
 
383
        if (createIfNotExist && row.getString("CODE") != null && row.getString("CODE").trim().length() > 0 && row.getString("NOM") != null && row.getString("NOM").trim().length() > 0) {
413
        if (createIfNotExist && row.getString("CODE") != null && row.getString("CODE").trim().length() > 0 && row.getString("NOM") != null && row.getString("NOM").trim().length() > 0) {
384
            SQLRowValues vals = new SQLRowValues(row);
414
            SQLRowValues vals = new SQLRowValues(row);
385
            BigDecimal taux = BigDecimal.ONE.add(new BigDecimal(TaxeCache.getCache().getTauxFromId(row.getForeignID("ID_TAXE")) / 100f));
415
            BigDecimal taux = BigDecimal.ONE.add(new BigDecimal(TaxeCache.getCache().getTauxFromId(row.getForeignID("ID_TAXE")) / 100f));
386
            vals.put("PV_TTC", vals.getBigDecimal("PV_HT").multiply(taux));
416
            vals.put("PV_TTC", vals.getBigDecimal("PV_HT").multiply(taux));
-
 
417
            vals.put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID);
387
            int idArticle;
418
            int idArticle;
388
            try {
419
            try {
389
 
420
 
390
                // Liaison avec l'article fournisseur si il existe
421
                // Liaison avec l'article fournisseur si il existe
391
                SQLSelect selMatchingCodeF = new SQLSelect();
422
                SQLSelect selMatchingCodeF = new SQLSelect();
Line 492... Line 523...
492
    public static boolean isReferenceEquals(SQLRowValues rowVals1, SQLRowValues rowVals2) {
523
    public static boolean isReferenceEquals(SQLRowValues rowVals1, SQLRowValues rowVals2) {
493
        return (rowVals1.getObject("CODE").equals(rowVals2.getObject("CODE")) && rowVals1.getString("VALEUR_METRIQUE_1").equals(rowVals2.getString("VALEUR_METRIQUE_1"))
524
        return (rowVals1.getObject("CODE").equals(rowVals2.getObject("CODE")) && rowVals1.getString("VALEUR_METRIQUE_1").equals(rowVals2.getString("VALEUR_METRIQUE_1"))
494
                && rowVals1.getString("VALEUR_METRIQUE_2").equals(rowVals2.getString("VALEUR_METRIQUE_2")) && rowVals1.getString("VALEUR_METRIQUE_3").equals(rowVals2.getString("VALEUR_METRIQUE_3")));
525
                && rowVals1.getString("VALEUR_METRIQUE_2").equals(rowVals2.getString("VALEUR_METRIQUE_2")) && rowVals1.getString("VALEUR_METRIQUE_3").equals(rowVals2.getString("VALEUR_METRIQUE_3")));
495
    }
526
    }
496
 
527
 
-
 
528
    public void initStock(int id) {
-
 
529
        SQLRow row = getTable().getRow(id);
-
 
530
        SQLSelect sel = new SQLSelect();
-
 
531
        sel.addSelectStar(getTable().getTable("DEPOT_STOCK"));
-
 
532
        List<SQLRow> rowsDepot = SQLRowListRSH.execute(sel);
-
 
533
 
-
 
534
        SQLSelect selStock = new SQLSelect();
-
 
535
        selStock.addSelectStar(getTable().getTable("STOCK"));
-
 
536
        selStock.setWhere(new Where(getTable().getTable("STOCK").getField("ID_ARTICLE"), "=", id));
-
 
537
        List<SQLRow> rowsStock = SQLRowListRSH.execute(selStock);
-
 
538
        Map<Integer, SQLRow> initedDepot = new HashMap<>();
-
 
539
        for (SQLRow sqlRow : rowsStock) {
-
 
540
            initedDepot.put(sqlRow.getForeignID("ID_DEPOT_STOCK"), sqlRow);
-
 
541
        }
-
 
542
 
-
 
543
        List<StockItem> stockItems = new ArrayList<StockItem>();
-
 
544
        for (SQLRow sqlRow : rowsDepot) {
-
 
545
            try {
-
 
546
                if (!initedDepot.keySet().contains(sqlRow.getID())) {
-
 
547
                    SQLRowValues rowVals = new SQLRowValues(getTable().getTable("STOCK"));
-
 
548
                    rowVals.put("ID_ARTICLE", row.getID());
-
 
549
                    rowVals.put("ID_DEPOT_STOCK", sqlRow.getID());
-
 
550
 
-
 
551
                    SQLRow rowStock = rowVals.commit();
-
 
552
                    if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) {
-
 
553
                        row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit();
-
 
554
                    } else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) {
-
 
555
                        row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit();
-
 
556
                    }
-
 
557
                    stockItems.add(new StockItem(row, rowStock));
-
 
558
 
-
 
559
                } else {
-
 
560
                    SQLRow rowExisting = initedDepot.get(sqlRow.getID());
-
 
561
                    if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) {
-
 
562
                        row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit();
-
 
563
                    } else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) {
-
 
564
                        row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).commit();
-
 
565
                    }
-
 
566
                    stockItems.add(new StockItem(row, rowExisting));
-
 
567
                }
-
 
568
            } catch (SQLException e) {
-
 
569
                ExceptionHandler.handle("Erreur lors de l'initialisation du stock de l'article", e);
-
 
570
            }
-
 
571
        }
-
 
572
        if (row.getReferentRows(getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")).size() > 0) {
-
 
573
            ComposedItemStockUpdater up = new ComposedItemStockUpdater(getTable().getDBRoot(), stockItems);
-
 
574
            try {
-
 
575
                up.updateNomenclature(stockItems);
-
 
576
            } catch (SQLException e) {
-
 
577
                ExceptionHandler.handle("Erreur lors de l'actualisation du stock!", e);
-
 
578
            }
-
 
579
        }
-
 
580
    }
-
 
581
 
497
    @Override
582
    @Override
498
    protected String createCode() {
583
    protected String createCode() {
499
        return createCodeFromPackage() + ".ref";
584
        return createCodeOfPackage() + ".ref";
500
    }
585
    }
-
 
586
 
-
 
587
    @Override
-
 
588
    protected void _initComboRequest(ComboSQLRequest req) {
-
 
589
        super._initComboRequest(req);
-
 
590
        req.addToGraphToFetch("ID_DEPOT_STOCK");
-
 
591
        // req.addForeignToGraphToFetch("ID_DEPOT_STOCK", Arrays.asList("ID"));
-
 
592
    }
-
 
593
 
501
}
594
}