use of org.compiere.model.MCostDetail in project adempiere by adempiere.
the class Doc_Movement method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MMM.
* <pre>
* Movement
* Inventory DR CR
* InventoryTo DR CR
* </pre>
* @param as account schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
// Line pointers
FactLine dr = null;
FactLine cr = null;
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
BigDecimal costs = Env.ZERO;
for (MCostDetail cost : line.getCostDetail(as, false)) {
if (!MCostDetail.existsCost(cost))
continue;
//get costing method for product
String description = cost.getM_CostElement().getName() + " " + cost.getM_CostType().getName();
costs = MCostDetail.getTotalCost(cost, as);
MTransaction trx = new MTransaction(getCtx(), cost.getM_Transaction_ID(), getTrxName());
if (MTransaction.MOVEMENTTYPE_MovementFrom.equals(trx.getMovementType())) {
// ** Inventory DR CR
dr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), // from (-) CR
costs.negate());
if (dr == null)
continue;
dr.setM_Locator_ID(line.getM_Locator_ID());
dr.addDescription(description);
dr.setM_Product_ID(cost.getM_Product_ID());
// outgoing
dr.setQty(cost.getQty().negate());
if (m_DocStatus.equals(MMovement.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Movement
if (!dr.updateReverseLine(MMovement.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty().negate(), Env.ONE.negate())) {
p_Error = "Original Inventory Move not posted yet";
return null;
}
}
continue;
}
if (MTransaction.MOVEMENTTYPE_MovementTo.equals(trx.getMovementType())) {
// ** InventoryTo DR CR
cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), // to (+) DR
costs);
if (cr == null)
continue;
cr.setM_Locator_ID(line.getM_LocatorTo_ID());
cr.addDescription(description);
cr.setM_Product_ID(cost.getM_Product_ID());
cr.setQty(cost.getQty());
if (m_DocStatus.equals(MMovement.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctCr from Original Movement
if (!cr.updateReverseLine(MMovement.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty(), Env.ONE.negate())) {
p_Error = "Original Inventory Move not posted yet";
return null;
}
//get original cost
costs = cr.getAcctBalance();
}
}
}
}
//
ArrayList<Fact> facts = new ArrayList<Fact>();
facts.add(fact);
return facts;
}
use of org.compiere.model.MCostDetail in project adempiere by adempiere.
the class GenerateCostDetail method generateCostCollectorNotTransaction.
private void generateCostCollectorNotTransaction(MAcctSchema accountSchema, MCostType costType, int productId, String trxName) throws SQLException {
List<MPPCostCollector> costCollectors = MPPCostCollector.getCostCollectorNotTransaction(getCtx(), productId, getAccountDate(), getAccountDateTo(), trxName);
// Process Collector Cost Manufacturing
for (MPPCostCollector costCollector : costCollectors) {
for (MCostDetail costDetail : MCostDetail.getByCollectorCost(costCollector)) {
costDetail.deleteEx(true);
}
CostEngineFactory.getCostEngine(getAD_Client_ID()).clearAccounting(accountSchema, costType, costCollector, productId, costCollector.getDateAcct());
final StandardCostingMethod standardCostingMethod = (StandardCostingMethod) CostingMethodFactory.get().getCostingMethod(X_M_CostType.COSTINGMETHOD_StandardCosting);
if (MPPCostCollector.COSTCOLLECTORTYPE_UsegeVariance.equals(costCollector.getCostCollectorType()))
standardCostingMethod.createUsageVariances(costCollector);
else if (MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance.equals(costCollector.getCostCollectorType()))
standardCostingMethod.createMethodVariances(costCollector);
else if (MPPCostCollector.COSTCOLLECTORTYPE_RateVariance.equals(costCollector.getCostCollectorType()))
standardCostingMethod.createRateVariances(costCollector);
else if (MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl.equals(costCollector.getCostCollectorType()))
standardCostingMethod.createActivityControl(costCollector);
//else
//System.out.println("Cost Collector Type: " + costCollector.getCostCollectorType());
}
}
Aggregations