IDEMPIERE-308 Performance: Replace use of StringBuffer and String concatenation with StringBuilder / thanks to Richard Morales and David Peñuela

This commit is contained in:
Carlos Ruiz 2012-09-21 19:21:59 -05:00
parent 5c1d614ec9
commit ae107dbb64
21 changed files with 1210 additions and 1141 deletions

View File

@ -162,14 +162,18 @@ public class ColumnEncryption extends SvrProcess {
// Length Test // Length Test
if (p_MaxLength != 0) { if (p_MaxLength != 0) {
String testClear = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; StringBuilder testClear = new StringBuilder();
testClear.append("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
while (testClear.length() < p_MaxLength) while (testClear.length() < p_MaxLength)
testClear += testClear; testClear.append(testClear);
testClear = testClear.substring(0, p_MaxLength); testClear.delete(p_MaxLength,testClear.length());
log.config("Test=" + testClear + " (" + p_MaxLength + ")"); StringBuilder msglog = new StringBuilder()
.append("Test=").append(testClear.toString()).append(" (").append(p_MaxLength).append(")");
log.config(msglog.toString());
// //
String encString = SecureEngine.encrypt(testClear); String encString = SecureEngine.encrypt(testClear.toString());
int encLength = encString.length(); int encLength = encString.length();
addLog(0, null, null, "Test Max Length=" + testClear.length() addLog(0, null, null, "Test Max Length=" + testClear.length()
+ " -> " + encLength); + " -> " + encLength);
if (encLength <= column.getFieldLength()) if (encLength <= column.getFieldLength())
@ -272,12 +276,12 @@ public class ColumnEncryption extends SvrProcess {
int recordsEncrypted = 0; int recordsEncrypted = 0;
String idColumnName = tableName + "_ID"; String idColumnName = tableName + "_ID";
StringBuffer selectSql = new StringBuffer(); StringBuilder selectSql = new StringBuilder();
selectSql.append("SELECT " + idColumnName + "," + columnName); selectSql.append("SELECT " + idColumnName + "," + columnName);
selectSql.append(" FROM " + tableName); selectSql.append(" FROM " + tableName);
selectSql.append(" ORDER BY " + idColumnName); selectSql.append(" ORDER BY " + idColumnName);
StringBuffer updateSql = new StringBuffer(); StringBuilder updateSql = new StringBuilder();
updateSql.append("UPDATE " + tableName); updateSql.append("UPDATE " + tableName);
updateSql.append(" SET " + columnName + "=?"); updateSql.append(" SET " + columnName + "=?");
updateSql.append(" WHERE " + idColumnName + "=?"); updateSql.append(" WHERE " + idColumnName + "=?");
@ -321,13 +325,12 @@ public class ColumnEncryption extends SvrProcess {
* @return The length of the encrypted column. * @return The length of the encrypted column.
*/ */
private int encryptedColumnLength(int colLength) { private int encryptedColumnLength(int colLength) {
String str = ""; StringBuilder str = new StringBuilder();
for (int i = 0; i < colLength; i++) { for (int i = 0; i < colLength; i++) {
str += "1"; str.append("1");
} }
str = SecureEngine.encrypt(str); str = new StringBuilder(SecureEngine.encrypt(str.toString()));
return str.length(); return str.length();
} // encryptedColumnLength } // encryptedColumnLength
@ -347,7 +350,7 @@ public class ColumnEncryption extends SvrProcess {
int rowsEffected = -1; int rowsEffected = -1;
// Select SQL // Select SQL
StringBuffer selectSql = new StringBuffer(); StringBuilder selectSql = new StringBuilder();
selectSql.append("SELECT FieldLength"); selectSql.append("SELECT FieldLength");
selectSql.append(" FROM AD_Column"); selectSql.append(" FROM AD_Column");
selectSql.append(" WHERE AD_Column_ID=?"); selectSql.append(" WHERE AD_Column_ID=?");

View File

@ -135,39 +135,41 @@ public class DunningRunCreate extends SvrProcess
private int addInvoices(MDunningLevel level) private int addInvoices(MDunningLevel level)
{ {
int count = 0; int count = 0;
String sql = "SELECT i.C_Invoice_ID, i.C_Currency_ID,"
+ " i.GrandTotal*i.MultiplierAP," StringBuilder sql = new StringBuilder("SELECT i.C_Invoice_ID, i.C_Currency_ID,");
+ " invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)*MultiplierAP," sql.append(" i.GrandTotal*i.MultiplierAP,");
+ " COALESCE(daysBetween(?,ips.DueDate),paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,?))," // ##1/2 sql.append(" invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)*MultiplierAP,");
+ " i.IsInDispute, i.C_BPartner_ID, i.C_InvoicePaySchedule_ID " sql.append(" COALESCE(daysBetween(?,ips.DueDate),paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,?)),");// ##1/2
+ "FROM C_Invoice_v i " sql.append(" i.IsInDispute, i.C_BPartner_ID, i.C_InvoicePaySchedule_ID ");
+ " LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID) " sql.append("FROM C_Invoice_v i ");
+ "WHERE i.IsPaid='N' AND i.AD_Client_ID=?" // ##3 sql.append(" LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID) ");
+ " AND i.DocStatus IN ('CO','CL')" sql.append("WHERE i.IsPaid='N' AND i.AD_Client_ID=?"); // ##3
+ " AND (i.DunningGrace IS NULL OR i.DunningGrace<?) " sql.append(" AND i.DocStatus IN ('CO','CL')");
// Only BP(Group) with Dunning defined sql.append(" AND (i.DunningGrace IS NULL OR i.DunningGrace<?) ");
+ " AND EXISTS (SELECT * FROM C_DunningLevel dl " // Only BP(Group) with Dunning defined
+ "WHERE dl.C_DunningLevel_ID=?" // // ##4 sql.append(" AND EXISTS (SELECT * FROM C_DunningLevel dl ");
+ " AND dl.C_Dunning_ID IN " sql.append("WHERE dl.C_DunningLevel_ID=?"); //##4
+ "(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) " sql.append(" AND dl.C_Dunning_ID IN ");
+ "FROM C_BPartner bp" sql.append("(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) ");
+ " INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) " sql.append("FROM C_BPartner bp");
+ "WHERE i.C_BPartner_ID=bp.C_BPartner_ID" + sql.append(" INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) ");
" AND (bp.DunningGrace IS NULL OR bp.DunningGrace<?)))"; sql.append("WHERE i.C_BPartner_ID=bp.C_BPartner_ID");
sql.append(" AND (bp.DunningGrace IS NULL OR bp.DunningGrace<?)))");
if (p_C_BPartner_ID != 0) if (p_C_BPartner_ID != 0)
sql += " AND i.C_BPartner_ID=?"; // ##5 sql.append(" AND i.C_BPartner_ID=?"); // ##5
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.append(" AND EXISTS (SELECT * FROM C_BPartner bp ")
+ "WHERE i.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##5 .append("WHERE i.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)");// ##5
if (p_OnlySOTrx) if (p_OnlySOTrx)
sql += " AND i.IsSOTrx='Y'"; sql.append(" AND i.IsSOTrx='Y'");
if (!p_IsAllCurrencies) if (!p_IsAllCurrencies)
sql += " AND i.C_Currency_ID=" + p_C_Currency_ID; sql.append(" AND i.C_Currency_ID=").append(p_C_Currency_ID);
if ( p_AD_Org_ID != 0 ) if ( p_AD_Org_ID != 0 )
sql += " AND i.AD_Org_ID=" + p_AD_Org_ID; sql.append(" AND i.AD_Org_ID=").append(p_AD_Org_ID);
// log.info(sql); // log.info(sql);
String sql2=null; StringBuilder sql2= new StringBuilder();
// 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!
@ -175,22 +177,24 @@ public class DunningRunCreate extends SvrProcess
// Build a list of all topmost Dunning Levels // Build a list of all topmost Dunning Levels
MDunningLevel[] previousLevels = level.getPreviousLevels(); MDunningLevel[] previousLevels = level.getPreviousLevels();
if (previousLevels!=null && previousLevels.length>0) { if (previousLevels!=null && previousLevels.length>0) {
String sqlAppend = ""; StringBuilder sqlAppend = new StringBuilder();
for (MDunningLevel element : previousLevels) { for (MDunningLevel element : previousLevels) {
sqlAppend += " AND i.C_Invoice_ID IN (SELECT C_Invoice_ID FROM C_DunningRunLine WHERE " + sqlAppend.append(" 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 " + sqlAppend.append("C_DunningRunEntry_ID IN (SELECT C_DunningRunEntry_ID FROM C_DunningRunEntry WHERE ");
"C_DunningRun_ID IN (SELECT C_DunningRun_ID FROM C_DunningRunEntry WHERE " + sqlAppend.append("C_DunningRun_ID IN (SELECT C_DunningRun_ID FROM C_DunningRunEntry WHERE ");
"C_DunningLevel_ID=" + element.get_ID () + ")) AND Processed<>'N')"; sqlAppend.append("C_DunningLevel_ID=");
sqlAppend.append(element.get_ID ());
sqlAppend.append(")) AND Processed<>'N')");
} }
sql += sqlAppend; sql.append(sqlAppend.toString());
} }
} }
// 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 = "SELECT COUNT(*), COALESCE(DAYSBETWEEN(MAX(dr2.DunningDate), MAX(dr.DunningDate)),0)" sql2.append("SELECT COUNT(*), COALESCE(DAYSBETWEEN(MAX(dr2.DunningDate), MAX(dr.DunningDate)),0)");
+ "FROM C_DunningRun dr2, C_DunningRun dr" sql2.append("FROM C_DunningRun dr2, C_DunningRun dr");
+ " INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)" sql2.append(" 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) " sql2.append(" INNER JOIN C_DunningRunLine drl ON (dre.C_DunningRunEntry_ID=drl.C_DunningRunEntry_ID) ");
+ "WHERE dr2.C_DunningRun_ID=? AND drl.C_Invoice_ID=?"; // ##1 ##2 sql2.append("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();
@ -200,7 +204,7 @@ public class DunningRunCreate extends SvrProcess
ResultSet rs = null; ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setTimestamp(1, m_run.getDunningDate()); pstmt.setTimestamp(1, m_run.getDunningDate());
pstmt.setTimestamp(2, m_run.getDunningDate()); pstmt.setTimestamp(2, m_run.getDunningDate());
pstmt.setInt (3, m_run.getAD_Client_ID()); pstmt.setInt (3, m_run.getAD_Client_ID());
@ -212,7 +216,7 @@ public class DunningRunCreate extends SvrProcess
else if (p_C_BP_Group_ID != 0) else if (p_C_BP_Group_ID != 0)
pstmt.setInt (7, p_C_BP_Group_ID); pstmt.setInt (7, p_C_BP_Group_ID);
// //
pstmt2 = DB.prepareStatement (sql2, get_TrxName()); pstmt2 = DB.prepareStatement (sql2.toString(), get_TrxName());
// //
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
@ -225,9 +229,15 @@ public class DunningRunCreate extends SvrProcess
boolean IsInDispute = "Y".equals(rs.getString(6)); boolean IsInDispute = "Y".equals(rs.getString(6));
int C_BPartner_ID = rs.getInt(7); int C_BPartner_ID = rs.getInt(7);
int C_InvoicePaySchedule_ID = rs.getInt(8); int C_InvoicePaySchedule_ID = rs.getInt(8);
log.fine("DaysAfterDue: " + DaysAfterDue.intValue() + " isShowAllDue: " + level.isShowAllDue());
log.fine("C_Invoice_ID - DaysDue - GrandTotal: " + C_Invoice_ID + " - " + DaysDue + " - " + GrandTotal); StringBuilder msglog = new StringBuilder()
log.fine("C_InvoicePaySchedule_ID: " + C_InvoicePaySchedule_ID); .append("DaysAfterDue: ").append(DaysAfterDue.intValue()).append(" isShowAllDue: ").append(level.isShowAllDue());
log.fine(msglog.toString());
msglog = new StringBuilder()
.append("C_Invoice_ID - DaysDue - GrandTotal: ").append(C_Invoice_ID).append(" - ").append(DaysDue).append(" - ").append(GrandTotal);
log.fine(msglog.toString());
msglog = new StringBuilder("C_InvoicePaySchedule_ID: ").append(C_InvoicePaySchedule_ID);
log.fine(msglog.toString());
// //
// Check for Dispute // Check for Dispute
if (!p_IncludeInDispute && IsInDispute) if (!p_IncludeInDispute && IsInDispute)
@ -317,10 +327,12 @@ public class DunningRunCreate extends SvrProcess
} }
catch (BPartnerNoAddressException e) catch (BPartnerNoAddressException e)
{ {
String msg = "@Skip@ @C_Invoice_ID@ " + MInvoice.get(getCtx(), C_Invoice_ID).getDocumentInfo() StringBuilder msg = new StringBuilder("@Skip@ @C_Invoice_ID@ ");
+ ", @C_BPartner_ID@ " + MBPartner.get(getCtx(), C_BPartner_ID).getName() msg.append(MInvoice.get(getCtx(), C_Invoice_ID).getDocumentInfo().toString());
+ " @No@ @IsActive@ @C_BPartner_Location_ID@"; msg.append(", @C_BPartner_ID@ ");
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg); msg.append(MBPartner.get(getCtx(), C_BPartner_ID).getName().toString());
msg.append(" @No@ @IsActive@ @C_BPartner_Location_ID@");
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg.toString());
return false; return false;
} }
@ -349,42 +361,44 @@ public class DunningRunCreate extends SvrProcess
*/ */
private int addPayments(MDunningLevel level) private int addPayments(MDunningLevel level)
{ {
String sql = "SELECT C_Payment_ID, C_Currency_ID, PayAmt," StringBuilder sql = new StringBuilder("SELECT C_Payment_ID, C_Currency_ID, PayAmt,");
+ " paymentAvailable(C_Payment_ID), C_BPartner_ID " sql.append(" paymentAvailable(C_Payment_ID), C_BPartner_ID ");
+ "FROM C_Payment_v p " sql.append("FROM C_Payment_v p ");
+ "WHERE AD_Client_ID=?" // ##1 sql.append("WHERE AD_Client_ID=?"); // ##1
+ " AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL" sql.append(" AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL");
+ " AND C_Charge_ID IS NULL" sql.append(" AND C_Charge_ID IS NULL");
+ " AND DocStatus IN ('CO','CL')" sql.append(" AND DocStatus IN ('CO','CL')");
// Only BP(Group) with Dunning defined //Only BP(Group) with Dunning defined
+ " AND EXISTS (SELECT * FROM C_DunningLevel dl " sql.append(" AND EXISTS (SELECT * FROM C_DunningLevel dl ");
+ "WHERE dl.C_DunningLevel_ID=?" // // ##2 sql.append("WHERE dl.C_DunningLevel_ID=?");
+ " AND dl.C_Dunning_ID IN " sql.append(" AND dl.C_Dunning_ID IN ");
+ "(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) " sql.append("(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) ");
+ "FROM C_BPartner bp" sql.append("FROM C_BPartner bp");
+ " INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) " sql.append(" 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))"; sql.append("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.append(" 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.append(" AND EXISTS (SELECT * FROM C_BPartner bp ")
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##3 .append("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, // 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! // because we do not want to dunn for money we owe the customer!
if (!level.isStatement()) if (!level.isStatement())
sql += " AND C_BPartner_ID IN (SELECT C_BPartner_ID FROM C_DunningRunEntry WHERE C_DunningRun_ID=" + m_run.get_ID () + ")"; sql.append(" AND C_BPartner_ID IN (SELECT C_BPartner_ID FROM C_DunningRunEntry WHERE C_DunningRun_ID=")
.append(m_run.get_ID ()).append(")");
// show only receipts / if only Sales // show only receipts / if only Sales
if (p_OnlySOTrx) if (p_OnlySOTrx)
sql += " AND IsReceipt='Y'"; sql.append(" AND IsReceipt='Y'");
if ( p_AD_Org_ID != 0 ) if ( p_AD_Org_ID != 0 )
sql += " AND p.AD_Org_ID=" + p_AD_Org_ID; sql.append(" AND p.AD_Org_ID=").append(p_AD_Org_ID);
int count = 0; int count = 0;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setInt (1, getAD_Client_ID()); pstmt.setInt (1, getAD_Client_ID());
pstmt.setInt (2, level.getC_DunningLevel_ID()); pstmt.setInt (2, level.getC_DunningLevel_ID());
if (p_C_BPartner_ID != 0) if (p_C_BPartner_ID != 0)
@ -413,7 +427,7 @@ public class DunningRunCreate extends SvrProcess
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql.toString(), e);
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, e.getLocalizedMessage()); getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, e.getLocalizedMessage());
} }
finally finally
@ -441,10 +455,13 @@ public class DunningRunCreate extends SvrProcess
entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID); entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID, c_DunningLevel_ID);
} catch (BPartnerNoAddressException e) { } catch (BPartnerNoAddressException e) {
MPayment payment = new MPayment(getCtx(), C_Payment_ID, null); MPayment payment = new MPayment(getCtx(), C_Payment_ID, null);
String msg = "@Skip@ @C_Payment_ID@ " + payment.getDocumentInfo()
+ ", @C_BPartner_ID@ " + MBPartner.get(getCtx(), C_BPartner_ID).getName() StringBuilder msg = new StringBuilder("@Skip@ @C_Payment_ID@ ");
+ " @No@ @IsActive@ @C_BPartner_Location_ID@"; msg.append(payment.getDocumentInfo().toString());
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg); msg.append(", @C_BPartner_ID@ ");
msg.append(MBPartner.get(getCtx(), C_BPartner_ID).getName().toString());
msg.append(" @No@ @IsActive@ @C_BPartner_Location_ID@");
getProcessInfo().addLog(getProcessInfo().getAD_PInstance_ID(), null, null, msg.toString());
return false; return false;
} }
if (entry.get_ID() == 0) if (entry.get_ID() == 0)

View File

@ -135,36 +135,37 @@ public class InventoryCountCreate extends SvrProcess
// Create Null Storage records // Create Null Storage records
if (p_QtyRange != null && p_QtyRange.equals("=")) if (p_QtyRange != null && p_QtyRange.equals("="))
{ {
String sql = "INSERT INTO M_Storage " StringBuilder sql = new StringBuilder("INSERT INTO M_Storage ");
+ "(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy," sql.append("(AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,");
+ " M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID," sql.append(" M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,");
+ " QtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) " sql.append(" QtyOnHand, QtyReserved, QtyOrdered, DateLastInventory) ");
+ "SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0," sql.append("SELECT l.AD_CLIENT_ID, l.AD_ORG_ID, 'Y', SysDate, 0,SysDate, 0,");
+ " l.M_Locator_ID, p.M_Product_ID, 0," sql.append(" l.M_Locator_ID, p.M_Product_ID, 0,");
+ " 0,0,0,null " sql.append(" 0,0,0,null ");
+ "FROM M_Locator l" sql.append("FROM M_Locator l");
+ " INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) " sql.append(" INNER JOIN M_Product p ON (l.AD_Client_ID=p.AD_Client_ID) ");
+ "WHERE l.M_Warehouse_ID=" + m_inventory.getM_Warehouse_ID(); sql.append("WHERE l.M_Warehouse_ID=");
sql.append(m_inventory.getM_Warehouse_ID());
if (p_M_Locator_ID != 0) if (p_M_Locator_ID != 0)
sql += " AND l.M_Locator_ID=" + p_M_Locator_ID; sql.append(" AND l.M_Locator_ID=").append(p_M_Locator_ID);
sql += " AND l.IsDefault='Y'" sql.append(" AND l.IsDefault='Y'")
+ " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'" .append(" AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'")
+ " AND NOT EXISTS (SELECT * FROM M_Storage s" .append(" AND NOT EXISTS (SELECT * FROM M_Storage s")
+ " INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) " .append(" INNER JOIN M_Locator sl ON (s.M_Locator_ID=sl.M_Locator_ID) ")
+ "WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID" .append("WHERE sl.M_Warehouse_ID=l.M_Warehouse_ID")
+ " AND s.M_Product_ID=p.M_Product_ID)"; .append(" AND s.M_Product_ID=p.M_Product_ID)");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("'0' Inserted #" + no); log.fine("'0' Inserted #" + no);
} }
StringBuffer sql = new StringBuffer( StringBuilder sql = new StringBuilder("SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID,");
"SELECT s.M_Product_ID, s.M_Locator_ID, s.M_AttributeSetInstance_ID," sql.append(" s.QtyOnHand, p.M_AttributeSet_ID ");
+ " s.QtyOnHand, p.M_AttributeSet_ID " sql.append("FROM M_Product p");
+ "FROM M_Product p" sql.append(" INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)");
+ " INNER JOIN M_Storage s ON (s.M_Product_ID=p.M_Product_ID)" sql.append(" INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) ");
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID) " sql.append("WHERE l.M_Warehouse_ID=?");
+ "WHERE l.M_Warehouse_ID=?" sql.append(" AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");
+ " AND p.IsActive='Y' AND p.IsStocked='Y' and p.ProductType='I'");
// //
if (p_M_Locator_ID != 0) if (p_M_Locator_ID != 0)
sql.append(" AND s.M_Locator_ID=?"); sql.append(" AND s.M_Locator_ID=?");
@ -182,15 +183,17 @@ public class InventoryCountCreate extends SvrProcess
sql.append(" AND UPPER(p.Value) LIKE ?"); sql.append(" AND UPPER(p.Value) LIKE ?");
// //
if (p_M_Product_Category_ID != 0) if (p_M_Product_Category_ID != 0)
sql.append(" AND p.M_Product_Category_ID IN (" + getSubCategoryWhereClause(p_M_Product_Category_ID) + ")"); sql.append(" AND p.M_Product_Category_ID IN (")
.append(getSubCategoryWhereClause(p_M_Product_Category_ID))
.append(")");
// Do not overwrite existing records // Do not overwrite existing records
if (!p_DeleteOld) if (!p_DeleteOld)
sql.append(" AND NOT EXISTS (SELECT * FROM M_InventoryLine il " sql.append(" AND NOT EXISTS (SELECT * FROM M_InventoryLine il ")
+ "WHERE il.M_Inventory_ID=?" .append("WHERE il.M_Inventory_ID=?")
+ " AND il.M_Product_ID=s.M_Product_ID" .append(" AND il.M_Product_ID=s.M_Product_ID")
+ " AND il.M_Locator_ID=s.M_Locator_ID" .append(" AND il.M_Locator_ID=s.M_Locator_ID")
+ " AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))"); .append(" AND COALESCE(il.M_AttributeSetInstance_ID,0)=COALESCE(s.M_AttributeSetInstance_ID,0))");
// + " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)"); // + " AND il.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID)");
// //
sql.append(" ORDER BY l.Value, p.Value, s.QtyOnHand DESC"); // Locator/Product sql.append(" ORDER BY l.Value, p.Value, s.QtyOnHand DESC"); // Locator/Product
@ -373,7 +376,7 @@ public class InventoryCountCreate extends SvrProcess
* @throws AdempiereSystemError if a loop is detected * @throws AdempiereSystemError if a loop is detected
*/ */
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError { private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = ""; StringBuilder ret = new StringBuilder();
final Iterator iter = categories.iterator(); final Iterator iter = categories.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next(); SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -381,11 +384,12 @@ public class InventoryCountCreate extends SvrProcess
if (node.getNodeId() == loopIndicatorId) { if (node.getNodeId() == loopIndicatorId) {
throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId); throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId);
} }
ret = ret + getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId) + ","; ret.append(getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId));
ret.append(",");
} }
} }
log.fine(ret); log.fine(ret.toString());
return ret + productCategoryId; return ret.toString() + productCategoryId;
} }
/** /**

View File

@ -79,10 +79,10 @@ public class M_PriceList_Create extends SvrProcess {
*/ */
protected String doIt() throws Exception { protected String doIt() throws Exception {
String sql; StringBuilder sql = new StringBuilder();
String sqlupd; StringBuilder sqlupd = new StringBuilder();
String sqldel; StringBuilder sqldel = new StringBuilder();
String sqlins; StringBuilder sqlins = new StringBuilder();
int cntu = 0; int cntu = 0;
int cntd = 0; int cntd = 0;
int cnti = 0; int cnti = 0;
@ -96,62 +96,61 @@ public class M_PriceList_Create extends SvrProcess {
//Checking Prerequisites //Checking Prerequisites
//PO Prices must exists //PO Prices must exists
// //
sqlupd = "UPDATE M_Product_PO " + " SET PriceList = 0 " sqlupd.append("UPDATE M_Product_PO SET PriceList = 0 ")
+ " WHERE PriceList IS NULL "; .append(" WHERE PriceList IS NULL ");
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError( raiseError(
"Update The PriceList to zero of M_Product_PO WHERE PriceList IS NULL", "Update The PriceList to zero of M_Product_PO WHERE PriceList IS NULL",
sqlupd); sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
sqlupd = "UPDATE M_Product_PO " + " SET PriceLastPO = 0 " sqlupd = new StringBuilder("UPDATE M_Product_PO SET PriceLastPO = 0 ");
+ " WHERE PriceLastPO IS NULL "; sqlupd.append(" WHERE PriceLastPO IS NULL ");
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError( raiseError(
"Update The PriceListPO to zero of M_Product_PO WHERE PriceLastPO IS NULL", "Update The PriceListPO to zero of M_Product_PO WHERE PriceLastPO IS NULL",
sqlupd); sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
sqlupd = "UPDATE M_Product_PO " sqlupd = new StringBuilder("UPDATE M_Product_PO SET PricePO = PriceLastPO ");
+ " SET PricePO = PriceLastPO " sqlupd.append(" WHERE (PricePO IS NULL OR PricePO = 0) AND PriceLastPO <> 0 ");
+ " WHERE (PricePO IS NULL OR PricePO = 0) AND PriceLastPO <> 0 ";
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError( raiseError(
"Update The PricePO to PriceLastPO of M_Product_PO WHERE (PricePO IS NULL OR PricePO = 0) AND PriceLastPO <> 0 ", "Update The PricePO to PriceLastPO of M_Product_PO WHERE (PricePO IS NULL OR PricePO = 0) AND PriceLastPO <> 0 ",
sqlupd); sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
sqlupd = "UPDATE M_Product_PO " + " SET PricePO = 0 " sqlupd = new StringBuilder("UPDATE M_Product_PO SET PricePO = 0 ");
+ " WHERE PricePO IS NULL "; sqlupd.append(" WHERE PricePO IS NULL ");
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError( raiseError(
"Update The PricePO to Zero of M_Product_PO WHERE PricePO IS NULL", "Update The PricePO to Zero of M_Product_PO WHERE PricePO IS NULL",
sqlupd); sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
// //
// Set default current vendor // Set default current vendor
// //
sqlupd = "UPDATE M_Product_PO " + " SET IsCurrentVendor = 'Y' " sqlupd = new StringBuilder("UPDATE M_Product_PO SET IsCurrentVendor = 'Y' ");
+ " WHERE IsCurrentVendor = 'N' " + " AND NOT EXISTS " sqlupd.append(" WHERE IsCurrentVendor = 'N' AND NOT EXISTS ");
+ " (SELECT pp.M_Product_ID " + " FROM M_Product_PO pp " sqlupd.append(" (SELECT pp.M_Product_ID FROM M_Product_PO pp ");
+ " WHERE pp.M_Product_ID = M_Product_PO.M_Product_ID" sqlupd.append(" WHERE pp.M_Product_ID = M_Product_PO.M_Product_ID");
+ " GROUP BY pp.M_Product_ID HAVING COUNT(*) > 1) "; sqlupd.append(" GROUP BY pp.M_Product_ID HAVING COUNT(*) > 1) ");
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError("Update IsCurrentVendor to Y of M_Product_PO ", sqlupd); raiseError("Update IsCurrentVendor to Y of M_Product_PO ", sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
@ -161,26 +160,26 @@ public class M_PriceList_Create extends SvrProcess {
// //
// Make sure that we have only one active product // Make sure that we have only one active product
// //
sql = "SELECT DISTINCT M_Product_ID FROM M_Product_PO po " sql.append("SELECT DISTINCT M_Product_ID FROM M_Product_PO po ");
+ " WHERE IsCurrentVendor='Y' AND IsActive='Y' " sql.append(" WHERE IsCurrentVendor='Y' AND IsActive='Y' ");
+ " AND EXISTS (SELECT M_Product_ID " sql.append(" AND EXISTS (SELECT M_Product_ID ");
+ " FROM M_Product_PO x " sql.append(" FROM M_Product_PO x ");
+ " WHERE x.M_Product_ID=po.M_Product_ID " sql.append(" WHERE x.M_Product_ID=po.M_Product_ID ");
+ " AND IsCurrentVendor='Y' AND IsActive='Y' " sql.append(" AND IsCurrentVendor='Y' AND IsActive='Y' ");
+ " GROUP BY M_Product_ID " + " HAVING COUNT(*) > 1 ) "; sql.append(" GROUP BY M_Product_ID ").append(" HAVING COUNT(*) > 1 ) ");
PreparedStatement Cur_Duplicates = null; PreparedStatement Cur_Duplicates = null;
Cur_Duplicates = DB.prepareStatement(sql, get_TrxName()); Cur_Duplicates = DB.prepareStatement(sql.toString(), get_TrxName());
ResultSet dupl = Cur_Duplicates.executeQuery(); ResultSet dupl = Cur_Duplicates.executeQuery();
while (dupl.next()) { while (dupl.next()) {
sql = "SELECT M_Product_ID " + " ,C_BPartner_ID " sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID ");
+ " FROM M_Product_PO " + " WHERE IsCurrentVendor = 'Y' " sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' ");
+ " AND IsActive = 'Y' " sql.append(" AND IsActive = 'Y' ");
+ " AND M_Product_ID = " + dupl.getInt("M_Product_ID") sql.append(" AND M_Product_ID = ").append(dupl.getInt("M_Product_ID"));
+ " ORDER BY PriceList DESC"; sql.append(" ORDER BY PriceList DESC");
PreparedStatement Cur_Vendors = null; PreparedStatement Cur_Vendors = null;
Cur_Vendors = DB.prepareStatement(sql, get_TrxName()); Cur_Vendors = DB.prepareStatement(sql.toString(), get_TrxName());
ResultSet Vend = Cur_Vendors.executeQuery(); ResultSet Vend = Cur_Vendors.executeQuery();
// //
@ -189,17 +188,17 @@ public class M_PriceList_Create extends SvrProcess {
Vend.next(); Vend.next();
while (Vend.next()) { while (Vend.next()) {
sqlupd = "UPDATE M_Product_PO " sqlupd = new StringBuilder("UPDATE M_Product_PO ");
+ " SET IsCurrentVendor = 'N' " sqlupd.append(" SET IsCurrentVendor = 'N' ");
+ " WHERE M_Product_ID= " + Vend.getInt("M_Product_ID") sqlupd.append(" WHERE M_Product_ID= ").append(Vend.getInt("M_Product_ID"));
+ " AND C_BPartner_ID= " sqlupd.append(" AND C_BPartner_ID= ");
+ Vend.getInt("C_BPartner_ID"); sqlupd.append(Vend.getInt("C_BPartner_ID"));
cntu = DB.executeUpdate(sqlupd, get_TrxName()); cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError( raiseError(
"Update IsCurrentVendor to N of M_Product_PO for a M_Product_ID and C_BPartner_ID ingresed", "Update IsCurrentVendor to N of M_Product_PO for a M_Product_ID and C_BPartner_ID ingresed",
sqlupd); sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
@ -219,12 +218,12 @@ public class M_PriceList_Create extends SvrProcess {
// Delete Old Data // Delete Old Data
// //
if (p_DeleteOld.equals("Y")) { if (p_DeleteOld.equals("Y")) {
sqldel = "DELETE M_ProductPrice " sqldel.append("DELETE M_ProductPrice ")
+ " WHERE M_PriceList_Version_ID = " .append(" WHERE M_PriceList_Version_ID = ")
+ p_PriceList_Version_ID; .append(p_PriceList_Version_ID);
cntd = DB.executeUpdate(sqldel, get_TrxName()); cntd = DB.executeUpdate(sqldel.toString(), get_TrxName());
if (cntd == -1) if (cntd == -1)
raiseError(" DELETE M_ProductPrice ", sqldel); raiseError(" DELETE M_ProductPrice ", sqldel.toString());
totd += cntd; totd += cntd;
Message = "@Deleted@=" + cntd + " - "; Message = "@Deleted@=" + cntd + " - ";
log.fine("Deleted " + cntd); log.fine("Deleted " + cntd);
@ -232,43 +231,47 @@ public class M_PriceList_Create extends SvrProcess {
// //
// Get PriceList Info // Get PriceList Info
// //
sql = "SELECT p.C_Currency_ID " + " , c.StdPrecision " sql = new StringBuilder("SELECT p.C_Currency_ID , c.StdPrecision ");
+ " , v.AD_Client_ID " + " , v.AD_Org_ID " + " , v.UpdatedBy " sql.append(" , v.AD_Client_ID , v.AD_Org_ID , v.UpdatedBy ");
+ " , v.M_DiscountSchema_ID " sql.append(" , v.M_DiscountSchema_ID ");
+ " , M_PriceList_Version_Base_ID " + " FROM M_PriceList p " sql.append(" , M_PriceList_Version_Base_ID FROM M_PriceList p ");
+ " ,M_PriceList_Version v " + " ,C_Currency c " sql.append(" ,M_PriceList_Version v ,C_Currency c ");
+ " WHERE p.M_PriceList_ID = v.M_PriceList_ID " sql.append(" WHERE p.M_PriceList_ID = v.M_PriceList_ID ");
+ " AND p.C_Currency_ID = c.C_Currency_ID" sql.append(" AND p.C_Currency_ID = c.C_Currency_ID");
+ " AND v.M_PriceList_Version_ID = " + p_PriceList_Version_ID; sql.append(" AND v.M_PriceList_Version_ID = ").append(p_PriceList_Version_ID);
PreparedStatement curgen = null; PreparedStatement curgen = null;
curgen = DB.prepareStatement(sql, get_TrxName()); curgen = DB.prepareStatement(sql.toString(), get_TrxName());
ResultSet v = curgen.executeQuery(); ResultSet v = curgen.executeQuery();
while (v.next()) { while (v.next()) {
// //
// For All Discount Lines in Sequence // For All Discount Lines in Sequence
// //
sql = "SELECT m_discountschemaline_id" sql = new StringBuilder("SELECT m_discountschemaline_id");
+ ",ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby" sql.append(",ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby");
+ ",m_discountschema_id,seqno,m_product_category_id,c_bpartner_id,m_product_id" sql.append(",m_discountschema_id,seqno,m_product_category_id,c_bpartner_id,m_product_id");
+ ",conversiondate,list_base,list_addamt,list_discount,list_rounding,list_minamt" sql.append(",conversiondate,list_base,list_addamt,list_discount,list_rounding,list_minamt");
+ ",list_maxamt,list_fixed,std_base,std_addamt,std_discount,std_rounding" sql.append(",list_maxamt,list_fixed,std_base,std_addamt,std_discount,std_rounding");
+ ",std_minamt,std_maxamt,std_fixed,limit_base,limit_addamt,limit_discount" sql.append(",std_minamt,std_maxamt,std_fixed,limit_base,limit_addamt,limit_discount");
+ ",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id" sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id");
+ " FROM M_DiscountSchemaLine" sql.append(" FROM M_DiscountSchemaLine");
+ " WHERE M_DiscountSchema_ID=" sql.append(" WHERE M_DiscountSchema_ID=");
+ v.getInt("M_DiscountSchema_ID") sql.append(v.getInt("M_DiscountSchema_ID"));
+ " AND IsActive='Y' ORDER BY SeqNo"; sql.append(" AND IsActive='Y' ORDER BY SeqNo");
PreparedStatement Cur_DiscountLine = null; PreparedStatement Cur_DiscountLine = null;
Cur_DiscountLine = DB.prepareStatement(sql, get_TrxName()); Cur_DiscountLine = DB.prepareStatement(sql.toString(), get_TrxName());
ResultSet dl = Cur_DiscountLine.executeQuery(); ResultSet dl = Cur_DiscountLine.executeQuery();
while (dl.next()) { while (dl.next()) {
// //
//Clear Temporary Table //Clear Temporary Table
// //
sqldel = "DELETE FROM T_Selection WHERE AD_PInstance_ID="+ m_AD_PInstance_ID; sqldel = new StringBuilder("DELETE FROM T_Selection WHERE AD_PInstance_ID=");
cntd = DB.executeUpdate(sqldel, get_TrxName()); sqldel.append(m_AD_PInstance_ID);
cntd = DB.executeUpdate(sqldel.toString(), get_TrxName());
if (cntd == -1) if (cntd == -1)
raiseError(" DELETE T_Selection ", sqldel); raiseError(" DELETE T_Selection ", sqldel.toString());
totd += cntd; totd += cntd;
log.fine("Deleted " + cntd); log.fine("Deleted " + cntd);
// //
@ -281,29 +284,30 @@ public class M_PriceList_Create extends SvrProcess {
// //
//Create Selection from M_Product_PO //Create Selection from M_Product_PO
// //
sqlins = "INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID) " sqlins.append("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID) ");
+ " SELECT DISTINCT " + m_AD_PInstance_ID +", po.M_Product_ID " sqlins.append( " SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", po.M_Product_ID ");
+ " FROM M_Product p, M_Product_PO po" sqlins.append(" FROM M_Product p, M_Product_PO po");
+ " WHERE p.M_Product_ID=po.M_Product_ID " sqlins.append(" WHERE p.M_Product_ID=po.M_Product_ID ");
+ " AND (p.AD_Client_ID=" + v.getInt("AD_Client_ID") + " OR p.AD_Client_ID=0)" sqlins.append(" AND (p.AD_Client_ID=").append(v.getInt("AD_Client_ID")).append(" OR p.AD_Client_ID=0)");
+ " AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' " sqlins.append(" AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' ");
// //
//Optional Restrictions //Optional Restrictions
// //
// globalqss - detected bug, JDBC returns zero for null values // globalqss - detected bug, JDBC returns zero for null values
// so we're going to use NULLIF(value, 0) // so we're going to use NULLIF(value, 0)
+ " AND (NULLIF(" + dl.getInt("M_Product_Category_ID") + ",0) IS NULL" sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
+ " OR p.M_Product_Category_ID IN (" + getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")) + "))"; sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")))
.append("))");
if(dl_Group1 != null) if(dl_Group1 != null)
sqlins = sqlins + " AND (p.Group1=?)"; sqlins.append(" AND (p.Group1=?)");
if (dl_Group2 != null) if (dl_Group2 != null)
sqlins = sqlins + " AND (p.Group2=?)"; sqlins.append(" AND (p.Group2=?)");
sqlins = sqlins + " AND (NULLIF(" + dl.getInt("C_BPartner_ID") + ",0) IS NULL " sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL ");
+ " OR po.C_BPartner_ID=" + dl.getInt("C_BPartner_ID") + ")" sqlins.append(" OR po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append(")");
+ " AND (NULLIF(" + dl.getInt("M_Product_ID") + ",0) IS NULL " sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
+ " OR p.M_Product_ID=" + dl.getInt("M_Product_ID") + ")"; sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
CPreparedStatement stmt = DB.prepareStatement(sqlins, get_TrxName()); CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
int i = 1; int i = 1;
@ -315,7 +319,7 @@ public class M_PriceList_Create extends SvrProcess {
cnti = stmt.executeUpdate(); cnti = stmt.executeUpdate();
if (cnti == -1) if (cnti == -1)
raiseError(" INSERT INTO T_Selection ", sqlins); raiseError(" INSERT INTO T_Selection ", sqlins.toString());
toti += cnti; toti += cnti;
log.fine("Inserted " + cnti); log.fine("Inserted " + cnti);
@ -323,36 +327,37 @@ public class M_PriceList_Create extends SvrProcess {
// //
// Create Selection from existing PriceList // Create Selection from existing PriceList
// //
sqlins = "INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID)" sqlins = new StringBuilder("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID)");
+ " SELECT DISTINCT " + m_AD_PInstance_ID +", p.M_Product_ID" sqlins.append(" SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", p.M_Product_ID");
+ " FROM M_Product p, M_ProductPrice pp" sqlins.append(" FROM M_Product p, M_ProductPrice pp");
+ " WHERE p.M_Product_ID=pp.M_Product_ID" sqlins.append(" WHERE p.M_Product_ID=pp.M_Product_ID");
+ " AND pp.M_PriceList_Version_ID = " + v.getInt("M_PriceList_Version_Base_ID") sqlins.append(" AND pp.M_PriceList_Version_ID = ").append(v.getInt("M_PriceList_Version_Base_ID"));
+ " AND p.IsActive='Y' AND pp.IsActive='Y'" sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'");
// //
//Optional Restrictions //Optional Restrictions
// //
+ " AND (NULLIF(" + dl.getInt("M_Product_Category_ID") + ",0) IS NULL" sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
+ " OR p.M_Product_Category_ID IN (" + getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")) + "))"; sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")))
.append("))");
if(dl_Group1 != null) if(dl_Group1 != null)
sqlins = sqlins + " AND (p.Group1=?)"; sqlins.append(" AND (p.Group1=?)");
if (dl_Group2 != null) if (dl_Group2 != null)
sqlins = sqlins + " AND (p.Group2=?)"; sqlins.append(" AND (p.Group2=?)");
sqlins = sqlins + " AND (NULLIF(" + dl.getInt("C_BPartner_ID") + ",0) IS NULL OR EXISTS " sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS ");
+ "(SELECT m_product_id,c_bpartner_id,ad_client_id,ad_org_id,isactive" sqlins.append("(SELECT m_product_id,c_bpartner_id,ad_client_id,ad_org_id,isactive");
+ ",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id" sqlins.append(",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id");
+ ",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo" sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo");
+ ",pricelastinv,vendorproductno,upc,vendorcategory,discontinued" sqlins.append(",pricelastinv,vendorproductno,upc,vendorcategory,discontinued");
+ ",discontinuedby,order_min,order_pack,costperorder" sqlins.append(",discontinuedby,order_min,order_pack,costperorder");
+ ",deliverytime_promised,deliverytime_actual,qualityrating" sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating");
+ ",royaltyamt,group1,group2" sqlins.append(",royaltyamt,group1,group2");
+ ",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID" sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID");
+ " AND po.C_BPartner_ID=" + dl.getInt("C_BPartner_ID") + "))" sqlins.append(" AND po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append("))");
+ " AND (NULLIF(" + dl.getInt("M_Product_ID") + ",0) IS NULL " sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
+ " OR p.M_Product_ID=" + dl.getInt("M_Product_ID") + ")"; sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
CPreparedStatement stmt = DB.prepareStatement(sqlins, get_TrxName()); CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
int i = 1; int i = 1;
if (dl_Group1!=null) if (dl_Group1!=null)
@ -364,7 +369,7 @@ public class M_PriceList_Create extends SvrProcess {
if (cnti == -1) if (cnti == -1)
raiseError( raiseError(
" INSERT INTO T_Selection from existing PriceList", " INSERT INTO T_Selection from existing PriceList",
sqlins); sqlins.toString());
toti += cnti; toti += cnti;
log.fine("Inserted " + cnti); log.fine("Inserted " + cnti);
@ -378,15 +383,15 @@ public class M_PriceList_Create extends SvrProcess {
V_temp = v.getInt("M_PriceList_Version_Base_ID"); V_temp = v.getInt("M_PriceList_Version_Base_ID");
if (v.wasNull() || V_temp != p_PriceList_Version_ID) { if (v.wasNull() || V_temp != p_PriceList_Version_ID) {
sqldel = "DELETE M_ProductPrice pp" sqldel = new StringBuilder("DELETE M_ProductPrice pp");
+ " WHERE pp.M_PriceList_Version_ID = " sqldel.append(" WHERE pp.M_PriceList_Version_ID = ");
+ p_PriceList_Version_ID sqldel.append(p_PriceList_Version_ID);
+ " AND EXISTS (SELECT t_selection_id FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID" sqldel.append(" AND EXISTS (SELECT t_selection_id FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ")"; sqldel.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
cntd = DB.executeUpdate(sqldel, get_TrxName()); cntd = DB.executeUpdate(sqldel.toString(), get_TrxName());
if (cntd == -1) if (cntd == -1)
raiseError(" DELETE M_ProductPrice ", sqldel); raiseError(" DELETE M_ProductPrice ", sqldel.toString());
totd += cntd; totd += cntd;
Message = Message + ", @Deleted@=" + cntd; Message = Message + ", @Deleted@=" + cntd;
log.fine("Deleted " + cntd); log.fine("Deleted " + cntd);
@ -406,71 +411,71 @@ public class M_PriceList_Create extends SvrProcess {
//Copy and Convert from Product_PO //Copy and Convert from Product_PO
// //
{ {
sqlins = "INSERT INTO M_ProductPrice " sqlins = new StringBuilder("INSERT INTO M_ProductPrice ");
+ "(M_PriceList_Version_ID" sqlins.append("(M_PriceList_Version_ID");
+ " ,M_Product_ID " sqlins.append(" ,M_Product_ID ");
+ " ,AD_Client_ID" sqlins.append(" ,AD_Client_ID");
+ " , AD_Org_ID" sqlins.append(" , AD_Org_ID");
+ " , IsActive" sqlins.append(" , IsActive");
+ " , Created" sqlins.append(" , Created");
+ " , CreatedBy" sqlins.append(" , CreatedBy");
+ " , Updated" sqlins.append(" , Updated");
+ " , UpdatedBy" sqlins.append(" , UpdatedBy");
+ " , PriceList" sqlins.append(" , PriceList");
+ " , PriceStd" sqlins.append(" , PriceStd");
+ " , PriceLimit) " sqlins.append(" , PriceLimit) ");
+ "SELECT " sqlins.append("SELECT ");
+ p_PriceList_Version_ID sqlins.append(p_PriceList_Version_ID);
+ " ,po.M_Product_ID " sqlins.append(" ,po.M_Product_ID ");
+ " ," sqlins.append(" ,");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ " ," sqlins.append(" ,");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ " ,'Y'" sqlins.append(" ,'Y'");
+ " ,SysDate," sqlins.append(" ,SysDate,");
+ v.getInt("UpdatedBy") sqlins.append(v.getInt("UpdatedBy"));
+ " ,SysDate," sqlins.append(" ,SysDate,");
+ v.getInt("UpdatedBy") sqlins.append(v.getInt("UpdatedBy"));
// //
//Price List //Price List
// //
+ " ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, " sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ ", ? , " sqlins.append(", ? , ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)" sqlins.append("),0)");
// Price Std // Price Std
+ " ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, " sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ ", ? , " sqlins.append(", ? , ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)" sqlins.append("),0)");
// Price Limit // Price Limit
+ " ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, " sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ ",? , " sqlins.append(",? , ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)" sqlins.append("),0)");
+ " FROM M_Product_PO po " sqlins.append(" FROM M_Product_PO po ");
+ " WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID" sqlins.append(" WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ") " sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(") ");
+ " AND po.IsCurrentVendor='Y' AND po.IsActive='Y'"; sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'");
PreparedStatement pstmt = DB.prepareStatement(sqlins, PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, get_TrxName()); ResultSet.CONCUR_UPDATABLE, get_TrxName());
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate")); pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
@ -481,68 +486,68 @@ public class M_PriceList_Create extends SvrProcess {
if (cnti == -1) if (cnti == -1)
raiseError( raiseError(
" INSERT INTO T_Selection from existing PriceList", " INSERT INTO T_Selection from existing PriceList",
sqlins); sqlins.toString());
toti += cnti; toti += cnti;
log.fine("Inserted " + cnti); log.fine("Inserted " + cnti);
} else { } else {
// //
//Copy and Convert from other PriceList_Version //Copy and Convert from other PriceList_Version
// //
sqlins = "INSERT INTO M_ProductPrice " sqlins = new StringBuilder("INSERT INTO M_ProductPrice ");
+ " (M_PriceList_Version_ID, M_Product_ID," sqlins.append(" (M_PriceList_Version_ID, M_Product_ID,");
+ " AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy," sqlins.append(" AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,");
+ " PriceList, PriceStd, PriceLimit)" sqlins.append(" PriceList, PriceStd, PriceLimit)");
+ " SELECT " sqlins.append(" SELECT ");
+ p_PriceList_Version_ID sqlins.append(p_PriceList_Version_ID);
+ ", pp.M_Product_ID," sqlins.append(", pp.M_Product_ID,");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ ", 'Y', SysDate, " sqlins.append(", 'Y', SysDate, ");
+ v.getInt("UpdatedBy") sqlins.append(v.getInt("UpdatedBy"));
+ ", SysDate, " sqlins.append(", SysDate, ");
+ v.getInt("UpdatedBy") sqlins.append(v.getInt("UpdatedBy"));
+ " ," sqlins.append(" ,");
// Price List // Price List
+ "COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, " sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ ", ?, " sqlins.append(", ?, ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)," sqlins.append("),0),");
// Price Std // Price Std
+ "COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, " sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ " , ? , " sqlins.append(" , ? , ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)," sqlins.append("),0),");
//Price Limit //Price Limit
+ " COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, " sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, ");
+ v.getInt("C_Currency_ID") sqlins.append(v.getInt("C_Currency_ID"));
+ " , ? , " sqlins.append(" , ? , ");
+ dl.getInt("C_ConversionType_ID") sqlins.append(dl.getInt("C_ConversionType_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Client_ID") sqlins.append(v.getInt("AD_Client_ID"));
+ ", " sqlins.append(", ");
+ v.getInt("AD_Org_ID") sqlins.append(v.getInt("AD_Org_ID"));
+ "),0)" sqlins.append("),0)");
+ " FROM M_ProductPrice pp" sqlins.append(" FROM M_ProductPrice pp");
+ " INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)" sqlins.append(" INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)");
+ " INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)" sqlins.append(" INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)");
+ " WHERE pp.M_PriceList_Version_ID=" sqlins.append(" WHERE pp.M_PriceList_Version_ID=");
+ v.getInt("M_PriceList_Version_Base_ID") sqlins.append(v.getInt("M_PriceList_Version_Base_ID"));
+ " AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID" sqlins.append(" AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ")" sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
+ "AND pp.IsActive='Y'"; sqlins.append("AND pp.IsActive='Y'");
PreparedStatement pstmt = DB.prepareStatement(sqlins, PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, get_TrxName()); ResultSet.CONCUR_UPDATABLE, get_TrxName());
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate")); pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
@ -554,7 +559,7 @@ public class M_PriceList_Create extends SvrProcess {
if (cnti == -1) if (cnti == -1)
raiseError( raiseError(
" INSERT INTO T_Selection from existing PriceList", " INSERT INTO T_Selection from existing PriceList",
sqlins); sqlins.toString());
toti += cnti; toti += cnti;
log.fine("Inserted " + cnti); log.fine("Inserted " + cnti);
@ -563,23 +568,24 @@ public class M_PriceList_Create extends SvrProcess {
// //
// Calculation // Calculation
// //
sqlupd = "UPDATE M_ProductPrice p " sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
+ " SET PriceList = (DECODE( '" sqlupd.append(" SET PriceList = (DECODE( '");
+ dl.getString("List_Base") sqlupd.append(dl.getString("List_Base"));
+ "', 'S', PriceStd, 'X', PriceLimit, PriceList)" sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)");
+ " + ?) * (1 - ?/100)," + " PriceStd = (DECODE('" sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('");
+ dl.getString("Std_Base") sqlupd.append(dl.getString("Std_Base"));
+ "', 'L', PriceList, 'X', PriceLimit, PriceStd) " sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) ");
+ " + ?) * (1 - ?/100), " + " PriceLimit = (DECODE('" sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('");
+ dl.getString("Limit_Base") sqlupd.append(dl.getString("Limit_Base"));
+ "', 'L', PriceList, 'S', PriceStd, PriceLimit) " sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) ");
+ " + ?) * (1 - ? /100) " sqlupd.append(" + ?) * (1 - ? /100) ");
+ " WHERE M_PriceList_Version_ID = " sqlupd.append(" WHERE M_PriceList_Version_ID = ");
+ p_PriceList_Version_ID sqlupd.append(p_PriceList_Version_ID);
+ " AND EXISTS (SELECT * FROM T_Selection s " sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s ");
+ " WHERE s.T_Selection_ID = p.M_Product_ID" sqlupd.append(" WHERE s.T_Selection_ID = p.M_Product_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ")"; sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
PreparedStatement pstmu = DB.prepareStatement(sqlupd,
PreparedStatement pstmu = DB.prepareStatement(sqlupd.toString(),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, get_TrxName()); ResultSet.CONCUR_UPDATABLE, get_TrxName());
@ -593,59 +599,60 @@ public class M_PriceList_Create extends SvrProcess {
cntu = pstmu.executeUpdate(); cntu = pstmu.executeUpdate();
if (cntu == -1) if (cntu == -1)
raiseError("Update M_ProductPrice ", sqlupd); raiseError("Update M_ProductPrice ", sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
// //
//Rounding (AD_Reference_ID=155) //Rounding (AD_Reference_ID=155)
// //
sqlupd = "UPDATE M_ProductPrice p " sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
+ " SET PriceList = DECODE('" sqlupd.append(" SET PriceList = DECODE('");
+ dl.getString("List_Rounding") + "'," sqlupd.append(dl.getString("List_Rounding")).append("',");
+ " 'N', PriceList, " sqlupd.append(" 'N', PriceList, ");
+ " '0', ROUND(PriceList, 0)," //Even .00 sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00
+ " 'D', ROUND(PriceList, 1)," //Dime .10 sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10
+ " 'T', ROUND(PriceList, -1), " //Ten 10.00 sqlupd.append(" 'T', ROUND(PriceList, -1), "); //Ten 10.00
+ " '5', ROUND(PriceList*20,0)/20," //Nickle .05 sqlupd.append(" '5', ROUND(PriceList*20,0)/20,"); //Nickle .05
+ " 'Q', ROUND(PriceList*4,0)/4," //Quarter .25 sqlupd.append(" 'Q', ROUND(PriceList*4,0)/4,"); //Quarter .25
+ " '9', CASE" //Whole 9 or 5 sqlupd.append(" '9', CASE"); //Whole 9 or 5
+ " WHEN MOD(ROUND(PriceList),10)<=5 THEN ROUND(PriceList)+(5-MOD(ROUND(PriceList),10))" sqlupd.append(" WHEN MOD(ROUND(PriceList),10)<=5 THEN ROUND(PriceList)+(5-MOD(ROUND(PriceList),10))");
+ " WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END," sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,");
+ " ROUND(PriceList, " + v.getInt("StdPrecision") sqlupd.append(" ROUND(PriceList, ").append(v.getInt("StdPrecision"));
+ "))," //Currency sqlupd.append(")),");//Currency
+ " PriceStd = DECODE('" + dl.getString("Std_Rounding") sqlupd.append(" PriceStd = DECODE('").append(dl.getString("Std_Rounding"));
+ "'," + " 'N', PriceStd, " sqlupd.append("',").append(" 'N', PriceStd, ");
+ " '0', ROUND(PriceStd, 0), " //Even .00 sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00
+ " 'D', ROUND(PriceStd, 1), " //Dime .10 sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10
+ "'T', ROUND(PriceStd, -1)," //Ten 10.00 sqlupd.append("'T', ROUND(PriceStd, -1),"); //Ten 10.00)
+ "'5', ROUND(PriceStd*20,0)/20," //Nickle .05 sqlupd.append("'5', ROUND(PriceStd*20,0)/20,"); //Nickle .05
+ "'Q', ROUND(PriceStd*4,0)/4," //Quarter .25 sqlupd.append("'Q', ROUND(PriceStd*4,0)/4,"); //Quarter .25
+ " '9', CASE" //Whole 9 or 5 sqlupd.append(" '9', CASE"); //Whole 9 or 5
+ " WHEN MOD(ROUND(PriceStd),10)<=5 THEN ROUND(PriceStd)+(5-MOD(ROUND(PriceStd),10))" sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)<=5 THEN ROUND(PriceStd)+(5-MOD(ROUND(PriceStd),10))");
+ " WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END," sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,");
+ "ROUND(PriceStd, " + v.getInt("StdPrecision") + "))," //Currency sqlupd.append("ROUND(PriceStd, ").append(v.getInt("StdPrecision")).append(")),"); //Currency
+ "PriceLimit = DECODE('" sqlupd.append("PriceLimit = DECODE('");
+ dl.getString("Limit_Rounding") + "', " sqlupd.append(dl.getString("Limit_Rounding")).append("', ");
+ " 'N', PriceLimit, " sqlupd.append(" 'N', PriceLimit, ");
+ " '0', ROUND(PriceLimit, 0), " // Even .00 sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00
+ " 'D', ROUND(PriceLimit, 1), " // Dime .10 sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10
+ " 'T', ROUND(PriceLimit, -1), " // Ten 10.00 sqlupd.append(" 'T', ROUND(PriceLimit, -1), "); // Ten 10.00
+ " '5', ROUND(PriceLimit*20,0)/20, " // Nickle .05 sqlupd.append(" '5', ROUND(PriceLimit*20,0)/20, "); // Nickle .05
+ " 'Q', ROUND(PriceLimit*4,0)/4, " //Quarter .25 sqlupd.append(" 'Q', ROUND(PriceLimit*4,0)/4, "); //Quarter .25
+ " '9', CASE" //Whole 9 or 5 sqlupd.append(" '9', CASE"); //Whole 9 or 5
+ " WHEN MOD(ROUND(PriceLimit),10)<=5 THEN ROUND(PriceLimit)+(5-MOD(ROUND(PriceLimit),10))" sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)<=5 THEN ROUND(PriceLimit)+(5-MOD(ROUND(PriceLimit),10))");
+ " WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END," sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,");
+ " ROUND(PriceLimit, " + v.getInt("StdPrecision") sqlupd.append(" ROUND(PriceLimit, ").append(v.getInt("StdPrecision"));
+ ")) " // Currency sqlupd.append(")) "); // Currency
+ " WHERE M_PriceList_Version_ID=" sqlupd.append(" WHERE M_PriceList_Version_ID=");
+ p_PriceList_Version_ID sqlupd.append(p_PriceList_Version_ID);
+ " AND EXISTS (SELECT * FROM T_Selection s " sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s ");
+ " WHERE s.T_Selection_ID=p.M_Product_ID" sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ")"; sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
cntu = DB.executeUpdate(sqlupd, get_TrxName());
cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError("Update M_ProductPrice ", sqlupd); raiseError("Update M_ProductPrice ", sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
@ -653,24 +660,25 @@ public class M_PriceList_Create extends SvrProcess {
// //
//Fixed Price overwrite //Fixed Price overwrite
// //
sqlupd = "UPDATE M_ProductPrice p " sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
+ " SET PriceList = DECODE('" sqlupd.append(" SET PriceList = DECODE('");
+ dl.getString("List_Base") + "', 'F', " sqlupd.append(dl.getString("List_Base")).append("', 'F', ");
+ dl.getDouble("List_Fixed") + ", PriceList), " sqlupd.append(dl.getDouble("List_Fixed")).append(", PriceList), ");
+ " PriceStd = DECODE('" sqlupd.append(" PriceStd = DECODE('");
+ dl.getString("Std_Base") + "', 'F', " sqlupd.append(dl.getString("Std_Base")).append("', 'F', ");
+ dl.getDouble("Std_Fixed") + ", PriceStd)," sqlupd.append(dl.getDouble("Std_Fixed")).append(", PriceStd),");
+ " PriceLimit = DECODE('" sqlupd.append(" PriceLimit = DECODE('");
+ dl.getString("Limit_Base") + "', 'F', " sqlupd.append(dl.getString("Limit_Base")).append("', 'F', ");
+ dl.getDouble("Limit_Fixed") + ", PriceLimit)" sqlupd.append(dl.getDouble("Limit_Fixed")).append(", PriceLimit)");
+ " WHERE M_PriceList_Version_ID=" sqlupd.append(" WHERE M_PriceList_Version_ID=");
+ p_PriceList_Version_ID sqlupd.append(p_PriceList_Version_ID);
+ " AND EXISTS (SELECT * FROM T_Selection s" sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s");
+ " WHERE s.T_Selection_ID=p.M_Product_ID" sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID");
+ " AND s.AD_PInstance_ID=" + m_AD_PInstance_ID + ")"; sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
cntu = DB.executeUpdate(sqlupd, get_TrxName());
cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
if (cntu == -1) if (cntu == -1)
raiseError("Update M_ProductPrice ", sqlupd); raiseError("Update M_ProductPrice ", sqlupd.toString());
totu += cntu; totu += cntu;
log.fine("Updated " + cntu); log.fine("Updated " + cntu);
@ -685,10 +693,10 @@ public class M_PriceList_Create extends SvrProcess {
// //
// Delete Temporary Selection // Delete Temporary Selection
// //
sqldel = "DELETE FROM T_Selection "; sqldel = new StringBuilder("DELETE FROM T_Selection ");
cntd = DB.executeUpdate(sqldel, get_TrxName()); cntd = DB.executeUpdate(sqldel.toString(), get_TrxName());
if (cntd == -1) if (cntd == -1)
raiseError(" DELETE T_Selection ", sqldel); raiseError(" DELETE T_Selection ", sqldel.toString());
totd += cntd; totd += cntd;
log.fine("Deleted " + cntd); log.fine("Deleted " + cntd);
@ -753,7 +761,7 @@ public class M_PriceList_Create extends SvrProcess {
* @throws AdempiereSystemError if a loop is detected * @throws AdempiereSystemError if a loop is detected
*/ */
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError { private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = ""; StringBuilder ret = new StringBuilder();
final Iterator iter = categories.iterator(); final Iterator iter = categories.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next(); SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -761,11 +769,12 @@ public class M_PriceList_Create extends SvrProcess {
if (node.getNodeId() == loopIndicatorId) { if (node.getNodeId() == loopIndicatorId) {
throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId); throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId);
} }
ret = ret + getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId) + ","; ret.append(getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId));
ret.append(",");
} }
} }
log.fine(ret); log.fine(ret.toString());
return ret + productCategoryId; return ret.toString() + productCategoryId;
} }
/** /**
@ -793,6 +802,6 @@ public class M_PriceList_Create extends SvrProcess {
} }
} }
} // M_PriceList_Create } // M_PriceList_Create

View File

@ -100,10 +100,11 @@ public class ReplenishReport extends SvrProcess
*/ */
protected String doIt() throws Exception protected String doIt() throws Exception
{ {
log.info("M_Warehouse_ID=" + p_M_Warehouse_ID StringBuilder msglog = new StringBuilder("M_Warehouse_ID=").append(p_M_Warehouse_ID)
+ ", C_BPartner_ID=" + p_C_BPartner_ID .append(", C_BPartner_ID=").append(p_C_BPartner_ID)
+ " - ReplenishmentCreate=" + p_ReplenishmentCreate .append(" - ReplenishmentCreate=").append(p_ReplenishmentCreate)
+ ", C_DocType_ID=" + p_C_DocType_ID); .append(", C_DocType_ID=").append(p_C_DocType_ID);
log.info(msglog.toString());
if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0) if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0)
throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@"); throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
@ -138,56 +139,57 @@ public class ReplenishReport extends SvrProcess
private void prepareTable() private void prepareTable()
{ {
// Level_Max must be >= Level_Max // Level_Max must be >= Level_Max
String sql = "UPDATE M_Replenish" StringBuilder sql = new StringBuilder("UPDATE M_Replenish")
+ " SET Level_Max = Level_Min " .append(" SET Level_Max = Level_Min ")
+ "WHERE Level_Max < Level_Min"; .append("WHERE Level_Max < Level_Min");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Max_Level=" + no); log.fine("Corrected Max_Level=" + no);
// Minimum Order should be 1 // Minimum Order should be 1
sql = "UPDATE M_Product_PO" sql = new StringBuilder("UPDATE M_Product_PO")
+ " SET Order_Min = 1 " .append(" SET Order_Min = 1 ")
+ "WHERE Order_Min IS NULL OR Order_Min < 1"; .append("WHERE Order_Min IS NULL OR Order_Min < 1");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Order Min=" + no); log.fine("Corrected Order Min=" + no);
// Pack should be 1 // Pack should be 1
sql = "UPDATE M_Product_PO" sql = new StringBuilder("UPDATE M_Product_PO")
+ " SET Order_Pack = 1 " .append(" SET Order_Pack = 1 ")
+ "WHERE Order_Pack IS NULL OR Order_Pack < 1"; .append("WHERE Order_Pack IS NULL OR Order_Pack < 1");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Order Pack=" + no); log.fine("Corrected Order Pack=" + no);
// Set Current Vendor where only one vendor // Set Current Vendor where only one vendor
sql = "UPDATE M_Product_PO p"
+ " SET IsCurrentVendor='Y' " sql = new StringBuilder("UPDATE M_Product_PO p")
+ "WHERE IsCurrentVendor<>'Y'" .append(" SET IsCurrentVendor='Y' ")
+ " AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp " .append("WHERE IsCurrentVendor<>'Y'")
+ "WHERE p.M_Product_ID=pp.M_Product_ID " .append(" AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp ")
+ "GROUP BY pp.M_Product_ID " .append("WHERE p.M_Product_ID=pp.M_Product_ID ")
+ "HAVING COUNT(*) = 1)"; .append("GROUP BY pp.M_Product_ID ")
no = DB.executeUpdate(sql, get_TrxName()); .append("HAVING COUNT(*) = 1)");
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected CurrentVendor(Y)=" + no); log.fine("Corrected CurrentVendor(Y)=" + no);
// More then one current vendor // More then one current vendor
sql = "UPDATE M_Product_PO p" sql = new StringBuilder("UPDATE M_Product_PO p")
+ " SET IsCurrentVendor='N' " .append(" SET IsCurrentVendor='N' ")
+ "WHERE IsCurrentVendor = 'Y'" .append("WHERE IsCurrentVendor = 'Y'")
+ " AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp " .append(" AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp ")
+ "WHERE p.M_Product_ID=pp.M_Product_ID AND pp.IsCurrentVendor='Y' " .append("WHERE p.M_Product_ID=pp.M_Product_ID AND pp.IsCurrentVendor='Y' ")
+ "GROUP BY pp.M_Product_ID " .append("GROUP BY pp.M_Product_ID ")
+ "HAVING COUNT(*) > 1)"; .append("HAVING COUNT(*) > 1)");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected CurrentVendor(N)=" + no); log.fine("Corrected CurrentVendor(N)=" + no);
// Just to be sure // Just to be sure
sql = "DELETE T_Replenish WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql = new StringBuilder("DELETE T_Replenish WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete Existing Temp=" + no); log.fine("Delete Existing Temp=" + no);
} // prepareTable } // prepareTable
@ -198,146 +200,146 @@ public class ReplenishReport extends SvrProcess
*/ */
private void fillTable (MWarehouse wh) throws Exception private void fillTable (MWarehouse wh) throws Exception
{ {
String sql = "INSERT INTO T_Replenish " StringBuilder sql = new StringBuilder("INSERT INTO T_Replenish ");
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," sql.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID,");
+ " ReplenishType, Level_Min, Level_Max," sql.append(" ReplenishType, Level_Min, Level_Max,");
+ " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " sql.append(" C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) ");
+ "SELECT " + getAD_PInstance_ID() sql.append("SELECT ").append(getAD_PInstance_ID());
+ ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," sql.append(", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID,");
+ " r.ReplenishType, r.Level_Min, r.Level_Max," sql.append(" r.ReplenishType, r.Level_Min, r.Level_Max,");
+ " po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, "; sql.append(" po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, ");
if (p_ReplenishmentCreate == null) if (p_ReplenishmentCreate == null)
sql += "null"; sql.append("null");
else else
sql += "'" + p_ReplenishmentCreate + "'"; sql.append("'").append(p_ReplenishmentCreate).append("'");
sql += " FROM M_Replenish r" sql.append(" FROM M_Replenish r");
+ " INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) " sql.append(" INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) ");
+ "WHERE po.IsCurrentVendor='Y'" // Only Current Vendor sql.append("WHERE po.IsCurrentVendor='Y'"); // Only Current Vendor
+ " AND r.ReplenishType<>'0'" sql.append(" AND r.ReplenishType<>'0'");
+ " AND po.IsActive='Y' AND r.IsActive='Y'" sql.append(" AND po.IsActive='Y' AND r.IsActive='Y'");
+ " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID; sql.append(" AND r.M_Warehouse_ID=").append(p_M_Warehouse_ID);
if (p_C_BPartner_ID != 0) if (p_C_BPartner_ID != 0)
sql += " AND po.C_BPartner_ID=" + p_C_BPartner_ID; sql.append(" AND po.C_BPartner_ID=").append(p_C_BPartner_ID);
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
log.finest(sql); log.finest(sql.toString());
log.fine("Insert (1) #" + no); log.fine("Insert (1) #" + no);
if (p_C_BPartner_ID == 0) if (p_C_BPartner_ID == 0)
{ {
sql = "INSERT INTO T_Replenish " sql = new StringBuilder("INSERT INTO T_Replenish ");
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," sql.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID,");
+ " ReplenishType, Level_Min, Level_Max," sql.append(" ReplenishType, Level_Min, Level_Max,");
+ " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " sql.append(" C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) ");
+ "SELECT " + getAD_PInstance_ID() sql.append("SELECT ").append(getAD_PInstance_ID());
+ ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," sql.append(", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID,");
+ " r.ReplenishType, r.Level_Min, r.Level_Max," sql.append(" r.ReplenishType, r.Level_Min, r.Level_Max,");
+ " 0, 1, 1, 0, "; sql.append(" 0, 1, 1, 0, ");
if (p_ReplenishmentCreate == null) if (p_ReplenishmentCreate == null)
sql += "null"; sql.append("null");
else else
sql += "'" + p_ReplenishmentCreate + "'"; sql.append("'").append(p_ReplenishmentCreate).append("'");
sql += " FROM M_Replenish r " sql.append(" FROM M_Replenish r ");
+ "WHERE r.ReplenishType<>'0' AND r.IsActive='Y'" sql.append("WHERE r.ReplenishType<>'0' AND r.IsActive='Y'");
+ " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID sql.append(" AND r.M_Warehouse_ID=").append(p_M_Warehouse_ID);
+ " AND NOT EXISTS (SELECT * FROM T_Replenish t " sql.append(" AND NOT EXISTS (SELECT * FROM T_Replenish t ");
+ "WHERE r.M_Product_ID=t.M_Product_ID" sql.append("WHERE r.M_Product_ID=t.M_Product_ID");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID() + ")"; sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID()).append(")");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Insert (BP) #" + no); log.fine("Insert (BP) #" + no);
} }
sql = new StringBuilder("UPDATE T_Replenish t SET ");
sql = "UPDATE T_Replenish t SET " sql.append("QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ "QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID),");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," sql.append("QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ "QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID),");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," sql.append("QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ "QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)";
if (p_C_DocType_ID != 0) if (p_C_DocType_ID != 0)
sql += ", C_DocType_ID=" + p_C_DocType_ID; sql.append(", C_DocType_ID=").append(p_C_DocType_ID);
sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update #" + no); log.fine("Update #" + no);
// Delete inactive products and replenishments // Delete inactive products and replenishments
sql = "DELETE T_Replenish r " sql = new StringBuilder("DELETE T_Replenish r ");
+ "WHERE (EXISTS (SELECT * FROM M_Product p " sql.append("WHERE (EXISTS (SELECT * FROM M_Product p ");
+ "WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')" sql.append("WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')");
+ " OR EXISTS (SELECT * FROM M_Replenish rr " sql.append(" OR EXISTS (SELECT * FROM M_Replenish rr ");
+ " WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'" sql.append(" WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'");
+ " AND rr.M_Warehouse_ID=" + p_M_Warehouse_ID + " ))" sql.append(" AND rr.M_Warehouse_ID=").append(p_M_Warehouse_ID).append(" ))");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete Inactive=" + no); log.fine("Delete Inactive=" + no);
// Ensure Data consistency // Ensure Data consistency
sql = "UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
// Set Minimum / Maximum Maintain Level // Set Minimum / Maximum Maintain Level
// X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel // X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min " sql.append(" SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min ");
+ " THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered " sql.append(" THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered ");
+ " ELSE 0 END " sql.append(" ELSE 0 END ");
+ "WHERE ReplenishType='1'" sql.append("WHERE ReplenishType='1'");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update Type-1=" + no); log.fine("Update Type-1=" + no);
// //
// X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel // X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered " sql.append(" SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered ");
+ "WHERE ReplenishType='2'" sql.append("WHERE ReplenishType='2'" );
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update Type-2=" + no); log.fine("Update Type-2=" + no);
// Minimum Order Quantity // Minimum Order Quantity
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = Order_Min " sql.append(" SET QtyToOrder = Order_Min ");
+ "WHERE QtyToOrder < Order_Min" sql.append("WHERE QtyToOrder < Order_Min");
+ " AND QtyToOrder > 0" sql.append(" AND QtyToOrder > 0" );
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set MinOrderQty=" + no); log.fine("Set MinOrderQty=" + no);
// Even dividable by Pack // Even dividable by Pack
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack " sql.append(" SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack ");
+ "WHERE MOD(QtyToOrder, Order_Pack) <> 0" sql.append("WHERE MOD(QtyToOrder, Order_Pack) <> 0");
+ " AND QtyToOrder > 0" sql.append(" AND QtyToOrder > 0");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set OrderPackQty=" + no); log.fine("Set OrderPackQty=" + no);
// Source from other warehouse // Source from other warehouse
if (wh.getM_WarehouseSource_ID() != 0) if (wh.getM_WarehouseSource_ID() != 0)
{ {
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET M_WarehouseSource_ID=" + wh.getM_WarehouseSource_ID() sql.append(" SET M_WarehouseSource_ID=").append(wh.getM_WarehouseSource_ID());
+ " WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set Source Warehouse=" + no); log.fine("Set Source Warehouse=" + no);
} }
// Check Source Warehouse // Check Source Warehouse
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET M_WarehouseSource_ID = NULL " sql.append(" SET M_WarehouseSource_ID = NULL ");
+ "WHERE M_Warehouse_ID=M_WarehouseSource_ID" sql.append("WHERE M_Warehouse_ID=M_WarehouseSource_ID");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set same Source Warehouse=" + no); log.fine("Set same Source Warehouse=" + no);
@ -381,10 +383,10 @@ public class ReplenishReport extends SvrProcess
} }
} }
// Delete rows where nothing to order // Delete rows where nothing to order
sql = "DELETE T_Replenish " sql = new StringBuilder("DELETE T_Replenish ");
+ "WHERE QtyToOrder < 1" sql.append("WHERE QtyToOrder < 1");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete No QtyToOrder=" + no); log.fine("Delete No QtyToOrder=" + no);
} // fillTable } // fillTable
@ -395,7 +397,7 @@ public class ReplenishReport extends SvrProcess
private void createPO() private void createPO()
{ {
int noOrders = 0; int noOrders = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MOrder order = null; MOrder order = null;
MWarehouse wh = null; MWarehouse wh = null;
@ -424,7 +426,8 @@ public class ReplenishReport extends SvrProcess
return; return;
log.fine(order.toString()); log.fine(order.toString());
noOrders++; noOrders++;
info += " - " + order.getDocumentNo(); info.append(" - ");
info.append(order.getDocumentNo());
} }
MOrderLine line = new MOrderLine (order); MOrderLine line = new MOrderLine (order);
line.setM_Product_ID(replenish.getM_Product_ID()); line.setM_Product_ID(replenish.getM_Product_ID());
@ -432,7 +435,7 @@ public class ReplenishReport extends SvrProcess
line.setPrice(); line.setPrice();
line.saveEx(); line.saveEx();
} }
m_info = "#" + noOrders + info; m_info = "#" + noOrders + info.toString();
log.info(m_info); log.info(m_info);
} // createPO } // createPO
@ -442,7 +445,7 @@ public class ReplenishReport extends SvrProcess
private void createRequisition() private void createRequisition()
{ {
int noReqs = 0; int noReqs = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MRequisition requisition = null; MRequisition requisition = null;
MWarehouse wh = null; MWarehouse wh = null;
@ -467,7 +470,8 @@ public class ReplenishReport extends SvrProcess
return; return;
log.fine(requisition.toString()); log.fine(requisition.toString());
noReqs++; noReqs++;
info += " - " + requisition.getDocumentNo(); info.append(" - ");
info.append(requisition.getDocumentNo());
} }
// //
MRequisitionLine line = new MRequisitionLine(requisition); MRequisitionLine line = new MRequisitionLine(requisition);
@ -477,7 +481,7 @@ public class ReplenishReport extends SvrProcess
line.setPrice(); line.setPrice();
line.saveEx(); line.saveEx();
} }
m_info = "#" + noReqs + info; m_info = "#" + noReqs + info.toString();
log.info(m_info); log.info(m_info);
} // createRequisition } // createRequisition
@ -487,7 +491,7 @@ public class ReplenishReport extends SvrProcess
private void createMovements() private void createMovements()
{ {
int noMoves = 0; int noMoves = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MClient client = null; MClient client = null;
MMovement move = null; MMovement move = null;
@ -523,7 +527,7 @@ public class ReplenishReport extends SvrProcess
return; return;
log.fine(move.toString()); log.fine(move.toString());
noMoves++; noMoves++;
info += " - " + move.getDocumentNo(); info.append(" - ").append(move.getDocumentNo());
} }
// To // To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID(); int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
@ -579,7 +583,7 @@ public class ReplenishReport extends SvrProcess
private void createDO() throws Exception private void createDO() throws Exception
{ {
int noMoves = 0; int noMoves = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MClient client = null; MClient client = null;
MDDOrder order = null; MDDOrder order = null;
@ -646,7 +650,7 @@ public class ReplenishReport extends SvrProcess
return; return;
log.fine(order.toString()); log.fine(order.toString());
noMoves++; noMoves++;
info += " - " + order.getDocumentNo(); info.append(" - ").append(order.getDocumentNo());
} }
// To // To
@ -726,16 +730,16 @@ public class ReplenishReport extends SvrProcess
*/ */
private X_T_Replenish[] getReplenish (String where) private X_T_Replenish[] getReplenish (String where)
{ {
String sql = "SELECT * FROM T_Replenish " StringBuilder sql = new StringBuilder("SELECT * FROM T_Replenish ");
+ "WHERE AD_PInstance_ID=? AND C_BPartner_ID > 0 "; sql.append("WHERE AD_PInstance_ID=? AND C_BPartner_ID > 0 ");
if (where != null && where.length() > 0) if (where != null && where.length() > 0)
sql += " AND " + where; sql.append(" AND ").append(where);
sql += " ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"; sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID");
ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>(); ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setInt (1, getAD_PInstance_ID()); pstmt.setInt (1, getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery (); ResultSet rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
@ -746,7 +750,7 @@ public class ReplenishReport extends SvrProcess
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql.toString(), e);
} }
try try
{ {
@ -769,16 +773,16 @@ public class ReplenishReport extends SvrProcess
*/ */
private X_T_Replenish[] getReplenishDO (String where) private X_T_Replenish[] getReplenishDO (String where)
{ {
String sql = "SELECT * FROM T_Replenish " StringBuilder sql = new StringBuilder("SELECT * FROM T_Replenish ");
+ "WHERE AD_PInstance_ID=? "; sql.append("WHERE AD_PInstance_ID=? ");
if (where != null && where.length() > 0) if (where != null && where.length() > 0)
sql += " AND " + where; sql.append(" AND ").append(where);
sql += " ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"; sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID");
ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>(); ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setInt (1, getAD_PInstance_ID()); pstmt.setInt (1, getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery (); ResultSet rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
@ -789,7 +793,7 @@ public class ReplenishReport extends SvrProcess
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql.toString(), e);
} }
try try
{ {

View File

@ -1,4 +1,5 @@
/****************************************************************************** /******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution * * Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
@ -108,10 +109,11 @@ public class ReplenishReportProduction extends SvrProcess
*/ */
protected String doIt() throws Exception protected String doIt() throws Exception
{ {
log.info("M_Warehouse_ID=" + p_M_Warehouse_ID StringBuilder msglog = new StringBuilder("M_Warehouse_ID=").append(p_M_Warehouse_ID)
+ ", C_BPartner_ID=" + p_C_BPartner_ID .append(", C_BPartner_ID=").append(p_C_BPartner_ID)
+ " - ReplenishmentCreate=" + p_ReplenishmentCreate .append(" - ReplenishmentCreate=").append(p_ReplenishmentCreate)
+ ", C_DocType_ID=" + p_C_DocType_ID); .append(", C_DocType_ID=").append(p_C_DocType_ID);
log.info(msglog.toString());
if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0 && !p_ReplenishmentCreate.equals("PRD")) if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0 && !p_ReplenishmentCreate.equals("PRD"))
throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@"); throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
@ -148,56 +150,56 @@ public class ReplenishReportProduction extends SvrProcess
private void prepareTable() private void prepareTable()
{ {
// Level_Max must be >= Level_Max // Level_Max must be >= Level_Max
String sql = "UPDATE M_Replenish" StringBuilder sql = new StringBuilder("UPDATE M_Replenish")
+ " SET Level_Max = Level_Min " .append(" SET Level_Max = Level_Min ")
+ "WHERE Level_Max < Level_Min"; .append("WHERE Level_Max < Level_Min");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Max_Level=" + no); log.fine("Corrected Max_Level=" + no);
// Minimum Order should be 1 // Minimum Order should be 1
sql = "UPDATE M_Product_PO" sql = new StringBuilder("UPDATE M_Product_PO")
+ " SET Order_Min = 1 " .append(" SET Order_Min = 1 ")
+ "WHERE Order_Min IS NULL OR Order_Min < 1"; .append("WHERE Order_Min IS NULL OR Order_Min < 1");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Order Min=" + no); log.fine("Corrected Order Min=" + no);
// Pack should be 1 // Pack should be 1
sql = "UPDATE M_Product_PO" sql = new StringBuilder("UPDATE M_Product_PO")
+ " SET Order_Pack = 1 " .append(" SET Order_Pack = 1 ")
+ "WHERE Order_Pack IS NULL OR Order_Pack < 1"; .append("WHERE Order_Pack IS NULL OR Order_Pack < 1");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected Order Pack=" + no); log.fine("Corrected Order Pack=" + no);
// Set Current Vendor where only one vendor // Set Current Vendor where only one vendor
sql = "UPDATE M_Product_PO p" sql = new StringBuilder("UPDATE M_Product_PO p")
+ " SET IsCurrentVendor='Y' " .append(" SET IsCurrentVendor='Y' ")
+ "WHERE IsCurrentVendor<>'Y'" .append("WHERE IsCurrentVendor<>'Y'")
+ " AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp " .append(" AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp ")
+ "WHERE p.M_Product_ID=pp.M_Product_ID " .append("WHERE p.M_Product_ID=pp.M_Product_ID ")
+ "GROUP BY pp.M_Product_ID " .append("GROUP BY pp.M_Product_ID ")
+ "HAVING COUNT(*) = 1)"; .append("HAVING COUNT(*) = 1)");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected CurrentVendor(Y)=" + no); log.fine("Corrected CurrentVendor(Y)=" + no);
// More then one current vendor // More then one current vendor
sql = "UPDATE M_Product_PO p" sql = new StringBuilder("UPDATE M_Product_PO p")
+ " SET IsCurrentVendor='N' " .append(" SET IsCurrentVendor='N' ")
+ "WHERE IsCurrentVendor = 'Y'" .append("WHERE IsCurrentVendor = 'Y'")
+ " AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp " .append(" AND EXISTS (SELECT pp.M_Product_ID FROM M_Product_PO pp ")
+ "WHERE p.M_Product_ID=pp.M_Product_ID AND pp.IsCurrentVendor='Y' " .append("WHERE p.M_Product_ID=pp.M_Product_ID AND pp.IsCurrentVendor='Y' ")
+ "GROUP BY pp.M_Product_ID " .append("GROUP BY pp.M_Product_ID ")
+ "HAVING COUNT(*) > 1)"; .append("HAVING COUNT(*) > 1)");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Corrected CurrentVendor(N)=" + no); log.fine("Corrected CurrentVendor(N)=" + no);
// Just to be sure // Just to be sure
sql = "DELETE T_Replenish WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql = new StringBuilder("DELETE T_Replenish WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete Existing Temp=" + no); log.fine("Delete Existing Temp=" + no);
} // prepareTable } // prepareTable
@ -208,170 +210,170 @@ public class ReplenishReportProduction extends SvrProcess
*/ */
private void fillTable (MWarehouse wh) throws Exception private void fillTable (MWarehouse wh) throws Exception
{ {
String sql = "INSERT INTO T_Replenish " StringBuilder sql = new StringBuilder("INSERT INTO T_Replenish ");
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," sql.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID,");
+ " ReplenishType, Level_Min, Level_Max," sql.append(" ReplenishType, Level_Min, Level_Max,");
+ " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " sql.append(" C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) ");
+ "SELECT " + getAD_PInstance_ID() sql.append("SELECT ").append(getAD_PInstance_ID());
+ ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," sql.append(", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID,");
+ " r.ReplenishType, r.Level_Min, r.Level_Max," sql.append(" r.ReplenishType, r.Level_Min, r.Level_Max,");
+ " po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, "; sql.append(" po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, ");
if (p_ReplenishmentCreate == null) if (p_ReplenishmentCreate == null)
sql += "null"; sql.append("null");
else else
sql += "'" + p_ReplenishmentCreate + "'"; sql.append("'").append(p_ReplenishmentCreate).append("'");
sql += " FROM M_Replenish r" sql.append(" FROM M_Replenish r");
+ " INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) " sql.append(" INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) ");
+ " INNER JOIN M_Product p ON (p.M_Product_ID=po.M_Product_ID) " sql.append(" INNER JOIN M_Product p ON (p.M_Product_ID=po.M_Product_ID) ");
+ "WHERE po.IsCurrentVendor='Y'" // Only Current Vendor sql.append("WHERE po.IsCurrentVendor='Y'"); // Only Current Vendor
+ " AND r.ReplenishType<>'0'" sql.append(" AND r.ReplenishType<>'0'");
+ " AND po.IsActive='Y' AND r.IsActive='Y'" sql.append(" AND po.IsActive='Y' AND r.IsActive='Y'");
+ " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID; sql.append(" AND r.M_Warehouse_ID=").append(p_M_Warehouse_ID);
if (p_C_BPartner_ID != 0) if (p_C_BPartner_ID != 0)
sql += " AND po.C_BPartner_ID=" + p_C_BPartner_ID; sql.append(" AND po.C_BPartner_ID=").append(p_C_BPartner_ID);
if ( p_M_Product_Category_ID != 0 ) if ( p_M_Product_Category_ID != 0 )
sql += " AND p.M_Product_Category_ID=" + p_M_Product_Category_ID; sql.append(" AND p.M_Product_Category_ID=").append(p_M_Product_Category_ID);
if ( isKanban != null ) if ( isKanban != null )
sql += " AND p.IsKanban = '" + isKanban + "' "; sql.append(" AND p.IsKanban = '").append(isKanban).append("' ");
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdate(sql.toString(), get_TrxName());
log.finest(sql); log.finest(sql.toString());
log.fine("Insert (1) #" + no); log.fine("Insert (1) #" + no);
if (p_C_BPartner_ID == 0) if (p_C_BPartner_ID == 0)
{ {
sql = "INSERT INTO T_Replenish " sql = new StringBuilder("INSERT INTO T_Replenish ");
+ "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," sql.append("(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID,");
+ " ReplenishType, Level_Min, Level_Max," sql.append(" ReplenishType, Level_Min, Level_Max,");
+ " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " sql.append(" C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) ");
+ "SELECT " + getAD_PInstance_ID() sql.append("SELECT ").append(getAD_PInstance_ID());
+ ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," sql.append(", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID,");
+ " r.ReplenishType, r.Level_Min, r.Level_Max," sql.append(" r.ReplenishType, r.Level_Min, r.Level_Max,");
+ " 0, 1, 1, 0, "; sql.append(" 0, 1, 1, 0, ");
if (p_ReplenishmentCreate == null) if (p_ReplenishmentCreate == null)
sql += "null"; sql.append("null");
else else
sql += "'" + p_ReplenishmentCreate + "'"; sql.append("'").append(p_ReplenishmentCreate).append("'");
sql += " FROM M_Replenish r " sql.append(" FROM M_Replenish r ");
+ " INNER JOIN M_Product p ON (p.M_Product_ID=r.M_Product_ID) " sql.append(" INNER JOIN M_Product p ON (p.M_Product_ID=r.M_Product_ID) ");
+ "WHERE r.ReplenishType<>'0' AND r.IsActive='Y'" sql.append("WHERE r.ReplenishType<>'0' AND r.IsActive='Y'");
+ " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID sql.append(" AND r.M_Warehouse_ID=").append(p_M_Warehouse_ID);
+ " AND NOT EXISTS (SELECT * FROM T_Replenish t " sql.append(" AND NOT EXISTS (SELECT * FROM T_Replenish t ");
+ "WHERE r.M_Product_ID=t.M_Product_ID" sql.append("WHERE r.M_Product_ID=t.M_Product_ID");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID() + ")"; sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID()).append(")");
if ( p_M_Product_Category_ID != 0 ) if ( p_M_Product_Category_ID != 0 )
sql += " AND p.M_Product_Category_ID=" + p_M_Product_Category_ID; sql.append(" AND p.M_Product_Category_ID=").append(p_M_Product_Category_ID);
if ( isKanban != null ) if ( isKanban != null )
sql += " AND p.IsKanban = '" + isKanban + "' "; sql.append(" AND p.IsKanban = '").append(isKanban).append("' ");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Insert (BP) #" + no); log.fine("Insert (BP) #" + no);
} }
sql = "UPDATE T_Replenish t SET " sql = new StringBuilder("UPDATE T_Replenish t SET ");
+ "QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append("QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID),");
+ "QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append("QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID),");
+ "QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" sql.append("QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID");
+ " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)"; sql.append(" AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)");
if (p_C_DocType_ID != 0) if (p_C_DocType_ID != 0)
sql += ", C_DocType_ID=" + p_C_DocType_ID; sql.append(", C_DocType_ID=").append(p_C_DocType_ID);
sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update #" + no); log.fine("Update #" + no);
// add production lines // add production lines
sql = "UPDATE T_Replenish t SET " sql = new StringBuilder("UPDATE T_Replenish t SET ");
+ "QtyReserved = QtyReserved - COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID" sql.append("QtyReserved = QtyReserved - COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID");
+ " AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty < 0 AND p.Processed = 'N'),0)," sql.append(" AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty < 0 AND p.Processed = 'N'),0),");
+ "QtyOrdered = QtyOrdered + COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID" sql.append("QtyOrdered = QtyOrdered + COALESCE((SELECT COALESCE(SUM(MovementQty),0) FROM M_ProductionLine p, M_Locator l WHERE t.M_Product_ID=p.M_Product_ID");
+ " AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty > 0 AND p.Processed = 'N'),0)"; sql.append(" AND l.M_Locator_ID=p.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID AND MovementQty > 0 AND p.Processed = 'N'),0)");
if (p_C_DocType_ID != 0) if (p_C_DocType_ID != 0)
sql += ", C_DocType_ID=" + p_C_DocType_ID; sql.append(", C_DocType_ID=").append(p_C_DocType_ID);
sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update #" + no); log.fine("Update #" + no);
// Delete inactive products and replenishments // Delete inactive products and replenishments
sql = "DELETE T_Replenish r " sql = new StringBuilder("DELETE T_Replenish r ");
+ "WHERE (EXISTS (SELECT * FROM M_Product p " sql.append("WHERE (EXISTS (SELECT * FROM M_Product p ");
+ "WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')" sql.append("WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')");
+ " OR EXISTS (SELECT * FROM M_Replenish rr " sql.append(" OR EXISTS (SELECT * FROM M_Replenish rr ");
+ " WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'" sql.append(" WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'");
+ " AND rr.M_Warehouse_ID=" + p_M_Warehouse_ID + " ))" sql.append(" AND rr.M_Warehouse_ID=").append(p_M_Warehouse_ID).append(" ))");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete Inactive=" + no); log.fine("Delete Inactive=" + no);
// Ensure Data consistency // Ensure Data consistency
sql = "UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
sql = "UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL"; sql = new StringBuilder("UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL");
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
// Set Minimum / Maximum Maintain Level // Set Minimum / Maximum Maintain Level
// X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel // X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min " sql.append(" SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min ");
+ " THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered " sql.append(" THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered ");
+ " ELSE 0 END " sql.append(" ELSE 0 END ");
+ "WHERE ReplenishType='1'" sql.append("WHERE ReplenishType='1'");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update Type-1=" + no); log.fine("Update Type-1=" + no);
// //
// X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel // X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered " sql.append(" SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered ");
+ "WHERE ReplenishType='2'" sql.append("WHERE ReplenishType='2'" );
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Update Type-2=" + no); log.fine("Update Type-2=" + no);
// Minimum Order Quantity // Minimum Order Quantity
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = Order_Min " sql.append(" SET QtyToOrder = Order_Min ");
+ "WHERE QtyToOrder < Order_Min" sql.append("WHERE QtyToOrder < Order_Min");
+ " AND QtyToOrder > 0" sql.append(" AND QtyToOrder > 0" );
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set MinOrderQty=" + no); log.fine("Set MinOrderQty=" + no);
// Even dividable by Pack // Even dividable by Pack
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack " sql.append(" SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack ");
+ "WHERE MOD(QtyToOrder, Order_Pack) <> 0" sql.append("WHERE MOD(QtyToOrder, Order_Pack) <> 0");
+ " AND QtyToOrder > 0" sql.append(" AND QtyToOrder > 0");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set OrderPackQty=" + no); log.fine("Set OrderPackQty=" + no);
// Source from other warehouse // Source from other warehouse
if (wh.getM_WarehouseSource_ID() != 0) if (wh.getM_WarehouseSource_ID() != 0)
{ {
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET M_WarehouseSource_ID=" + wh.getM_WarehouseSource_ID() sql.append(" SET M_WarehouseSource_ID=").append(wh.getM_WarehouseSource_ID());
+ " WHERE AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" WHERE AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set Source Warehouse=" + no); log.fine("Set Source Warehouse=" + no);
} }
// Check Source Warehouse // Check Source Warehouse
sql = "UPDATE T_Replenish" sql = new StringBuilder("UPDATE T_Replenish");
+ " SET M_WarehouseSource_ID = NULL " sql.append(" SET M_WarehouseSource_ID = NULL " );
+ "WHERE M_Warehouse_ID=M_WarehouseSource_ID" sql.append("WHERE M_Warehouse_ID=M_WarehouseSource_ID");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Set same Source Warehouse=" + no); log.fine("Set same Source Warehouse=" + no);
@ -415,10 +417,10 @@ public class ReplenishReportProduction extends SvrProcess
} }
} }
// Delete rows where nothing to order // Delete rows where nothing to order
sql = "DELETE T_Replenish " sql = new StringBuilder("DELETE T_Replenish ");
+ "WHERE QtyToOrder < 1" sql.append("WHERE QtyToOrder < 1");
+ " AND AD_PInstance_ID=" + getAD_PInstance_ID(); sql.append(" AND AD_PInstance_ID=").append(getAD_PInstance_ID());
no = DB.executeUpdate(sql, get_TrxName()); no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0) if (no != 0)
log.fine("Delete No QtyToOrder=" + no); log.fine("Delete No QtyToOrder=" + no);
@ -430,7 +432,7 @@ public class ReplenishReportProduction extends SvrProcess
private void createPO() private void createPO()
{ {
int noOrders = 0; int noOrders = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MOrder order = null; MOrder order = null;
MWarehouse wh = null; MWarehouse wh = null;
@ -459,7 +461,8 @@ public class ReplenishReportProduction extends SvrProcess
return; return;
log.fine(order.toString()); log.fine(order.toString());
noOrders++; noOrders++;
info += " - " + order.getDocumentNo(); info.append(" - ");
info.append(order.getDocumentNo());
} }
MOrderLine line = new MOrderLine (order); MOrderLine line = new MOrderLine (order);
line.setM_Product_ID(replenish.getM_Product_ID()); line.setM_Product_ID(replenish.getM_Product_ID());
@ -467,7 +470,7 @@ public class ReplenishReportProduction extends SvrProcess
line.setPrice(); line.setPrice();
line.saveEx(); line.saveEx();
} }
m_info = "#" + noOrders + info; m_info = "#" + noOrders + info.toString();
log.info(m_info); log.info(m_info);
} // createPO } // createPO
@ -477,7 +480,7 @@ public class ReplenishReportProduction extends SvrProcess
private void createRequisition() private void createRequisition()
{ {
int noReqs = 0; int noReqs = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MRequisition requisition = null; MRequisition requisition = null;
MWarehouse wh = null; MWarehouse wh = null;
@ -502,7 +505,8 @@ public class ReplenishReportProduction extends SvrProcess
return; return;
log.fine(requisition.toString()); log.fine(requisition.toString());
noReqs++; noReqs++;
info += " - " + requisition.getDocumentNo(); info.append(" - ");
info.append(requisition.getDocumentNo());
} }
// //
MRequisitionLine line = new MRequisitionLine(requisition); MRequisitionLine line = new MRequisitionLine(requisition);
@ -512,7 +516,7 @@ public class ReplenishReportProduction extends SvrProcess
line.setPrice(); line.setPrice();
line.saveEx(); line.saveEx();
} }
m_info = "#" + noReqs + info; m_info = "#" + noReqs + info.toString();
log.info(m_info); log.info(m_info);
} // createRequisition } // createRequisition
@ -522,7 +526,7 @@ public class ReplenishReportProduction extends SvrProcess
private void createMovements() private void createMovements()
{ {
int noMoves = 0; int noMoves = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MClient client = null; MClient client = null;
MMovement move = null; MMovement move = null;
@ -558,7 +562,7 @@ public class ReplenishReportProduction extends SvrProcess
return; return;
log.fine(move.toString()); log.fine(move.toString());
noMoves++; noMoves++;
info += " - " + move.getDocumentNo(); info.append(" - ").append(move.getDocumentNo());
} }
// To // To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID(); int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
@ -603,7 +607,7 @@ public class ReplenishReportProduction extends SvrProcess
} }
else else
{ {
m_info = "#" + noMoves + info; m_info = "#" + noMoves + info.toString();
log.info(m_info); log.info(m_info);
} }
} // Create Inventory Movements } // Create Inventory Movements
@ -614,7 +618,7 @@ public class ReplenishReportProduction extends SvrProcess
private void createDO() throws Exception private void createDO() throws Exception
{ {
int noMoves = 0; int noMoves = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MClient client = null; MClient client = null;
MDDOrder order = null; MDDOrder order = null;
@ -681,7 +685,7 @@ public class ReplenishReportProduction extends SvrProcess
return; return;
log.fine(order.toString()); log.fine(order.toString());
noMoves++; noMoves++;
info += " - " + order.getDocumentNo(); info.append(" - ").append(order.getDocumentNo());
} }
// To // To
@ -750,7 +754,7 @@ public class ReplenishReportProduction extends SvrProcess
} }
else else
{ {
m_info = "#" + noMoves + info; m_info = "#" + noMoves + info.toString();
log.info(m_info); log.info(m_info);
} }
} // create Distribution Order } // create Distribution Order
@ -760,7 +764,7 @@ public class ReplenishReportProduction extends SvrProcess
private void createProduction() private void createProduction()
{ {
int noProds = 0; int noProds = 0;
String info = ""; StringBuilder info = new StringBuilder();
// //
MProduction production = null; MProduction production = null;
MWarehouse wh = null; MWarehouse wh = null;
@ -811,11 +815,12 @@ public class ReplenishReportProduction extends SvrProcess
production.saveEx(get_TrxName()); production.saveEx(get_TrxName());
log.fine(production.toString()); log.fine(production.toString());
noProds++; noProds++;
info += " - " + production.getDocumentNo(); info.append(" - ");
info.append(production.getDocumentNo());
} }
} }
m_info = "#" + noProds + info; m_info = "#" + noProds + info.toString();
log.info(m_info); log.info(m_info);
} // createRequisition } // createRequisition
@ -825,16 +830,16 @@ public class ReplenishReportProduction extends SvrProcess
*/ */
private X_T_Replenish[] getReplenish (String where) private X_T_Replenish[] getReplenish (String where)
{ {
String sql = "SELECT * FROM T_Replenish " StringBuilder sql = new StringBuilder("SELECT * FROM T_Replenish ");
+ "WHERE AD_PInstance_ID=? "; sql.append("WHERE AD_PInstance_ID=? ");
if (where != null && where.length() > 0) if (where != null && where.length() > 0)
sql += " AND " + where; sql.append(" AND ").append(where);
sql += " ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"; sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID");
ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>(); ArrayList<X_T_Replenish> list = new ArrayList<X_T_Replenish>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
pstmt.setInt (1, getAD_PInstance_ID()); pstmt.setInt (1, getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery (); ResultSet rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
@ -845,7 +850,7 @@ public class ReplenishReportProduction extends SvrProcess
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql.toString(), e);
} }
try try
{ {

View File

@ -76,15 +76,15 @@ public class UUIDGenerator extends SvrProcess {
tableName = tableName.trim(); tableName = tableName.trim();
if (!tableName.endsWith("%")) if (!tableName.endsWith("%"))
tableName = tableName + "%"; tableName = tableName + "%";
String sql = "SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName like ? AND IsView = 'N' AND IsActive='Y'"; StringBuilder sql = new StringBuilder("SELECT AD_Table_ID, TableName FROM AD_Table WHERE TableName like ? AND IsView = 'N' AND IsActive='Y'");
if (DB.isOracle()) { if (DB.isOracle()) {
sql = sql + " ESCAPE '\' "; sql.append(" ESCAPE '\' ");
} }
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int count = 0; int count = 0;
try { try {
stmt = DB.prepareStatement(sql, null); stmt = DB.prepareStatement(sql.toString(), null);
stmt.setString(1, tableName); stmt.setString(1, tableName);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while(rs.next()) { while(rs.next()) {
@ -133,7 +133,7 @@ public class UUIDGenerator extends SvrProcess {
public static void updateUUID(MColumn column, String trxName) { public static void updateUUID(MColumn column, String trxName) {
MTable table = (MTable) column.getAD_Table(); MTable table = (MTable) column.getAD_Table();
int AD_Column_ID = DB.getSQLValue(null, "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=? AND ColumnName=?", table.getAD_Table_ID(), table.getTableName()+"_ID"); int AD_Column_ID = DB.getSQLValue(null, "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=? AND ColumnName=?", table.getAD_Table_ID(), table.getTableName()+"_ID");
StringBuffer sql = new StringBuffer("SELECT "); StringBuilder sql = new StringBuilder("SELECT ");
String keyColumn = null; String keyColumn = null;
List<String> compositeKeys = null; List<String> compositeKeys = null;
if (AD_Column_ID > 0) { if (AD_Column_ID > 0) {
@ -151,19 +151,16 @@ public class UUIDGenerator extends SvrProcess {
} }
sql.append(" FROM ").append(table.getTableName()); sql.append(" FROM ").append(table.getTableName());
sql.append(" WHERE ").append(column.getColumnName()).append(" IS NULL "); sql.append(" WHERE ").append(column.getColumnName()).append(" IS NULL ");
StringBuffer updateSQL = new StringBuffer(); StringBuilder updateSQL = new StringBuilder("UPDATE ");
updateSQL.append("UPDATE ");
updateSQL.append(table.getTableName()); updateSQL.append(table.getTableName());
updateSQL.append(" SET "); updateSQL.append(" SET ");
updateSQL.append(column.getColumnName()); updateSQL.append(column.getColumnName());
updateSQL.append("=? WHERE "); updateSQL.append("=? WHERE ");
if (AD_Column_ID > 0) { if (AD_Column_ID > 0) {
updateSQL.append(keyColumn); updateSQL.append(keyColumn).append("=?");
updateSQL.append("=?");
} else { } else {
for(String s : compositeKeys) { for(String s : compositeKeys) {
updateSQL.append(s); updateSQL.append(s).append("=? AND ");
updateSQL.append("=? AND ");
} }
int length = updateSQL.length(); int length = updateSQL.length();
updateSQL.delete(length-5, length); // delete last AND updateSQL.delete(length-5, length); // delete last AND
@ -235,7 +232,7 @@ public class UUIDGenerator extends SvrProcess {
tableName = tableName.toLowerCase(); tableName = tableName.toLowerCase();
} }
int noColumns = 0; int noColumns = 0;
String sql = null; StringBuilder sql = null;
// //
ResultSet rs = null; ResultSet rs = null;
try try
@ -244,13 +241,13 @@ public class UUIDGenerator extends SvrProcess {
while (rs.next()) while (rs.next())
{ {
noColumns++; noColumns++;
String columnName = rs.getString ("COLUMN_NAME"); StringBuilder columnName = new StringBuilder(rs.getString ("COLUMN_NAME"));
if (!columnName.equalsIgnoreCase(column.getColumnName())) if (!columnName.toString().equalsIgnoreCase(column.getColumnName()))
continue; continue;
// update existing column // update existing column
boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE"); boolean notNull = DatabaseMetaData.columnNoNulls == rs.getInt("NULLABLE");
sql = column.getSQLModify(table, column.isMandatory() != notNull); sql = new StringBuilder(column.getSQLModify(table, column.isMandatory() != notNull));
break; break;
} }
} }
@ -261,20 +258,20 @@ public class UUIDGenerator extends SvrProcess {
// No Table // No Table
if (noColumns == 0) if (noColumns == 0)
sql = table.getSQLCreate (); sql = new StringBuilder(table.getSQLCreate ());
// No existing column // No existing column
else if (sql == null) else if (sql == null)
sql = column.getSQLAdd(table); sql = new StringBuilder(column.getSQLAdd(table));
int no = 0; int no = 0;
if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1)
{ {
no = DB.executeUpdate(sql, false, null); no = DB.executeUpdate(sql.toString(), false, null);
addLog (0, null, new BigDecimal(no), sql); addLog (0, null, new BigDecimal(no), sql.toString());
} }
else else
{ {
String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); String statements[] = sql.toString().split(DB.SQLSTATEMENT_SEPARATOR);
for (int i = 0; i < statements.length; i++) for (int i = 0; i < statements.length; i++)
{ {
int count = DB.executeUpdate(statements[i], false, null); int count = DB.executeUpdate(statements[i], false, null);
@ -285,25 +282,25 @@ public class UUIDGenerator extends SvrProcess {
if (no != -1) if (no != -1)
{ {
String indexName = column.getColumnName()+"_idx"; StringBuilder indexName = new StringBuilder(column.getColumnName()).append("_idx");
if (indexName.length() > 30) { if (indexName.length() > 30) {
int i = indexName.length() - 31; int i = indexName.length() - 31;
indexName = column.getColumnName().substring(0, column.getColumnName().length() - i); indexName = new StringBuilder(column.getColumnName().substring(0, column.getColumnName().length() - i));
indexName = indexName + "_uu_idx"; indexName.append("_uu_idx");
} }
String indexSql = "CREATE UNIQUE INDEX " + indexName + " ON " + tableName StringBuilder indexSql = new StringBuilder("CREATE UNIQUE INDEX ").append(indexName).append(" ON ").append(tableName)
+ "(" + column.getColumnName() +")"; .append("(").append(column.getColumnName()).append(")");
DB.executeUpdateEx(indexSql, null); DB.executeUpdateEx(indexSql.toString(), null);
} }
if (no == -1) if (no == -1)
{ {
String msg = "@Error@ "; StringBuilder msg = new StringBuilder("@Error@ ");
ValueNamePair pp = CLogger.retrieveError(); ValueNamePair pp = CLogger.retrieveError();
if (pp != null) if (pp != null)
msg = pp.getName() + " - "; msg = new StringBuilder(pp.getName()).append(" - ");
msg += sql; msg.append(sql);
throw new AdempiereUserError (msg); throw new AdempiereUserError (msg.toString());
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DBException(e); throw new DBException(e);

View File

@ -64,8 +64,10 @@ public abstract class AbstractDocumentSearch {
*/ */
public boolean openDocumentsByDocumentNo(String searchString) { public boolean openDocumentsByDocumentNo(String searchString) {
windowOpened = false; windowOpened = false;
StringBuilder msglog = new StringBuilder();
log.fine("Search started with String: " + searchString);
msglog.append("Search started with String: ").append(searchString);
log.fine(msglog.toString());
// Check if / how many transaction-codes are used // Check if / how many transaction-codes are used
if (! Util.isEmpty(searchString)) { if (! Util.isEmpty(searchString)) {
@ -73,7 +75,7 @@ public abstract class AbstractDocumentSearch {
List<String> codeList = new ArrayList<String>(); List<String> codeList = new ArrayList<String>();
boolean codeSearch = true; boolean codeSearch = true;
StringBuffer search = new StringBuffer(); StringBuilder search = new StringBuilder();
// Analyze String to separate transactionCodes from searchString // Analyze String to separate transactionCodes from searchString
for (int i = 0; i < codes.length; i++) { for (int i = 0; i < codes.length; i++) {
@ -99,12 +101,15 @@ public abstract class AbstractDocumentSearch {
// Start the search for every single code // Start the search for every single code
if (codeList.size() > 0) { if (codeList.size() > 0) {
for (int i = 0; i < codeList.size(); i++) { for (int i = 0; i < codeList.size(); i++) {
log.fine("Search with Transaction: '" + codeList.get(i) + "' for: '" msglog = new StringBuilder("Search with Transaction: '");
+ search.toString() + "'"); msglog.append(codeList.get(i)).append("' for: '")
.append(search.toString()).append("'");
log.fine(msglog.toString());
getID(codeList.get(i), search.toString()); getID(codeList.get(i), search.toString());
} }
} else { } else {
log.fine("Search without Transaction: " + search.toString()); msglog = new StringBuilder("Search without Transaction: ").append(search.toString());
log.fine(msglog.toString());
getID(null, search.toString()); getID(null, search.toString());
} }
} else { } else {
@ -125,8 +130,10 @@ public abstract class AbstractDocumentSearch {
ResultSet rsPO = null; ResultSet rsPO = null;
PreparedStatement pstmtSO = null; PreparedStatement pstmtSO = null;
PreparedStatement pstmtPO = null; PreparedStatement pstmtPO = null;
String sqlSO = null; StringBuilder sqlSO = null;
String sqlPO = null; StringBuilder sqlPO = null;
StringBuilder msglog = null;
final Properties ctx = Env.getCtx(); final Properties ctx = Env.getCtx();
final MRole role = MRole.get(ctx, Env.getAD_Role_ID(ctx), Env.getAD_User_ID(ctx), true); final MRole role = MRole.get(ctx, Env.getAD_Role_ID(ctx), Env.getAD_User_ID(ctx), true);
@ -138,21 +145,22 @@ public abstract class AbstractDocumentSearch {
// SearchDefinition with a given table and column // SearchDefinition with a given table and column
if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_TABLE)) { if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_TABLE)) {
MColumn column = new MColumn(Env.getCtx(), msd.getAD_Column_ID(), null); MColumn column = new MColumn(Env.getCtx(), msd.getAD_Column_ID(), null);
sqlSO = "SELECT " + table.getTableName() + "_ID FROM " + table.getTableName() + " "; sqlSO = new StringBuilder("SELECT ").append(table.getTableName()).append("_ID FROM ").append(table.getTableName())
.append(" ");
// search for an Integer // search for an Integer
if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) {
sqlSO += "WHERE " + column.getColumnName() + "=?"; sqlSO.append("WHERE ").append(column.getColumnName()).append("=?");
// search for a String // search for a String
} else { } else {
sqlSO += "WHERE UPPER(" + column.getColumnName()+ ") LIKE UPPER(?)"; sqlSO.append("WHERE UPPER(").append(column.getColumnName()).append(") LIKE UPPER(?)");
} }
if (msd.getPO_Window_ID() != 0) { if (msd.getPO_Window_ID() != 0) {
sqlPO = sqlSO + " AND IsSOTrx='N'"; sqlPO = new StringBuilder(sqlSO.toString()).append(" AND IsSOTrx='N'");
sqlSO += " AND IsSOTrx='Y'"; sqlSO.append(" AND IsSOTrx='Y'");
} }
pstmtSO = DB.prepareStatement(sqlSO, null); pstmtSO = DB.prepareStatement(sqlSO.toString(), null);
pstmtPO = DB.prepareStatement(sqlPO, null); pstmtPO = DB.prepareStatement(sqlPO.toString(), null);
// search for a Integer // search for a Integer
if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) { if (msd.getDataType().equals(MSearchDefinition.DATATYPE_INTEGER)) {
pstmtSO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", ""))); pstmtSO.setInt(1, Integer.valueOf(searchString.replaceAll("\\D", "")));
@ -168,11 +176,11 @@ public abstract class AbstractDocumentSearch {
} }
// SearchDefinition with a special query // SearchDefinition with a special query
} else if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_QUERY)) { } else if (msd.getSearchType().equals(MSearchDefinition.SEARCHTYPE_QUERY)) {
sqlSO = msd.getQuery(); sqlSO = new StringBuilder(msd.getQuery());
pstmtSO = DB.prepareStatement(sqlSO, null); pstmtSO = DB.prepareStatement(sqlSO.toString(), null);
// count '?' in statement // count '?' in statement
int count = 1; int count = 1;
for (char c : sqlSO.toCharArray()) { for (char c : sqlSO.toString().toCharArray()) {
if (c == '?') { if (c == '?') {
count++; count++;
} }
@ -186,15 +194,17 @@ public abstract class AbstractDocumentSearch {
} }
} }
if (pstmtSO != null) { if (pstmtSO != null) {
log.fine("SQL Sales: " + sqlSO); msglog = new StringBuilder("SQL Sales: ").append(sqlSO.toString());
log.fine(msglog.toString());
rsSO = pstmtSO.executeQuery(); rsSO = pstmtSO.executeQuery();
Vector<Integer> idSO = new Vector<Integer>(); Vector<Integer> idSO = new Vector<Integer>();
while (rsSO.next()) { while (rsSO.next()) {
idSO.add(new Integer(rsSO.getInt(1))); idSO.add(new Integer(rsSO.getInt(1)));
} }
if (role.getWindowAccess(msd.getAD_Window_ID()) != null) { if (role.getWindowAccess(msd.getAD_Window_ID()) != null) {
log.fine("Open Window: " + msd.getAD_Window_ID() + " / Table: " msglog = new StringBuilder("Open Window: ").append(msd.getAD_Window_ID()).append(" / Table: ")
+ table.getTableName() + " / Number of Results: " + idSO.size()); .append(table.getTableName()).append(" / Number of Results: ").append(idSO.size());
log.fine(msglog.toString());
if (idSO.size() == 0 && (searchString == null || searchString.trim().length() == 0)) { if (idSO.size() == 0 && (searchString == null || searchString.trim().length() == 0)) {
// No search string - open the window with new record // No search string - open the window with new record
@ -207,15 +217,17 @@ public abstract class AbstractDocumentSearch {
} }
} }
if (pstmtPO != null) { if (pstmtPO != null) {
log.fine("SQL Purchase: " + sqlPO); msglog = new StringBuilder("SQL Purchase: ").append(sqlPO);
log.fine(msglog.toString());
rsPO = pstmtPO.executeQuery(); rsPO = pstmtPO.executeQuery();
Vector<Integer> idPO = new Vector<Integer>(); Vector<Integer> idPO = new Vector<Integer>();
while (rsPO.next()) { while (rsPO.next()) {
idPO.add(new Integer(rsPO.getInt(1))); idPO.add(new Integer(rsPO.getInt(1)));
} }
if (role.getWindowAccess(msd.getPO_Window_ID()) != null) { if (role.getWindowAccess(msd.getPO_Window_ID()) != null) {
log.fine("Open Window: " + msd.getPO_Window_ID() + " / Table: " msglog = new StringBuilder("Open Window: ").append(msd.getPO_Window_ID()).append(" / Table: ")
+ table.getTableName() + " / Number of Results: " + idPO.size()); .append(table.getTableName()).append(" / Number of Results: ").append(idPO.size());
log.fine(msglog.toString());
openWindow(idPO, table.getTableName(), msd.getPO_Window_ID()); openWindow(idPO, table.getTableName(), msd.getPO_Window_ID());
} else { } else {
log.warning("Role is not allowed to view this window"); log.warning("Role is not allowed to view this window");
@ -253,17 +265,13 @@ public abstract class AbstractDocumentSearch {
if (ids == null || ids.size() == 0) { if (ids == null || ids.size() == 0) {
return; return;
} }
StringBuffer whereString = new StringBuffer(); StringBuilder whereString = new StringBuilder(" ").append(tableName).append("_ID");
whereString.append(" ");
whereString.append(tableName);
whereString.append("_ID");
// create query string // create query string
if (ids.size() == 1) { if (ids.size() == 1) {
if (ids.get(0).intValue() == 0) { if (ids.get(0).intValue() == 0) {
whereString = null; whereString = null;
} else { } else {
whereString.append("="); whereString.append("=").append(ids.get(0).intValue());
whereString.append(ids.get(0).intValue());
} }
} else { } else {
whereString.append(" IN ("); whereString.append(" IN (");
@ -276,12 +284,14 @@ public abstract class AbstractDocumentSearch {
} }
} }
} }
log.fine(whereString.toString());
final MQuery query = new MQuery(tableName); final MQuery query = new MQuery(tableName);
query.addRestriction(whereString.toString()); query.addRestriction(whereString.toString());
final boolean ok = openWindow(windowId, query); final boolean ok = openWindow(windowId, query);
if (!ok) { if (!ok) {
log.severe("Unable to open window: " + whereString.toString()); StringBuilder msglog = new StringBuilder("Unable to open window: ").append(whereString.toString());
log.severe(msglog.toString());
} }
if (!windowOpened && ok) if (!windowOpened && ok)
windowOpened = true; windowOpened = true;

View File

@ -75,8 +75,8 @@ public class ModelClassGenerator
this.packageName = packageName; this.packageName = packageName;
// create column access methods // create column access methods
StringBuffer mandatory = new StringBuffer(); StringBuilder mandatory = new StringBuilder();
StringBuffer sb = createColumns(AD_Table_ID, mandatory); StringBuilder sb = createColumns(AD_Table_ID, mandatory);
// Header // Header
String className = createHeader(AD_Table_ID, sb, mandatory, packageName); String className = createHeader(AD_Table_ID, sb, mandatory, packageName);
@ -105,7 +105,7 @@ public class ModelClassGenerator
* @param packageName package name * @param packageName package name
* @return class name * @return class name
*/ */
private String createHeader (int AD_Table_ID, StringBuffer sb, StringBuffer mandatory, String packageName) private String createHeader (int AD_Table_ID, StringBuilder sb, StringBuilder mandatory, String packageName)
{ {
String tableName = ""; String tableName = "";
int accessLevel = 0; int accessLevel = 0;
@ -147,7 +147,7 @@ public class ModelClassGenerator
String keyColumn = tableName + "_ID"; String keyColumn = tableName + "_ID";
String className = "X_" + tableName; String className = "X_" + tableName;
// //
StringBuffer start = new StringBuffer () StringBuilder start = new StringBuilder()
.append (ModelInterfaceGenerator.COPY) .append (ModelInterfaceGenerator.COPY)
.append ("/** Generated Model - DO NOT CHANGE */").append(NL) .append ("/** Generated Model - DO NOT CHANGE */").append(NL)
.append("package " + packageName + ";").append(NL) .append("package " + packageName + ";").append(NL)
@ -248,7 +248,7 @@ public class ModelClassGenerator
.append(" }").append(NL) .append(" }").append(NL)
; ;
StringBuffer end = new StringBuffer ("}"); StringBuilder end = new StringBuilder ("}");
// //
sb.insert(0, start); sb.insert(0, start);
sb.append(end); sb.append(end);
@ -262,9 +262,9 @@ public class ModelClassGenerator
* @param mandatory init call for mandatory columns * @param mandatory init call for mandatory columns
* @return set/get method * @return set/get method
*/ */
private StringBuffer createColumns (int AD_Table_ID, StringBuffer mandatory) private StringBuilder createColumns (int AD_Table_ID, StringBuilder mandatory)
{ {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3 String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3
+ " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7 + " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7
+ " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12 + " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12
@ -319,8 +319,10 @@ public class ModelClassGenerator
isKeyNamePairCreated = true; isKeyNamePairCreated = true;
} }
else { else {
throw new RuntimeException("More than one primary identifier found "
+ " (AD_Table_ID=" + AD_Table_ID + ", ColumnName=" + columnName + ")"); StringBuilder msgException = new StringBuilder("More than one primary identifier found ")
.append(" (AD_Table_ID=").append(AD_Table_ID).append(", ColumnName=").append(columnName).append(")");
throw new RuntimeException(msgException.toString());
} }
} }
} }
@ -357,7 +359,7 @@ public class ModelClassGenerator
* @param IsEncrypted stored encrypted * @param IsEncrypted stored encrypted
@return set/get method @return set/get method
*/ */
private String createColumnMethods (StringBuffer mandatory, private String createColumnMethods (StringBuilder mandatory,
String columnName, boolean isUpdateable, boolean isMandatory, String columnName, boolean isUpdateable, boolean isMandatory,
int displayType, int AD_Reference_ID, int fieldLength, int displayType, int AD_Reference_ID, int fieldLength,
String defaultValue, String ValueMin, String ValueMax, String VFormat, String defaultValue, String ValueMin, String ValueMax, String VFormat,
@ -384,7 +386,7 @@ public class ModelClassGenerator
setValue = "\t\tset_ValueNoCheckE"; setValue = "\t\tset_ValueNoCheckE";
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
// TODO - New functionality // TODO - New functionality
// 1) Must understand which class to reference // 1) Must understand which class to reference
@ -542,7 +544,7 @@ public class ModelClassGenerator
// ****** Set Comment ****** // ****** Set Comment ******
public void generateJavaSetComment(String columnName, String propertyName, String description, StringBuffer result) { public void generateJavaSetComment(String columnName, String propertyName, String description, StringBuilder result) {
result.append(NL) result.append(NL)
.append("\t/** Set ").append(propertyName).append(".").append(NL) .append("\t/** Set ").append(propertyName).append(".").append(NL)
@ -558,7 +560,7 @@ public class ModelClassGenerator
} }
// ****** Get Comment ****** // ****** Get Comment ******
public void generateJavaGetComment(String propertyName, String description, StringBuffer result) { public void generateJavaGetComment(String propertyName, String description, StringBuilder result) {
result.append(NL) result.append(NL)
.append("\t/** Get ").append(propertyName); .append("\t/** Get ").append(propertyName);
@ -584,18 +586,18 @@ public class ModelClassGenerator
public static final String NEXTACTION_None = "N"; public static final String NEXTACTION_None = "N";
public static final String NEXTACTION_FollowUp = "F"; public static final String NEXTACTION_FollowUp = "F";
*/ */
private String addListValidation (StringBuffer sb, int AD_Reference_ID, private String addListValidation (StringBuilder sb, int AD_Reference_ID,
String columnName) String columnName)
{ {
StringBuffer retValue = new StringBuffer(); StringBuilder retValue = new StringBuilder();
retValue.append("\n\t/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */") retValue.append("\n\t/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */")
.append("\n\tpublic static final int ").append(columnName.toUpperCase()) .append("\n\tpublic static final int ").append(columnName.toUpperCase())
.append("_AD_Reference_ID=").append(AD_Reference_ID).append(";"); .append("_AD_Reference_ID=").append(AD_Reference_ID).append(";");
// //
boolean found = false; boolean found = false;
StringBuffer values = new StringBuffer("Reference_ID=") StringBuilder values = new StringBuilder("Reference_ID=")
.append(AD_Reference_ID); .append(AD_Reference_ID);
StringBuffer statement = new StringBuffer(); StringBuilder statement = new StringBuilder();
// //
String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=? ORDER BY AD_Ref_List_ID"; String sql = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=? ORDER BY AD_Ref_List_ID";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -625,7 +627,7 @@ public class ModelClassGenerator
// Name (SmallTalkNotation) // Name (SmallTalkNotation)
String name = rs.getString(2); String name = rs.getString(2);
char[] nameArray = name.toCharArray(); char[] nameArray = name.toCharArray();
StringBuffer nameClean = new StringBuffer(); StringBuilder nameClean = new StringBuilder();
boolean initCap = true; boolean initCap = true;
for (int i = 0; i < nameArray.length; i++) for (int i = 0; i < nameArray.length; i++)
{ {
@ -678,10 +680,10 @@ public class ModelClassGenerator
DB.close(rs, pstmt); DB.close(rs, pstmt);
rs = null; pstmt = null; rs = null; pstmt = null;
} }
statement.append(")" statement.append(")")
+ "; " .append("; ")
+ "else " .append("else ")
+ "throw new IllegalArgumentException (\"").append(columnName) .append("throw new IllegalArgumentException (\"").append(columnName)
.append(" Invalid value - \" + ").append(columnName) .append(" Invalid value - \" + ").append(columnName)
.append(" + \" - ").append(values).append("\");"); .append(" + \" - ").append(values).append("\");");
// [1762461] - Remove hardcoded list items checking in generated models // [1762461] - Remove hardcoded list items checking in generated models
@ -697,13 +699,13 @@ public class ModelClassGenerator
* * @param displayType int * * @param displayType int
@return method code @return method code
*/ */
private StringBuffer createKeyNamePair (String columnName, int displayType) private StringBuilder createKeyNamePair (String columnName, int displayType)
{ {
String method = "get" + columnName + "()"; String method = "get" + columnName + "()";
if (displayType != DisplayType.String) if (displayType != DisplayType.String)
method = "String.valueOf(" + method + ")"; method = "String.valueOf(" + method + ")";
StringBuffer sb = new StringBuffer(NL) StringBuilder sb = new StringBuilder(NL)
.append(" /** Get Record ID/ColumnName").append(NL) .append(" /** Get Record ID/ColumnName").append(NL)
.append(" @return ID/ColumnName pair").append(NL) .append(" @return ID/ColumnName pair").append(NL)
.append(" */").append(NL) .append(" */").append(NL)
@ -722,7 +724,7 @@ public class ModelClassGenerator
* @param sb string buffer * @param sb string buffer
* @param fileName file name * @param fileName file name
*/ */
private void writeToFile (StringBuffer sb, String fileName) private void writeToFile (StringBuilder sb, String fileName)
{ {
try try
{ {
@ -797,7 +799,7 @@ public class ModelClassGenerator
* Generate java imports * Generate java imports
* @param sb * @param sb
*/ */
private void createImports(StringBuffer sb) { private void createImports(StringBuilder sb) {
for (String name : s_importClasses) { for (String name : s_importClasses) {
sb.append("import ").append(name).append(";").append(NL); sb.append("import ").append(name).append(";").append(NL);
} }
@ -810,7 +812,7 @@ public class ModelClassGenerator
*/ */
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer ("GenerateModel[").append("]"); StringBuilder sb = new StringBuilder("GenerateModel[").append("]");
return sb.toString(); return sb.toString();
} }
@ -839,7 +841,7 @@ public class ModelClassGenerator
if (!tableLike.startsWith("'") || !tableLike.endsWith("'")) if (!tableLike.startsWith("'") || !tableLike.endsWith("'"))
tableLike = "'" + tableLike + "'"; tableLike = "'" + tableLike + "'";
StringBuffer entityTypeFilter = new StringBuffer(); StringBuilder entityTypeFilter = new StringBuilder();
if (entityType != null && entityType.trim().length() > 0) if (entityType != null && entityType.trim().length() > 0)
{ {
entityTypeFilter.append("EntityType IN ("); entityTypeFilter.append("EntityType IN (");
@ -877,7 +879,7 @@ public class ModelClassGenerator
file.mkdirs(); file.mkdirs();
// complete sql // complete sql
StringBuffer sql = new StringBuffer(); StringBuilder sql = new StringBuilder();
sql.append("SELECT AD_Table_ID ") sql.append("SELECT AD_Table_ID ")
.append("FROM AD_Table ") .append("FROM AD_Table ")
.append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views .append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views

View File

@ -109,8 +109,8 @@ public class ModelInterfaceGenerator
public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) { public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) {
this.packageName = packageName; this.packageName = packageName;
// create column access methods // create column access methods
StringBuffer mandatory = new StringBuffer(); StringBuilder mandatory = new StringBuilder();
StringBuffer sb = createColumns(AD_Table_ID, mandatory); StringBuilder sb = createColumns(AD_Table_ID, mandatory);
// Header // Header
String tableName = createHeader(AD_Table_ID, sb, mandatory); String tableName = createHeader(AD_Table_ID, sb, mandatory);
@ -134,7 +134,7 @@ public class ModelInterfaceGenerator
* @param packageName package name * @param packageName package name
* @return class name * @return class name
*/ */
private String createHeader(int AD_Table_ID, StringBuffer sb, StringBuffer mandatory) { private String createHeader(int AD_Table_ID, StringBuilder sb, StringBuilder mandatory) {
String tableName = ""; String tableName = "";
int accessLevel = 0; int accessLevel = 0;
String sql = "SELECT TableName, AccessLevel FROM AD_Table WHERE AD_Table_ID=?"; String sql = "SELECT TableName, AccessLevel FROM AD_Table WHERE AD_Table_ID=?";
@ -162,18 +162,18 @@ public class ModelInterfaceGenerator
if (tableName == null) if (tableName == null)
throw new RuntimeException("TableName not found for ID=" + AD_Table_ID); throw new RuntimeException("TableName not found for ID=" + AD_Table_ID);
// //
String accessLevelInfo = accessLevel + " "; StringBuilder accessLevelInfo = new StringBuilder(accessLevel).append(" ");
if (accessLevel >= 4 ) if (accessLevel >= 4 )
accessLevelInfo += "- System "; accessLevelInfo.append("- System ");
if (accessLevel == 2 || accessLevel == 3 || accessLevel == 6 || accessLevel == 7) if (accessLevel == 2 || accessLevel == 3 || accessLevel == 6 || accessLevel == 7)
accessLevelInfo += "- Client "; accessLevelInfo.append("- Client ");
if (accessLevel == 1 || accessLevel == 3 || accessLevel == 5 || accessLevel == 7) if (accessLevel == 1 || accessLevel == 3 || accessLevel == 5 || accessLevel == 7)
accessLevelInfo += "- Org "; accessLevelInfo.append("- Org ");
// //
String className = "I_" + tableName; String className = "I_" + tableName;
// //
StringBuffer start = new StringBuffer() StringBuilder start = new StringBuilder()
.append (COPY) .append (COPY)
.append("package ").append(packageName).append(";").append(NL) .append("package ").append(packageName).append(";").append(NL)
; ;
@ -216,7 +216,7 @@ public class ModelInterfaceGenerator
//.append(" POInfo initPO (Properties ctx);") // INFO - Should this be here??? //.append(" POInfo initPO (Properties ctx);") // INFO - Should this be here???
; ;
StringBuffer end = new StringBuffer("}"); StringBuilder end = new StringBuilder("}");
// //
sb.insert(0, start); sb.insert(0, start);
sb.append(end); sb.append(end);
@ -231,8 +231,8 @@ public class ModelInterfaceGenerator
* @param mandatory init call for mandatory columns * @param mandatory init call for mandatory columns
* @return set/get method * @return set/get method
*/ */
private StringBuffer createColumns(int AD_Table_ID, StringBuffer mandatory) { private StringBuilder createColumns(int AD_Table_ID, StringBuilder mandatory) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3 String sql = "SELECT c.ColumnName, c.IsUpdateable, c.IsMandatory," // 1..3
+ " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7 + " c.AD_Reference_ID, c.AD_Reference_Value_ID, DefaultValue, SeqNo, " // 4..7
+ " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12 + " c.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12
@ -321,7 +321,7 @@ public class ModelInterfaceGenerator
* @param IsEncrypted stored encrypted * @param IsEncrypted stored encrypted
* @return set/get method * @return set/get method
*/ */
private String createColumnMethods(StringBuffer mandatory, private String createColumnMethods(StringBuilder mandatory,
String columnName, boolean isUpdateable, boolean isMandatory, String columnName, boolean isUpdateable, boolean isMandatory,
int displayType, int AD_Reference_ID, int fieldLength, int displayType, int AD_Reference_ID, int fieldLength,
String defaultValue, String ValueMin, String ValueMax, String defaultValue, String ValueMin, String ValueMax,
@ -333,7 +333,7 @@ public class ModelInterfaceGenerator
if (defaultValue == null) if (defaultValue == null)
defaultValue = ""; defaultValue = "";
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
if (isGenerateSetter(columnName)) if (isGenerateSetter(columnName))
{ {
@ -375,7 +375,7 @@ public class ModelInterfaceGenerator
} }
// ****** Set/Get Comment ****** // ****** Set/Get Comment ******
public void generateJavaComment(String startOfComment, String propertyName, String description, StringBuffer result) { public void generateJavaComment(String startOfComment, String propertyName, String description, StringBuilder result) {
result.append("\n") result.append("\n")
.append("\t/** ").append(startOfComment).append(" ") .append("\t/** ").append(startOfComment).append(" ")
.append(propertyName); .append(propertyName);
@ -392,7 +392,7 @@ public class ModelInterfaceGenerator
* @param sb string buffer * @param sb string buffer
* @param fileName file name * @param fileName file name
*/ */
private void writeToFile(StringBuffer sb, String fileName) { private void writeToFile(StringBuilder sb, String fileName) {
try { try {
File out = new File(fileName); File out = new File(fileName);
Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8"); Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8");
@ -462,7 +462,7 @@ public class ModelInterfaceGenerator
* Generate java imports * Generate java imports
* @param sb * @param sb
*/ */
private void createImports(StringBuffer sb) { private void createImports(StringBuilder sb) {
for (String name : s_importClasses) { for (String name : s_importClasses) {
sb.append("import ").append(name).append(";"); //.append(NL); sb.append("import ").append(name).append(";"); //.append(NL);
} }
@ -634,13 +634,13 @@ public class ModelInterfaceGenerator
public static String getReferenceClassName(int AD_Table_ID, String columnName, int displayType, int AD_Reference_ID) public static String getReferenceClassName(int AD_Table_ID, String columnName, int displayType, int AD_Reference_ID)
{ {
String referenceClassName = null; StringBuilder referenceClassName = null;
// //
if (displayType == DisplayType.TableDir if (displayType == DisplayType.TableDir
|| (displayType == DisplayType.Search && AD_Reference_ID == 0)) || (displayType == DisplayType.Search && AD_Reference_ID == 0))
{ {
String refTableName = MQuery.getZoomTableName(columnName); // teo_sarca: BF [ 1817768 ] Isolate hardcoded table direct columns String refTableName = MQuery.getZoomTableName(columnName); // teo_sarca: BF [ 1817768 ] Isolate hardcoded table direct columns
referenceClassName = "I_"+refTableName; referenceClassName = new StringBuilder("I_").append(refTableName);
MTable table = MTable.get(Env.getCtx(), refTableName); MTable table = MTable.get(Env.getCtx(), refTableName);
if (table != null) if (table != null)
@ -649,7 +649,7 @@ public class ModelInterfaceGenerator
String modelpackage = getModelPackage(entityType) ; String modelpackage = getModelPackage(entityType) ;
if (modelpackage != null) if (modelpackage != null)
{ {
referenceClassName = modelpackage+"."+referenceClassName; referenceClassName = new StringBuilder(".").append(referenceClassName);
} }
if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType)) if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType))
{ {
@ -691,11 +691,11 @@ public class ModelInterfaceGenerator
final int refDisplayType = rs.getInt(3); final int refDisplayType = rs.getInt(3);
if (refDisplayType == DisplayType.ID) if (refDisplayType == DisplayType.ID)
{ {
referenceClassName = "I_"+refTableName; referenceClassName = new StringBuilder("I_").append(refTableName);
String modelpackage = getModelPackage(entityType); String modelpackage = getModelPackage(entityType);
if (modelpackage != null) if (modelpackage != null)
{ {
referenceClassName = modelpackage+"."+referenceClassName; referenceClassName = new StringBuilder(modelpackage).append(".").append(referenceClassName);
} }
if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType)) if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType))
{ {
@ -716,19 +716,19 @@ public class ModelInterfaceGenerator
} }
else if (displayType == DisplayType.Location) else if (displayType == DisplayType.Location)
{ {
referenceClassName = "I_C_Location"; referenceClassName = new StringBuilder("I_C_Location");
} }
else if (displayType == DisplayType.Locator) else if (displayType == DisplayType.Locator)
{ {
referenceClassName = "I_M_Locator"; referenceClassName = new StringBuilder("I_M_Locator");
} }
else if (displayType == DisplayType.Account) else if (displayType == DisplayType.Account)
{ {
referenceClassName = "I_C_ValidCombination"; referenceClassName = new StringBuilder("I_C_ValidCombination");
} }
else if (displayType == DisplayType.PAttribute) else if (displayType == DisplayType.PAttribute)
{ {
referenceClassName = "I_M_AttributeSetInstance"; referenceClassName = new StringBuilder("I_M_AttributeSetInstance");
} }
else else
{ {
@ -736,7 +736,7 @@ public class ModelInterfaceGenerator
//sb.append("\tpublic I_"+columnName+" getI_").append(columnName).append("(){return null; };"); //sb.append("\tpublic I_"+columnName+" getI_").append(columnName).append("(){return null; };");
} }
// //
return referenceClassName; return referenceClassName.toString();
} }
@ -746,7 +746,7 @@ public class ModelInterfaceGenerator
* @return string representation * @return string representation
*/ */
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer("GenerateModel[").append("]"); StringBuilder sb = new StringBuilder("GenerateModel[").append("]");
return sb.toString(); return sb.toString();
} }
@ -775,16 +775,16 @@ public class ModelInterfaceGenerator
if (!tableLike.startsWith("'") || !tableLike.endsWith("'")) if (!tableLike.startsWith("'") || !tableLike.endsWith("'"))
tableLike = "'" + tableLike + "'"; tableLike = "'" + tableLike + "'";
StringBuffer entityTypeFilter = new StringBuffer(); StringBuilder entityTypeFilter = new StringBuilder();
if (entityType != null && entityType.trim().length() > 0) if (entityType != null && entityType.trim().length() > 0)
{ {
entityTypeFilter.append("EntityType IN ("); entityTypeFilter.append("EntityType IN (");
StringTokenizer tokenizer = new StringTokenizer(entityType, ","); StringTokenizer tokenizer = new StringTokenizer(entityType, ",");
int i = 0; int i = 0;
while(tokenizer.hasMoreTokens()) { while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken().trim(); StringBuilder token = new StringBuilder(tokenizer.nextToken().trim());
if (!token.startsWith("'") || !token.endsWith("'")) if (!token.toString().startsWith("'") || !token.toString().endsWith("'"))
token = "'" + token + "'"; token = new StringBuilder("'").append(token).append("'");
if (i > 0) if (i > 0)
entityTypeFilter.append(","); entityTypeFilter.append(",");
entityTypeFilter.append(token); entityTypeFilter.append(token);
@ -797,23 +797,23 @@ public class ModelInterfaceGenerator
entityTypeFilter.append("EntityType IN ('U','A')"); entityTypeFilter.append("EntityType IN ('U','A')");
} }
String directory = sourceFolder.trim(); StringBuilder directory = new StringBuilder(sourceFolder.trim());
String packagePath = packageName.replace(".", File.separator); String packagePath = packageName.replace(".", File.separator);
if (!(directory.endsWith("/") || directory.endsWith("\\"))) if (!(directory.toString().endsWith("/") || directory.toString().endsWith("\\")))
{ {
directory = directory + File.separator; directory.append(File.separator);
} }
if (File.separator.equals("/")) if (File.separator.equals("/"))
directory = directory.replaceAll("[\\\\]", File.separator); directory = new StringBuilder(directory.toString().replaceAll("[\\\\]", File.separator));
else else
directory = directory.replaceAll("[/]", File.separator); directory = new StringBuilder(directory.toString().replaceAll("[/]", File.separator));
directory = directory + packagePath; directory = new StringBuilder(directory).append(packagePath);
file = new File(directory); file = new File(directory.toString());
if (!file.exists()) if (!file.exists())
file.mkdirs(); file.mkdirs();
// complete sql // complete sql
StringBuffer sql = new StringBuffer(); StringBuilder sql = new StringBuilder();
sql.append("SELECT AD_Table_ID ") sql.append("SELECT AD_Table_ID ")
.append("FROM AD_Table ") .append("FROM AD_Table ")
.append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views .append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views
@ -833,7 +833,7 @@ public class ModelInterfaceGenerator
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName); new ModelInterfaceGenerator(rs.getInt(1), directory.toString(), packageName);
count++; count++;
} }
} }

View File

@ -56,8 +56,8 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
{ {
protected MBankStatementLoader m_controller; protected MBankStatementLoader m_controller;
protected String m_errorMessage = ""; protected StringBuffer m_errorMessage;
protected String m_errorDescription = ""; protected StringBuffer m_errorDescription;
protected BufferedReader m_reader = null; protected BufferedReader m_reader = null;
protected SAXParser m_parser; protected SAXParser m_parser;
@ -177,8 +177,8 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
boolean result = false; boolean result = false;
if (controller == null) if (controller == null)
{ {
m_errorMessage = "ErrorInitializingParser"; m_errorMessage = new StringBuffer("ErrorInitializingParser");
m_errorDescription = "ImportController is a null reference"; m_errorDescription = new StringBuffer("ImportController is a null reference");
return result; return result;
} }
this.m_controller = controller; this.m_controller = controller;
@ -190,13 +190,13 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
} }
catch(ParserConfigurationException e) catch(ParserConfigurationException e)
{ {
m_errorMessage = "ErrorInitializingParser"; m_errorMessage = new StringBuffer("ErrorInitializingParser");
m_errorDescription = "Unable to configure SAX parser: " + e.getMessage(); m_errorDescription = new StringBuffer("Unable to configure SAX parser: ").append(e.getMessage());
} }
catch(SAXException e) catch(SAXException e)
{ {
m_errorMessage = "ErrorInitializingParser"; m_errorMessage = new StringBuffer("ErrorInitializingParser");
m_errorDescription = "Unable to initialize SAX parser: " + e.getMessage(); m_errorDescription = new StringBuffer("Unable to initialize SAX parser: ").append(e.getMessage());
} }
return result; return result;
} // init } // init
@ -217,7 +217,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
{ {
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); BufferedReader reader = new BufferedReader(new InputStreamReader(is));
reader.mark(HEADER_SIZE + 100); reader.mark(HEADER_SIZE + 100);
StringBuffer header = new StringBuffer(""); StringBuilder header = new StringBuilder();
for (int i = 0; i < HEADER_SIZE; i++) for (int i = 0; i < HEADER_SIZE; i++)
{ {
header.append(reader.readLine()); header.append(reader.readLine());
@ -250,8 +250,8 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
} }
catch(IOException e) catch(IOException e)
{ {
m_errorMessage = "ErrorReadingData"; m_errorMessage = new StringBuffer("ErrorReadingData");
m_errorDescription = e.getMessage(); m_errorDescription = new StringBuffer(e.getMessage());
return result; return result;
} }
@ -311,13 +311,13 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
} }
catch(SAXException e) catch(SAXException e)
{ {
m_errorMessage = "ErrorParsingData"; m_errorMessage = new StringBuffer("ErrorParsingData");
m_errorDescription = e.getMessage(); m_errorDescription = new StringBuffer(e.getMessage());
} }
catch(IOException e) catch(IOException e)
{ {
m_errorMessage = "ErrorReadingData"; m_errorMessage = new StringBuffer("ErrorReadingData");
m_errorDescription = e.getMessage(); m_errorDescription = new StringBuffer(e.getMessage());
} }
return result; return result;
@ -536,7 +536,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
*/ */
if (!validOFX) if (!validOFX)
{ {
m_errorDescription = "Invalid OFX syntax: " + qName; m_errorDescription = new StringBuffer("Invalid OFX syntax: ").append(qName);
throw new SAXException("Invalid OFX syntax: " + qName); throw new SAXException("Invalid OFX syntax: " + qName);
} }
if (qName.equals(XML_STMTTRN_TAG)) if (qName.equals(XML_STMTTRN_TAG))
@ -721,7 +721,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
catch(Exception e) catch(Exception e)
{ {
m_errorDescription = "Invalid data: " + value + " <-> " + e.getMessage(); m_errorDescription = new StringBuffer("Invalid data: ").append(value).append(" <-> ").append(e.getMessage());
throw new SAXException("Invalid data: " + value); throw new SAXException("Invalid data: " + value);
} }
@ -731,9 +731,9 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
{ {
if (!m_controller.saveLine()) if (!m_controller.saveLine())
{ {
m_errorMessage = m_controller.getErrorMessage(); m_errorMessage = new StringBuffer(m_controller.getErrorMessage());
m_errorDescription = m_controller.getErrorDescription(); m_errorDescription = new StringBuffer(m_controller.getErrorDescription());
throw new SAXException(m_errorMessage); throw new SAXException(m_errorMessage.toString());
} }
} }
} }
@ -766,7 +766,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
*/ */
public String getLastErrorMessage() public String getLastErrorMessage()
{ {
return m_errorMessage; return m_errorMessage.toString();
} }
/** /**
@ -775,7 +775,7 @@ public abstract class OFXBankStatementHandler extends DefaultHandler
*/ */
public String getLastErrorDescription() public String getLastErrorDescription()
{ {
return m_errorDescription; return m_errorDescription.toString();
} }
/** /**

View File

@ -69,8 +69,8 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im
} }
catch(Exception e) catch(Exception e)
{ {
m_errorMessage = "ErrorReadingData"; m_errorMessage = new StringBuffer("ErrorReadingData");
m_errorDescription = ""; m_errorDescription = new StringBuffer();
} }
return result; return result;

View File

@ -162,9 +162,10 @@ public class MLanguage extends X_AD_Language
*/ */
public String toString() public String toString()
{ {
return "MLanguage[" + getAD_Language() + "-" + getName() StringBuilder str = new StringBuilder("MLanguage[").append(getAD_Language()).append("-").append(getName())
+ ",Language=" + getLanguageISO() + ",Country=" + getCountryCode() .append(",Language=").append(getLanguageISO()).append(",Country=").append(getCountryCode())
+ "]"; .append("]");
return str.toString();
} // toString } // toString
/** /**
@ -214,7 +215,7 @@ public class MLanguage extends X_AD_Language
// some short formats have only one M and d (e.g. ths US) // some short formats have only one M and d (e.g. ths US)
if (sFormat.indexOf("MM") == -1 && sFormat.indexOf("dd") == -1) if (sFormat.indexOf("MM") == -1 && sFormat.indexOf("dd") == -1)
{ {
StringBuffer nFormat = new StringBuffer(""); StringBuilder nFormat = new StringBuilder();
for (int i = 0; i < sFormat.length(); i++) for (int i = 0; i < sFormat.length(); i++)
{ {
if (sFormat.charAt(i) == 'M') if (sFormat.charAt(i) == 'M')
@ -235,7 +236,7 @@ public class MLanguage extends X_AD_Language
if (m_dateFormat.toPattern().indexOf("yyyy") == -1) if (m_dateFormat.toPattern().indexOf("yyyy") == -1)
{ {
sFormat = m_dateFormat.toPattern(); sFormat = m_dateFormat.toPattern();
StringBuffer nFormat = new StringBuffer(""); StringBuilder nFormat = new StringBuilder();
for (int i = 0; i < sFormat.length(); i++) for (int i = 0; i < sFormat.length(); i++)
{ {
if (sFormat.charAt(i) == 'y') if (sFormat.charAt(i) == 'y')
@ -365,8 +366,8 @@ public class MLanguage extends X_AD_Language
*/ */
private int deleteTable (String tableName) private int deleteTable (String tableName)
{ {
String sql = "DELETE FROM "+tableName+" WHERE AD_Language=?"; StringBuilder sql = new StringBuilder("DELETE FROM ").append(tableName).append(" WHERE AD_Language=?");
int no = DB.executeUpdateEx(sql, new Object[]{getAD_Language()}, get_TrxName()); int no = DB.executeUpdateEx(sql.toString(), new Object[]{getAD_Language()}, get_TrxName());
log.fine(tableName + " #" + no); log.fine(tableName + " #" + no);
return no; return no;
} // deleteTable } // deleteTable
@ -420,27 +421,28 @@ public class MLanguage extends X_AD_Language
// Insert Statement // Insert Statement
int AD_User_ID = Env.getAD_User_ID(getCtx()); int AD_User_ID = Env.getAD_User_ID(getCtx());
String keyColumn = baseTable + "_ID"; String keyColumn = baseTable + "_ID";
String insert = "INSERT INTO " + tableName StringBuilder insert = new StringBuilder("INSERT INTO ").append(tableName)
+ "(AD_Language,IsTranslated, AD_Client_ID,AD_Org_ID, " .append("(AD_Language,IsTranslated, AD_Client_ID,AD_Org_ID, ")
+ "Createdby,UpdatedBy, " .append("Createdby,UpdatedBy, ")
+ keyColumn + cols + ") " .append(keyColumn).append(cols).append(") ")
+ "SELECT '" + getAD_Language() + "','N', AD_Client_ID,AD_Org_ID, " .append("SELECT '").append(getAD_Language()).append("','N', AD_Client_ID,AD_Org_ID, ")
+ AD_User_ID + "," + AD_User_ID + ", " .append(AD_User_ID).append(",").append(AD_User_ID).append(", ")
+ keyColumn + cols .append(keyColumn).append(cols)
+ " FROM " + baseTable .append(" FROM ").append(baseTable)
+ " WHERE " + keyColumn + " NOT IN (SELECT " + keyColumn .append(" WHERE ").append(keyColumn).append(" NOT IN (SELECT ").append(keyColumn)
+ " FROM " + tableName .append(" FROM ").append(tableName)
+ " WHERE AD_Language='" + getAD_Language() + "')"; .append(" WHERE AD_Language='").append(getAD_Language()).append("')");
// + " WHERE (" + keyColumn + ",'" + getAD_Language()+ "') NOT IN (SELECT " // + " WHERE (" + keyColumn + ",'" + getAD_Language()+ "') NOT IN (SELECT "
// + keyColumn + ",AD_Language FROM " + tableName + ")"; // + keyColumn + ",AD_Language FROM " + tableName + ")";
int no = DB.executeUpdateEx(insert, null, get_TrxName()); int no = DB.executeUpdateEx(insert.toString(), null, get_TrxName());
// IDEMPIERE-99 Language Maintenance does not create UUIDs // IDEMPIERE-99 Language Maintenance does not create UUIDs
MTable table = MTable.get(getCtx(), tableName); MTable table = MTable.get(getCtx(), tableName);
MColumn column = table.getColumn(PO.getUUIDColumnName(tableName)); MColumn column = table.getColumn(PO.getUUIDColumnName(tableName));
if (column != null) if (column != null)
UUIDGenerator.updateUUID(column, get_TrxName()); UUIDGenerator.updateUUID(column, get_TrxName());
// //
log.fine(tableName + " #" + no); StringBuilder msglog = new StringBuilder(tableName).append(" #").append(no);
log.fine(msglog.toString());
return no; return no;
} // addTable } // addTable

View File

@ -197,11 +197,10 @@ public class MPasswordRule extends X_AD_PasswordRule {
passwordData.setUsername(username); passwordData.setUsername(username);
RuleResult result = validator.validate(passwordData); RuleResult result = validator.validate(passwordData);
if (!result.isValid()) { if (!result.isValid()) {
StringBuffer error = new StringBuffer(Msg.getMsg(getCtx(), "PasswordErrors")); StringBuilder error = new StringBuilder(Msg.getMsg(getCtx(), "PasswordErrors"));
error.append(": ["); error.append(": [");
for (String msg : validator.getMessages(result)) { for (String msg : validator.getMessages(result)) {
error.append(" "); error.append(" ").append(msg);
error.append(msg);
} }
error.append(" ]"); error.append(" ]");
throw new AdempiereException(error.toString()); throw new AdempiereException(error.toString());
@ -213,8 +212,9 @@ public class MPasswordRule extends X_AD_PasswordRule {
Properties props = null; Properties props = null;
InputStream in = null; InputStream in = null;
try { try {
String file = "vtpassword_messages_" + Env.getLoginLanguage(getCtx()).getLocale().getLanguage() + ".properties"; StringBuilder file = new StringBuilder("vtpassword_messages_").append(Env.getLoginLanguage(getCtx()).getLocale().getLanguage())
in = this.getClass().getResourceAsStream(file); .append(".properties");
in = this.getClass().getResourceAsStream(file.toString());
if (in != null) { if (in != null) {
props = new Properties(); props = new Properties();
props.load(in); props.load(in);

View File

@ -282,7 +282,9 @@ public class Language implements Serializable
String language = lang.substring(0,2); String language = lang.substring(0,2);
String country = lang.substring(3); String country = lang.substring(3);
Locale locale = new Locale(language, country); Locale locale = new Locale(language, country);
log.info ("Adding Language=" + language + ", Country=" + country + ", Locale=" + locale); StringBuilder msglog = new StringBuilder()
.append("Adding Language=").append(language).append(", Country=").append(country).append(", Locale=").append(locale);
log.info (msglog.toString());
Language ll = new Language (lang, lang, locale); Language ll = new Language (lang, lang, locale);
// Add to Languages // Add to Languages
ArrayList<Language> list = new ArrayList<Language>(Arrays.asList(s_languages)); ArrayList<Language> list = new ArrayList<Language>(Arrays.asList(s_languages));
@ -626,7 +628,7 @@ public class Language implements Serializable
if (m_dateFormat.toPattern().indexOf("yyyy") == -1) if (m_dateFormat.toPattern().indexOf("yyyy") == -1)
{ {
sFormat = m_dateFormat.toPattern(); sFormat = m_dateFormat.toPattern();
StringBuffer nFormat = new StringBuffer(""); StringBuilder nFormat = new StringBuilder();
for (int i = 0; i < sFormat.length(); i++) for (int i = 0; i < sFormat.length(); i++)
{ {
if (sFormat.charAt(i) == 'y') if (sFormat.charAt(i) == 'y')
@ -701,7 +703,7 @@ public class Language implements Serializable
*/ */
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer("Language=["); StringBuilder sb = new StringBuilder("Language=[");
sb.append(m_name).append(",Locale=").append(m_locale.toString()) sb.append(m_name).append(",Locale=").append(m_locale.toString())
.append(",AD_Language=").append(m_AD_Language) .append(",AD_Language=").append(m_AD_Language)
.append(",DatePattern=").append(getDBdatePattern()) .append(",DatePattern=").append(getDBdatePattern())

View File

@ -108,7 +108,7 @@ public class HtmlDashboard extends JPanel implements MouseListener,
private String createHTML(PAGE_TYPE requestPage){ private String createHTML(PAGE_TYPE requestPage){
String result = "<html><head>"; StringBuilder result = new StringBuilder("<html><head>");
// READ CSS // READ CSS
URL url = getClass().getClassLoader(). URL url = getClass().getClassLoader().
@ -118,27 +118,28 @@ public class HtmlDashboard extends JPanel implements MouseListener,
ins = new InputStreamReader(url.openStream()); ins = new InputStreamReader(url.openStream());
BufferedReader bufferedReader = new BufferedReader( ins ); BufferedReader bufferedReader = new BufferedReader( ins );
String cssLine; String cssLine;
result += "<style type=\"text/css\">"; result.append("<style type=\"text/css\">");
while ((cssLine = bufferedReader.readLine()) != null) while ((cssLine = bufferedReader.readLine()) != null)
result += cssLine + "\n"; result.append(cssLine).append("\n");
result += "</style>"; result.append("</style>");
} catch (IOException e1) { } catch (IOException e1) {
log.log(Level.SEVERE, e1.getLocalizedMessage(), e1); log.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
} }
//System.out.println(result); //System.out.println(result);
switch (requestPage) { switch (requestPage) {
case PAGE_LOGO: case PAGE_LOGO:
result += "</head><body class=\"header\">"
+ "<table width=\"100%\"><tr><td>" result.append("</head><body class=\"header\">")
+ "<img src=\"res:org/compiere/images/logo_ad.png\">" .append("<table width=\"100%\"><tr><td>")
+ "</td><td></td><td width=\"290\">" .append("<img src=\"res:org/compiere/images/logo_ad.png\">")
//+ "<img src=\"res:at/freecom/apps/images/logo_fc.png\">" .append("</td><td></td><td width=\"290\">")
+ "</td></tr></table>" .append("</td></tr></table>")
+ "</body></html>"; .append("</body></html>");
break; break;
case PAGE_HOME: //************************************************************** case PAGE_HOME: //**************************************************************
result += // "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///c:/standard.css\"/>"
"</head><body><div class=\"content\">\n"; result.append("</head><body><div class=\"content\">\n");// "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///c:/standard.css\"/>"
queryZoom = null; queryZoom = null;
queryZoom = new ArrayList<MQuery>(); queryZoom = new ArrayList<MQuery>();
String appendToHome = null; String appendToHome = null;
@ -164,21 +165,22 @@ public class HtmlDashboard extends JPanel implements MouseListener,
String descriptionTrl = dp.get_Translation(MDashboardContent.COLUMNNAME_Description); String descriptionTrl = dp.get_Translation(MDashboardContent.COLUMNNAME_Description);
if (appendToHome != null) { if (appendToHome != null) {
if (descriptionTrl != null) if (descriptionTrl != null)
result += "<H2>" + descriptionTrl + "</H2>\n"; result.append("<H2>").append(descriptionTrl).append("</H2>\n");
result += stripHtml(appendToHome, false) + "<br>\n"; result.append(stripHtml(appendToHome, false)).append("<br>\n");
} }
if (dc.getAD_Menu_ID() > 0) { if (dc.getAD_Menu_ID() > 0) {
result += "<a class=\"hrefNode\" href=\"http:///window/node#" result.append("<a class=\"hrefNode\" href=\"http:///window/node#");
+ String.valueOf( dc.getAD_Window_ID() // "AD_MENU_ID") fcsku 3.7.07 result.append(String.valueOf(dc.getAD_Window_ID()));// "AD_MENU_ID") fcsku 3.7.07
+ "\">" result.append("\">");
+ descriptionTrl result.append(descriptionTrl.toString());
+ "</a><br>\n"); result.append("</a><br>\n");
} }
result += "<br>\n"; result.append("<br>\n");
//result += "table id: " + rs.getInt("AD_TABLE_ID"); //result += "table id: " + rs.getInt("AD_TABLE_ID");
if (dc.getPA_Goal_ID() > 0) if (dc.getPA_Goal_ID() > 0)
result += goalsDetail(dc.getPA_Goal_ID()); result.append(goalsDetail(dc.getPA_Goal_ID()));
} }
} }
catch (Exception e) catch (Exception e)
@ -188,13 +190,13 @@ public class HtmlDashboard extends JPanel implements MouseListener,
finally finally
{ {
} }
result += "<br><br><br>\n" result.append("<br><br><br>\n")
+ "</div>\n</body>\n</html>\n"; .append("</div>\n</body>\n</html>\n");
break; break;
default: //************************************************************** default: //**************************************************************
log.warning("Unknown option - "+requestPage); log.warning("Unknown option - "+requestPage);
} }
return result; return result.toString();
} }
private void createDashboardPreference() private void createDashboardPreference()
@ -215,30 +217,33 @@ public class HtmlDashboard extends JPanel implements MouseListener,
preference.setLine(dc.getLine()); preference.setLine(dc.getLine());
preference.setPA_DashboardContent_ID(dc.getPA_DashboardContent_ID()); preference.setPA_DashboardContent_ID(dc.getPA_DashboardContent_ID());
if (!preference.save()) if (!preference.save()){
log.log(Level.SEVERE, "Failed to create dashboard preference " + preference.toString()); StringBuilder msglog = new StringBuilder("Failed to create dashboard preference ").append(preference.toString());
log.log(Level.SEVERE, msglog.toString());
}
} }
} }
ArrayList<MQuery> queryZoom = null; //new ArrayList<MQuery>(); ArrayList<MQuery> queryZoom = null; //new ArrayList<MQuery>();
private String goalsDetail(int AD_Table_ID) { //TODO link to goals private String goalsDetail(int AD_Table_ID) { //TODO link to goals
String output = ""; StringBuilder output = new StringBuilder();
if (m_goals==null) return output; if (m_goals==null) return output.toString();
for (int i = 0; i < m_goals.length; i++) { for (int i = 0; i < m_goals.length; i++) {
MMeasureCalc mc = MMeasureCalc.get(Env.getCtx(), m_goals[i].getMeasure().getPA_MeasureCalc_ID()); MMeasureCalc mc = MMeasureCalc.get(Env.getCtx(), m_goals[i].getMeasure().getPA_MeasureCalc_ID());
if (AD_Table_ID == m_goals[i].getPA_Goal_ID()){// mc.getAD_Table_ID()) { if (AD_Table_ID == m_goals[i].getPA_Goal_ID()){// mc.getAD_Table_ID()) {
output += "<table class=\"dataGrid\"><tr>\n<th colspan=\"3\" class=\"label\"><b>" + m_goals[i].getName() + "</b></th></tr>\n"; output.append("<table class=\"dataGrid\"><tr>\n<th colspan=\"3\" class=\"label\"><b>").append(m_goals[i].getName()).append("</b></th></tr>\n");
output += "<tr><td class=\"label\">Target</td><td colspan=\"2\" class=\"tdcontent\">" + m_goals[i].getMeasureTarget() + "</td></tr>\n"; output.append("<tr><td class=\"label\">Target</td><td colspan=\"2\" class=\"tdcontent\">").append(m_goals[i].getMeasureTarget()).append("</td></tr>\n");
output += "<tr><td class=\"label\">Actual</td><td colspan=\"2\" class=\"tdcontent\">" + m_goals[i].getMeasureActual() + "</td></tr>\n"; output.append("<tr><td class=\"label\">Actual</td><td colspan=\"2\" class=\"tdcontent\">").append(m_goals[i].getMeasureActual()).append("</td></tr>\n");
//if (mc.getTableName()!=null) output += "table: " + mc.getAD_Table_ID() + "<br>\n"; //if (mc.getTableName()!=null) output += "table: " + mc.getAD_Table_ID() + "<br>\n";
Graph barPanel = new Graph(m_goals[i]); Graph barPanel = new Graph(m_goals[i]);
GraphColumn[] bList = barPanel.getGraphColumnList(); GraphColumn[] bList = barPanel.getGraphColumnList();
MQuery query = null; MQuery query = null;
output += "<tr><td rowspan=\"" + bList.length + "\" class=\"label\" valign=\"top\">" + m_goals[i].getXAxisText() + "</td>\n"; output.append("<tr><td rowspan=\"").append(bList.length).append("\" class=\"label\" valign=\"top\">").append(m_goals[i].getXAxisText()).append("</td>\n");
for (int k=0; k<bList.length; k++) { for (int k=0; k<bList.length; k++) {
GraphColumn bgc = bList[k]; GraphColumn bgc = bList[k];
if (k>0) output += "<tr>"; if (k>0) output.append("<tr>");
if (bgc.getAchievement() != null) // Single Achievement if (bgc.getAchievement() != null) // Single Achievement
{ {
MAchievement a = bgc.getAchievement(); MAchievement a = bgc.getAchievement();
@ -270,33 +275,33 @@ public class HtmlDashboard extends JPanel implements MouseListener,
bgc.getMeasureDisplay(), bgc.getDate(), bgc.getID(), bgc.getMeasureDisplay(), bgc.getDate(), bgc.getID(),
MRole.getDefault()); // logged in role MRole.getDefault()); // logged in role
} }
output += "<td class=\"tdcontent\">"+ bgc.getLabel() + "</td><td class=\"tdcontent\">"; output.append("<td class=\"tdcontent\">").append(bgc.getLabel()).append("</td><td class=\"tdcontent\">");
if (query != null) { if (query != null) {
output += "<a class=\"hrefZoom\" href=\"http:///window/zoom#" output.append("<a class=\"hrefZoom\" href=\"http:///window/zoom#")
+ queryZoom.size() .append(queryZoom.size())
+ "\">" .append("\">")
+ bgc.getValue() .append(bgc.getValue())
+ "</a><br>\n"; .append("</a><br>\n");
queryZoom.add(query); queryZoom.add(query);
} }
else { else {
log.info("Nothing to zoom to - " + bgc); log.info("Nothing to zoom to - " + bgc);
output += bgc.getValue(); output.append(bgc.getValue());
} }
output += "</td></tr>"; output.append("</td></tr>");
} }
output += "</tr>" output.append("</tr>")
+ "<tr><td colspan=\"3\">" .append("<tr><td colspan=\"3\">")
+ m_goals[i].getDescription() .append(m_goals[i].getDescription())
+ "<br>" .append("<br>")
+ stripHtml(m_goals[i].getColorSchema().getDescription(), true) .append(stripHtml(m_goals[i].getColorSchema().getDescription(), true))
+ "</td></tr>" .append("</td></tr>")
+ "</table>\n"; .append("</table>\n");
bList = null; bList = null;
barPanel = null; barPanel = null;
} }
} }
return output; return output.toString();
} }
private String stripHtml(String htmlString, boolean all) { private String stripHtml(String htmlString, boolean all) {

View File

@ -670,16 +670,16 @@ public final class Find extends CDialog
{ {
GridField field = m_findFields[c]; GridField field = m_findFields[c];
String columnName = field.getColumnName(); String columnName = field.getColumnName();
String header = field.getHeader(); StringBuilder header = new StringBuilder(field.getHeader());
if (header == null || header.length() == 0) if (header == null || header.length() == 0)
{ {
header = Msg.translate(Env.getCtx(), columnName); header = new StringBuilder(Msg.translate(Env.getCtx(), columnName));
if (header == null || header.length() == 0) if (header == null || header.length() == 0)
continue; continue;
} }
if (field.isKey()) if (field.isKey())
header += (" (ID)"); header.append((" (ID)"));
ValueNamePair pp = new ValueNamePair(columnName, header); ValueNamePair pp = new ValueNamePair(columnName, header.toString());
// System.out.println(pp + " = " + field); // System.out.println(pp + " = " + field);
items.add(pp); items.add(pp);
} }
@ -1011,6 +1011,8 @@ public final class Find extends CDialog
private void cmd_ok_Simple() private void cmd_ok_Simple()
{ {
// Create Query String // Create Query String
StringBuilder msglog;
m_query = new MQuery(m_tableName); m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false)); m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
if (hasValue && !valueField.getText().equals("%") && valueField.getText().length() != 0) if (hasValue && !valueField.getText().equals("%") && valueField.getText().length() != 0)
@ -1054,32 +1056,33 @@ public final class Find extends CDialog
Object value = ved.getValue(); Object value = ved.getValue();
if (value != null && value.toString().length() > 0) if (value != null && value.toString().length() > 0)
{ {
String ColumnName = ((Component)ved).getName (); StringBuilder ColumnName = new StringBuilder(((Component)ved).getName ());
log.fine(ColumnName + "=" + value); msglog = new StringBuilder(ColumnName).append("=").append(value);
log.fine(msglog.toString());
// globalqss - Carlos Ruiz - 20060711 // globalqss - Carlos Ruiz - 20060711
// fix a bug with virtualColumn + isSelectionColumn not yielding results // fix a bug with virtualColumn + isSelectionColumn not yielding results
GridField field = getTargetMField(ColumnName); GridField field = getTargetMField(ColumnName.toString());
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
String ColumnSQL = field.getColumnSQL(false); StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false));
// //
// Be more permissive for String columns // Be more permissive for String columns
if (isSearchLike(field)) if (isSearchLike(field))
{ {
String valueStr = value.toString().toUpperCase(); StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase());
if (!valueStr.endsWith("%")) if (!valueStr.toString().endsWith("%"))
valueStr += "%"; valueStr.append("%");
// //
ColumnSQL = "UPPER("+ColumnSQL+")"; ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")");
value = valueStr; value = valueStr;
} }
// //
if (value.toString().indexOf('%') != -1) if (value.toString().indexOf('%') != -1)
m_query.addRestriction(ColumnSQL, MQuery.LIKE, value, ColumnName, ved.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName.toString(), ved.getDisplay());
else if (isProductCategoryField && value instanceof Integer) else if (isProductCategoryField && value instanceof Integer)
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue())); m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
else else
m_query.addRestriction(ColumnSQL, MQuery.EQUAL, value, ColumnName, ved.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.EQUAL, value, ColumnName.toString(), ved.getDisplay());
/* /*
if (value.toString().indexOf('%') != -1) if (value.toString().indexOf('%') != -1)
m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay()); m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay());
@ -1152,7 +1155,7 @@ public final class Find extends CDialog
// //
m_query = new MQuery(m_tableName); m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false)); m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
StringBuffer code = new StringBuffer(); StringBuilder code = new StringBuilder();
int openBrackets = 0; int openBrackets = 0;
for (int row = 0; row < advancedTable.getRowCount(); row++) for (int row = 0; row < advancedTable.getRowCount(); row++)
{ {
@ -1160,17 +1163,17 @@ public final class Find extends CDialog
Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME); Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME);
if (column == null) if (column == null)
continue; continue;
String ColumnName = column instanceof ValueNamePair ? StringBuilder ColumnName = new StringBuilder(column instanceof ValueNamePair ?
((ValueNamePair)column).getValue() : column.toString(); ((ValueNamePair)column).getValue() : column.toString());
String infoName = column.toString(); StringBuilder infoName = new StringBuilder(column.toString());
// //
GridField field = getTargetMField(ColumnName); GridField field = getTargetMField(ColumnName.toString());
if (field == null) if (field == null)
continue; continue;
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
String ColumnSQL = field.getColumnSQL(false); StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false));
String lBrackets = (String) advancedTable.getValueAt(row, INDEX_LEFTBRACKET); StringBuilder lBrackets = new StringBuilder((String) advancedTable.getValueAt(row, INDEX_LEFTBRACKET));
if ( lBrackets != null ) if ( lBrackets != null )
openBrackets += lBrackets.length(); openBrackets += lBrackets.length();
String rBrackets = (String) advancedTable.getValueAt(row, INDEX_RIGHTBRACKET); String rBrackets = (String) advancedTable.getValueAt(row, INDEX_RIGHTBRACKET);
@ -1193,12 +1196,12 @@ public final class Find extends CDialog
if ( MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) if ( MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)
|| MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op) ) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op) )
{ {
m_query.addRestriction(ColumnSQL, Operator, null, m_query.addRestriction(ColumnSQL.toString(), Operator, null,
infoName, null, and, openBrackets); infoName.toString(), null, and, openBrackets);
if (code.length() > 0) if (code.length() > 0)
code.append(SEGMENT_SEPARATOR); code.append(SEGMENT_SEPARATOR);
code.append(ColumnName) code.append(ColumnName.toString())
.append(FIELD_SEPARATOR) .append(FIELD_SEPARATOR)
.append(Operator) .append(Operator)
.append(FIELD_SEPARATOR) .append(FIELD_SEPARATOR)
@ -1238,8 +1241,8 @@ public final class Find extends CDialog
String infoDisplay_to = value2.toString(); String infoDisplay_to = value2.toString();
if (parsedValue2 == null) if (parsedValue2 == null)
continue; continue;
m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, m_query.addRangeRestriction(ColumnSQL.toString(), parsedValue, parsedValue2,
infoName, infoDisplay, infoDisplay_to, and, openBrackets); infoName.toString(), infoDisplay, infoDisplay_to, and, openBrackets);
} }
else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) { else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
if (!(parsedValue instanceof Integer)) { if (!(parsedValue instanceof Integer)) {
@ -1250,12 +1253,12 @@ public final class Find extends CDialog
.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets); .addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
} }
else else
m_query.addRestriction(ColumnSQL, Operator, parsedValue, m_query.addRestriction(ColumnSQL.toString(), Operator, parsedValue,
infoName, infoDisplay, and, openBrackets); infoName.toString(), infoDisplay, and, openBrackets);
if (code.length() > 0) if (code.length() > 0)
code.append(SEGMENT_SEPARATOR); code.append(SEGMENT_SEPARATOR);
code.append(ColumnName) code.append(ColumnName.toString())
.append(FIELD_SEPARATOR) .append(FIELD_SEPARATOR)
.append(Operator) .append(Operator)
.append(FIELD_SEPARATOR) .append(FIELD_SEPARATOR)
@ -1273,17 +1276,17 @@ public final class Find extends CDialog
} }
Object selected = fQueryName.getSelectedItem(); Object selected = fQueryName.getSelectedItem();
if (selected != null && saveQuery) { if (selected != null && saveQuery) {
String name = selected.toString(); StringBuilder name = new StringBuilder(selected.toString());
if (Util.isEmpty(name, true)) if (Util.isEmpty(name.toString(), true))
{ {
ADialog.warn(m_targetWindowNo, this, "FillMandatory", Msg.translate(Env.getCtx(), "Name")); ADialog.warn(m_targetWindowNo, this, "FillMandatory", Msg.translate(Env.getCtx(), "Name"));
return; return;
} }
MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name); MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name.toString());
if (uq == null && code.length() > 0) if (uq == null && code.length() > 0)
{ {
uq = new MUserQuery (Env.getCtx(), 0, null); uq = new MUserQuery (Env.getCtx(), 0, null);
uq.setName (name); uq.setName (name.toString());
uq.setAD_Tab_ID(m_AD_Tab_ID); //red1 UserQuery [ 1798539 ] taking in new field from Compiere uq.setAD_Tab_ID(m_AD_Tab_ID); //red1 UserQuery [ 1798539 ] taking in new field from Compiere
uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); //red1 - [ 1798539 ] missing in Compiere delayed source :-) uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); //red1 - [ 1798539 ] missing in Compiere delayed source :-)
} }
@ -1291,11 +1294,11 @@ public final class Find extends CDialog
{ {
if (uq.delete(true)) if (uq.delete(true))
{ {
ADialog.info (m_targetWindowNo, this, "Deleted", name); ADialog.info (m_targetWindowNo, this, "Deleted", name.toString());
refreshUserQueries(); refreshUserQueries();
} }
else else
ADialog.warn (m_targetWindowNo, this, "DeleteError", name); ADialog.warn (m_targetWindowNo, this, "DeleteError", name.toString());
return; return;
} }
@ -1304,11 +1307,11 @@ public final class Find extends CDialog
// //
if (uq.save()) if (uq.save())
{ {
ADialog.info (m_targetWindowNo, this, "Saved", name); ADialog.info (m_targetWindowNo, this, "Saved", name.toString());
refreshUserQueries(); refreshUserQueries();
} }
else else
ADialog.warn (m_targetWindowNo, this, "SaveError", name); ADialog.warn (m_targetWindowNo, this, "SaveError", name.toString());
} }
} // cmd_save } // cmd_save
@ -1347,7 +1350,7 @@ public final class Find extends CDialog
private String getSubCategoryWhereClause(int productCategoryId) { private String getSubCategoryWhereClause(int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree //if a node with this id is found later in the search we have a loop in the tree
int subTreeRootParentId = 0; int subTreeRootParentId = 0;
String retString = " M_Product_Category_ID IN ("; StringBuilder retString = new StringBuilder(" M_Product_Category_ID IN (");
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100); final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
Statement stmt = null; Statement stmt = null;
@ -1361,20 +1364,20 @@ public final class Find extends CDialog
} }
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
} }
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId); retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId));
retString += ") "; retString.append(") ");
} catch (SQLException e) { } catch (SQLException e) {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
retString = ""; retString = new StringBuilder();
} catch (AdempiereSystemError e) { } catch (AdempiereSystemError e) {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
retString = ""; retString = new StringBuilder();
} }
finally { finally {
DB.close(rs, stmt); DB.close(rs, stmt);
rs = null; stmt = null; rs = null; stmt = null;
} }
return retString; return retString.toString();
} }
/** /**
@ -1386,7 +1389,7 @@ public final class Find extends CDialog
* @throws AdempiereSystemError if a loop is detected * @throws AdempiereSystemError if a loop is detected
*/ */
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError { private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = ""; StringBuilder ret = new StringBuilder();
final Iterator<SimpleTreeNode> iter = categories.iterator(); final Iterator<SimpleTreeNode> iter = categories.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next(); SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -1394,11 +1397,11 @@ public final class Find extends CDialog
if (node.getNodeId() == loopIndicatorId) { if (node.getNodeId() == loopIndicatorId) {
throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId); throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId);
} }
ret = ret + getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId) + ","; ret.append(getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId)).append(",");
} }
} }
log.fine(ret); log.fine(ret.toString());
return ret + productCategoryId; return ret.toString() + productCategoryId;
} }
/** /**
@ -1469,7 +1472,8 @@ public final class Find extends CDialog
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e); StringBuilder msglog = new StringBuilder(in.toString()).append("(").append(in.getClass()).append(")").append(e);
log.log(Level.SEVERE, msglog.toString());
time = DisplayType.getDateFormat(dt).parse(in.toString()).getTime(); time = DisplayType.getDateFormat(dt).parse(in.toString()).getTime();
} }
return new Timestamp(time); return new Timestamp(time);
@ -1484,7 +1488,7 @@ public final class Find extends CDialog
String error = ex.getLocalizedMessage(); String error = ex.getLocalizedMessage();
if (error == null || error.length() == 0) if (error == null || error.length() == 0)
error = ex.toString(); error = ex.toString();
StringBuffer errMsg = new StringBuffer(); StringBuilder errMsg = new StringBuilder();
errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error); errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error);
// //
ADialog.error(0, this, "ValidationError", errMsg.toString()); ADialog.error(0, this, "ValidationError", errMsg.toString());
@ -1502,7 +1506,8 @@ public final class Find extends CDialog
*/ */
private Object parseString(GridField field, String in) private Object parseString(GridField field, String in)
{ {
log.log(Level.FINE, "Parse: " +field + ":" + in); StringBuilder msglog = new StringBuilder("Parse: ").append(field).append(":").append(in);
log.log(Level.FINE, msglog.toString());
if (in == null) if (in == null)
return null; return null;
int dt = field.getDisplayType(); int dt = field.getDisplayType();
@ -1531,7 +1536,8 @@ public final class Find extends CDialog
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e); msglog = new StringBuilder(in.toString()).append("(").append(in.getClass()).append(")").append(e);
log.log(Level.SEVERE,msglog.toString());
time = DisplayType.getDateFormat(dt).parse(in).getTime(); time = DisplayType.getDateFormat(dt).parse(in).getTime();
} }
return new Timestamp(time); return new Timestamp(time);
@ -1611,7 +1617,7 @@ public final class Find extends CDialog
private int getNoOfRecords (MQuery query, boolean alertZeroRecords) private int getNoOfRecords (MQuery query, boolean alertZeroRecords)
{ {
log.config("" + query); log.config("" + query);
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM "); StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM ");
sql.append(m_tableName); sql.append(m_tableName);
boolean hasWhere = false; boolean hasWhere = false;
if (m_whereExtended != null && m_whereExtended.length() > 0) if (m_whereExtended != null && m_whereExtended.length() > 0)
@ -1677,8 +1683,8 @@ public final class Find extends CDialog
*/ */
private void setStatusDB (int currentCount) private void setStatusDB (int currentCount)
{ {
String text = " " + currentCount + " / " + m_total + " "; StringBuilder text = new StringBuilder(" ").append(currentCount).append(" / ").append(m_total).append(" ");
statusBar.setStatusDB(text); statusBar.setStatusDB(text.toString());
} // setDtatusDB } // setDtatusDB

View File

@ -31,7 +31,6 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Label;
@ -51,18 +50,17 @@ import org.compiere.util.Env;
import org.compiere.util.Ini; import org.compiere.util.Ini;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.zkoss.util.media.Media; import org.zkoss.util.media.Media;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.UploadEvent; import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center; import org.zkoss.zul.Center;
import org.zkoss.zul.North;
import org.zkoss.zul.South;
import org.zkoss.zul.Div; import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox; import org.zkoss.zul.Hbox;
import org.zkoss.zul.North;
import org.zkoss.zul.Separator; import org.zkoss.zul.Separator;
import org.zkoss.zul.South;
/** /**
* Fixed length file import * Fixed length file import
@ -367,18 +365,18 @@ public class WFileImport extends ADForm implements EventListener
// not safe see p108 Network pgm // not safe see p108 Network pgm
String s = null; String s = null;
String concat = ""; StringBuilder concat = new StringBuilder();
while ((s = in.readLine()) != null) while ((s = in.readLine()) != null)
{ {
m_data.add(s); m_data.add(s);
concat += s; concat.append(s);
concat += "\n"; concat.append("\n");
if (m_data.size() < MAX_LOADED_LINES) if (m_data.size() < MAX_LOADED_LINES)
{ {
rawData.setValue(concat); rawData.setValue(concat.toString());
} }
} }
in.close(); in.close();
@ -399,12 +397,13 @@ public class WFileImport extends ADForm implements EventListener
if (m_data.size() > 0) if (m_data.size() > 0)
length = m_data.get(index).toString().length(); length = m_data.get(index).toString().length();
info.setValue(Msg.getMsg(Env.getCtx(), "Records") + "=" + m_data.size() StringBuilder msginfo = new StringBuilder(Msg.getMsg(Env.getCtx(), "Records")).append("=").append(m_data.size()).append(", ")
+ ", " + Msg.getMsg(Env.getCtx(), "Length") + "=" + length + " "); .append(Msg.getMsg(Env.getCtx(), "Length")).append("=").append(length).append(" ");
info.setValue(msginfo.toString());
//setCursor (Cursor.getDefaultCursor()); //setCursor (Cursor.getDefaultCursor());
StringBuilder msglog = new StringBuilder("Records=").append(m_data.size()).append(", Length=").append(length);
log.config("Records=" + m_data.size() + ", Length=" + length); log.config(msglog.toString());
} // cmd_loadFile } // cmd_loadFile
/** /**

View File

@ -205,43 +205,43 @@ public class WTranslationDialog extends TranslationController implements IFormCo
statusBar.setStatusLine(directory); statusBar.setStatusLine(directory);
Translation t = new Translation(Env.getCtx()); Translation t = new Translation(Env.getCtx());
String msg = t.validateLanguage(AD_Language.getValue()); StringBuilder msg = new StringBuilder(t.validateLanguage(AD_Language.getValue()));
if (msg.length() > 0) if (msg.length() > 0)
{ {
FDialog.error(m_WindowNo, form, "LanguageSetupError", msg); FDialog.error(m_WindowNo, form, "LanguageSetupError", msg.toString());
return; return;
} }
// All Tables // All Tables
if (AD_Table.getValue().equals("")) if (AD_Table.getValue().equals(""))
{ {
msg = ""; msg = new StringBuilder();
for (int i = 1; i < cbTable.getItemCount(); i++) for (int i = 1; i < cbTable.getItemCount(); i++)
{ {
AD_Table = (ValueNamePair)cbTable.getItemAtIndex(i).toValueNamePair(); AD_Table = (ValueNamePair)cbTable.getItemAtIndex(i).toValueNamePair();
// Carlos Ruiz - globalqss - improve output message from translation import process // Carlos Ruiz - globalqss - improve output message from translation import process
msg += AD_Table.getValue() + " " + (imp msg.append(AD_Table.getValue()).append(" ").append((imp
? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()) ? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())) + " "; : t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()))).append(" ");
} }
if(msg == null || msg.length() == 0) if(msg == null || msg.length() == 0)
msg = (imp ? "Import" : "Export") + " Successful. [" + directory + "]"; msg = new StringBuilder((imp ? "Import" : "Export")).append(" Successful. [").append(directory).append("]");
statusBar.setStatusLine(msg); statusBar.setStatusLine(msg.toString());
} }
else // single table else // single table
{ {
msg = null; msg = null;
msg = imp msg = new StringBuilder(imp
? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()) ? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
: t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()); : t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()));
if(msg == null || msg.length() == 0) if(msg == null || msg.length() == 0)
msg = (imp ? "Import" : "Export") + " Successful. [" + directory + "]"; msg = new StringBuilder(imp ? "Import" : "Export").append(" Successful. [").append(directory).append("]");
statusBar.setStatusLine(msg); statusBar.setStatusLine(msg.toString());
} }
} // actionPerformed } // actionPerformed

View File

@ -892,17 +892,17 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
GridField field = m_findFields[c]; GridField field = m_findFields[c];
String columnName = field.getColumnName(); String columnName = field.getColumnName();
String header = field.getHeader(); StringBuilder header = new StringBuilder(field.getHeader());
if (header == null || header.length() == 0) if (header == null || header.length() == 0)
{ {
header = Msg.translate(Env.getCtx(), columnName); header = new StringBuilder(Msg.translate(Env.getCtx(), columnName));
if (header == null || header.length() == 0) if (header == null || header.length() == 0)
continue; continue;
} }
if (field.isKey()) if (field.isKey())
header += (" (ID)"); header.append((" (ID)"));
ValueNamePair pp = new ValueNamePair(columnName, header); ValueNamePair pp = new ValueNamePair(columnName, header.toString());
items.add(pp); items.add(pp);
} }
ValueNamePair[] cols = new ValueNamePair[items.size()]; ValueNamePair[] cols = new ValueNamePair[items.size()];
@ -1248,7 +1248,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e); StringBuilder msglog = new StringBuilder(in.toString()).append("(").append(in.getClass()).append(")").append(e);
log.log(Level.SEVERE, msglog.toString());
time = DisplayType.getDateFormat(dt).parse(in).getTime(); time = DisplayType.getDateFormat(dt).parse(in).getTime();
} }
@ -1290,7 +1291,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
// //
m_query = new MQuery(m_tableName); m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false)); m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
StringBuffer code = new StringBuffer(); StringBuilder code = new StringBuilder();
int openBrackets = 0; int openBrackets = 0;
@ -1675,7 +1676,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (value != null && value.toString().length() > 0) if (value != null && value.toString().length() > 0)
{ {
String ColumnName = wed.getColumnName(); String ColumnName = wed.getColumnName();
log.fine(ColumnName + "=" + value); StringBuilder msglog = new StringBuilder(ColumnName).append("=").append(value);
log.fine(msglog.toString());
// globalqss - Carlos Ruiz - 20060711 // globalqss - Carlos Ruiz - 20060711
// fix a bug with virtualColumn + isSelectionColumn not yielding results // fix a bug with virtualColumn + isSelectionColumn not yielding results
@ -1686,25 +1688,25 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
String ColumnSQL = field.getColumnSQL(false); StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false));
// //
// Be more permissive for String columns // Be more permissive for String columns
if (isSearchLike(field)) if (isSearchLike(field))
{ {
String valueStr = value.toString().toUpperCase(); StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase());
if (!valueStr.endsWith("%")) if (!valueStr.toString().endsWith("%"))
valueStr += "%"; valueStr.append("%");
// //
ColumnSQL = "UPPER("+ColumnSQL+")"; ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")");
value = valueStr; value = valueStr.toString();
} }
// //
if (value.toString().indexOf('%') != -1) if (value.toString().indexOf('%') != -1)
m_query.addRestriction(ColumnSQL, MQuery.LIKE, value, ColumnName, wed.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.LIKE, value, ColumnName, wed.getDisplay());
else if (isProductCategoryField && value instanceof Integer) else if (isProductCategoryField && value instanceof Integer)
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue())); m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
else else
m_query.addRestriction(ColumnSQL, MQuery.EQUAL, value, ColumnName, wed.getDisplay()); m_query.addRestriction(ColumnSQL.toString(), MQuery.EQUAL, value, ColumnName, wed.getDisplay());
/* /*
if (value.toString().indexOf('%') != -1) if (value.toString().indexOf('%') != -1)
@ -1760,7 +1762,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (null!=selectedHistoryItem && selectedHistoryItem.toString().length() > 0 && getHistoryDays(selectedHistoryValue) > 0) if (null!=selectedHistoryItem && selectedHistoryItem.toString().length() > 0 && getHistoryDays(selectedHistoryValue) > 0)
{ {
StringBuffer where = new StringBuffer(); StringBuilder where = new StringBuilder();
where.append("Created >= "); where.append("Created >= ");
where.append("SysDate-").append(getHistoryDays(selectedHistoryValue)); where.append("SysDate-").append(getHistoryDays(selectedHistoryValue));
m_query.addRestriction(where.toString()); m_query.addRestriction(where.toString());
@ -1822,7 +1824,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
private int getNoOfRecords (MQuery query, boolean alertZeroRecords) private int getNoOfRecords (MQuery query, boolean alertZeroRecords)
{ {
log.config("" + query); log.config("" + query);
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM "); StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM ");
sql.append(m_tableName); sql.append(m_tableName);
boolean hasWhere = false; boolean hasWhere = false;
if (m_whereExtended != null && m_whereExtended.length() > 0) if (m_whereExtended != null && m_whereExtended.length() > 0)
@ -1902,7 +1904,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
private String getSubCategoryWhereClause(int productCategoryId) { private String getSubCategoryWhereClause(int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree //if a node with this id is found later in the search we have a loop in the tree
int subTreeRootParentId = 0; int subTreeRootParentId = 0;
String retString = " M_Product_Category_ID IN ("; StringBuilder retString = new StringBuilder(" M_Product_Category_ID IN (");
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100); final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
try { try {
@ -1914,18 +1916,18 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
} }
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId); retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId))
retString += ") "; .append(") ");
rs.close(); rs.close();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
retString = ""; retString = new StringBuilder();
} catch (AdempiereSystemError e) { } catch (AdempiereSystemError e) {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
retString = ""; retString = new StringBuilder();
} }
return retString; return retString.toString();
} // getSubCategoryWhereClause } // getSubCategoryWhereClause
@ -1938,7 +1940,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
* @throws AdempiereSystemError if a loop is detected * @throws AdempiereSystemError if a loop is detected
**/ **/
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError { private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = ""; StringBuilder ret = new StringBuilder();
final Iterator<SimpleTreeNode> iter = categories.iterator(); final Iterator<SimpleTreeNode> iter = categories.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next(); SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -1946,11 +1948,11 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (node.getNodeId() == loopIndicatorId) { if (node.getNodeId() == loopIndicatorId) {
throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId); throw new AdempiereSystemError("The product category tree contains a loop on categoryId: " + loopIndicatorId);
} }
ret = ret + getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId) + ","; ret.append(getSubCategoriesString(node.getNodeId(), categories, loopIndicatorId)).append(",");
} }
} }
log.fine(ret); log.fine(ret.toString());
return ret + productCategoryId; return ret.toString() + productCategoryId;
} // getSubCategoriesString } // getSubCategoriesString
@ -2021,7 +2023,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e); StringBuilder msglog = new StringBuilder(in.toString()).append("(").append(in.getClass()).append(")").append(e);
log.log(Level.SEVERE, msglog.toString());
time = DisplayType.getDateFormat(dt).parse(in.toString()).getTime(); time = DisplayType.getDateFormat(dt).parse(in.toString()).getTime();
} }
return new Timestamp(time); return new Timestamp(time);
@ -2036,7 +2039,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
String error = ex.getLocalizedMessage(); String error = ex.getLocalizedMessage();
if (error == null || error.length() == 0) if (error == null || error.length() == 0)
error = ex.toString(); error = ex.toString();
StringBuffer errMsg = new StringBuffer(); StringBuilder errMsg = new StringBuilder();
errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error); errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error);
// //
FDialog.error(0, this, "ValidationError", errMsg.toString()); FDialog.error(0, this, "ValidationError", errMsg.toString());

View File

@ -194,17 +194,17 @@ public class DB_Oracle implements AdempiereDatabase
*/ */
public String getConnectionURL (CConnection connection) public String getConnectionURL (CConnection connection)
{ {
StringBuffer sb = null; StringBuilder sb = null;
// Server Connections (bequeath) // Server Connections (bequeath)
if (connection.isBequeath()) if (connection.isBequeath())
{ {
sb = new StringBuffer ("jdbc:oracle:oci8:@"); sb = new StringBuilder("jdbc:oracle:oci8:@");
// bug: does not work if there is more than one db instance - use Net8 // bug: does not work if there is more than one db instance - use Net8
// sb.append(connection.getDbName()); // sb.append(connection.getDbName());
} }
else // thin driver else // thin driver
{ {
sb = new StringBuffer ("jdbc:oracle:thin:@"); sb = new StringBuilder("jdbc:oracle:thin:@");
// direct connection // direct connection
if (connection.isViaFirewall()) if (connection.isViaFirewall())
{ {
@ -305,11 +305,11 @@ public class DB_Oracle implements AdempiereDatabase
*/ */
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer("DB_Oracle["); StringBuilder sb = new StringBuilder("DB_Oracle[");
sb.append(m_connectionURL); sb.append(m_connectionURL);
try try
{ {
StringBuffer logBuffer = new StringBuffer(50); StringBuilder logBuffer = new StringBuilder(50);
logBuffer.append("# Connections: ").append(m_ds.getNumConnections()); logBuffer.append("# Connections: ").append(m_ds.getNumConnections());
logBuffer.append(" , # Busy Connections: ").append(m_ds.getNumBusyConnections()); logBuffer.append(" , # Busy Connections: ").append(m_ds.getNumBusyConnections());
logBuffer.append(" , # Idle Connections: ").append(m_ds.getNumIdleConnections()); logBuffer.append(" , # Idle Connections: ").append(m_ds.getNumIdleConnections());
@ -334,7 +334,7 @@ public class DB_Oracle implements AdempiereDatabase
return null; return null;
} }
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
try try
{ {
sb.append("# Connections: ").append(m_ds.getNumConnections()); sb.append("# Connections: ").append(m_ds.getNumConnections());
@ -431,7 +431,7 @@ public class DB_Oracle implements AdempiereDatabase
return "SysDate"; return "SysDate";
} }
StringBuffer dateString = new StringBuffer("TO_DATE('"); StringBuilder dateString = new StringBuilder("TO_DATE('");
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format // YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
String myDate = time.toString(); String myDate = time.toString();
if (dayOnly) if (dayOnly)
@ -462,7 +462,7 @@ public class DB_Oracle implements AdempiereDatabase
* */ * */
public String TO_CHAR (String columnName, int displayType, String AD_Language) public String TO_CHAR (String columnName, int displayType, String AD_Language)
{ {
StringBuffer retValue = new StringBuffer("TRIM(TO_CHAR("); StringBuilder retValue = new StringBuilder("TRIM(TO_CHAR(");
retValue.append(columnName); retValue.append(columnName);
// Numbers // Numbers
@ -699,9 +699,10 @@ public class DB_Oracle implements AdempiereDatabase
+ getConnectionURL(connection) + getConnectionURL(connection)
+ " - UserID=" + connection.getDbUid()); + " - UserID=" + connection.getDbUid());
*/ */
System.err.println("Cannot connect to database: " StringBuilder msgerr = new StringBuilder("Cannot connect to database: ")
+ getConnectionURL(connection) .append(getConnectionURL(connection))
+ " - UserID=" + connection.getDbUid()); .append(" - UserID=").append(connection.getDbUid());
System.err.println(msgerr.toString());
} }
} }
@ -987,22 +988,22 @@ public class DB_Oracle implements AdempiereDatabase
try try
{ {
String myString1 = "123456789 12345678"; String myString1 = "123456789 12345678";
String myString = ""; StringBuilder myString = new StringBuilder();
for (int i = 0; i < 99; i++) for (int i = 0; i < 99; i++)
myString += myString1 + (char)('a'+i) + "\n"; myString.append(myString1).append((char)('a'+i)).append("\n");
System.out.println(myString.length()); System.out.println(myString.length());
System.out.println(Util.size(myString)); System.out.println(Util.size(myString.toString()));
// //
myString = Util.trimSize(myString, 2000); myString = new StringBuilder(Util.trimSize(myString.toString(), 2000));
System.out.println(myString.length()); System.out.println(myString.length());
System.out.println(Util.size(myString)); System.out.println(Util.size(myString.toString()));
// //
Connection conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED); Connection conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED);
/** **/ /** **/
PreparedStatement pstmt = conn2.prepareStatement PreparedStatement pstmt = conn2.prepareStatement
("INSERT INTO X_Test(Text1, Text2) values(?,?)"); ("INSERT INTO X_Test(Text1, Text2) values(?,?)");
pstmt.setString(1, myString); // NVARCHAR2 column pstmt.setString(1, myString.toString()); // NVARCHAR2 column
pstmt.setString(2, myString); // VARCHAR2 column pstmt.setString(2, myString.toString()); // VARCHAR2 column
System.out.println(pstmt.executeUpdate()); System.out.println(pstmt.executeUpdate());
/** **/ /** **/
Statement stmt = conn2.createStatement(); Statement stmt = conn2.createStatement();
@ -1158,12 +1159,12 @@ public class DB_Oracle implements AdempiereDatabase
public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start , String trxName) public boolean createSequence(String name , int increment , int minvalue , int maxvalue ,int start , String trxName)
{ {
int no = DB.executeUpdate("DROP SEQUENCE "+name.toUpperCase(), trxName); int no = DB.executeUpdate("DROP SEQUENCE "+name.toUpperCase(), trxName);
no = DB.executeUpdateEx("CREATE SEQUENCE "+name.toUpperCase() StringBuilder msgDB = new StringBuilder("CREATE SEQUENCE ").append(name.toUpperCase())
+ " MINVALUE " + minvalue .append(" MINVALUE ").append(minvalue)
+ " MAXVALUE " + maxvalue .append(" MAXVALUE ").append(maxvalue)
+ " START WITH " + start .append(" START WITH ").append(start)
+ " INCREMENT BY " + increment +" CACHE 20", trxName) .append(" INCREMENT BY ").append(increment).append(" CACHE 20");
; no = DB.executeUpdateEx(msgDB.toString(), trxName);
if(no == -1 ) if(no == -1 )
return false; return false;
else else
@ -1223,7 +1224,7 @@ public class DB_Oracle implements AdempiereDatabase
String[] keyColumns = po.get_KeyColumns(); String[] keyColumns = po.get_KeyColumns();
if (keyColumns != null && keyColumns.length > 0 && !po.is_new()) { if (keyColumns != null && keyColumns.length > 0 && !po.is_new()) {
StringBuffer sqlBuffer = new StringBuffer(" SELECT "); StringBuilder sqlBuffer = new StringBuilder(" SELECT ");
sqlBuffer.append(keyColumns[0]) sqlBuffer.append(keyColumns[0])
.append(" FROM ") .append(" FROM ")
.append(po.get_TableName()) .append(po.get_TableName())