#1002861 Product Costing in Bizidum. Fixed reversal for matchpo, matchinv and cost adjustment. IDEMPIERE-1180 IDEMPIERE-1188

This commit is contained in:
Heng Sin Low 2013-09-25 12:25:33 +08:00
parent c82c64c1ab
commit e8b984a1e8
9 changed files with 238 additions and 348 deletions

View File

@ -72,6 +72,7 @@ public class Doc_MatchInv extends Doc
private MInOutLine m_receiptLine = null; private MInOutLine m_receiptLine = null;
private ProductCost m_pc = null; private ProductCost m_pc = null;
private MMatchInv m_matchInv;
/** Commitments */ /** Commitments */
// private DocLine[] m_commitments = null; // private DocLine[] m_commitments = null;
@ -83,21 +84,21 @@ public class Doc_MatchInv extends Doc
protected String loadDocumentDetails () protected String loadDocumentDetails ()
{ {
setC_Currency_ID (Doc.NO_CURRENCY); setC_Currency_ID (Doc.NO_CURRENCY);
MMatchInv matchInv = (MMatchInv)getPO(); m_matchInv = (MMatchInv)getPO();
setDateDoc(matchInv.getDateTrx()); setDateDoc(m_matchInv.getDateTrx());
setQty (matchInv.getQty()); setQty (m_matchInv.getQty());
// Invoice Info // Invoice Info
int C_InvoiceLine_ID = matchInv.getC_InvoiceLine_ID(); int C_InvoiceLine_ID = m_matchInv.getC_InvoiceLine_ID();
m_invoiceLine = new MInvoiceLine (getCtx(), C_InvoiceLine_ID, getTrxName()); m_invoiceLine = new MInvoiceLine (getCtx(), C_InvoiceLine_ID, getTrxName());
// BP for NotInvoicedReceipts // BP for NotInvoicedReceipts
int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID(); int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID();
setC_BPartner_ID(C_BPartner_ID); setC_BPartner_ID(C_BPartner_ID);
// //
int M_InOutLine_ID = matchInv.getM_InOutLine_ID(); int M_InOutLine_ID = m_matchInv.getM_InOutLine_ID();
m_receiptLine = new MInOutLine (getCtx(), M_InOutLine_ID, getTrxName()); m_receiptLine = new MInOutLine (getCtx(), M_InOutLine_ID, getTrxName());
// //
m_pc = new ProductCost (Env.getCtx(), m_pc = new ProductCost (Env.getCtx(),
getM_Product_ID(), matchInv.getM_AttributeSetInstance_ID(), getTrxName()); getM_Product_ID(), m_matchInv.getM_AttributeSetInstance_ID(), getTrxName());
m_pc.setQty(getQty()); m_pc.setQty(getQty());
return null; return null;
@ -171,12 +172,19 @@ public class Doc_MatchInv extends Doc
return null; return null;
} }
dr.setQty(getQty()); dr.setQty(getQty());
// dr.setM_Locator_ID(m_receiptLine.getM_Locator_ID());
// MInOut receipt = m_receiptLine.getParent();
// dr.setLocationFromBPartner(receipt.getC_BPartner_Location_ID(), true); // from Loc
// dr.setLocationFromLocator(m_receiptLine.getM_Locator_ID(), false); // to Loc
BigDecimal temp = dr.getAcctBalance(); BigDecimal temp = dr.getAcctBalance();
// Set AmtAcctCr/Dr from Receipt (sets also Project) // Set AmtAcctCr/Dr from Receipt (sets also Project)
if (m_matchInv.getReversal_ID() > 0)
{
if (!dr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
{
p_Error = "Failed to create reversal entry";
return null;
}
}
else
{
if (!dr.updateReverseLine (MInOut.Table_ID, // Amt updated if (!dr.updateReverseLine (MInOut.Table_ID, // Amt updated
m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(), m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(),
multiplier)) multiplier))
@ -184,6 +192,7 @@ public class Doc_MatchInv extends Doc
p_Error = "Mat.Receipt not posted yet"; p_Error = "Mat.Receipt not posted yet";
return null; return null;
} }
}
if (log.isLoggable(Level.FINE)) log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance() if (log.isLoggable(Level.FINE)) log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance()
+ ") - " + dr.toString()); + ") - " + dr.toString());
@ -214,15 +223,27 @@ public class Doc_MatchInv extends Doc
cr.setAmtAcctCr(BigDecimal.ZERO); cr.setAmtAcctCr(BigDecimal.ZERO);
cr.setAmtSourceCr(BigDecimal.ZERO); cr.setAmtSourceCr(BigDecimal.ZERO);
} }
cr.setQty(getQty().negate());
temp = cr.getAcctBalance(); temp = cr.getAcctBalance();
if (m_matchInv.getReversal_ID() > 0)
{
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
{
p_Error = "Failed to create reversal entry";
return null;
}
}
else
{
cr.setQty(getQty().negate());
// Set AmtAcctCr/Dr from Invoice (sets also Project) // Set AmtAcctCr/Dr from Invoice (sets also Project)
if (as.isAccrual() && !cr.updateReverseLine (MInvoice.Table_ID, // Amt updated if (!cr.updateReverseLine (MInvoice.Table_ID, // Amt updated
m_invoiceLine.getC_Invoice_ID(), m_invoiceLine.getC_InvoiceLine_ID(), multiplier)) m_invoiceLine.getC_Invoice_ID(), m_invoiceLine.getC_InvoiceLine_ID(), multiplier))
{ {
p_Error = "Invoice not posted yet"; p_Error = "Invoice not posted yet";
return null; return null;
} }
}
if (log.isLoggable(Level.FINE)) log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance() if (log.isLoggable(Level.FINE)) log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance()
+ ") - " + cr.toString()); + ") - " + cr.toString());
} }
@ -236,8 +257,22 @@ public class Doc_MatchInv extends Doc
invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
cr = fact.createLine (null, expense, cr = fact.createLine (null, expense,
as.getC_Currency_ID(), null, LineNetAmt); as.getC_Currency_ID(), null, LineNetAmt);
if (m_matchInv.getReversal_ID() > 0)
{
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
{
p_Error = "Failed to create reversal entry";
return null;
}
}
else
{
cr.setQty(getQty().multiply(multiplier).negate()); cr.setQty(getQty().multiply(multiplier).negate());
} }
}
if (m_matchInv.getReversal_ID() == 0)
{
cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID()); cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID()); cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
cr.setC_Project_ID(m_invoiceLine.getC_Project_ID()); cr.setC_Project_ID(m_invoiceLine.getC_Project_ID());
@ -246,6 +281,7 @@ public class Doc_MatchInv extends Doc
cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID()); cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
cr.setUser1_ID(m_invoiceLine.getUser1_ID()); cr.setUser1_ID(m_invoiceLine.getUser1_ID());
cr.setUser2_ID(m_invoiceLine.getUser2_ID()); cr.setUser2_ID(m_invoiceLine.getUser2_ID());
}
//AZ Goodwill //AZ Goodwill
//Desc: Source Not Balanced problem because Currency is Difference - PO=CNY but AP=USD //Desc: Source Not Balanced problem because Currency is Difference - PO=CNY but AP=USD

View File

@ -71,6 +71,7 @@ public class Doc_MatchPO extends Doc
private ProductCost m_pc; private ProductCost m_pc;
private int m_M_AttributeSetInstance_ID = 0; private int m_M_AttributeSetInstance_ID = 0;
private MMatchPO m_matchPO;
/** /**
* Load Specific Document Details * Load Specific Document Details
@ -79,19 +80,19 @@ public class Doc_MatchPO extends Doc
protected String loadDocumentDetails () protected String loadDocumentDetails ()
{ {
setC_Currency_ID (Doc.NO_CURRENCY); setC_Currency_ID (Doc.NO_CURRENCY);
MMatchPO matchPO = (MMatchPO)getPO(); m_matchPO = (MMatchPO)getPO();
setDateDoc(matchPO.getDateTrx()); setDateDoc(m_matchPO.getDateTrx());
// //
m_M_AttributeSetInstance_ID = matchPO.getM_AttributeSetInstance_ID(); m_M_AttributeSetInstance_ID = m_matchPO.getM_AttributeSetInstance_ID();
setQty (matchPO.getQty()); setQty (m_matchPO.getQty());
// //
m_C_OrderLine_ID = matchPO.getC_OrderLine_ID(); m_C_OrderLine_ID = m_matchPO.getC_OrderLine_ID();
m_oLine = new MOrderLine (getCtx(), m_C_OrderLine_ID, getTrxName()); m_oLine = new MOrderLine (getCtx(), m_C_OrderLine_ID, getTrxName());
// //
m_M_InOutLine_ID = matchPO.getM_InOutLine_ID(); m_M_InOutLine_ID = m_matchPO.getM_InOutLine_ID();
m_ioLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, getTrxName()); m_ioLine = new MInOutLine (getCtx(), m_M_InOutLine_ID, getTrxName());
m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID(); m_C_InvoiceLine_ID = m_matchPO.getC_InvoiceLine_ID();
// //
m_pc = new ProductCost (Env.getCtx(), m_pc = new ProductCost (Env.getCtx(),
@ -190,6 +191,31 @@ public class Doc_MatchPO extends Doc
MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs
if (MAcctSchema.COSTINGMETHOD_StandardCosting.equals(costingMethod)) if (MAcctSchema.COSTINGMETHOD_StandardCosting.equals(costingMethod))
{
if (m_matchPO.getReversal_ID() > 0)
{
// Product PPV
FactLine cr = fact.createLine(null,
m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as),
as.getC_Currency_ID(), Env.ONE);
if (!cr.updateReverseLine(MMatchPO.Table_ID, m_matchPO.getM_MatchPO_ID(), 0, Env.ONE))
{
fact.remove(cr);
cr = null;
}
if (cr != null)
{
// PPV Offset
FactLine dr = fact.createLine(null,
getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), Env.ONE);
if (!dr.updateReverseLine(MMatchPO.Table_ID, m_matchPO.getM_MatchPO_ID(), 0, Env.ONE))
{
p_Error = "Failed to create reversal entry for ACCTTYPE_PPVOffset";
return null;
}
}
}
else
{ {
// No Costs yet - no PPV // No Costs yet - no PPV
if (costs == null || costs.signum() == 0) if (costs == null || costs.signum() == 0)
@ -264,6 +290,7 @@ public class Doc_MatchPO extends Doc
} }
// End Avoid usage of clearing accounts // End Avoid usage of clearing accounts
}
// //
facts.add(fact); facts.add(fact);

View File

@ -1074,7 +1074,15 @@ public final class FactLine extends X_Fact_Acct
StringBuilder sql = new StringBuilder("SELECT * ") StringBuilder sql = new StringBuilder("SELECT * ")
.append("FROM Fact_Acct ") .append("FROM Fact_Acct ")
.append("WHERE C_AcctSchema_ID=? AND AD_Table_ID=? AND Record_ID=?") .append("WHERE C_AcctSchema_ID=? AND AD_Table_ID=? AND Record_ID=?")
.append(" AND Line_ID=? AND Account_ID=?"); .append(" AND Account_ID=?");
if (Line_ID > 0)
{
sql.append(" AND Line_ID=? ");
}
else
{
sql.append(" AND Line_ID IS NULL ");
}
// MZ Goodwill // MZ Goodwill
// for Inventory Move // for Inventory Move
if (MMovement.Table_ID == AD_Table_ID) if (MMovement.Table_ID == AD_Table_ID)
@ -1084,16 +1092,20 @@ public final class FactLine extends X_Fact_Acct
ResultSet rs = null; ResultSet rs = null;
try try
{ {
int pindex=1;
pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_AcctSchema_ID()); pstmt.setInt(pindex++, getC_AcctSchema_ID());
pstmt.setInt(2, AD_Table_ID); pstmt.setInt(pindex++, AD_Table_ID);
pstmt.setInt(3, Record_ID); pstmt.setInt(pindex++, Record_ID);
pstmt.setInt(4, Line_ID); pstmt.setInt(pindex++, m_acct.getAccount_ID());
pstmt.setInt(5, m_acct.getAccount_ID()); if (Line_ID > 0)
{
pstmt.setInt(pindex++, Line_ID);
}
// MZ Goodwill // MZ Goodwill
// for Inventory Move // for Inventory Move
if (MMovement.Table_ID == AD_Table_ID) if (MMovement.Table_ID == AD_Table_ID)
pstmt.setInt(6, getM_Locator_ID()); pstmt.setInt(pindex++, getM_Locator_ID());
// end MZ // end MZ
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())

View File

@ -1287,59 +1287,15 @@ public class MCostDetail extends X_M_CostDetail
history.setNewCostPrice(cost.getCurrentCostPrice()); history.setNewCostPrice(cost.getCurrentCostPrice());
history.setNewCAmt(cost.getCumulatedAmt()); history.setNewCAmt(cost.getCumulatedAmt());
history.setNewCQty(cost.getCumulatedQty()); history.setNewCQty(cost.getCumulatedQty());
//save history if there are movement of qty or costprice
if (history.getNewQty().compareTo(history.getOldQty()) != 0
|| history.getNewCostPrice().compareTo(history.getOldCostPrice()) != 0)
{
if (!history.save()) if (!history.save())
return false; return false;
}
return cost.save(); return cost.save();
} // process } // process
// Elaine 2008/6/20
protected boolean afterDelete (boolean success)
{
if(success)
{
// recalculate MCost
boolean ok = false;
// get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
String CostingLevel = product.getCostingLevel(as);
// Org Element
int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{
Org_ID = 0;
M_ASI_ID = 0;
}
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
M_ASI_ID = 0;
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
Org_ID = 0;
// Create Material Cost elements
if (getM_CostElement_ID() == 0)
{
MCostElement[] ces = MCostElement.getCostingMethods(this);
for (int i = 0; i < ces.length; i++)
{
MCostElement ce = ces[i];
ok = process (as, product, ce, Org_ID, M_ASI_ID);
if (!ok)
break;
}
} // Material Cost elements
else
{
MCostElement ce = MCostElement.get(getCtx(), getM_CostElement_ID());
ok = process (as, product, ce, Org_ID, M_ASI_ID);
}
return ok;
}
return super.afterDelete(success);
}
//
} // MCostDetail } // MCostDetail

View File

@ -2151,31 +2151,10 @@ public class MInOut extends X_M_InOut implements DocAction
// Reverse/Delete Matching // Reverse/Delete Matching
if (!isSOTrx()) if (!isSOTrx())
{
if (accrual)
{ {
if (!reverseMatching(reversalDate)) if (!reverseMatching(reversalDate))
return null; return null;
} }
else
{
MMatchInv[] mInv = MMatchInv.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
for (int i = 0; i < mInv.length; i++)
mInv[i].deleteEx(true);
MMatchPO[] mPO = MMatchPO.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
for (int i = 0; i < mPO.length; i++)
{
if (mPO[i].getC_InvoiceLine_ID() == 0)
mPO[i].deleteEx(true);
else
{
mPO[i].setM_InOutLine_ID(0);
mPO[i].saveEx();
}
}
}
}
// Deep Copy // Deep Copy
MInOut reversal = copyFrom (this, reversalMovementDate, reversalDate, MInOut reversal = copyFrom (this, reversalMovementDate, reversalDate,
@ -2263,6 +2242,9 @@ public class MInOut extends X_M_InOut implements DocAction
MMatchInv[] mInv = MMatchInv.getInOut(getCtx(), getM_InOut_ID(), get_TrxName()); MMatchInv[] mInv = MMatchInv.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
for (MMatchInv mMatchInv : mInv) for (MMatchInv mMatchInv : mInv)
{ {
if (mMatchInv.getReversal_ID() > 0)
continue;
String description = mMatchInv.getDescription(); String description = mMatchInv.getDescription();
if (description == null || !description.endsWith("<-)")) if (description == null || !description.endsWith("<-)"))
{ {
@ -2276,6 +2258,9 @@ public class MInOut extends X_M_InOut implements DocAction
MMatchPO[] mMatchPOList = MMatchPO.getInOut(getCtx(), getM_InOut_ID(), get_TrxName()); MMatchPO[] mMatchPOList = MMatchPO.getInOut(getCtx(), getM_InOut_ID(), get_TrxName());
for (MMatchPO mMatchPO : mMatchPOList) for (MMatchPO mMatchPO : mMatchPOList)
{ {
if (mMatchPO.getReversal_ID() > 0)
continue;
String description = mMatchPO.getDescription(); String description = mMatchPO.getDescription();
if (description == null || !description.endsWith("<-)")) if (description == null || !description.endsWith("<-)"))
{ {

View File

@ -835,6 +835,8 @@ public class MInventory extends X_M_Inventory implements DocAction
rLine.setQtyBook (oLine.getQtyCount()); // switch rLine.setQtyBook (oLine.getQtyCount()); // switch
rLine.setQtyCount (oLine.getQtyBook()); rLine.setQtyCount (oLine.getQtyBook());
rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate()); rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate());
rLine.setNewCostPrice(oLine.getCurrentCostPrice());
rLine.setCurrentCostPrice(oLine.getNewCostPrice());
rLine.saveEx(); rLine.saveEx();

View File

@ -2286,6 +2286,11 @@ public class MInvoice extends X_C_Invoice implements DocAction
accrual = true; accrual = true;
} }
if (!accrual)
{
}
if (accrual) if (accrual)
return reverseAccrualIt(); return reverseAccrualIt();
else else
@ -2378,12 +2383,13 @@ public class MInvoice extends X_C_Invoice implements DocAction
} }
// Reverse/Delete Matching // Reverse/Delete Matching
if (!isSOTrx()) if (!isSOTrx())
{
if (accrual)
{ {
MMatchInv[] mInv = MMatchInv.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName()); MMatchInv[] mInv = MMatchInv.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
for (int i = 0; i < mInv.length; i++) for (int i = 0; i < mInv.length; i++)
{ {
if (mInv[i].getReversal_ID() > 0)
continue;
if (!mInv[i].reverse(reversalDate)) if (!mInv[i].reverse(reversalDate))
{ {
m_processMsg = "Could not Reverse MatchInv"; m_processMsg = "Could not Reverse MatchInv";
@ -2393,6 +2399,9 @@ public class MInvoice extends X_C_Invoice implements DocAction
MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName()); MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
for (int i = 0; i < mPO.length; i++) for (int i = 0; i < mPO.length; i++)
{ {
if (mPO[i].getReversal_ID() > 0)
continue;
if (mPO[i].getM_InOutLine_ID() == 0) if (mPO[i].getM_InOutLine_ID() == 0)
{ {
if (!mPO[i].reverse(reversalDate)) if (!mPO[i].reverse(reversalDate))
@ -2408,26 +2417,6 @@ public class MInvoice extends X_C_Invoice implements DocAction
} }
} }
} }
else
{
MMatchInv[] mInv = MMatchInv.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
for (int i = 0; i < mInv.length; i++)
{
mInv[i].deleteEx(true);
}
MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
for (int i = 0; i < mPO.length; i++)
{
if (mPO[i].getM_InOutLine_ID() == 0)
mPO[i].deleteEx(true);
else
{
mPO[i].setC_InvoiceLine_ID(null);
mPO[i].saveEx(get_TrxName());
}
}
}
}
// //
load(get_TrxName()); // reload allocation reversal info load(get_TrxName()); // reload allocation reversal info

View File

@ -24,7 +24,6 @@ import java.util.Properties;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Match Invoice (Receipt<>Invoice) Model. * Match Invoice (Receipt<>Invoice) Model.
@ -305,34 +304,6 @@ public class MMatchInv extends X_M_MatchInv
// AZ Goodwill // AZ Goodwill
deleteMatchInvCostDetail(); deleteMatchInvCostDetail();
// end AZ // end AZ
// delete m_matchinv doesn't auto make m_matchpo invalid
// Get Order and decrease invoices
/*
MInvoiceLine iLine = new MInvoiceLine (getCtx(), getC_InvoiceLine_ID(), get_TrxName());
int C_OrderLine_ID = iLine.getC_OrderLine_ID();
if (C_OrderLine_ID == 0)
{
MInOutLine ioLine = new MInOutLine (getCtx(), getM_InOutLine_ID(), get_TrxName());
C_OrderLine_ID = ioLine.getC_OrderLine_ID();
}
// No Order Found
if (C_OrderLine_ID == 0)
return success;
// Find MatchPO
MMatchPO[] mPO = MMatchPO.get(getCtx(), C_OrderLine_ID,
getC_InvoiceLine_ID(), get_TrxName());
for (int i = 0; i < mPO.length; i++)
{
if (mPO[i].getM_InOutLine_ID() == 0)
mPO[i].delete(true);
else
{
mPO[i].setC_InvoiceLine_ID(null);
mPO[i].saveEx();
}
}
*/
} }
return success; return success;
} // afterDelete } // afterDelete
@ -352,43 +323,11 @@ public class MMatchInv extends X_M_MatchInv
continue; continue;
} }
// update/delete Cost Detail and recalculate Current Cost MCostDetail cd = MCostDetail.get (getCtx(), "M_MatchInv_ID=?",
MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?", getM_MatchInv_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
getC_InvoiceLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
if (cd != null) if (cd != null)
{ {
if (cd.isProcessed()) cd.deleteEx(true);
{
MInOut receipt = (new MInOutLine(getCtx(),getM_InOutLine_ID(),get_TrxName())).getParent();
BigDecimal qty = getQty();
if (receipt.getMovementType().equals(MInOut.MOVEMENTTYPE_VendorReturns))
qty = getQty().negate();
//
BigDecimal price = null;
if (cd.getQty().compareTo(Env.ZERO) == 0) // avoid division by zero
price = Env.ZERO;
else
price = cd.getAmt().divide(cd.getQty(),12,BigDecimal.ROUND_HALF_UP);
cd.setDeltaAmt(price.multiply(qty.negate()));
cd.setDeltaQty(qty.negate());
cd.setProcessed(false);
//
cd.setAmt(price.multiply(cd.getQty().subtract(qty)));
cd.setQty(cd.getQty().subtract(qty));
if (!cd.isProcessed())
{
cd.process();
}
if (cd.getQty().compareTo(Env.ZERO) == 0)
{
cd.setProcessed(false);
cd.delete(true);
}
}
else
{
cd.delete(true);
}
} }
} }

View File

@ -1032,10 +1032,6 @@ public class MMatchPO extends X_M_MatchPO
// (Reserved in VMatch and MInOut.completeIt) // (Reserved in VMatch and MInOut.completeIt)
if (success && getC_OrderLine_ID() != 0) if (success && getC_OrderLine_ID() != 0)
{ {
// AZ Goodwill
deleteMatchPOCostDetail();
// end AZ
MOrderLine orderLine = new MOrderLine (getCtx(), getC_OrderLine_ID(), get_TrxName()); MOrderLine orderLine = new MOrderLine (getCtx(), getC_OrderLine_ID(), get_TrxName());
if (getM_InOutLine_ID() != 0) if (getM_InOutLine_ID() != 0)
orderLine.setQtyDelivered(orderLine.getQtyDelivered().subtract(getQty())); orderLine.setQtyDelivered(orderLine.getQtyDelivered().subtract(getQty()));
@ -1136,58 +1132,6 @@ public class MMatchPO extends X_M_MatchPO
if (s_log.isLoggable(Level.INFO)) s_log.info("Success #" + success + " - Error #" + errors); if (s_log.isLoggable(Level.INFO)) s_log.info("Success #" + success + " - Error #" + errors);
} // consolidate } // consolidate
//AZ Goodwill
private String deleteMatchPOCostDetail()
{
// 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];
if (as.isSkipOrg(getAD_Org_ID()))
{
continue;
}
// update/delete Cost Detail and recalculate Current Cost
MCostDetail cd = MCostDetail.get (getCtx(), "C_OrderLine_ID=?",
getC_OrderLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
if (cd != null)
{
if (cd.isProcessed())
{
if (cd.getQty().compareTo(Env.ZERO) > 0)
{
BigDecimal price = cd.getAmt().divide(cd.getQty(),12,BigDecimal.ROUND_HALF_UP);
cd.setDeltaAmt(price.multiply(getQty().negate()));
cd.setDeltaQty(getQty().negate());
cd.setProcessed(false);
//
cd.setAmt(price.multiply(cd.getQty().subtract(getQty())));
cd.setQty(cd.getQty().subtract(getQty()));
if (!cd.isProcessed())
{
cd.process();
}
}
//after process clean-up
if (cd.getQty().compareTo(Env.ZERO) == 0)
{
cd.setProcessed(false);
cd.delete(true);
}
}
else
{
cd.delete(true);
}
}
}
return "";
}
/** /**
* Reverse MatchPO. * Reverse MatchPO.
* @param reversalDate * @param reversalDate