IDEMPIERE-568 Review proper closing of JDBC statements and resultsets
This commit is contained in:
parent
f737c1fc87
commit
555e234496
|
@ -44,17 +44,18 @@ import org.compiere.util.DB;
|
||||||
public class ApplyMigrationScripts extends SvrProcess {
|
public class ApplyMigrationScripts extends SvrProcess {
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger
|
private static CLogger log = CLogger.getCLogger(ApplyMigrationScripts.class);
|
||||||
.getCLogger(ApplyMigrationScripts.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doIt() throws Exception {
|
protected String doIt() throws Exception {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
log.info("Applying migrations scripts");
|
log.info("Applying migrations scripts");
|
||||||
StringBuilder sql = new StringBuilder()
|
StringBuilder sql = new StringBuilder()
|
||||||
.append("select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created");
|
.append("select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created");
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = pstmt.executeQuery();
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||||
|
rs = pstmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
byte[] scriptArray = rs.getBytes(2);
|
byte[] scriptArray = rs.getBytes(2);
|
||||||
int seqID = rs.getInt(1);
|
int seqID = rs.getInt(1);
|
||||||
|
@ -75,18 +76,17 @@ public class ApplyMigrationScripts extends SvrProcess {
|
||||||
log.severe(e.getMessage());
|
log.severe(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? ");
|
sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? ");
|
||||||
pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
PreparedStatement pstmtu = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||||
if (execOk) {
|
if (execOk) {
|
||||||
pstmt.setString(1, "CO");
|
pstmtu.setString(1, "CO");
|
||||||
pstmt.setInt(2, seqID);
|
pstmtu.setInt(2, seqID);
|
||||||
} else {
|
} else {
|
||||||
pstmt.setString(1, "ER");
|
pstmtu.setString(1, "ER");
|
||||||
pstmt.setInt(2, seqID);
|
pstmtu.setInt(2, seqID);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
pstmt.executeUpdate();
|
pstmtu.executeUpdate();
|
||||||
if (!execOk) {
|
if (!execOk) {
|
||||||
pstmt.close();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -94,17 +94,23 @@ public class ApplyMigrationScripts extends SvrProcess {
|
||||||
StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage());
|
StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage());
|
||||||
log.saveError("Error", msglog.toString());
|
log.saveError("Error", msglog.toString());
|
||||||
log.severe(e.getMessage());
|
log.severe(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
DB.close(pstmtu);
|
||||||
|
pstmtu = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
} catch (SQLException e) {
|
||||||
pstmt.close();
|
throw e;
|
||||||
|
} finally {
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepare() {
|
protected void prepare() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +162,8 @@ public class ApplyMigrationScripts extends SvrProcess {
|
||||||
log.saveError("Error", msglog.toString());
|
log.saveError("Error", msglog.toString());
|
||||||
log.severe(e.getMessage());
|
log.severe(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (stmt != null)stmt.close();
|
DB.close(stmt);
|
||||||
|
stmt = null;
|
||||||
if(execOk)
|
if(execOk)
|
||||||
conn.commit();
|
conn.commit();
|
||||||
else
|
else
|
||||||
|
|
|
@ -92,9 +92,9 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
int toti = 0;
|
int toti = 0;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int totd = 0;
|
int totd = 0;
|
||||||
int V_temp;
|
int v_temp;
|
||||||
int v_NextNo = 0;
|
int v_NextNo = 0;
|
||||||
StringBuilder Message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
//
|
//
|
||||||
//Checking Prerequisites
|
//Checking Prerequisites
|
||||||
//PO Prices must exists
|
//PO Prices must exists
|
||||||
|
@ -171,31 +171,34 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sql.append(" AND IsCurrentVendor='Y' AND IsActive='Y' ");
|
sql.append(" AND IsCurrentVendor='Y' AND IsActive='Y' ");
|
||||||
sql.append(" GROUP BY M_Product_ID ").append(" HAVING COUNT(*) > 1 ) ");
|
sql.append(" GROUP BY M_Product_ID ").append(" HAVING COUNT(*) > 1 ) ");
|
||||||
|
|
||||||
PreparedStatement Cur_Duplicates = null;
|
PreparedStatement stmtDupl = null;
|
||||||
Cur_Duplicates = DB.prepareStatement(sql.toString(), get_TrxName());
|
ResultSet rsDupl = null;
|
||||||
ResultSet dupl = Cur_Duplicates.executeQuery();
|
PreparedStatement stmtVendors = null;
|
||||||
while (dupl.next()) {
|
ResultSet rsVend = null;
|
||||||
|
try {
|
||||||
|
stmtDupl = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
|
rsDupl = stmtDupl.executeQuery();
|
||||||
|
while (rsDupl.next()) {
|
||||||
sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID ");
|
sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID ");
|
||||||
sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' ");
|
sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' ");
|
||||||
sql.append(" AND IsActive = 'Y' ");
|
sql.append(" AND IsActive = 'Y' ");
|
||||||
sql.append(" AND M_Product_ID = ").append(dupl.getInt("M_Product_ID"));
|
sql.append(" AND M_Product_ID = ").append(rsDupl.getInt("M_Product_ID"));
|
||||||
sql.append(" ORDER BY PriceList DESC");
|
sql.append(" ORDER BY PriceList DESC");
|
||||||
|
|
||||||
PreparedStatement Cur_Vendors = null;
|
stmtVendors = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
Cur_Vendors = DB.prepareStatement(sql.toString(), get_TrxName());
|
rsVend = stmtVendors.executeQuery();
|
||||||
ResultSet Vend = Cur_Vendors.executeQuery();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Leave First
|
// Leave First
|
||||||
//
|
//
|
||||||
Vend.next();
|
rsVend.next();
|
||||||
|
|
||||||
while (Vend.next()) {
|
while (rsVend.next()) {
|
||||||
sqlupd = new StringBuilder("UPDATE M_Product_PO ");
|
sqlupd = new StringBuilder("UPDATE M_Product_PO ");
|
||||||
sqlupd.append(" SET IsCurrentVendor = 'N' ");
|
sqlupd.append(" SET IsCurrentVendor = 'N' ");
|
||||||
sqlupd.append(" WHERE M_Product_ID= ").append(Vend.getInt("M_Product_ID"));
|
sqlupd.append(" WHERE M_Product_ID= ").append(rsVend.getInt("M_Product_ID"));
|
||||||
sqlupd.append(" AND C_BPartner_ID= ");
|
sqlupd.append(" AND C_BPartner_ID= ");
|
||||||
sqlupd.append(Vend.getInt("C_BPartner_ID"));
|
sqlupd.append(rsVend.getInt("C_BPartner_ID"));
|
||||||
|
|
||||||
cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
|
cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
|
||||||
if (cntu == -1)
|
if (cntu == -1)
|
||||||
|
@ -204,16 +207,16 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlupd.toString());
|
sqlupd.toString());
|
||||||
totu += cntu;
|
totu += cntu;
|
||||||
log.fine("Updated " + cntu);
|
log.fine("Updated " + cntu);
|
||||||
|
|
||||||
}
|
}
|
||||||
Vend.close();
|
|
||||||
Cur_Vendors.close();
|
|
||||||
Cur_Vendors = null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
dupl.close();
|
} catch (SQLException e) {
|
||||||
Cur_Duplicates.close();
|
throw e;
|
||||||
Cur_Duplicates = null;
|
} finally {
|
||||||
|
DB.close(rsDupl, stmtDupl);
|
||||||
|
rsDupl = null; stmtDupl = null;
|
||||||
|
DB.close(rsVend, stmtVendors);
|
||||||
|
rsVend = null; stmtVendors = null;
|
||||||
|
}
|
||||||
|
|
||||||
// DB.commit(true, get_TrxName());
|
// DB.commit(true, get_TrxName());
|
||||||
|
|
||||||
|
@ -228,7 +231,7 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
if (cntd == -1)
|
if (cntd == -1)
|
||||||
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
||||||
totd += cntd;
|
totd += cntd;
|
||||||
Message = new StringBuilder("@Deleted@=").append(cntd).append(" - ");
|
message = new StringBuilder("@Deleted@=").append(cntd).append(" - ");
|
||||||
log.fine("Deleted " + cntd);
|
log.fine("Deleted " + cntd);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -243,10 +246,16 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sql.append(" AND p.C_Currency_ID = c.C_Currency_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);
|
sql.append(" AND v.M_PriceList_Version_ID = ").append(p_PriceList_Version_ID);
|
||||||
|
|
||||||
PreparedStatement curgen = null;
|
PreparedStatement stmtCurgen = null;
|
||||||
curgen = DB.prepareStatement(sql.toString(), get_TrxName());
|
ResultSet rsCurgen = null;
|
||||||
ResultSet v = curgen.executeQuery();
|
PreparedStatement stmtDiscountLine = null;
|
||||||
while (v.next()) {
|
ResultSet rsDiscountLine = null;
|
||||||
|
CPreparedStatement stmt = null;
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
try {
|
||||||
|
stmtCurgen = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
|
rsCurgen = stmtCurgen.executeQuery();
|
||||||
|
while (rsCurgen.next()) {
|
||||||
//
|
//
|
||||||
// For All Discount Lines in Sequence
|
// For All Discount Lines in Sequence
|
||||||
//
|
//
|
||||||
|
@ -259,13 +268,12 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id");
|
sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id");
|
||||||
sql.append(" FROM M_DiscountSchemaLine");
|
sql.append(" FROM M_DiscountSchemaLine");
|
||||||
sql.append(" WHERE M_DiscountSchema_ID=");
|
sql.append(" WHERE M_DiscountSchema_ID=");
|
||||||
sql.append(v.getInt("M_DiscountSchema_ID"));
|
sql.append(rsCurgen.getInt("M_DiscountSchema_ID"));
|
||||||
sql.append(" AND IsActive='Y' ORDER BY SeqNo");
|
sql.append(" AND IsActive='Y' ORDER BY SeqNo");
|
||||||
|
|
||||||
PreparedStatement Cur_DiscountLine = null;
|
stmtDiscountLine = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
Cur_DiscountLine = DB.prepareStatement(sql.toString(), get_TrxName());
|
rsDiscountLine = stmtDiscountLine.executeQuery();
|
||||||
ResultSet dl = Cur_DiscountLine.executeQuery();
|
while (rsDiscountLine.next()) {
|
||||||
while (dl.next()) {
|
|
||||||
//
|
//
|
||||||
//Clear Temporary Table
|
//Clear Temporary Table
|
||||||
//
|
//
|
||||||
|
@ -280,10 +288,10 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
//
|
//
|
||||||
//Create Selection in temporary table
|
//Create Selection in temporary table
|
||||||
//
|
//
|
||||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||||
String dl_Group1 = dl.getString("Group1");
|
String dl_Group1 = rsDiscountLine.getString("Group1");
|
||||||
String dl_Group2 = dl.getString("Group2");
|
String dl_Group2 = rsDiscountLine.getString("Group2");
|
||||||
if (v.wasNull()) {
|
if (rsCurgen.wasNull()) {
|
||||||
//
|
//
|
||||||
//Create Selection from M_Product_PO
|
//Create Selection from M_Product_PO
|
||||||
//
|
//
|
||||||
|
@ -291,26 +299,26 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlins.append( " SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", po.M_Product_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(" FROM M_Product p, M_Product_PO po");
|
||||||
sqlins.append(" WHERE p.M_Product_ID=po.M_Product_ID ");
|
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.AD_Client_ID=").append(rsCurgen.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' ");
|
sqlins.append(" AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' ");
|
||||||
//
|
//
|
||||||
//Optional Restrictions
|
//Optional Restrictions
|
||||||
//
|
//
|
||||||
// globalqss - detected bug, JDBC returns zero for null values
|
// globalqss - detected bug, JDBC returns zero for null values
|
||||||
// so we're going to use NULLIF(value, 0)
|
// so we're going to use NULLIF(value, 0)
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.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")))
|
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID")))
|
||||||
.append("))");
|
.append("))");
|
||||||
if(dl_Group1 != null)
|
if(dl_Group1 != null)
|
||||||
sqlins.append(" AND (p.Group1=?)");
|
sqlins.append(" AND (p.Group1=?)");
|
||||||
if (dl_Group2 != null)
|
if (dl_Group2 != null)
|
||||||
sqlins.append(" AND (p.Group2=?)");
|
sqlins.append(" AND (p.Group2=?)");
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL ");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("C_BPartner_ID")).append(",0) IS NULL ");
|
||||||
sqlins.append(" OR po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append(")");
|
sqlins.append(" OR po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append(")");
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||||
sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
|
sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")");
|
||||||
|
|
||||||
CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
|
@ -334,19 +342,19 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlins.append(" SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", p.M_Product_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(" FROM M_Product p, M_ProductPrice pp");
|
||||||
sqlins.append(" WHERE p.M_Product_ID=pp.M_Product_ID");
|
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 pp.M_PriceList_Version_ID = ").append(rsCurgen.getInt("M_PriceList_Version_Base_ID"));
|
||||||
sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'");
|
sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'");
|
||||||
//
|
//
|
||||||
//Optional Restrictions
|
//Optional Restrictions
|
||||||
//
|
//
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.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")))
|
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID")))
|
||||||
.append("))");
|
.append("))");
|
||||||
if(dl_Group1 != null)
|
if(dl_Group1 != null)
|
||||||
sqlins.append(" AND (p.Group1=?)");
|
sqlins.append(" AND (p.Group1=?)");
|
||||||
if (dl_Group2 != null)
|
if (dl_Group2 != null)
|
||||||
sqlins.append(" AND (p.Group2=?)");
|
sqlins.append(" AND (p.Group2=?)");
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS ");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.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("(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(",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id");
|
||||||
sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo");
|
sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo");
|
||||||
|
@ -355,12 +363,12 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating");
|
sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating");
|
||||||
sqlins.append(",royaltyamt,group1,group2");
|
sqlins.append(",royaltyamt,group1,group2");
|
||||||
sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID");
|
sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID");
|
||||||
sqlins.append(" AND po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append("))");
|
sqlins.append(" AND po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append("))");
|
||||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
|
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||||
sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
|
sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")");
|
||||||
|
|
||||||
|
|
||||||
CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
if (dl_Group1!=null)
|
if (dl_Group1!=null)
|
||||||
|
@ -378,13 +386,13 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.append("@Selected@=").append(cnti);
|
message.append("@Selected@=").append(cnti);
|
||||||
|
|
||||||
//
|
//
|
||||||
//Delete Prices in Selection, so that we can insert
|
//Delete Prices in Selection, so that we can insert
|
||||||
//
|
//
|
||||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||||
if (v.wasNull() || V_temp != p_PriceList_Version_ID) {
|
if (rsCurgen.wasNull() || v_temp != p_PriceList_Version_ID) {
|
||||||
|
|
||||||
sqldel = new StringBuilder("DELETE M_ProductPrice pp");
|
sqldel = new StringBuilder("DELETE M_ProductPrice pp");
|
||||||
sqldel.append(" WHERE pp.M_PriceList_Version_ID = ");
|
sqldel.append(" WHERE pp.M_PriceList_Version_ID = ");
|
||||||
|
@ -396,20 +404,20 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
if (cntd == -1)
|
if (cntd == -1)
|
||||||
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
||||||
totd += cntd;
|
totd += cntd;
|
||||||
Message.append(", @Deleted@=").append(cntd);
|
message.append(", @Deleted@=").append(cntd);
|
||||||
log.fine("Deleted " + cntd);
|
log.fine("Deleted " + cntd);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy (Insert) Prices
|
// Copy (Insert) Prices
|
||||||
//
|
//
|
||||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||||
if (V_temp == p_PriceList_Version_ID)
|
if (v_temp == p_PriceList_Version_ID)
|
||||||
//
|
//
|
||||||
// We have Prices already
|
// We have Prices already
|
||||||
//
|
//
|
||||||
;
|
;
|
||||||
else if (v.wasNull())
|
else if (rsCurgen.wasNull())
|
||||||
//
|
//
|
||||||
//Copy and Convert from Product_PO
|
//Copy and Convert from Product_PO
|
||||||
//
|
//
|
||||||
|
@ -431,59 +439,59 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlins.append(p_PriceList_Version_ID);
|
sqlins.append(p_PriceList_Version_ID);
|
||||||
sqlins.append(" ,po.M_Product_ID ");
|
sqlins.append(" ,po.M_Product_ID ");
|
||||||
sqlins.append(" ,");
|
sqlins.append(" ,");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(" ,");
|
sqlins.append(" ,");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append(" ,'Y'");
|
sqlins.append(" ,'Y'");
|
||||||
sqlins.append(" ,SysDate,");
|
sqlins.append(" ,SysDate,");
|
||||||
sqlins.append(v.getInt("UpdatedBy"));
|
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||||
sqlins.append(" ,SysDate,");
|
sqlins.append(" ,SysDate,");
|
||||||
sqlins.append(v.getInt("UpdatedBy"));
|
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||||
//
|
//
|
||||||
//Price List
|
//Price List
|
||||||
//
|
//
|
||||||
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(", ? , ");
|
sqlins.append(", ? , ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0)");
|
sqlins.append("),0)");
|
||||||
|
|
||||||
// Price Std
|
// Price Std
|
||||||
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(", ? , ");
|
sqlins.append(", ? , ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0)");
|
sqlins.append("),0)");
|
||||||
|
|
||||||
// Price Limit
|
// Price Limit
|
||||||
sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, ");
|
sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(",? , ");
|
sqlins.append(",? , ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0)");
|
sqlins.append("),0)");
|
||||||
sqlins.append(" FROM M_Product_PO po ");
|
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(" 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 s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(") ");
|
||||||
sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'");
|
sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'");
|
||||||
|
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
|
pstmt = DB.prepareStatement(sqlins.toString(),
|
||||||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||||
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
|
|
||||||
cnti = pstmt.executeUpdate();
|
cnti = pstmt.executeUpdate();
|
||||||
if (cnti == -1)
|
if (cnti == -1)
|
||||||
|
@ -503,59 +511,59 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlins.append(" SELECT ");
|
sqlins.append(" SELECT ");
|
||||||
sqlins.append(p_PriceList_Version_ID);
|
sqlins.append(p_PriceList_Version_ID);
|
||||||
sqlins.append(", pp.M_Product_ID,");
|
sqlins.append(", pp.M_Product_ID,");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append(", 'Y', SysDate, ");
|
sqlins.append(", 'Y', SysDate, ");
|
||||||
sqlins.append(v.getInt("UpdatedBy"));
|
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||||
sqlins.append(", SysDate, ");
|
sqlins.append(", SysDate, ");
|
||||||
sqlins.append(v.getInt("UpdatedBy"));
|
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||||
sqlins.append(" ,");
|
sqlins.append(" ,");
|
||||||
// Price List
|
// Price List
|
||||||
sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, ");
|
sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(", ?, ");
|
sqlins.append(", ?, ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0),");
|
sqlins.append("),0),");
|
||||||
// Price Std
|
// Price Std
|
||||||
sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, ");
|
sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(" , ? , ");
|
sqlins.append(" , ? , ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0),");
|
sqlins.append("),0),");
|
||||||
//Price Limit
|
//Price Limit
|
||||||
sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, ");
|
sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, ");
|
||||||
sqlins.append(v.getInt("C_Currency_ID"));
|
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||||
sqlins.append(" , ? , ");
|
sqlins.append(" , ? , ");
|
||||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Client_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||||
sqlins.append(", ");
|
sqlins.append(", ");
|
||||||
sqlins.append(v.getInt("AD_Org_ID"));
|
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||||
sqlins.append("),0)");
|
sqlins.append("),0)");
|
||||||
sqlins.append(" FROM M_ProductPrice pp");
|
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_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(" INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)");
|
||||||
sqlins.append(" WHERE pp.M_PriceList_Version_ID=");
|
sqlins.append(" WHERE pp.M_PriceList_Version_ID=");
|
||||||
sqlins.append(v.getInt("M_PriceList_Version_Base_ID"));
|
sqlins.append(rsCurgen.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 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 s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
|
||||||
sqlins.append("AND pp.IsActive='Y'");
|
sqlins.append("AND pp.IsActive='Y'");
|
||||||
|
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
|
pstmt = DB.prepareStatement(sqlins.toString(),
|
||||||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||||
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate"));
|
pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||||
|
|
||||||
cnti = pstmt.executeUpdate();
|
cnti = pstmt.executeUpdate();
|
||||||
|
|
||||||
|
@ -567,19 +575,19 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
log.fine("Inserted " + cnti);
|
log.fine("Inserted " + cnti);
|
||||||
|
|
||||||
}
|
}
|
||||||
Message.append(", @Inserted@=").append(cnti);
|
message.append(", @Inserted@=").append(cnti);
|
||||||
//
|
//
|
||||||
// Calculation
|
// Calculation
|
||||||
//
|
//
|
||||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||||
sqlupd.append(" SET PriceList = (DECODE( '");
|
sqlupd.append(" SET PriceList = (DECODE( '");
|
||||||
sqlupd.append(dl.getString("List_Base"));
|
sqlupd.append(rsDiscountLine.getString("List_Base"));
|
||||||
sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)");
|
sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)");
|
||||||
sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('");
|
sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('");
|
||||||
sqlupd.append(dl.getString("Std_Base"));
|
sqlupd.append(rsDiscountLine.getString("Std_Base"));
|
||||||
sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) ");
|
sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) ");
|
||||||
sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('");
|
sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('");
|
||||||
sqlupd.append(dl.getString("Limit_Base"));
|
sqlupd.append(rsDiscountLine.getString("Limit_Base"));
|
||||||
sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) ");
|
sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) ");
|
||||||
sqlupd.append(" + ?) * (1 - ? /100) ");
|
sqlupd.append(" + ?) * (1 - ? /100) ");
|
||||||
sqlupd.append(" WHERE M_PriceList_Version_ID = ");
|
sqlupd.append(" WHERE M_PriceList_Version_ID = ");
|
||||||
|
@ -592,12 +600,12 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||||
|
|
||||||
pstmu.setDouble(1, dl.getDouble("List_AddAmt"));
|
pstmu.setDouble(1, rsDiscountLine.getDouble("List_AddAmt"));
|
||||||
pstmu.setDouble(2, dl.getDouble("List_Discount"));
|
pstmu.setDouble(2, rsDiscountLine.getDouble("List_Discount"));
|
||||||
pstmu.setDouble(3, dl.getDouble("Std_AddAmt"));
|
pstmu.setDouble(3, rsDiscountLine.getDouble("Std_AddAmt"));
|
||||||
pstmu.setDouble(4, dl.getDouble("Std_Discount"));
|
pstmu.setDouble(4, rsDiscountLine.getDouble("Std_Discount"));
|
||||||
pstmu.setDouble(5, dl.getDouble("Limit_AddAmt"));
|
pstmu.setDouble(5, rsDiscountLine.getDouble("Limit_AddAmt"));
|
||||||
pstmu.setDouble(6, dl.getDouble("Limit_Discount"));
|
pstmu.setDouble(6, rsDiscountLine.getDouble("Limit_Discount"));
|
||||||
|
|
||||||
cntu = pstmu.executeUpdate();
|
cntu = pstmu.executeUpdate();
|
||||||
|
|
||||||
|
@ -611,7 +619,7 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
//
|
//
|
||||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||||
sqlupd.append(" SET PriceList = DECODE('");
|
sqlupd.append(" SET PriceList = DECODE('");
|
||||||
sqlupd.append(dl.getString("List_Rounding")).append("',");
|
sqlupd.append(rsDiscountLine.getString("List_Rounding")).append("',");
|
||||||
sqlupd.append(" 'N', PriceList, ");
|
sqlupd.append(" 'N', PriceList, ");
|
||||||
sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00
|
sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00
|
||||||
sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10
|
sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10
|
||||||
|
@ -621,9 +629,9 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
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)+(5-MOD(ROUND(PriceList),10))");
|
||||||
sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,");
|
sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,");
|
||||||
sqlupd.append(" ROUND(PriceList, ").append(v.getInt("StdPrecision"));
|
sqlupd.append(" ROUND(PriceList, ").append(rsCurgen.getInt("StdPrecision"));
|
||||||
sqlupd.append(")),");//Currency
|
sqlupd.append(")),");//Currency
|
||||||
sqlupd.append(" PriceStd = DECODE('").append(dl.getString("Std_Rounding"));
|
sqlupd.append(" PriceStd = DECODE('").append(rsDiscountLine.getString("Std_Rounding"));
|
||||||
sqlupd.append("',").append(" 'N', PriceStd, ");
|
sqlupd.append("',").append(" 'N', PriceStd, ");
|
||||||
sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00
|
sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00
|
||||||
sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10
|
sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10
|
||||||
|
@ -633,9 +641,9 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
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)+(5-MOD(ROUND(PriceStd),10))");
|
||||||
sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,");
|
sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,");
|
||||||
sqlupd.append("ROUND(PriceStd, ").append(v.getInt("StdPrecision")).append(")),"); //Currency
|
sqlupd.append("ROUND(PriceStd, ").append(rsCurgen.getInt("StdPrecision")).append(")),"); //Currency
|
||||||
sqlupd.append("PriceLimit = DECODE('");
|
sqlupd.append("PriceLimit = DECODE('");
|
||||||
sqlupd.append(dl.getString("Limit_Rounding")).append("', ");
|
sqlupd.append(rsDiscountLine.getString("Limit_Rounding")).append("', ");
|
||||||
sqlupd.append(" 'N', PriceLimit, ");
|
sqlupd.append(" 'N', PriceLimit, ");
|
||||||
sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00
|
sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00
|
||||||
sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10
|
sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10
|
||||||
|
@ -645,7 +653,7 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
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)+(5-MOD(ROUND(PriceLimit),10))");
|
||||||
sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,");
|
sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,");
|
||||||
sqlupd.append(" ROUND(PriceLimit, ").append(v.getInt("StdPrecision"));
|
sqlupd.append(" ROUND(PriceLimit, ").append(rsCurgen.getInt("StdPrecision"));
|
||||||
sqlupd.append(")) "); // Currency
|
sqlupd.append(")) "); // Currency
|
||||||
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
||||||
sqlupd.append(p_PriceList_Version_ID);
|
sqlupd.append(p_PriceList_Version_ID);
|
||||||
|
@ -659,20 +667,20 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
totu += cntu;
|
totu += cntu;
|
||||||
log.fine("Updated " + cntu);
|
log.fine("Updated " + cntu);
|
||||||
|
|
||||||
Message.append(", @Updated@=").append(cntu);
|
message.append(", @Updated@=").append(cntu);
|
||||||
//
|
//
|
||||||
//Fixed Price overwrite
|
//Fixed Price overwrite
|
||||||
//
|
//
|
||||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||||
sqlupd.append(" SET PriceList = DECODE('");
|
sqlupd.append(" SET PriceList = DECODE('");
|
||||||
sqlupd.append(dl.getString("List_Base")).append("', 'F', ");
|
sqlupd.append(rsDiscountLine.getString("List_Base")).append("', 'F', ");
|
||||||
sqlupd.append(dl.getDouble("List_Fixed")).append(", PriceList), ");
|
sqlupd.append(rsDiscountLine.getDouble("List_Fixed")).append(", PriceList), ");
|
||||||
sqlupd.append(" PriceStd = DECODE('");
|
sqlupd.append(" PriceStd = DECODE('");
|
||||||
sqlupd.append(dl.getString("Std_Base")).append("', 'F', ");
|
sqlupd.append(rsDiscountLine.getString("Std_Base")).append("', 'F', ");
|
||||||
sqlupd.append(dl.getDouble("Std_Fixed")).append(", PriceStd),");
|
sqlupd.append(rsDiscountLine.getDouble("Std_Fixed")).append(", PriceStd),");
|
||||||
sqlupd.append(" PriceLimit = DECODE('");
|
sqlupd.append(" PriceLimit = DECODE('");
|
||||||
sqlupd.append(dl.getString("Limit_Base")).append("', 'F', ");
|
sqlupd.append(rsDiscountLine.getString("Limit_Base")).append("', 'F', ");
|
||||||
sqlupd.append(dl.getDouble("Limit_Fixed")).append(", PriceLimit)");
|
sqlupd.append(rsDiscountLine.getDouble("Limit_Fixed")).append(", PriceLimit)");
|
||||||
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
||||||
sqlupd.append(p_PriceList_Version_ID);
|
sqlupd.append(p_PriceList_Version_ID);
|
||||||
sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s");
|
sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s");
|
||||||
|
@ -686,13 +694,9 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
log.fine("Updated " + cntu);
|
log.fine("Updated " + cntu);
|
||||||
|
|
||||||
v_NextNo = v_NextNo + 1;
|
v_NextNo = v_NextNo + 1;
|
||||||
addLog(0, null, null, Message.toString());
|
addLog(0, null, null, message.toString());
|
||||||
Message = new StringBuilder();
|
message = new StringBuilder();
|
||||||
}
|
}
|
||||||
dl.close();
|
|
||||||
Cur_DiscountLine.close();
|
|
||||||
Cur_DiscountLine = null;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Delete Temporary Selection
|
// Delete Temporary Selection
|
||||||
//
|
//
|
||||||
|
@ -710,9 +714,18 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
// DB.commit(true, get_TrxName());
|
// DB.commit(true, get_TrxName());
|
||||||
|
|
||||||
}
|
}
|
||||||
v.close();
|
} catch (SQLException e) {
|
||||||
curgen.close();
|
throw e;
|
||||||
curgen = null;
|
} finally {
|
||||||
|
DB.close(rsCurgen, stmtCurgen);
|
||||||
|
rsCurgen = null; stmtCurgen = null;
|
||||||
|
DB.close(rsDiscountLine, stmtDiscountLine);
|
||||||
|
rsDiscountLine = null; stmtDiscountLine = null;
|
||||||
|
DB.close(stmt);
|
||||||
|
stmt = null;
|
||||||
|
DB.close(pstmt);
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
|
||||||
return "OK";
|
return "OK";
|
||||||
|
|
||||||
|
@ -734,15 +747,19 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
* It is used as restriction in MQuery.
|
* It is used as restriction in MQuery.
|
||||||
* @param productCategoryId
|
* @param productCategoryId
|
||||||
* @return
|
* @return
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError{
|
private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError {
|
||||||
//if a node with this id is found later in the search we have a loop in the tree
|
//if a node with this id is found later in the search we have a loop in the tree
|
||||||
int subTreeRootParentId = 0;
|
int subTreeRootParentId = 0;
|
||||||
StringBuilder retString = new StringBuilder();
|
StringBuilder retString = new StringBuilder();
|
||||||
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
|
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
|
||||||
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
|
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
|
||||||
Statement stmt = DB.createStatement();
|
Statement stmt = null;
|
||||||
ResultSet rs = stmt.executeQuery(sql);
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
stmt = DB.createStatement();
|
||||||
|
rs = stmt.executeQuery(sql);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if(rs.getInt(1)==productCategoryId) {
|
if(rs.getInt(1)==productCategoryId) {
|
||||||
subTreeRootParentId = rs.getInt(2);
|
subTreeRootParentId = rs.getInt(2);
|
||||||
|
@ -750,8 +767,12 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
|
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
|
||||||
}
|
}
|
||||||
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId));
|
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId));
|
||||||
rs.close();
|
} catch (SQLException e) {
|
||||||
stmt.close();
|
throw e;
|
||||||
|
} finally {
|
||||||
|
DB.close(rs, stmt);
|
||||||
|
rs = null; stmt = null;
|
||||||
|
}
|
||||||
return retString.toString();
|
return retString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,7 +781,7 @@ public class M_PriceList_Create extends SvrProcess {
|
||||||
* @param productCategoryId
|
* @param productCategoryId
|
||||||
* @param categories
|
* @param categories
|
||||||
* @param loopIndicatorId
|
* @param loopIndicatorId
|
||||||
* @return comma seperated list of category ids
|
* @return comma separated list of category ids
|
||||||
* @throws AdempiereSystemError if a loop is detected
|
* @throws AdempiereSystemError if a loop is detected
|
||||||
*/
|
*/
|
||||||
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
|
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
|
||||||
|
|
Loading…
Reference in New Issue