use of org.compiere.model.MCostQueue in project adempiere by adempiere.
the class FifoLifoCostingMethod method updateCurrentCost.
public void updateCurrentCost(MCostDetail m_costdetail) {
MCostQueue[] cQueue = MCostQueue.getQueue(dimension, m_costdetail.getDateAcct(), m_costdetail.get_TrxName());
//TODO: need evaluate this!
if (cQueue != null) {
MCostType ct = (MCostType) dimension.getM_CostType();
if (cQueue.length > 0 && ct.isFifo())
dimension.setCurrentCostPrice(cQueue[0].getCurrentCostPrice());
else if (cQueue.length > 0 && MCostElement.COSTELEMENTTYPE_LandedCost.equals(dimension.getM_CostElement().getCostElementType()))
dimension.setCurrentCostPrice(cQueue[0].getCurrentCostPrice());
}
dimension.setCurrentQty(dimension.getCurrentQty().add(m_costdetail.getQty()));
if (cQueue != null && cQueue.length > 0) {
BigDecimal cAmt = cQueue[0].getCurrentCostPrice().multiply(m_costdetail.getQty());
dimension.setCumulatedAmt(dimension.getCumulatedAmt().add(cAmt));
dimension.setCumulatedQty(dimension.getCumulatedQty().add(m_costdetail.getQty()));
}
log.finer("QtyAdjust - FiFo/Lifo - " + dimension);
dimension.saveEx();
}
use of org.compiere.model.MCostQueue in project adempiere by adempiere.
the class FifoLifoCostingMethod method processCostDetail.
public void processCostDetail() {
//check if document is entered with delay
lastCostDetail = MCostDetail.getLastTransaction(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costingLevel);
if (lastCostDetail == null) {
lastCostDetail = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), Env.ZERO, Env.ZERO, Env.ZERO, transaction.get_TrxName());
lastCostDetail.setDateAcct(new Timestamp(System.currentTimeMillis()));
}
if (model.getReversalLine_ID() > 0) {
createReversalCostDetail();
MCostQueue cq = MCostQueue.getQueueForAdjustment(costDetail, dimension, model.get_TrxName());
if (cq.getCurrentQty().compareTo(costDetail.getQty()) == 1 || cq.getCurrentQty().compareTo(costDetail.getCurrentQty()) == 0) {
cq.setCurrentQty(cq.getCurrentQty().add(costDetail.getQty()));
dimension.setCurrentQty(dimension.getCurrentQty().add(costDetail.getQty()));
cq.saveEx();
dimension.saveEx();
} else
processCostDetail(costDetail);
return;
}
if (costDetail == null) {
for (MCostDetail cost : createCostDetails()) {
if (CostDimension.isSameCostDimension(accountSchema, model) && (transaction.getMovementType().equals("M+") || transaction.getMovementType().equals("M-"))) {
costDetail = cost;
continue;
}
processCostDetail(cost);
if (costDetail.getDateAcct().compareTo(lastCostDetail.getDateAcct()) < 0) {
adjustementQueue(cost);
}
}
} else {
amount = transaction.getMovementQty().multiply(costThisLevel.add(costLowLevel));
amountLowerLevel = transaction.getMovementQty().multiply(costLowLevel);
accumulatedQuantity = dimension.getCumulatedQty();
adjustCost = amount.subtract(costDetail.getAmt());
accumulatedAmount = costDetail.getCumulatedAmt().add(amount).add(adjustCost);
accumulatedAmountLowerLevel = getNewAccumulatedAmountLowerLevel(lastCostDetail).add(amountLowerLevel);
if (accumulatedAmount.signum() != 0)
currentCostPrice = accumulatedAmount.divide(accumulatedQuantity.signum() != 0 ? accumulatedQuantity : BigDecimal.ONE, accountSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
else
currentCostPrice = Env.ZERO;
if (accumulatedAmountLowerLevel.signum() != 0)
currentCostPriceLowerLevel = accumulatedAmountLowerLevel.divide(accumulatedQuantity.signum() != 0 ? accumulatedQuantity : BigDecimal.ONE, accountSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
else
currentCostPriceLowerLevel = Env.ZERO;
if (adjustCost.compareTo(Env.ZERO) != 0) {
costDetail.setCostAdjustment(adjustCost);
costDetail.setProcessed(false);
costDetail.setDescription("Adjust Cost:" + adjustCost);
costDetail.setCostAdjustmentDate(model.getDateAcct());
costDetail.saveEx();
}
costDetail.saveEx();
if (costDetail.getCostAdjustmentDate() != null) {
if (accountSchema.isAdjustCOGS()) {
adjustementQueue(costDetail);
}
}
}
}
use of org.compiere.model.MCostQueue 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);
}
}
use of org.compiere.model.MCostQueue in project adempiere by adempiere.
the class InventoryTestException method dumpStatus.
private void dumpStatus(MMDocument doc, String trxName) {
MProduct product = InventoryUtil.getCreateProduct(doc);
MStorage[] storage = MStorage.getOfProduct(getCtx(), product.get_ID(), trxName);
System.err.println("" + product.toString());
System.err.println("STORAGE____________________________________________________");
System.err.println(" " + doc);
for (MStorage s : storage) {
System.err.println("" + s);
}
//
//
System.err.println("COST QUEUE ________________________________________________");
List<MCostQueue> queue = new Query(getCtx(), MCostQueue.Table_Name, "M_Product_ID=?", trxName).setParameters(new Object[] { product.get_ID() }).setOrderBy(MCostQueue.COLUMNNAME_M_CostQueue_ID).list();
for (MCostQueue q : queue) {
System.err.println("" + q);
}
//
//
System.err.println("COST Detail ________________________________________________");
List<MCostDetail> details = new Query(getCtx(), MCostDetail.Table_Name, "M_Product_ID=?", trxName).setParameters(new Object[] { product.get_ID() }).setOrderBy(MCostDetail.COLUMNNAME_M_CostDetail_ID).list();
for (MCostDetail cd : details) {
System.err.println("" + cd.toString());
}
//
//
System.err.println(doc.scenario.toString());
//
System.err.println("___________________________________________________________");
System.err.flush();
System.err.flush();
}
Aggregations