use of org.compiere.model.MCostDetail in project adempiere by adempiere.
the class Doc_PPCostCollector method createActivityControl.
/**
* Feedback Labor and Burden absorbed
* Debit Work in Process Account for each Labor or Burden using the current cost rate
* Create a fact line for labor or burden
* Labor(Resources)
* Burden
* Credit Labor Absorbed or Burden Absorbed Account
* Create a fact line for labor or burden
* Labor Absorbed
* Burden Absorbed
*/
protected List<Fact> createActivityControl(MAcctSchema acctSchema) {
final ArrayList<Fact> facts = new ArrayList<Fact>();
final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
facts.add(fact);
final MProduct product = costCollector.getM_Product();
MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
for (MCostDetail costDetail : getCostDetailsActivityControl()) {
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
MAccount creditCostAccount = docLineCostCollector.getAccount(acctSchema, costElement);
createLines(costElement, acctSchema, fact, product, workInProcessAccount, creditCostAccount, cost, costCollector.getMovementQty());
}
//
return facts;
}
use of org.compiere.model.MCostDetail in project adempiere by adempiere.
the class AbstractCostingMethod method createCostDetails.
protected List<MCostDetail> createCostDetails() {
final String idColumnName;
if (model instanceof MMatchPO) {
idColumnName = I_C_OrderLine.COLUMNNAME_C_OrderLine_ID;
} else if (model instanceof MMatchInv) {
idColumnName = I_C_InvoiceLine.COLUMNNAME_C_InvoiceLine_ID;
} else {
idColumnName = model.get_TableName() + "_ID";
}
List<MCostDetail> list = new ArrayList<MCostDetail>();
if (model.isSOTrx() == true || model instanceof MInventoryLine || model instanceof MMovementLine) {
List<CostComponent> costComponents = getCalculatedCosts();
for (CostComponent costComponent : costComponents) {
MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costComponent.getAmount(), Env.ZERO, costComponent.getQty(), model.get_TrxName());
if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, model.get_ID()))
throw new AdempiereException("Cannot set " + idColumnName);
StringBuilder description = new StringBuilder();
if (!Util.isEmpty(model.getDescription(), true))
description.append(model.getDescription());
if (model.isSOTrx() != false) {
description.append(model.isSOTrx() ? "(|->)" : "(|<-)");
}
if (// TODO: need evaluate anca
model.isSOTrx() != false)
cost.setIsSOTrx(model.isSOTrx());
else
cost.setIsSOTrx(model.isSOTrx());
cost.setM_Transaction_ID(transaction.get_ID());
cost.setDescription(description.toString());
cost.saveEx();
list.add(cost);
}
} else // qty and amt is take from documentline
{
MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costThisLevel.multiply(model.getMovementQty()), Env.ZERO, model.getMovementQty(), model.get_TrxName());
int id;
if (model instanceof MMatchPO) {
I_M_InOutLine inOutLine = transaction.getM_InOutLine();
I_C_OrderLine orderLine = inOutLine.getC_OrderLine();
id = orderLine.getC_OrderLine_ID();
} else {
id = model.get_ID();
}
if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, id))
throw new AdempiereException("Cannot set " + idColumnName);
if (model.isSOTrx() != false)
cost.setIsSOTrx(model.isSOTrx());
else
cost.setIsSOTrx(model.isSOTrx());
cost.setM_Transaction_ID(transaction.get_ID());
cost.saveEx();
list.add(cost);
}
return list;
}
use of org.compiere.model.MCostDetail 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();
}
use of org.compiere.model.MCostDetail in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method createCostAdjustment.
public void createCostAdjustment() {
// only re process cost detail if account schema need adjust cost
if (!accountSchema.isAdjustCOGS())
return;
// void the cycle process, only process the adjustment
if (costDetail == null || costDetail.isProcessing())
return;
// Check if cost detail is an earlier transaction
// get the cost details that need be re process before this cost
// transaction
List<MCostDetail> costDetails = MCostDetail.getAfterDate(costDetail, costingLevel);
if (costDetails == null || costDetails.size() == 0)
return;
MCostDetail lastCostDetail = costDetail;
costDetail = null;
//Renumber sequence
for (MCostDetail cost : costDetails) {
// remunerate sequence
cost.setSeqNo(lastCostDetail.getSeqNo() + 10);
cost.setProcessing(true);
cost.saveEx();
lastCostDetail = cost;
// Only uncomment to debug
// Trx.get(cd.get_TrxName(), false).commit();
}
int costDetailAdjustmentNo = 0;
for (MCostDetail cost : costDetails) {
costDetailAdjustmentNo++;
adjustCostDetail(cost);
cost.setProcessing(false);
cost.saveEx();
//clearAccounting(cd);
// Only uncomment to debug
// Trx.get(cd.get_TrxName(), false).commit();
}
}
use of org.compiere.model.MCostDetail 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);
}
}
}
}
Aggregations