use of org.compiere.model.MMatchPO in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* Clear Accounting
* @param accountSchema
* @param costType
* @param model
* @param productId
* @param dateAcct
* @return true clean
*/
public boolean clearAccounting(MAcctSchema accountSchema, I_M_CostType costType, PO model, int productId, Timestamp dateAcct) {
// check if costing type need reset accounting
if (!accountSchema.getCostingMethod().equals(costType.getCostingMethod())) {
MProduct product = MProduct.get(accountSchema.getCtx(), productId);
MProductCategoryAcct productCategoryAcct = MProductCategoryAcct.get(accountSchema.getCtx(), product.getM_Product_Category_ID(), accountSchema.get_ID(), model.get_TrxName());
if (productCategoryAcct == null || !costType.getCostingMethod().equals(productCategoryAcct.getCostingMethod()))
return false;
}
final String docBaseType;
// check if account period is open
if (model instanceof MMatchInv)
docBaseType = MPeriodControl.DOCBASETYPE_MatchInvoice;
else if (model instanceof MMatchPO)
docBaseType = MPeriodControl.DOCBASETYPE_MatchPO;
else if (model instanceof MProduction)
docBaseType = MPeriodControl.DOCBASETYPE_MaterialProduction;
else {
MDocType docType = MDocType.get(model.getCtx(), model.get_ValueAsInt(MDocType.COLUMNNAME_C_DocType_ID));
docBaseType = docType.getDocBaseType();
}
Boolean openPeriod = MPeriod.isOpen(model.getCtx(), dateAcct, docBaseType, model.getAD_Org_ID());
if (!openPeriod) {
System.out.println("Period closed.");
return false;
}
final String sqlUpdate = "UPDATE " + model.get_TableName() + " SET Posted = 'N' WHERE " + model.get_TableName() + "_ID=?";
DB.executeUpdate(sqlUpdate, new Object[] { model.get_ID() }, false, model.get_TrxName());
//Delete account
final String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
DB.executeUpdate(sqldelete, new Object[] { model.get_ID(), model.get_Table_ID() }, false, model.get_TrxName());
return true;
}
use of org.compiere.model.MMatchPO in project adempiere by adempiere.
the class CostEngine method createCostDetail.
/**
* Create Cost Detail
* @param accountSchema Account Schema
* @param transaction Material Transaction
* @param model IDocumentLine
* @param costType Cost Type
* @param costElement Cost Element
*/
public void createCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction, IDocumentLine model, boolean force) {
if (!force)
return;
BigDecimal costThisLevel = Env.ZERO;
BigDecimal costLowLevel = Env.ZERO;
String costingLevel = MProduct.get(transaction.getCtx(), transaction.getM_Product_ID()).getCostingLevel(accountSchema, transaction.getAD_Org_ID());
// adjustment for Average PO Costing method
if (model instanceof MMatchInv && MCostType.COSTINGMETHOD_AveragePO.equals(costType.getCostingMethod()))
return;
// adjustment for Average PO Costing method
if (model instanceof MMatchPO && MCostType.COSTINGMETHOD_AverageInvoice.equals(costType.getCostingMethod()))
return;
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
MCost cost = MCost.validateCostForCostType(accountSchema, costType, costElement, transaction.getM_Product_ID(), transaction.getAD_Org_ID(), transaction.getM_Warehouse_ID(), transaction.getM_AttributeSetInstance_ID(), transaction.get_TrxName());
// get the cost for positive transaction
if ((MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()) || MCostElement.COSTELEMENTTYPE_LandedCost.equals(costElement.getCostElementType())) && transaction.getMovementType().contains("+") && !MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
if (model instanceof MMovementLine || model instanceof MInventoryLine || (model instanceof MInOutLine && MTransaction.MOVEMENTTYPE_CustomerReturns.equals(transaction.getMovementType()))) {
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
if (model instanceof MInventoryLine) {
MInventoryLine inventoryLine = (MInventoryLine) model;
// try get cost from physical inventory
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
if (costThisLevel.signum() == 0)
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
// try get cost low level from physical inventory
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
}
if (costLowLevel.signum() == 0)
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
}
//Get cost from movement from if it > that zero replace cost This Level
if (model instanceof MMovementLine) {
MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFrom.signum() > 0)
costThisLevel = costMovementFrom;
BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFromLL.signum() > 0)
costLowLevel = costMovementFromLL;
}
} else if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
}
if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
if (model instanceof MPPCostCollector) {
MPPCostCollector costCollector = (MPPCostCollector) model;
if (MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(costCollector.getCostCollectorType())) {
// get Actual Cost for Cost Type and Cost Element
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
costLowLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), costCollector);
}
}
if (model instanceof MProductionLine) {
MProductionLine productionLine = (MProductionLine) model;
if (productionLine.isParent())
costThisLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType, costElement, productionLine.getM_Production());
if (costThisLevel.signum() == 0)
costThisLevel = cost.getCurrentCostPrice();
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
// Material Receipt for Production light
if (productionLine.isParent()) {
// if the product is purchase then no use low level
if (!productionLine.getM_Product().isPurchased()) {
costLowLevel = costThisLevel;
costThisLevel = Env.ZERO;
}
} else if (productionLine.getMovementQty().signum() < 0)
costLowLevel = Env.ZERO;
}
} else if (MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
costThisLevel = cost.getCurrentCostPrice();
costLowLevel = cost.getCurrentCostPriceLL();
//Define Cost Inventory Line
if (model instanceof MInventoryLine) {
MInventoryLine inventoryLine = (MInventoryLine) model;
//Define Current Cost Level
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
cost.setCurrentCostPrice(costThisLevel);
cost.saveEx();
}
if (costThisLevel.signum() == 0)
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
//Define Current Cost Low Level
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
cost.setCurrentCostPriceLL(costLowLevel);
cost.saveEx();
}
if (costLowLevel.signum() == 0)
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
}
if (model instanceof MMovementLine) {
MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (costMovementFrom.signum() > 0)
costThisLevel = costMovementFrom;
}
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFromLL.signum() > 0)
costLowLevel = costMovementFromLL;
}
}
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
if (costThisLevel.signum() == 0)
if (model instanceof MInOutLine && !model.isSOTrx()) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
if (costThisLevel.signum() != 0) {
cost.setCurrentCostPrice(costThisLevel);
cost.saveEx();
}
}
if (costLowLevel.signum() != 0) {
cost.setCurrentCostPriceLL(costLowLevel);
cost.saveEx();
}
}
final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
method.setCostingMethod(accountSchema, transaction, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
method.process();
}
use of org.compiere.model.MMatchPO 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.MMatchPO in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method updateAmountCost.
/**
* Update Cost Amt
*/
public void updateAmountCost() {
if (movementQuantity.signum() > 0) {
costDetail.setCostAmt(costDetail.getAmt().subtract(costDetail.getCostAdjustment()));
costDetail.setCostAmtLL(costDetail.getAmtLL().subtract(costDetail.getCostAdjustmentLL()));
} else if (movementQuantity.signum() < 0) {
costDetail.setCostAmt(costDetail.getAmt().add(adjustCost));
costDetail.setCostAmtLL(costDetail.getAmtLL().add(adjustCostLowerLevel));
}
costDetail.setCumulatedQty(getNewAccumulatedQuantity(lastCostDetail));
costDetail.setCumulatedAmt(getNewAccumulatedAmount(lastCostDetail));
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(currentCostPrice);
costDetail.setCurrentCostPriceLL(currentCostPriceLowerLevel);
// set the id for model
final String idColumnName = CostEngine.getIDColumnName(model);
costDetail.set_ValueOfColumn(idColumnName, CostEngine.getIDColumn(model));
if (model instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) model;
costDetail.setC_OrderLine_ID(ioLine.getC_OrderLine_ID());
// IMPORTANT : reset possible provision purchase cost processed
costDetail.setC_InvoiceLine_ID(0);
}
if (model instanceof MMatchInv && costDetail.getM_InOutLine_ID() == 0) {
MMatchInv iMatch = (MMatchInv) model;
costDetail.setM_InOutLine_ID(iMatch.getM_InOutLine_ID());
}
if (model instanceof MMatchPO && costDetail.getM_InOutLine_ID() == 0) {
MMatchPO poMatch = (MMatchPO) model;
costDetail.setM_InOutLine_ID(poMatch.getM_InOutLine_ID());
}
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costDetail.setM_InOutLine_ID(allocation.getM_InOutLine_ID());
costDetail.setC_InvoiceLine_ID(allocation.getC_InvoiceLine_ID());
costDetail.setC_LandedCostAllocation_ID(allocation.getC_LandedCostAllocation_ID());
costDetail.setProcessed(false);
}
costDetail.saveEx();
}
use of org.compiere.model.MMatchPO in project adempiere by adempiere.
the class AveragePOCostingMethod method updateAmountCost.
/**
* Update Cost Amt
*/
public void updateAmountCost() {
if (movementQuantity.signum() > 0) {
costDetail.setCostAmt(costDetail.getAmt().subtract(costDetail.getCostAdjustment()));
costDetail.setCostAmtLL(costDetail.getAmtLL().subtract(costDetail.getCostAdjustmentLL()));
} else if (movementQuantity.signum() < 0) {
costDetail.setCostAmt(costDetail.getAmt().add(adjustCost));
costDetail.setCostAmtLL(costDetail.getAmtLL().add(adjustCostLowerLevel));
}
costDetail.setCumulatedQty(getNewAccumulatedQuantity(lastCostDetail));
costDetail.setCumulatedAmt(getNewAccumulatedAmount(lastCostDetail));
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(currentCostPrice);
costDetail.setCurrentCostPriceLL(currentCostPriceLowerLevel);
// set the id for model
final String idColumnName = CostEngine.getIDColumnName(model);
costDetail.set_ValueOfColumn(idColumnName, CostEngine.getIDColumn(model));
if (model instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) model;
costDetail.setC_OrderLine_ID(ioLine.getC_OrderLine_ID());
// IMPORTANT : reset possible provision purchase cost processed
costDetail.setC_InvoiceLine_ID(0);
}
if (model instanceof MMatchPO && costDetail.getM_InOutLine_ID() == 0) {
MMatchPO poMatch = (MMatchPO) model;
costDetail.setM_InOutLine_ID(poMatch.getM_InOutLine_ID());
}
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costDetail.setM_InOutLine_ID(allocation.getM_InOutLine_ID());
costDetail.setC_InvoiceLine_ID(allocation.getC_InvoiceLine_ID());
costDetail.setProcessed(false);
}
costDetail.saveEx();
}
Aggregations