Search in sources :

Example 6 with MPPCostCollector

use of org.eevolution.model.MPPCostCollector 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 7 with MPPCostCollector

use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.

the class StandardCostingMethod method createCostDetail.

private void createCostDetail() {
    final String idColumnName = CostEngine.getIDColumnName(model);
    if (model.getReversalLine_ID() > 0) {
        createReversalCostDetail();
        return;
    }
    int seqNo = lastCostDetail.getSeqNo() + 10;
    if (model instanceof MPPCostCollector) {
        MPPCostCollector cc = (MPPCostCollector) model;
        if (MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance.equals(cc.getCostCollectorType())) {
            createMethodVariances(cc);
        } else if (MPPCostCollector.COSTCOLLECTORTYPE_UsegeVariance.equals(cc.getCostCollectorType())) {
            createUsageVariances(cc);
        } else if (MPPCostCollector.COSTCOLLECTORTYPE_RateVariance.equals(cc.getCostCollectorType())) {
            createRateVariances(cc);
        } else if (MPPCostCollector.COSTCOLLECTORTYPE_MixVariance.equals(cc.getCostCollectorType())) {
            // no implement
            ;
        }
    }
    if (costDetail == null) {
        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());
        costDetail.setDateAcct(dateAccounting);
        costDetail.setSeqNo(seqNo);
    }
    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 + " Adjust Cost:" + 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 + " Adjust Cost LL:" + adjustCost);
        }
    }
    if (!costDetail.set_ValueOfColumnReturningBoolean(idColumnName, model.get_ID()))
        throw new AdempiereException("Cannot set " + idColumnName);
    // set if transaction is sales order type or not
    if (isSalesTransaction != null)
        costDetail.setIsSOTrx(isSalesTransaction);
    else
        costDetail.setIsSOTrx(model.isSOTrx());
    // set transaction id
    if (transaction != null)
        costDetail.setM_Transaction_ID(transaction.getM_Transaction_ID());
    costDetail.setCumulatedQty(dimension.getCumulatedQty());
    costDetail.setCumulatedAmt(dimension.getCumulatedAmt());
    costDetail.setCumulatedAmtLL(dimension.getCumulatedAmtLL());
    costDetail.setCurrentCostPrice(dimension.getCurrentCostPrice());
    costDetail.setCurrentCostPriceLL(dimension.getCurrentCostPriceLL());
    StringBuilder description = new StringBuilder();
    if (!Util.isEmpty(model.getDescription(), true))
        description.append(model.getDescription());
    if (isSalesTransaction != null) {
        description.append(isSalesTransaction ? "(|->)" : "(|<-)");
    }
    if (transaction != null)
        costDetail.setM_Transaction_ID(transaction.getM_Transaction_ID());
    costDetail.setDescription(description.toString());
    updateAmountCost();
    costDetail.saveEx();
    return;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MPPCostCollector(org.eevolution.model.MPPCostCollector)

Example 8 with MPPCostCollector

use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.

the class StandardCostingMethod method createRateVariances.

public void createRateVariances(MPPCostCollector costCollector) {
    MProduct product = null;
    if (costCollector.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl)) {
        final I_AD_WF_Node node = costCollector.getPP_Order_Node().getAD_WF_Node();
        product = MProduct.forS_Resource_ID(costCollector.getCtx(), node.getS_Resource_ID(), null);
    } else if (costCollector.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_ComponentIssue)) {
        final I_PP_Order_BOMLine bomLine = costCollector.getPP_Order_BOMLine();
        product = MProduct.get(costCollector.getCtx(), bomLine.getM_Product_ID());
    } else if (MPPCostCollector.COSTCOLLECTORTYPE_RateVariance.equals(costCollector.getCostCollectorType()))
        product = MProduct.get(costCollector.getCtx(), costCollector.getM_Product_ID());
    // Cost Collector - Rate Variance
    MPPCostCollector costCollectorRateVariance = null;
    for (MAcctSchema accountSchema : CostEngine.getAcctSchema(costCollector)) {
        for (MCostElement costElement : MCostElement.getCostElement(costCollector.getCtx(), costCollector.get_TrxName())) {
            final MCostDetail cost = MCostDetail.getCostDetail(costCollector, costElement.getM_CostElement_ID());
            if (cost == null)
                continue;
            //
            final BigDecimal quantity = cost.getQty();
            final BigDecimal priceStandard = getProductStandardCostPrice(costCollector, product, accountSchema, costElement);
            final BigDecimal priceActual = getProductActualCostPrice(costCollector, product, accountSchema, costElement, costCollector.get_TrxName());
            final BigDecimal amountStandard = CostEngine.roundCost(priceStandard.multiply(quantity), accountSchema.getC_AcctSchema_ID());
            final BigDecimal amtActual = CostEngine.roundCost(priceActual.multiply(quantity), accountSchema.getC_AcctSchema_ID());
            if (amountStandard.compareTo(amtActual) == 0)
                continue;
            //
            if (costCollectorRateVariance == null)
                costCollectorRateVariance = MPPCostCollector.createVarianceCostCollector(costCollector, MPPCostCollector.COSTCOLLECTORTYPE_RateVariance);
            List<MCostType> costTypes = MCostType.get(accountSchema.getCtx(), accountSchema.get_TrxName());
            for (MCostType costType : costTypes) {
                createVarianceCostDetail(costCollectorRateVariance, amtActual.abs(), quantity, cost, null, accountSchema, costType, costElement);
                createVarianceCostDetail(costCollectorRateVariance, amountStandard.abs(), quantity, cost, null, accountSchema, costType, costElement);
            }
        }
    }
    //
    if (costCollectorRateVariance != null) {
        boolean ok = costCollectorRateVariance.processIt(MPPCostCollector.ACTION_Complete);
        costCollectorRateVariance.saveEx();
        if (!ok)
            throw new AdempiereException(costCollectorRateVariance.getProcessMsg());
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MPPCostCollector(org.eevolution.model.MPPCostCollector) BigDecimal(java.math.BigDecimal) I_PP_Order_BOMLine(org.eevolution.model.I_PP_Order_BOMLine)

Example 9 with MPPCostCollector

use of org.eevolution.model.MPPCostCollector 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

MPPCostCollector (org.eevolution.model.MPPCostCollector)9 BigDecimal (java.math.BigDecimal)4 MInOutLine (org.compiere.model.MInOutLine)4 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MInventoryLine (org.compiere.model.MInventoryLine)3 MMovementLine (org.compiere.model.MMovementLine)3 MMatchInv (org.compiere.model.MMatchInv)2 MMatchPO (org.compiere.model.MMatchPO)2 MOrderLine (org.compiere.model.MOrderLine)2 MProductionLine (org.compiere.model.MProductionLine)2 MTransaction (org.compiere.model.MTransaction)2 StandardCostingMethod (org.adempiere.engine.StandardCostingMethod)1 MCost (org.compiere.model.MCost)1 MCostDetail (org.compiere.model.MCostDetail)1 MDocType (org.compiere.model.MDocType)1 MInOut (org.compiere.model.MInOut)1 MLandedCostAllocation (org.compiere.model.MLandedCostAllocation)1 MLocator (org.compiere.model.MLocator)1 MProduction (org.compiere.model.MProduction)1 MProjectIssue (org.compiere.model.MProjectIssue)1