Search in sources :

Example 21 with MCostDetail

use of org.compiere.model.MCostDetail in project adempiere by adempiere.

the class MCostDetailTest method testQuery.

public void testQuery() throws Exception {
    MCostDetail cd = MCostDetail.get(getCtx(), "C_InvoiceLine_ID=?", 1000003, 1000001, 1000001, getTrxName());
    assertTrue("Such Cost Detail record exists", cd.get_ID() > 0);
    MProduct prod = new MProduct(getCtx(), 1000002, getTrxName());
//assertTrue("must have true result", MCostDetail.processProduct(prod, getTrxName())); //red1 test mock falce recs in MCostDetail
}
Also used : MProduct(org.compiere.model.MProduct) MCostDetail(org.compiere.model.MCostDetail)

Example 22 with MCostDetail

use of org.compiere.model.MCostDetail in project adempiere by adempiere.

the class Doc_PPCostCollector method createComponentIssue.

/**
	 * The Issue Component product created next account fact
	 * Debit Work in Process Account for each Cost Element using current cost
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing	
	 * Credit Product Asset Account for each Cost Element using current cost
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing		
	 * Credit Floor Stock Account for each Cost Element using current cost
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing		
	 */
protected Fact createComponentIssue(MAcctSchema acctSchema) {
    final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
    BigDecimal totalCost = Env.ZERO;
    FactLine debitLine = null;
    FactLine creditLine = null;
    MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
    MAccount inventoryAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Asset, acctSchema);
    if (costCollector.isFloorStock())
        inventoryAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_FloorStock, acctSchema);
    for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, false)) {
        BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
        if (absoluteCost.signum() == 0)
            continue;
        BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
        if (cost.compareTo(Env.ZERO) == 0)
            continue;
        if (cost.scale() > acctSchema.getStdPrecision())
            cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
        debitLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), cost.negate());
        I_M_CostElement costElement = costDetail.getM_CostElement();
        String description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName();
        debitLine.setDescription(description);
        totalCost = totalCost.add(cost);
    }
    String description = manufacturingOrder.getDocumentNo();
    creditLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalCost);
    creditLine.setDescription(description);
    return fact;
}
Also used : MAccount(org.compiere.model.MAccount) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal) I_M_CostElement(org.compiere.model.I_M_CostElement)

Example 23 with MCostDetail

use of org.compiere.model.MCostDetail in project adempiere by adempiere.

the class Doc_PPCostCollector method createMaterialReceipt.

/**
	 * The Receipt Finish good product created the next account fact
	 * Debit Product Asset Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing
	 * Debit Scrap Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing			
	 * Credit Work in Process Account for each Cost Element using Current Cost 
	 * Create a fact line for each cost element type
	 * 		Material
	 * 		Labor(Resources)
	 * 		Burden
	 * 		Overhead 
	 * 		Outsite Processing		
	 */
protected Fact createMaterialReceipt(MAcctSchema acctSchema) {
    final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
    FactLine debitLine = null;
    FactLine creditLine = null;
    final MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
    final MAccount burdenAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Burden, acctSchema);
    MAccount inventoryAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Asset, acctSchema);
    BigDecimal totalcosts = BigDecimal.ZERO;
    BigDecimal totalcostsScrapped = BigDecimal.ZERO;
    for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, true)) {
        MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
        String description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName();
        if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(costElement.getCostElementType())) {
            BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            if (cost.compareTo(Env.ZERO) == 0)
                continue;
            creditLine = fact.createLine(docLineCostCollector, burdenAccount, acctSchema.getC_Currency_ID(), null, cost);
            creditLine.setQty(costCollector.getMovementQty());
            creditLine.setDescription(description);
            totalcosts = totalcosts.add(cost);
            continue;
        }
        if (costCollector.getMovementQty().signum() != 0) {
            BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            if (cost.compareTo(Env.ZERO) == 0)
                continue;
            creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), cost.negate());
            creditLine.setQty(costCollector.getMovementQty());
            creditLine.setDescription(description);
            totalcosts = totalcosts.add(cost);
        }
        if (costCollector.getScrappedQty().signum() != 0) {
            BigDecimal absoluteCost = costDetail.getPrice().multiply(costCollector.getScrappedQty()).add(costDetail.getTotalCost(costDetail, acctSchema));
            if (absoluteCost.signum() == 0)
                continue;
            BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
            if (cost.scale() > acctSchema.getStdPrecision())
                cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
            creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), null, cost.negate());
            creditLine.setQty(costCollector.getMovementQty());
            description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName() + " - " + Msg.parseTranslation(getCtx(), "@Scrap@");
            ;
            creditLine.setDescription(description);
            totalcostsScrapped = totalcostsScrapped.add(cost);
        }
    }
    String description = manufacturingOrder.getDocumentNo();
    // Debit Amount based on sign of total costs
    debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcosts);
    debitLine.setQty(costCollector.getMovementQty());
    debitLine.setDescription(description);
    if (totalcostsScrapped.compareTo(Env.ZERO) != 0) {
        debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcostsScrapped);
        debitLine.setQty(costCollector.getScrappedQty());
        description = Msg.parseTranslation(getCtx(), "@Scrap@");
        debitLine.setDescription(description);
    }
    return fact;
}
Also used : MCostElement(org.compiere.model.MCostElement) MAccount(org.compiere.model.MAccount) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Example 24 with MCostDetail

use of org.compiere.model.MCostDetail in project adempiere by adempiere.

the class Doc_PPCostCollector method createVariance.

protected Fact createVariance(MAcctSchema acctSchema, int varianceAcctType) {
    final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
    final MProduct product = costCollector.getM_Product();
    MAccount varianceAccount = docLineCostCollector.getAccount(varianceAcctType, acctSchema);
    MAccount workInProcess = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
    for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, false)) {
        MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
        BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
        if (absoluteCost.signum() == 0)
            continue;
        BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
        if (cost == null)
            cost = BigDecimal.ZERO;
        if (cost.scale() > acctSchema.getStdPrecision())
            cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
        BigDecimal qty = costDetail.getQty();
        createLines(costElement, acctSchema, fact, product, varianceAccount, workInProcess, cost, qty);
    }
    return fact;
}
Also used : MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MAccount(org.compiere.model.MAccount) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Example 25 with MCostDetail

use of org.compiere.model.MCostDetail in project adempiere by adempiere.

the class Doc_ProjectIssue method createFacts.

//  getBalance
/**
	 *  Create Facts (the accounting logic) for
	 *  PJI
	 *  <pre>
	 *  Issue
	 *      ProjectWIP      DR
	 *      Inventory               CR
	 *  </pre>
	 *  Project Account is either Asset or WIP depending on Project Type
	 *  @param as accounting 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());
    MProject project = new MProject(getCtx(), m_issue.getC_Project_ID(), getTrxName());
    String ProjectCategory = project.getProjectCategory();
    MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID());
    //  Line pointers
    FactLine dr = null;
    FactLine cr = null;
    //  Issue Cost
    BigDecimal costs = null;
    BigDecimal total = Env.ZERO;
    if (m_issue.getM_InOutLine_ID() != 0)
        costs = getPOCost(as);
    else if (m_issue.getS_TimeExpenseLine_ID() != 0)
        costs = getLaborCost(as);
    if (//	standard Product Costs
    costs == null) {
        for (MCostDetail cost : m_line.getCostDetail(as, false)) {
            if (!MCostDetail.existsCost(cost))
                continue;
            costs = MCostDetail.getTotalCost(cost, as);
            total = total.add(costs);
        }
    }
    if (total == null || total.signum() == 0) {
        p_Error = "Resubmit - No Costs for " + product.getName();
        log.log(Level.WARNING, p_Error);
        return null;
    }
    //  Project         DR
    int acctType = ACCTTYPE_ProjectWIP;
    if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory))
        acctType = ACCTTYPE_ProjectAsset;
    dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), costs, null);
    dr.setQty(m_line.getQty().negate());
    //  Inventory               CR
    acctType = ProductCost.ACCTTYPE_P_Asset;
    if (product.isService())
        acctType = ProductCost.ACCTTYPE_P_Expense;
    cr = fact.createLine(m_line, m_line.getAccount(acctType, as), as.getC_Currency_ID(), null, costs);
    cr.setM_Locator_ID(m_line.getM_Locator_ID());
    // from Loc
    cr.setLocationFromLocator(m_line.getM_Locator_ID(), true);
    //
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal) MProject(org.compiere.model.MProject)

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