Search in sources :

Example 11 with MTransaction

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

the class AveragePOCostingMethod method adjustCostDetail.

/**
	 * Recalculate Cost Detail
	 * @param costDetail
     */
public void adjustCostDetail(MCostDetail costDetail) {
    Properties ctx = costDetail.getCtx();
    String trxName = costDetail.get_TrxName();
    int transactionId = costDetail.getM_Transaction_ID();
    int clientId = costDetail.getAD_Client_ID();
    MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
    MCostType costType = (MCostType) costDetail.getM_CostType();
    MCostElement costElement = (MCostElement) costDetail.getM_CostElement();
    MAcctSchema accountSchema = (MAcctSchema) costDetail.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 (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0) {
                CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
            } else if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0 && costDetail.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 (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() == 0 && costDetail.getC_OrderLine_ID() > 0) {
                List<MMatchPO> poMatches = MMatchPO.getInOutLine(line);
                for (MMatchPO match : poMatches) {
                    if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
                        CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
                    }
                }
            }
        }
        for (MLandedCostAllocation allocation : MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID())) {
            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) MAcctSchema(org.compiere.model.MAcctSchema) MLandedCostAllocation(org.compiere.model.MLandedCostAllocation) MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MTransaction(org.compiere.model.MTransaction) List(java.util.List) MCostType(org.compiere.model.MCostType) Properties(java.util.Properties)

Example 12 with MTransaction

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

the class AveragePOCostingMethod method createUpdateAverageCostDetail.

public void createUpdateAverageCostDetail(MPPCostCollector costCollectorVariance, BigDecimal costVarianceThisLevel, BigDecimal costVarianceLowLevel, MProduct product, MAcctSchema acctSchema, MCostType costType, MCostElement costElement) {
    String whereClause = " exists (select 1 from pp_cost_collector pc" + " where pc.pp_cost_collector_ID=m_transaction.pp_Cost_collector_ID and costcollectortype =? " + " and pc.pp_order_ID=?)";
    MTransaction mtrx = new Query(costCollectorVariance.getCtx(), MTransaction.Table_Name, whereClause, costCollectorVariance.get_TrxName()).setParameters(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, costCollectorVariance.getPP_Order_ID()).setOrderBy("M_Transaction_ID desc").first();
    BigDecimal costThisLevel = Env.ZERO;
    BigDecimal costLowLevel = Env.ZERO;
    costCollectorVariance.set_ValueOfColumn("Cost", costVarianceThisLevel.compareTo(Env.ZERO) != 0 ? costVarianceThisLevel : costVarianceLowLevel);
    costCollectorVariance.saveEx();
    IDocumentLine model = costCollectorVariance;
    MCost cost = MCost.validateCostForCostType(acctSchema, costType, costElement, product.getM_Product_ID(), 0, 0, 0, mtrx.get_TrxName());
    final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
    method.setCostingMethod(acctSchema, mtrx, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
    method.process();
}
Also used : Query(org.compiere.model.Query) MCost(org.compiere.model.MCost) MTransaction(org.compiere.model.MTransaction) BigDecimal(java.math.BigDecimal)

Example 13 with MTransaction

use of org.compiere.model.MTransaction 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 14 with MTransaction

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

the class AbstractCostingMethod method clearAccounting.

public void clearAccounting(MCostDetail cost) {
    // Only can delete if period is open
    MTransaction trx = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
    IDocumentLine documentLine = trx.getDocumentLine();
    MDocType docType = MDocType.get(cost.getCtx(), documentLine.getC_DocType_ID());
    Boolean openPeriod = MPeriod.isOpen(cost.getCtx(), cost.getDateAcct(), docType.getDocBaseType(), cost.getAD_Org_ID());
    if (!openPeriod)
        return;
    String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
    int tableId = 0;
    int recordId = 0;
    if (cost.getC_OrderLine_ID() != 0) {
        MOrderLine line = (MOrderLine) cost.getC_OrderLine();
        line.getParent().setPosted(false);
        line.getParent().saveEx();
        recordId = line.getParent().get_ID();
        tableId = line.getParent().get_Table_ID();
    }
    if (cost.getM_InOutLine_ID() != 0) {
        MInOutLine line = (MInOutLine) cost.getM_InOutLine();
        line.getParent().setPosted(false);
        line.getParent().saveEx();
        recordId = line.getParent().get_ID();
        tableId = line.getParent().get_Table_ID();
    }
    if (cost.getM_InventoryLine_ID() != 0) {
        MInventoryLine line = (MInventoryLine) cost.getM_InventoryLine();
        line.getParent().setPosted(false);
        line.getParent().saveEx();
        recordId = line.getParent().get_ID();
        tableId = line.getParent().get_Table_ID();
    }
    if (cost.getM_MovementLine_ID() != 0) {
        MMovementLine line = (MMovementLine) cost.getM_MovementLine();
        line.getParent().setPosted(false);
        line.getParent().saveEx();
        recordId = line.getParent().get_ID();
        tableId = line.getParent().get_Table_ID();
    }
    if (cost.getM_ProductionLine_ID() != 0) {
    }
    if (cost.getPP_Cost_Collector_ID() != 0) {
        MPPCostCollector costCollector = (MPPCostCollector) cost.getPP_Cost_Collector();
        costCollector.setPosted(false);
        costCollector.saveEx();
        recordId = costCollector.get_ID();
        tableId = costCollector.get_Table_ID();
    }
    int no = DB.executeUpdateEx(sqldelete, new Object[] { recordId, tableId }, cost.get_TrxName());
}
Also used : MDocType(org.compiere.model.MDocType) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MTransaction(org.compiere.model.MTransaction) MPPCostCollector(org.eevolution.model.MPPCostCollector) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine)

Example 15 with MTransaction

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

MTransaction (org.compiere.model.MTransaction)16 MCostElement (org.compiere.model.MCostElement)6 MCostType (org.compiere.model.MCostType)6 MInOutLine (org.compiere.model.MInOutLine)6 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)4 MAcctSchema (org.compiere.model.MAcctSchema)4 MCostDetail (org.compiere.model.MCostDetail)4 Query (org.compiere.model.Query)4 MCost (org.compiere.model.MCost)3 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)3 MMatchPO (org.compiere.model.MMatchPO)3 List (java.util.List)2 Properties (java.util.Properties)2 MInventoryLine (org.compiere.model.MInventoryLine)2 MMatchInv (org.compiere.model.MMatchInv)2 MMovementLine (org.compiere.model.MMovementLine)2 MProduct (org.compiere.model.MProduct)2 MPPCostCollector (org.eevolution.model.MPPCostCollector)2 SQLException (java.sql.SQLException)1