OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 12... Line 12...
12
 */
12
 */
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.config.update.Updater_1_5;
17
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18
import org.openconcerto.erp.core.edm.AttachmentAction;
19
import org.openconcerto.erp.core.edm.AttachmentAction;
19
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
20
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.reports.history.ui.HistoriqueArticleFrame;
21
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
22
import org.openconcerto.erp.core.sales.product.action.InventairePanel;
22
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent;
23
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;
24
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
25
import org.openconcerto.erp.core.supplychain.stock.element.StockItem;
-
 
26
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
25
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet;
27
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
26
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
28
import org.openconcerto.erp.preferences.DefaultNXProps;
27
import org.openconcerto.erp.preferences.DefaultNXProps;
29
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
28
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
30
import org.openconcerto.sql.Configuration;
29
import org.openconcerto.sql.Configuration;
Line 51... Line 50...
51
import org.openconcerto.sql.view.list.SQLTableModelSource;
50
import org.openconcerto.sql.view.list.SQLTableModelSource;
52
import org.openconcerto.ui.FrameUtil;
51
import org.openconcerto.ui.FrameUtil;
53
import org.openconcerto.ui.PanelFrame;
52
import org.openconcerto.ui.PanelFrame;
54
import org.openconcerto.utils.CollectionUtils;
53
import org.openconcerto.utils.CollectionUtils;
55
import org.openconcerto.utils.DecimalUtils;
54
import org.openconcerto.utils.DecimalUtils;
56
import org.openconcerto.utils.ExceptionHandler;
-
 
57
import org.openconcerto.utils.ListMap;
55
import org.openconcerto.utils.ListMap;
58
 
56
 
59
import java.awt.event.ActionEvent;
57
import java.awt.event.ActionEvent;
60
import java.math.BigDecimal;
58
import java.math.BigDecimal;
61
import java.sql.SQLException;
59
import java.sql.SQLException;
Line 219... Line 217...
219
        l.add("ID_FAMILLE_ARTICLE");
217
        l.add("ID_FAMILLE_ARTICLE");
220
        l.add("ID_FOURNISSEUR");
218
        l.add("ID_FOURNISSEUR");
221
        l.add("SKU");
219
        l.add("SKU");
222
 
220
 
223
        // if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
221
        // if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) {
-
 
222
        l.add("GESTION_STOCK");
224
        l.add("ID_STOCK");
223
        l.add("ID_STOCK");
225
        // }
224
        // }
226
        String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
225
        String val = DefaultNXProps.getInstance().getStringProperty("ArticleService");
227
        Boolean b = Boolean.valueOf(val);
226
        Boolean b = Boolean.valueOf(val);
228
        if (b != null && b.booleanValue()) {
227
        if (b != null && b.booleanValue()) {
Line 525... Line 524...
525
                && rowVals1.getString("VALEUR_METRIQUE_2").equals(rowVals2.getString("VALEUR_METRIQUE_2")) && rowVals1.getString("VALEUR_METRIQUE_3").equals(rowVals2.getString("VALEUR_METRIQUE_3")));
524
                && rowVals1.getString("VALEUR_METRIQUE_2").equals(rowVals2.getString("VALEUR_METRIQUE_2")) && rowVals1.getString("VALEUR_METRIQUE_3").equals(rowVals2.getString("VALEUR_METRIQUE_3")));
526
    }
525
    }
527
 
526
 
528
    public void initStock(int id) {
527
    public void initStock(int id) {
529
        SQLRow row = getTable().getRow(id);
528
        SQLRow row = getTable().getRow(id);
530
        SQLSelect sel = new SQLSelect();
529
        Updater_1_5.initStock(row);
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
    }
530
    }
581
 
531
 
582
    @Override
532
    @Override
583
    protected String createCode() {
533
    protected String createCode() {
584
        return createCodeOfPackage() + ".ref";
534
        return createCodeOfPackage() + ".ref";