Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/model/ProductHelper.java |
---|
24,6 → 24,7 |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.utils.DecimalUtils; |
import org.openconcerto.utils.ListMap; |
import org.openconcerto.utils.cc.ITransformer; |
import java.math.BigDecimal; |
211,11 → 212,12 |
return getChildWithQtyFrom(items, new HashSet<Integer>()); |
} |
private List<ProductComponent> getChildWithQtyFrom(List<ProductComponent> items, Set<Integer> ancestors) { |
private List<ProductComponent> getChildWithQtyFrom(List<ProductComponent> items, Set<Integer> ancestorsOrigin) { |
if (root.contains("ARTICLE_ELEMENT")) { |
int originalAncestorsSize = ancestors.size(); |
int originalAncestorsSize = ancestorsOrigin.size(); |
Set<Integer> ancestors = new HashSet<Integer>(ancestorsOrigin); |
List<ProductComponent> result = new ArrayList<ProductComponent>(); |
222,17 → 224,22 |
// liste des ids parents |
final List<Integer> parentsArticleIDs = new ArrayList<Integer>(); |
// ID Article -- component |
ListMap<Integer, ProductComponent> productCompByID = new ListMap<Integer, ProductComponent>(); |
// Quantité par parents |
Map<Integer, ProductComponent> productCompByID = new HashMap<Integer, ProductComponent>(); |
final Map<Integer, BigDecimal> qtyParent = new HashMap<Integer, BigDecimal>(); |
// final ListMap<Integer, BigDecimal> qtyParentIDSource = new HashMap<Integer, |
// BigDecimal>(); |
for (ProductComponent p : items) { |
parentsArticleIDs.add(p.getProduct().getID()); |
BigDecimal qty = BigDecimal.ZERO; |
if (qtyParent.get(p.getProduct().getID()) != null) { |
qty = qtyParent.get(p.getProduct().getID()); |
productCompByID.add(p.getProduct().getID(), p); |
int idSource = p.getProduct().getID(); |
parentsArticleIDs.add(idSource); |
// BigDecimal qty = BigDecimal.ZERO; |
// if (qtyParent.get(idSource) != null) { |
// qty = qtyParent.get(idSource); |
// } |
// qtyParent.put(idSource, qty.add(p.getQty())); |
} |
qtyParent.put(p.getProduct().getID(), qty.add(p.getQty())); |
} |
// get all childs |
final SQLTable costTable = root.getTable("ARTICLE_ELEMENT"); |
239,8 → 246,10 |
SQLRowValues rowVals = new SQLRowValues(costTable); |
final SQLRowValues stockRowValues = rowVals.putRowValues("ID_ARTICLE").put("ID", null).put("GESTION_STOCK", null).put("CODE", null).put("NOM", null).putRowValues("ID_STOCK"); |
stockRowValues.putNulls("QTE_TH", "QTE_RECEPT_ATTENTE", "QTE_REEL", "QTE_LIV_ATTENTE"); |
final SQLRowValues artRowValues = rowVals.putRowValues("ID_ARTICLE").putNulls("ID", "GESTION_STOCK", "CODE", "NOM", "ID_DEPOT_STOCK", "ID_UNITE_VENTE"); |
SQLRowValues stockRowVals = new SQLRowValues(root.getTable("STOCK")); |
stockRowVals.putNulls("QTE_TH", "QTE_RECEPT_ATTENTE", "QTE_REEL", "QTE_LIV_ATTENTE", "ID_DEPOT_STOCK"); |
stockRowVals.put("ID_ARTICLE", artRowValues); |
rowVals.putRowValues("ID_ARTICLE_PARENT").put("ID", null); |
rowVals.put("QTE", null); |
rowVals.put("QTE_UNITAIRE", null); |
263,22 → 272,33 |
for (SQLRowValues childRowValues : childs) { |
final SQLRowAccessor foreignArticleParent = childRowValues.getForeign("ID_ARTICLE_PARENT"); |
if (!childRowValues.isForeignEmpty("ID_ARTICLE") && childRowValues.getForeign("ID_ARTICLE") != null) { |
ProductComponent childComponent = ProductComponent.createFrom(childRowValues); |
if (childRowValues.getObject("ID_ARTICLE") != null && !childRowValues.isForeignEmpty("ID_ARTICLE")) { |
List<ProductComponent> source = productCompByID.get(foreignArticleParent.getID()); |
// Test pour éviter les boucles dans les boms |
if (!ancestors.contains(childComponent.getProduct().getID())) { |
if (!ancestorsOrigin.contains(foreignArticleParent.getID())) { |
ancestors.add(foreignArticleParent.getID()); |
for (ProductComponent productParent : source) { |
final SQLRowAccessor foreignArticle = childRowValues.getForeign("ID_ARTICLE"); |
ProductComponent childComponent = ProductComponent.createFromRowArticle(foreignArticle, productParent.getSource()); |
// parentsArticleIDs.remove(foreignArticleParent.getID()); |
// Calcul de la quantité qte_unit * qte * qteMergedParent |
childComponent.setQty(childComponent.getQty().multiply(qtyParent.get(foreignArticleParent.getID()), DecimalUtils.HIGH_PRECISION)); |
childComponent.setQty(childComponent.getQty().multiply(productParent.getQty(), DecimalUtils.HIGH_PRECISION)); |
// Cumul des valeurs si l'article est présent plusieurs fois dans le bom |
ProductComponent existProduct = productCompByID.get(childComponent.getProduct().getID()); |
if (existProduct == null) { |
// Cumul des valeurs si l'article est présent plusieurs fois dans le |
// bom |
// ProductComponent existProduct = |
// productCompByID.get(childComponent.getProduct().getID()); |
// if (existProduct == null) { |
// Maintenant on garde une ligne disctincte pour chaque kit |
result.add(childComponent); |
productCompByID.put(childComponent.getProduct().getID(), childComponent); |
} else { |
existProduct.addQty(childComponent.getQty()); |
// productCompByID.put(childComponent.getProduct().getID(), |
// childComponent); |
// } else { |
// existProduct.addQty(childComponent.getQty()); |
// } |
} |
} |
} |
289,34 → 309,34 |
// Merge des valeurs |
for (ProductComponent s : bomFromChilds) { |
ProductComponent existProduct = productCompByID.get(s.getProduct().getID()); |
if (existProduct == null) { |
// ProductComponent existProduct = productCompByID.get(s.getProduct().getID()); |
// if (existProduct == null) { |
result.add(s); |
productCompByID.put(s.getProduct().getID(), s); |
} else { |
existProduct.addQty(s.getQty()); |
// productCompByID.put(s.getProduct().getID(), s); |
// } else { |
// existProduct.addQty(s.getQty()); |
// } |
} |
} |
} |
// Ajout des articles présents dans l'ensemble de départ |
if (originalAncestorsSize == 0) { |
for (ProductComponent p : items) { |
ProductComponent existProduct = productCompByID.get(p.getProduct().getID()); |
if (existProduct == null) { |
// ProductComponent existProduct = productCompByID.get(p.getProduct().getID()); |
// if (existProduct == null) { |
result.add(p); |
productCompByID.put(p.getProduct().getID(), p); |
} else { |
existProduct.addQty(p.getQty()); |
// productCompByID.put(p.getProduct().getID(), p); |
// } else { |
// existProduct.addQty(p.getQty()); |
// } |
} |
} |
} |
// On supprime les ancestors (kits) du result |
for (Integer anc : ancestors) { |
ProductComponent comp = productCompByID.get(anc); |
if (comp != null) { |
result.remove(comp); |
// ProductComponent comp = productCompByID.get(anc); |
if (productCompByID.containsKey(anc)) { |
result.removeAll(productCompByID.get(anc)); |
} |
} |