Commit 12b34a76 authored by ngadkari's avatar ngadkari

change for point base scheme

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@201959 ce508802-f39f-4f6c-b175-0d175dae99d5
parent fbcfbeee
......@@ -5329,11 +5329,13 @@ public class PostOrderActivity {
}
}
sql="UPDATE SCHEME_BALANCE SET BALANCE_FREE_VALUE = BALANCE_FREE_VALUE + ? WHERE CUST_CODE = ? AND ITEM_CODE= ?";
sql="UPDATE SCHEME_BALANCE SET BALANCE_FREE_VALUE = BALANCE_FREE_VALUE + ? WHERE CUST_CODE = ? AND ITEM_CODE= ? AND ? >= EFF_FROM and ? <= VALID_UPTO";
pstmt1=conn.prepareStatement(sql);
pstmt1.setDouble(1, totalpoints);
pstmt1.setString(2, custCode);
pstmt1.setString(3, "X");
pstmt1.setTimestamp(4, orderDate);
pstmt1.setTimestamp(5, orderDate);
pstmt1.executeUpdate();
if (pstmt1 != null){
pstmt1.close();
......@@ -5365,11 +5367,13 @@ public class PostOrderActivity {
retString = itmDBAccessEJB.getErrorString("","VTFREEPOIN","","",conn);
}
else {
sql="UPDATE SCHEME_BALANCE SET USED_FREE_VALUE = USED_FREE_VALUE + ? WHERE CUST_CODE = ? AND ITEM_CODE= ?";
sql="UPDATE SCHEME_BALANCE SET USED_FREE_VALUE = USED_FREE_VALUE + ? WHERE CUST_CODE = ? AND ITEM_CODE= ? AND ? >= EFF_FROM and ? <= VALID_UPTO";
pstmt1=conn.prepareStatement(sql);
pstmt1.setDouble(1, totalusedpoints);
pstmt1.setString(2, custCode);
pstmt1.setString(3, "X");
pstmt1.setTimestamp(4, orderDate);
pstmt1.setTimestamp(5, orderDate);
pstmt1.executeUpdate();
if (pstmt1 != null){
pstmt1.close();
......
......@@ -866,10 +866,12 @@ public class SaleOrderPostSave extends ValidatorEJB implements SaleOrderPostSave
{
sql = " SELECT BALANCE_FREE_VALUE - USED_FREE_VALUE FROM SCHEME_BALANCE WHERE BALANCE_FREE_VALUE - USED_FREE_VALUE > 0 "
+ " AND CUST_CODE = ? AND ITEM_CODE= ? ";
+ " AND CUST_CODE = ? AND ITEM_CODE= ? AND EFF_FROM <= ? AND VALID_UPTO >=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setString(2,"X");
pstmt.setTimestamp(3, orderDate);
pstmt.setTimestamp(4, orderDate);
rs = pstmt.executeQuery();
if (rs.next())
......
......@@ -3155,10 +3155,12 @@ public class SalesOrderIC extends ValidatorEJB implements SalesOrderICLocal, Sal
}
sql = " SELECT BALANCE_FREE_VALUE - USED_FREE_VALUE FROM SCHEME_BALANCE WHERE BALANCE_FREE_VALUE - USED_FREE_VALUE > 0 "
+ " AND CUST_CODE = ? AND ITEM_CODE= ? ";
+ " AND CUST_CODE = ? AND ITEM_CODE= ? AND EFF_FROM <= ? AND VALID_UPTO >=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setString(2,"X");
pstmt.setTimestamp(3, orderDate);
pstmt.setTimestamp(4, orderDate);
rs = pstmt.executeQuery();
if (rs.next())
......
......@@ -16,6 +16,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
......@@ -35,6 +36,7 @@ import org.w3c.dom.NodeList;
public class SorderAct extends ActionHandlerEJB implements SorderActLocal, SorderActRemote
{
E12GenericUtility genericUtility= new E12GenericUtility();
DistCommon distCommon = new DistCommon();//added by nandkumar gadkari on 11/06/19
/*public void ejbCreate() throws RemoteException, CreateException
{
}
......@@ -174,7 +176,7 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
}
@Override
//public String getFreeSchemeAction(String actionType, String xmlString, String xmlString1, String objContext, String xtraParams, String selDataStr) throws RemoteException,ITMException
//public String k(String actionType, String xmlString, String xmlString1, String objContext, String xtraParams, String selDataStr) throws RemoteException,ITMException
public String getFreeSchemeaction(String actionType, String xmlString, String xmlString1, String objContext, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
......@@ -250,6 +252,8 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
Set<String> finalApplicableSchemeSet = new HashSet<String>();
String itemValues = "",itemCodeSchm = "",rate = "",SaleOrder = "",schemeCode1 = "",siteCode1="",stateCodeDlv="",countCodeDlv="";
double finRate =0.0;
String freeBalOrd="",pointBaseSchemeXml="",schemeCodeList="";
List<String> getSchemeListPur = new ArrayList<String>();
try
{
......@@ -358,13 +362,36 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
//getSchemeList.add(schemeCode);
itmCode = rs.getString("item_code");
System.out.println("Applicable Scheme for Purchase Item ["+itmCode+"]" + " is === Scheme Code ["+schemeCode1+"]");
getSchemeListPur.add(schemeCode1);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
// added by nandkumar gadkari on 12/06/19
schemeCodeList = "";
itr = getSchemeListPur.iterator();
while(itr.hasNext())
{
schemeCodeList = schemeCodeList + "'"+(String) itr.next() + "'";
if(itr.hasNext())
{
schemeCodeList=schemeCodeList+ ",";
}
}
sql = "select distinct(a.scheme_code) from scheme_applicability a,scheme_applicability_det b"
sql = "select distinct(a.scheme_code) from scheme_applicability a,scheme_applicability_det b"
+ " where a.scheme_code = b.scheme_code"
+ " and a.prod_sch = 'Y'"
+ " and a.app_from<= ?" + " and a.valid_upto>= ?"
+ " and b.site_code=?"
+ " or b.state_code = ?" + " or b.count_code= ?";
+ " and (b.site_code=?"
+ " or b.state_code = ?" + " or b.count_code= ?) and a.scheme_code in ("+schemeCodeList+")";// condition change by nandkumar gadkari on 12/06/19
pstmt2 = conn.prepareStatement(sql);
//pstmt2.setString(1, itmCode);
pstmt2.setTimestamp(1, TranDateDet);
......@@ -377,7 +404,8 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
while(rs2.next())
{
schemeCode = rs2.getString("scheme_code");
getSchemeList.add(schemeCode);
//getSchemeList.add(schemeCode); commented and aaded by nandkumar gadkari on 12/06/19
finalApplicableSchemeSet.add(schemeCode);
//System.out.println("All Applicable Schemes in scheme_applicability Table ["+getSchemeList+"]");
//System.out.println("schemeCode["+schemeCode+"]" + "itmCode["+itmCode+"]" + "\t");
}
......@@ -393,7 +421,7 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
}
//checking Applicability of schemes
if(getSchemeList.contains(schemeCode1))
/*if(getSchemeList.contains(schemeCode1))
{
if(getSchemeItemList.containsKey(schemeCode1))
{
......@@ -413,12 +441,12 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
getSchemeItemList.put(schemeCode1,schemeInfo);
}
}
}*/// commented by nandkumar gadkari on 12/06/19
System.out.println("Applicable Scheme code and Item code are :::"+getSchemeItemList);
System.out.println("Scheme Applicable for Purchased Item in ArrayList ::["+finalApplicableSchemeSet+"]");
}
/*}
if(pstmt != null)
{
pstmt.close();
......@@ -428,10 +456,11 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
{
rs.close();
rs = null;
}
} */
//itr = getSchemeList.iterator();
if(getSchemeItemList.size() > 0)
//if(getSchemeItemList.size() > 0) condition chnage by nandkumar gadkari on 12/06/19
if(getSchemeListPur.size() > 0)
{
//List<String> finalApplicableSchemeList = getSchemeItemList.get("schemeInfo");
System.out.println("finalApplicableSchemeSet :: ["+finalApplicableSchemeSet+"]");
......@@ -466,7 +495,7 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
schemeCode = rs.getString("scheme_code");
schemeType = rs.getString("scheme_type");
schemeDescr = rs.getString("descr");
purcBase = Double.valueOf(rs.getString("purc_base"));
purcBase = Double.valueOf(checkDouble(rs.getString("purc_base")));
schAllowence1= Double.valueOf(checkDouble(rs.getString("sch_allowence")));
discount = Double.valueOf(checkDouble(rs.getString("discount")));
System.out.println("Applicable schemeType ["+schemeType+"]" + "for schemeCode ["+schemeCode+"]" + "purcBase ["+purcBase+"]" +"schAllowence1 ["+schAllowence1+"]" +"Scheme Description ["+schemeDescr+"]" + "Discount is :::["+discount+"]");
......@@ -705,6 +734,7 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
}
}
}//end of while loop
if(pstmt != null)
{
......@@ -719,78 +749,98 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
//valueXmlString.append(s12);
}//end of if block for list
//valueXmlString.append("</Root>\r\n");
/**
* New code added by kaustubh on 31 Dec 2018 regarding fetching scheme details from scheme_balance table -------------start
* **/
System.out.println("inside Scheme balance Changes");
TranDateDet = getTimeStamp(dsp_date);
System.out.println("cust_code "+custCode+"TranDate "+ TranDateDet);
outSql = " select TRAN_ID from SCHEME_BALANCE where EFF_FROM <= ? AND VALID_UPTO >= ? AND CUST_CODE = ? " ;
//conditon of FREE_BAL_ORD added by nandkumar gadkari on 11/06/19
freeBalOrd = distCommon.getDisparams( "999999", "FREE_BAL_ORD", conn );
if(freeBalOrd==null || freeBalOrd.trim().length() ==0 || freeBalOrd.equalsIgnoreCase("NULLFOUND"))
{
freeBalOrd="N";
}
else
{
freeBalOrd=freeBalOrd.trim();
}
if("Y".equalsIgnoreCase(freeBalOrd))
{
/**
* New code added by kaustubh on 31 Dec 2018 regarding fetching scheme details from scheme_balance table -------------start
* **/
pstmtOut = conn.prepareStatement(outSql);
pstmtOut.setTimestamp(1, TranDateDet);
pstmtOut.setTimestamp(2, TranDateDet);
pstmtOut.setString(3,custCode);
rs3 = pstmtOut.executeQuery();
while(rs3.next())
{
tranID = rs3.getString("TRAN_ID");
System.out.println("inside Scheme balance Changes");
TranDateDet = getTimeStamp(dsp_date);
System.out.println("cust_code "+custCode+"TranDate "+ TranDateDet);
sql = " SELECT tran_id,"
+ "CASE WHEN item_code = 'X' THEN 'X' "
+" ELSE item_code end as item_code , SCHEME_CODE,SCHEME_TYPE, "
+" CASE WHEN item_code = 'X' THEN 'V' "
+" when item_code <> 'X' THEN 'I' END AS nature,"
+" CASE WHEN (BALANCE_FREE_VALUE - USED_FREE_VALUE > 0) THEN (BALANCE_FREE_VALUE - USED_FREE_VALUE ) "
+" WHEN ( balance_free_qty - USED_FREE_qty > 0 ) THEN ( balance_free_qty - USED_FREE_qty )"
+" END AS free_qty "
+" FROM SCHEME_BALANCE "
+" WHERE (BALANCE_FREE_VALUE - USED_FREE_VALUE > 0 or balance_free_qty - USED_FREE_qty > 0 ) "
+" and EFF_FROM <= ? AND VALID_UPTO >= ? "
+" AND CUST_CODE = ? and TRAN_ID = ? ";
pstmtIn = conn.prepareStatement(sql);
pstmtIn.setTimestamp(1, TranDateDet);
pstmtIn.setTimestamp(2, TranDateDet);
pstmtIn.setString(3,custCode);
pstmtIn.setString(4, tranID);
rs4 = pstmtIn.executeQuery();
outSql = " select TRAN_ID from SCHEME_BALANCE where EFF_FROM <= ? AND VALID_UPTO >= ? AND CUST_CODE = ? " ;
pstmtOut = conn.prepareStatement(outSql);
pstmtOut.setTimestamp(1, TranDateDet);
pstmtOut.setTimestamp(2, TranDateDet);
pstmtOut.setString(3,custCode);
while(rs4.next())
{
domID++;
rs3 = pstmtOut.executeQuery();
while(rs3.next())
{
tranID = rs3.getString("TRAN_ID");
System.out.println("DomId"+domID);
itemCode = rs4.getString("item_code");
schemeCode = rs4.getString("SCHEME_CODE");
schemeType = rs4.getString("SCHEME_TYPE");
nature = rs4.getString("nature");
freeQuantity =rs4.getDouble("free_qty");
valueXmlString.append("<Detail domId='"+(domID)+"'>\r\n");
System.out.println("Free Items "+itemCode);
itemDescription = getItemDescr(itemCode,conn);
valueXmlString.append("<scheme_type>").append("<![CDATA[").append(schemeType).append("]]>").append("</scheme_type>\r\n");
valueXmlString.append("<applicable_scheme>").append("<![CDATA[").append(schemeCode).append("]]>").append("</applicable_scheme>\r\n");
valueXmlString.append("<purchase_item_code>").append("<![CDATA[").append(itemValues).append("]]>").append("</purchase_item_code>\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code>\r\n");
valueXmlString.append("<item_descr>").append("<![CDATA[").append(itemDescription).append("]]>").append("</item_descr>\r\n");
valueXmlString.append("<scheme_descr>").append("<![CDATA[").append(schemeDescr).append("]]>").append("</scheme_descr>\r\n");
valueXmlString.append("<quantity>").append("<![CDATA[").append(freeQuantity).append("]]>").append("</quantity>\r\n");
valueXmlString.append("<discount>").append("<![CDATA[").append(discount).append("]]>").append("</discount>\r\n");
valueXmlString.append("<nature>").append("<![CDATA[").append(nature).append("]]>").append("</nature>\r\n");
valueXmlString.append("<rate>").append("<![CDATA[").append(0).append("]]>").append("</rate>\r\n");
valueXmlString.append("<item_code__ord>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code__ord>\r\n");
valueXmlString.append("</Detail>\r\n");
sql = " SELECT tran_id,"
+ "CASE WHEN item_code = 'X' THEN 'X' "
+" ELSE item_code end as item_code , SCHEME_CODE,SCHEME_TYPE, "
+" CASE WHEN item_code = 'X' THEN 'V' "
+" when item_code <> 'X' THEN 'I' END AS nature,"
+" CASE WHEN (BALANCE_FREE_VALUE - USED_FREE_VALUE > 0) THEN (BALANCE_FREE_VALUE - USED_FREE_VALUE ) "
+" WHEN ( balance_free_qty - USED_FREE_qty > 0 ) THEN ( balance_free_qty - USED_FREE_qty )"
+" END AS free_qty "
+" FROM SCHEME_BALANCE "
+" WHERE (BALANCE_FREE_VALUE - USED_FREE_VALUE > 0 or balance_free_qty - USED_FREE_qty > 0 ) "
+" and EFF_FROM <= ? AND VALID_UPTO >= ? "
+" AND CUST_CODE = ? and TRAN_ID = ? ";
pstmtIn = conn.prepareStatement(sql);
pstmtIn.setTimestamp(1, TranDateDet);
pstmtIn.setTimestamp(2, TranDateDet);
pstmtIn.setString(3,custCode);
pstmtIn.setString(4, tranID);
rs4 = pstmtIn.executeQuery();
while(rs4.next())
{
domID++;
System.out.println("DomId"+domID);
itemCode = rs4.getString("item_code");
schemeCode = rs4.getString("SCHEME_CODE");
schemeType = rs4.getString("SCHEME_TYPE");
nature = rs4.getString("nature");
freeQuantity =rs4.getDouble("free_qty");
valueXmlString.append("<Detail domId='"+(domID)+"'>\r\n");
System.out.println("Free Items "+itemCode);
itemDescription = getItemDescr(itemCode,conn);
valueXmlString.append("<scheme_type>").append("<![CDATA[").append(schemeType).append("]]>").append("</scheme_type>\r\n");
valueXmlString.append("<applicable_scheme>").append("<![CDATA[").append(schemeCode).append("]]>").append("</applicable_scheme>\r\n");
valueXmlString.append("<purchase_item_code>").append("<![CDATA[").append(itemValues).append("]]>").append("</purchase_item_code>\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code>\r\n");
valueXmlString.append("<item_descr>").append("<![CDATA[").append(itemDescription).append("]]>").append("</item_descr>\r\n");
valueXmlString.append("<scheme_descr>").append("<![CDATA[").append(schemeDescr).append("]]>").append("</scheme_descr>\r\n");
valueXmlString.append("<quantity>").append("<![CDATA[").append(freeQuantity).append("]]>").append("</quantity>\r\n");
valueXmlString.append("<discount>").append("<![CDATA[").append(discount).append("]]>").append("</discount>\r\n");
valueXmlString.append("<nature>").append("<![CDATA[").append(nature).append("]]>").append("</nature>\r\n");
valueXmlString.append("<rate>").append("<![CDATA[").append(0).append("]]>").append("</rate>\r\n");
valueXmlString.append("<item_code__ord>").append("<![CDATA[").append(itemCode).append("]]>").append("</item_code__ord>\r\n");
valueXmlString.append("</Detail>\r\n");
}
}
}
if("P".equalsIgnoreCase(freeBalOrd))//conditon of FREE_BAL_ORD added by nandkumar gadkari on 11/06/19
{
if(finalApplicableSchemeSet.size() > 0)
{
pointBaseSchemeXml=pointBaseScheme(dom,dom1,xtraParams,s,conn);
valueXmlString.append(pointBaseSchemeXml);
}
}
valueXmlString.append("</Root>\r\n");
/**
......@@ -1242,7 +1292,353 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
return stationTo;
}
//added by nandkumar gadkari on 12/06/19
public String pointBaseScheme(Document dom, Document dom1, String xtraParams,String s,Connection conn)
{
String sql = "",custCode="";
PreparedStatement pstmt = null,pstmt1 = null,pstmt2 = null, pstmt4=null,pstmt5=null;
ResultSet rs = null ,rs1 = null,rs2 = null,rs3 = null,rs4=null;
Node currDetail = null, headerNode = null;
StringBuffer valueXmlString = new StringBuffer();
String itmCode="",schemeCode = "",itemCodeOrd = "",schemeType="",saleOrder="",siteCode="",itemDescription="",schemeDescr="",dsp_date="",nature="",schemeCodePur="";
Timestamp orderDate=null;
double offerPoints=0,totalpoints=0,freePoints=0,reqPoints=0,availQty=0,unConfFreeQty=0,unconfreqPoints=0,unConfTotFreePoints=0,quantity=0,prvFreePoints=0;
int cnt=0,domID=0,len=0,noOfDetails=0;
String countCodeDlv="",stateCodeDlv="",schemeCodeList="",browItemCode="";
List<String> getSchemeList = new ArrayList<String>();
List<String> schemeList = new ArrayList<String>();
NodeList detailList = null;
String arrStr[] = null;
Iterator<String> itr = null;
try
{
headerNode = dom1.getElementsByTagName("Detail1").item(0);
custCode = checkNull(genericUtility.getColumnValueFromNode("cust_code", headerNode));
orderDate = Timestamp.valueOf(genericUtility.getValidDateString(
genericUtility.getColumnValueFromNode("due_date", headerNode),
genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat())
+ " 00:00:00.0");
siteCode = checkNull(genericUtility.getColumnValueFromNode("site_code", headerNode));
saleOrder = checkNull(genericUtility.getColumnValueFromNode("sale_order", headerNode));
stateCodeDlv = checkNull(genericUtility.getColumnValueFromNode("state_code__dlv", headerNode));
countCodeDlv = checkNull(genericUtility.getColumnValueFromNode("count_code__dlv", headerNode));
if(saleOrder.trim().length() == 0)
{
saleOrder=" ";
}
sql = "select distinct(scheme_code),item_code from sch_pur_items where item_code in ("+s+")";
System.out.println("sql ==="+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next())
{
schemeCodePur = rs.getString(1);
getSchemeList.add(schemeCodePur);
System.out.println("Applicable Scheme for Purchase Item Scheme Code ["+schemeCodePur+"]");
}
schemeCodeList = "";
itr = getSchemeList.iterator();
while(itr.hasNext())
{
schemeCodeList = schemeCodeList + "'"+(String) itr.next() + "'";
if(itr.hasNext())
{
schemeCodeList=schemeCodeList+ ",";
}
}
sql = "select distinct(a.scheme_code) from scheme_applicability a,scheme_applicability_det b"
+ " where a.scheme_code = b.scheme_code"
+ " and a.prod_sch = 'Y'"
+ " and a.app_from<= ?" + " and a.valid_upto>= ?"
+ " and (b.site_code=?"
+ " or b.state_code = ?" + " or b.count_code= ?) and a.scheme_code in ("+schemeCodeList+")";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setTimestamp(1, orderDate);
pstmt2.setTimestamp(2, orderDate);
pstmt2.setString(3, siteCode);
pstmt2.setString(4, stateCodeDlv);
pstmt2.setString(5, countCodeDlv);
rs2 = pstmt2.executeQuery();
while(rs2.next())
{
schemeCode = rs2.getString("scheme_code");
schemeList.add(schemeCode);
}
if(pstmt2 != null)
{
pstmt2.close();
pstmt2 = null;
}
if(rs2 != null)
{
rs2.close();
rs2 = null;
}
schemeCodeList="";
itr = schemeList.iterator();
/*while(itr.hasNext())
{
schemeCodeList = schemeCodeList + "'"+(String) itr.next() + "'"+",";
}
if(schemeCodeList != null && schemeCodeList.length() != 0)
{
schemeCodeList = schemeCodeList.substring(0,schemeCodeList.length()-1);
}*/
while(itr.hasNext())
{
schemeCodeList = schemeCodeList + "'"+(String) itr.next() + "'";
if(itr.hasNext())
{
schemeCodeList=schemeCodeList+ ",";
}
}
sql = "select scheme_code,descr,scheme_type from sch_group_def where scheme_code in ("+schemeCodeList+") and scheme_type = ?";
System.out.println("sql >> ["+sql+"]");
pstmt4 = conn.prepareStatement(sql);
pstmt4.setInt(1,3);
rs4 = pstmt4.executeQuery();
while(rs4.next())
{
schemeCode = rs4.getString("scheme_code");
schemeDescr = rs4.getString("descr");
schemeType = rs4.getString("scheme_type");
sql = " SELECT BALANCE_FREE_VALUE - USED_FREE_VALUE FROM SCHEME_BALANCE WHERE BALANCE_FREE_VALUE - USED_FREE_VALUE > 0 "
+ " AND CUST_CODE = ? AND ITEM_CODE= ? AND EFF_FROM <= ? AND VALID_UPTO >=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setString(2,"X");
pstmt.setTimestamp(3, orderDate);
pstmt.setTimestamp(4, orderDate);
rs = pstmt.executeQuery();
if (rs.next())
{
freePoints = rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(freePoints > 0)
{
sql = " select b.item_code__ord ,b.quantity " +
" from sorder a,sorddet b where a.sale_order = b.sale_order and a.site_code = ? "
+ " and a.cust_code = ? and a.sale_order <> ? and a.order_date between ? and ?"
+ " and (case when a.confirmed is null then 'N' else a.confirmed end )= 'N' and b.nature in ('P')";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, siteCode);
pstmt1.setString(2, custCode);
pstmt1.setString(3, saleOrder);
pstmt1.setTimestamp(4, orderDate);
pstmt1.setTimestamp(5, orderDate);
rs1 = pstmt1.executeQuery();
while (rs1.next()) {
itemCodeOrd=rs1.getString(1);
unConfFreeQty = rs1.getDouble(2);
System.out.println("unConfFreeQty" + unConfFreeQty);
sql = "select count (*) as cnt from SCH_OFFER_ITEMS where SCHEME_CODE =? and item_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, schemeCode);
pstmt.setString(2, itemCodeOrd);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt > 0)
{
sql = "select required_points from SCH_OFFER_ITEMS where SCHEME_CODE =? and item_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, schemeCode);
pstmt.setString(2, itemCodeOrd);
rs = pstmt.executeQuery();
if (rs.next())
{
unconfreqPoints = rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
unConfTotFreePoints = unConfTotFreePoints + (unConfFreeQty * unconfreqPoints);
}
}
pstmt1.close();
rs1.close();
pstmt1 = null;
rs1 = null;
freePoints= freePoints - unConfTotFreePoints;
detailList = dom1.getElementsByTagName("Detail2");
noOfDetails = detailList.getLength();
System.out.println("noOfDetails >>"+noOfDetails);
for(int ctr = 0; ctr < noOfDetails; ctr++)
{
currDetail = detailList.item(ctr);
browItemCode = checkNull(genericUtility.getColumnValueFromNode("item_code__ord", currDetail));
quantity = checkDoubleNull(genericUtility.getColumnValueFromNode("quantity", currDetail));
nature = checkNull(genericUtility.getColumnValueFromNode("nature", currDetail));
System.out.println("itemCode["+browItemCode+"]" + "quantity["+quantity+"]" + "siteCode["+siteCode+"]" + "nature["+nature+"]");
if (nature.equals("P")) {
sql = "select count (*) as cnt from SCH_OFFER_ITEMS where SCHEME_CODE =? and item_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, schemeCode);
pstmt.setString(2, browItemCode);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt > 0)
{
sql = "select required_points from SCH_OFFER_ITEMS where SCHEME_CODE =? and item_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, schemeCode);
pstmt.setString(2, browItemCode);
rs = pstmt.executeQuery();
if (rs.next())
{
unconfreqPoints = rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
prvFreePoints = prvFreePoints + quantity * unconfreqPoints;
}
}
}
freePoints= freePoints - prvFreePoints;
sql = "select item_code, required_points from SCH_OFFER_ITEMS where SCHEME_CODE =? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, schemeCode);
rs2 = pstmt2.executeQuery();
while (rs2.next())
{
if(freePoints > 0)
{
itemCodeOrd = rs2.getString(1);
reqPoints = rs2.getDouble(2);
sql="SELECT SUM(a.QUANTITY - a.ALLOC_QTY - CASE WHEN a.HOLD_QTY IS NULL THEN 0 ELSE a.HOLD_QTY END ) AVAIL_QTY "
+" FROM STOCK A, "
+"LOCATION B, "
+"INVSTAT C "
+"WHERE A.LOC_CODE = B.LOC_CODE "
+"AND B.INV_STAT = C.INV_STAT "
+"AND A.ITEM_CODE = ? "
+"AND A.SITE_CODE = ? "
+"AND C.AVAILABLE = 'Y' "
+"AND C.STAT_TYPE = 'M' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCodeOrd);
pstmt.setString(2, siteCode);
rs = pstmt.executeQuery();
if (rs.next())
{
availQty = rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(availQty <= 0)
{
continue;
}
quantity=integralPartQty(freePoints/reqPoints);
if(quantity <= 0)
{
continue;
}
domID++;
valueXmlString.append("<Detail domId='"+(domID)+"'>\r\n");
System.out.println("Free Items "+itemCodeOrd);
itemDescription = getItemDescr(itemCodeOrd,conn);
valueXmlString.append("<scheme_type>").append("<![CDATA[").append("Point Base Scheme").append("]]>").append("</scheme_type>\r\n");
valueXmlString.append("<applicable_scheme>").append("<![CDATA[").append(schemeCode).append("]]>").append("</applicable_scheme>\r\n");
valueXmlString.append("<purchase_item_code>").append("<![CDATA[").append(itemCodeOrd).append("]]>").append("</purchase_item_code>\r\n");
valueXmlString.append("<item_code>").append("<![CDATA[").append(itemCodeOrd).append("]]>").append("</item_code>\r\n");
valueXmlString.append("<item_descr>").append("<![CDATA[").append(itemDescription).append("]]>").append("</item_descr>\r\n");
valueXmlString.append("<scheme_descr>").append("<![CDATA[").append(schemeDescr).append("]]>").append("</scheme_descr>\r\n");
valueXmlString.append("<quantity>").append("<![CDATA[").append(quantity).append("]]>").append("</quantity>\r\n");
valueXmlString.append("<quantity__stduom>").append("<![CDATA[").append(quantity).append("]]>").append("</quantity__stduom>\r\n");
valueXmlString.append("<discount>").append("<![CDATA[").append(0).append("]]>").append("</discount>\r\n");
valueXmlString.append("<nature>").append("<![CDATA[").append("P").append("]]>").append("</nature>\r\n");
valueXmlString.append("<rate>").append("<![CDATA[").append(0).append("]]>").append("</rate>\r\n");
valueXmlString.append("<item_code__ord>").append("<![CDATA[").append(itemCodeOrd).append("]]>").append("</item_code__ord>\r\n");
valueXmlString.append("</Detail>\r\n");
}
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
}
}
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e);
}
return valueXmlString.toString();
}
private double integralPartQty(double value) {
double fractionalPart = value % 1;
double integralPart = value - fractionalPart;
System.out.println(integralPart +" integralPart "+ fractionalPart);
return integralPart;
}
private double checkDoubleNull(String str) {
if (str == null || str.trim().length() == 0) {
return 0.0;
} else {
return Double.parseDouble(str);
}
}
//added by nandkumar gadkari on 11/02/19------------------------end--------------------------------
}
\ 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