use of org.compiere.model.ProductCost in project adempiere by adempiere.
the class Doc_Invoice method landedCost.
// createFactCash
/**
* Create Landed Cost accounting & Cost lines
* @param as accounting schema
* @param fact fact
* @param line document line
* @param isDebit DR entry (normal api)
* @return true if landed costs were created
*/
private boolean landedCost(MAcctSchema as, Fact fact, DocLine line, boolean isDebit) {
int invoiceLineId = line.get_ID();
MLandedCostAllocation[] landedCostAllocations = MLandedCostAllocation.getOfInvoiceLine(getCtx(), invoiceLineId, getTrxName());
if (landedCostAllocations.length == 0)
return false;
BigDecimal totalBase = Arrays.stream(landedCostAllocations).map(MLandedCostAllocation::getBase).reduce(BigDecimal.ZERO, BigDecimal::add);
// Create New
MInvoiceLine invoiceLine = new MInvoiceLine(getCtx(), invoiceLineId, getTrxName());
Arrays.stream(landedCostAllocations).filter(// only cost allocation with base > 0
landedCostAllocation -> landedCostAllocation.getBase().signum() != 0).forEach(landedCostAllocation -> {
BigDecimal percent = landedCostAllocation.getBase().divide(totalBase, BigDecimal.ROUND_HALF_UP);
String desc = invoiceLine.getDescription();
if (desc == null)
desc = percent + "%";
else
desc += " - " + percent + "%";
if (line.getDescription() != null)
desc += " - " + line.getDescription();
ProductCost productCost = new ProductCost(Env.getCtx(), landedCostAllocation.getM_Product_ID(), landedCostAllocation.getM_AttributeSetInstance_ID(), getTrxName());
BigDecimal debitAmount = BigDecimal.ZERO;
BigDecimal creditAmount = BigDecimal.ZERO;
;
FactLine factLine = null;
MCostType costType = MCostType.get(as, landedCostAllocation.getM_Product_ID(), landedCostAllocation.getAD_Org_ID());
if (MCostType.COSTINGMETHOD_AverageInvoice.equals(costType.getCostingMethod())) {
BigDecimal assetAmount = Optional.ofNullable(MCostDetail.getByDocLineLandedCost(landedCostAllocation, as.getC_AcctSchema_ID(), costType.get_ID())).orElse(BigDecimal.ZERO);
BigDecimal costAdjustment = landedCostAllocation.getAmt().subtract(assetAmount);
if (assetAmount.signum() != 0) {
if (isDebit)
debitAmount = assetAmount;
else
creditAmount = assetAmount;
factLine = fact.createLine(line, productCost.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), debitAmount, creditAmount);
factLine.setDescription(desc + " " + landedCostAllocation.getM_CostElement().getName());
factLine.setM_Product_ID(landedCostAllocation.getM_Product_ID());
}
if (costAdjustment.signum() != 0) {
if (isDebit)
debitAmount = costAdjustment;
else
creditAmount = costAdjustment;
factLine = fact.createLine(line, productCost.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), getC_Currency_ID(), debitAmount, creditAmount);
}
} else {
factLine = fact.createLine(line, productCost.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), getC_Currency_ID(), debitAmount, creditAmount);
}
factLine.setDescription(desc + " " + landedCostAllocation.getM_CostElement().getName());
factLine.setM_Product_ID(landedCostAllocation.getM_Product_ID());
});
log.config("Created #" + landedCostAllocations.length);
return true;
}
use of org.compiere.model.ProductCost in project adempiere by adempiere.
the class Doc_MatchInv method loadDocumentDetails.
/** Commitments */
// private DocLine[] m_commitments = null;
/**
* Load Specific Document Details
* @return error message or null
*/
protected String loadDocumentDetails() {
setC_Currency_ID(Doc.NO_CURRENCY);
MMatchInv matchInv = (MMatchInv) getPO();
setDateDoc(matchInv.getDateTrx());
setQty(matchInv.getQty());
// Invoice Info
int C_InvoiceLine_ID = matchInv.getC_InvoiceLine_ID();
m_invoiceLine = new MInvoiceLine(getCtx(), C_InvoiceLine_ID, getTrxName());
// BP for NotInvoicedReceipts
int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID();
setC_BPartner_ID(C_BPartner_ID);
//
int M_InOutLine_ID = matchInv.getM_InOutLine_ID();
m_receiptLine = new MInOutLine(getCtx(), M_InOutLine_ID, getTrxName());
//
m_pc = new ProductCost(Env.getCtx(), getM_Product_ID(), matchInv.getM_AttributeSetInstance_ID(), getTrxName());
m_pc.setQty(getQty());
return null;
}
use of org.compiere.model.ProductCost in project adempiere by adempiere.
the class FifoLifoCostingMethod method calculate.
public void calculate() {
ProductCost pc = new ProductCost(model.getCtx(), model.getM_Product_ID(), model.getM_AttributeSetInstance_ID(), model.get_TrxName());
pc.setQty(transaction.getMovementQty());
//
List<CostComponent> ccs = pc.getProductCostsLayers(dimension, 0, false);
if (ccs == null || ccs.size() == 0) {
MProduct product = MProduct.get(Env.getCtx(), model.getM_Product_ID());
throw new AdempiereException("No Costs for " + product.getName());
}
m_calculatedCosts = ccs;
}
use of org.compiere.model.ProductCost in project adempiere by adempiere.
the class Doc_MatchPO method loadDocumentDetails.
/**
* Load Specific Document Details
* @return error message or null
*/
protected String loadDocumentDetails() {
setC_Currency_ID(Doc.NO_CURRENCY);
MMatchPO matchPO = (MMatchPO) getPO();
setDateDoc(matchPO.getDateTrx());
//
m_M_AttributeSetInstance_ID = matchPO.getM_AttributeSetInstance_ID();
setQty(matchPO.getQty());
//
m_C_OrderLine_ID = matchPO.getC_OrderLine_ID();
m_oLine = new MOrderLine(getCtx(), m_C_OrderLine_ID, getTrxName());
//
m_M_InOutLine_ID = matchPO.getM_InOutLine_ID();
m_ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID();
//
m_pc = new ProductCost(Env.getCtx(), getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName());
m_pc.setQty(getQty());
return null;
}
use of org.compiere.model.ProductCost in project adempiere by adempiere.
the class MAssetAcct method getP_Asset_Acct.
public MAccount getP_Asset_Acct(int M_Product_ID) {
MAcctSchema as = getC_AcctSchema();
ProductCost pc = new ProductCost(getCtx(), M_Product_ID, 0, null);
return pc.getAccount(ProductCost.ACCTTYPE_P_Asset, as);
}
Aggregations