From 4f047fdb8734e6fbfc0501e1c71be5847dc3ae72 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 31 Dec 2007 23:01:34 +0000 Subject: [PATCH] [ 1840016 ] Avoid usage of clearing accounts problem with realized gain & loss reported by Anh Han (anhhn) https://sourceforge.net/forum/message.php?msg_id=4687667 --- .../src/org/compiere/acct/Doc_Allocation.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/base/src/org/compiere/acct/Doc_Allocation.java b/base/src/org/compiere/acct/Doc_Allocation.java index c2e592d407..d15263b3b9 100644 --- a/base/src/org/compiere/acct/Doc_Allocation.java +++ b/base/src/org/compiere/acct/Doc_Allocation.java @@ -159,6 +159,7 @@ public class Doc_Allocation extends Doc // create Fact Header Fact fact = new Fact(this, as, Fact.POST_Actual); + Fact factForRGL = new Fact(this, as, Fact.POST_Actual); // dummy fact (not posted) to calculate Realized Gain & Loss for (int i = 0; i < p_lines.length; i++) { @@ -177,13 +178,12 @@ public class Doc_Allocation extends Doc BigDecimal allocationSource = line.getAmtSource() .add(line.getDiscountAmt()) .add(line.getWriteOffAmt()); - //Modified Lines by Armen - //Old: - //BigDecimal allocationAccounted = null; // AR/AP balance corrected + BigDecimal allocationSourceForRGL = allocationSource; // for realized gain & loss purposes BigDecimal allocationAccounted = Env.ZERO; // AR/AP balance corrected - //End of Modified Lines + BigDecimal allocationAccountedForRGL = Env.ZERO; // for realized gain & loss purposes FactLine fl = null; + FactLine flForRGL = null; MAccount bpAcct = null; // Liability/Receivables // MPayment payment = null; @@ -284,11 +284,18 @@ public class Doc_Allocation extends Doc allocationAccounted = fl.getAcctBalance().negate(); if (fl != null && invoice != null) fl.setAD_Org_ID(invoice.getAD_Org_ID()); + + // for Realized Gain & Loss + flForRGL = factForRGL.createLine (line, bpAcct, + getC_Currency_ID(), null, allocationSourceForRGL); // payment currency + if (flForRGL != null) + allocationAccountedForRGL = flForRGL.getAcctBalance().negate(); } else // Cash Based { allocationAccounted = createCashBasedAcct (as, fact, invoice, allocationSource); + allocationAccountedForRGL = allocationAccounted; } } // Purchase Invoice @@ -306,6 +313,9 @@ public class Doc_Allocation extends Doc MAccount acct_liability = getAccount(Doc.ACCTTYPE_V_Liability, as); boolean isUsingClearing = true; + // Save original allocation source for realized gain & loss purposes + allocationSourceForRGL = allocationSourceForRGL.negate(); + if ((!as.isPostIfClearingEqual()) && acct_payment_select != null && acct_payment_select.equals(acct_liability)) { // if not using clearing accounts, then don't post amtsource @@ -327,11 +337,18 @@ public class Doc_Allocation extends Doc allocationAccounted = fl.getAcctBalance(); if (fl != null && invoice != null) fl.setAD_Org_ID(invoice.getAD_Org_ID()); + + // for Realized Gain & Loss + flForRGL = factForRGL.createLine (line, bpAcct, + getC_Currency_ID(), allocationSourceForRGL, null); // payment currency + if (flForRGL != null) + allocationAccountedForRGL = flForRGL.getAcctBalance(); } else // Cash Based { allocationAccounted = createCashBasedAcct (as, fact, invoice, allocationSource); + allocationAccountedForRGL = allocationAccounted; } // Discount CR @@ -395,7 +412,7 @@ public class Doc_Allocation extends Doc || getC_Currency_ID() != line.getInvoiceC_Currency_ID())) // allocation <> invoice currency { p_Error = createRealizedGainLoss (as, fact, bpAcct, invoice, - allocationSource, allocationAccounted); + allocationSourceForRGL, allocationAccountedForRGL); if (p_Error != null) return null; }