use of org.compiere.model.MProduct in project adempiere by adempiere.
the class Doc_InOut method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MMS, MMR.
* <pre>
* Shipment
* CoGS (RevOrg) DR
* Inventory CR
* Shipment of Project Issue
* CoGS DR
* Project CR
* Receipt
* Inventory DR
* NotInvoicedReceipt CR
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
//
ArrayList<Fact> facts = new ArrayList<Fact>();
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
// Line pointers
FactLine dr = null;
FactLine cr = null;
// *** Sales - Shipment
if (getDocumentType().equals(DOCTYPE_MatShipment) && isSOTrx()) {
BigDecimal total = Env.ZERO;
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
BigDecimal costs = null;
MProduct product = line.getProduct();
for (MCostDetail cost : line.getCostDetail(as, false)) {
if (!MCostDetail.existsCost(cost))
continue;
costs = MCostDetail.getTotalCost(cost, as);
total = total.add(costs);
//get costing method for product
String description = cost.getM_CostElement().getName() + " " + cost.getM_CostType().getName();
// CoGS DR
dr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Cogs, as), as.getC_Currency_ID(), costs, null);
if (dr == null) {
p_Error = "FactLine DR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
dr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
dr.setLocationFromLocator(line.getM_Locator_ID(), true);
// to Loc
dr.setLocationFromBPartner(getC_BPartner_Location_ID(), false);
// Revenue X-Org
dr.setAD_Org_ID(line.getOrder_Org_ID());
dr.setM_Product_ID(cost.getM_Product_ID());
dr.setQty(cost.getQty().negate());
dr.addDescription(description);
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Shipment/Receipt
if (!dr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty().negate(), Env.ONE.negate())) {
p_Error = "Original Shipment/Receipt not posted yet";
return null;
}
}
// Inventory CR
cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), null, costs);
if (cr == null) {
p_Error = "FactLine CR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
cr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
cr.setLocationFromLocator(line.getM_Locator_ID(), true);
// to Loc
cr.setLocationFromBPartner(getC_BPartner_Location_ID(), false);
cr.addDescription(description);
cr.setM_Product_ID(cost.getM_Product_ID());
cr.setQty(cost.getQty());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctCr from Original Shipment/Receipt
if (!cr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty(), Env.ONE.negate())) {
p_Error = "Original Shipment/Receipt not posted yet";
return null;
}
//get original cost
costs = cr.getAcctBalance();
}
}
// costing elements
if (// zero costs OK
total == null || total.signum() == 0) {
/*if (product.isStocked())
{
p_Error = "No Costs for " + line.getProduct().getName();
log.log(Level.WARNING, p_Error);
return null;
}
else // ignore service
continue;
*/
}
}
/** Commitment release ****/
if (as.isAccrual() && as.isCreateSOCommitment()) {
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
BigDecimal multiplier = Env.ONE.negate();
if (m_Reversal_ID != 0 && m_Reversal_ID < get_ID())
multiplier = multiplier.negate();
Fact factcomm = Doc_Order.getCommitmentSalesRelease(as, this, line.getQty(), line.get_ID(), multiplier);
if (factcomm != null)
facts.add(factcomm);
}
}
// Commitment
} else // *** Sales - Return
if (getDocumentType().equals(DOCTYPE_MatReceipt) && isSOTrx()) {
BigDecimal total = Env.ZERO;
for (int i = 0; i < p_lines.length; i++) {
DocLine line = p_lines[i];
BigDecimal costs = null;
MProduct product = line.getProduct();
for (MCostDetail cost : line.getCostDetail(as, false)) {
if (!MCostDetail.existsCost(cost))
continue;
costs = MCostDetail.getTotalCost(cost, as);
total = total.add(costs);
String description = cost.getM_CostElement().getName() + " " + cost.getM_CostType().getName();
// Inventory DR
dr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), costs, null);
if (dr == null) {
p_Error = "FactLine DR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
dr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
dr.setLocationFromLocator(line.getM_Locator_ID(), true);
// to Loc
dr.setLocationFromBPartner(getC_BPartner_Location_ID(), false);
dr.addDescription(description);
dr.setM_Product_ID(cost.getM_Product_ID());
dr.setQty(cost.getQty());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Shipment/Receipt
if (!dr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty(), Env.ONE.negate())) {
p_Error = "Original Shipment/Receipt not posted yet";
return null;
}
//get original cost
costs = dr.getAcctBalance();
}
// CoGS CR
cr = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Cogs, as), as.getC_Currency_ID(), null, costs);
if (cr == null) {
p_Error = "FactLine CR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
cr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
cr.setLocationFromLocator(line.getM_Locator_ID(), true);
// to Loc
cr.setLocationFromBPartner(getC_BPartner_Location_ID(), false);
// Revenue X-Org
cr.setAD_Org_ID(line.getOrder_Org_ID());
cr.setM_Product_ID(cost.getM_Product_ID());
cr.setQty(cost.getQty().negate());
cr.addDescription(description);
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctCr from Original Shipment/Receipt
if (!cr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty().negate(), Env.ONE.negate())) {
p_Error = "Original Shipment/Receipt not posted yet";
return null;
}
}
}
if (// zero costs OK
total == null || total.signum() == 0) {
/*if (product.isStocked())
{
p_Error = "No Costs for " + line.getProduct().getName();
log.log(Level.WARNING, p_Error);
return null;
}
else // ignore service
continue;
*/
}
}
// for all lines
} else // *** Purchasing - Receipt
if (getDocumentType().equals(DOCTYPE_MatReceipt) && !isSOTrx()) {
BigDecimal total = Env.ZERO;
for (int i = 0; i < p_lines.length; i++) {
int C_Currency_ID = as.getC_Currency_ID();
//
DocLine line = p_lines[i];
BigDecimal costs = null;
MProduct product = line.getProduct();
for (MCostDetail cost : line.getCostDetail(as, true)) {
if (!MCostDetail.existsCost(cost))
continue;
costs = MCostDetail.getTotalCost(cost, as);
total = total.add(costs);
String description = cost.getM_CostElement().getName() + " " + cost.getM_CostType().getName();
// Inventory/Asset DR
MAccount assets = line.getAccount(ProductCost.ACCTTYPE_P_Asset, as);
if (product.isService()) {
//if the line is a Outside Processing then DR WIP
if (line.getPP_Cost_Collector_ID() > 0)
assets = line.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, as);
else
assets = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
}
dr = fact.createLine(line, assets, C_Currency_ID, costs, null);
dr.addDescription(description);
//
if (dr == null) {
p_Error = "DR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
dr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
dr.setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
dr.setLocationFromLocator(line.getM_Locator_ID(), false);
dr.setM_Product_ID(cost.getM_Product_ID());
dr.setQty(cost.getQty());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Shipment/Receipt
if (!dr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty(), Env.ONE.negate())) {
p_Error = "Original Receipt not posted yet";
return null;
}
}
cr = fact.createLine(line, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), C_Currency_ID, null, costs);
cr.addDescription(description);
//
if (cr == null) {
p_Error = "CR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
cr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
cr.setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
cr.setLocationFromLocator(line.getM_Locator_ID(), false);
cr.setM_Product_ID(cost.getM_Product_ID());
cr.setQty(cost.getQty().negate());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctCr from Original Shipment/Receipt
if (!cr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty().negate(), Env.ONE.negate())) {
p_Error = "Original Receipt not posted yet";
return null;
}
}
cost.setProcessed(true);
cost.saveEx();
}
/*if (total == null || total.signum() == 0)
{
p_Error = "Resubmit - No Costs for " + product.getName();
log.log(Level.WARNING, p_Error);
return null;
}*/
}
} else // *** Purchasing - return
if (getDocumentType().equals(DOCTYPE_MatShipment) && !isSOTrx()) {
BigDecimal total = Env.ZERO;
for (int i = 0; i < p_lines.length; i++) {
int C_Currency_ID = as.getC_Currency_ID();
//
DocLine line = p_lines[i];
BigDecimal costs = null;
MProduct product = line.getProduct();
for (MCostDetail cost : line.getCostDetail(as, true)) {
if (!MCostDetail.existsCost(cost))
continue;
costs = MCostDetail.getTotalCost(cost, as);
total = total.add(costs);
String description = cost.getM_CostElement().getName() + " " + cost.getM_CostType().getName();
dr = fact.createLine(line, getAccount(Doc.ACCTTYPE_NotInvoicedReceipts, as), C_Currency_ID, costs, null);
dr.addDescription(description);
//
if (dr == null) {
p_Error = "CR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
dr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
dr.setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
dr.setLocationFromLocator(line.getM_Locator_ID(), false);
dr.setM_Product_ID(cost.getM_Product_ID());
dr.setQty(cost.getQty().negate());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Shipment/Receipt
if (!dr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty().negate(), Env.ONE.negate())) {
p_Error = "Original Receipt not posted yet";
return null;
}
}
// Inventory/Asset CR
MAccount assets = line.getAccount(ProductCost.ACCTTYPE_P_Asset, as);
if (product.isService())
assets = line.getAccount(ProductCost.ACCTTYPE_P_Expense, as);
cr = fact.createLine(line, assets, C_Currency_ID, null, costs);
//
if (cr == null) {
p_Error = "DR not created: " + line;
log.log(Level.WARNING, p_Error);
return null;
}
cr.setM_Locator_ID(line.getM_Locator_ID());
// from Loc
cr.setLocationFromBPartner(getC_BPartner_Location_ID(), true);
// to Loc
cr.setLocationFromLocator(line.getM_Locator_ID(), false);
cr.addDescription(description);
cr.setM_Product_ID(cost.getM_Product_ID());
cr.setQty(cost.getQty());
if (m_DocStatus.equals(MInOut.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctCr from Original Shipment/Receipt
if (!cr.updateReverseLine(MInOut.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), cost.getQty(), Env.ONE.negate())) {
p_Error = "Original Receipt not posted yet";
return null;
}
}
}
/*if (total == null || total.signum() == 0)
{
p_Error = "Resubmit - No Costs for " + product.getName();
log.log(Level.WARNING, p_Error);
return null;
}*/
}
} else // Purchasing Return
{
p_Error = "DocumentType unknown: " + getDocumentType();
log.log(Level.SEVERE, p_Error);
return null;
}
//
facts.add(fact);
return facts;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class Doc_Production method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MMP.
* <pre>
* Production
* Inventory DR CR
* </pre>
* @param as account schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
// Line pointer
FactLine factLine = null;
BigDecimal total = Env.ZERO;
DocLine parentProductionLine = null;
for (DocLine line : p_lines) {
MProduct product = line.getProduct();
if (line.isProductionBOM())
parentProductionLine = line;
if (X_M_Product.PRODUCTTYPE_Item.equals(product.getProductType())) {
BigDecimal totalCosts = Env.ZERO;
BigDecimal qty = line.getQty();
BigDecimal costTransaction = Env.ZERO;
for (MCostDetail cost : line.getCostDetail(as, false)) {
if (!MCostDetail.existsCost(cost))
continue;
costTransaction = MCostDetail.getTotalCost(cost, as);
totalCosts = totalCosts.add(costTransaction);
}
if (qty.signum() < 0)
totalCosts = totalCosts.negate();
total = total.add(totalCosts);
factLine = fact.createLine(line, line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), line.getAccount(ProductCost.ACCTTYPE_P_Asset, as), as.getC_Currency_ID(), totalCosts);
factLine.setM_Product_ID(line.getM_Product_ID());
factLine.setM_Locator_ID(line.getM_LocatorTo_ID());
factLine.setDescription("");
factLine.saveEx();
} else if (!X_M_Product.PRODUCTTYPE_Item.equals(product.getProductType())) {
BigDecimal totalCosts = Env.ZERO;
MAccount acct = null;
for (MCostElement costElement : MCostElement.getCostElement(line.getCtx(), line.getTrxName())) {
if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(costElement.getCostElementType()))
acct = line.getAccount(ProductCost.ACCTTYPE_P_Burden, as);
else if (MCostElement.COSTELEMENTTYPE_OutsideProcessing.equals(costElement.getCostElementType()))
acct = line.getAccount(ProductCost.ACCTTYPE_P_OutsideProcessing, as);
else if (MCostElement.COSTELEMENTTYPE_Overhead.equals(costElement.getCostElementType()))
acct = line.getAccount(ProductCost.ACCTTYPE_P_Overhead, as);
else if (MCostElement.COSTELEMENTTYPE_Resource.equals(costElement.getCostElementType()))
acct = line.getAccount(ProductCost.ACCTTYPE_P_Labor, as);
else
acct = line.getAccount(ProductCost.ACCTTYPE_P_OutsideProcessing, as);
int warehouseId = DB.getSQLValue(line.getTrxName(), "SELECT M_Warehouse_ID from M_Locator WHERE M_Locator_ID=?", line.getM_Locator_ID());
BigDecimal costTransaction = Env.ZERO;
MCost costDimension = MCost.validateCostForCostType(as, (MCostType) as.getM_CostType(), costElement, product.getM_Product_ID(), line.getAD_Org_ID(), warehouseId, line.getM_AttributeSetInstance_ID(), line.getTrxName());
if (costDimension != null)
costTransaction = costDimension.getCurrentCostPrice().add(costDimension.getCurrentCostPriceLL());
totalCosts = totalCosts.add(costTransaction.multiply(line.getQty()));
}
factLine = fact.createLine(line, acct, acct, as.getC_Currency_ID(), totalCosts);
factLine.setM_Product_ID(line.getM_Product_ID());
factLine.setM_Locator_ID(line.getM_LocatorTo_ID());
if (m_DocStatus.equals(MProduction.DOCSTATUS_Reversed) && m_Reversal_ID != 0 && line.getReversalLine_ID() != 0) {
// Set AmtAcctDr from Original Phys.Inventory
if (!factLine.updateReverseLine(MProduction.Table_ID, m_Reversal_ID, line.getReversalLine_ID(), line.getQty(), Env.ONE)) {
p_Error = "Original Physical Inventory not posted yet";
return null;
}
}
factLine.setDescription("");
factLine.saveEx();
total = total.add(totalCosts);
}
}
// When total no is zero then create an adjustment cost , can happen when of resource rate was changes from original cost finish good
if (total.signum() != 0) {
factLine = fact.createLine(parentProductionLine, parentProductionLine.getAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as), as.getC_Currency_ID(), total);
factLine.setM_Product_ID(parentProductionLine.getM_Product_ID());
factLine.setM_Locator_ID(parentProductionLine.getM_LocatorTo_ID());
factLine.setDescription(" Adjustment Cost");
factLine.saveEx();
}
ArrayList<Fact> facts = new ArrayList<Fact>();
facts.add(fact);
return facts;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class Doc_MatchPO method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MXP.
* <pre>
* Product PPV <difference>
* PPV_Offset <difference>
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
ArrayList<Fact> facts = new ArrayList<Fact>();
//
if (// Nothing to do if no Product
getM_Product_ID() == 0 || getQty().signum() == 0 || // No posting if not matched to Shipment
m_M_InOutLine_ID == 0) {
log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty());
return facts;
}
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
boolean isInterOrg = isInterOrg(as);
// Purchase Order Line
BigDecimal poCost = m_oLine.getPriceCost();
if (poCost == null || poCost.signum() == 0)
poCost = m_oLine.getPriceActual();
MInOutLine receiptLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
MInOut inOut = receiptLine.getParent();
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
// calculate po cost
// Delivered so far
poCost = poCost.multiply(getQty());
// Different currency
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) {
MOrder order = m_oLine.getParent();
Timestamp dateAcct = order.getDateAcct();
BigDecimal rate = MConversionRate.getRate(order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), m_oLine.getAD_Client_ID(), m_oLine.getAD_Org_ID());
if (rate == null) {
p_Error = "Purchase Order not convertible - " + as.getName();
return null;
}
poCost = poCost.multiply(rate);
if (poCost.scale() > as.getCostingPrecision())
poCost = poCost.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
// Calculate PPV for standard costing
//get standard cost and also make sure cost for other costing method is updated
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
String costingMethod = ct.getCostingMethod();
MInOutLine ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
BigDecimal costs = Env.ZERO;
for (MTransaction transaction : MTransaction.getByInOutLine(ioLine)) {
MCostElement element = MCostElement.getByMaterialCostElementType(transaction);
MCostDetail cd = MCostDetail.getByTransaction(ioLine, transaction, as.getC_AcctSchema_ID(), ct.getM_CostType_ID(), element.getM_CostElement_ID());
if (cd != null)
costs = costs.add(MCostDetail.getTotalCost(cd, as));
}
if (MCostType.COSTINGMETHOD_StandardCosting.equals(costingMethod)) {
// No Costs yet - no PPV
if (costs == null || costs.signum() == 0) {
// TODO make these a translatable message
p_Error = "No Standard Cost information was found for " + product.getName() + ". Please add a standard cost for material and repost this document.";
log.log(Level.SEVERE, p_Error);
return null;
}
// Difference
BigDecimal difference = poCost.subtract(costs.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP));
// Nothing to post
if (difference.signum() == 0) {
log.log(Level.FINE, "No Cost Difference for M_Product_ID=" + getM_Product_ID());
return facts;
}
// Product PPV
FactLine cr = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
if (cr != null) {
cr.setQty(isReturnTrx ? getQty().negate() : getQty());
cr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
cr.setC_Activity_ID(m_oLine.getC_Activity_ID());
cr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
cr.setC_Project_ID(m_oLine.getC_Project_ID());
cr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
cr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
cr.setC_UOM_ID(m_oLine.getC_UOM_ID());
cr.setUser1_ID(m_oLine.getUser1_ID());
cr.setUser2_ID(m_oLine.getUser2_ID());
cr.setUser3_ID(m_oLine.getUser3_ID());
cr.setUser4_ID(m_oLine.getUser4_ID());
}
// PPV Offset
FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
if (dr != null) {
dr.setQty(isReturnTrx ? getQty() : getQty().negate());
dr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
dr.setC_Activity_ID(m_oLine.getC_Activity_ID());
dr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
dr.setC_Project_ID(m_oLine.getC_Project_ID());
dr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
dr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
dr.setC_UOM_ID(m_oLine.getC_UOM_ID());
dr.setUser1_ID(m_oLine.getUser1_ID());
dr.setUser2_ID(m_oLine.getUser2_ID());
dr.setUser3_ID(m_oLine.getUser3_ID());
dr.setUser4_ID(m_oLine.getUser4_ID());
}
// Avoid usage of clearing accounts
// If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
// then remove the posting
// PPV
MAccount acct_db = dr.getAccount();
// PPV Offset
MAccount acct_cr = cr.getAccount();
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr();
if (debit.compareTo(credit) == 0) {
fact.remove(dr);
fact.remove(cr);
}
}
// End Avoid usage of clearing accounts
//
facts.add(fact);
return facts;
} else {
return facts;
}
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class ProductLowLevelCalculator method icomponent.
/**
* get an implotion the product
* @param ID Product
* @param ID BOM
* @return DefaultMutableTreeNode Tree with all parent product
*/
private DefaultMutableTreeNode icomponent(int AD_Client_ID, int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom) {
final String sql = "SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml" + " INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)" + " WHERE pbom.IsActive=? AND pboml.IsActive=? AND pboml.AD_Client_ID=? AND pboml.PP_Product_BOMLine_ID=? ";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, m_trxName);
DB.setParameters(pstmt, new Object[] { true, true, AD_Client_ID, PP_Product_BOMLine_ID });
rs = pstmt.executeQuery();
while (rs.next()) {
if (M_Product_ID != rs.getInt(1)) {
//BOM Loop Error
if (!tableproduct(rs.getInt(1), rs.getInt(3))) {
bom.add(iparent(AD_Client_ID, rs.getInt(1), rs.getInt(3)));
} else {
throw new AdempiereException("Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")");
}
} else {
//Child = Parent error
MProduct product = MProduct.get(m_ctx, M_Product_ID);
throw new AdempiereException("Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")" + " - Component: " + product.getValue() + "(" + product.getM_Product_ID() + ")");
}
}
} catch (SQLException e) {
throw new DBException(e, sql);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return null;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class myJTree method addChild.
// action_fillTree
public void addChild(MProductBOM bomline, DefaultMutableTreeNode parent) {
//System.out.println("-------------------------Parent:" + bom.getName());
MProduct M_Product = MProduct.get(getCtx(), bomline.getM_ProductBOM_ID());
Vector<Object> line = new Vector<Object>(17);
// 0 Select
line.add(new Boolean(false));
// 1 IsActive
line.add(new Boolean(bomline.isActive()));
// 2 Line
line.add(new Integer(bomline.getLine()));
KeyNamePair pp = new KeyNamePair(M_Product.getM_Product_ID(), M_Product.getValue().concat("_").concat(M_Product.getName()));
// 3 M_Product_ID
line.add(pp);
MUOM u = new MUOM(M_Product.getCtx(), M_Product.getC_UOM_ID(), M_Product.get_TrxName());
KeyNamePair uom = new KeyNamePair(M_Product.getC_UOM_ID(), u.getUOMSymbol());
// 4 C_UOM_ID
line.add(uom);
// 5 QtyBOM
line.add((BigDecimal) ((bomline.getBOMQty() != null) ? bomline.getBOMQty() : new BigDecimal(0)));
DefaultMutableTreeNode child = new DefaultMutableTreeNode(line);
parent.add(child);
if (m_selected_id == bomline.getM_Product_ID() || getM_Product_ID() == bomline.getM_Product_ID())
dataBOM.add(line);
if (reload)
return;
for (MProductBOM bom : getChildBOMs(bomline.getM_ProductBOM_ID(), false)) {
addChild(bom, child);
}
}
Aggregations