Commit 85498f0a authored by ssalve's avatar ssalve

Sarita : Added method for scheme

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@176922 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e5e4001c
package ibase.webitm.ejb.dis.adv;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.*;
import org.w3c.dom.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ejb.*;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
// added for ejb3
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.utility.E12GenericUtility;
import ibase.system.config.*;
import javax.ejb.Stateless; // added for ejb3
@Stateless // added for ejb3
public class SorderAct extends ActionHandlerEJB implements SorderActLocal, SorderActRemote
{
E12GenericUtility genericUtility= new E12GenericUtility();
/*public void ejbCreate() throws RemoteException, CreateException
{
}
......@@ -152,4 +166,390 @@ public class SorderAct extends ActionHandlerEJB implements SorderActLocal, Sorde
System.out.println("valueXmlString.toString() "+valueXmlString.toString());
return valueXmlString.toString();
}
@Override
//Added by sarita on 21/12/2017
public String getFreeSchemeaction(String actionType, String xmlString, String xmlString1, String objContext, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
//Document selDataDom = null;
String retString = null;
try
{
System.out.println("xmlString :::"+xmlString);
System.out.println("xmlString1 :::"+xmlString1);
if(xmlString != null && xmlString.trim().length()!=0)
{
dom = new ibase.utility.E12GenericUtility().parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length()!=0)
{
dom1 = new ibase.utility.E12GenericUtility().parseString(xmlString1);
}
/*if(selDataStr != null && selDataStr.length() > 0)
{
selDataDom = new ibase.utility.E12GenericUtility().parseString(selDataStr);
}*/
System.out.println("actionType:"+actionType+":");
if (actionType.equalsIgnoreCase("sorderScheme"))
{
retString = getFreeSchemeaction(dom, dom1, objContext, xtraParams);
}
}
catch(Exception e)
{
System.out.println("Exception :Porcp :actionHandlerTransform(String xmlString):" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("returning String from Porcp : actionHandlerTransform"+retString);
return retString;
}
@Override
//Added by sarita on 21/03/2017
public String getFreeSchemeaction(Document dom, Document dom1,String objContext, String xtraParams)throws ITMException
{
System.out.println("getFreeSchemeAction is calling.............");
StringBuffer valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n");
String sql = "";
String detCnt = "0";
int noOfDetails = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int count = 0;
String itemCode = "",schemeCode = "",itemDescription="",updateFlag="";
NodeList detailList = null;
Node currDetail = null;
String itmCode="",s = "",s1 = "",quantity="",schemeType="",schAllowence="";
double qty = 0.0;
double purcBase=0.0;
double schAllowence1=0.0;
Iterator<String> itr = null;
List<String> itemList = new ArrayList<String>();
List<String> getSchemeList = new ArrayList<String>();
HashMap<String,Double> itemQuantityMap = new HashMap<String,Double>();
HashMap<String,List<String>> getSchemeItemList = new HashMap<String,List<String>>();
HashMap<String,List<String>> freeItemInfoMap = new HashMap<String,List<String>>();
List<String> schemeInfo = null;
try
{
conn = getConnection();
detailList = dom1.getElementsByTagName("Detail2");
noOfDetails = detailList.getLength();
//updateFlag = getAttributeVal(dom1,"updateFlag");
System.out.println("noOfDetails >>"+noOfDetails);
for(int ctr = 0; ctr < noOfDetails; ctr++)
{
currDetail = detailList.item(ctr);
itemCode = genericUtility.getColumnValueFromNode("item_code__ord", currDetail);
quantity = genericUtility.getColumnValueFromNode("quantity", currDetail);
qty = Double.valueOf(quantity);
itemList.add(itemCode);
if(itemQuantityMap.containsKey(itemCode))
{
if(quantity != null)
{
qty = qty + Double.valueOf(itemQuantityMap.get(itemCode));
}
itemQuantityMap.put(itemCode.trim(), qty);
}
else
{
itemQuantityMap.put(itemCode.trim(), qty);
}
}
itr = itemList.iterator();
while(itr.hasNext())
{
s = s + "'"+(String) itr.next() + "'"+",";
}
if(s != null && s.length() != 0)
{
s = s.substring(0,s.length()-1);
}
System.out.println("s :::::::::"+s);
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())
{
schemeCode = rs.getString("scheme_code");
getSchemeList.add(schemeCode);
itmCode = rs.getString("item_code");
//System.out.println("schemeCode["+schemeCode+"]" + "itmCode["+itmCode+"]" + "\t");
if(getSchemeItemList.containsKey(schemeCode))
{
//System.out.println("Inside 1");
schemeInfo = getSchemeItemList.get(schemeCode);
schemeInfo.add(itmCode.trim());
getSchemeItemList.put(schemeCode,schemeInfo);
}
else
{
//System.out.println("Inside 2");
schemeInfo = new ArrayList<String>();
schemeInfo.add(itmCode.trim());
System.out.println("schemeInfo1"+schemeInfo);
getSchemeItemList.put(schemeCode,schemeInfo);
}
System.out.println("getSchemeItemList:::"+getSchemeItemList);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
itr = getSchemeList.iterator();
while(itr.hasNext())
{
s1 = s1 + "'"+(String) itr.next() + "'"+",";
}
//System.out.println("s1 is "+s1);
if(s1 != null && s1.length() != 0)
{
s1 = s1.substring(0,s1.length()-1);
// System.out.println("s1 is "+s1);
}
//Working on Scheme Applicability...
System.out.println("Scheme Applicability...."+getSchemeItemList.size());
if(getSchemeItemList.size() > 0)
{
sql = "select scheme_code,scheme_type,purc_base,sch_allowence from sch_group_def where scheme_code in ("+s1+")";
System.out.println("sql >> ["+sql+"]");
pstmt = conn.prepareStatement(sql);
//pstmt.setString(1,s1);
rs = pstmt.executeQuery();
while(rs.next())
{
schemeCode = rs.getString("scheme_code");
schemeType = rs.getString("scheme_type");
purcBase = Double.valueOf(rs.getString("purc_base"));
schAllowence1= Double.valueOf(rs.getString("sch_allowence"));
System.out.println("schemeType ["+schemeType+"]" + "schemeCode ["+schemeCode+"]" + "purcBase ["+purcBase+"]" +"schAllowence1 ["+schAllowence1+"]");
if("0".equalsIgnoreCase(schemeType))
{
//System.out.println("Scheme Type in O applicable on quantity");
List<String> itemCodeListScheme = new ArrayList<String>();
itemCodeListScheme = getSchemeItemList.get(schemeCode);
System.out.println("itemCodeListScheme **"+itemCodeListScheme.size());
if(itemCodeListScheme.size() > 0)
{
for(int cntr=0; cntr<itemCodeListScheme.size();cntr++)
{
List<String> freeItemList = new ArrayList<String>();
String itemCodeSchm = itemCodeListScheme.get(cntr);
System.out.println("itemCodeSchm ::::"+itemCodeSchm);
if(itemQuantityMap.containsKey(itemCodeSchm))
{
double xmlQty = itemQuantityMap.get(itemCodeSchm);
// System.out.println("xmlQty is==="+xmlQty);
if(xmlQty >= purcBase)
{
double freeQty = ((xmlQty * schAllowence1)/purcBase);
System.out.println("Items Applicable for Free Schemes :::"+itemCodeSchm + "free quantity"+(int)freeQty);
sql = "SELECT S.item_code FROM SCH_PUR_ITEMS P ,SCH_OFFER_ITEMS S WHERE P.SCHEME_CODE=S.SCHEME_CODE AND P.ITEM_CODE='"+itemCodeSchm+"'";
System.out.println("sql :::::"+sql);
pstmt = conn.prepareStatement(sql);
//pstmt.setString(1,itemCodeSchm);
rs = pstmt.executeQuery();
while(rs.next())
{
String freeItem = rs.getString("item_code");
freeItemList.add(freeItem);
freeItemInfoMap.put(itemCodeSchm, freeItemList);
}
List finalFreeItems = freeItemInfoMap.get(itemCodeSchm);
System.out.println("finalFreeItems :::"+finalFreeItems);
System.out.println("finalFreeItems :::"+finalFreeItems.size());
if(finalFreeItems.size() > 0)
{
for(int cnt = 0;cnt<finalFreeItems.size();cnt++)
{
System.out.println(finalFreeItems.get(cnt));
itemDescription = getItemDescr((String)finalFreeItems.get(cnt),conn);
valueXmlString.append("<Detail>\r\n");
valueXmlString.append("<item_code__ord>").append("<![CDATA[").append(finalFreeItems.get(cnt)).append("]]>").append("</item_code__ord>\r\n");
valueXmlString.append("<item_descr>").append("<![CDATA[").append(itemDescription).append("]]>").append("</item_descr>\r\n");
valueXmlString.append("<quantity protect=\"0\">").append("<![CDATA[]]>").append("</quantity>\r\n");
valueXmlString.append("</Detail>\r\n");
}
}
/*valueXmlString.append("<Detail1>\r\n");
for(int cnt = 0;cnt<freeItemInfoMap.size();cnt++)
{
System.out.println(freeItemInfoMap.get(cnt));
valueXmlString.append("<free_item>").append("<![CDATA[").append(freeItemInfoMap.get(cnt)).append("]]>").append("</free_item>\r\n");
}
valueXmlString.append("<Detail1>\r\n");
System.out.println("Final List for Items :::"+freeItemInfoMap);*/
}
else
{
System.out.println("Scheme is NOT applicable for ::"+itemCodeSchm + "Purchased Item quantity::"+xmlQty +"is greater NOT than or equal to applicable quantity"+purcBase+"for scheme "+schemeCode);
}
}
else
{
System.out.println(itemCodeSchm + "Not contains in XML File");
}
}
}
}
}
}
valueXmlString.append("</Root>\r\n");
}
catch(Exception e)
{
System.out.println("Exception : Sorder : getFreeSchemeAction " +e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception ex)
{
System.out.println("Finally Exception : "+ex.getMessage());
ex.printStackTrace();
}
}
return valueXmlString.toString();
}
public String getItemDescr(String itemCode , Connection conn)
{
String descr = "",sql="";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
conn = getConnection();
sql = "select descr from item where item_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
descr = rs.getString("descr");
System.out.println("Item Description is :::::::::::::"+descr);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception ex)
{
System.out.println("Finally Exception : "+ex.getMessage());
ex.printStackTrace();
}
}
return descr;
}
public String getAttributeVal(Node dom, String attribName )throws ITMException
{
String AttribValue = null;
try
{
NodeList detailList = dom.getChildNodes();
int detListLength = detailList.getLength();
for(int ctr = 0; ctr < detListLength; ctr++)
{
Node curDetail = detailList.item(ctr);
if(curDetail.getNodeName().equals("attribute"))
{
AttribValue = curDetail.getAttributes().getNamedItem(attribName).getNodeValue();
break;
}
else
{
continue;
}
}
}
catch (Exception e)
{
System.out.println("Exception : : searchNode :"+e);
throw new ITMException(e);
}
return AttribValue;
}
}
\ 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