Commit 42e8e950 authored by pborate's avatar pborate

Updated ecmOrderDao.java and UserActivityDao.java

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@175961 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 36bed009
package proteus.ecm.hibernate.dao;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
......@@ -21,6 +21,7 @@ import org.hibernate.Session;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.quartz.impl.jdbcjobstore.SybaseDelegate;
import org.w3c.dom.Node;
import ibase.system.config.AppConnectParm;
......@@ -29,13 +30,17 @@ import ibase.utility.BaseException;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.dis.SalesOrderIC;
import ibase.webitm.utility.ITMException;
import proteus.ecm.cache.bean.ECMUserTracker;
import proteus.ecm.cache.dao.ProductCache;
import proteus.ecm.cache.dao.UserActivityCache;
import proteus.ecm.hibernate.bean.ECMOrder;
import proteus.ecm.hibernate.bean.EntityAddress;
import proteus.ecm.hibernate.bean.ItemDetails;
import proteus.ecm.hibernate.util.HibernateUtil;
import ibase.webitm.ejb.dis.*;
public class ECMOrderDAO {
......@@ -44,7 +49,10 @@ public class ECMOrderDAO {
private UserInfoBean userInfo = null;
private E12GenericUtility genericUtility = new E12GenericUtility();
ProductCache productCache = new ProductCache();
// ItemDetails itemDetail ;
private DistCommon distCommon=new DistCommon();
private SalesOrderIC salesOrderIc=new SalesOrderIC();
ProductDAO productDAO = new ProductDAO();
String siteCode = "";
......@@ -73,14 +81,14 @@ public class ECMOrderDAO {
return order;
}
public List<ECMOrder> getOrderList(String userid) {
public List<ECMOrder> getOrderList(String userid,String siteCode) {
List<ECMOrder> orderList = new ArrayList<ECMOrder>();
try {
System.out.println("Inside get order list try" +userid);
System.out.println("Inside get order list try [" +userid+"] site code ["+siteCode+"]");
// 1. Get Session object
Session session = HibernateUtil.getSessionFactory(siteTranDB).openSession();
// 2. Create Query
Query query = session.createQuery("from ECMOrder where userId='"+ userid+"' order by orderNo");
Query query = session.createQuery("from ECMOrder where userId='"+ userid+"' AND ecmSite='"+ siteCode+ "' order by orderNo");
List<ECMOrder> ordersList = query.getResultList();
......@@ -102,7 +110,6 @@ public class ECMOrderDAO {
System.out.println("Inside save Order Dao data is" +data);
String returnString ;
String result="";
JSONObject orderJsonObj = new JSONObject();
ECMUserTracker userBean = userActivityCache.getCachedUserData(uniqueId, cacheName);
System.out.println("inside save order userbean>" + userBean );
if( userBean != null ) {
......@@ -110,13 +117,11 @@ public class ECMOrderDAO {
Map<String, String> cartMap = userBean.getCartProducts();
System.out.println("Inside getCartItem > cartMap >" + cartMap );
returnString = "Success";
try
{
returnString = getXMLString("ecm_order", requestData, cartMap,cacheName);
returnString = getXMLString("ecm_order", requestData, siteCode,cartMap,cacheName);
System.out.println("returnString json " +returnString);
//returnString = genericUtility.jsonToXMLString( returnString );
System.out.println("returnString " +returnString);
result = checkNull( processRequest( returnString, contexObject ) );
}
catch (ITMException e) {
......@@ -132,14 +137,44 @@ public class ECMOrderDAO {
System.out.println(" Exception saveOrder :");
e.printStackTrace();
}
System.out.println("After orderJsonObj " + orderJsonObj + "\n returnString >> " + result);
System.out.println("After orderJsonObj \n returnString >> " + result);
}
else {
result = "Invalid";
}
return result;
}
// Added By PriyankaB on start
public double getsalesRate(String siteCode, String itemCode,String custCode) throws BaseException, Exception{
Connection conn = null;
String transDB = getUserInfo().getTransDB();
ConnDriver connDriver = new ConnDriver();
if( checkNull( transDB ).length() > 0 )
{
System.out.println("Inside processRequest transDB ");
conn = connDriver.getConnectDB( transDB );
}
else
{
System.out.println("Inside processRequest transDB else");
conn = connDriver.getConnectDB( "DriverITM" );
}
Timestamp orderDt = new Timestamp(System.currentTimeMillis());
System.out.println("Inside get Sales Price List orderDt:"+orderDt);
String ContractNo = salesOrderIc.getContract(siteCode, custCode, orderDt, itemCode, "", "", conn);
String orderDate = genericUtility.getValidDateString(new Date(), genericUtility.getApplDateFormat() );
String ldtDateStr = orderDate;
String mOrderDateStr =orderDate;
System.out.println("Inside get Sales Price List ContNo:"+ContractNo);
String lsContractNo=ContractNo;
String pricelist= distCommon.getSalesPriceList(custCode, custCode, siteCode, ContractNo, itemCode, orderDate, conn);
double SalesRate =distCommon.getSalesRate(pricelist, siteCode, custCode, mOrderDateStr, ldtDateStr, "C", ContractNo, lsContractNo, itemCode, 0.0, conn);
System.out.println("In Order DAO SalesRate[ " +SalesRate+"]");
return SalesRate;
}
// Added By PriyankaB on end
private JSONObject createDocumentJSON() {
JSONObject rootObj = new JSONObject();
......@@ -169,7 +204,6 @@ public class ECMOrderDAO {
System.out.println("createDocumentJSON" + rootObj);
return rootObj;
}
/*From E12ExtService processRequest, addFollowUpAction*/
private String processRequest( String xmlString, Object contexObject ) throws ITMException
......@@ -345,7 +379,8 @@ public class ECMOrderDAO {
return ctx;
}
private String getXMLString(String objName, JSONObject requestData, Map<String, String> cartMap, String cacheName) throws ITMException, BaseException, Exception{
// Added By PriyankaB on start
private String getXMLString(String objName, JSONObject requestData,String siteCode, Map<String, String> cartMap, String cacheName) throws ITMException, BaseException, Exception{
StringBuffer finalXML = new StringBuffer();
finalXML.append("<DocumentRoot>");
finalXML.append("<description>Datawindow Root</description>");
......@@ -371,7 +406,7 @@ public class ECMOrderDAO {
// updateFlag="E" />
// </Detail1>
finalXML.append( getDetail1XML(objName, requestData,cartMap, cacheName) );
finalXML.append( getDetail1XML(objName, requestData,siteCode, cartMap, cacheName) );
finalXML.append( getDetail2XML(objName, requestData,cartMap, cacheName) );
finalXML.append("</Header0>");
......@@ -381,68 +416,103 @@ public class ECMOrderDAO {
return finalXML.toString();
}
private String getDetail1XML(String objName, JSONObject requestData, Map<String, String> cartMap, String cacheName ) throws ITMException, BaseException, Exception
private String getDetail1XML(String objName, JSONObject requestData, String siteCode, Map<String, String> cartMap, String cacheName ) throws ITMException, BaseException, Exception
{
StringBuffer detailBuff = new StringBuffer();
String ecm_type =requestData.getString("ecm_type");
System.out.println("getDetail1XML cart map data [" + cartMap +"] ecm_type :" +ecm_type);
System.out.println("cartMap.size() getDetail1XML" + cartMap.size());
System.out.println("In getDetail1XML cartMap.size" + cartMap.size());
List<String > keySet=new ArrayList<String>( cartMap.keySet());
System.out.println("cartMap.keySet() getDetail1XML" + keySet);
System.out.println("In getDetail1XML keySet" + keySet);
int idx = 0;
double orderAmount = 0;
double orderDiscAmount = 0;
double orderNetAmount = 0;
System.out.println("cartMap.keySet() getDetail1XML requestData" + requestData);
JSONObject billAddress = new JSONObject();
billAddress=requestData.getJSONObject("billAddress");
System.out.println("cartMap.keySet() getDetail1XML billAddress" + billAddress);
String addr1 = billAddress.getString("addr1");
String addr2 = billAddress.getString("addr2");
String addr3 = billAddress.getString("addr3");
String countDescr = billAddress.getString("countDescr");
String stateDescr = billAddress.getString("stateDescr");
String pinCode = billAddress.getString("pinCode");
String city = billAddress.getString("city");
String addrUse = billAddress.getString("addrUse");
System.out.println("cartMap.keySet() getDetail1XML addrUse" + addrUse);
String addr1;
String addr2 ;
String addr3 ;
String countDescr;
String stateDescr ;
String pinCode;
String city ;
String dlvAdd ="";
//String billAdd=addr1.concat(addr2).concat(addr3).concat(city).concat(countDescr).concat(stateDescr).concat(pinCode);
String billAdd=addr1+" "+addr2+" "+addr3+" "+city+" " +countDescr+" "+stateDescr+" "+pinCode;
char addrUsed=addrUse.charAt(0);
if(addrUsed=='D')
{
System.out.println("getDetail1XML addrUse in if" + addrUse);
dlvAdd=billAdd;
billAdd="";
System.out.println("getDetail1XML dlvAdd in if" + dlvAdd);
}
else if(addrUsed=='A'){
dlvAdd=billAdd;
String billAdd ="";
String address="";
System.out.println("In getDetail1XML requestData" + requestData);
char ecmType = ecm_type.charAt(0);
if(ecmType=='2') {
System.out.println("Inside getDetail1XML Sale Address");
JSONObject saleAddress = new JSONObject();
saleAddress=requestData.getJSONObject("saleAddress");
System.out.println("Inside getDetail1XML Sale Address" + saleAddress);
JSONObject billTo = new JSONObject();
billTo=saleAddress.getJSONObject("billTo");
JSONObject billToAddress = new JSONObject();
billToAddress=billTo.getJSONObject("address");
addr1 = billToAddress.getString("addr1");
addr2 = billToAddress.getString("addr2");
addr3 = billToAddress.getString("addr3");
countDescr = billToAddress.getString("countDescr");
stateDescr = billToAddress.getString("stateDescr");
pinCode = billToAddress.getString("pinCode");
city = billToAddress.getString("city");
billAdd=addr1+" "+addr2+" "+addr3+" "+city+" " +countDescr+" "+stateDescr+" "+pinCode;
System.out.println("Inside getDetail1XML billAdd" + billAdd);
JSONObject deliverTo = new JSONObject();
deliverTo=saleAddress.getJSONObject("deliverTo");
JSONObject dlvToAddress = new JSONObject();
dlvToAddress=deliverTo.getJSONObject("address");
addr1 = dlvToAddress.getString("addr1");
addr2 = dlvToAddress.getString("addr2");
addr3 = dlvToAddress.getString("addr3");
countDescr = dlvToAddress.getString("countDescr");
stateDescr = dlvToAddress.getString("stateDescr");
pinCode = dlvToAddress.getString("pinCode");
city = dlvToAddress.getString("city");
dlvAdd=addr1+" "+addr2+" "+addr3+" "+city+" " +countDescr+" "+stateDescr+" "+pinCode;
System.out.println("Inside getDetail1XML dlvAdd" + dlvAdd);
} // for sales catalog category
else{
JSONObject billAddress = new JSONObject();
billAddress=requestData.getJSONObject("billAddress");
System.out.println("In getDetail1XML billAddress" + billAddress);
addr1 = billAddress.getString("addr1");
addr2 = billAddress.getString("addr2");
addr3 = billAddress.getString("addr3");
countDescr = billAddress.getString("countDescr");
stateDescr = billAddress.getString("stateDescr");
pinCode = billAddress.getString("pinCode");
city = billAddress.getString("city");
String addrUse = billAddress.getString("addrUse");
System.out.println("cartMap.keySet() getDetail1XML addrUse" + addrUse);
address=addr1+" "+addr2+" "+addr3+" "+city+" " +countDescr+" "+stateDescr+" "+pinCode;
char addrUsed=addrUse.charAt(0);
if(addrUsed=='D') {
dlvAdd=address;
System.out.println("getDetail1XML dlvAdd in if" + addrUsed);
}//if(address is Delivery Address)
else if(addrUsed=='B'){
billAdd=address;
System.out.println("getDetail1XML dlvAdd in if" + addrUsed);
}//if(address is Billing Address)
else {
dlvAdd=address;
billAdd=address;
System.out.println("getDetail1XML dlvAdd in if" + addrUsed);
}//if(address is both delivery and billing Address)
}
JSONArray orderedItems = new JSONArray();
orderedItems=requestData.getJSONArray("orderedItems");
int itemQuantity=0;
System.out.println("cartMap.keySet() getDetail1XML orderedItems" + orderedItems);
// for(int i = 0; i < orderedItems.length(); i++){
// JSONObject jsonObj = orderedItems.getJSONObject(i);
// itemQuantity = jsonObj.getInt("itemQuantity");
// System.out.println("cartMap.keySet() getDetail1XML itemQuantity" + itemQuantity);
// }
// for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
for(int i = 0; i < orderedItems.length(); i++){
JSONObject jsonObj = orderedItems.getJSONObject(i);
itemQuantity = jsonObj.getInt("itemQuantity");
System.out.println("cartMap.keySet() getDetail1XML itemQuantity" + itemQuantity);
String itemCode = jsonObj.getString("itemCode");
System.out.println("cartMap.keySet() getDetail1XML itemQuantity" + itemCode);
ItemDetails itemDetail = productCache.getCachedItemDetail(itemCode, cacheName);
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
String itemCode = (String) iterator.next();
int itemQuantity = Integer.parseInt(cartMap.get(itemCode));
System.out.println("item_Detail in getDetail2XML quantity[" + itemQuantity + "]");
System.out.println("item_Detail in getDetail2XML index [" +idx +"] itemCode[" + itemCode + "]");
ItemDetails itemDetail = productCache.getCachedItemDetail(itemCode, cacheName);
if( itemDetail == null )
{
productDAO.prepareItemDetails(cacheName, siteCode, itemCode);
......@@ -450,9 +520,10 @@ public class ECMOrderDAO {
}
JSONObject itemHeader = new JSONObject(itemDetail.getItemHeader());
System.out.println("itemHeader.getDouble(itemCostRate) [" + itemHeader.getDouble("itemCostRate") +"] and discountrate [" + itemHeader.getDouble("itemDiscountedRate") +"]");
orderAmount =orderAmount + (itemHeader.getDouble("itemCostRate") * itemQuantity );
orderNetAmount =orderNetAmount + (itemHeader.getDouble("itemDiscountedRate") * itemQuantity ) ;
orderDiscAmount =orderAmount-orderNetAmount;
orderAmount =orderAmount + (itemHeader.getDouble("itemCostRate") * itemQuantity ); // Total Amount of Items [Sum of RATE multiply with QUANTITY of ecm_order_det]
orderNetAmount =orderNetAmount + (itemHeader.getDouble("itemDiscountedRate") * itemQuantity ) ; // Total Amount of Items - Total Discount Amount [Multiply with QUANTITY of ecm_order_det]
orderDiscAmount =orderAmount-orderNetAmount; // Total Discount Amount of Items
idx++;
}
System.out.println("orderAmount" + orderAmount);
System.out.println("orderDiscAmount" + orderDiscAmount);
......@@ -462,7 +533,7 @@ public class ECMOrderDAO {
detailBuff.append("<attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\" />");
detailBuff.append("<eorder_no>").append("<![CDATA[]]>").append("</eorder_no>");
detailBuff.append("<user_id>").append("<![CDATA[" + userInfo.getLoginCode() + "]]>").append("</user_id>");
detailBuff.append("<ecm_site>").append("<![CDATA[" + userInfo.getSiteCode() + "]]>").append("</ecm_site>");
detailBuff.append("<ecm_site>").append("<![CDATA[" + siteCode + "]]>").append("</ecm_site>");
detailBuff.append("<curr_code>").append("<![CDATA[INR]]>").append("</curr_code>");
detailBuff.append("<exch_rate>").append("<![CDATA[1]]>").append("</exch_rate>");
detailBuff.append("<order_date>").append("<![CDATA[ " + genericUtility.getValidDateString(new Date(), genericUtility.getApplDateFormat() ) +"]]>").append("</order_date>");
......@@ -514,17 +585,14 @@ public class ECMOrderDAO {
System.out.println("cartMap.keySet()" + keySet);
int idx = 0;
JSONArray orderedItems = new JSONArray();
orderedItems=requestData.getJSONArray("orderedItems");
int quantity=0;
System.out.println("cartMap.keySet() getDetail1XML orderedItems" + orderedItems);
for(int i = 0; i < orderedItems.length(); i++){
JSONObject jsonObj = orderedItems.getJSONObject(i);
String itemCode = jsonObj.getString("itemCode");
System.out.println("cartMap.keySet() getDetail1XML itemQuantity" + itemCode);
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
String itemCode = (String) iterator.next();
String lineNo = (idx+1) + "";
quantity = jsonObj.getInt("itemQuantity");
double netAmount ;
int quantity = Integer.parseInt(cartMap.get(itemCode));
System.out.println("item_Detail in getDetail2XML quantity[" + quantity + "]");
System.out.println("item_Detail in getDetail2XML index [" +idx +"] itemCode[" + itemCode + "]");
double netAmount ;
ItemDetails itemDetail = productCache.getCachedItemDetail(itemCode, cacheName);
if( itemDetail == null )
......@@ -532,15 +600,10 @@ public class ECMOrderDAO {
productDAO.prepareItemDetails(cacheName, siteCode, itemCode);
itemDetail = productCache.getCachedItemDetail(itemCode, cacheName);
}
JSONObject itemHeader = new JSONObject(itemDetail.getItemHeader());
//rate=itemHeader.getDouble("itemCostRate") * quantity;
netAmount=itemHeader.getDouble("itemDiscountedRate") * quantity;
//discount=rate - netAmount;
netAmount=itemHeader.getDouble("itemDiscountedRate") * quantity; // Rate of an Item - Discount % available on an Item [Multiply with QUANTITY]
System.out.println("itemHeader.getDouble(itemCostRate) in detail2 [" + itemHeader.getDouble("itemCostRate") +"] and discountrate [" + itemHeader.getDouble("itemDiscountedRate") +"]");
System.out.println("item_Detail in getDetail2XML netAmount[" + netAmount + "]");
System.out.println("item_Detail in getDetail2XML quantity[" + quantity + "]");
System.out.println("item_Detail in getDetail2XML index [" +idx +"] itemCode[" + itemCode + "] itemDetail : [" + itemDetail +"] ");
detailBuff.append("<Detail2 dbID=\"\" domID=\"" + lineNo + "\" objContext=\"2\" objName=\"" + objName + "\" >");
detailBuff.append("<attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\" />");
......@@ -569,12 +632,11 @@ public class ECMOrderDAO {
}
return detailBuff.toString();
}
// Added By PriyankaB on end
/*chitranga */
public String getCustomerList(String userType, String entityCode ,String siteCode) {
Statement stmt = null;
Connection conn = null;
String sql = null;
......
......@@ -618,10 +618,19 @@ public class UserActivityDAO {
userProfile = userList.get(0);
Date birthDate = userProfile.getBirthDate();
String birthDateStr = HibernateUtil.getValidDB2APPLDate(birthDate.toString());
System.out.println("B4 birthDate[" + birthDate + "]");
if(birthDate==null)
{
String birthDateDefault = "No birth date available";
birthDate = HibernateUtil.getDateObject(birthDateDefault, HibernateUtil.APPL_DATE_FORMAT);
System.out.println("After birthDate[" + birthDateDefault + "] birth date ["+birthDate+"]");
}
else{
String birthDateStr = HibernateUtil.getValidDB2APPLDate(birthDate.toString());
birthDate = HibernateUtil.getDateObject(birthDateStr, HibernateUtil.APPL_DATE_FORMAT);
System.out.println("After birthDate[" + birthDate + "]");
System.out.println("After birthDate[" + birthDateStr + "] birthDate ["+birthDate+"]");
}
userProfile.setBirthDate(birthDate);
String uName = userProfile.getUserName();
......
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