use of org.compiere.model.MTransaction 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);
}
use of org.compiere.model.MTransaction in project adempiere by adempiere.
the class AveragePOCostingMethod 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;
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();
}
use of org.compiere.model.MTransaction in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
Properties ctx = cost.getCtx();
String trxName = cost.get_TrxName();
int transactionId = cost.getM_Transaction_ID();
int clientId = cost.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) cost.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 (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0 && cost.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 (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() == 0 && cost.getC_InvoiceLine_ID() > 0 && cost.getC_LandedCostAllocation_ID() == 0) {
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
// only own allocation
if (cost.getC_LandedCostAllocation_ID() != 0) {
MLandedCostAllocation allocation = (MLandedCostAllocation) cost.getC_LandedCostAllocation();
{
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
use of org.compiere.model.MTransaction in project adempiere by adempiere.
the class AbstractCostingMethod method clearAccounting.
public void clearAccounting(MCostDetail cost) {
// Only can delete if period is open
MTransaction trx = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
IDocumentLine documentLine = trx.getDocumentLine();
MDocType docType = MDocType.get(cost.getCtx(), documentLine.getC_DocType_ID());
Boolean openPeriod = MPeriod.isOpen(cost.getCtx(), cost.getDateAcct(), docType.getDocBaseType(), cost.getAD_Org_ID());
if (!openPeriod)
return;
String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
int tableId = 0;
int recordId = 0;
if (cost.getC_OrderLine_ID() != 0) {
MOrderLine line = (MOrderLine) cost.getC_OrderLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InOutLine_ID() != 0) {
MInOutLine line = (MInOutLine) cost.getM_InOutLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InventoryLine_ID() != 0) {
MInventoryLine line = (MInventoryLine) cost.getM_InventoryLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_MovementLine_ID() != 0) {
MMovementLine line = (MMovementLine) cost.getM_MovementLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_ProductionLine_ID() != 0) {
}
if (cost.getPP_Cost_Collector_ID() != 0) {
MPPCostCollector costCollector = (MPPCostCollector) cost.getPP_Cost_Collector();
costCollector.setPosted(false);
costCollector.saveEx();
recordId = costCollector.get_ID();
tableId = costCollector.get_Table_ID();
}
int no = DB.executeUpdateEx(sqldelete, new Object[] { recordId, tableId }, cost.get_TrxName());
}
use of org.compiere.model.MTransaction in project adempiere by adempiere.
the class AbstractCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MTransaction transaction = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
IDocumentLine docLine = transaction.getDocumentLine();
CostEngineFactory.getCostEngine(cost.getAD_Client_ID()).createCostDetail((MAcctSchema) cost.getC_AcctSchema(), costType, costElement, transaction, docLine, true);
}
Aggregations