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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -75,8 +75,8 @@ public class ModelClassGenerator
this.packageName = packageName;
// create column access methods
StringBuffer mandatory = new StringBuffer();
StringBuffer sb = createColumns(AD_Table_ID, mandatory);
StringBuilder mandatory = new StringBuilder();
StringBuilder sb = createColumns(AD_Table_ID, mandatory);
// Header
String className = createHeader(AD_Table_ID, sb, mandatory, packageName);
@ -105,7 +105,7 @@ public class ModelClassGenerator
* @param packageName package 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 = "";
int accessLevel = 0;
@ -147,7 +147,7 @@ public class ModelClassGenerator
String keyColumn = tableName + "_ID";
String className = "X_" + tableName;
//
StringBuffer start = new StringBuffer ()
StringBuilder start = new StringBuilder()
.append (ModelInterfaceGenerator.COPY)
.append ("/** Generated Model - DO NOT CHANGE */").append(NL)
.append("package " + packageName + ";").append(NL)
@ -248,7 +248,7 @@ public class ModelClassGenerator
.append(" }").append(NL)
;
StringBuffer end = new StringBuffer ("}");
StringBuilder end = new StringBuilder ("}");
//
sb.insert(0, start);
sb.append(end);
@ -262,9 +262,9 @@ public class ModelClassGenerator
* @param mandatory init call for mandatory columns
* @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
+ " 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
@ -319,8 +319,10 @@ public class ModelClassGenerator
isKeyNamePairCreated = true;
}
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
@return set/get method
*/
private String createColumnMethods (StringBuffer mandatory,
private String createColumnMethods (StringBuilder mandatory,
String columnName, boolean isUpdateable, boolean isMandatory,
int displayType, int AD_Reference_ID, int fieldLength,
String defaultValue, String ValueMin, String ValueMax, String VFormat,
@ -384,7 +386,7 @@ public class ModelClassGenerator
setValue = "\t\tset_ValueNoCheckE";
}
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
// TODO - New functionality
// 1) Must understand which class to reference
@ -542,7 +544,7 @@ public class ModelClassGenerator
// ****** 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)
.append("\t/** Set ").append(propertyName).append(".").append(NL)
@ -558,7 +560,7 @@ public class ModelClassGenerator
}
// ****** Get Comment ******
public void generateJavaGetComment(String propertyName, String description, StringBuffer result) {
public void generateJavaGetComment(String propertyName, String description, StringBuilder result) {
result.append(NL)
.append("\t/** Get ").append(propertyName);
@ -584,18 +586,18 @@ public class ModelClassGenerator
public static final String NEXTACTION_None = "N";
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)
{
StringBuffer retValue = new StringBuffer();
StringBuilder retValue = new StringBuilder();
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("_AD_Reference_ID=").append(AD_Reference_ID).append(";");
//
boolean found = false;
StringBuffer values = new StringBuffer("Reference_ID=")
StringBuilder values = new StringBuilder("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";
PreparedStatement pstmt = null;
@ -625,7 +627,7 @@ public class ModelClassGenerator
// Name (SmallTalkNotation)
String name = rs.getString(2);
char[] nameArray = name.toCharArray();
StringBuffer nameClean = new StringBuffer();
StringBuilder nameClean = new StringBuilder();
boolean initCap = true;
for (int i = 0; i < nameArray.length; i++)
{
@ -678,10 +680,10 @@ public class ModelClassGenerator
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
statement.append(")"
+ "; "
+ "else "
+ "throw new IllegalArgumentException (\"").append(columnName)
statement.append(")")
.append("; ")
.append("else ")
.append("throw new IllegalArgumentException (\"").append(columnName)
.append(" Invalid value - \" + ").append(columnName)
.append(" + \" - ").append(values).append("\");");
// [1762461] - Remove hardcoded list items checking in generated models
@ -697,13 +699,13 @@ public class ModelClassGenerator
* * @param displayType int
@return method code
*/
private StringBuffer createKeyNamePair (String columnName, int displayType)
private StringBuilder createKeyNamePair (String columnName, int displayType)
{
String method = "get" + columnName + "()";
if (displayType != DisplayType.String)
method = "String.valueOf(" + method + ")";
StringBuffer sb = new StringBuffer(NL)
StringBuilder sb = new StringBuilder(NL)
.append(" /** Get Record ID/ColumnName").append(NL)
.append(" @return ID/ColumnName pair").append(NL)
.append(" */").append(NL)
@ -722,7 +724,7 @@ public class ModelClassGenerator
* @param sb string buffer
* @param fileName file name
*/
private void writeToFile (StringBuffer sb, String fileName)
private void writeToFile (StringBuilder sb, String fileName)
{
try
{
@ -797,7 +799,7 @@ public class ModelClassGenerator
* Generate java imports
* @param sb
*/
private void createImports(StringBuffer sb) {
private void createImports(StringBuilder sb) {
for (String name : s_importClasses) {
sb.append("import ").append(name).append(";").append(NL);
}
@ -810,7 +812,7 @@ public class ModelClassGenerator
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("GenerateModel[").append("]");
StringBuilder sb = new StringBuilder("GenerateModel[").append("]");
return sb.toString();
}
@ -839,7 +841,7 @@ public class ModelClassGenerator
if (!tableLike.startsWith("'") || !tableLike.endsWith("'"))
tableLike = "'" + tableLike + "'";
StringBuffer entityTypeFilter = new StringBuffer();
StringBuilder entityTypeFilter = new StringBuilder();
if (entityType != null && entityType.trim().length() > 0)
{
entityTypeFilter.append("EntityType IN (");
@ -877,7 +879,7 @@ public class ModelClassGenerator
file.mkdirs();
// complete sql
StringBuffer sql = new StringBuffer();
StringBuilder sql = new StringBuilder();
sql.append("SELECT AD_Table_ID ")
.append("FROM AD_Table ")
.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) {
this.packageName = packageName;
// create column access methods
StringBuffer mandatory = new StringBuffer();
StringBuffer sb = createColumns(AD_Table_ID, mandatory);
StringBuilder mandatory = new StringBuilder();
StringBuilder sb = createColumns(AD_Table_ID, mandatory);
// Header
String tableName = createHeader(AD_Table_ID, sb, mandatory);
@ -134,7 +134,7 @@ public class ModelInterfaceGenerator
* @param packageName package 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 = "";
int accessLevel = 0;
String sql = "SELECT TableName, AccessLevel FROM AD_Table WHERE AD_Table_ID=?";
@ -162,18 +162,18 @@ public class ModelInterfaceGenerator
if (tableName == null)
throw new RuntimeException("TableName not found for ID=" + AD_Table_ID);
//
String accessLevelInfo = accessLevel + " ";
StringBuilder accessLevelInfo = new StringBuilder(accessLevel).append(" ");
if (accessLevel >= 4 )
accessLevelInfo += "- System ";
accessLevelInfo.append("- System ");
if (accessLevel == 2 || accessLevel == 3 || accessLevel == 6 || accessLevel == 7)
accessLevelInfo += "- Client ";
accessLevelInfo.append("- Client ");
if (accessLevel == 1 || accessLevel == 3 || accessLevel == 5 || accessLevel == 7)
accessLevelInfo += "- Org ";
accessLevelInfo.append("- Org ");
//
String className = "I_" + tableName;
//
StringBuffer start = new StringBuffer()
StringBuilder start = new StringBuilder()
.append (COPY)
.append("package ").append(packageName).append(";").append(NL)
;
@ -216,7 +216,7 @@ public class ModelInterfaceGenerator
//.append(" POInfo initPO (Properties ctx);") // INFO - Should this be here???
;
StringBuffer end = new StringBuffer("}");
StringBuilder end = new StringBuilder("}");
//
sb.insert(0, start);
sb.append(end);
@ -231,8 +231,8 @@ public class ModelInterfaceGenerator
* @param mandatory init call for mandatory columns
* @return set/get method
*/
private StringBuffer createColumns(int AD_Table_ID, StringBuffer mandatory) {
StringBuffer sb = new StringBuffer();
private StringBuilder createColumns(int AD_Table_ID, StringBuilder mandatory) {
StringBuilder sb = new StringBuilder();
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.FieldLength, c.ValueMin, c.ValueMax, c.VFormat, c.Callout, " // 8..12
@ -321,7 +321,7 @@ public class ModelInterfaceGenerator
* @param IsEncrypted stored encrypted
* @return set/get method
*/
private String createColumnMethods(StringBuffer mandatory,
private String createColumnMethods(StringBuilder mandatory,
String columnName, boolean isUpdateable, boolean isMandatory,
int displayType, int AD_Reference_ID, int fieldLength,
String defaultValue, String ValueMin, String ValueMax,
@ -333,7 +333,7 @@ public class ModelInterfaceGenerator
if (defaultValue == null)
defaultValue = "";
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
if (isGenerateSetter(columnName))
{
@ -375,7 +375,7 @@ public class ModelInterfaceGenerator
}
// ****** 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")
.append("\t/** ").append(startOfComment).append(" ")
.append(propertyName);
@ -392,7 +392,7 @@ public class ModelInterfaceGenerator
* @param sb string buffer
* @param fileName file name
*/
private void writeToFile(StringBuffer sb, String fileName) {
private void writeToFile(StringBuilder sb, String fileName) {
try {
File out = new File(fileName);
Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8");
@ -462,7 +462,7 @@ public class ModelInterfaceGenerator
* Generate java imports
* @param sb
*/
private void createImports(StringBuffer sb) {
private void createImports(StringBuilder sb) {
for (String name : s_importClasses) {
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)
{
String referenceClassName = null;
StringBuilder referenceClassName = null;
//
if (displayType == DisplayType.TableDir
|| (displayType == DisplayType.Search && AD_Reference_ID == 0))
{
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);
if (table != null)
@ -649,7 +649,7 @@ public class ModelInterfaceGenerator
String modelpackage = getModelPackage(entityType) ;
if (modelpackage != null)
{
referenceClassName = modelpackage+"."+referenceClassName;
referenceClassName = new StringBuilder(".").append(referenceClassName);
}
if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType))
{
@ -691,11 +691,11 @@ public class ModelInterfaceGenerator
final int refDisplayType = rs.getInt(3);
if (refDisplayType == DisplayType.ID)
{
referenceClassName = "I_"+refTableName;
referenceClassName = new StringBuilder("I_").append(refTableName);
String modelpackage = getModelPackage(entityType);
if (modelpackage != null)
{
referenceClassName = modelpackage+"."+referenceClassName;
referenceClassName = new StringBuilder(modelpackage).append(".").append(referenceClassName);
}
if (!isGenerateModelGetterForEntity(AD_Table_ID, entityType))
{
@ -716,19 +716,19 @@ public class ModelInterfaceGenerator
}
else if (displayType == DisplayType.Location)
{
referenceClassName = "I_C_Location";
referenceClassName = new StringBuilder("I_C_Location");
}
else if (displayType == DisplayType.Locator)
{
referenceClassName = "I_M_Locator";
referenceClassName = new StringBuilder("I_M_Locator");
}
else if (displayType == DisplayType.Account)
{
referenceClassName = "I_C_ValidCombination";
referenceClassName = new StringBuilder("I_C_ValidCombination");
}
else if (displayType == DisplayType.PAttribute)
{
referenceClassName = "I_M_AttributeSetInstance";
referenceClassName = new StringBuilder("I_M_AttributeSetInstance");
}
else
{
@ -736,7 +736,7 @@ public class ModelInterfaceGenerator
//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
*/
public String toString() {
StringBuffer sb = new StringBuffer("GenerateModel[").append("]");
StringBuilder sb = new StringBuilder("GenerateModel[").append("]");
return sb.toString();
}
@ -775,16 +775,16 @@ public class ModelInterfaceGenerator
if (!tableLike.startsWith("'") || !tableLike.endsWith("'"))
tableLike = "'" + tableLike + "'";
StringBuffer entityTypeFilter = new StringBuffer();
StringBuilder entityTypeFilter = new StringBuilder();
if (entityType != null && entityType.trim().length() > 0)
{
entityTypeFilter.append("EntityType IN (");
StringTokenizer tokenizer = new StringTokenizer(entityType, ",");
int i = 0;
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken().trim();
if (!token.startsWith("'") || !token.endsWith("'"))
token = "'" + token + "'";
StringBuilder token = new StringBuilder(tokenizer.nextToken().trim());
if (!token.toString().startsWith("'") || !token.toString().endsWith("'"))
token = new StringBuilder("'").append(token).append("'");
if (i > 0)
entityTypeFilter.append(",");
entityTypeFilter.append(token);
@ -797,23 +797,23 @@ public class ModelInterfaceGenerator
entityTypeFilter.append("EntityType IN ('U','A')");
}
String directory = sourceFolder.trim();
StringBuilder directory = new StringBuilder(sourceFolder.trim());
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("/"))
directory = directory.replaceAll("[\\\\]", File.separator);
directory = new StringBuilder(directory.toString().replaceAll("[\\\\]", File.separator));
else
directory = directory.replaceAll("[/]", File.separator);
directory = directory + packagePath;
file = new File(directory);
directory = new StringBuilder(directory.toString().replaceAll("[/]", File.separator));
directory = new StringBuilder(directory).append(packagePath);
file = new File(directory.toString());
if (!file.exists())
file.mkdirs();
// complete sql
StringBuffer sql = new StringBuffer();
StringBuilder sql = new StringBuilder();
sql.append("SELECT AD_Table_ID ")
.append("FROM AD_Table ")
.append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views
@ -833,7 +833,7 @@ public class ModelInterfaceGenerator
rs = pstmt.executeQuery();
while (rs.next())
{
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
new ModelInterfaceGenerator(rs.getInt(1), directory.toString(), packageName);
count++;
}
}

View File

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

View File

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

View File

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

View File

@ -282,7 +282,9 @@ public class Language implements Serializable
String language = lang.substring(0,2);
String country = lang.substring(3);
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);
// Add to 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)
{
sFormat = m_dateFormat.toPattern();
StringBuffer nFormat = new StringBuffer("");
StringBuilder nFormat = new StringBuilder();
for (int i = 0; i < sFormat.length(); i++)
{
if (sFormat.charAt(i) == 'y')
@ -701,7 +703,7 @@ public class Language implements Serializable
*/
public String toString()
{
StringBuffer sb = new StringBuffer("Language=[");
StringBuilder sb = new StringBuilder("Language=[");
sb.append(m_name).append(",Locale=").append(m_locale.toString())
.append(",AD_Language=").append(m_AD_Language)
.append(",DatePattern=").append(getDBdatePattern())

View File

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

View File

@ -670,16 +670,16 @@ public final class Find extends CDialog
{
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
StringBuilder header = new StringBuilder(field.getHeader());
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)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
header.append((" (ID)"));
ValueNamePair pp = new ValueNamePair(columnName, header.toString());
// System.out.println(pp + " = " + field);
items.add(pp);
}
@ -1011,6 +1011,8 @@ public final class Find extends CDialog
private void cmd_ok_Simple()
{
// Create Query String
StringBuilder msglog;
m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
if (hasValue && !valueField.getText().equals("%") && valueField.getText().length() != 0)
@ -1054,32 +1056,33 @@ public final class Find extends CDialog
Object value = ved.getValue();
if (value != null && value.toString().length() > 0)
{
String ColumnName = ((Component)ved).getName ();
log.fine(ColumnName + "=" + value);
StringBuilder ColumnName = new StringBuilder(((Component)ved).getName ());
msglog = new StringBuilder(ColumnName).append("=").append(value);
log.fine(msglog.toString());
// globalqss - Carlos Ruiz - 20060711
// 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());
String ColumnSQL = field.getColumnSQL(false);
StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false));
//
// Be more permissive for String columns
if (isSearchLike(field))
{
String valueStr = value.toString().toUpperCase();
if (!valueStr.endsWith("%"))
valueStr += "%";
StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase());
if (!valueStr.toString().endsWith("%"))
valueStr.append("%");
//
ColumnSQL = "UPPER("+ColumnSQL+")";
ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")");
value = valueStr;
}
//
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)
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
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)
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.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
StringBuffer code = new StringBuffer();
StringBuilder code = new StringBuilder();
int openBrackets = 0;
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);
if (column == null)
continue;
String ColumnName = column instanceof ValueNamePair ?
((ValueNamePair)column).getValue() : column.toString();
String infoName = column.toString();
StringBuilder ColumnName = new StringBuilder(column instanceof ValueNamePair ?
((ValueNamePair)column).getValue() : column.toString());
StringBuilder infoName = new StringBuilder(column.toString());
//
GridField field = getTargetMField(ColumnName);
GridField field = getTargetMField(ColumnName.toString());
if (field == null)
continue;
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 )
openBrackets += lBrackets.length();
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)
|| MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op) )
{
m_query.addRestriction(ColumnSQL, Operator, null,
infoName, null, and, openBrackets);
m_query.addRestriction(ColumnSQL.toString(), Operator, null,
infoName.toString(), null, and, openBrackets);
if (code.length() > 0)
code.append(SEGMENT_SEPARATOR);
code.append(ColumnName)
code.append(ColumnName.toString())
.append(FIELD_SEPARATOR)
.append(Operator)
.append(FIELD_SEPARATOR)
@ -1238,8 +1241,8 @@ public final class Find extends CDialog
String infoDisplay_to = value2.toString();
if (parsedValue2 == null)
continue;
m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2,
infoName, infoDisplay, infoDisplay_to, and, openBrackets);
m_query.addRangeRestriction(ColumnSQL.toString(), parsedValue, parsedValue2,
infoName.toString(), infoDisplay, infoDisplay_to, and, openBrackets);
}
else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
if (!(parsedValue instanceof Integer)) {
@ -1250,12 +1253,12 @@ public final class Find extends CDialog
.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
}
else
m_query.addRestriction(ColumnSQL, Operator, parsedValue,
infoName, infoDisplay, and, openBrackets);
m_query.addRestriction(ColumnSQL.toString(), Operator, parsedValue,
infoName.toString(), infoDisplay, and, openBrackets);
if (code.length() > 0)
code.append(SEGMENT_SEPARATOR);
code.append(ColumnName)
code.append(ColumnName.toString())
.append(FIELD_SEPARATOR)
.append(Operator)
.append(FIELD_SEPARATOR)
@ -1273,17 +1276,17 @@ public final class Find extends CDialog
}
Object selected = fQueryName.getSelectedItem();
if (selected != null && saveQuery) {
String name = selected.toString();
if (Util.isEmpty(name, true))
StringBuilder name = new StringBuilder(selected.toString());
if (Util.isEmpty(name.toString(), true))
{
ADialog.warn(m_targetWindowNo, this, "FillMandatory", Msg.translate(Env.getCtx(), "Name"));
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)
{
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_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))
{
ADialog.info (m_targetWindowNo, this, "Deleted", name);
ADialog.info (m_targetWindowNo, this, "Deleted", name.toString());
refreshUserQueries();
}
else
ADialog.warn (m_targetWindowNo, this, "DeleteError", name);
ADialog.warn (m_targetWindowNo, this, "DeleteError", name.toString());
return;
}
@ -1304,11 +1307,11 @@ public final class Find extends CDialog
//
if (uq.save())
{
ADialog.info (m_targetWindowNo, this, "Saved", name);
ADialog.info (m_targetWindowNo, this, "Saved", name.toString());
refreshUserQueries();
}
else
ADialog.warn (m_targetWindowNo, this, "SaveError", name);
ADialog.warn (m_targetWindowNo, this, "SaveError", name.toString());
}
} // cmd_save
@ -1347,7 +1350,7 @@ public final class Find extends CDialog
private String getSubCategoryWhereClause(int productCategoryId) {
//if a node with this id is found later in the search we have a loop in the tree
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";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
Statement stmt = null;
@ -1361,20 +1364,20 @@ public final class Find extends CDialog
}
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
}
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId);
retString += ") ";
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId));
retString.append(") ");
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
retString = "";
retString = new StringBuilder();
} catch (AdempiereSystemError e) {
log.log(Level.SEVERE, sql, e);
retString = "";
retString = new StringBuilder();
}
finally {
DB.close(rs, stmt);
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
*/
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = "";
StringBuilder ret = new StringBuilder();
final Iterator<SimpleTreeNode> iter = categories.iterator();
while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -1394,11 +1397,11 @@ public final class Find extends CDialog
if (node.getNodeId() == 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);
return ret + productCategoryId;
log.fine(ret.toString());
return ret.toString() + productCategoryId;
}
/**
@ -1469,7 +1472,8 @@ public final class Find extends CDialog
}
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();
}
return new Timestamp(time);
@ -1484,7 +1488,7 @@ public final class Find extends CDialog
String error = ex.getLocalizedMessage();
if (error == null || error.length() == 0)
error = ex.toString();
StringBuffer errMsg = new StringBuffer();
StringBuilder errMsg = new StringBuilder();
errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error);
//
ADialog.error(0, this, "ValidationError", errMsg.toString());
@ -1502,7 +1506,8 @@ public final class Find extends CDialog
*/
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)
return null;
int dt = field.getDisplayType();
@ -1531,7 +1536,8 @@ public final class Find extends CDialog
}
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();
}
return new Timestamp(time);
@ -1611,7 +1617,7 @@ public final class Find extends CDialog
private int getNoOfRecords (MQuery query, boolean alertZeroRecords)
{
log.config("" + query);
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ");
StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM ");
sql.append(m_tableName);
boolean hasWhere = false;
if (m_whereExtended != null && m_whereExtended.length() > 0)
@ -1677,8 +1683,8 @@ public final class Find extends CDialog
*/
private void setStatusDB (int currentCount)
{
String text = " " + currentCount + " / " + m_total + " ";
statusBar.setStatusDB(text);
StringBuilder text = new StringBuilder(" ").append(currentCount).append(" / ").append(m_total).append(" ");
statusBar.setStatusDB(text.toString());
} // setDtatusDB

View File

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

View File

@ -205,43 +205,43 @@ public class WTranslationDialog extends TranslationController implements IFormCo
statusBar.setStatusLine(directory);
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)
{
FDialog.error(m_WindowNo, form, "LanguageSetupError", msg);
FDialog.error(m_WindowNo, form, "LanguageSetupError", msg.toString());
return;
}
// All Tables
if (AD_Table.getValue().equals(""))
{
msg = "";
msg = new StringBuilder();
for (int i = 1; i < cbTable.getItemCount(); i++)
{
AD_Table = (ValueNamePair)cbTable.getItemAtIndex(i).toValueNamePair();
// 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.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)
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
{
msg = null;
msg = imp
msg = new StringBuilder(imp
? 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)
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

View File

@ -892,17 +892,17 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
StringBuilder header = new StringBuilder(field.getHeader());
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)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
header.append((" (ID)"));
ValueNamePair pp = new ValueNamePair(columnName, header.toString());
items.add(pp);
}
ValueNamePair[] cols = new ValueNamePair[items.size()];
@ -1248,7 +1248,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
}
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();
}
@ -1290,7 +1291,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
//
m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
StringBuffer code = new StringBuffer();
StringBuilder code = new StringBuilder();
int openBrackets = 0;
@ -1675,7 +1676,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (value != null && value.toString().length() > 0)
{
String ColumnName = wed.getColumnName();
log.fine(ColumnName + "=" + value);
StringBuilder msglog = new StringBuilder(ColumnName).append("=").append(value);
log.fine(msglog.toString());
// globalqss - Carlos Ruiz - 20060711
// 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());
String ColumnSQL = field.getColumnSQL(false);
StringBuilder ColumnSQL = new StringBuilder(field.getColumnSQL(false));
//
// Be more permissive for String columns
if (isSearchLike(field))
{
String valueStr = value.toString().toUpperCase();
if (!valueStr.endsWith("%"))
valueStr += "%";
StringBuilder valueStr = new StringBuilder(value.toString().toUpperCase());
if (!valueStr.toString().endsWith("%"))
valueStr.append("%");
//
ColumnSQL = "UPPER("+ColumnSQL+")";
value = valueStr;
ColumnSQL = new StringBuilder("UPPER(").append(ColumnSQL).append(")");
value = valueStr.toString();
}
//
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)
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
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)
@ -1760,7 +1762,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (null!=selectedHistoryItem && selectedHistoryItem.toString().length() > 0 && getHistoryDays(selectedHistoryValue) > 0)
{
StringBuffer where = new StringBuffer();
StringBuilder where = new StringBuilder();
where.append("Created >= ");
where.append("SysDate-").append(getHistoryDays(selectedHistoryValue));
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)
{
log.config("" + query);
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM ");
StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM ");
sql.append(m_tableName);
boolean hasWhere = false;
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) {
//if a node with this id is found later in the search we have a loop in the tree
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";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
try {
@ -1914,18 +1916,18 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
}
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
}
retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId);
retString += ") ";
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId))
.append(") ");
rs.close();
stmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
retString = "";
retString = new StringBuilder();
} catch (AdempiereSystemError e) {
log.log(Level.SEVERE, sql, e);
retString = "";
retString = new StringBuilder();
}
return retString;
return retString.toString();
} // getSubCategoryWhereClause
@ -1938,7 +1940,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
* @throws AdempiereSystemError if a loop is detected
**/
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
String ret = "";
StringBuilder ret = new StringBuilder();
final Iterator<SimpleTreeNode> iter = categories.iterator();
while (iter.hasNext()) {
SimpleTreeNode node = (SimpleTreeNode) iter.next();
@ -1946,11 +1948,11 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (node.getNodeId() == 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);
return ret + productCategoryId;
log.fine(ret.toString());
return ret.toString() + productCategoryId;
} // getSubCategoriesString
@ -2021,7 +2023,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
}
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();
}
return new Timestamp(time);
@ -2036,7 +2039,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
String error = ex.getLocalizedMessage();
if (error == null || error.length() == 0)
error = ex.toString();
StringBuffer errMsg = new StringBuffer();
StringBuilder errMsg = new StringBuilder();
errMsg.append(field.getColumnName()).append(" = ").append(in).append(" - ").append(error);
//
FDialog.error(0, this, "ValidationError", errMsg.toString());

View File

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