Replace ApprovedRate.java

parent 85f7b1af
package ibase.webitm.ejb.vhb.msq1; package ibase.webitm.ejb.vhb.msq1;
import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -16,6 +14,7 @@ import ibase.utility.UserInfoBean; ...@@ -16,6 +14,7 @@ import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
public class ApprovedRate extends ValidatorEJB { public class ApprovedRate extends ValidatorEJB {
String usersiteCode = ""; String usersiteCode = "";
E12GenericUtility genericUtility = new E12GenericUtility(); E12GenericUtility genericUtility = new E12GenericUtility();
...@@ -27,31 +26,31 @@ public class ApprovedRate extends ValidatorEJB { ...@@ -27,31 +26,31 @@ public class ApprovedRate extends ValidatorEJB {
BaseLogger.log("3", getUserInfo(), null, "usersiteCode : " + usersiteCode); BaseLogger.log("3", getUserInfo(), null, "usersiteCode : " + usersiteCode);
} }
public HashMap<String, ArrayList<String>> getLastThreeQuotationRates(String itemCode) throws ITMException, SQLException { public HashMap<String, HashMap<String, ArrayList<String>>> getLastThreeQuotationRates(String itemCode) throws ITMException, SQLException {
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
LinkedHashMap<String, ArrayList<String>> quotationRatesMap = new LinkedHashMap<>(); HashMap<String, ArrayList<String>> quotationRatesMap = new HashMap<>();
HashMap<String, ArrayList<String>> quotationRatesMapmin = new HashMap<>();
int count = 0; int count = 0;
String customerCode = "" , quotNo = "" , addDate = "" ,aprvRate = "" , quantity="" , customerName="" , itemDescr=""; String customerCode = "", quotNo = "", addDate = "", aprvRate = "", quantity = "", customerName = "", itemDescr = "";
String minRate = "", maxRate = "";
String sql = "SELECT irh.cust_code, c.cust_name, irh.quot_no, irh.created_date, irh.item_code, irh.item_descr, irh.approved_rate, irh.quantity FROM item_rate_hist irh LEFT JOIN customer c ON irh.cust_code = c.cust_code WHERE irh.item_code = ? AND irh.created_date IS NOT NULL ORDER BY irh.created_date DESC LIMIT 5"; String sql = "SELECT irh.cust_code, c.cust_name, irh.quot_no, irh.created_date, irh.item_code, irh.item_descr, irh.approved_rate, irh.quantity FROM item_rate_hist irh LEFT JOIN customer c ON irh.cust_code = c.cust_code WHERE irh.item_code = ? AND irh.created_date IS NOT NULL ORDER BY irh.created_date DESC LIMIT 5";
try { try {
BaseLogger.log("3", getUserInfo(), null, "Fetching last 5 quotation rates for item_code: " + itemCode); BaseLogger.log("3", getUserInfo(), null, "Fetching last 5 quotation rates for item_code: " + itemCode);
conn = getConnection(); conn = getConnection();
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode); pstmt.setString(1, itemCode);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next()) {
{
ArrayList<String> quotationDetails = new ArrayList<>(); ArrayList<String> quotationDetails = new ArrayList<>();
customerCode = checkNull(rs.getString("cust_code")); customerCode = checkNull(rs.getString("cust_code"));
customerName= checkNull(rs.getString("cust_name")); customerName = checkNull(rs.getString("cust_name"));
quotNo = checkNull(rs.getString("quot_no")); quotNo = checkNull(rs.getString("quot_no"));
addDate = checkNull(rs.getString("created_date")); addDate = checkNull(rs.getString("created_date"));
itemCode = checkNull(rs.getString("item_code")); itemCode = checkNull(rs.getString("item_code"));
itemDescr= checkNull(rs.getString("item_descr")); itemDescr = checkNull(rs.getString("item_descr"));
aprvRate = checkNull(rs.getString("approved_rate")); aprvRate = checkNull(rs.getString("approved_rate"));
quantity = checkNull(rs.getString("quantity")); quantity = checkNull(rs.getString("quantity"));
...@@ -73,15 +72,29 @@ public class ApprovedRate extends ValidatorEJB { ...@@ -73,15 +72,29 @@ public class ApprovedRate extends ValidatorEJB {
count++; count++;
} }
sql = "select item_code, min(approved_rate) as min_rate, max(approved_rate) as max_rate from item_rate_hist where item_code = ? group by item_code";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
while (rs.next()) {
ArrayList<String> quotationDetailsmax = new ArrayList<>();
itemCode = checkNull(rs.getString("item_code"));
minRate = checkNull(rs.getString("min_rate"));
maxRate = checkNull(rs.getString("max_rate"));
quotationDetailsmax.add(itemCode);
quotationDetailsmax.add(minRate);
quotationDetailsmax.add(maxRate);
quotationRatesMapmin.put(String.valueOf(count), quotationDetailsmax);
count++;
} }
catch (Exception e)
{
BaseLogger.log("3", getUserInfo(), null, "Exception in getLastFiveQuotationRates: " + e.getMessage());
throw new ITMException(e);
}
finally
{
} catch (Exception e) {
BaseLogger.log("3", getUserInfo(), null, "Exception in getLastThreeQuotationRates: " + e.getMessage());
throw new ITMException(e);
} finally {
if (rs != null) { if (rs != null) {
rs.close(); rs.close();
} }
...@@ -93,15 +106,14 @@ public class ApprovedRate extends ValidatorEJB { ...@@ -93,15 +106,14 @@ public class ApprovedRate extends ValidatorEJB {
} }
} }
return quotationRatesMap; HashMap<String, HashMap<String, ArrayList<String>>> resultMap = new HashMap<>();
resultMap.put("quotationRatesMap", quotationRatesMap);
resultMap.put("quotationRatesMapmin", quotationRatesMapmin);
return resultMap;
} }
private String checkNull(String str) private String checkNull(String str) {
{ return (str == null) ? "" : str;
if (str == null) {
return "";
} else {
return str;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment