From a51eb600847d5ef4b60713e601b3e5cf3cd13295 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 12 May 2007 18:41:41 +0000 Subject: [PATCH] Include in trunk revision 2333 lost with changes in revision 2335. Thanks Teo for noticing this. --- base/src/org/compiere/acct/Fact.java | 147 +++++++++++++++------------ 1 file changed, 82 insertions(+), 65 deletions(-) diff --git a/base/src/org/compiere/acct/Fact.java b/base/src/org/compiere/acct/Fact.java index 779e3f50b8..6a419f1aa5 100644 --- a/base/src/org/compiere/acct/Fact.java +++ b/base/src/org/compiere/acct/Fact.java @@ -640,71 +640,88 @@ public final class Fact * GL Distribution of Fact Lines * @return true if success */ - public boolean distribute() - { - // no lines -> nothing to distribute - if (m_lines.size() == 0) - return true; - - ArrayList newLines = new ArrayList(); - // For all fact lines - for (int i = 0; i < m_lines.size(); i++) - { - FactLine dLine = (FactLine)m_lines.get(i); - MDistribution[] distributions = MDistribution.get (dLine.getAccount(), - m_postingType, m_doc.getC_DocType_ID()); - // No Distribution for this line - if (distributions == null || distributions.length == 0) - continue; - // Just the first - if (distributions.length > 1) - log.warning("More then one Distributiion for " + dLine.getAccount()); - MDistribution distribution = distributions[0]; - // Add Reversal - FactLine reversal = dLine.reverse(distribution.getName()); - log.info("Reversal=" + reversal); - newLines.add(reversal); // saved in postCommit - // Prepare - distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getC_Currency_ID()); - MDistributionLine[] lines = distribution.getLines(false); - for (int j = 0; j < lines.length; j++) - { - MDistributionLine dl = lines[j]; - if (!dl.isActive() || dl.getAmt().signum() == 0) - continue; - FactLine factLine = new FactLine (m_doc.getCtx(), m_doc.get_Table_ID(), - m_doc.get_ID(), 0, m_trxName); - // Set Info & Account - factLine.setDocumentInfo(m_doc, dLine.getDocLine()); - factLine.setAccount(m_acctSchema, dl.getAccount()); - factLine.setPostingType(m_postingType); - if (dl.isOverwriteOrg()) // set Org explicitly - factLine.setAD_Org_ID(dl.getOrg_ID()); - // - if (dl.getAmt().signum() < 0) - factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs()); - else - factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null); - // Convert - factLine.convert(); - // - String description = distribution.getName() + " #" + dl.getLine(); - if (dl.getDescription() != null) - description += " - " + dl.getDescription(); - factLine.addDescription(description); - // - log.info(factLine.toString()); - newLines.add(factLine); - } - } // for all lines - - // Add Lines - for (int i = 0; i < newLines.size(); i++) - m_lines.add(newLines.get(i)); - - return true; - } // distribute - + public boolean distribute() + { + // no lines -> nothing to distribute + if (m_lines.size() == 0) + return true; + + ArrayList newLines = new ArrayList(); + // For all fact lines + for (int i = 0; i < m_lines.size(); i++) + { + FactLine dLine = (FactLine)m_lines.get(i); + MDistribution[] distributions = MDistribution.get (dLine.getAccount(), + m_postingType, m_doc.getC_DocType_ID()); + // No Distribution for this line + //AZ Goodwill + //The above "get" only work in GL Journal because it's using ValidCombination Account + //Old: + //if (distributions == null || distributions.length == 0) + // continue; + //For other document, we try the followings (from FactLine): + //New: + if (distributions == null || distributions.length == 0) + { + distributions = MDistribution.get (dLine.getCtx(), dLine.getC_AcctSchema_ID(), + m_postingType, m_doc.getC_DocType_ID(), + dLine.getAD_Org_ID(), dLine.getAccount_ID(), + dLine.getM_Product_ID(), dLine.getC_BPartner_ID(), dLine.getC_Project_ID(), + dLine.getC_Campaign_ID(), dLine.getC_Activity_ID(), dLine.getAD_OrgTrx_ID(), + dLine.getC_SalesRegion_ID(), dLine.getC_LocTo_ID(), dLine.getC_LocFrom_ID(), + dLine.getUser1_ID(), dLine.getUser2_ID()); + if (distributions == null || distributions.length == 0) + continue; + } + //end AZ + // Just the first + if (distributions.length > 1) + log.warning("More then one Distributiion for " + dLine.getAccount()); + MDistribution distribution = distributions[0]; + // Add Reversal + FactLine reversal = dLine.reverse(distribution.getName()); + log.info("Reversal=" + reversal); + newLines.add(reversal); // saved in postCommit + // Prepare + distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getC_Currency_ID()); + MDistributionLine[] lines = distribution.getLines(false); + for (int j = 0; j < lines.length; j++) + { + MDistributionLine dl = lines[j]; + if (!dl.isActive() || dl.getAmt().signum() == 0) + continue; + FactLine factLine = new FactLine (m_doc.getCtx(), m_doc.get_Table_ID(), + m_doc.get_ID(), 0, m_trxName); + // Set Info & Account + factLine.setDocumentInfo(m_doc, dLine.getDocLine()); + factLine.setAccount(m_acctSchema, dl.getAccount()); + factLine.setPostingType(m_postingType); + if (dl.isOverwriteOrg()) // set Org explicitly + factLine.setAD_Org_ID(dl.getOrg_ID()); + // + if (dl.getAmt().signum() < 0) + factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs()); + else + factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null); + // Convert + factLine.convert(); + // + String description = distribution.getName() + " #" + dl.getLine(); + if (dl.getDescription() != null) + description += " - " + dl.getDescription(); + factLine.addDescription(description); + // + log.info(factLine.toString()); + newLines.add(factLine); + } + } // for all lines + + // Add Lines + for (int i = 0; i < newLines.size(); i++) + m_lines.add(newLines.get(i)); + + return true; + } // distribute /************************************************************************** * String representation