Search in sources :

Example 26 with MCostDetail

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;
}
Also used : MTransaction(org.compiere.model.MTransaction) ArrayList(java.util.ArrayList) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Example 27 with MCostDetail

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());
    }
}
Also used : MPPCostCollector(org.eevolution.model.MPPCostCollector) MCostDetail(org.compiere.model.MCostDetail) StandardCostingMethod(org.adempiere.engine.StandardCostingMethod)

Aggregations

MCostDetail (org.compiere.model.MCostDetail)27 BigDecimal (java.math.BigDecimal)15 ArrayList (java.util.ArrayList)9 MProduct (org.compiere.model.MProduct)9 MAccount (org.compiere.model.MAccount)8 MCostElement (org.compiere.model.MCostElement)5 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)4 MTransaction (org.compiere.model.MTransaction)4 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MCostQueue (org.compiere.model.MCostQueue)3 MMatchInv (org.compiere.model.MMatchInv)3 MMatchPO (org.compiere.model.MMatchPO)3 Timestamp (java.sql.Timestamp)2 MCostType (org.compiere.model.MCostType)2 Date (java.sql.Date)1 StandardCostingMethod (org.adempiere.engine.StandardCostingMethod)1 I_C_OrderLine (org.compiere.model.I_C_OrderLine)1 I_M_CostElement (org.compiere.model.I_M_CostElement)1 I_M_InOutLine (org.compiere.model.I_M_InOutLine)1 MAcctSchema (org.compiere.model.MAcctSchema)1