Search in sources :

Example 6 with MMatchInv

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

the class GenerateCostDetail method generateCostDetail.

public void generateCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction) {
    //Create Cost Detail for this Transaction
    CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
    CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
    // invoices
    if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
        MInOutLine line = (MInOutLine) transaction.getDocumentLine();
        if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            //get purchase matches
            List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
            orderMatches.stream().forEach(match -> {
                if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
                    CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
                }
            });
            //get invoice matches
            List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
            invoiceMatches.forEach(match -> {
                if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
                    CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
                }
            });
        }
        //get landed allocation cost
        MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID()).stream().forEach(allocation -> {
            if (allocation.getDateAcct().after(getAccountDate()) && allocation.getDateAcct().before(getAccountDateTo()))
                CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
        });
    }
}
Also used : MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MMatchInv(org.compiere.model.MMatchInv)

Example 7 with MMatchInv

use of org.compiere.model.MMatchInv 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;
}
Also used : ProductCost(org.compiere.model.ProductCost) MInOutLine(org.compiere.model.MInOutLine) MInvoiceLine(org.compiere.model.MInvoiceLine) MMatchInv(org.compiere.model.MMatchInv)

Example 8 with MMatchInv

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

the class AveragePOCostingMethod method setCostingMethod.

/**
     * Constructor for Cost Engine
     * @param accountSchema
     * @param transaction
     * @param model
     * @param dimension
     * @param costThisLevel
     * @param costLowLevel
     * @param isSalesTransaction
     */
public void setCostingMethod(MAcctSchema accountSchema, MTransaction transaction, IDocumentLine model, MCost dimension, BigDecimal costThisLevel, BigDecimal costLowLevel, Boolean isSalesTransaction) {
    if (model instanceof MMatchInv) {
        if (costDetail != null && costDetail.get_ID() > 0) {
            costDetail.setC_InvoiceLine_ID(((MMatchInv) model).getC_InvoiceLine_ID());
            costDetail.saveEx();
        }
        return;
    }
    this.accountSchema = accountSchema;
    this.transaction = transaction;
    this.dimension = dimension;
    this.costThisLevel = (costThisLevel == null ? Env.ZERO : costThisLevel);
    this.costLowLevel = (costLowLevel == null ? Env.ZERO : costLowLevel);
    this.isSalesTransaction = isSalesTransaction;
    this.model = model;
    this.costingLevel = MProduct.get(this.transaction.getCtx(), this.transaction.getM_Product_ID()).getCostingLevel(accountSchema, transaction.getAD_Org_ID());
    // find if this transaction exist into cost detail
    this.costDetail = MCostDetail.getByTransaction(this.model, this.transaction, this.accountSchema.getC_AcctSchema_ID(), this.dimension.getM_CostType_ID(), this.dimension.getM_CostElement_ID());
    //Setting Accounting period status
    MDocType documentType = new MDocType(transaction.getCtx(), transaction.getDocumentLine().getC_DocType_ID(), transaction.get_TrxName());
    this.isOpenPeriod = MPeriod.isOpen(transaction.getCtx(), model.getDateAcct(), documentType.getDocBaseType(), transaction.getAD_Org_ID());
    //Setting Date Accounting based on Open Period
    if (this.isOpenPeriod)
        this.dateAccounting = model.getDateAcct();
    else
        // Is Necessary define that happen in this case when period is close
        this.dateAccounting = null;
    this.movementQuantity = transaction.getMovementQty();
}
Also used : MDocType(org.compiere.model.MDocType) MMatchInv(org.compiere.model.MMatchInv)

Example 9 with MMatchInv

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

the class AverageInvoiceCostingMethod method createCostDetail.

private void createCostDetail() {
    //Validate if model have a reverses and processing of reverse
    if (model.getReversalLine_ID() > 0 && costDetail == null) {
        createReversalCostDetail();
        return;
    } else if (model.getReversalLine_ID() > 0)
        return;
    int seqNo = lastCostDetail.getSeqNo() + 10;
    // adjustment
    if (transaction.getM_Transaction_ID() != lastCostDetail.getM_Transaction_ID() && costDetail == null || adjustCost.add(adjustCostLowerLevel).signum() != 0 && costDetail == null) {
        // if exist adjustment cost for Landed Cost Allocation or Match Inv then set the movement qty to zero
        if ((adjustCost.add(adjustCostLowerLevel).signum() != 0 && costDetail != null) || (model instanceof MLandedCostAllocation || model instanceof MMatchInv))
            movementQuantity = Env.ZERO;
        // create new cost detail
        costDetail = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), currentCostPrice.multiply(movementQuantity).abs(), currentCostPriceLowerLevel.multiply(movementQuantity).abs(), movementQuantity, transaction.get_TrxName());
        // set account date for this cost detail
        costDetail.setDateAcct(dateAccounting);
        costDetail.setSeqNo(seqNo);
        // set transaction id
        if (transaction != null)
            costDetail.setM_Transaction_ID(transaction.getM_Transaction_ID());
        // set if transaction is sales order type or not
        if (isSalesTransaction != null && isSalesTransaction)
            costDetail.setIsSOTrx(isSalesTransaction);
        else if (isSalesTransaction != null && !isSalesTransaction)
            costDetail.setIsSOTrx(model.isSOTrx());
        if (adjustCost.signum() != 0 || adjustCostLowerLevel.signum() != 0) {
            String description = costDetail.getDescription() != null ? costDetail.getDescription() : "";
            // update adjustment cost this level
            if (adjustCost.signum() != 0) {
                costDetail.setCostAdjustmentDate(model.getDateAcct());
                costDetail.setCostAdjustment(adjustCost);
                costDetail.setCostAmt(BigDecimal.ZERO);
                costDetail.setAmt(costDetail.getAmt().add(costDetail.getCostAdjustment()));
                costDetail.setDescription(description + Msg.parseTranslation(Env.getCtx(), "@CostAdjustment@ ") + adjustCost);
            }
            // update adjustment cost lower level
            if (adjustCostLowerLevel.signum() != 0) {
                description = costDetail.getDescription() != null ? costDetail.getDescription() : "";
                costDetail.setCostAdjustmentDateLL(model.getDateAcct());
                costDetail.setCostAdjustmentLL(adjustCostLowerLevel);
                costDetail.setCostAmtLL(BigDecimal.ZERO);
                costDetail.setAmt(costDetail.getCostAmtLL().add(costDetail.getCostAdjustmentLL()));
                costDetail.setDescription(description + Msg.parseTranslation(Env.getCtx(), "@CostAdjustmentLL@ ") + adjustCost);
            }
        }
        updateAmountCost();
        return;
    }
}
Also used : MLandedCostAllocation(org.compiere.model.MLandedCostAllocation) MMatchInv(org.compiere.model.MMatchInv) MCostDetail(org.compiere.model.MCostDetail)

Example 10 with MMatchInv

use of org.compiere.model.MMatchInv 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)

Aggregations

MMatchInv (org.compiere.model.MMatchInv)14 MMatchPO (org.compiere.model.MMatchPO)8 MInOutLine (org.compiere.model.MInOutLine)7 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)5 MCostDetail (org.compiere.model.MCostDetail)3 MInventoryLine (org.compiere.model.MInventoryLine)3 MMovementLine (org.compiere.model.MMovementLine)3 BigDecimal (java.math.BigDecimal)2 MDocType (org.compiere.model.MDocType)2 MInvoiceLine (org.compiere.model.MInvoiceLine)2 MProduction (org.compiere.model.MProduction)2 MProductionLine (org.compiere.model.MProductionLine)2 MTransaction (org.compiere.model.MTransaction)2 MPPCostCollector (org.eevolution.model.MPPCostCollector)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 AssetException (org.compiere.FA.exceptions.AssetException)1 I_C_OrderLine (org.compiere.model.I_C_OrderLine)1