Search in sources :

Example 11 with MCostType

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

the class Doc_MatchPO method createFacts.

//  getBalance
/**
	 *  Create Facts (the accounting logic) for
	 *  MXP.
	 *  <pre>
	 *      Product PPV     <difference>
	 *      PPV_Offset                  <difference>
	 *  </pre>
	 *  @param as accounting schema
	 *  @return Fact
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    ArrayList<Fact> facts = new ArrayList<Fact>();
    //
    if (//  Nothing to do if no Product
    getM_Product_ID() == 0 || getQty().signum() == 0 || //  No posting if not matched to Shipment
    m_M_InOutLine_ID == 0) {
        log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty());
        return facts;
    }
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());
    boolean isInterOrg = isInterOrg(as);
    //	Purchase Order Line
    BigDecimal poCost = m_oLine.getPriceCost();
    if (poCost == null || poCost.signum() == 0)
        poCost = m_oLine.getPriceActual();
    MInOutLine receiptLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
    MInOut inOut = receiptLine.getParent();
    boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
    // calculate po cost
    //	Delivered so far
    poCost = poCost.multiply(getQty());
    //	Different currency
    if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) {
        MOrder order = m_oLine.getParent();
        Timestamp dateAcct = order.getDateAcct();
        BigDecimal rate = MConversionRate.getRate(order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), m_oLine.getAD_Client_ID(), m_oLine.getAD_Org_ID());
        if (rate == null) {
            p_Error = "Purchase Order not convertible - " + as.getName();
            return null;
        }
        poCost = poCost.multiply(rate);
        if (poCost.scale() > as.getCostingPrecision())
            poCost = poCost.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
    }
    //	Calculate PPV for standard costing
    //get standard cost and also make sure cost for other costing method is updated
    MProduct product = MProduct.get(getCtx(), getM_Product_ID());
    MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
    String costingMethod = ct.getCostingMethod();
    MInOutLine ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
    BigDecimal costs = Env.ZERO;
    for (MTransaction transaction : MTransaction.getByInOutLine(ioLine)) {
        MCostElement element = MCostElement.getByMaterialCostElementType(transaction);
        MCostDetail cd = MCostDetail.getByTransaction(ioLine, transaction, as.getC_AcctSchema_ID(), ct.getM_CostType_ID(), element.getM_CostElement_ID());
        if (cd != null)
            costs = costs.add(MCostDetail.getTotalCost(cd, as));
    }
    if (MCostType.COSTINGMETHOD_StandardCosting.equals(costingMethod)) {
        //	No Costs yet - no PPV
        if (costs == null || costs.signum() == 0) {
            // TODO make these a translatable message
            p_Error = "No Standard Cost information was found for " + product.getName() + ".  Please add a standard cost for material and repost this document.";
            log.log(Level.SEVERE, p_Error);
            return null;
        }
        //	Difference
        BigDecimal difference = poCost.subtract(costs.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP));
        //	Nothing to post
        if (difference.signum() == 0) {
            log.log(Level.FINE, "No Cost Difference for M_Product_ID=" + getM_Product_ID());
            return facts;
        }
        //  Product PPV
        FactLine cr = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
        if (cr != null) {
            cr.setQty(isReturnTrx ? getQty().negate() : getQty());
            cr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
            cr.setC_Activity_ID(m_oLine.getC_Activity_ID());
            cr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
            cr.setC_Project_ID(m_oLine.getC_Project_ID());
            cr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
            cr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
            cr.setC_UOM_ID(m_oLine.getC_UOM_ID());
            cr.setUser1_ID(m_oLine.getUser1_ID());
            cr.setUser2_ID(m_oLine.getUser2_ID());
            cr.setUser3_ID(m_oLine.getUser3_ID());
            cr.setUser4_ID(m_oLine.getUser4_ID());
        }
        //  PPV Offset
        FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
        if (dr != null) {
            dr.setQty(isReturnTrx ? getQty() : getQty().negate());
            dr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
            dr.setC_Activity_ID(m_oLine.getC_Activity_ID());
            dr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
            dr.setC_Project_ID(m_oLine.getC_Project_ID());
            dr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
            dr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
            dr.setC_UOM_ID(m_oLine.getC_UOM_ID());
            dr.setUser1_ID(m_oLine.getUser1_ID());
            dr.setUser2_ID(m_oLine.getUser2_ID());
            dr.setUser3_ID(m_oLine.getUser3_ID());
            dr.setUser4_ID(m_oLine.getUser4_ID());
        }
        // Avoid usage of clearing accounts
        // If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
        // then remove the posting
        // PPV
        MAccount acct_db = dr.getAccount();
        // PPV Offset
        MAccount acct_cr = cr.getAccount();
        if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
            BigDecimal debit = dr.getAmtSourceDr();
            BigDecimal credit = cr.getAmtSourceCr();
            if (debit.compareTo(credit) == 0) {
                fact.remove(dr);
                fact.remove(cr);
            }
        }
        // End Avoid usage of clearing accounts
        //
        facts.add(fact);
        return facts;
    } else {
        return facts;
    }
}
Also used : MInOut(org.compiere.model.MInOut) MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) MTransaction(org.compiere.model.MTransaction) MCostType(org.compiere.model.MCostType) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) MCostDetail(org.compiere.model.MCostDetail)

Example 12 with MCostType

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

the class GenerateCostDetail method generateCostDetail.

public void generateCostDetail() {
    //Generate Costdetail
    KeyNamePair[] transactions = getTransactionIdsByDateAcct();
    // System.out.println("Transaction to process : " + transactions.length);
    Integer process = 0;
    Integer productId = 0;
    boolean processNewProduct = true;
    Trx dbTransaction = null;
    try {
        //Process transaction
        for (KeyNamePair keyNamePair : transactions) {
            int transactionId = keyNamePair.getKey();
            int transactionProductId = new Integer(keyNamePair.getName());
            //Detected a new product
            if (productId != transactionProductId) {
                //commit last transaction by product
                if (dbTransaction != null) {
                    dbTransaction.commit(true);
                    dbTransaction.close();
                }
                productId = transactionProductId;
                processNewProduct = true;
                //Create new transaction for this product
                dbTransaction = Trx.get(productId.toString(), true);
            }
            MTransaction transaction = new MTransaction(getCtx(), transactionId, dbTransaction.getTrxName());
            // for each Account Schema
            for (MAcctSchema accountSchema : acctSchemas) {
                // for each Cost Type
                for (MCostType costType : costTypes) {
                    // for each Cost Element
                    for (MCostElement costElement : costElements) {
                        if (processNewProduct) {
                            applyCriteria(accountSchema.getC_AcctSchema_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), productId, getAccountDate(), getAccountDateTo());
                            deleteCostDetail(dbTransaction.getTrxName());
                            resetCostDimension(costType.getCostingMethod(), dbTransaction.getTrxName());
                            generateCostCollectorNotTransaction(accountSchema, costType, productId, dbTransaction.getTrxName());
                            processNewProduct = false;
                        }
                        generateCostDetail(accountSchema, costType, costElement, transaction);
                    }
                }
            }
            process++;
        //System.out.println("Transaction : " + transactionId + " Transaction Type :"+ transaction.getMovementType() + " record ..." + process);
        }
        if (dbTransaction != null) {
            dbTransaction.commit(true);
            dbTransaction.close();
            dbTransaction = null;
        }
    } catch (Exception e) {
        if (dbTransaction != null) {
            dbTransaction.rollback();
            dbTransaction.close();
            dbTransaction = null;
            e.printStackTrace();
            addLog(e.getMessage());
        }
    } finally {
        if (dbTransaction != null) {
            dbTransaction.commit();
            dbTransaction.close();
            dbTransaction = null;
        }
    }
}
Also used : MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MTransaction(org.compiere.model.MTransaction) KeyNamePair(org.compiere.util.KeyNamePair) Trx(org.compiere.util.Trx) MCostType(org.compiere.model.MCostType) SQLException(java.sql.SQLException)

Example 13 with MCostType

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

the class Doc_MatchInv method createFacts.

//  getBalance
/**
	 *  Create Facts (the accounting logic) for
	 *  MXI.
	 * 	(single line)
	 *  <pre>
	 *      NotInvoicedReceipts     DR			(Receipt Org)
	 *      InventoryClearing               CR
	 *      InvoicePV               DR      CR  (difference)
	 *  Commitment
	 * 		Expense							CR
	 * 		Offset					DR
	 *  </pre>
	 *  @param as accounting schema
	 *  @return Fact
	 */
public ArrayList<Fact> createFacts(MAcctSchema as) {
    ArrayList<Fact> facts = new ArrayList<Fact>();
    //  Nothing to do
    if (//	no Product
    getM_Product_ID() == 0 || getQty().signum() == 0 || //	Qty = 0
    m_receiptLine.getMovementQty().signum() == 0) {
        log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
        return facts;
    }
    MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());
    boolean isInterOrg = isInterOrg(as);
    /**	Needs to be handeled in PO Matching as no Receipt info
		if (m_pc.isService())
		{
			log.fine("Service - skipped");
			return fact;
		}
		**/
    if (!m_receiptLine.getM_Product().isStocked())
        return facts;
    //  NotInvoicedReceipt      DR
    //  From Receipt
    BigDecimal multiplier = getQty().divide(m_receiptLine.getMovementQty(), 12, BigDecimal.ROUND_HALF_UP).abs();
    FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), as.getC_Currency_ID(), Env.ONE, // updated below
    null);
    if (dr == null) {
        p_Error = "No Product Costs";
        return null;
    }
    dr.setM_Product_ID(m_receiptLine.getM_Product_ID());
    String documentBaseTypeReceipt = DB.getSQLValueString(m_receiptLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_receiptLine.getParent().getC_DocType_ID());
    BigDecimal quantityReceipt = MDocType.DOCBASETYPE_MaterialReceipt.equals(documentBaseTypeReceipt) ? getQty() : getQty().negate();
    dr.setQty(quantityReceipt);
    BigDecimal temp = dr.getAcctBalance();
    //	Set AmtAcctCr/Dr from Receipt (sets also Project)
    if (!//	Amt updated
    dr.updateReverseLine(//	Amt updated
    MInOut.Table_ID, m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(), quantityReceipt, multiplier)) {
        p_Error = "Mat.Receipt not posted yet";
        return null;
    }
    log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() + ") - " + dr.toString());
    //  InventoryClearing               CR
    //  From Invoice
    MAccount expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_InventoryClearing, as);
    if (m_pc.isService())
        expense = m_pc.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
    BigDecimal LineNetAmt = m_invoiceLine.getLineNetAmt();
    multiplier = getQty().divide(m_invoiceLine.getQtyInvoiced(), 12, BigDecimal.ROUND_HALF_UP).abs();
    if (multiplier.compareTo(Env.ONE) != 0)
        LineNetAmt = LineNetAmt.multiply(multiplier);
    if (m_pc.isService())
        //	book out exact receipt amt
        LineNetAmt = dr.getAcctBalance();
    FactLine cr = null;
    if (as.isAccrual()) {
        cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, //	updated below
        LineNetAmt);
        if (cr == null) {
            log.fine("Line Net Amt=0 - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty() + ",InOutQty=" + m_receiptLine.getMovementQty());
            //  Invoice Price Variance
            BigDecimal ipv = dr.getSourceBalance().negate();
            if (ipv.signum() != 0) {
                BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
                int ACCTTYPE_P = 0;
                if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
                    ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
                else
                    ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
                BigDecimal diff = ipv.subtract(costs);
                MInvoice m_invoice = m_invoiceLine.getParent();
                int C_Currency_ID = m_invoice.getC_Currency_ID();
                FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), C_Currency_ID, ipv);
                pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
                pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                pv.setUser1_ID(m_invoiceLine.getUser1_ID());
                pv.setUser2_ID(m_invoiceLine.getUser2_ID());
                pv.setUser3_ID(m_invoiceLine.getUser3_ID());
                pv.setUser4_ID(m_invoiceLine.getUser4_ID());
                if (diff.compareTo(Env.ZERO) != 0 && MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
                    FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), C_Currency_ID, diff.negate());
                    diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                    diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                    diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                    diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                    diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                    diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
                    diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
                    diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
                    diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
                }
            }
            log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
            facts.add(fact);
            return facts;
        }
        cr.setM_Product_ID(m_invoiceLine.getM_Product_ID());
        temp = cr.getAcctBalance();
        String documentBaseTypeInvoice = DB.getSQLValueString(m_invoiceLine.get_TrxName(), "SELECT DocBaseType FROM C_DocType WHERE C_DocType_ID=?", m_invoiceLine.getParent().getC_DocType_ID());
        BigDecimal quantityInvoice = MDocType.DOCBASETYPE_APInvoice.equals(documentBaseTypeInvoice) ? getQty().negate() : getQty();
        cr.setQty(quantityInvoice);
        //	Set AmtAcctCr/Dr from Invoice (sets also Project)
        if (as.isAccrual() && !//	Amt updated
        cr.updateReverseLine(//	Amt updated
        MInvoice.Table_ID, m_invoiceLine.getC_Invoice_ID(), m_invoiceLine.getC_InvoiceLine_ID(), quantityInvoice, multiplier)) {
            p_Error = "Invoice not posted yet";
            return null;
        }
        log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() + ") - " + cr.toString());
    } else //	Cash Acct
    {
        MInvoice invoice = m_invoiceLine.getParent();
        if (as.getC_Currency_ID() != invoice.getC_Currency_ID())
            LineNetAmt = MConversionRate.convert(getCtx(), LineNetAmt, invoice.getC_Currency_ID(), as.getC_Currency_ID(), invoice.getDateAcct(), invoice.getC_ConversionType_ID(), invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
        cr = fact.createLine(null, expense, as.getC_Currency_ID(), null, LineNetAmt);
        cr.setQty(getQty().multiply(multiplier).negate());
    }
    cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
    cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
    cr.setC_Project_ID(m_invoiceLine.getC_Project_ID());
    cr.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
    cr.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
    cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
    cr.setUser1_ID(m_invoiceLine.getUser1_ID());
    cr.setUser2_ID(m_invoiceLine.getUser2_ID());
    cr.setUser3_ID(m_invoiceLine.getUser3_ID());
    cr.setUser4_ID(m_invoiceLine.getUser4_ID());
    //see also Fact.java: checking for isMultiCurrency()
    if (dr.getC_Currency_ID() != cr.getC_Currency_ID())
        setIsMultiCurrency(true);
    //end AZ
    // Avoid usage of clearing accounts
    // If both accounts Not Invoiced Receipts and Inventory Clearing are equal
    // then remove the posting
    // not_invoiced_receipts
    MAccount acct_db = dr.getAccount();
    // inventory_clearing
    MAccount acct_cr = cr.getAccount();
    if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
        BigDecimal debit = dr.getAmtSourceDr();
        BigDecimal credit = cr.getAmtSourceCr();
        if (debit.compareTo(credit) == 0) {
            fact.remove(dr);
            fact.remove(cr);
        }
    }
    // End Avoid usage of clearing accounts
    //  Invoice Price Variance 	difference
    BigDecimal ipv = cr.getAcctBalance().add(dr.getAcctBalance()).negate();
    if (ipv.compareTo(Env.ZERO) == 0) {
        facts.add(fact);
        return facts;
    }
    if (!MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod())) {
        int ACCTTYPE_P = 0;
        if (MCostType.COSTINGMETHOD_StandardCosting.equals(ct.getCostingMethod()) || MCostType.COSTINGMETHOD_AverageInvoice.equals(ct.getCostingMethod()))
            ACCTTYPE_P = ProductCost.ACCTTYPE_P_IPV;
        else
            ACCTTYPE_P = ProductCost.ACCTTYPE_P_Asset;
        FactLine pv = fact.createLine(null, m_pc.getAccount(ACCTTYPE_P, as), as.getC_Currency_ID(), ipv);
        pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
        pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
        pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
        pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
        pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
        pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
        pv.setUser1_ID(m_invoiceLine.getUser1_ID());
        pv.setUser2_ID(m_invoiceLine.getUser2_ID());
        pv.setUser3_ID(m_invoiceLine.getUser3_ID());
        pv.setUser4_ID(m_invoiceLine.getUser4_ID());
    //
    } else {
        BigDecimal costs = MCostDetail.getByDocLineMatchInv(m_invoiceLine, m_receiptLine, as.getC_AcctSchema_ID(), as.getM_CostType_ID());
        FactLine pv = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), costs);
        if (pv != null) {
            pv.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
            pv.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
            pv.setC_Project_ID(m_invoiceLine.getC_Project_ID());
            pv.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
            pv.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
            pv.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
            pv.setUser1_ID(m_invoiceLine.getUser1_ID());
            pv.setUser2_ID(m_invoiceLine.getUser2_ID());
            pv.setUser3_ID(m_invoiceLine.getUser3_ID());
            pv.setUser4_ID(m_invoiceLine.getUser4_ID());
        }
        BigDecimal diff = ipv.subtract(costs);
        MInvoice m_invoice = m_invoiceLine.getParent();
        if (diff.compareTo(Env.ZERO) != 0) {
            FactLine diffline = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), as.getC_Currency_ID(), diff);
            if (diffline != null) {
                diffline.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
                diffline.setC_Project_ID(m_invoiceLine.getC_Project_ID());
                diffline.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
                diffline.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
                diffline.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
                diffline.setUser1_ID(m_invoiceLine.getUser1_ID());
                diffline.setUser2_ID(m_invoiceLine.getUser2_ID());
                diffline.setUser3_ID(m_invoiceLine.getUser3_ID());
                diffline.setUser4_ID(m_invoiceLine.getUser4_ID());
            }
        }
    }
    log.fine("IPV=" + ipv + "; Balance=" + fact.getSourceBalance());
    facts.add(fact);
    /** Commitment release										****/
    if (as.isAccrual() && as.isCreatePOCommitment()) {
        fact = Doc_Order.getCommitmentRelease(as, this, getQty(), m_invoiceLine.getC_InvoiceLine_ID(), Env.ONE);
        if (fact == null)
            return null;
        facts.add(fact);
    }
    return facts;
}
Also used : MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) MInvoice(org.compiere.model.MInvoice) MCostType(org.compiere.model.MCostType) BigDecimal(java.math.BigDecimal)

Example 14 with MCostType

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

the class AverageInvoiceCostingMethod method adjustCostDetail.

/**
	 * Recalculate Cost Detail
	 * @param cost
     */
public void adjustCostDetail(MCostDetail cost) {
    Properties ctx = cost.getCtx();
    String trxName = cost.get_TrxName();
    int transactionId = cost.getM_Transaction_ID();
    int clientId = cost.getAD_Client_ID();
    MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
    MCostType costType = (MCostType) cost.getM_CostType();
    MCostElement costElement = (MCostElement) cost.getM_CostElement();
    MAcctSchema accountSchema = (MAcctSchema) cost.getC_AcctSchema();
    CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
    if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
        MInOutLine line = (MInOutLine) transaction.getDocumentLine();
        if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0) {
                CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
            } else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0 && cost.getC_OrderLine_ID() > 0) {
                List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
                for (MMatchPO match : orderMatches) {
                    if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
                        CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
                    }
                }
            } else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() == 0 && cost.getC_InvoiceLine_ID() > 0 && cost.getC_LandedCostAllocation_ID() == 0) {
                List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
                for (MMatchInv match : invoiceMatches) {
                    if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
                        CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
                    }
                }
            }
        }
        // only own allocation
        if (cost.getC_LandedCostAllocation_ID() != 0) {
            MLandedCostAllocation allocation = (MLandedCostAllocation) cost.getC_LandedCostAllocation();
            {
                CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
            }
        }
    } else
        CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
Also used : MCostElement(org.compiere.model.MCostElement) MLandedCostAllocation(org.compiere.model.MLandedCostAllocation) MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MTransaction(org.compiere.model.MTransaction) MCostType(org.compiere.model.MCostType) Properties(java.util.Properties) MAcctSchema(org.compiere.model.MAcctSchema) MMatchInv(org.compiere.model.MMatchInv) List(java.util.List)

Example 15 with MCostType

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

the class AbstractCostingMethod method adjustCostDetail.

/**
	 * Recalculate Cost Detail
	 * @param cost
	 */
public void adjustCostDetail(MCostDetail cost) {
    MCostType costType = (MCostType) cost.getM_CostType();
    MCostElement costElement = (MCostElement) cost.getM_CostElement();
    MTransaction transaction = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
    IDocumentLine docLine = transaction.getDocumentLine();
    CostEngineFactory.getCostEngine(cost.getAD_Client_ID()).createCostDetail((MAcctSchema) cost.getC_AcctSchema(), costType, costElement, transaction, docLine, true);
}
Also used : MCostElement(org.compiere.model.MCostElement) MTransaction(org.compiere.model.MTransaction) MCostType(org.compiere.model.MCostType)

Aggregations

MCostType (org.compiere.model.MCostType)20 MCostElement (org.compiere.model.MCostElement)15 MAcctSchema (org.compiere.model.MAcctSchema)13 ArrayList (java.util.ArrayList)11 BigDecimal (java.math.BigDecimal)10 List (java.util.List)8 MProduct (org.compiere.model.MProduct)8 Arrays (java.util.Arrays)7 MCost (org.compiere.model.MCost)7 Query (org.compiere.model.Query)7 Trx (org.compiere.util.Trx)7 MTransaction (org.compiere.model.MTransaction)6 CostDimension (org.adempiere.engine.CostDimension)5 MAccount (org.compiere.model.MAccount)4 MInOutLine (org.compiere.model.MInOutLine)4 Env (org.compiere.util.Env)4 Msg (org.compiere.util.Msg)4 Optional (java.util.Optional)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3