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 174
Line 20... Line 20...
20
import org.openconcerto.erp.core.sales.account.VenteFactureSituationSQLComponent;
20
import org.openconcerto.erp.core.sales.account.VenteFactureSituationSQLComponent;
21
import org.openconcerto.erp.core.sales.account.VenteFactureSoldeSQLComponent;
21
import org.openconcerto.erp.core.sales.account.VenteFactureSoldeSQLComponent;
22
import org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent;
22
import org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent;
23
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
23
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet;
24
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
24
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient;
25
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement;
25
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement;
-
 
26
import org.openconcerto.erp.core.sales.product.model.ProductComponent;
-
 
27
import org.openconcerto.erp.core.sales.product.model.ProductHelper;
26
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
28
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent;
27
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
29
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
28
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
30
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement;
29
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
31
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
30
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
32
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel;
Line 34... Line 36...
34
import org.openconcerto.sql.element.SQLElementLink.LinkType;
36
import org.openconcerto.sql.element.SQLElementLink.LinkType;
35
import org.openconcerto.sql.element.SQLElementLinksSetup;
37
import org.openconcerto.sql.element.SQLElementLinksSetup;
36
import org.openconcerto.sql.element.TreesOfSQLRows;
38
import org.openconcerto.sql.element.TreesOfSQLRows;
37
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
39
import org.openconcerto.sql.model.ConnectionHandlerNoSetup;
38
import org.openconcerto.sql.model.SQLDataSource;
40
import org.openconcerto.sql.model.SQLDataSource;
39
import org.openconcerto.sql.model.SQLField;
-
 
40
import org.openconcerto.sql.model.SQLInjector;
41
import org.openconcerto.sql.model.SQLInjector;
41
import org.openconcerto.sql.model.SQLRow;
42
import org.openconcerto.sql.model.SQLRow;
42
import org.openconcerto.sql.model.SQLRowAccessor;
43
import org.openconcerto.sql.model.SQLRowAccessor;
43
import org.openconcerto.sql.model.SQLRowListRSH;
44
import org.openconcerto.sql.model.SQLRowListRSH;
44
import org.openconcerto.sql.model.SQLRowValues;
45
import org.openconcerto.sql.model.SQLRowValues;
Line 577... Line 578...
577
     * @param commandeID
578
     * @param commandeID
578
     */
579
     */
579
    public void transfertCommande(int commandeID, boolean useCommandeEnCours) {
580
    public void transfertCommande(int commandeID, boolean useCommandeEnCours) {
580
 
581
 
581
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
582
        SQLElement elt = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT");
582
        SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable();
-
 
583
        SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE");
-
 
584
        SQLRow rowCmd = getTable().getRow(commandeID);
583
        SQLRow rowCmd = getTable().getRow(commandeID);
585
        List<SQLRow> rows = rowCmd.getReferentRows(elt.getTable());
584
        List<SQLRow> rows = rowCmd.getReferentRows(elt.getTable());
586
        final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
-
 
587
        for (SQLRow sqlRow : rows) {
585
        transfertEltToCommandeF(rows);
588
            // on récupére l'article qui lui correspond
-
 
589
            SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable());
-
 
590
            for (SQLField field : eltArticle.getTable().getFields()) {
-
 
591
                if (sqlRow.getTable().getFieldsName().contains(field.getName())) {
-
 
592
                    rowArticle.put(field.getName(), sqlRow.getObject(field.getName()));
-
 
593
                }
586
    }
-
 
587
 
-
 
588
    public void transfertEltToCommandeF(List<? extends SQLRowAccessor> rowsItems) {
-
 
589
        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() {
-
 
590
 
-
 
591
            @Override
-
 
592
            public void run() {
-
 
593
                ProductHelper helper = new ProductHelper(getTable().getDBRoot());
-
 
594
                List<ProductComponent> productComp = new ArrayList<>();
-
 
595
                helper.fillProductComponent(rowsItems, productComp, 1, 0, 1);
-
 
596
 
-
 
597
                List<ProductComponent> leafItems = helper.getChildWithQtyFrom(productComp);
-
 
598
 
-
 
599
                final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>();
-
 
600
                final Set<Integer> stockChecked = new HashSet<Integer>();
-
 
601
                for (ProductComponent comp : leafItems) {
-
 
602
                    SQLRowAccessor rowArticleFind = comp.getProduct();
-
 
603
 
-
 
604
                    SQLRow row = rowArticleFind.asRow();
-
 
605
                    SQLRowAccessor rowStock = comp.getStock();
-
 
606
                    int value = 0;
-
 
607
                    if (row.getBoolean("GESTION_STOCK") && !stockChecked.contains(rowStock.getID())) {
-
 
608
                        stockChecked.add(rowStock.getID());
-
 
609
 
-
 
610
                        value = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN"));
-
 
611
                    } else if (!row.getBoolean("GESTION_STOCK")) {
-
 
612
                        value = comp.getQty().intValue();
-
 
613
                    }
-
 
614
                    if (value > 0) {
-
 
615
 
-
 
616
                        SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE_ELEMENT"));
-
 
617
                        SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(row));
-
 
618
 
-
 
619
                        int qte = 1;
-
 
620
                        BigDecimal qteUV = BigDecimal.ONE;
-
 
621
 
-
 
622
                        if (row.getObject("ID_UNITE_VENTE") != null && row.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) {
-
 
623
                            qteUV = comp.getQty();
-
 
624
                        } else {
-
 
625
                            qte = comp.getQty().setScale(0, RoundingMode.HALF_UP).intValue();
594
            }
626
                        }
595
 
627
 
596
            int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true);
-
 
597
            SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle);
-
 
598
            if (rowArticleFind != null && !rowArticleFind.isUndefined()) {
-
 
599
                SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt);
-
 
600
                SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind));
-
 
601
                rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE"));
628
                        rowValsElt.put("QTE", qte);
602
                rowValsElt.put("QTE", sqlRow.getObject("QTE"));
629
                        rowValsElt.put("QTE_UNITAIRE", qteUV);
-
 
630
 
603
                rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
631
                        rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE"));
604
                rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
632
                        rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION));
605
                rowValsElt.put("T_PA_TTC",
-
 
606
                        ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION));
633
                        rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)),
607
                final SQLRow foreignRow = rowArticleFind.getForeignRow("ID_FOURNISSEUR");
-
 
608
                if (foreignRow != null && !foreignRow.isUndefined()) {
634
                                DecimalUtils.HIGH_PRECISION));
609
                    rowValsElt.put("ID_DEVISE", foreignRow.getForeignID("ID_DEVISE"));
635
                        // rowValsElt.put("ID_DEVISE",
610
                } else {
-
 
611
                    rowValsElt.put("ID_DEVISE", rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE"));
636
                        // rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE"));
612
                }
-
 
613
                map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt);
637
                        map.add(rowArticleFind.getForeign("ID_FOURNISSEUR").asRow(), rowValsElt);
614
            }
638
                    }
615
 
639
 
616
        }
640
                }
617
        MouvementStockSQLElement.createCommandeF(map, rowCmd.getForeignRow("ID_TARIF").getForeignRow("ID_DEVISE"), rowCmd.getString("NUMERO") + " - " + rowCmd.getString("NOM"), useCommandeEnCours);
641
                MouvementStockSQLElement.createCommandeF(map, null, "");
-
 
642
            }
-
 
643
        });
618
    }
644
    }
619
 
645
 
620
    /**
646
    /**
621
     * Transfert en BL
647
     * Transfert en BL
622
     * 
648
     *