use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class CreateCostElement method doIt.
// prepare
protected String doIt() throws Exception {
MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
int count_costs = 0, count_all = 0;
for (final int org_id : getOrgs(as)) {
for (final int product_id : getProduct_IDs()) {
for (final MCostElement element : getElements()) {
MProduct product = MProduct.get(getCtx(), product_id);
MCost.getOrCreate(product, 0, as, org_id, 0, as.getM_CostType_ID(), element.getM_CostElement_ID());
count_all++;
}
}
}
return "@Created@ #" + count_costs + " / " + count_all;
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class FifoLifoCostingMethod method processCostDetail.
// need this for reversal documents
public void processCostDetail(MCostDetail costDetail) {
boolean addition = costDetail.getQty().signum() > 0;
MAcctSchema as = MAcctSchema.get(costDetail.getCtx(), costDetail.getC_AcctSchema_ID());
int precision = as.getCostingPrecision();
MProduct product = MProduct.get(costDetail.getCtx(), costDetail.getM_Product_ID());
BigDecimal price = costDetail.getAmt();
if (costDetail.getQty().signum() != 0)
price = costDetail.getAmt().divide(costDetail.getQty(), precision, BigDecimal.ROUND_HALF_UP);
int AD_Org_ID = costDetail.getAD_Org_ID();
int M_ASI_ID = costDetail.getM_AttributeSetInstance_ID();
if (costDetail.getC_OrderLine_ID() != 0 && !(model.getReversalLine_ID() > 0)) {
log.finer("Inv - FiFo/LiFo - amt=" + costDetail.getAmt() + ", qty=" + costDetail.getQty() + " [NOTHING TO DO]");
} else if (// AR Shipment Detail Record
costDetail.getM_InOutLine_ID() != 0 || costDetail.getM_MovementLine_ID() != 0 || costDetail.getM_InventoryLine_ID() != 0 || costDetail.getM_ProductionLine_ID() != 0 || costDetail.getC_ProjectIssue_ID() != 0 || costDetail.getPP_Cost_Collector_ID() != 0 || costDetail.getC_LandedCostAllocation_ID() != 0) {
if (addition) {
MCostQueue.add(product, M_ASI_ID, as, AD_Org_ID, costDetail.getM_CostElement_ID(), costDetail.getAmt(), costDetail.getQty(), precision, (MCostDetail) costDetail, costDetail.get_TrxName());
} else {
BigDecimal amtQueue = MCostQueue.adjustQty(dimension, costDetail.getQty().negate(), costDetail.getDateAcct(), costDetail.get_TrxName());
// outgoing amt should be negative
amtQueue = amtQueue.negate();
if (costDetail.getAmt().compareTo(amtQueue) != 0) {
BigDecimal priceQueue = Env.ZERO;
if (costDetail.getQty().signum() != 0)
priceQueue = amtQueue.divide(costDetail.getQty(), precision, BigDecimal.ROUND_HALF_UP);
log.warning("Amt not match " + this + ": price=" + price + ", priceQueue=" + priceQueue + " [ADJUSTED]");
// FIXME: teo_sarca: should not happen
if ("Y".equals(Env.getContext(costDetail.getCtx(), "#M_CostDetail_CorrectAmt"))) {
costDetail.setAmt(amtQueue);
costDetail.setAmt(amtQueue);
costDetail.setPrice(priceQueue);
} else {
throw new AdempiereException("Amt not match " + this + ": price=" + price + ", priceQueue=" + priceQueue);
}
}
}
costDetail.setCumulatedQty(dimension.getCumulatedQty());
costDetail.setCumulatedAmt(dimension.getCumulatedQty());
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(dimension.getCurrentCostPrice());
updateCurrentCost(costDetail);
costDetail.saveEx();
this.costDetail = costDetail;
}
}
use of org.compiere.model.MAcctSchema 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);
}
}
}
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class CostEngine method createCostDetail.
/**
* Generate by transaction
* @param transaction
*/
public void createCostDetail(MTransaction transaction, IDocumentLine model) {
MClient client = new MClient(transaction.getCtx(), transaction.getAD_Client_ID(), transaction.get_TrxName());
StringBuilder description = new StringBuilder();
if (model != null && model.getDescription() != null && !Util.isEmpty(model.getDescription(), true))
description.append(model.getDescription());
if (model != null) {
description.append(model.isSOTrx() ? "(|->)" : "(|<-)");
}
List<MAcctSchema> acctSchemas = new ArrayList(Arrays.asList(MAcctSchema.getClientAcctSchema(transaction.getCtx(), transaction.getAD_Client_ID(), transaction.get_TrxName())));
List<MCostElement> costElements = MCostElement.getCostElement(transaction.getCtx(), transaction.get_TrxName());
List<MCostType> costTypes = MCostType.get(transaction.getCtx(), transaction.get_TrxName());
for (MAcctSchema accountSchema : acctSchemas) {
for (MCostType costType : costTypes) {
if (!costType.isActive())
continue;
for (MCostElement costElement : costElements) {
createCostDetail(accountSchema, costType, costElement, transaction, model, client.isCostImmediate());
}
}
}
}
use of org.compiere.model.MAcctSchema in project adempiere by adempiere.
the class AveragePOCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param costDetail
*/
public void adjustCostDetail(MCostDetail costDetail) {
Properties ctx = costDetail.getCtx();
String trxName = costDetail.get_TrxName();
int transactionId = costDetail.getM_Transaction_ID();
int clientId = costDetail.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) costDetail.getM_CostType();
MCostElement costElement = (MCostElement) costDetail.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) costDetail.getC_AcctSchema();
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0 && costDetail.getC_OrderLine_ID() > 0) {
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
} else if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() == 0 && costDetail.getC_OrderLine_ID() > 0) {
List<MMatchPO> poMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : poMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
for (MLandedCostAllocation allocation : MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID())) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
Aggregations