From 992d0f422af5a5264a337eecd31acf4b2b41f51f Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 12 Oct 2009 17:48:52 +0000 Subject: [PATCH] Implement [2872010] - Dunning Run for a complete Dunning (not just level) https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2872010&group_id=176962 --- .../adempiere/util/ModelClassGenerator.java | 6 +- .../org/compiere/model/I_C_DunningRun.java | 15 + .../compiere/model/I_C_DunningRunEntry.java | 11 + base/src/org/compiere/model/MDunningRun.java | 57 +++- .../org/compiere/model/MDunningRunEntry.java | 21 +- .../org/compiere/model/X_C_DunningRun.java | 32 +- .../compiere/model/X_C_DunningRunEntry.java | 29 +- base/src/org/compiere/print/ReportEngine.java | 30 +- .../org/compiere/process/DunningPrint.java | 36 ++- .../compiere/process/DunningRunCreate.java | 79 ++--- .../oracle/views/C_DUNNING_HEADER_V.sql | 2 +- .../oracle/views/C_DUNNING_HEADER_VT.sql | 4 +- .../postgresql/views/C_DUNNING_HEADER_V.sql | 2 +- .../postgresql/views/C_DUNNING_HEADER_VT.sql | 4 +- .../595_FR2872010DunningImprovements.sql | 276 ++++++++++++++++++ .../595_FR2872010DunningImprovements.sql | 261 +++++++++++++++++ 16 files changed, 765 insertions(+), 100 deletions(-) create mode 100644 migration/354a-trunk/oracle/595_FR2872010DunningImprovements.sql create mode 100644 migration/354a-trunk/postgresql/595_FR2872010DunningImprovements.sql diff --git a/base/src/org/adempiere/util/ModelClassGenerator.java b/base/src/org/adempiere/util/ModelClassGenerator.java index f1ddf0cd6d..4ffe7d4e82 100644 --- a/base/src/org/adempiere/util/ModelClassGenerator.java +++ b/base/src/org/adempiere/util/ModelClassGenerator.java @@ -176,10 +176,8 @@ public class ModelClassGenerator .append("\t *").append(NL) .append("\t */").append(NL) .append("\tprivate static final long serialVersionUID = ") - .append(Adempiere.DB_VERSION.substring(0,4)) - .append(Adempiere.DB_VERSION.substring(5,7)) - .append(Adempiere.DB_VERSION.substring(8)) - .append("L;").append(NL) + .append(String.format("%1$tY%1$tm%1$td", new Timestamp(System.currentTimeMillis()))) + .append("L;").append(NL) //.append("\tprivate static final long serialVersionUID = 1L;").append(NL) // Standard Constructor diff --git a/base/src/org/compiere/model/I_C_DunningRun.java b/base/src/org/compiere/model/I_C_DunningRun.java index 83119ef862..c8c044133f 100644 --- a/base/src/org/compiere/model/I_C_DunningRun.java +++ b/base/src/org/compiere/model/I_C_DunningRun.java @@ -62,6 +62,21 @@ public interface I_C_DunningRun */ public int getAD_Org_ID(); + /** Column name C_Dunning_ID */ + public static final String COLUMNNAME_C_Dunning_ID = "C_Dunning_ID"; + + /** Set Dunning. + * Dunning Rules for overdue invoices + */ + public void setC_Dunning_ID (int C_Dunning_ID); + + /** Get Dunning. + * Dunning Rules for overdue invoices + */ + public int getC_Dunning_ID(); + + public I_C_Dunning getC_Dunning() throws RuntimeException; + /** Column name C_DunningLevel_ID */ public static final String COLUMNNAME_C_DunningLevel_ID = "C_DunningLevel_ID"; diff --git a/base/src/org/compiere/model/I_C_DunningRunEntry.java b/base/src/org/compiere/model/I_C_DunningRunEntry.java index fdf0b262e2..89a0f253a2 100644 --- a/base/src/org/compiere/model/I_C_DunningRunEntry.java +++ b/base/src/org/compiere/model/I_C_DunningRunEntry.java @@ -135,6 +135,17 @@ public interface I_C_DunningRunEntry public I_C_Currency getC_Currency() throws RuntimeException; + /** Column name C_DunningLevel_ID */ + public static final String COLUMNNAME_C_DunningLevel_ID = "C_DunningLevel_ID"; + + /** Set Dunning Level */ + public void setC_DunningLevel_ID (int C_DunningLevel_ID); + + /** Get Dunning Level */ + public int getC_DunningLevel_ID(); + + public I_C_DunningLevel getC_DunningLevel() throws RuntimeException; + /** Column name C_DunningRunEntry_ID */ public static final String COLUMNNAME_C_DunningRunEntry_ID = "C_DunningRunEntry_ID"; diff --git a/base/src/org/compiere/model/MDunningRun.java b/base/src/org/compiere/model/MDunningRun.java index cf49bf3d00..9323d40197 100644 --- a/base/src/org/compiere/model/MDunningRun.java +++ b/base/src/org/compiere/model/MDunningRun.java @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -30,13 +31,15 @@ import org.compiere.util.DB; * * @author Jorg Janke * @version $Id: MDunningRun.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $ + * + * FR 2872010 - Dunning Run for a complete Dunning (not just level) - Developer: Carlos Ruiz - globalqss - Sponsor: Metas */ public class MDunningRun extends X_C_DunningRun { /** * */ - private static final long serialVersionUID = 3786948971790998292L; + private static final long serialVersionUID = 8450276205229694644L; /** * Standard Constructor @@ -66,19 +69,43 @@ public class MDunningRun extends X_C_DunningRun super(ctx, rs, trxName); } // MDunningRun - private MDunningLevel m_level = null; private MDunningRunEntry[] m_entries = null; + private MDunningLevel[] m_levels = null; /** - * Get Dunning Level - * @return level + * Get Dunning Levels + * @return array of level */ - public MDunningLevel getLevel() - { - if (m_level == null) - m_level = new MDunningLevel (getCtx(), getC_DunningLevel_ID(), get_TrxName()); - return m_level; - } // getLevel + public MDunningLevel[] getLevels() { + if (m_levels != null) + return m_levels; + + List levels; + if (getC_DunningLevel_ID() > 0) { + // just one level + levels = new Query( + getCtx(), + MDunningLevel.Table_Name, + "C_Dunning_ID=? AND C_DunningLevel_ID=?", + get_TrxName()) + .setParameters(new Object[]{getC_Dunning_ID(), getC_DunningLevel_ID()}) + .setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID") + .list(); + } else { + // all levels of the dun + levels = new Query( + getCtx(), + MDunningLevel.Table_Name, + "C_Dunning_ID=?", + get_TrxName()) + .setParameters(new Object[]{getC_Dunning_ID()}) + .setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID") + .list(); + } + m_levels = new MDunningLevel[levels.size()]; + levels.toArray (m_levels); + return m_levels; + } /** * Get Entries @@ -90,7 +117,7 @@ public class MDunningRun extends X_C_DunningRun if (m_entries != null && !requery) return m_entries; - String sql = "SELECT * FROM C_DunningRunEntry WHERE C_DunningRun_ID=?"; + String sql = "SELECT * FROM C_DunningRunEntry WHERE C_DunningRun_ID=? ORDER BY C_DunningLevel_ID, C_DunningRunEntry_ID"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; try @@ -147,9 +174,10 @@ public class MDunningRun extends X_C_DunningRun * @param C_BPartner_ID business partner * @param C_Currency_ID currency * @param SalesRep_ID sales rep + * @param C_DunningLevel_ID dunning level * @return entry */ - public MDunningRunEntry getEntry (int C_BPartner_ID, int C_Currency_ID, int SalesRep_ID) + public MDunningRunEntry getEntry (int C_BPartner_ID, int C_Currency_ID, int SalesRep_ID, int C_DunningLevel_ID) { // TODO: Related BP int C_BPartnerRelated_ID = C_BPartner_ID; @@ -158,7 +186,7 @@ public class MDunningRun extends X_C_DunningRun for (int i = 0; i < m_entries.length; i++) { MDunningRunEntry entry = m_entries[i]; - if (entry.getC_BPartner_ID() == C_BPartnerRelated_ID) + if (entry.getC_BPartner_ID() == C_BPartnerRelated_ID && entry.getC_DunningLevel_ID() == C_DunningLevel_ID) return entry; } // New Entry @@ -169,9 +197,10 @@ public class MDunningRun extends X_C_DunningRun if (entry.getSalesRep_ID() == 0) entry.setSalesRep_ID (SalesRep_ID); entry.setC_Currency_ID (C_Currency_ID); + entry.setC_DunningLevel_ID(C_DunningLevel_ID); // m_entries = null; return entry; } // getEntry - + } // MDunningRun diff --git a/base/src/org/compiere/model/MDunningRunEntry.java b/base/src/org/compiere/model/MDunningRunEntry.java index c946dfb756..f6916499f6 100644 --- a/base/src/org/compiere/model/MDunningRunEntry.java +++ b/base/src/org/compiere/model/MDunningRunEntry.java @@ -33,7 +33,9 @@ import org.compiere.util.Env; * @author Jorg Janke * @version $Id: MDunningRunEntry.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $ * - * @author Teo Sarca - BF [ 1739022 ], BF [ 1739096 ] + * @author Teo Sarca - BF [ 1739022 ], BF [ 1739096 ] + * + * FR 2872010 - Dunning Run for a complete Dunning (not just level) - Developer: Carlos Ruiz - globalqss - Sponsor: Metas */ public class MDunningRunEntry extends X_C_DunningRunEntry { @@ -41,7 +43,7 @@ public class MDunningRunEntry extends X_C_DunningRunEntry * */ private static final long serialVersionUID = 2028055451030209868L; - + /** Logger */ private static CLogger s_log = CLogger.getCLogger (MPayment.class); @@ -159,7 +161,7 @@ public class MDunningRunEntry extends X_C_DunningRunEntry throw new BPartnerNoAddressException(bp); } // User with location - MUser[] users = MUser.getOfBPartner(getCtx(), bp.getC_BPartner_ID(), null); + MUser[] users = MUser.getOfBPartner(getCtx(), bp.getC_BPartner_ID(), get_TrxName()); if (users.length == 1) setAD_User_ID (users[0].getAD_User_ID()); else @@ -221,7 +223,6 @@ public class MDunningRunEntry extends X_C_DunningRunEntry return retValue; } - /** * Get Parent * @return Dunning Run @@ -236,6 +237,7 @@ public class MDunningRunEntry extends X_C_DunningRunEntry @Override protected boolean beforeSave (boolean newRecord) { + I_C_DunningLevel level = getC_DunningLevel(); // Set Amt if (isProcessed ()) { @@ -245,20 +247,17 @@ public class MDunningRunEntry extends X_C_DunningRunEntry theseLines[i].setProcessed (true); theseLines[i].save (get_TrxName()); } - MDunningRun parent = getParent(); - if (parent.getLevel ().isSetCreditStop () || parent.getLevel ().isSetPaymentTerm ()) + if (level.isSetCreditStop () || level.isSetPaymentTerm ()) { MBPartner thisBPartner = MBPartner.get (getCtx(), getC_BPartner_ID()); - if (parent.getLevel ().isSetCreditStop ()) + if (level.isSetCreditStop ()) thisBPartner.setSOCreditStatus (X_C_BPartner.SOCREDITSTATUS_CreditStop); - if (parent.getLevel ().isSetPaymentTerm ()) - thisBPartner.setC_PaymentTerm_ID (parent.getLevel().getC_PaymentTerm_ID ()); + if (level.isSetPaymentTerm ()) + thisBPartner.setC_PaymentTerm_ID (level.getC_PaymentTerm_ID ()); thisBPartner.save (); } } return true; } // beforeSave - - } // MDunningRunEntry diff --git a/base/src/org/compiere/model/X_C_DunningRun.java b/base/src/org/compiere/model/X_C_DunningRun.java index 084bc40b6c..e9a7361b16 100644 --- a/base/src/org/compiere/model/X_C_DunningRun.java +++ b/base/src/org/compiere/model/X_C_DunningRun.java @@ -31,7 +31,7 @@ public class X_C_DunningRun extends PO implements I_C_DunningRun, I_Persistent /** * */ - private static final long serialVersionUID = 20090915L; + private static final long serialVersionUID = 20091004L; /** Standard Constructor */ public X_C_DunningRun (Properties ctx, int C_DunningRun_ID, String trxName) @@ -39,7 +39,7 @@ public class X_C_DunningRun extends PO implements I_C_DunningRun, I_Persistent super (ctx, C_DunningRun_ID, trxName); /** if (C_DunningRun_ID == 0) { - setC_DunningLevel_ID (0); + setC_Dunning_ID (0); setC_DunningRun_ID (0); setDunningDate (new Timestamp( System.currentTimeMillis() )); // @#Date@ @@ -75,6 +75,34 @@ public class X_C_DunningRun extends PO implements I_C_DunningRun, I_Persistent return sb.toString(); } + public I_C_Dunning getC_Dunning() throws RuntimeException + { + return (I_C_Dunning)MTable.get(getCtx(), I_C_Dunning.Table_Name) + .getPO(getC_Dunning_ID(), get_TrxName()); } + + /** Set Dunning. + @param C_Dunning_ID + Dunning Rules for overdue invoices + */ + public void setC_Dunning_ID (int C_Dunning_ID) + { + if (C_Dunning_ID < 1) + set_ValueNoCheck (COLUMNNAME_C_Dunning_ID, null); + else + set_ValueNoCheck (COLUMNNAME_C_Dunning_ID, Integer.valueOf(C_Dunning_ID)); + } + + /** Get Dunning. + @return Dunning Rules for overdue invoices + */ + public int getC_Dunning_ID () + { + Integer ii = (Integer)get_Value(COLUMNNAME_C_Dunning_ID); + if (ii == null) + return 0; + return ii.intValue(); + } + public I_C_DunningLevel getC_DunningLevel() throws RuntimeException { return (I_C_DunningLevel)MTable.get(getCtx(), I_C_DunningLevel.Table_Name) diff --git a/base/src/org/compiere/model/X_C_DunningRunEntry.java b/base/src/org/compiere/model/X_C_DunningRunEntry.java index 5de1e20502..3be6796935 100644 --- a/base/src/org/compiere/model/X_C_DunningRunEntry.java +++ b/base/src/org/compiere/model/X_C_DunningRunEntry.java @@ -32,7 +32,7 @@ public class X_C_DunningRunEntry extends PO implements I_C_DunningRunEntry, I_Pe /** * */ - private static final long serialVersionUID = 20090915L; + private static final long serialVersionUID = 20091004L; /** Standard Constructor */ public X_C_DunningRunEntry (Properties ctx, int C_DunningRunEntry_ID, String trxName) @@ -44,6 +44,8 @@ public class X_C_DunningRunEntry extends PO implements I_C_DunningRunEntry, I_Pe setC_BPartner_ID (0); setC_BPartner_Location_ID (0); setC_Currency_ID (0); + setC_DunningLevel_ID (0); +// @C_DunningLevel_ID@ setC_DunningRunEntry_ID (0); setC_DunningRun_ID (0); setProcessed (false); @@ -212,6 +214,31 @@ public class X_C_DunningRunEntry extends PO implements I_C_DunningRunEntry, I_Pe return ii.intValue(); } + public I_C_DunningLevel getC_DunningLevel() throws RuntimeException + { + return (I_C_DunningLevel)MTable.get(getCtx(), I_C_DunningLevel.Table_Name) + .getPO(getC_DunningLevel_ID(), get_TrxName()); } + + /** Set Dunning Level. + @param C_DunningLevel_ID Dunning Level */ + public void setC_DunningLevel_ID (int C_DunningLevel_ID) + { + if (C_DunningLevel_ID < 1) + set_ValueNoCheck (COLUMNNAME_C_DunningLevel_ID, null); + else + set_ValueNoCheck (COLUMNNAME_C_DunningLevel_ID, Integer.valueOf(C_DunningLevel_ID)); + } + + /** Get Dunning Level. + @return Dunning Level */ + public int getC_DunningLevel_ID () + { + Integer ii = (Integer)get_Value(COLUMNNAME_C_DunningLevel_ID); + if (ii == null) + return 0; + return ii.intValue(); + } + /** Set Dunning Run Entry. @param C_DunningRunEntry_ID Dunning Run Entry diff --git a/base/src/org/compiere/print/ReportEngine.java b/base/src/org/compiere/print/ReportEngine.java index a7bc470501..864fe97cc1 100644 --- a/base/src/org/compiere/print/ReportEngine.java +++ b/base/src/org/compiere/print/ReportEngine.java @@ -57,15 +57,15 @@ import org.apache.ecs.xhtml.td; import org.apache.ecs.xhtml.th; import org.apache.ecs.xhtml.tr; import org.compiere.model.MClient; +import org.compiere.model.MDunningRunEntry; +import org.compiere.model.MInOut; +import org.compiere.model.MInvoice; +import org.compiere.model.MOrder; +import org.compiere.model.MPaySelectionCheck; +import org.compiere.model.MProject; import org.compiere.model.MQuery; +import org.compiere.model.MRfQResponse; import org.compiere.model.PrintInfo; -import org.compiere.model.X_C_DunningRunEntry; -import org.compiere.model.X_C_Invoice; -import org.compiere.model.X_C_Order; -import org.compiere.model.X_C_PaySelectionCheck; -import org.compiere.model.X_C_Project; -import org.compiere.model.X_C_RfQResponse; -import org.compiere.model.X_M_InOut; import org.compiere.print.layout.LayoutEngine; import org.compiere.process.ProcessInfo; import org.compiere.util.CLogger; @@ -75,8 +75,8 @@ import org.compiere.util.Env; import org.compiere.util.Ini; import org.compiere.util.Language; import org.compiere.util.Util; -import org.eevolution.model.X_DD_Order; -import org.eevolution.model.X_PP_Order; +import org.eevolution.model.MDDOrder; +import org.eevolution.model.MPPOrder; /** * Report Engine. @@ -99,6 +99,8 @@ import org.eevolution.model.X_PP_Order; * https://sourceforge.net/tracker/?func=detail&aid=2828300&group_id=176962&atid=879332 *
  • BF [ 2828886 ] Problem with reports from temporary tables * https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2828886&group_id=176962 + * + * FR 2872010 - Dunning Run for a complete Dunning (not just level) - Developer: Carlos Ruiz - globalqss - Sponsor: Metas */ public class ReportEngine implements PrintServiceAttributeListener { @@ -1187,10 +1189,10 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) "C_PaySelectionCheck_ID", "C_PaySelectionCheck_ID", "C_DunningRunEntry_ID" , "PP_Order_ID" , "DD_Order_ID" }; private static final int[] DOC_TABLE_ID = new int[] { - X_C_Order.Table_ID, X_M_InOut.Table_ID, X_C_Invoice.Table_ID, X_C_Project.Table_ID, - X_C_RfQResponse.Table_ID, - X_C_PaySelectionCheck.Table_ID, X_C_PaySelectionCheck.Table_ID, - X_C_DunningRunEntry.Table_ID , X_PP_Order.Table_ID ,X_DD_Order.Table_ID }; + MOrder.Table_ID, MInOut.Table_ID, MInvoice.Table_ID, MProject.Table_ID, + MRfQResponse.Table_ID, + MPaySelectionCheck.Table_ID, MPaySelectionCheck.Table_ID, + MDunningRunEntry.Table_ID, MPPOrder.Table_ID, MDDOrder.Table_ID }; /************************************************************************** * Get Document Print Engine for Document Type. @@ -1257,7 +1259,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) + " INNER JOIN AD_Client c ON (d.AD_Client_ID=c.AD_Client_ID)" + " INNER JOIN C_BPartner bp ON (d.C_BPartner_ID=bp.C_BPartner_ID)" + " INNER JOIN C_DunningRun dr ON (d.C_DunningRun_ID=dr.C_DunningRun_ID)" - + " INNER JOIN C_DunningLevel dl ON (dl.C_DunningLevel_ID=dr.C_DunningLevel_ID) " + + " INNER JOIN C_DunningLevel dl ON (dl.C_DunningLevel_ID=d.C_DunningLevel_ID) " + "WHERE d.C_DunningRunEntry_ID=?"; // info from Dunning else if (type == REMITTANCE) sql = "SELECT pf.Remittance_PrintFormat_ID," diff --git a/base/src/org/compiere/process/DunningPrint.java b/base/src/org/compiere/process/DunningPrint.java index b178fd3afe..4380dca14b 100644 --- a/base/src/org/compiere/process/DunningPrint.java +++ b/base/src/org/compiere/process/DunningPrint.java @@ -29,7 +29,6 @@ import org.compiere.model.MQuery; import org.compiere.model.MUser; import org.compiere.model.MUserMail; import org.compiere.model.PrintInfo; -import org.compiere.model.X_C_DunningRunEntry; import org.compiere.print.MPrintFormat; import org.compiere.print.ReportEngine; import org.compiere.util.AdempiereUserError; @@ -40,6 +39,8 @@ import org.compiere.util.EMail; * * @author Jorg Janke * @version $Id: DunningPrint.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $ + * + * FR 2872010 - Dunning Run for a complete Dunning (not just level) - Developer: Carlos Ruiz - globalqss - Sponsor: Metas */ public class DunningPrint extends SvrProcess { @@ -108,10 +109,6 @@ public class DunningPrint extends SvrProcess MDunningRun run = new MDunningRun (getCtx(), p_C_DunningRun_ID, get_TrxName()); if (run.get_ID() == 0) throw new AdempiereUserError ("@NotFound@: @C_DunningRun_ID@ - " + p_C_DunningRun_ID); - // Print Format on Dunning Level - MDunningLevel level = new MDunningLevel (getCtx(), run.getC_DunningLevel_ID(), get_TrxName()); - MPrintFormat format = MPrintFormat.get (getCtx(), level.getDunning_PrintFormat_ID(), false); - MClient client = MClient.get(getCtx()); int count = 0; @@ -120,6 +117,13 @@ public class DunningPrint extends SvrProcess for (int i = 0; i < entries.length; i++) { MDunningRunEntry entry = entries[i]; + + // Print Format on Dunning Level + MDunningLevel level = new MDunningLevel (getCtx(), entry.getC_DunningLevel_ID(), get_TrxName()); + MPrintFormat format = null; + if (level.getDunning_PrintFormat_ID() > 0) + format = MPrintFormat.get (getCtx(), level.getDunning_PrintFormat_ID(), false); + if (p_IsOnlyIfBPBalance && entry.getAmt().signum() <= 0) continue; if (p_PrintUnprocessedOnly && entry.isProcessed()) @@ -157,11 +161,13 @@ public class DunningPrint extends SvrProcess // Engine PrintInfo info = new PrintInfo( bp.getName(), - X_C_DunningRunEntry.Table_ID, + MDunningRunEntry.Table_ID, entry.getC_DunningRunEntry_ID(), entry.getC_BPartner_ID()); info.setDescription(bp.getName() + ", Amt=" + entry.getAmt()); - ReportEngine re = new ReportEngine(getCtx(), format, query, info); + ReportEngine re = null; + if (format != null) + re = new ReportEngine(getCtx(), format, query, info); boolean printed = false; if (p_EMailPDF) { @@ -185,9 +191,11 @@ public class DunningPrint extends SvrProcess email.setMessageText (message); } // - File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf")); - log.fine(to + " - " + attachment); - email.addAttachment(attachment); + if (re != null) { + File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf")); + log.fine(to + " - " + attachment); + email.addAttachment(attachment); + } // String msg = email.send(); MUserMail um = new MUserMail(mText, entry.getAD_User_ID(), email); @@ -208,9 +216,11 @@ public class DunningPrint extends SvrProcess } else { - re.print (); - count++; - printed = true; + if (re != null) { + re.print (); + count++; + printed = true; + } } if (printed) { diff --git a/base/src/org/compiere/process/DunningRunCreate.java b/base/src/org/compiere/process/DunningRunCreate.java index ea3b3c478e..ab4f62b533 100644 --- a/base/src/org/compiere/process/DunningRunCreate.java +++ b/base/src/org/compiere/process/DunningRunCreate.java @@ -38,6 +38,8 @@ import org.compiere.util.Env; * * @author Jorg Janke * @version $Id: DunningRunCreate.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $ + * + * FR 2872010 - Dunning Run for a complete Dunning (not just level) - Developer: Carlos Ruiz - globalqss - Sponsor: Metas */ public class DunningRunCreate extends SvrProcess { @@ -52,7 +54,6 @@ public class DunningRunCreate extends SvrProcess private int p_AD_Org_ID = 0; private MDunningRun m_run = null; - private MDunningLevel m_level = null; /** * Prepare - e.g., get Parameters. @@ -108,23 +109,27 @@ public class DunningRunCreate extends SvrProcess if (p_C_Currency_ID == 0) throw new IllegalArgumentException ("No Currency"); // - m_level = m_run.getLevel (); - - int inv = addInvoices(); - int pay = addPayments(); - - if (m_level.isChargeFee ()) - addFees(); - + int inv = 0; + int pay = 0; + for (MDunningLevel l_level : m_run.getLevels()) { + + inv += addInvoices(l_level); + pay += addPayments(l_level); + + if (l_level.isChargeFee ()) + addFees(l_level); + } + return "@C_Invoice_ID@ #" + inv + " - @C_Payment_ID@=" + pay; } // doIt /************************************************************************** * Add Invoices to Run - * @return no of invoices + * @param level the Dunning level + * @return no of invoices */ - private int addInvoices() + private int addInvoices(MDunningLevel level) { int count = 0; String sql = "SELECT i.C_Invoice_ID, i.C_Currency_ID," @@ -164,9 +169,9 @@ public class DunningRunCreate extends SvrProcess // if sequentially we must check for other levels with smaller days for // which this invoice is not yet included! MDunningLevel[] previousLevels = null; - if (m_level.getParent ().isCreateLevelsSequentially ()) { + if (level.getParent ().isCreateLevelsSequentially ()) { // Build a list of all topmost Dunning Levels - previousLevels = m_level.getPreviousLevels(); + previousLevels = level.getPreviousLevels(); if (previousLevels!=null && previousLevels.length>0) { String sqlAppend = ""; for (int i=0; ipreviousLevels.length - && !m_level.isShowAllDue() && !m_level.isShowNotDue()) { + if (level.getParent().isCreateLevelsSequentially() && previousLevels!=null && TimesDunned>previousLevels.length + && !level.isShowAllDue() && !level.isShowNotDue()) + { continue; } log.fine(DaysBetweenDunning + " - " + DaysAfterLast); - if (DaysBetweenDunning != 0 && DaysAfterLast < DaysBetweenDunning && !m_level.isShowAllDue () && !m_level.isShowNotDue ()) + if (DaysBetweenDunning != 0 && DaysAfterLast < DaysBetweenDunning && !level.isShowAllDue() && !level.isShowNotDue()) continue; // - if (createInvoiceLine (C_Invoice_ID, C_InvoicePaySchedule_ID, C_Currency_ID, GrandTotal, Open, - DaysDue, IsInDispute, C_BPartner_ID, - TimesDunned, DaysAfterLast)) + if (createInvoiceLine(C_Invoice_ID, C_InvoicePaySchedule_ID, C_Currency_ID, GrandTotal, Open, + DaysDue, IsInDispute, C_BPartner_ID, + TimesDunned, DaysAfterLast, level.getC_DunningLevel_ID())) { count++; } @@ -288,16 +294,17 @@ public class DunningRunCreate extends SvrProcess * @param C_BPartner_ID * @param TimesDunned * @param DaysAfterLast + * @param c_DunningLevel_ID */ private boolean createInvoiceLine (int C_Invoice_ID, int C_InvoicePaySchedule_ID, int C_Currency_ID, BigDecimal GrandTotal, BigDecimal Open, int DaysDue, boolean IsInDispute, - int C_BPartner_ID, int TimesDunned, int DaysAfterLast) + int C_BPartner_ID, int TimesDunned, int DaysAfterLast, int c_DunningLevel_ID) { MDunningRunEntry entry = null; try { - entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID); + entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID); } catch (BPartnerNoAddressException e) { @@ -322,7 +329,7 @@ public class DunningRunCreate extends SvrProcess if (!line.save()) throw new IllegalStateException("Cannot save MDunningRunLine"); MInvoice invoice = new MInvoice(getCtx(),C_Invoice_ID, get_TrxName()); - invoice.setC_DunningLevel_ID(m_run.getC_DunningLevel_ID()); + invoice.setC_DunningLevel_ID(c_DunningLevel_ID); if (!invoice.save()) throw new IllegalStateException("Cannot update dunning level information in invoice"); @@ -332,9 +339,10 @@ public class DunningRunCreate extends SvrProcess /************************************************************************** * Add Payments to Run + * @param level the Dunning level * @return no of payments */ - private int addPayments() + private int addPayments(MDunningLevel level) { String sql = "SELECT C_Payment_ID, C_Currency_ID, PayAmt," + " paymentAvailable(C_Payment_ID), C_BPartner_ID " @@ -364,7 +372,7 @@ public class DunningRunCreate extends SvrProcess { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getAD_Client_ID()); - pstmt.setInt (2, m_run.getC_DunningLevel_ID()); + pstmt.setInt (2, level.getC_DunningLevel_ID()); if (p_C_BPartner_ID != 0) pstmt.setInt (3, p_C_BPartner_ID); else if (p_C_BP_Group_ID != 0) @@ -383,7 +391,7 @@ public class DunningRunCreate extends SvrProcess continue; // if (createPaymentLine (C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt, - C_BPartner_ID)) + C_BPartner_ID, level.getC_DunningLevel_ID())) { count++; } @@ -409,13 +417,14 @@ public class DunningRunCreate extends SvrProcess * @param PayAmt * @param OpenAmt * @param C_BPartner_ID + * @param c_DunningLevel_ID */ private boolean createPaymentLine (int C_Payment_ID, int C_Currency_ID, - BigDecimal PayAmt, BigDecimal OpenAmt, int C_BPartner_ID) + BigDecimal PayAmt, BigDecimal OpenAmt, int C_BPartner_ID, int c_DunningLevel_ID) { MDunningRunEntry entry = null; try { - entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID); + entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID); } catch (BPartnerNoAddressException e) { MPayment payment = new MPayment(getCtx(), C_Payment_ID, null); String msg = "@Skip@ @C_Payment_ID@ " + payment.getDocumentInfo() @@ -435,13 +444,13 @@ public class DunningRunCreate extends SvrProcess return true; } // createPaymentLine - private void addFees() + private void addFees(MDunningLevel level) { MDunningRunEntry [] entries = m_run.getEntries (true); if (entries!=null && entries.length>0) { for (int i=0;i