Replace ApprovedRate.java

parent 85f7b1af
package ibase.webitm.ejb.vhb.msq1;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -16,6 +14,7 @@ import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
public class ApprovedRate extends ValidatorEJB {
String usersiteCode = "";
E12GenericUtility genericUtility = new E12GenericUtility();
......@@ -27,31 +26,31 @@ public class ApprovedRate extends ValidatorEJB {
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;
PreparedStatement pstmt = 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;
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";
try {
BaseLogger.log("3", getUserInfo(), null, "Fetching last 5 quotation rates for item_code: " + itemCode);
conn = getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
while (rs.next())
{
while (rs.next()) {
ArrayList<String> quotationDetails = new ArrayList<>();
customerCode = checkNull(rs.getString("cust_code"));
customerName= checkNull(rs.getString("cust_name"));
customerName = checkNull(rs.getString("cust_name"));
quotNo = checkNull(rs.getString("quot_no"));
addDate = checkNull(rs.getString("created_date"));
itemCode = checkNull(rs.getString("item_code"));
itemDescr= checkNull(rs.getString("item_descr"));
itemDescr = checkNull(rs.getString("item_descr"));
aprvRate = checkNull(rs.getString("approved_rate"));
quantity = checkNull(rs.getString("quantity"));
......@@ -73,15 +72,29 @@ public class ApprovedRate extends ValidatorEJB {
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) {
rs.close();
}
......@@ -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)
{
if (str == null) {
return "";
} else {
return str;
}
private String checkNull(String str) {
return (str == null) ? "" : 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