diff --git a/base/src/org/compiere/acct/DocLine.java b/base/src/org/compiere/acct/DocLine.java index 2356a124a8..69a2f4f75a 100644 --- a/base/src/org/compiere/acct/DocLine.java +++ b/base/src/org/compiere/acct/DocLine.java @@ -703,7 +703,7 @@ public class DocLine if (whereClause != null) { MCostDetail cd = MCostDetail.get (Env.getCtx(), whereClause, - get_ID(), getM_AttributeSetInstance_ID(), p_po.get_TrxName()); + get_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), p_po.get_TrxName()); if (cd != null) return cd.getAmt(); } diff --git a/base/src/org/compiere/acct/Doc_InOut.java b/base/src/org/compiere/acct/Doc_InOut.java index f8550241fb..6438f428a9 100644 --- a/base/src/org/compiere/acct/Doc_InOut.java +++ b/base/src/org/compiere/acct/Doc_InOut.java @@ -151,7 +151,7 @@ public class Doc_InOut extends Doc DocLine line = p_lines[i]; // MZ Goodwill // if Shipment CostDetail exist then get Cost from Cost Detail - BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=? AND M_AttributeSetInstance_ID=?"); + BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=?"); // end MZ if (costs == null || costs.signum() == 0) // zero costs OK { @@ -251,7 +251,7 @@ public class Doc_InOut extends Doc DocLine line = p_lines[i]; // MZ Goodwill // if Shipment CostDetail exist then get Cost from Cost Detail - BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=? AND M_AttributeSetInstance_ID=?"); + BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=?"); // end MZ if (costs == null || costs.signum() == 0) // zero costs OK diff --git a/base/src/org/compiere/acct/Doc_Inventory.java b/base/src/org/compiere/acct/Doc_Inventory.java index 6d9aeb1580..b21c7c4c00 100644 --- a/base/src/org/compiere/acct/Doc_Inventory.java +++ b/base/src/org/compiere/acct/Doc_Inventory.java @@ -143,7 +143,7 @@ public class Doc_Inventory extends Doc DocLine line = p_lines[i]; // MZ Goodwill // if Physical Inventory CostDetail is exist then get Cost from Cost Detail - BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InventoryLine_ID=? AND M_AttributeSetInstance_ID=?"); + BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InventoryLine_ID=?"); // end MZ if (costs == null || costs.signum() == 0) { diff --git a/base/src/org/compiere/acct/Doc_Movement.java b/base/src/org/compiere/acct/Doc_Movement.java index 9b55207424..b4f716251f 100644 --- a/base/src/org/compiere/acct/Doc_Movement.java +++ b/base/src/org/compiere/acct/Doc_Movement.java @@ -129,7 +129,7 @@ public class Doc_Movement extends Doc DocLine line = p_lines[i]; // MZ Goodwill // if Inventory Move CostDetail exist then get Cost from Cost Detail - BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_MovementLine_ID=? AND M_AttributeSetInstance_ID=? AND IsSOTrx='N'"); + BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_MovementLine_ID=? AND IsSOTrx='N'"); // end MZ // ** Inventory DR CR diff --git a/base/src/org/compiere/acct/Doc_Production.java b/base/src/org/compiere/acct/Doc_Production.java index 57349ddc6d..64c386ca47 100644 --- a/base/src/org/compiere/acct/Doc_Production.java +++ b/base/src/org/compiere/acct/Doc_Production.java @@ -170,8 +170,8 @@ public class Doc_Production extends Doc // MZ Goodwill // if Production CostDetail exist then get Cost from Cost Detail - MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=? AND M_AttributeSetInstance_ID=?", - line.get_ID(), line.getM_AttributeSetInstance_ID(), getTrxName()); + MCostDetail cd = MCostDetail.get (as.getCtx(), "M_ProductionLine_ID=?", + line.get_ID(), line.getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), getTrxName()); if (cd != null) costs = cd.getAmt(); else diff --git a/base/src/org/compiere/model/MCostDetail.java b/base/src/org/compiere/model/MCostDetail.java index c19c28baed..e8979e5b8d 100644 --- a/base/src/org/compiere/model/MCostDetail.java +++ b/base/src/org/compiere/model/MCostDetail.java @@ -30,7 +30,10 @@ import org.compiere.util.Env; * Cost Detail Model * * @author Jorg Janke + * @author Armen Rizal & Bayu Cahya + *
  • BF [ 2129781 ] Cost Detail not created properly for multi acc schema * @version $Id: MCostDetail.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $ + * */ public class MCostDetail extends X_M_CostDetail { @@ -61,12 +64,13 @@ public class MCostDetail extends X_M_CostDetail String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND C_OrderLine_ID=" + C_OrderLine_ID + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "C_OrderLine_ID=? AND M_AttributeSetInstance_ID=?", - C_OrderLine_ID, M_AttributeSetInstance_ID, trxName); + MCostDetail cd = get (as.getCtx(), "C_OrderLine_ID=?", + C_OrderLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -129,12 +133,13 @@ public class MCostDetail extends X_M_CostDetail String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND C_InvoiceLine_ID=" + C_InvoiceLine_ID + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "C_InvoiceLine_ID=? AND M_AttributeSetInstance_ID=?", - C_InvoiceLine_ID, M_AttributeSetInstance_ID, trxName); + MCostDetail cd = get (as.getCtx(), "C_InvoiceLine_ID=?", + C_InvoiceLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -197,12 +202,13 @@ public class MCostDetail extends X_M_CostDetail String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND M_InOutLine_ID=" + M_InOutLine_ID + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "M_InOutLine_ID=? AND M_AttributeSetInstance_ID=?", - M_InOutLine_ID, M_AttributeSetInstance_ID, trxName); + MCostDetail cd = get (as.getCtx(), "M_InOutLine_ID=?", + M_InOutLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -265,12 +271,13 @@ public class MCostDetail extends X_M_CostDetail String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND M_InventoryLine_ID=" + M_InventoryLine_ID + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "M_InventoryLine_ID=? AND M_AttributeSetInstance_ID=?", - M_InventoryLine_ID, M_AttributeSetInstance_ID, trxName); + MCostDetail cd = get (as.getCtx(), "M_InventoryLine_ID=?", + M_InventoryLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -334,13 +341,14 @@ public class MCostDetail extends X_M_CostDetail + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND M_MovementLine_ID=" + M_MovementLine_ID + " AND IsSOTrx=" + (from ? "'Y'" : "'N'") + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "M_MovementLine_ID=? AND M_AttributeSetInstance_ID=? AND IsSOTrx=" + MCostDetail cd = get (as.getCtx(), "M_MovementLine_ID=? AND IsSOTrx=" + (from ? "'Y'" : "'N'"), - M_MovementLine_ID, M_AttributeSetInstance_ID, trxName); + M_MovementLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -403,12 +411,13 @@ public class MCostDetail extends X_M_CostDetail String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND M_ProductionLine_ID=" + M_ProductionLine_ID + + " AND C_AcctSchema_ID =" + as.getC_AcctSchema_ID() + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; int no = DB.executeUpdate(sql, trxName); if (no != 0) s_log.config("Deleted #" + no); - MCostDetail cd = get (as.getCtx(), "M_ProductionLine_ID=? AND M_AttributeSetInstance_ID=?", - M_ProductionLine_ID, M_AttributeSetInstance_ID, trxName); + MCostDetail cd = get (as.getCtx(), "M_ProductionLine_ID=?", + M_ProductionLine_ID, M_AttributeSetInstance_ID, as.getC_AcctSchema_ID(), trxName); // if (cd == null) // createNew { @@ -456,9 +465,11 @@ public class MCostDetail extends X_M_CostDetail * @return cost detail */ public static MCostDetail get (Properties ctx, String whereClause, - int ID, int M_AttributeSetInstance_ID, String trxName) + int ID, int M_AttributeSetInstance_ID, int C_AcctSchema_ID, String trxName) { - String sql = "SELECT * FROM M_CostDetail WHERE " + whereClause; + String sql = "SELECT * FROM M_CostDetail WHERE " + whereClause + + " AND M_AttributeSetInstance_ID=?" + + " AND C_AcctSchema_ID=?"; MCostDetail retValue = null; PreparedStatement pstmt = null; try @@ -466,6 +477,7 @@ public class MCostDetail extends X_M_CostDetail pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, ID); pstmt.setInt (2, M_AttributeSetInstance_ID); + pstmt.setInt (3, C_AcctSchema_ID); ResultSet rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MCostDetail (ctx, rs, trxName); diff --git a/base/src/org/compiere/model/MInvoice.java b/base/src/org/compiere/model/MInvoice.java index 625addb824..8174982e07 100644 --- a/base/src/org/compiere/model/MInvoice.java +++ b/base/src/org/compiere/model/MInvoice.java @@ -1791,7 +1791,12 @@ public class MInvoice extends X_C_Invoice implements DocAction return DocAction.STATUS_Invalid; } else - matchInv++; + matchInv++; + + // Elaine 2008/6/20 + String err = createMatchInvCostDetail(inv, line, receiptLine); + if(err != null && err.length() > 0) return err; + // } } // for all lines if (matchInv > 0) @@ -1918,7 +1923,92 @@ public class MInvoice extends X_C_Invoice implements DocAction setProcessed(true); setDocAction(DOCACTION_Close); return DocAction.STATUS_Completed; - } // completeIt + } // completeIt + + // Elaine 2008/6/20 + private String createMatchInvCostDetail(MMatchInv inv, MInvoiceLine m_invoiceLine, MInOutLine m_receiptLine) + { + // Get Account Schemas to create MCostDetail + MAcctSchema[] acctschemas = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()); + for(int asn = 0; asn < acctschemas.length; asn++) + { + MAcctSchema as = acctschemas[asn]; + + boolean skip = false; + if (as.getAD_OrgOnly_ID() != 0) + { + if (as.getOnlyOrgs() == null) + as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), + 0, MAcctSchemaElement.ELEMENTTYPE_Organization, + as.getAD_OrgOnly_ID())); + + // Header Level Org + skip = as.isSkipOrg(getAD_Org_ID()); + // Line Level Org + skip = as.isSkipOrg(m_invoiceLine.getAD_Org_ID()); + } + if (skip) + continue; + + BigDecimal LineNetAmt = m_invoiceLine.getLineNetAmt(); + BigDecimal multiplier = inv.getQty() + .divide(m_invoiceLine.getQtyInvoiced(), 12, BigDecimal.ROUND_HALF_UP) + .abs(); + if (multiplier.compareTo(Env.ONE) != 0) + LineNetAmt = LineNetAmt.multiply(multiplier); + + // Source from Doc_MatchInv.createFacts(MAcctSchema) + // Cost Detail Record - data from Expense/IncClearing (CR) record + // MZ Goodwill + // Create Cost Detail Matched Invoice using Total Amount and Total Qty based on InvoiceLine + MMatchInv[] mInv = MMatchInv.getInvoiceLine(getCtx(), m_invoiceLine.getC_InvoiceLine_ID(), inv.get_TrxName()); + BigDecimal tQty = Env.ZERO; + BigDecimal tAmt = Env.ZERO; + for (int i = 0 ; i < mInv.length ; i++) + { + if (mInv[i].isPosted() && mInv[i].getM_MatchInv_ID() != get_ID()) + { + tQty = tQty.add(mInv[i].getQty()); + multiplier = mInv[i].getQty() + .divide(m_invoiceLine.getQtyInvoiced(), 12, BigDecimal.ROUND_HALF_UP).abs(); + tAmt = tAmt.add(m_invoiceLine.getLineNetAmt().multiply(multiplier)); + } + } + + // Different currency + MInvoice invoice = m_invoiceLine.getParent(); + if (as.getC_Currency_ID() != invoice.getC_Currency_ID()) + { + tAmt = MConversionRate.convert(getCtx(), tAmt, + invoice.getC_Currency_ID(), as.getC_Currency_ID(), + invoice.getDateAcct(), invoice.getC_ConversionType_ID(), + invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); + if (tAmt == null) + { + return "AP Invoice not convertible - " + as.getName(); + } + } + + tAmt = tAmt.add(LineNetAmt); //Invoice Price + // set Qty to negative value when MovementType is Vendor Returns + MInOut receipt = m_receiptLine.getParent(); + if (receipt.getMovementType().equals(MInOut.MOVEMENTTYPE_VendorReturns)) + tQty = tQty.add(inv.getQty().negate()); // Qty is set to negative value + else + tQty = tQty.add(inv.getQty()); + + // Set Total Amount and Total Quantity from Matched Invoice + MCostDetail.createInvoice(as, getAD_Org_ID(), + inv.getM_Product_ID(), inv.getM_AttributeSetInstance_ID(), + m_invoiceLine.getC_InvoiceLine_ID(), 0, // No cost element + tAmt, tQty, getDescription(), inv.get_TrxName()); + // end MZ + // end + } + + return ""; + } + // /** * Set the definite document number after completed @@ -2222,6 +2312,11 @@ public class MInvoice extends X_C_Invoice implements DocAction iLine.setM_InOutLine_ID(0); iLine.save(get_TrxName()); } + //AZ Goodwill + if (!isSOTrx()) + { + deleteMatchInvCostDetail(iLine); + } } setProcessed(true); //FR1948157 @@ -2258,23 +2353,6 @@ public class MInvoice extends X_C_Invoice implements DocAction alloc.save(); } - //MZ Goodwill - if (!isSOTrx()) - { - // delete Matched Invoice Cost Detail - MInvoiceLine[] lines = getLines(); - for (int i = 0; i < lines.length; i++) - { - MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=? AND M_AttributeSetInstance_ID=?", - lines[i].getC_InvoiceLine_ID(), lines[i].getM_AttributeSetInstance_ID(), get_TrxName()); - if (cd != null) - { - cd.setProcessed(false); - cd.delete(true); - } - } - } - //End MZ // After reverseCorrect m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_REVERSECORRECT); if (m_processMsg != null) @@ -2405,4 +2483,39 @@ public class MInvoice extends X_C_Invoice implements DocAction setUser2_ID(originalInvoice.getUser2_ID()); } + //AZ Goodwill + private String deleteMatchInvCostDetail(MInvoiceLine line) + { + // Get Account Schemas to delete MCostDetail + MAcctSchema[] acctschemas = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()); + for(int asn = 0; asn < acctschemas.length; asn++) + { + MAcctSchema as = acctschemas[asn]; + + boolean skip = false; + if (as.getAD_OrgOnly_ID() != 0) + { + if (as.getOnlyOrgs() == null) + as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), + 0, MAcctSchemaElement.ELEMENTTYPE_Organization, + as.getAD_OrgOnly_ID())); + skip = as.isSkipOrg(getAD_Org_ID()); + } + if (skip) + continue; + + // update/delete Cost Detail and recalculate Current Cost + MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?", + line.getC_InvoiceLine_ID(), line.getM_AttributeSetInstance_ID(), + as.getC_AcctSchema_ID(), get_TrxName()); + if (cd != null) + { + cd.setProcessed(false); + cd.delete(true); + } + } + + return ""; + } + } // MInvoice diff --git a/base/src/org/compiere/model/MMatchInv.java b/base/src/org/compiere/model/MMatchInv.java index e1e2e56191..a5281c7304 100644 --- a/base/src/org/compiere/model/MMatchInv.java +++ b/base/src/org/compiere/model/MMatchInv.java @@ -508,8 +508,8 @@ public class MMatchInv extends X_M_MatchInv continue; // update/delete Cost Detail and recalculate Current Cost - MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=? AND M_AttributeSetInstance_ID=?", - getC_InvoiceLine_ID(), getM_AttributeSetInstance_ID(), get_TrxName()); + MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?", + getC_InvoiceLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName()); if (cd != null) { MInOut receipt = (new MInOutLine(getCtx(),getM_InOutLine_ID(),get_TrxName())).getParent(); @@ -535,7 +535,7 @@ public class MMatchInv extends X_M_MatchInv cd.setProcessed(false); cd.delete(true); } - } + } } return ""; diff --git a/base/src/org/compiere/model/MMatchPO.java b/base/src/org/compiere/model/MMatchPO.java index 5de715bdb6..e1d7486989 100644 --- a/base/src/org/compiere/model/MMatchPO.java +++ b/base/src/org/compiere/model/MMatchPO.java @@ -913,8 +913,8 @@ public class MMatchPO extends X_M_MatchPO continue; // update/delete Cost Detail and recalculate Current Cost - MCostDetail cd = MCostDetail.get (getCtx(), "C_OrderLine_ID=? AND M_AttributeSetInstance_ID=?", - getC_OrderLine_ID(), getM_AttributeSetInstance_ID(), get_TrxName()); + MCostDetail cd = MCostDetail.get (getCtx(), "C_OrderLine_ID=?", + getC_OrderLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName()); if (cd != null) { BigDecimal price = cd.getAmt().divide(cd.getQty(),12,BigDecimal.ROUND_HALF_UP); diff --git a/base/src/org/compiere/model/MOrder.java b/base/src/org/compiere/model/MOrder.java index 9ca7a0531b..5c5b874b25 100644 --- a/base/src/org/compiere/model/MOrder.java +++ b/base/src/org/compiere/model/MOrder.java @@ -30,6 +30,7 @@ import org.adempiere.exceptions.FillMandatoryException; import org.compiere.print.ReportEngine; import org.compiere.process.DocAction; import org.compiere.process.DocumentEngine; +import org.compiere.report.MReportTree; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; @@ -1937,6 +1938,11 @@ public class MOrder extends X_C_Order implements DocAction line.setLineNetAmt(Env.ZERO); line.save(get_TrxName()); } + //AZ Goodwill + if (!isSOTrx()) + { + deleteMatchPOCostDetail(line); + } } addDescription(Msg.getMsg(getCtx(), "Voided")); // Clear Reservations @@ -1949,29 +1955,6 @@ public class MOrder extends X_C_Order implements DocAction if (!createReversals()) return false; - //MZ Goodwill - if (!isSOTrx()) - { - // delete Matched PO Cost Detail - MOrderLine[] linesMZ = getLines(); - for (int i = 0; i < lines.length; i++) - { - MMatchPO[] mPO = MMatchPO.getOrderLine(getCtx(), linesMZ[i].getC_OrderLine_ID(), get_TrxName()); - // delete Cost Detail if the Matched PO has been deleted - if (mPO.length == 0) - { - MCostDetail cd = MCostDetail.get(getCtx(), "C_OrderLine_ID=? AND M_AttributeSetInstance_ID=?", - linesMZ[i].getC_OrderLine_ID(), linesMZ[i].getM_AttributeSetInstance_ID(), get_TrxName()); - if (cd != null) - { - cd.setProcessed(false); - cd.delete(true); - } - } - } - } - //End MZ - // After Void m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID); if (m_processMsg != null) @@ -2311,4 +2294,44 @@ public class MOrder extends X_C_Order implements DocAction return getGrandTotal(); } // getApprovalAmt + //AZ Goodwill + private String deleteMatchPOCostDetail(MOrderLine line) + { + // Get Account Schemas to delete MCostDetail + MAcctSchema[] acctschemas = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID()); + for(int asn = 0; asn < acctschemas.length; asn++) + { + MAcctSchema as = acctschemas[asn]; + + boolean skip = false; + if (as.getAD_OrgOnly_ID() != 0) + { + if (as.getOnlyOrgs() == null) + as.setOnlyOrgs(MReportTree.getChildIDs(getCtx(), + 0, MAcctSchemaElement.ELEMENTTYPE_Organization, + as.getAD_OrgOnly_ID())); + skip = as.isSkipOrg(getAD_Org_ID()); + } + if (skip) + continue; + + // update/delete Cost Detail and recalculate Current Cost + MMatchPO[] mPO = MMatchPO.getOrderLine(getCtx(), line.getC_OrderLine_ID(), get_TrxName()); + // delete Cost Detail if the Matched PO has been deleted + if (mPO.length == 0) + { + MCostDetail cd = MCostDetail.get(getCtx(), "C_OrderLine_ID=?", + line.getC_OrderLine_ID(), line.getM_AttributeSetInstance_ID(), + as.getC_AcctSchema_ID(), get_TrxName()); + if (cd != null) + { + cd.setProcessed(false); + cd.delete(true); + } + } + } + + return ""; + } + } // MOrder