hg merge release-1.0c (forward-porting)
This commit is contained in:
commit
7e974b0535
|
@ -0,0 +1,11 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
UPDATE M_CostDetail SET M_MatchInv_ID=NULL WHERE M_MatchInv_ID IS NOT NULL AND NOT EXISTS (SELECT a.M_MatchInv_ID FROM M_MatchInv a WHERE a.M_MatchInv_ID=M_CostDetail.M_MatchInv_ID)
|
||||
;
|
||||
|
||||
ALTER TABLE M_CostDetail ADD CONSTRAINT MCostDetail_MatchInv FOREIGN KEY(M_MatchInv_ID) REFERENCES M_MatchInv(M_MatchInv_ID) ON DELETE RESTRICT
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201309250432_IDEMPIERE-1188.sql') FROM dual
|
||||
;
|
|
@ -0,0 +1,8 @@
|
|||
UPDATE M_CostDetail SET M_MatchInv_ID=NULL WHERE M_MatchInv_ID IS NOT NULL AND NOT EXISTS (SELECT a.M_MatchInv_ID FROM M_MatchInv a WHERE a.M_MatchInv_ID=M_CostDetail.M_MatchInv_ID)
|
||||
;
|
||||
|
||||
ALTER TABLE M_CostDetail ADD CONSTRAINT MCostDetail_MatchInv FOREIGN KEY(M_MatchInv_ID) REFERENCES M_MatchInv(M_MatchInv_ID) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201309250432_IDEMPIERE-1188.sql') FROM dual
|
||||
;
|
|
@ -78,6 +78,7 @@ public class Doc_MatchInv extends Doc
|
|||
private MInOutLine m_receiptLine = null;
|
||||
|
||||
private ProductCost m_pc = null;
|
||||
private MMatchInv m_matchInv;
|
||||
|
||||
/** Commitments */
|
||||
// private DocLine[] m_commitments = null;
|
||||
|
@ -89,21 +90,21 @@ public class Doc_MatchInv extends Doc
|
|||
protected String loadDocumentDetails ()
|
||||
{
|
||||
setC_Currency_ID (Doc.NO_CURRENCY);
|
||||
MMatchInv matchInv = (MMatchInv)getPO();
|
||||
setDateDoc(matchInv.getDateTrx());
|
||||
setQty (matchInv.getQty());
|
||||
m_matchInv = (MMatchInv)getPO();
|
||||
setDateDoc(m_matchInv.getDateTrx());
|
||||
setQty (m_matchInv.getQty());
|
||||
// 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());
|
||||
// BP for NotInvoicedReceipts
|
||||
int C_BPartner_ID = m_invoiceLine.getParent().getC_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_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());
|
||||
|
||||
return null;
|
||||
|
@ -177,12 +178,19 @@ public class Doc_MatchInv extends Doc
|
|||
return null;
|
||||
}
|
||||
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();
|
||||
// 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
|
||||
m_receiptLine.getM_InOut_ID(), m_receiptLine.getM_InOutLine_ID(),
|
||||
multiplier))
|
||||
|
@ -190,6 +198,7 @@ public class Doc_MatchInv extends Doc
|
|||
p_Error = "Mat.Receipt not posted yet";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (log.isLoggable(Level.FINE)) log.fine("CR - Amt(" + temp + "->" + dr.getAcctBalance()
|
||||
+ ") - " + dr.toString());
|
||||
|
||||
|
@ -220,15 +229,27 @@ public class Doc_MatchInv extends Doc
|
|||
cr.setAmtAcctCr(BigDecimal.ZERO);
|
||||
cr.setAmtSourceCr(BigDecimal.ZERO);
|
||||
}
|
||||
cr.setQty(getQty().negate());
|
||||
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)
|
||||
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))
|
||||
{
|
||||
p_Error = "Invoice not posted yet";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (log.isLoggable(Level.FINE)) log.fine("DR - Amt(" + temp + "->" + cr.getAcctBalance()
|
||||
+ ") - " + cr.toString());
|
||||
}
|
||||
|
@ -242,9 +263,35 @@ public class Doc_MatchInv extends Doc
|
|||
invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
|
||||
cr = fact.createLine (null, expense,
|
||||
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());
|
||||
}
|
||||
}
|
||||
if (m_matchInv.getReversal_ID() == 0)
|
||||
{
|
||||
cr.setC_Activity_ID(m_invoiceLine.getC_Activity_ID());
|
||||
cr.setC_Campaign_ID(m_invoiceLine.getC_Campaign_ID());
|
||||
cr.setC_Project_ID(m_invoiceLine.getC_Project_ID());
|
||||
cr.setC_ProjectPhase_ID(m_invoiceLine.getC_ProjectPhase_ID());
|
||||
cr.setC_ProjectTask_ID(m_invoiceLine.getC_ProjectTask_ID());
|
||||
cr.setC_UOM_ID(m_invoiceLine.getC_UOM_ID());
|
||||
cr.setUser1_ID(m_invoiceLine.getUser1_ID());
|
||||
cr.setUser2_ID(m_invoiceLine.getUser2_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
updateFactLine(cr);
|
||||
}
|
||||
|
||||
//AZ Goodwill
|
||||
//Desc: Source Not Balanced problem because Currency is Difference - PO=CNY but AP=USD
|
||||
|
|
|
@ -75,6 +75,7 @@ public class Doc_MatchPO extends Doc
|
|||
|
||||
private ProductCost m_pc;
|
||||
private int m_M_AttributeSetInstance_ID = 0;
|
||||
private MMatchPO m_matchPO;
|
||||
|
||||
/**
|
||||
* Load Specific Document Details
|
||||
|
@ -83,19 +84,19 @@ public class Doc_MatchPO extends Doc
|
|||
protected String loadDocumentDetails ()
|
||||
{
|
||||
setC_Currency_ID (Doc.NO_CURRENCY);
|
||||
MMatchPO matchPO = (MMatchPO)getPO();
|
||||
setDateDoc(matchPO.getDateTrx());
|
||||
m_matchPO = (MMatchPO)getPO();
|
||||
setDateDoc(m_matchPO.getDateTrx());
|
||||
//
|
||||
m_M_AttributeSetInstance_ID = matchPO.getM_AttributeSetInstance_ID();
|
||||
setQty (matchPO.getQty());
|
||||
m_M_AttributeSetInstance_ID = m_matchPO.getM_AttributeSetInstance_ID();
|
||||
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_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_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID();
|
||||
m_C_InvoiceLine_ID = m_matchPO.getC_InvoiceLine_ID();
|
||||
|
||||
//
|
||||
m_pc = new ProductCost (Env.getCtx(),
|
||||
|
@ -251,6 +252,31 @@ public class Doc_MatchPO extends Doc
|
|||
MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs
|
||||
|
||||
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
|
||||
if (costs == null || costs.signum() == 0)
|
||||
|
@ -325,6 +351,7 @@ public class Doc_MatchPO extends Doc
|
|||
|
||||
}
|
||||
// End Avoid usage of clearing accounts
|
||||
}
|
||||
|
||||
//
|
||||
facts.add(fact);
|
||||
|
|
|
@ -1074,7 +1074,15 @@ public final class FactLine extends X_Fact_Acct
|
|||
StringBuilder sql = new StringBuilder("SELECT * ")
|
||||
.append("FROM Fact_Acct ")
|
||||
.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
|
||||
// for Inventory Move
|
||||
if (MMovement.Table_ID == AD_Table_ID)
|
||||
|
@ -1084,16 +1092,20 @@ public final class FactLine extends X_Fact_Acct
|
|||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
int pindex=1;
|
||||
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
pstmt.setInt(1, getC_AcctSchema_ID());
|
||||
pstmt.setInt(2, AD_Table_ID);
|
||||
pstmt.setInt(3, Record_ID);
|
||||
pstmt.setInt(4, Line_ID);
|
||||
pstmt.setInt(5, m_acct.getAccount_ID());
|
||||
pstmt.setInt(pindex++, getC_AcctSchema_ID());
|
||||
pstmt.setInt(pindex++, AD_Table_ID);
|
||||
pstmt.setInt(pindex++, Record_ID);
|
||||
pstmt.setInt(pindex++, m_acct.getAccount_ID());
|
||||
if (Line_ID > 0)
|
||||
{
|
||||
pstmt.setInt(pindex++, Line_ID);
|
||||
}
|
||||
// MZ Goodwill
|
||||
// for Inventory Move
|
||||
if (MMovement.Table_ID == AD_Table_ID)
|
||||
pstmt.setInt(6, getM_Locator_ID());
|
||||
pstmt.setInt(pindex++, getM_Locator_ID());
|
||||
// end MZ
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
|
|
|
@ -1299,59 +1299,15 @@ public class MCostDetail extends X_M_CostDetail
|
|||
history.setNewCostPrice(cost.getCurrentCostPrice());
|
||||
history.setNewCAmt(cost.getCumulatedAmt());
|
||||
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())
|
||||
return false;
|
||||
}
|
||||
|
||||
return cost.save();
|
||||
} // 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
|
||||
|
|
|
@ -2151,31 +2151,10 @@ public class MInOut extends X_M_InOut implements DocAction
|
|||
|
||||
// Reverse/Delete Matching
|
||||
if (!isSOTrx())
|
||||
{
|
||||
if (accrual)
|
||||
{
|
||||
if (!reverseMatching(reversalDate))
|
||||
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
|
||||
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());
|
||||
for (MMatchInv mMatchInv : mInv)
|
||||
{
|
||||
if (mMatchInv.getReversal_ID() > 0)
|
||||
continue;
|
||||
|
||||
String description = mMatchInv.getDescription();
|
||||
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());
|
||||
for (MMatchPO mMatchPO : mMatchPOList)
|
||||
{
|
||||
if (mMatchPO.getReversal_ID() > 0)
|
||||
continue;
|
||||
|
||||
String description = mMatchPO.getDescription();
|
||||
if (description == null || !description.endsWith("<-)"))
|
||||
{
|
||||
|
|
|
@ -835,6 +835,8 @@ public class MInventory extends X_M_Inventory implements DocAction
|
|||
rLine.setQtyBook (oLine.getQtyCount()); // switch
|
||||
rLine.setQtyCount (oLine.getQtyBook());
|
||||
rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate());
|
||||
rLine.setNewCostPrice(oLine.getCurrentCostPrice());
|
||||
rLine.setCurrentCostPrice(oLine.getNewCostPrice());
|
||||
|
||||
rLine.saveEx();
|
||||
|
||||
|
|
|
@ -2238,6 +2238,11 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
|||
accrual = true;
|
||||
}
|
||||
|
||||
if (!accrual)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (accrual)
|
||||
return reverseAccrualIt();
|
||||
else
|
||||
|
@ -2330,12 +2335,13 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
|||
}
|
||||
// Reverse/Delete Matching
|
||||
if (!isSOTrx())
|
||||
{
|
||||
if (accrual)
|
||||
{
|
||||
MMatchInv[] mInv = MMatchInv.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
for (int i = 0; i < mInv.length; i++)
|
||||
{
|
||||
if (mInv[i].getReversal_ID() > 0)
|
||||
continue;
|
||||
|
||||
if (!mInv[i].reverse(reversalDate))
|
||||
{
|
||||
m_processMsg = "Could not Reverse MatchInv";
|
||||
|
@ -2345,6 +2351,9 @@ public class MInvoice extends X_C_Invoice implements DocAction
|
|||
MMatchPO[] mPO = MMatchPO.getInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
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].reverse(reversalDate))
|
||||
|
@ -2360,26 +2369,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
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Properties;
|
|||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* Match Invoice (Receipt<>Invoice) Model.
|
||||
|
@ -305,34 +304,6 @@ public class MMatchInv extends X_M_MatchInv
|
|||
// AZ Goodwill
|
||||
deleteMatchInvCostDetail();
|
||||
// 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;
|
||||
} // afterDelete
|
||||
|
@ -352,43 +323,11 @@ public class MMatchInv extends X_M_MatchInv
|
|||
continue;
|
||||
}
|
||||
|
||||
// update/delete Cost Detail and recalculate Current Cost
|
||||
MCostDetail cd = MCostDetail.get (getCtx(), "C_InvoiceLine_ID=?",
|
||||
getC_InvoiceLine_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
|
||||
MCostDetail cd = MCostDetail.get (getCtx(), "M_MatchInv_ID=?",
|
||||
getM_MatchInv_ID(), getM_AttributeSetInstance_ID(), as.getC_AcctSchema_ID(), get_TrxName());
|
||||
if (cd != null)
|
||||
{
|
||||
if (cd.isProcessed())
|
||||
{
|
||||
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);
|
||||
}
|
||||
cd.deleteEx(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1032,10 +1032,6 @@ public class MMatchPO extends X_M_MatchPO
|
|||
// (Reserved in VMatch and MInOut.completeIt)
|
||||
if (success && getC_OrderLine_ID() != 0)
|
||||
{
|
||||
// AZ Goodwill
|
||||
deleteMatchPOCostDetail();
|
||||
// end AZ
|
||||
|
||||
MOrderLine orderLine = new MOrderLine (getCtx(), getC_OrderLine_ID(), get_TrxName());
|
||||
if (getM_InOutLine_ID() != 0)
|
||||
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);
|
||||
} // 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.
|
||||
* @param reversalDate
|
||||
|
|
|
@ -64,6 +64,7 @@ import org.zkoss.zk.ui.event.Events;
|
|||
import org.zkoss.zul.A;
|
||||
import org.zkoss.zul.Borderlayout;
|
||||
import org.zkoss.zul.Center;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.Hlayout;
|
||||
import org.zkoss.zul.North;
|
||||
import org.zkoss.zul.Separator;
|
||||
|
@ -200,8 +201,10 @@ public class WAllocation extends Allocation
|
|||
row.appendCellChild(bpartnerLabel.rightAlign());
|
||||
bpartnerSearch.getComponent().setHflex("true");
|
||||
row.appendCellChild(bpartnerSearch.getComponent(),2);
|
||||
row.appendCellChild(dateLabel.rightAlign());
|
||||
row.appendCellChild(dateField.getComponent());
|
||||
Hbox box = new Hbox();
|
||||
box.appendChild(dateLabel.rightAlign());
|
||||
box.appendChild(dateField.getComponent());
|
||||
row.appendCellChild(box);
|
||||
row.appendCellChild(organizationLabel.rightAlign());
|
||||
organizationPick.getComponent().setHflex("true");
|
||||
row.appendCellChild(organizationPick.getComponent(),1);
|
||||
|
@ -210,7 +213,7 @@ public class WAllocation extends Allocation
|
|||
row.appendCellChild(currencyLabel.rightAlign(),1);
|
||||
currencyPick.getComponent().setHflex("true");
|
||||
row.appendCellChild(currencyPick.getComponent(),1);
|
||||
row.appendCellChild(multiCurrency,2);
|
||||
row.appendCellChild(multiCurrency,1);
|
||||
row.appendCellChild(autoWriteOff,2);
|
||||
row.appendCellChild(new Space(),1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue