OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 177
Line 23... Line 23...
23
import org.openconcerto.sql.model.SQLSelect;
23
import org.openconcerto.sql.model.SQLSelect;
24
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
25
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.Where;
26
import org.openconcerto.utils.DecimalUtils;
26
import org.openconcerto.utils.DecimalUtils;
27
import org.openconcerto.utils.ListMap;
27
import org.openconcerto.utils.ListMap;
-
 
28
import org.openconcerto.utils.Tuple2;
28
import org.openconcerto.utils.cc.ITransformer;
29
import org.openconcerto.utils.cc.ITransformer;
29
 
30
 
30
import java.math.BigDecimal;
31
import java.math.BigDecimal;
31
import java.math.RoundingMode;
32
import java.math.RoundingMode;
32
import java.util.ArrayList;
33
import java.util.ArrayList;
Line 450... Line 451...
450
        }
451
        }
451
        return cost;
452
        return cost;
452
 
453
 
453
    }
454
    }
454
 
455
 
-
 
456
    public Tuple2<BigDecimal, BigDecimal> getStandardBomPrices(Collection<? extends SQLRowAccessor> rowValuesProductItems) {
-
 
457
        final Map<Long, Integer> productQties = new HashMap<Long, Integer>();
-
 
458
        for (SQLRowAccessor v : rowValuesProductItems) {
-
 
459
            if (v.getObject("ID_ARTICLE") != null) {
-
 
460
                System.out.println("id:" + v.getObject("ID_ARTICLE"));
-
 
461
                int id = v.getForeignID("ID_ARTICLE");
-
 
462
                int qte = v.getInt("QTE");
-
 
463
                Integer qteForId = productQties.get(Long.valueOf(id));
-
 
464
                if (qteForId == null) {
-
 
465
                    productQties.put(Long.valueOf(id), qte);
-
 
466
                } else {
-
 
467
                    productQties.put(Long.valueOf(id), qte + qteForId);
-
 
468
                }
-
 
469
            }
-
 
470
        }
-
 
471
        BigDecimal costPV = null;
-
 
472
        BigDecimal costPA = null;
-
 
473
 
-
 
474
        for (SQLRowAccessor v : rowValuesProductItems) {
-
 
475
            if (v.getObject("ID_ARTICLE") != null) {
-
 
476
                SQLRowAccessor rowChild = v.getForeign("ID_ARTICLE");
-
 
477
                int qte = v.getInt("QTE");
-
 
478
                BigDecimal unitCostPV = rowChild.getBigDecimal("PV_HT");
-
 
479
                BigDecimal unitCostPA = rowChild.getBigDecimal("PA_HT");
-
 
480
                BigDecimal lineCostPV = unitCostPV.multiply(BigDecimal.valueOf(qte)).multiply(v.getBigDecimal("QTE_UNITAIRE"));
-
 
481
                if (costPV == null) {
-
 
482
                    costPV = BigDecimal.ZERO;
-
 
483
                }
-
 
484
                costPV = costPV.add(lineCostPV);
-
 
485
                BigDecimal lineCostPA = unitCostPA.multiply(BigDecimal.valueOf(qte)).multiply(v.getBigDecimal("QTE_UNITAIRE"));
-
 
486
                if (costPA == null) {
-
 
487
                    costPA = BigDecimal.ZERO;
-
 
488
                }
-
 
489
                costPA = costPA.add(lineCostPA);
-
 
490
            }
-
 
491
        }
-
 
492
        return Tuple2.create(costPA, costPV);
-
 
493
 
-
 
494
    }
-
 
495
 
455
    public BigDecimal getUnitCost(int id, int qty, TypePrice type) {
496
    public BigDecimal getUnitCost(int id, int qty, TypePrice type) {
456
        Map<Long, Integer> productQties = new HashMap<Long, Integer>();
497
        Map<Long, Integer> productQties = new HashMap<Long, Integer>();
457
        productQties.put(Long.valueOf(id), Integer.valueOf(qty));
498
        productQties.put(Long.valueOf(id), Integer.valueOf(qty));
458
        final Map<Long, BigDecimal> unitCost = getUnitCost(productQties, type);
499
        final Map<Long, BigDecimal> unitCost = getUnitCost(productQties, type);
459
        System.out.println(">" + unitCost);
500
        System.out.println(">" + unitCost);