Commit f2350149 authored by kdabholkar's avatar kdabholkar

commited new changes related rate

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@173846 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 38b2a120
...@@ -18,7 +18,8 @@ import ibase.webitm.utility.*; ...@@ -18,7 +18,8 @@ import ibase.webitm.utility.*;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.fin.FinCommon; import ibase.webitm.ejb.fin.FinCommon;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;//import java.util.Date; import java.util.Calendar;
import java.util.Date;
import ibase.webitm.ejb.sys.UtilMethods; import ibase.webitm.ejb.sys.UtilMethods;
public class DistCommon public class DistCommon
{ {
...@@ -8279,9 +8280,9 @@ public class DistCommon ...@@ -8279,9 +8280,9 @@ public class DistCommon
* @exception Exception * @exception Exception
* @see * @see
*/ */
public java.sql.Timestamp CalcExpiry(java.sql.Timestamp date, double shelfLife) throws Exception public java.sql.Timestamp CalcExpiry(java.sql.Timestamp date, double shelfLife) throws Exception
{ {
UtilMethods utilMethods = UtilMethods.getInstance(); UtilMethods utilMethods = UtilMethods.getInstance();
java.sql.Timestamp expDate = null; java.sql.Timestamp expDate = null;
int lastDay = 0, iShelfLife = 0; int lastDay = 0, iShelfLife = 0;
iShelfLife = (int)shelfLife; iShelfLife = (int)shelfLife;
...@@ -8294,15 +8295,15 @@ public class DistCommon ...@@ -8294,15 +8295,15 @@ public class DistCommon
iShelfLife = iShelfLife - 1; iShelfLife = iShelfLife - 1;
} }
expDate = utilMethods.AddMonths(date, iShelfLife); expDate = utilMethods.AddMonths(date, iShelfLife);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(expDate); cal.setTime(expDate);
lastDay = cal.getMaximum(Calendar.DAY_OF_MONTH); lastDay = cal.getMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH,lastDay); cal.set(Calendar.DAY_OF_MONTH,lastDay);
java.util.Date newDate = cal.getTime(); java.util.Date newDate = cal.getTime();
SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
expDate = java.sql.Timestamp.valueOf(sdt.format(newDate) + " 00:00:00.000"); expDate = java.sql.Timestamp.valueOf(sdt.format(newDate) + " 00:00:00.000");
utilMethods = null; utilMethods = null;
return expDate; return expDate;
} }
// added by cpatil on 10/oct/12 start // added by cpatil on 10/oct/12 start
...@@ -11020,4 +11021,669 @@ public class DistCommon ...@@ -11020,4 +11021,669 @@ public class DistCommon
} }
//End added by chandrashekar on 10-aug-2016 //End added by chandrashekar on 10-aug-2016
//Added By Kaustubh on 14 Nov 2017 start
public String getSalesPriceList(String custCd, String custCdDlv, String siteCd, String contrNo, String itmCode,String orddt, Connection conn) throws ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String priceLst = "", sql = "";
Timestamp OrderDate=null;
try
{
System.out.println(">>>>>>>>>Enter in getPriceList method");
System.out.println(">>>>>>>>custCd===" + custCd);
System.out.println(">>>>>>>>custCdDlv===" + custCdDlv);
System.out.println(">>>>>>>>siteCd===" + siteCd);
System.out.println(">>>>>>>>contractNo===" + contrNo);
System.out.println(">>>>>>>>itmCode===" + itmCode);
System.out.println(">>>>>>>>orddt===" + orddt);
if(orddt !=null && orddt.trim().length()>0)
{
OrderDate = Timestamp.valueOf(genericUtility.getValidDateString(orddt,
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if (contrNo != null && contrNo.trim().length() > 0)
{
sql = "select price_list from scontract where contract_no=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, contrNo);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
System.out.println("Price list from contract no===========" + priceLst);
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
pstmt.setString(2, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
pstmt.setString(2, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
}
}
}
}
} else
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
pstmt.setString(2, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
pstmt.setString(2, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
}
}
}
}
if (contrNo != null && contrNo.trim().length() > 0)
{
sql="select price_list from scontract where contract_no=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, contrNo);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = rs.getString("price_list");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(priceLst==null ||priceLst.trim().length()==0)
{
sql = " select g.price_list from group_pricelist g,pricelist p where " + " g.cust_code = ? "
+ " and p.item_code = ? " + " and (? between to_date(g.eff_from) and to_date(g.valid_upto)) AND g.price_list=p.price_list ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCd);
pstmt.setString(2, itmCode);
pstmt.setTimestamp(3, OrderDate);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
// pstmt2.setString(2,custCd);// as
// per mail on 29 aug
pstmt.setString(2, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
if (priceLst == null)
{
priceLst = "";
}
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCd);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
System.out.println(">>>>>>>>>>>priceList Null found for Customer Code:" + priceLst);
sql = " select g.price_list from group_pricelist g,pricelist p where "
+ " g.cust_code = ? " + " and p.item_code = ? "
+ " and (? between to_date(g.eff_from) and to_date(g.valid_upto)) AND g.price_list=p.price_list ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCdDlv);
pstmt.setString(2, itmCode);
pstmt.setTimestamp(3, OrderDate);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from site_customer where site_code = ? and cust_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCd);
pstmt.setString(2, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (priceLst == null || priceLst.trim().length() == 0)
{
sql = "select price_list from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCdDlv);
rs = pstmt.executeQuery();
if (rs.next())
{
priceLst = checkNull(rs.getString("price_list"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
}
}
}
}
}
}
}
System.out.println("Final Price List =======" + priceLst);
} catch (Exception e)
{
System.out.println("Exception ::" + e);
throw new ITMException(e);
}
return priceLst;
}
public double getSalesRate(String pricelist,String SiteCode,String custCode,String mOrderDateStr ,String ldtDateStr,String lsNature, String ContractNo,String lsContractNo,String itemCode,double mQty,Connection conn)throws ITMException
{
System.out.println("+++++++++++++++inside getSalesRate++++++++++++++");
System.out.println("pricelist::"+pricelist);
System.out.println("SiteCode::"+SiteCode);
System.out.println("SiteCode::"+custCode);
System.out.println("mOrderDateStr::"+mOrderDateStr);
double salesRate = 0, mRate = 0.0,lcRate = 0.0,mquantity = 0.0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "",lsLineNoContr="",priceListDiscount="";
String lsListType = "",lsPriceListParent ="",lsRefNo = "",lsUnit ="";
Timestamp ldPlistDate = null, mTranDate = null;
Timestamp mOrderDate=null,ldtPlDate=null;
try
{
lsListType = getPriceListType(pricelist, conn);
sql = "select unit from item where item_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pricelist);
rs = pstmt.executeQuery();
if (rs.next())
{
lsUnit = rs.getString("unit");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (ldtDateStr == null || ldtDateStr.trim().length() <= 0)
{
ldtDateStr = mOrderDateStr;
}
if(mOrderDateStr !=null && mOrderDateStr.trim().length()>0)
{
mOrderDate = Timestamp.valueOf(genericUtility.getValidDateString(mOrderDateStr,
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(ldtDateStr !=null && ldtDateStr.length()>0)
{
ldtPlDate = Timestamp.valueOf(genericUtility.getValidDateString(ldtDateStr,
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(ContractNo.trim().length() > 0 )
{
sql = "select site_code,item_code,item_flg,quantity,unit,dsp_date,"
+" rate,discount,tax_amt,tax_class,tax_chap,"
+" tax_env, net_amt,remarks,item_descr,unit__rate,"
+" pack_code, pack_instr,no_art,quantity__stduom,rate__stduom,"
+" unit__std, conv__qty_stduom, conv__rtuom_stduom"
+" from scontractdet where contract_no= ? and line_no =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lsContractNo);
pstmt.setString(2, lsLineNoContr);
rs = pstmt.executeQuery();
if (rs.next())
{
mRate = rs.getDouble("rate");
mquantity = rs.getDouble("quantity");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
if (mRate <= 0)
{
if ("F".equalsIgnoreCase(lsNature) || "B".equalsIgnoreCase(lsNature) || "S".equalsIgnoreCase(lsNature))
{
mRate = 0;
}
else
{
if (pricelist != null || pricelist.trim().length() > 0)
{
if("B".equalsIgnoreCase(lsListType) && mRate <= 0)
{
sql = "select max(ref_no)from pricelist where price_list =? and item_code= ? and unit=? and list_type= ?"
+ " and eff_from<=? and valid_upto>=? and min_qty<=? and max_qty>=? and (ref_no is not null)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pricelist);
pstmt.setString(2, itemCode);
pstmt.setString(3, lsUnit);
pstmt.setString(4, lsListType);
pstmt.setTimestamp(5, mOrderDate);
pstmt.setTimestamp(6, mOrderDate);
pstmt.setDouble(7, mQty);
pstmt.setDouble(8, mQty);
rs = pstmt.executeQuery();
if (rs.next())
{
lsRefNo = rs.getString("ref_no");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(lsRefNo != null && lsRefNo.trim().length() > 0)
{
mRate = pickRateRefnoWise(pricelist, ldtDateStr, itemCode, lsRefNo, "L", mQty, conn);
}
}
if(mRate <= 0)
{
mRate = pickRate(pricelist, ldtDateStr, itemCode,"","L",mQty, conn);
}
}
if (lsListType == null || lsListType.trim().length() == 0)
{
sql = "select price_list__parent from pricelist where price_list = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, pricelist);
rs = pstmt.executeQuery();
if (rs.next())
{
lsPriceListParent = rs.getString("price_list__parent");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (lsPriceListParent != null || lsPriceListParent.trim().length() > 0)
{
lsListType = getPriceListType(lsPriceListParent, conn);
}
}
if ("B".equalsIgnoreCase(lsListType) && mRate < 0)
{
mRate = 0;
}
}
}//if (mRate <= 0)
if(mRate > 0)
{
sql = "select pricelist.rate rate, "
+" case when pricelist.rate_type = 'P' then '%' else 'Fix' end as rate_type, "
+"pricelist.price_list price_list"
+" from site_customer ,pricelist "
+" where site_customer.price_list__disc = pricelist.price_list "
+" and pricelist.list_type = 'M' "
+" and site_customer.site_code = ? "
+" and site_customer.cust_code = ? "
+" and pricelist.item_code = ? "
+" and site_customer.price_list__disc is not null" ;
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,SiteCode);
pstmt.setString(2,custCode);
pstmt.setString(3,itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
priceListDiscount =rs.getString("price_list") == null ? "" : rs.getString("price_list");
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if(priceListDiscount !=null && priceListDiscount.length() >0)
{
lcRate = getDiscount(priceListDiscount,mOrderDate, custCode, SiteCode, itemCode, lsUnit, 0.0, ldtPlDate, mquantity, conn);
}
if(lcRate > 0)
{
mRate = mRate - (mRate*lcRate/100);
}
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
throw new ITMException(e);
}
return mRate;
}
public double getDiscount(String priceList, Date orderDate, String custCode, String siteCode, String itemCode, String unit, double discMerge, Date pListDate, double quantity, Connection conn) throws ITMException
{
String listType = "", itmSer = "";
double disc = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
double rate = 0;
try
{
if (priceList != null && priceList.trim().length() > 0)
{
listType = getPriceListType(priceList,conn);
sql = " select case when rate is null then 0 else rate end as rate from pricelist where price_list=? and item_code =? and unit= ? and list_type IN ('M','N') and case when min_qty is null then 0 else ? end <=? and ((case when max_qty is null then 0 else max_qty end >= ?) OR (case when max_qty is null then 0 else max_qty end=0)) and eff_from<= ? and valid_upto >= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, priceList);
pstmt.setString(2, itemCode);
pstmt.setString(3, unit);
pstmt.setDouble(4, quantity);
pstmt.setDouble(5, quantity);
pstmt.setDouble(6, quantity);
pstmt.setDate(7, (java.sql.Date) orderDate);
pstmt.setDate(8, (java.sql.Date) orderDate);
rs = pstmt.executeQuery();
while (rs.next())
{
rate = rs.getDouble("rate");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
if (listType.equals("M") || priceList == null || priceList.trim().length() == 0 || rate == 0)
{
sql = "select item_ser from item where item_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
if (rs.next())
{
itmSer = rs.getString("item_ser");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "select disc_perc from customer_series where cust_code = ? and item_ser =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, itmSer);
rs = pstmt.executeQuery();
if (rs.next())
{
disc = rs.getDouble("disc_perc");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (disc == 0)
{
sql = "select disc_perc from site_customer where site_code = ? and cust_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
disc = rs.getDouble("disc_perc");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
if (disc == 0)
{
sql = "select disc_perc from customer where cust_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
disc = rs.getDouble("disc_perc");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
if (listType.equals("M"))
{
discMerge = disc;
if (rate != 0)
{
disc = rate;
}
} else
{
discMerge = 0;
}
if (disc == 0)
{
disc = 0;
}
if (itemCode == null || itemCode.trim().length() == 0)
{
disc = 0;
}
}
} catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return disc;
}
public String checkNull(String input)
{
if (input == null)
{
input = "";
}
return input;
}
// Added by kaustubh 14 Nov 2017 End
}//class }//class
\ No newline at end of file
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