Search in sources :

Example 6 with MTransaction

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

the class AbstractCostingMethod method createReversalCostDetail.

/**
	 * Create Reversal Transaction
	 */
public void createReversalCostDetail() {
    MTransaction originalTransaction = MTransaction.getByDocumentLine(transaction);
    if (originalTransaction == null) {
        //throw new AdempiereException("Can not found the original transaction");
        //System.out.println("Transaction not found :" + transaction);
        log.info("Transaction not found :" + transaction);
        return;
    }
    costDetail = new MCostDetail(model.getCtx(), 0, transaction.get_TrxName());
    // Qty Transaction
    lastCostDetail = MCostDetail.getByTransaction(originalTransaction.getDocumentLine(), originalTransaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID());
    if (lastCostDetail == null) {
        /*lastCostDetail = MCostDetail.getByTransaction(model,
					original_trx, accountSchema.getC_AcctSchema_ID(),
					dimension.getM_CostType_ID(),
					dimension.getM_CostElement_ID());*/
        //throw new
        //		 AdempiereException("Can not found the original cost detail");
        //System.out.println("Detail Cost not found :" + originalTransaction);
        log.info("Detail Cost not found :" + originalTransaction);
        return;
    }
    costDetail.copyValues(lastCostDetail, costDetail);
    costDetail.setAD_Org_ID(lastCostDetail.getAD_Org_ID());
    costDetail.setM_Warehouse_ID(lastCostDetail.getM_Warehouse_ID());
    setReversalCostDetail();
    costDetail.setM_AttributeSetInstance_ID(transaction.getM_AttributeSetInstance_ID());
    costDetail.setDateAcct(model.getDateAcct());
    //costDetail.setProcessing(false); not should change so that be costing re processing by early transaction
    //costDetail.setM_Transaction_ID(transaction.getM_Transaction_ID());
    costDetail.setDescription("Reversal " + originalTransaction.getM_Transaction_ID());
    costDetail.setIsReversal(true);
    costDetail.saveEx();
    // Update the original cost detail
    lastCostDetail.setDescription(lastCostDetail.getDescription() != null ? lastCostDetail.getDescription() : "" + "|Reversal " + costDetail.getM_Transaction_ID());
    lastCostDetail.setIsReversal(true);
    lastCostDetail.saveEx(transaction.get_TrxName());
// Only uncomment to debug Trx.get(costDetail.get_TrxName(),
// false).commit();
}
Also used : MTransaction(org.compiere.model.MTransaction) MCostDetail(org.compiere.model.MCostDetail)

Example 7 with MTransaction

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

the class AverageInvoiceCostingMethod 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;
    String costingLevel = MProduct.get(mtrx.getCtx(), mtrx.getM_Product_ID()).getCostingLevel(acctSchema, mtrx.getAD_Org_ID());
    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 8 with MTransaction

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

the class StorageEngine method create.

private static void create(IDocumentLine model, String MovementType, Timestamp MovementDate, int M_AttributeSetInstance_ID, BigDecimal Qty) {
    MTransaction mtrx = new MTransaction(model.getCtx(), model.getAD_Org_ID(), MovementType, model.getM_Locator_ID(), model.getM_Product_ID(), M_AttributeSetInstance_ID, Qty, MovementDate, model.get_TrxName());
    setReferenceLine_ID(mtrx, model);
    mtrx.saveEx();
}
Also used : MTransaction(org.compiere.model.MTransaction)

Example 9 with MTransaction

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

the class FifoLifoCostingMethod method adjustementQueue.

public void adjustementQueue(MCostDetail costDetail) {
    final List<MCostDetail> cds;
    if (costDetail.getCostAdjustmentDate() != null) {
        cds = MCostDetail.getAfterDate(costDetail, costingLevel);
    } else
        cds = MCostDetail.getAfterDate(costDetail, costingLevel);
    List<Object> list = new ArrayList<Object>();
    for (MCostDetail cd : cds) {
        if (cd == null)
            throw new AdempiereException("Error do not exist adjustment");
        MCostQueue cq = MCostQueue.getQueueForAdjustment(cd, dimension, model.get_TrxName());
        MTransaction trx = get(cd);
        //second condition - delayed transaction
        if ((!(cq.getCurrentQty().compareTo(Env.ZERO) == 0) && (trx.getMovementType().equals("C-") || trx.getMovementType().equals("I+") || trx.getMovementType().equals("I-")) && cd.getCostAdjustmentDate() != null) || ((trx.getMovementType().equals("C-") || trx.getMovementType().equals("I+") || trx.getMovementType().equals("I-")) && transaction.getMovementType().endsWith("+"))) {
            cq.addCurrentQty(cd.getQty().negate());
            cq.saveEx();
            cd.setProcessed(false);
            cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
            cd.saveEx();
            list.add(cd);
        } else if (trx.getMovementType().equals("V+") && costDetail.getCostAdjustmentDate() != null) {
            cd.setProcessed(false);
            cd.setAmt(amount);
            cd.saveEx();
            cq.setCurrentCostPrice(cd.getAmt().divide(cd.getQty()));
            cq.saveEx();
            break;
        } else if (trx.getMovementType().equals("M+") || trx.getMovementType().equals("M-")) {
            MTransaction trxTo;
            if (trx.getMovementType().equals("M+"))
                trxTo = getPrevious(trx);
            else
                trxTo = getNext(trx);
            cd.setProcessed(false);
            if (CostDimension.isSameCostDimension(accountSchema, trx, trxTo)) {
                cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
                cd.saveEx();
            } else {
                cq.addCurrentQty(cd.getQty().negate());
                cd.setAmt(cd.getQty().multiply(costThisLevel.add(costLowLevel)));
                cd.saveEx();
                if (trx.getMovementType().equals("M+"))
                    cq.setCurrentCostPrice(cd.getAmt().divide(cd.getQty()));
                if (cq.getCurrentCostPrice().compareTo(Env.ZERO) == 0)
                    cq.setCurrentCostPrice(cd.getCurrentCostPrice());
                cq.saveEx();
                list.add(cd);
            }
        } else
            continue;
    }
    for (MCostDetail cd : list.toArray(new MCostDetail[list.size()])) {
        processCostDetail(cd);
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) MTransaction(org.compiere.model.MTransaction) MCostQueue(org.compiere.model.MCostQueue) MCostDetail(org.compiere.model.MCostDetail)

Example 10 with MTransaction

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

the class CostEngine method createCostDetailForLandedCostAllocation.

//Create cost detail for by document
public void createCostDetailForLandedCostAllocation(MLandedCostAllocation allocation) {
    MInOutLine ioLine = (MInOutLine) allocation.getM_InOutLine();
    for (MTransaction transaction : MTransaction.getByInOutLine(ioLine)) {
        for (MAcctSchema accountSchema : MAcctSchema.getClientAcctSchema(allocation.getCtx(), allocation.getAD_Client_ID())) {
            List<MCostType> costTypes = MCostType.get(allocation.getCtx(), allocation.get_TrxName());
            for (MCostType costType : costTypes) {
                MCostElement costElement = (MCostElement) allocation.getM_CostElement();
                CostEngineFactory.getCostEngine(allocation.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
            }
        }
    }
}
Also used : MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MInOutLine(org.compiere.model.MInOutLine) 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