Implement [2902882] - Dunning Stabilization

https://sourceforge.net/tracker/index.php?func=detail&aid=2902882&group_id=176962&atid=879335
This commit is contained in:
Carlos Ruiz 2009-11-27 17:40:40 +00:00
parent 756b6dc2de
commit b6d614c696
11 changed files with 805 additions and 161 deletions

View File

@ -244,9 +244,11 @@ public class Doc_Cash extends Doc
} }
} // lines } // lines
// Cash Asset if (assetAmt.compareTo(Env.ZERO) != 0) { // Carlos Ruiz - globalqss [BF 2904269]
fact.createLine(null, getAccount(Doc.ACCTTYPE_CashAsset, as), // Cash Asset
getC_Currency_ID(), assetAmt); fact.createLine(null, getAccount(Doc.ACCTTYPE_CashAsset, as),
getC_Currency_ID(), assetAmt);
}
// //
ArrayList<Fact> facts = new ArrayList<Fact>(); ArrayList<Fact> facts = new ArrayList<Fact>();

View File

@ -223,6 +223,19 @@ public interface I_C_DunningLevel
*/ */
public BigDecimal getInterestPercent(); public BigDecimal getInterestPercent();
/** Column name InvoiceCollectionType */
public static final String COLUMNNAME_InvoiceCollectionType = "InvoiceCollectionType";
/** Set Collection Status.
* Invoice Collection Status
*/
public void setInvoiceCollectionType (String InvoiceCollectionType);
/** Get Collection Status.
* Invoice Collection Status
*/
public String getInvoiceCollectionType();
/** Column name IsActive */ /** Column name IsActive */
public static final String COLUMNNAME_IsActive = "IsActive"; public static final String COLUMNNAME_IsActive = "IsActive";
@ -288,6 +301,19 @@ public interface I_C_DunningLevel
*/ */
public boolean isShowNotDue(); public boolean isShowNotDue();
/** Column name IsStatement */
public static final String COLUMNNAME_IsStatement = "IsStatement";
/** Set Is Statement.
* Dunning Level is a definition of a statement
*/
public void setIsStatement (boolean IsStatement);
/** Get Is Statement.
* Dunning Level is a definition of a statement
*/
public boolean isStatement();
/** Column name Name */ /** Column name Name */
public static final String COLUMNNAME_Name = "Name"; public static final String COLUMNNAME_Name = "Name";

View File

@ -31,7 +31,7 @@ public class MDunning extends X_C_Dunning
/** /**
* *
*/ */
private static final long serialVersionUID = 796291742140033745L; private static final long serialVersionUID = -3844081441218291895L;
/** /**
* Standard Constructor * Standard Constructor
@ -55,4 +55,18 @@ public class MDunning extends X_C_Dunning
super(ctx, rs, trxName); super(ctx, rs, trxName);
} // MDunning } // MDunning
/**
* String Representation
* @return info
*/
@Override
public String toString()
{
StringBuffer sb = new StringBuffer("MDunning[").append(get_ID())
.append("-").append(getName());
sb.append("]");
return sb.toString();
} // toString
} // MDunning } // MDunning

View File

@ -39,7 +39,7 @@ public class MDunningRun extends X_C_DunningRun
/** /**
* *
*/ */
private static final long serialVersionUID = 8450276205229694644L; private static final long serialVersionUID = 6858939271415643483L;
/** /**
* Standard Constructor * Standard Constructor
@ -88,6 +88,7 @@ public class MDunningRun extends X_C_DunningRun
MDunningLevel.Table_Name, MDunningLevel.Table_Name,
"C_Dunning_ID=? AND C_DunningLevel_ID=?", "C_Dunning_ID=? AND C_DunningLevel_ID=?",
get_TrxName()) get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(new Object[]{getC_Dunning_ID(), getC_DunningLevel_ID()}) .setParameters(new Object[]{getC_Dunning_ID(), getC_DunningLevel_ID()})
.setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID") .setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID")
.list(); .list();
@ -98,6 +99,7 @@ public class MDunningRun extends X_C_DunningRun
MDunningLevel.Table_Name, MDunningLevel.Table_Name,
"C_Dunning_ID=?", "C_Dunning_ID=?",
get_TrxName()) get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(new Object[]{getC_Dunning_ID()}) .setParameters(new Object[]{getC_Dunning_ID()})
.setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID") .setOrderBy("DaysAfterDue DESC, C_DunningLevel_ID")
.list(); .list();
@ -113,6 +115,17 @@ public class MDunningRun extends X_C_DunningRun
* @return entries * @return entries
*/ */
public MDunningRunEntry[] getEntries (boolean requery) public MDunningRunEntry[] getEntries (boolean requery)
{
return getEntries(requery, false);
}
/**
* Get Entries
* @param requery requery requery
* @param onlyInvoices only invoices
* @return entries
*/
public MDunningRunEntry[] getEntries (boolean requery, boolean onlyInvoices)
{ {
if (m_entries != null && !requery) if (m_entries != null && !requery)
return m_entries; return m_entries;
@ -126,14 +139,18 @@ public class MDunningRun extends X_C_DunningRun
pstmt.setInt (1, getC_DunningRun_ID()); pstmt.setInt (1, getC_DunningRun_ID());
ResultSet rs = pstmt.executeQuery (); ResultSet rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{
MDunningRunEntry thisEntry = new MDunningRunEntry(getCtx(), rs, get_TrxName());
if (!(onlyInvoices && thisEntry.hasInvoices()))
list.add (new MDunningRunEntry(getCtx(), rs, get_TrxName())); list.add (new MDunningRunEntry(getCtx(), rs, get_TrxName()));
}
rs.close (); rs.close ();
pstmt.close (); pstmt.close ();
pstmt = null; pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "getEntries", e); log.log(Level.SEVERE, sql, e);
} }
try try
{ {
@ -158,9 +175,7 @@ public class MDunningRun extends X_C_DunningRun
public boolean deleteEntries(boolean force) public boolean deleteEntries(boolean force)
{ {
getEntries(true); getEntries(true);
for (int i = 0; i < m_entries.length; i++) for (MDunningRunEntry entry : m_entries) {
{
MDunningRunEntry entry = m_entries[i];
entry.delete(force); entry.delete(force);
} }
boolean ok = getEntries(true).length == 0; boolean ok = getEntries(true).length == 0;

View File

@ -42,7 +42,7 @@ public class MDunningRunEntry extends X_C_DunningRunEntry
/** /**
* *
*/ */
private static final long serialVersionUID = 2028055451030209868L; private static final long serialVersionUID = -3838792682143065656L;
/** Logger */ /** Logger */
private static CLogger s_log = CLogger.getCLogger (MPayment.class); private static CLogger s_log = CLogger.getCLogger (MPayment.class);
@ -187,9 +187,21 @@ public class MDunningRunEntry extends X_C_DunningRunEntry
* @return Array of all lines for this Run * @return Array of all lines for this Run
*/ */
public MDunningRunLine[] getLines() public MDunningRunLine[] getLines()
{
return getLines(false);
} // getLines
/**
* Get Lines
* @param onlyInvoices only with invoices
* @return Array of all lines for this Run
*/
public MDunningRunLine[] getLines (boolean onlyInvoices)
{ {
ArrayList<MDunningRunLine> list = new ArrayList<MDunningRunLine>(); ArrayList<MDunningRunLine> list = new ArrayList<MDunningRunLine>();
String sql = "SELECT * FROM C_DunningRunLine WHERE C_DunningRunEntry_ID=?"; String sql = "SELECT * FROM C_DunningRunLine WHERE C_DunningRunEntry_ID=?";
if (onlyInvoices)
sql += " AND C_Invoice_ID IS NOT NULL";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
@ -221,7 +233,47 @@ public class MDunningRunEntry extends X_C_DunningRunEntry
MDunningRunLine[] retValue = new MDunningRunLine[list.size()]; MDunningRunLine[] retValue = new MDunningRunLine[list.size()];
list.toArray(retValue); list.toArray(retValue);
return retValue; return retValue;
} // getLines
/**
* Check whether has Invoices
* @return true if it has Invoices
*/
public boolean hasInvoices()
{
boolean retValue = false;
String sql = "SELECT COUNT(*) FROM C_DunningRunLine WHERE C_DunningRunEntry_ID=? AND C_Invoice_ID IS NOT NULL";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, get_ID ());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
if (rs.getInt(1) > 0)
retValue = true;
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
return retValue;
} // hasInvoices
/** /**
* Get Parent * Get Parent
@ -245,7 +297,7 @@ public class MDunningRunEntry extends X_C_DunningRunEntry
for (int i=0;i<theseLines.length;i++) for (int i=0;i<theseLines.length;i++)
{ {
theseLines[i].setProcessed (true); theseLines[i].setProcessed (true);
theseLines[i].save (get_TrxName()); theseLines[i].saveEx(get_TrxName());
} }
if (level.isSetCreditStop () || level.isSetPaymentTerm ()) if (level.isSetCreditStop () || level.isSetPaymentTerm ())
{ {

View File

@ -272,6 +272,7 @@ public class MDunningRunLine extends X_C_DunningRunLine
* @param newRecord new * @param newRecord new
* @return true * @return true
*/ */
@Override
protected boolean beforeSave (boolean newRecord) protected boolean beforeSave (boolean newRecord)
{ {
// Set Amt // Set Amt
@ -288,16 +289,23 @@ public class MDunningRunLine extends X_C_DunningRunLine
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID())); getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
// Total // Total
setTotalAmt(getConvertedAmt().add(getFeeAmt()).add(getInterestAmt())); setTotalAmt(getConvertedAmt().add(getFeeAmt()).add(getInterestAmt()));
// Reset Collection Status only if null // Set Collection Status
if (getInvoice()!=null && getInvoice().getInvoiceCollectionType ()==null) if (isProcessed() && getInvoice() != null)
{ {
if (m_invoice!=null) I_C_DunningLevel level = getParent().getC_DunningLevel();
{ if (level != null) {
m_invoice.setInvoiceCollectionType (X_C_Invoice.INVOICECOLLECTIONTYPE_Dunning); getInvoice().setC_DunningLevel_ID(level.getC_DunningLevel_ID());
m_invoice.save (); if (level.getInvoiceCollectionType() != null) {
getInvoice().setInvoiceCollectionType (level.getInvoiceCollectionType());
} else {
if (! level.isStatement()) {
getInvoice().setInvoiceCollectionType (MInvoice.INVOICECOLLECTIONTYPE_Dunning);
}
}
getInvoice().saveEx();
} }
} }
//
return true; return true;
} // beforeSave } // beforeSave

View File

@ -32,7 +32,7 @@ public class X_C_DunningLevel extends PO implements I_C_DunningLevel, I_Persiste
/** /**
* *
*/ */
private static final long serialVersionUID = 20090915L; private static final long serialVersionUID = 20091123L;
/** Standard Constructor */ /** Standard Constructor */
public X_C_DunningLevel (Properties ctx, int C_DunningLevel_ID, String trxName) public X_C_DunningLevel (Properties ctx, int C_DunningLevel_ID, String trxName)
@ -50,6 +50,8 @@ public class X_C_DunningLevel extends PO implements I_C_DunningLevel, I_Persiste
setIsSetPaymentTerm (false); setIsSetPaymentTerm (false);
setIsShowAllDue (false); setIsShowAllDue (false);
setIsShowNotDue (false); setIsShowNotDue (false);
setIsStatement (false);
// N
setName (null); setName (null);
setPrintName (null); setPrintName (null);
} */ } */
@ -332,6 +334,34 @@ public class X_C_DunningLevel extends PO implements I_C_DunningLevel, I_Persiste
return bd; return bd;
} }
/** InvoiceCollectionType AD_Reference_ID=394 */
public static final int INVOICECOLLECTIONTYPE_AD_Reference_ID=394;
/** Dunning = D */
public static final String INVOICECOLLECTIONTYPE_Dunning = "D";
/** Collection Agency = C */
public static final String INVOICECOLLECTIONTYPE_CollectionAgency = "C";
/** Legal Procedure = L */
public static final String INVOICECOLLECTIONTYPE_LegalProcedure = "L";
/** Uncollectable = U */
public static final String INVOICECOLLECTIONTYPE_Uncollectable = "U";
/** Set Collection Status.
@param InvoiceCollectionType
Invoice Collection Status
*/
public void setInvoiceCollectionType (String InvoiceCollectionType)
{
set_Value (COLUMNNAME_InvoiceCollectionType, InvoiceCollectionType);
}
/** Get Collection Status.
@return Invoice Collection Status
*/
public String getInvoiceCollectionType ()
{
return (String)get_Value(COLUMNNAME_InvoiceCollectionType);
}
/** Set Credit Stop. /** Set Credit Stop.
@param IsSetCreditStop @param IsSetCreditStop
Set the business partner to credit stop Set the business partner to credit stop
@ -428,6 +458,30 @@ public class X_C_DunningLevel extends PO implements I_C_DunningLevel, I_Persiste
return false; return false;
} }
/** Set Is Statement.
@param IsStatement
Dunning Level is a definition of a statement
*/
public void setIsStatement (boolean IsStatement)
{
set_Value (COLUMNNAME_IsStatement, Boolean.valueOf(IsStatement));
}
/** Get Is Statement.
@return Dunning Level is a definition of a statement
*/
public boolean isStatement ()
{
Object oo = get_Value(COLUMNNAME_IsStatement);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}
/** Set Name. /** Set Name.
@param Name @param Name
Alphanumeric identifier of the entity Alphanumeric identifier of the entity

View File

@ -83,7 +83,7 @@ public class DunningPrint extends SvrProcess
} // prepare } // prepare
/** /**
* Pocess * Process
* @return info * @return info
* @throws Exception * @throws Exception
*/ */

View File

@ -109,18 +109,21 @@ public class DunningRunCreate extends SvrProcess
if (p_C_Currency_ID == 0) if (p_C_Currency_ID == 0)
throw new IllegalArgumentException ("No Currency"); throw new IllegalArgumentException ("No Currency");
// //
int inv = 0;
int pay = 0;
for (MDunningLevel l_level : m_run.getLevels()) { for (MDunningLevel l_level : m_run.getLevels()) {
inv += addInvoices(l_level); addInvoices(l_level);
pay += addPayments(l_level); addPayments(l_level);
if (l_level.isChargeFee ()) if (l_level.isChargeFee ())
addFees(l_level); addFees(l_level);
// we need to check whether this is a statement or not and some other rules
checkDunningEntry(l_level);
} }
return "@C_Invoice_ID@ #" + inv + " - @C_Payment_ID@=" + pay; int entries = DB.getSQLValue(get_TrxName(), "SELECT COUNT(*) FROM C_DunningRunEntry WHERE C_DunningRun_ID=?", m_run.get_ID());
return "@C_DunningRunEntry_ID@ #" + entries;
} // doIt } // doIt
@ -168,28 +171,26 @@ public class DunningRunCreate extends SvrProcess
// if sequentially we must check for other levels with smaller days for // if sequentially we must check for other levels with smaller days for
// which this invoice is not yet included! // which this invoice is not yet included!
MDunningLevel[] previousLevels = null;
if (level.getParent ().isCreateLevelsSequentially ()) { if (level.getParent ().isCreateLevelsSequentially ()) {
// Build a list of all topmost Dunning Levels // Build a list of all topmost Dunning Levels
previousLevels = level.getPreviousLevels(); MDunningLevel[] previousLevels = level.getPreviousLevels();
if (previousLevels!=null && previousLevels.length>0) { if (previousLevels!=null && previousLevels.length>0) {
String sqlAppend = ""; String sqlAppend = "";
for (int i=0; i<previousLevels.length; i++) for (MDunningLevel element : previousLevels) {
{
sqlAppend += " AND i.C_Invoice_ID IN (SELECT C_Invoice_ID FROM C_DunningRunLine WHERE " + sqlAppend += " AND i.C_Invoice_ID IN (SELECT C_Invoice_ID FROM C_DunningRunLine WHERE " +
"C_DunningRunEntry_ID IN (SELECT C_DunningRunEntry_ID FROM C_DunningRunEntry WHERE " + "C_DunningRunEntry_ID IN (SELECT C_DunningRunEntry_ID FROM C_DunningRunEntry WHERE " +
"C_DunningRun_ID IN (SELECT C_DunningRun_ID FROM C_DunningRun WHERE " + "C_DunningRun_ID IN (SELECT C_DunningRun_ID FROM C_DunningRunEntry WHERE " +
"C_DunningLevel_ID=" + previousLevels[i].get_ID () + ")) AND Processed<>'N')"; "C_DunningLevel_ID=" + element.get_ID () + ")) AND Processed<>'N')";
} }
sql += sqlAppend; sql += sqlAppend;
} }
} }
sql2 = "SELECT COUNT(*), COALESCE(TRUNC(?-MAX(dr.DunningDate)),0) " // ensure that we do only dunn what's not yet dunned, so we lookup the max of last Dunn Date which was processed
+ "FROM C_DunningRun dr" sql2 = "SELECT COUNT(*), COALESCE(DAYSBETWEEN(MAX(dr2.DunningDate), MAX(dr.DunningDate)),0)"
+ "FROM C_DunningRun dr2, C_DunningRun dr"
+ " INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)" + " INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)"
+ " INNER JOIN C_DunningRunLine drl ON (dre.C_DunningRunEntry_ID=drl.C_DunningRunEntry_ID) " + " INNER JOIN C_DunningRunLine drl ON (dre.C_DunningRunEntry_ID=drl.C_DunningRunEntry_ID) "
+ "WHERE drl.Processed='Y' AND drl.C_Invoice_ID=? AND COALESCE(drl.C_InvoicePaySchedule_ID, 0)=?"; + "WHERE dr2.C_DunningRun_ID=? AND drl.C_Invoice_ID=?"; // ##1 ##2
BigDecimal DaysAfterDue = level.getDaysAfterDue(); BigDecimal DaysAfterDue = level.getDaysAfterDue();
int DaysBetweenDunning = level.getDaysBetweenDunning(); int DaysBetweenDunning = level.getDaysBetweenDunning();
@ -228,19 +229,21 @@ public class DunningRunCreate extends SvrProcess
log.fine("C_Invoice_ID - DaysDue - GrandTotal: " + C_Invoice_ID + " - " + DaysDue + " - " + GrandTotal); log.fine("C_Invoice_ID - DaysDue - GrandTotal: " + C_Invoice_ID + " - " + DaysDue + " - " + GrandTotal);
log.fine("C_InvoicePaySchedule_ID: " + C_InvoicePaySchedule_ID); log.fine("C_InvoicePaySchedule_ID: " + C_InvoicePaySchedule_ID);
// //
// Check for Dispute
if (!p_IncludeInDispute && IsInDispute) if (!p_IncludeInDispute && IsInDispute)
continue; continue;
if (DaysDue < DaysAfterDue.intValue() && !level.isShowAllDue()) // Check the day again based on rulesets
if (DaysDue > 0 && DaysDue < DaysAfterDue.intValue() && !level.isShowAllDue ())
continue; continue;
// Check for an open amount
if (Env.ZERO.compareTo(Open) == 0) if (Env.ZERO.compareTo(Open) == 0)
continue; continue;
// //
int TimesDunned = 0; int TimesDunned = 0;
int DaysAfterLast = 0; int DaysAfterLast = 0;
// SubQuery // SubQuery
pstmt2.setTimestamp(1, m_run.getDunningDate()); pstmt2.setInt (1, m_run.get_ID ());
pstmt2.setInt (2, C_Invoice_ID); pstmt2.setInt (2, C_Invoice_ID);
pstmt2.setInt (3, C_InvoicePaySchedule_ID);
ResultSet rs2 = pstmt2.executeQuery (); ResultSet rs2 = pstmt2.executeQuery ();
if (rs2.next()) if (rs2.next())
{ {
@ -248,18 +251,24 @@ public class DunningRunCreate extends SvrProcess
DaysAfterLast = rs2.getInt(2); DaysAfterLast = rs2.getInt(2);
} }
rs2.close(); rs2.close();
if (previousLevels != null) {
log.fine(TimesDunned + " - " + previousLevels.length);
}
// SubQuery // SubQuery
if (level.getParent().isCreateLevelsSequentially() && previousLevels!=null && TimesDunned>previousLevels.length
&& !level.isShowAllDue() && !level.isShowNotDue()) // Ensure that Daysbetween Dunning is enforced
{ // Ensure Not ShowAllDue and Not ShowNotDue is selected
// PROBLEM: If you have ShowAll activated then DaysBetweenDunning is not working, because we don't know whether
// there is something which we really must Dunn.
if (DaysBetweenDunning != 0 && TimesDunned > 0 && DaysAfterLast < DaysBetweenDunning && !level.isShowAllDue () && !level.isShowNotDue ())
continue; continue;
}
log.fine(DaysBetweenDunning + " - " + DaysAfterLast); // We don't want to show non due documents
if (DaysBetweenDunning != 0 && DaysAfterLast < DaysBetweenDunning && !level.isShowAllDue() && !level.isShowNotDue()) if (DaysDue<0 && !level.isShowNotDue ())
continue; continue;
// We will minus the timesDunned if this is the DaysBetweenDunning is not fullfilled.
// Remember in checkup later we must reset them!
// See also checkDunningEntry()
if (DaysAfterLast < DaysBetweenDunning)
TimesDunned = TimesDunned*-1;
// //
if (createInvoiceLine(C_Invoice_ID, C_InvoicePaySchedule_ID, C_Currency_ID, GrandTotal, Open, if (createInvoiceLine(C_Invoice_ID, C_InvoicePaySchedule_ID, C_Currency_ID, GrandTotal, Open,
DaysDue, IsInDispute, C_BPartner_ID, DaysDue, IsInDispute, C_BPartner_ID,
@ -328,10 +337,6 @@ public class DunningRunCreate extends SvrProcess
line.setC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID); line.setC_InvoicePaySchedule_ID(C_InvoicePaySchedule_ID);
if (!line.save()) if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine"); throw new IllegalStateException("Cannot save MDunningRunLine");
MInvoice invoice = new MInvoice(getCtx(),C_Invoice_ID, get_TrxName());
invoice.setC_DunningLevel_ID(c_DunningLevel_ID);
if (!invoice.save())
throw new IllegalStateException("Cannot update dunning level information in invoice");
return true; return true;
} // createInvoiceLine } // createInvoiceLine
@ -351,15 +356,24 @@ public class DunningRunCreate extends SvrProcess
+ " AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL" + " AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL"
+ " AND C_Charge_ID IS NULL" + " AND C_Charge_ID IS NULL"
+ " AND DocStatus IN ('CO','CL')" + " AND DocStatus IN ('CO','CL')"
// Only BP with Dunning defined // Only BP(Group) with Dunning defined
+ " AND EXISTS (SELECT * FROM C_BPartner bp " + " AND EXISTS (SELECT * FROM C_DunningLevel dl "
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID" + "WHERE dl.C_DunningLevel_ID=?" // // ##2
+ " AND bp.C_Dunning_ID=(SELECT C_Dunning_ID FROM C_DunningLevel WHERE C_DunningLevel_ID=?))"; // ##2 + " AND dl.C_Dunning_ID IN "
+ "(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) "
+ "FROM C_BPartner bp"
+ " INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) "
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID))";
if (p_C_BPartner_ID != 0) if (p_C_BPartner_ID != 0)
sql += " AND C_BPartner_ID=?"; // ##3 sql += " AND C_BPartner_ID=?"; // ##3
else if (p_C_BP_Group_ID != 0) else if (p_C_BP_Group_ID != 0)
sql += " AND EXISTS (SELECT * FROM C_BPartner bp " sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##3 + "WHERE p.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##3
// If it is not a statement we will add lines only if InvoiceLines exists,
// because we do not want to dunn for money we owe the customer!
if (!level.isStatement())
sql += " AND C_BPartner_ID IN (SELECT C_BPartner_ID FROM C_DunningRunEntry WHERE C_DunningRun_ID=" + m_run.get_ID () + ")";
// show only receipts / if only Sales
if (p_OnlySOTrx) if (p_OnlySOTrx)
sql += " AND IsReceipt='Y'"; sql += " AND IsReceipt='Y'";
if ( p_AD_Org_ID != 0 ) if ( p_AD_Org_ID != 0 )
@ -444,18 +458,64 @@ public class DunningRunCreate extends SvrProcess
return true; return true;
} // createPaymentLine } // createPaymentLine
/**
* Add Fees for every line
*/
private void addFees(MDunningLevel level) private void addFees(MDunningLevel level)
{ {
MDunningRunEntry [] entries = m_run.getEntries (true); // Only add a fee if it contains InvoiceLines and is not a statement
if (entries!=null && entries.length>0) { boolean onlyInvoices = level.isStatement();
for (int i=0;i<entries.length;i++) { MDunningRunEntry [] entries = m_run.getEntries (true, onlyInvoices);
MDunningRunLine line = new MDunningRunLine (entries[i]); if (entries != null && entries.length > 0)
{
for (MDunningRunEntry element : entries) {
if (level.isShowAllDue() && level.isShowNotDue() && element.getAmt().compareTo(Env.ZERO) < 0)
// showing all the invoices and the amount of the entry is negative - don't generate a fee
continue;
MDunningRunLine line = new MDunningRunLine (element);
line.setFee (p_C_Currency_ID, level.getFeeAmt()); line.setFee (p_C_Currency_ID, level.getFeeAmt());
if (!line.save()) if (!line.save())
throw new IllegalStateException("Cannot save MDunningRunLine"); throw new IllegalStateException("Cannot save MDunningRunLine");
entries[i].setQty (entries[i].getQty ().subtract (new BigDecimal(1))); element.setQty (element.getQty ().subtract (new BigDecimal(1)));
}
} }
} }
} // addFees
/**
* Check the dunning run
* 1) Check for following Rule: ShowAll should produce only a record if at least one new line is found
*/
private void checkDunningEntry(MDunningLevel level)
{
// Check rule 1)
if (level.isShowAllDue ()) {
MDunningRunEntry [] entries = m_run.getEntries (true);
if (entries != null && entries.length > 0)
{
for (MDunningRunEntry element : entries) {
// We start with saying we delete this entry as long as we don't find something new
boolean entryDelete = true;
MDunningRunLine [] lines = element.getLines (true);
for (int j = 0; j < lines.length; j++)
{
if (lines[j].getTimesDunned() < 0)
{
// We clean up the *-1 from line 255
lines[j].setTimesDunned (lines[j].getTimesDunned()*-1);
if (!lines[j].save())
throw new IllegalStateException("Cannot save MDunningRunLine");
}
else
{
// We found something new, so we would not save anything...
entryDelete = false;
}
}
if(entryDelete)
element.delete (false);
}
}
}
} // checkDunningEntry
} // DunningRunCreate } // DunningRunCreate

View File

@ -0,0 +1,206 @@
-- Nov 23, 2009 9:06:59 PM COT
-- FR2902882-Dunning Stabilization
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Reference_Value_ID,AD_Table_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,58591,3092,0,17,394,331,'InvoiceCollectionType',TO_DATE('2009-11-23 21:06:55','YYYY-MM-DD HH24:MI:SS'),100,'Invoice Collection Status','D',1,'Status of the invoice collection process','Y','Y','N','N','N','N','N','N','N','N','N','N','Y','Collection Status',0,TO_DATE('2009-11-23 21:06:55','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Nov 23, 2009 9:06:59 PM COT
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=58591 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Nov 23, 2009 9:07:09 PM COT
ALTER TABLE C_DunningLevel ADD InvoiceCollectionType CHAR(1) DEFAULT NULL
;
-- Nov 23, 2009 9:08:03 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,58591,58079,0,268,TO_DATE('2009-11-23 21:08:00','YYYY-MM-DD HH24:MI:SS'),100,'Invoice Collection Status',0,'D','Status of the invoice collection process','Y','Y','Y','N','N','N','N','N','Collection Status',210,0,TO_DATE('2009-11-23 21:08:00','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:08:03 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=58079 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Nov 23, 2009 9:09:31 PM COT
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,54076,0,'IsStatement',TO_DATE('2009-11-23 21:09:31','YYYY-MM-DD HH24:MI:SS'),100,'Dunning Level is a definition of a statement','D','Y','Is Statement','Is Statement',TO_DATE('2009-11-23 21:09:31','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:09:32 PM COT
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=54076 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Nov 23, 2009 9:11:56 PM COT
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,Description,EntityType,FieldLength,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,58593,54076,0,20,331,'IsStatement',TO_DATE('2009-11-23 21:11:53','YYYY-MM-DD HH24:MI:SS'),100,'N','Dunning Level is a definition of a statement','D',1,'Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Is Statement',0,TO_DATE('2009-11-23 21:11:53','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Nov 23, 2009 9:11:56 PM COT
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=58593 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Nov 23, 2009 9:11:58 PM COT
ALTER TABLE C_DunningLevel ADD IsStatement CHAR(1) DEFAULT 'N' CHECK (IsStatement IN ('Y','N')) NOT NULL
;
-- Nov 23, 2009 9:12:23 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,58593,58080,0,268,TO_DATE('2009-11-23 21:12:22','YYYY-MM-DD HH24:MI:SS'),100,'Dunning Level is a definition of a statement',1,'D','Y','Y','Y','N','N','N','N','N','Is Statement',220,0,TO_DATE('2009-11-23 21:12:22','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:12:23 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=58080 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Nov 23, 2009 9:12:29 PM COT
UPDATE AD_Field SET DisplayLength=1,Updated=TO_DATE('2009-11-23 21:12:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=58079
;
-- Nov 23, 2009 9:13:19 PM COT
UPDATE AD_Field SET IsSameLine='Y',Updated=TO_DATE('2009-11-23 21:13:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=58080
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Element SET Name='Dunning Grace Date', PrintName='Dunning Grace Date',Updated=TO_DATE('2009-11-23 21:14:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Column SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Process_Para SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL, AD_Element_ID=53223 WHERE UPPER(ColumnName)='DUNNINGGRACE' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Process_Para SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Element_ID=53223 AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Field SET Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=53223) AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:14:18 PM COT
UPDATE AD_PrintFormatItem pi SET PrintName='Dunning Grace Date', Name='Dunning Grace Date' WHERE IsCentrallyMaintained='Y' AND EXISTS (SELECT * FROM AD_Column c WHERE c.AD_Column_ID=pi.AD_Column_ID AND c.AD_Element_ID=53223)
;
-- Nov 23, 2009 9:14:40 PM COT
UPDATE AD_Field SET DisplayLogic='@Processed@=Y',Updated=TO_DATE('2009-11-23 21:14:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=53257
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2241
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2251
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=10,IsDisplayed='Y' WHERE AD_Field_ID=2239
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=20,IsDisplayed='Y' WHERE AD_Field_ID=2240
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=30,IsDisplayed='Y' WHERE AD_Field_ID=2250
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=40,IsDisplayed='Y' WHERE AD_Field_ID=2245
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=50,IsDisplayed='Y' WHERE AD_Field_ID=2249
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=60,IsDisplayed='Y' WHERE AD_Field_ID=3221
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=70,IsDisplayed='Y' WHERE AD_Field_ID=13702
;
-- Nov 23, 2009 9:15:34 PM COT
UPDATE AD_Field SET IsSameLine='N',Updated=TO_DATE('2009-11-23 21:15:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13702
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2914
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2918
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=2921
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=2920
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=150,IsDisplayed='Y' WHERE AD_Field_ID=5738
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=160,IsDisplayed='Y' WHERE AD_Field_ID=13703
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=170,IsDisplayed='Y' WHERE AD_Field_ID=13705
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=180,IsDisplayed='Y' WHERE AD_Field_ID=13704
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=190,IsDisplayed='Y' WHERE AD_Field_ID=58079
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=200,IsDisplayed='Y' WHERE AD_Field_ID=58080
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Element SET Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.',Updated=TO_DATE('2009-11-23 21:19:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Column SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Process_Para SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.', AD_Element_ID=1092 WHERE UPPER(ColumnName)='DAYSAFTERDUE' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Process_Para SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Element_ID=1092 AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Field SET Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=1092) AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009
-- FR2902882-Dunning Stabilization
UPDATE C_DunningLevel SET IsStatement='Y' WHERE daysafterdue=-9999
;
-- Nov 23, 2009 10:20:48 PM COT
UPDATE C_DunningLevel SET IsShowAllDue='Y', IsShowNotDue='Y',Updated=TO_DATE('2009-11-23 22:20:48','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_DunningLevel_ID=100
;
-- Nov 23, 2009 10:20:52 PM COT
UPDATE C_DunningLevel SET IsShowAllDue='Y',Updated=TO_DATE('2009-11-23 22:20:52','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_DunningLevel_ID=101
;

View File

@ -0,0 +1,207 @@
-- Nov 23, 2009 9:06:59 PM COT
-- FR2902882-Dunning Stabilization
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Reference_Value_ID,AD_Table_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,58591,3092,0,17,394,331,'InvoiceCollectionType',TO_TIMESTAMP('2009-11-23 21:06:55','YYYY-MM-DD HH24:MI:SS'),100,'Invoice Collection Status','D',1,'Status of the invoice collection process','Y','Y','N','N','N','N','N','N','N','N','N','N','Y','Collection Status',0,TO_TIMESTAMP('2009-11-23 21:06:55','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Nov 23, 2009 9:06:59 PM COT
-- FR2902882-Dunning Stabilization
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=58591 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Nov 23, 2009 9:07:09 PM COT
ALTER TABLE C_DunningLevel ADD COLUMN InvoiceCollectionType CHAR(1) DEFAULT NULL
;
-- Nov 23, 2009 9:08:03 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,58591,58079,0,268,TO_TIMESTAMP('2009-11-23 21:08:00','YYYY-MM-DD HH24:MI:SS'),100,'Invoice Collection Status',0,'D','Status of the invoice collection process','Y','Y','Y','N','N','N','N','N','Collection Status',210,0,TO_TIMESTAMP('2009-11-23 21:08:00','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:08:03 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=58079 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Nov 23, 2009 9:09:31 PM COT
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,54076,0,'IsStatement',TO_TIMESTAMP('2009-11-23 21:09:31','YYYY-MM-DD HH24:MI:SS'),100,'Dunning Level is a definition of a statement','D','Y','Is Statement','Is Statement',TO_TIMESTAMP('2009-11-23 21:09:31','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:09:32 PM COT
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=54076 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Nov 23, 2009 9:11:56 PM COT
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,Description,EntityType,FieldLength,IsActive,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,58593,54076,0,20,331,'IsStatement',TO_TIMESTAMP('2009-11-23 21:11:53','YYYY-MM-DD HH24:MI:SS'),100,'N','Dunning Level is a definition of a statement','D',1,'Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Is Statement',0,TO_TIMESTAMP('2009-11-23 21:11:53','YYYY-MM-DD HH24:MI:SS'),100,0)
;
-- Nov 23, 2009 9:11:56 PM COT
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=58593 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Nov 23, 2009 9:11:58 PM COT
ALTER TABLE C_DunningLevel ADD COLUMN IsStatement CHAR(1) DEFAULT 'N' CHECK (IsStatement IN ('Y','N')) NOT NULL
;
-- Nov 23, 2009 9:12:23 PM COT
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,58593,58080,0,268,TO_TIMESTAMP('2009-11-23 21:12:22','YYYY-MM-DD HH24:MI:SS'),100,'Dunning Level is a definition of a statement',1,'D','Y','Y','Y','N','N','N','N','N','Is Statement',220,0,TO_TIMESTAMP('2009-11-23 21:12:22','YYYY-MM-DD HH24:MI:SS'),100)
;
-- Nov 23, 2009 9:12:23 PM COT
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=58080 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Nov 23, 2009 9:12:29 PM COT
UPDATE AD_Field SET DisplayLength=1,Updated=TO_TIMESTAMP('2009-11-23 21:12:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=58079
;
-- Nov 23, 2009 9:13:19 PM COT
UPDATE AD_Field SET IsSameLine='Y',Updated=TO_TIMESTAMP('2009-11-23 21:13:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=58080
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Element SET Name='Dunning Grace Date', PrintName='Dunning Grace Date',Updated=TO_TIMESTAMP('2009-11-23 21:14:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Column SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Element_ID=53223
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Process_Para SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL, AD_Element_ID=53223 WHERE UPPER(ColumnName)='DUNNINGGRACE' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Process_Para SET ColumnName='DunningGrace', Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Element_ID=53223 AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:14:17 PM COT
UPDATE AD_Field SET Name='Dunning Grace Date', Description=NULL, Help=NULL WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=53223) AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:14:18 PM COT
UPDATE AD_PrintFormatItem SET PrintName='Dunning Grace Date', Name='Dunning Grace Date' WHERE IsCentrallyMaintained='Y' AND EXISTS (SELECT * FROM AD_Column c WHERE c.AD_Column_ID=AD_PrintFormatItem.AD_Column_ID AND c.AD_Element_ID=53223)
;
-- Nov 23, 2009 9:14:40 PM COT
UPDATE AD_Field SET DisplayLogic='@Processed@=Y',Updated=TO_TIMESTAMP('2009-11-23 21:14:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=53257
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2241
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2251
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=10,IsDisplayed='Y' WHERE AD_Field_ID=2239
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=20,IsDisplayed='Y' WHERE AD_Field_ID=2240
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=30,IsDisplayed='Y' WHERE AD_Field_ID=2250
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=40,IsDisplayed='Y' WHERE AD_Field_ID=2245
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=50,IsDisplayed='Y' WHERE AD_Field_ID=2249
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=60,IsDisplayed='Y' WHERE AD_Field_ID=3221
;
-- Nov 23, 2009 9:15:24 PM COT
UPDATE AD_Field SET SeqNo=70,IsDisplayed='Y' WHERE AD_Field_ID=13702
;
-- Nov 23, 2009 9:15:34 PM COT
UPDATE AD_Field SET IsSameLine='N',Updated=TO_TIMESTAMP('2009-11-23 21:15:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=13702
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2914
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=0,IsDisplayed='N' WHERE AD_Field_ID=2918
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=2921
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=2920
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=150,IsDisplayed='Y' WHERE AD_Field_ID=5738
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=160,IsDisplayed='Y' WHERE AD_Field_ID=13703
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=170,IsDisplayed='Y' WHERE AD_Field_ID=13705
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=180,IsDisplayed='Y' WHERE AD_Field_ID=13704
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=190,IsDisplayed='Y' WHERE AD_Field_ID=58079
;
-- Nov 23, 2009 9:15:56 PM COT
UPDATE AD_Field SET SeqNo=200,IsDisplayed='Y' WHERE AD_Field_ID=58080
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Element SET Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.',Updated=TO_TIMESTAMP('2009-11-23 21:19:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Element_Trl SET IsTranslated='N' WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Column SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Element_ID=1092
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Process_Para SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.', AD_Element_ID=1092 WHERE UPPER(ColumnName)='DAYSAFTERDUE' AND IsCentrallyMaintained='Y' AND AD_Element_ID IS NULL
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Process_Para SET ColumnName='DaysAfterDue', Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Element_ID=1092 AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009 9:19:59 PM COT
UPDATE AD_Field SET Name='Days after due date', Description='Days after due date to dun (if negative days until due)', Help='The Days After Due Date indicates the number of days after the payment due date to initiate dunning. If the number is negative, it includes the not due invoices.' WHERE AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE AD_Element_ID=1092) AND IsCentrallyMaintained='Y'
;
-- Nov 23, 2009
-- FR2902882-Dunning Stabilization
UPDATE C_DunningLevel SET IsStatement='Y' WHERE daysafterdue=-9999
;
-- Nov 23, 2009 10:20:48 PM COT
UPDATE C_DunningLevel SET IsShowAllDue='Y', IsShowNotDue='Y',Updated=TO_TIMESTAMP('2009-11-23 22:20:48','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_DunningLevel_ID=100
;
-- Nov 23, 2009 10:20:52 PM COT
UPDATE C_DunningLevel SET IsShowAllDue='Y',Updated=TO_TIMESTAMP('2009-11-23 22:20:52','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_DunningLevel_ID=101
;