IDEMPIERE-308 Performance: Replace with StringBuilder / Thanks to Richard Morales and David Peñuela

This commit is contained in:
Carlos Ruiz 2012-09-25 12:54:09 -05:00
parent f41c5cf94b
commit bda4e5736d
7 changed files with 155 additions and 126 deletions

View File

@ -112,7 +112,8 @@ public class CopyOrder extends SvrProcess
// //
// Env.setSOTrx(getCtx(), newOrder.isSOTrx()); // Env.setSOTrx(getCtx(), newOrder.isSOTrx());
// return "@C_Order_ID@ " + newOrder.getDocumentNo(); // return "@C_Order_ID@ " + newOrder.getDocumentNo();
return dt.getName() + ": " + newOrder.getDocumentNo(); StringBuilder msgreturn = new StringBuilder(dt.getName()).append(": ").append(newOrder.getDocumentNo());
return msgreturn.toString();
} // doIt } // doIt
} // CopyOrder } // CopyOrder

View File

@ -88,8 +88,8 @@ public class CopyRole extends SvrProcess
String table = tables[i]; String table = tables[i];
String keycolumn = keycolumns[i]; String keycolumn = keycolumns[i];
String sql = "DELETE FROM " + table + " WHERE AD_Role_ID = " + m_AD_Role_ID_To; StringBuilder sql = new StringBuilder("DELETE FROM ").append(table).append(" WHERE AD_Role_ID = ").append(m_AD_Role_ID_To);
int no = DB.executeUpdateEx(sql, get_TrxName()); int no = DB.executeUpdateEx(sql.toString(), get_TrxName());
addLog(action++, null, BigDecimal.valueOf(no), "Old records deleted from " + table ); addLog(action++, null, BigDecimal.valueOf(no), "Old records deleted from " + table );
final boolean column_IsReadWrite = final boolean column_IsReadWrite =
@ -97,29 +97,29 @@ public class CopyRole extends SvrProcess
&& !table.equals(I_AD_Role_Included.Table_Name); && !table.equals(I_AD_Role_Included.Table_Name);
final boolean column_SeqNo = table.equals(I_AD_Role_Included.Table_Name); final boolean column_SeqNo = table.equals(I_AD_Role_Included.Table_Name);
sql = "INSERT INTO " + table sql = new StringBuilder("INSERT INTO ").append(table)
+ " (AD_Client_ID, AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, " .append(" (AD_Client_ID, AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, ")
+ "AD_Role_ID, " + keycolumn +", isActive"; .append( "AD_Role_ID, ").append(keycolumn).append(", isActive");
if (column_SeqNo) if (column_SeqNo)
sql += ", SeqNo "; sql.append(", SeqNo ");
if (column_IsReadWrite) if (column_IsReadWrite)
sql += ", isReadWrite) "; sql.append(", isReadWrite) ");
else else
sql += ") "; sql.append(") ");
sql += "SELECT " + m_AD_Client_ID sql.append("SELECT ").append(m_AD_Client_ID)
+ ", "+ m_AD_Org_ID .append(", ").append(m_AD_Org_ID)
+ ", getdate(), "+ Env.getAD_User_ID(Env.getCtx()) .append(", getdate(), ").append(Env.getAD_User_ID(Env.getCtx()))
+ ", getdate(), "+ Env.getAD_User_ID(Env.getCtx()) .append(", getdate(), ").append(Env.getAD_User_ID(Env.getCtx()))
+ ", " + m_AD_Role_ID_To .append(", ").append(m_AD_Role_ID_To)
+ ", " + keycolumn .append(", ").append(keycolumn)
+ ", IsActive "; .append(", IsActive ");
if (column_SeqNo) if (column_SeqNo)
sql += ", SeqNo "; sql.append(", SeqNo ");
if (column_IsReadWrite) if (column_IsReadWrite)
sql += ", isReadWrite "; sql.append(", isReadWrite ");
sql += "FROM " + table + " WHERE AD_Role_ID = " + m_AD_Role_ID_From; sql.append("FROM ").append(table).append(" WHERE AD_Role_ID = ").append(m_AD_Role_ID_From);
no = DB.executeUpdateEx (sql, get_TrxName()); no = DB.executeUpdateEx (sql.toString(), get_TrxName());
addLog(action++, null, new BigDecimal(no), "New records inserted into " + table ); addLog(action++, null, new BigDecimal(no), "New records inserted into " + table );
} }

View File

@ -151,11 +151,13 @@ public class DistributionCreate extends SvrProcess
// Update Qty // Update Qty
if (m_singleOrder != null) if (m_singleOrder != null)
{ {
m_singleOrder.setDescription("# " + counter + " - " + m_totalQty); StringBuilder msg = new StringBuilder("# ").append(counter).append(" - ").append(m_totalQty);
m_singleOrder.setDescription(msg.toString());
m_singleOrder.saveEx(); m_singleOrder.saveEx();
} }
return "@Created@ #" + counter + " - @Qty@=" + m_totalQty; StringBuilder msgreturn = new StringBuilder("@Created@ #").append(counter).append(" - @Qty@=").append(m_totalQty);
return msgreturn.toString();
} // doIt } // doIt
/** /**

View File

@ -320,10 +320,12 @@ public class DistributionRun extends SvrProcess
for (int j = 0; j < m_runLines.length; j++) for (int j = 0; j < m_runLines.length; j++)
{ {
MDistributionRunLine runLine = m_runLines[j]; MDistributionRunLine runLine = m_runLines[j];
if (runLine.isActualMinGtTotal()) if (runLine.isActualMinGtTotal()){
throw new Exception ("Line " + runLine.getLine() StringBuilder msg = new StringBuilder("Line ").append(runLine.getLine())
+ " Sum of Min Qty=" + runLine.getActualMin() .append(" Sum of Min Qty=").append(runLine.getActualMin())
+ " is greater than Total Qty=" + runLine.getTotalQty()); .append(" is greater than Total Qty=").append(runLine.getTotalQty());
throw new Exception (msg.toString());
}
if (allocationEqTotal && !runLine.isActualAllocationEqTotal()) if (allocationEqTotal && !runLine.isActualAllocationEqTotal())
allocationEqTotal = false; allocationEqTotal = false;
} // for all run lines } // for all run lines
@ -378,8 +380,9 @@ public class DistributionRun extends SvrProcess
} }
} }
} // for all detail lines } // for all detail lines
throw new Exception ("Cannot adjust Difference = " + difference StringBuilder msgexc = new StringBuilder("Cannot adjust Difference = ").append(difference)
+ " - You need to change Total Qty or Min Qty"); .append(" - You need to change Total Qty or Min Qty");
throw new Exception (msgexc.toString());
} }
else // Distibute else // Distibute
{ {
@ -394,9 +397,11 @@ public class DistributionRun extends SvrProcess
ratioTotal = ratioTotal.add(detail.getRatio()); ratioTotal = ratioTotal.add(detail.getRatio());
} }
} }
if (ratioTotal.compareTo(Env.ZERO) == 0) if (ratioTotal.compareTo(Env.ZERO) == 0){
throw new Exception ("Cannot distribute Difference = " + difference StringBuilder msgexc = new StringBuilder("Cannot distribute Difference = ").append(difference)
+ " - You need to change Total Qty or Min Qty"); .append(" - You need to change Total Qty or Min Qty");
throw new Exception (msgexc.toString());
}
// Distribute // Distribute
for (int i = 0; i < m_details.length; i++) for (int i = 0; i < m_details.length; i++)
{ {
@ -542,8 +547,8 @@ public class DistributionRun extends SvrProcess
product = MProduct.get (getCtx(), detail.getM_Product_ID()); product = MProduct.get (getCtx(), detail.getM_Product_ID());
if (p_IsTest) if (p_IsTest)
{ {
addLog(0,null, detail.getActualAllocation(), StringBuilder msglog = new StringBuilder(bp.getName()).append(" - ").append(product.getName());
bp.getName() + " - " + product.getName()); addLog(0,null, detail.getActualAllocation(), msglog.toString());
continue; continue;
} }
@ -566,8 +571,8 @@ public class DistributionRun extends SvrProcess
log.log(Level.SEVERE, "OrderLine not saved"); log.log(Level.SEVERE, "OrderLine not saved");
return false; return false;
} }
addLog(0,null, detail.getActualAllocation(), order.getDocumentNo() StringBuilder msglog = new StringBuilder(order.getDocumentNo()).append(": ").append(bp.getName()).append(" - ").append(product.getName());
+ ": " + bp.getName() + " - " + product.getName()); addLog(0,null, detail.getActualAllocation(), msglog.toString());
} }
// finish order // finish order
order = null; order = null;
@ -584,40 +589,40 @@ public class DistributionRun extends SvrProcess
private int insertDetailsDistributionDemand() private int insertDetailsDistributionDemand()
{ {
// Handle NULL // Handle NULL
String sql = "UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL"; StringBuilder sql = new StringBuilder("UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL"; sql = new StringBuilder("UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
// Delete Old // Delete Old
sql = "DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=" sql = new StringBuilder("DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=")
+ p_M_DistributionRun_ID; .append(p_M_DistributionRun_ID);
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("insertDetails - deleted #" + no); log.fine("insertDetails - deleted #" + no);
// Insert New // Insert New
sql = "INSERT INTO T_DistributionRunDetail " sql = new StringBuilder("INSERT INTO T_DistributionRunDetail ")
+ "(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID," .append("(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID,")
+ "AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy," .append("AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,")
+ "C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID," .append("C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID,")
+ "Ratio, MinQty, Qty) " .append("Ratio, MinQty, Qty) " )
+"SELECT MAX(rl.M_DistributionRun_ID), MAX(rl.M_DistributionRunLine_ID),MAX(ll.M_DistributionList_ID), MAX(ll.M_DistributionListLine_ID), " .append("SELECT MAX(rl.M_DistributionRun_ID), MAX(rl.M_DistributionRunLine_ID),MAX(ll.M_DistributionList_ID), MAX(ll.M_DistributionListLine_ID), ")
+"MAX(rl.AD_Client_ID),MAX(rl.AD_Org_ID), MAX(rl.IsActive), MAX(rl.Created),MAX(rl.CreatedBy), MAX(rl.Updated),MAX(rl.UpdatedBy), " .append("MAX(rl.AD_Client_ID),MAX(rl.AD_Org_ID), MAX(rl.IsActive), MAX(rl.Created),MAX(rl.CreatedBy), MAX(rl.Updated),MAX(rl.UpdatedBy), ")
+"MAX(ll.C_BPartner_ID), MAX(ll.C_BPartner_Location_ID), MAX(rl.M_Product_ID)," .append("MAX(ll.C_BPartner_ID), MAX(ll.C_BPartner_Location_ID), MAX(rl.M_Product_ID),")
// Ration for this process is equal QtyToDeliver // Ration for this process is equal QtyToDeliver
+"COALESCE (SUM(ol.QtyOrdered-ol.QtyDelivered-TargetQty), 0) , " .append("COALESCE (SUM(ol.QtyOrdered-ol.QtyDelivered-TargetQty), 0) , ")
// Min Qty for this process is equal to TargetQty // Min Qty for this process is equal to TargetQty
+" 0 , 0 FROM M_DistributionRunLine rl " .append(" 0 , 0 FROM M_DistributionRunLine rl ")
+"INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) " .append("INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) ")
+"INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) " .append("INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) ")
+"INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID AND o.DocStatus IN ('DR','IN')) " .append("INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID AND o.DocStatus IN ('DR','IN')) ")
+"INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) " .append("INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) ")
+"INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID="+p_M_Warehouse_ID+") " .append("INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID=").append(p_M_Warehouse_ID).append(") ")
+"WHERE rl.M_DistributionRun_ID="+p_M_DistributionRun_ID+" AND rl.IsActive='Y' AND ll.IsActive='Y' AND ol.DatePromised <= "+DB.TO_DATE(p_DatePromised) .append("WHERE rl.M_DistributionRun_ID=").append(p_M_DistributionRun_ID).append(" AND rl.IsActive='Y' AND ll.IsActive='Y' AND ol.DatePromised <= ").append(DB.TO_DATE(p_DatePromised))
+" GROUP BY o.M_Shipper_ID , ll.C_BPartner_ID, ol.M_Product_ID"; .append(" GROUP BY o.M_Shipper_ID , ll.C_BPartner_ID, ol.M_Product_ID");
//+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To) //+ " BETWEEN "+ DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To)
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
List<MDistributionRunDetail> records = new Query(getCtx(), List<MDistributionRunDetail> records = new Query(getCtx(),
MDistributionRunDetail.Table_Name, MDistributionRunDetail.Table_Name,
@ -647,16 +652,20 @@ public class DistributionRun extends SvrProcess
private BigDecimal getQtyDemand(int M_Product_ID) private BigDecimal getQtyDemand(int M_Product_ID)
{ {
StringBuffer sql = new StringBuffer("SELECT SUM (QtyOrdered-QtyDelivered-TargetQty) FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) "); String sql = "SELECT SUM (QtyOrdered-QtyDelivered-TargetQty) " +
//sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised BETWEEN ? AND ? AND l.M_Warehouse_ID=? AND ol.M_Product_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID"); "FROM DD_OrderLine ol " +
sql.append(" WHERE o.DocStatus IN ('DR','IN') AND ol.DatePromised <= ? AND l.M_Warehouse_ID=? AND ol.M_Product_ID=? GROUP BY M_Product_ID, l.M_Warehouse_ID"); "INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) " +
"INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) " +
" WHERE o.DocStatus IN ('DR','IN') " +
"AND ol.DatePromised <= ? " +
"AND l.M_Warehouse_ID=? " +
"AND ol.M_Product_ID=? " +
"GROUP BY M_Product_ID, l.M_Warehouse_ID";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setTimestamp(1, p_DatePromised); pstmt.setTimestamp(1, p_DatePromised);
//pstmt.setTimestamp(2, p_DatePromised_To); //pstmt.setTimestamp(2, p_DatePromised_To);
pstmt.setInt(2, p_M_Warehouse_ID); pstmt.setInt(2, p_M_Warehouse_ID);
@ -692,37 +701,37 @@ public class DistributionRun extends SvrProcess
private int insertDetailsDistribution() private int insertDetailsDistribution()
{ {
// Handle NULL // Handle NULL
String sql = "UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL"; StringBuilder sql = new StringBuilder("UPDATE M_DistributionRunLine SET MinQty = 0 WHERE MinQty IS NULL");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL"; sql = new StringBuilder("UPDATE M_DistributionListLine SET MinQty = 0 WHERE MinQty IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
// Delete Old // Delete Old
sql = "DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=" sql = new StringBuilder("DELETE FROM T_DistributionRunDetail WHERE M_DistributionRun_ID=")
+ p_M_DistributionRun_ID; .append(p_M_DistributionRun_ID);
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("insertDetails - deleted #" + no); log.fine("insertDetails - deleted #" + no);
// Insert New // Insert New
sql = "INSERT INTO T_DistributionRunDetail " sql = new StringBuilder("INSERT INTO T_DistributionRunDetail ")
+ "(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID," .append("(M_DistributionRun_ID, M_DistributionRunLine_ID, M_DistributionList_ID, M_DistributionListLine_ID,")
+ "AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy," .append("AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,")
+ "C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID," .append("C_BPartner_ID, C_BPartner_Location_ID, M_Product_ID,")
+ "Ratio, MinQty, Qty) " .append("Ratio, MinQty, Qty) ")
+"SELECT rl.M_DistributionRun_ID, rl.M_DistributionRunLine_ID,ll.M_DistributionList_ID, ll.M_DistributionListLine_ID, " .append("SELECT rl.M_DistributionRun_ID, rl.M_DistributionRunLine_ID,ll.M_DistributionList_ID, ll.M_DistributionListLine_ID, ")
+"rl.AD_Client_ID,rl.AD_Org_ID, rl.IsActive, rl.Created,rl.CreatedBy, rl.Updated,rl.UpdatedBy, " .append("rl.AD_Client_ID,rl.AD_Org_ID, rl.IsActive, rl.Created,rl.CreatedBy, rl.Updated,rl.UpdatedBy, ")
+"ll.C_BPartner_ID, ll.C_BPartner_Location_ID, rl.M_Product_ID, 0 , " .append("ll.C_BPartner_ID, ll.C_BPartner_Location_ID, rl.M_Product_ID, 0 , ")
+"ol.TargetQty AS MinQty , 0 FROM M_DistributionRunLine rl " .append("ol.TargetQty AS MinQty , 0 FROM M_DistributionRunLine rl ")
+"INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) " .append("INNER JOIN M_DistributionList l ON (rl.M_DistributionList_ID=l.M_DistributionList_ID) ")
+"INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) " .append("INNER JOIN M_DistributionListLine ll ON (rl.M_DistributionList_ID=ll.M_DistributionList_ID) ")
+"INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID) " .append("INNER JOIN DD_Order o ON (o.C_BPartner_ID=ll.C_BPartner_ID) ")
+"INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) AND ol.DatePromised" .append("INNER JOIN DD_OrderLine ol ON (ol.DD_Order_ID=o.DD_Order_ID AND ol.M_Product_ID=rl.M_Product_ID) AND ol.DatePromised")
//+ " BETWEEN " + DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To) //+ " BETWEEN " + DB.TO_DATE(p_DatePromised) +" AND "+ DB.TO_DATE(p_DatePromised_To)
+ "<="+DB.TO_DATE(p_DatePromised) .append( "<=").append(DB.TO_DATE(p_DatePromised))
+" INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID="+p_M_Warehouse_ID+") " .append(" INNER JOIN M_Locator loc ON (loc.M_Locator_ID=ol.M_Locator_ID AND loc.M_Warehouse_ID=").append(p_M_Warehouse_ID).append(") ")
+" WHERE rl.M_DistributionRun_ID="+p_M_DistributionRun_ID+" AND l.RatioTotal<>0 AND rl.IsActive='Y' AND ll.IsActive='Y'"; .append(" WHERE rl.M_DistributionRun_ID=").append(p_M_DistributionRun_ID).append(" AND l.RatioTotal<>0 AND rl.IsActive='Y' AND ll.IsActive='Y'");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
Query query = MTable.get(getCtx(), I_T_DistributionRunDetail.Table_ID). Query query = MTable.get(getCtx(), I_T_DistributionRunDetail.Table_ID).
createQuery(MDistributionRunDetail.COLUMNNAME_M_DistributionRun_ID + "=?", get_TrxName()); createQuery(MDistributionRunDetail.COLUMNNAME_M_DistributionRun_ID + "=?", get_TrxName());
@ -772,9 +781,9 @@ public class DistributionRun extends SvrProcess
{ {
MDistributionRunDetail detail = m_details[i]; MDistributionRunDetail detail = m_details[i];
StringBuffer sql = new StringBuffer("SELECT * FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) "); String sql = "SELECT * FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_Locator_ID) ";
//sql.append(" WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised BETWEEN ? AND ? "); //sql.append(" WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised BETWEEN ? AND ? ");
sql.append(" WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised <=?"); sql = sql + " WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND l.M_Warehouse_ID=? AND ol.DatePromised <=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -930,12 +939,12 @@ public class DistributionRun extends SvrProcess
if(p_ConsolidateDocument) if(p_ConsolidateDocument)
{ {
String whereClause = "DocStatus IN ('DR','IN') AND AD_Org_ID=" + bp.getAD_OrgBP_ID_Int() + " AND " + StringBuilder whereClause = new StringBuilder("DocStatus IN ('DR','IN') AND AD_Org_ID=").append(bp.getAD_OrgBP_ID_Int()).append(" AND ")
MDDOrder.COLUMNNAME_C_BPartner_ID +"=? AND " + .append(MDDOrder.COLUMNNAME_C_BPartner_ID).append("=? AND ")
MDDOrder.COLUMNNAME_M_Warehouse_ID +"=? AND " + .append(MDDOrder.COLUMNNAME_M_Warehouse_ID).append("=? AND ")
MDDOrder.COLUMNNAME_DatePromised +"<=? "; .append(MDDOrder.COLUMNNAME_DatePromised).append("<=? ");
order = new Query(getCtx(), MDDOrder.Table_Name, whereClause, get_TrxName()) order = new Query(getCtx(), MDDOrder.Table_Name, whereClause.toString(), get_TrxName())
.setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised}) .setParameters(new Object[]{lastC_BPartner_ID, ws[0].getM_Warehouse_ID(), p_DatePromised})
.setOrderBy(MDDOrder.COLUMNNAME_DatePromised +" DESC") .setOrderBy(MDDOrder.COLUMNNAME_DatePromised +" DESC")
.first(); .first();
@ -988,8 +997,8 @@ public class DistributionRun extends SvrProcess
product = MProduct.get (getCtx(), detail.getM_Product_ID()); product = MProduct.get (getCtx(), detail.getM_Product_ID());
if (p_IsTest) if (p_IsTest)
{ {
addLog(0,null, detail.getActualAllocation(), StringBuilder msglog = new StringBuilder(bp.getName()).append(" - ").append(product.getName());
bp.getName() + " - " + product.getName()); addLog(0,null, detail.getActualAllocation(), msglog.toString());
continue; continue;
} }
@ -1017,7 +1026,9 @@ public class DistributionRun extends SvrProcess
String Description =""; String Description ="";
if (m_run.getName() != null) if (m_run.getName() != null)
Description =Description.concat(m_run.getName()); Description =Description.concat(m_run.getName());
line.setDescription(Description + " " +Msg.translate(getCtx(), "Qty")+ " = " +QtyAllocation+" "); StringBuilder msgline = new StringBuilder(Description).append(" ").append(Msg.translate(getCtx(), "Qty"))
.append(" = ").append(QtyAllocation).append(" ");
line.setDescription(msgline.toString());
//line.setConfirmedQty(QtyAllocation); //line.setConfirmedQty(QtyAllocation);
line.saveEx(); line.saveEx();
} }
@ -1032,7 +1043,8 @@ public class DistributionRun extends SvrProcess
Description =""; Description ="";
if (m_run.getName() != null) if (m_run.getName() != null)
Description =Description.concat(m_run.getName()); Description =Description.concat(m_run.getName());
line.setDescription(Description + " " +Msg.translate(getCtx(), "Qty")+ " = " +QtyAllocation+" "); StringBuilder msgline = new StringBuilder(Description).append(" ").append(Msg.translate(getCtx(), "Qty")).append(" = ").append(QtyAllocation).append(" ");
line.setDescription(msgline.toString());
line.setQty(line.getQtyEntered().add(QtyAllocation)); line.setQty(line.getQtyEntered().add(QtyAllocation));
//line.setConfirmedQty(line.getConfirmedQty().add( QtyAllocation)); //line.setConfirmedQty(line.getConfirmedQty().add( QtyAllocation));
line.saveEx(); line.saveEx();
@ -1064,12 +1076,15 @@ public class DistributionRun extends SvrProcess
String Description =""; String Description ="";
if (m_run.getName() != null) if (m_run.getName() != null)
Description =Description.concat(m_run.getName()); Description =Description.concat(m_run.getName());
line.setDescription(Description + " " +Msg.translate(getCtx(), "Qty")+ " = " +detail.getActualAllocation()+" "); StringBuilder msgline = new StringBuilder(Description).append(" ").append(Msg.translate(getCtx(), "Qty")).append(" = ")
.append(detail.getActualAllocation()).append(" ");
line.setDescription(msgline.toString());
line.saveEx(); line.saveEx();
} }
addLog(0,null, detail.getActualAllocation(), order.getDocumentNo() StringBuilder msglog = new StringBuilder(order.getDocumentNo())
+ ": " + bp.getName() + " - " + product.getName()); .append(": ").append(bp.getName()).append(" - ").append(product.getName());
addLog(0,null, detail.getActualAllocation(), msglog.toString());
} }
// finish order // finish order
order = null; order = null;

View File

@ -132,7 +132,8 @@ public class DunningPrint extends SvrProcess
MBPartner bp = new MBPartner (getCtx(), entry.getC_BPartner_ID(), get_TrxName()); MBPartner bp = new MBPartner (getCtx(), entry.getC_BPartner_ID(), get_TrxName());
if (bp.get_ID() == 0) if (bp.get_ID() == 0)
{ {
addLog (entry.get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.getC_BPartner_ID()); StringBuilder msglog = new StringBuilder("@NotFound@: @C_BPartner_ID@ ").append(entry.getC_BPartner_ID());
addLog (entry.get_ID(), null, null,msglog.toString() );
errors++; errors++;
continue; continue;
} }
@ -142,13 +143,15 @@ public class DunningPrint extends SvrProcess
{ {
if (to.get_ID() == 0) if (to.get_ID() == 0)
{ {
addLog (entry.get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.getName()); StringBuilder msglog = new StringBuilder("@NotFound@: @AD_User_ID@ - ").append(bp.getName());
addLog (entry.get_ID(), null, null,msglog.toString());
errors++; errors++;
continue; continue;
} }
else if (to.getEMail() == null || to.getEMail().length() == 0) else if (to.getEMail() == null || to.getEMail().length() == 0)
{ {
addLog (entry.get_ID(), null, null, "@NotFound@: @EMail@ - " + to.getName()); StringBuilder msglog = new StringBuilder("@NotFound@: @EMail@ - ").append(to.getName());
addLog (entry.get_ID(), null, null, msglog.toString());
errors++; errors++;
continue; continue;
} }
@ -164,7 +167,8 @@ public class DunningPrint extends SvrProcess
MDunningRunEntry.Table_ID, MDunningRunEntry.Table_ID,
entry.getC_DunningRunEntry_ID(), entry.getC_DunningRunEntry_ID(),
entry.getC_BPartner_ID()); entry.getC_BPartner_ID());
info.setDescription(bp.getName() + ", Amt=" + entry.getAmt()); StringBuilder msginfo = new StringBuilder(bp.getName()).append(", Amt=").append(entry.getAmt());
info.setDescription(msginfo.toString());
ReportEngine re = null; ReportEngine re = null;
if (format != null) if (format != null)
re = new ReportEngine(getCtx(), format, query, info); re = new ReportEngine(getCtx(), format, query, info);
@ -174,8 +178,9 @@ public class DunningPrint extends SvrProcess
EMail email = client.createEMail(to.getEMail(), null, null); EMail email = client.createEMail(to.getEMail(), null, null);
if (!email.isValid()) if (!email.isValid())
{ {
addLog (entry.get_ID(), null, null, StringBuilder msglog = new StringBuilder(
"@RequestActionEMailError@ Invalid EMail: " + to); "@RequestActionEMailError@ Invalid EMail: ").append(to);
addLog (entry.get_ID(), null, null,msglog.toString() );
errors++; errors++;
continue; continue;
} }
@ -193,7 +198,8 @@ public class DunningPrint extends SvrProcess
// //
if (re != null) { if (re != null) {
File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf")); File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf"));
log.fine(to + " - " + attachment); StringBuilder msglog = new StringBuilder(to.toString()).append(" - ").append(attachment);
log.fine(msglog.toString());
email.addAttachment(attachment); email.addAttachment(attachment);
} }
// //
@ -202,15 +208,16 @@ public class DunningPrint extends SvrProcess
um.saveEx(); um.saveEx();
if (msg.equals(EMail.SENT_OK)) if (msg.equals(EMail.SENT_OK))
{ {
addLog (entry.get_ID(), null, null, StringBuilder msglog = new StringBuilder(
bp.getName() + " @RequestActionEMailOK@"); bp.getName()).append(" @RequestActionEMailOK@");
addLog (entry.get_ID(), null, null,msglog.toString());
count++; count++;
printed = true; printed = true;
} }
else else
{ {
addLog (entry.get_ID(), null, null, StringBuilder msglog = new StringBuilder(bp.getName()).append(" @RequestActionEMailError@ ").append(msg);
bp.getName() + " @RequestActionEMailError@ " + msg); addLog (entry.get_ID(), null, null,msglog.toString() );
errors++; errors++;
} }
} }
@ -233,8 +240,10 @@ public class DunningPrint extends SvrProcess
run.setProcessed(true); run.setProcessed(true);
run.saveEx(); run.saveEx();
} }
if (p_EMailPDF) if (p_EMailPDF){
return "@Sent@=" + count + " - @Errors@=" + errors; StringBuilder msgreturn = new StringBuilder("@Sent@=").append(count).append(" - @Errors@=").append(errors);
return msgreturn.toString();
}
return "@Printed@=" + count; return "@Printed@=" + count;
} // doIt } // doIt

View File

@ -169,7 +169,7 @@ public class DunningRunCreate extends SvrProcess
sql.append(" AND i.AD_Org_ID=").append(p_AD_Org_ID); sql.append(" AND i.AD_Org_ID=").append(p_AD_Org_ID);
// log.info(sql); // log.info(sql);
StringBuilder sql2= new StringBuilder(); String sql2= "";
// 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!
@ -190,11 +190,11 @@ public class DunningRunCreate extends SvrProcess
} }
} }
// ensure that we do only dunn what's not yet dunned, so we lookup the max of last Dunn Date which was processed // ensure that we do only dunn what's not yet dunned, so we lookup the max of last Dunn Date which was processed
sql2.append("SELECT COUNT(*), COALESCE(DAYSBETWEEN(MAX(dr2.DunningDate), MAX(dr.DunningDate)),0)"); sql2 = "SELECT COUNT(*), COALESCE(DAYSBETWEEN(MAX(dr2.DunningDate), MAX(dr.DunningDate)),0)"
sql2.append("FROM C_DunningRun dr2, C_DunningRun dr"); + "FROM C_DunningRun dr2, C_DunningRun dr"
sql2.append(" 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)"
sql2.append(" 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) "
sql2.append("WHERE dr2.C_DunningRun_ID=? AND drl.C_Invoice_ID=?"); // ##1 ##2 + "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();

View File

@ -55,7 +55,8 @@ public class EMailTest extends SvrProcess
// Test Client Mail // Test Client Mail
String clientTest = client.testEMail(); String clientTest = client.testEMail();
addLog(0, null, null, client.getName() + ": " + clientTest); StringBuilder msglog = new StringBuilder(client.getName()).append(": ").append(clientTest);
addLog(0, null, null, msglog.toString());
// Test Client DocumentDir // Test Client DocumentDir
if (!Ini.isClient()) if (!Ini.isClient())
@ -75,7 +76,8 @@ public class EMailTest extends SvrProcess
{ {
MStore store = wstores[i]; MStore store = wstores[i];
String test = store.testEMail(); String test = store.testEMail();
addLog(0, null, null, store.getName() + ": " + test); msglog = new StringBuilder(store.getName()).append(": ").append(test);
addLog(0, null, null, msglog.toString());
} }
return clientTest; return clientTest;