Include in trunk revision 2333 lost with changes in revision 2335.

Thanks Teo for noticing this.
This commit is contained in:
Carlos Ruiz 2007-05-12 18:41:41 +00:00
parent d75a3a5f7d
commit a51eb60084
1 changed files with 82 additions and 65 deletions

View File

@ -640,71 +640,88 @@ public final class Fact
* GL Distribution of Fact Lines * GL Distribution of Fact Lines
* @return true if success * @return true if success
*/ */
public boolean distribute() public boolean distribute()
{ {
// no lines -> nothing to distribute // no lines -> nothing to distribute
if (m_lines.size() == 0) if (m_lines.size() == 0)
return true; return true;
ArrayList<FactLine> newLines = new ArrayList<FactLine>(); ArrayList<FactLine> newLines = new ArrayList<FactLine>();
// For all fact lines // For all fact lines
for (int i = 0; i < m_lines.size(); i++) for (int i = 0; i < m_lines.size(); i++)
{ {
FactLine dLine = (FactLine)m_lines.get(i); FactLine dLine = (FactLine)m_lines.get(i);
MDistribution[] distributions = MDistribution.get (dLine.getAccount(), MDistribution[] distributions = MDistribution.get (dLine.getAccount(),
m_postingType, m_doc.getC_DocType_ID()); m_postingType, m_doc.getC_DocType_ID());
// No Distribution for this line // No Distribution for this line
if (distributions == null || distributions.length == 0) //AZ Goodwill
continue; //The above "get" only work in GL Journal because it's using ValidCombination Account
// Just the first //Old:
if (distributions.length > 1) //if (distributions == null || distributions.length == 0)
log.warning("More then one Distributiion for " + dLine.getAccount()); // continue;
MDistribution distribution = distributions[0]; //For other document, we try the followings (from FactLine):
// Add Reversal //New:
FactLine reversal = dLine.reverse(distribution.getName()); if (distributions == null || distributions.length == 0)
log.info("Reversal=" + reversal); {
newLines.add(reversal); // saved in postCommit distributions = MDistribution.get (dLine.getCtx(), dLine.getC_AcctSchema_ID(),
// Prepare m_postingType, m_doc.getC_DocType_ID(),
distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getC_Currency_ID()); dLine.getAD_Org_ID(), dLine.getAccount_ID(),
MDistributionLine[] lines = distribution.getLines(false); dLine.getM_Product_ID(), dLine.getC_BPartner_ID(), dLine.getC_Project_ID(),
for (int j = 0; j < lines.length; j++) dLine.getC_Campaign_ID(), dLine.getC_Activity_ID(), dLine.getAD_OrgTrx_ID(),
{ dLine.getC_SalesRegion_ID(), dLine.getC_LocTo_ID(), dLine.getC_LocFrom_ID(),
MDistributionLine dl = lines[j]; dLine.getUser1_ID(), dLine.getUser2_ID());
if (!dl.isActive() || dl.getAmt().signum() == 0) if (distributions == null || distributions.length == 0)
continue; continue;
FactLine factLine = new FactLine (m_doc.getCtx(), m_doc.get_Table_ID(), }
m_doc.get_ID(), 0, m_trxName); //end AZ
// Set Info & Account // Just the first
factLine.setDocumentInfo(m_doc, dLine.getDocLine()); if (distributions.length > 1)
factLine.setAccount(m_acctSchema, dl.getAccount()); log.warning("More then one Distributiion for " + dLine.getAccount());
factLine.setPostingType(m_postingType); MDistribution distribution = distributions[0];
if (dl.isOverwriteOrg()) // set Org explicitly // Add Reversal
factLine.setAD_Org_ID(dl.getOrg_ID()); FactLine reversal = dLine.reverse(distribution.getName());
// log.info("Reversal=" + reversal);
if (dl.getAmt().signum() < 0) newLines.add(reversal); // saved in postCommit
factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs()); // Prepare
else distribution.distribute(dLine.getAccount(), dLine.getSourceBalance(), dLine.getC_Currency_ID());
factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null); MDistributionLine[] lines = distribution.getLines(false);
// Convert for (int j = 0; j < lines.length; j++)
factLine.convert(); {
// MDistributionLine dl = lines[j];
String description = distribution.getName() + " #" + dl.getLine(); if (!dl.isActive() || dl.getAmt().signum() == 0)
if (dl.getDescription() != null) continue;
description += " - " + dl.getDescription(); FactLine factLine = new FactLine (m_doc.getCtx(), m_doc.get_Table_ID(),
factLine.addDescription(description); m_doc.get_ID(), 0, m_trxName);
// // Set Info & Account
log.info(factLine.toString()); factLine.setDocumentInfo(m_doc, dLine.getDocLine());
newLines.add(factLine); factLine.setAccount(m_acctSchema, dl.getAccount());
} factLine.setPostingType(m_postingType);
} // for all lines if (dl.isOverwriteOrg()) // set Org explicitly
factLine.setAD_Org_ID(dl.getOrg_ID());
// Add Lines //
for (int i = 0; i < newLines.size(); i++) if (dl.getAmt().signum() < 0)
m_lines.add(newLines.get(i)); factLine.setAmtSource(dLine.getC_Currency_ID(), null, dl.getAmt().abs());
else
return true; factLine.setAmtSource(dLine.getC_Currency_ID(), dl.getAmt(), null);
} // distribute // 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 * String representation