Commit 9e00d47d authored by sjarande's avatar sjarande

ES3 source files merged in head from cvs branch 5-12-146-5

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@165263 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 0181e987
package ibase.webitm.ejb.dis;
/**
* @author Saurabh Jarande[19/07/17]
* This component is used for validating AWACS process.
*
*/
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class AwacsToES3IC extends ValidatorEJB implements AwacsToES3ICRemote,AwacsToES3ICLocal {
E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{
System.out.println("In wfValData");
Document currDom = null, hdrDom = null, allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = validate(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+"[wfValData] : ==>\n" + e.getMessage());
}
return errString;
}
public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
System.out.println("In validate Data");
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
int noOfChilds = 0, currentFormNo = 0, cnt = 0, prdCnt=0, invDivisionCnt=0 , custCnt=0 , genCnt=0 , awcsCnt=0 , orgCustCnt=0 , orgCustCnt1 =0;
String errString = "",errorType = "",errCode = "", childNodeName = "", custCode="",prdCode="",sql="",prdTblNo="";
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
ConnDriver connDriver = null;
Node childNode = null;
ArrayList <String> opPrdList = new ArrayList<String>();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
try
{
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("************xtraParams*************" + xtraParams);
String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("**************loginCode************" + userId);
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail"+ currentFormNo);
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if ("prd_code".equalsIgnoreCase(childNodeName) )
{
prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(prdCode==null || prdCode.trim().length()==0)
{
errList.add("VMNULLPRD");//Invalid-Period can not be blank
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) AS COUNT FROM PERIOD WHERE CODE=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode);
rs = pstmt.executeQuery();
if (rs.next())
{
prdCnt = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(prdCnt == 0)
{
errList.add("VMINVPRD");//INVALID PRD CODE
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT SUBSTR(PRD_TBLNO,5,10) AS ITEM_SER FROM PERIOD_TBL WHERE PRD_CODE=? AND PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode);
rs = pstmt.executeQuery();
while (rs.next())
{
prdTblNo = rs.getString(1);
opPrdList.add(prdTblNo);
invDivisionCnt++;
}
callPstRs(pstmt, rs);
if(invDivisionCnt > 0)
{
errList.add("VMINVPRDCL");//Closed division
errFields.add(childNodeName.toLowerCase());
//break;
}
}
}
}
if ("cust_code".equalsIgnoreCase(childNodeName) )
{
custCode = checkNull(genericUtility.getColumnValue("cust_code", currDom));
prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(custCode==null || custCode.trim().length()==0)
{
errList.add("VPBLKCUSCD");//Invalid-Customer code can not be blank
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
custCnt = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(custCnt == 0)
{
//INVALID CUSTOMER
errList.add("VPINVCSCDM");
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) FROM ORG_STRUCTURE_CUST WHERE CUST_CODE=? AND VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
orgCustCnt = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(orgCustCnt==0)
{
// does not exist
errList.add("VPINVCSOG");
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) FROM ORG_STRUCTURE_CUST WHERE CUST_CODE=? AND VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) and source = 'A' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
orgCustCnt1 = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(orgCustCnt1 == 0 )
{
//not awacs cust
errList.add("VPINVCSOGA");
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) FROM CUST_STOCK WHERE CUST_CODE=? AND PRD_CODE=? AND POS_CODE IS NULL AND CONFIRMED = 'Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setString(2,prdCode);
rs = pstmt.executeQuery();
if (rs.next())
{
awcsCnt = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(awcsCnt == 0)
{
//transactions already created
errList.add("VTNULLRCD");
errFields.add(childNodeName.toLowerCase());
//break;
}
else
{
sql=" SELECT COUNT(*) FROM CUST_STOCK WHERE CUST_CODE=? AND PRD_CODE=? AND POS_CODE IS NOT NULL ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setString(2,prdCode);
rs = pstmt.executeQuery();
if (rs.next())
{
genCnt = rs.getInt(1);
}
callPstRs(pstmt, rs);
if(genCnt > 0)
{
//transactions already created
errList.add("VPINVCSCDA");
errFields.add(childNodeName.toLowerCase());
//break;
}
}
}
}
}
}
}
}
}
break;
}
int errListSize = errList.size();
cnt = 0;
String errFldName = "";
if ((errList != null) && (errListSize > 0))
{
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String) errList.get(cnt);
errFldName = (String) errFields.get(cnt);
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
if(opPrdList.size()>0 && errString.length() > 0 )
{
String begPart = errString.substring( 0, errString.indexOf("]]></description>") );
String mainStr="";
for(int i=0;i<opPrdList.size();i++)
{
mainStr=mainStr+ opPrdList.get(i)+",";
}
String endPart=errString.substring( errString.indexOf("]]></description>"), errString.length() );
mainStr=" Following Divisions are closed :: "+mainStr.substring(0,mainStr.length()-1);
errString = begPart+mainStr + endPart;
}
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........." + errStringXml);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer("");
}
errString = errStringXml.toString();
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >"+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
callPstRs(pstmt, rs);
if (conn != null && !conn.isClosed())
{
conn.close();
}
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String checkNull(String inputVal)
{
try{
inputVal = inputVal==null? "" : inputVal.trim();
}catch(Exception e){
e.printStackTrace();
}
return inputVal;
}
private String errorType(Connection conn, String errorCode)
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next()){
msgType = rs.getString("MSG_TYPE");
}
callPstRs(pstmt, rs);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return msgType;
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface AwacsToES3ICLocal
{
public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface AwacsToES3ICRemote {
public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException;
}
package ibase.webitm.ejb.dis;
/**
* @author Saurabh Jarande[19/07/17]
* This component is used for creating ES3 transactions from AWACS data uploaded by CFA.
*
*/
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterDataStatefulLocal;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.dis.adv.CustStockGWTConf;
import ibase.webitm.utility.ITMException;
import java.io.File;
import java.io.FileWriter;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class AwacsToES3Prc extends ProcessEJB implements AwacsToES3PrcLocal,AwacsToES3PrcRemote {
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null, headerDom = null;
String retStr = "";
System.out.println("windowName[process]::::::::::;;;" + windowName);
System.out.println("xtraParams[process]:::::::::;;;" + xtraParams);
try
{
System.out.println("xmlString[process]::::::::::;;;" + xmlString);
if (xmlString != null && xmlString.trim().length() != 0)
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom" + headerDom);
}
System.out.println("xmlString2[process]::::::::::;;;" + xmlString2);
if (xmlString2 != null && xmlString2.trim().length() != 0) {
detailDom = genericUtility.parseString(xmlString2);
System.out.println("detailDom" + detailDom);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getName()+" :process(String xmlString, String xmlString2, String windowName, String xtraParams):"+ e.getMessage() + ":");
e.printStackTrace();
retStr = e.getMessage();
}
return retStr;
}
public String process(Document headerDom, Document detailDom,String windowName, String xtraParams) throws RemoteException,ITMException
{
String errString = "",sql="",prdCode="",custCode="",prdCodeDom="",custCodeDom="",toDateStr="",fromDateStr="",
itemSer="",posCode="",empCode="",tranIdParent="",tranIdDel="";
Date tranDate=null;
Connection conn = null;
PreparedStatement pstmt = null,pstmt1=null;
ResultSet rs = null,rs1=null;
SimpleDateFormat sdf=null;
HashMap<String,String> invMap = new HashMap<String,String>();
HashMap<String,Integer> itemMap = new HashMap<String,Integer>();
String loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
String chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
String chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
UserInfoBean userInfo = new UserInfoBean();
userInfo.setLoginCode(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
userInfo.setEmpCode(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"));
userInfo.setSiteCode(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
userInfo.setEntityCode(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "entityCode"));
userInfo.setProfileId(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "profileId"));
userInfo.setUserType(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "userType"));
userInfo.setRemoteHost(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
prdCodeDom = checkNull(genericUtility.getColumnValue("prd_code", headerDom));
custCodeDom = checkNull(genericUtility.getColumnValue("cust_code", headerDom));
sql=" SELECT TRAN_ID FROM CUST_STOCK WHERE PRD_CODE=? AND POS_CODE IS NOT NULL AND TRAN_ID__PARENT IS NOT NULL " +
" AND TRAN_ID__PARENT NOT IN(SELECT TRAN_ID FROM CUST_STOCK WHERE PRD_CODE=? AND POS_CODE IS NULL AND CONFIRMED = 'Y' )";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeDom);
pstmt.setString(2, prdCodeDom);
rs = pstmt.executeQuery();
while(rs.next())
{
tranIdDel=checkNull(rs.getString("tran_id"));
System.out.println("tranIdDel::::"+tranIdDel);
sql="DELETE FROM CUST_STOCK WHERE TRAN_ID=?";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranIdDel);
int i=pstmt1.executeUpdate();
if(pstmt1!=null)
{
pstmt1.close();
pstmt1=null;
}
if(i>0)
{
sql="DELETE FROM CUST_STOCK_INV WHERE TRAN_ID=?";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranIdDel);
pstmt1.executeUpdate();
}
if(pstmt1!=null)
{
pstmt1.close();
pstmt1=null;
}
}
callPstRs(pstmt, rs);
sql=" SELECT FR_DATE,TO_DATE FROM PERIOD WHERE CODE=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeDom);
rs = pstmt.executeQuery();
if(rs.next())
{
fromDateStr=sdf.format(rs.getDate("FR_DATE"));
toDateStr=sdf.format(rs.getDate("TO_DATE"));
}
System.out.println("fromDateStr:::"+fromDateStr+":::toDateStr:::"+toDateStr);
callPstRs(pstmt, rs);
sql = " SELECT TRAN_ID,TRAN_DATE,CUST_CODE,PRD_CODE FROM CUST_STOCK WHERE CUST_CODE=? AND PRD_CODE=? AND POS_CODE IS NULL AND CONFIRMED = 'Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCodeDom);
pstmt.setString(2, prdCodeDom);
rs = pstmt.executeQuery();
if(rs.next())
{
tranIdParent=checkNull(rs.getString("tran_id"));
tranDate=rs.getDate("tran_date");
custCode=checkNull(rs.getString("cust_code"));
prdCode=checkNull(rs.getString("prd_code"));
invMap=getInvoiceDetails(tranIdParent,conn);
sql=" SELECT A.TABLE_NO,A.POS_CODE,A.CUST_CODE,A.EMP_CODE FROM "+
" (SELECT ROW_NUMBER() OVER (PARTITION BY C.TABLE_NO ORDER BY C.TABLE_NO) RN,C.POS_CODE,C.CUST_CODE,A.EMP_CODE,A.TABLE_NO "+
" FROM ORG_STRUCTURE A INNER JOIN ORG_STRUCTURE_CUST C ON A.VERSION_ID=C.VERSION_ID AND A.TABLE_NO=C.TABLE_NO AND A.POS_CODE=C.POS_CODE "+
" WHERE A.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND C.CUST_CODE= ? AND C.SOURCE = 'A' "+
" )A WHERE A.RN=1 ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
itemSer=checkNull(rs1.getString("TABLE_NO"));
posCode=checkNull(rs1.getString("POS_CODE"));
custCode=checkNull(rs1.getString("CUST_CODE"));
empCode=checkNull(rs1.getString("EMP_CODE"));
itemMap.clear();
itemMap=getItemDetails(tranIdParent,itemSer,conn);
System.out.println("itemMap::::"+itemMap.toString());
errString=awacsGenProcess(itemSer,posCode,custCode,empCode,prdCode,tranIdParent,tranDate,loginSiteCode,fromDateStr,toDateStr,invMap,itemMap,chgUser,chgTerm,xtraParams,userInfo,conn);
}
callPstRs(pstmt1, rs1);
}
callPstRs(pstmt, rs);
}// try end
catch (Exception e)
{
try{
System.out.println("Exception :"+this.getClass().getName()+":process(String xmlString2, String xmlString2, String windowName, String xtraParams):"+ e.getMessage() + ":");
e.printStackTrace();
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF", "","", conn);
conn.rollback();
}
catch(Exception ex)
{
ex.printStackTrace();
}
throw new ITMException(e);
}
finally
{
System.out.println("IN ["+this.getClass().getName()+"]>> Closing Connection....");
try {
if(errString==null || errString.trim().length()==0)
{
errString = itmDBAccessEJB.getErrorString("", "VTES3GENS", "","", conn);
}
else
{
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF", "","", conn);
}
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
errString = e.getMessage();
e.printStackTrace();
return errString;
}
}
System.out.println("Error Message=>" + errString);
return errString;
}// END OF PROCESS(2)
private HashMap<String, Integer> getItemDetails(String tranIdParent,String itemSer,Connection conn)
{
HashMap<String,Integer> itemMap = new HashMap<String,Integer>();
String sql="",itemCode="",itemSerHd="";
int clStock=0;
PreparedStatement pstmt=null;
ResultSet rs =null;
try
{
itemSerHd=getItemSerList(itemSer, conn);
sql=" SELECT ITEM_CODE,CL_STOCK,OP_STOCK FROM CUST_STOCK_DET WHERE TRAN_ID = ? AND ITEM_SER in ("+itemSerHd+") ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranIdParent);
//pstmt.setString(2, itemSerHd);
rs = pstmt.executeQuery();
while(rs.next())
{
itemCode=checkNull(rs.getString("ITEM_CODE"));
clStock=rs.getInt("CL_STOCK");
if(clStock <= 0)
{
clStock=0;
}
itemMap.put(itemCode, clStock);
}
}
catch (Exception e)
{
e.printStackTrace();
itemMap=null;
}
return itemMap;
}
public String getItemSerList(String itemser, Connection conn)
{
String itemSerGrpValue="",itemSerSplit="",resultItemSer="";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = null;
try
{
sql= " select distinct item_ser from" +
"(select item_ser from itemser where grp_code=? " +
"union all " +
"select item_ser from itemser where item_ser=?) ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemser);
pstmt.setString(2, itemser);
rs = pstmt.executeQuery();
while(rs.next())
{
itemSerGrpValue=checkNull(rs.getString("item_ser")).trim();
itemSerSplit=itemSerSplit+"'"+itemSerGrpValue+"',";
}
rs.close();
rs = null;
pstmt.close();
resultItemSer = itemSerSplit.substring(0, itemSerSplit.length() - 1);
System.out.println("resultItemSer>>>>>"+resultItemSer);
}
catch(Exception exception)
{
exception.printStackTrace();
try
{
throw new ITMException( exception );
} catch (ITMException e)
{
e.printStackTrace();
}
}
return resultItemSer;
}
private HashMap<String, String> getInvoiceDetails(String tranIdParent,Connection conn)
{
HashMap<String,String> invMap = new HashMap<String,String>();
String sql="",invoiceId="",dlvFlg="";
PreparedStatement pstmt=null;
ResultSet rs =null;
try
{
sql=" SELECT INVOICE_ID,DLV_FLG FROM CUST_STOCK_INV WHERE TRAN_ID = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranIdParent);
rs = pstmt.executeQuery();
while(rs.next())
{
invoiceId=checkNull(rs.getString("INVOICE_ID"));
dlvFlg=checkNull(rs.getString("DLV_FLG"));
invMap.put(invoiceId , dlvFlg);
}
}
catch (Exception e)
{
e.printStackTrace();
invMap=null;
}
return invMap;
}
private String awacsGenProcess(String itemSer, String posCode,String custCode, String empCode, String prdCode,String tranIdParent, Date tranDate, String loginSiteCode,
String fromDateStr, String toDateStr,HashMap invMap,HashMap itemMap, String chgUser, String chgTerm, String xtraParams,UserInfoBean userInfo, Connection conn)
{
boolean result=false;
CustStockGWTIC custStockGWTIC =new CustStockGWTIC();
CustStockGWTConf confTran=new CustStockGWTConf();
ArrayList<String>logList=null;
String xmlInEditMode="",xmlInEditMode2="",xmlInEditMode3="",sql="",orderType="",custType="",tranIdLast="",tranId="",
sysDate="",logDate="",countryCode="",xmlDetail2="",xmlParseStr="",retString="",retString1="",errString="",
custStockItemDetails="",custStockInvDetails="";
StringBuffer xmlBuff=null;
SimpleDateFormat sdf=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
int custCount = 0;
try
{
custCount=isCustExist(prdCode,custCode,itemSer,pstmt,rs,conn);
if(custCount==0)
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
logDate= sdf.format(Calendar.getInstance().getTime());
sysDate = sdf.format(Calendar.getInstance().getTime());
logList=new ArrayList<String>();
xmlInEditMode = getHeaderXML(userInfo,"1","2");
xmlInEditMode2 = getHeaderXML(userInfo,"2","1");
xmlInEditMode3 = getHeaderXML(userInfo,"3","1");
System.out.println("xmlInEditMode:::"+ xmlInEditMode);
System.out.println("xmlInEditMode2>>>>"+xmlInEditMode2);
System.out.println("xmlInEditMode3>>>>"+xmlInEditMode3);
StringBuffer xmlDetail1 = new StringBuffer();
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
callPstRs(pstmt, rs);
sql= " select order_type,cust_type from customer where cust_code=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if(rs.next())
{
orderType=checkNull(rs.getString("order_type"));
custType=checkNull(rs.getString("cust_type"));
}
callPstRs(pstmt, rs);
tranIdLast=getTranIdLast(orderType, itemSer, custCode,conn);
System.out.println("tranIdLast>>>"+tranIdLast+">>orderType>>>"+orderType+"custType>>>"+custType);
Document detailDom1 = genericUtility.parseString(xmlInEditMode);
NodeList parentNodeList1 = detailDom1.getElementsByTagName("Detail1");
Node parentNode1 = parentNodeList1.item(0);
NodeList childNodeList1 = parentNode1.getChildNodes();
int childNodeListLength1 = childNodeList1.getLength();
for (int ctr = 0; ctr < childNodeListLength1; ctr++)
{
Node childNode1 = childNodeList1.item(ctr);
String childNodeName1 = childNode1.getNodeName().trim();
if ("tran_id".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(tranId);
} else if ("tran_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sysDate);
} else if ("cust_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(custCode);
} else if ("item_ser".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(itemSer);
} else if ("order_type".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(orderType);
} else if ("from_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(fromDateStr);
} else if ("to_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(toDateStr);
} else if ("site_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(loginSiteCode);
} else if ("tran_id__last".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(tranIdLast);
} else if ("tran_id__parent".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(tranIdParent);
} else if ("stmt_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sysDate);
} else if ("confirmed".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("N");
} else if ("status".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("O");
} else if ("cust_type".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(custType);
} else if ("prd_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(prdCode);
} else if ("missing_inserted".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("Y");
} else if ("adm_chk".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("N");
} else if ("login_poscode".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(posCode);
} else if ("pos_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(posCode);
} else if ("emp_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(empCode);
} else if ("country_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(countryCode);
} else if ("edit_status".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("A");
} else if ("sale_per".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(empCode);
} else if ("chg_user".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(chgUser);
} else if ("chg_term".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(chgTerm);
} else if ("chg_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sysDate);
} else if ("add_user".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(chgUser);
} else if ("add_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sysDate);
} else if ("add_term".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(chgTerm);
}
}//for loop end
xmlDetail1 = xmlDetail1.append(genericUtility.serializeDom(detailDom1));
//header details end
System.out.println("xmlDetail1 final>>>>"+xmlDetail1.toString());
custStockInvDetails=custStockGWTIC.itemChanged("", xmlDetail1.toString(), xmlDetail1.toString(), "2", "itm_default", "A", xtraParams,"awacs_to_es3_prc",invMap);
System.out.println("custStockInvDetails>>>>"+custStockInvDetails);
if(custStockInvDetails.contains("Detail2"))
{
xmlDetail2=custStockInvDetails.substring(custStockInvDetails.indexOf("<Detail2"), custStockInvDetails.lastIndexOf("</Detail2>")+10);
System.out.println("xmlDetail2>>>"+xmlDetail2);
xmlBuff = new StringBuffer();
xmlBuff.append(xmlDetail1.substring(0,xmlDetail1.indexOf("</Header0>")));
xmlBuff.append(xmlDetail2);
xmlBuff.append(xmlDetail1.substring(xmlDetail1.indexOf("</Header0>")));
xmlParseStr = xmlBuff.toString();
xmlBuff = null;
System.out.println(":::xmlParseStr::with Invoice:" + xmlParseStr);
custStockItemDetails=custStockGWTIC.itemChanged(xmlInEditMode3, xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams,"awacs_to_es3_prc",itemMap);
}
else
{
xmlParseStr = xmlDetail1.toString();
System.out.println(":::xmlParseStr::without Invoice:" + xmlParseStr);
custStockItemDetails=custStockGWTIC.itemChanged(xmlInEditMode3, xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams,"awacs_to_es3_prc",itemMap);
}
System.out.println("custStockItemDetails>>>>>"+custStockItemDetails);
String xmlDetail3=custStockItemDetails.substring(custStockItemDetails.indexOf("<Detail3"), custStockItemDetails.lastIndexOf("</Detail3>")+10);
System.out.println("xmlDetail3>>>>"+xmlDetail3);
xmlBuff = new StringBuffer();
xmlBuff.append(xmlParseStr.substring(0,xmlParseStr.indexOf("<Header0>") + 9));
xmlBuff.append("<objName><![CDATA[").append("secondory_sale_gwt_wiz_dummy").append("]]></objName>");
xmlBuff.append("<pageContext><![CDATA[").append("1").append("]]></pageContext>");
xmlBuff.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
xmlBuff.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
xmlBuff.append("<focusedColumn><![CDATA[").append("").append("]]></focusedColumn>");
xmlBuff.append("<action><![CDATA[").append("SAVE").append("]]></action>");
xmlBuff.append("<elementName><![CDATA[").append("").append("]]></elementName>");
xmlBuff.append("<keyValue><![CDATA[").append("1").append("]]></keyValue>");
xmlBuff.append("<taxKeyValue><![CDATA[").append("").append("]]></taxKeyValue>");
xmlBuff.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
xmlBuff.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
xmlBuff.append("<taxInFocus><![CDATA[").append(true).append("]]></taxInFocus>");
xmlBuff.append(xmlParseStr.substring(xmlParseStr.indexOf("<Header0>") + 9,xmlParseStr.indexOf("</Header0>")));
xmlBuff.append(xmlDetail3);
xmlBuff.append(xmlParseStr.substring(xmlParseStr.indexOf("</Header0>")));
String xmlParseStrFinal = xmlBuff.toString();
xmlBuff = null;
System.out.println("xmlParseStrFinal>>>>"+xmlParseStrFinal);
retString=saveData(xmlParseStrFinal, conn, userInfo);
System.out.println("retString>>>>"+retString);
if (retString.toUpperCase().indexOf("SUCCESS") > -1)
{
conn.commit();
String[] arrayForTranId = retString.split("<TranID>");
int endIndex = arrayForTranId[1].indexOf("</TranID>");
String newTranIdGen = arrayForTranId[1].substring(0, endIndex);
if(newTranIdGen!=null && newTranIdGen.trim().length()>0)
{
retString1=confTran.submit(newTranIdGen, xtraParams, "");
System.out.println("retString1>>>"+retString1);
if (retString1.toUpperCase().indexOf("VTSUBM1") > -1)
{
errString = "Confirmed Transaction "+newTranIdGen+" Created for Customer code >>"+custCode+" of Position code >>"+posCode+" and Employee code >>"+empCode;
logList.add(errString);
errString=null;
result=true;
}
else
{
result=false;
}
}
}
else
{
String description = "";
Document parseString = genericUtility.parseString(retString);
NodeList nlErrorTag = null;
nlErrorTag = parseString.getElementsByTagName("error");
if (nlErrorTag.getLength() <= 0)
{
nlErrorTag = parseString.getElementsByTagName("Error");
}
for (int err = 0; err < nlErrorTag.getLength(); err++)
{
Node itemNode = nlErrorTag.item(err);
NamedNodeMap errorAttributes = itemNode.getAttributes();
Node errorTypeNode = errorAttributes.getNamedItem("type");
Node errorIdNode = errorAttributes.getNamedItem("type");
String errorType = errorTypeNode.getTextContent();
String errorId = errorIdNode.getTextContent();
NodeList childNodeListErr = itemNode.getChildNodes();
for (int k = 0; k < childNodeListErr.getLength(); k++)
{
Node childNodeErr = childNodeListErr.item(k);
if ("description".equalsIgnoreCase(childNodeErr.getNodeName()))
{
description = childNodeErr.getFirstChild().getNodeValue();
}
}
if ("W".equals(errorType)) {
errString = "Warnings: " + errorId + " : " + description;
}
else
{
errString = "Errors: " + errorId + " : " + description;
}
logList.add(errString);
}
}
System.out.println("result>>>"+result);
}
}
catch (Exception e)
{
e.printStackTrace();
result=false;
logList.add(e.getMessage());
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
writeLog(this.getClass().getSimpleName()+"_"+custCode+"_"+prdCode, logList,logDate);
return errString;
}
private void callPstRs(PreparedStatement pstmt, ResultSet rs) {
try {
if(pstmt!=null)
{
pstmt.close();
pstmt =null;
}
if(rs!=null)
{
rs.close();
rs =null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
private String checkNull(String input)
{
input = input==null ? "" : input.trim();
return input;
}
private String saveData(String xmlString, Connection conn,UserInfoBean userInfo) throws Exception
{
String retString = "";
InitialContext ctx = null;
MasterStatefulLocal masterStateful = null;
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal) ctx.lookup("ibase/MasterStatefulEJB/local");
String[] authencate = new String[2];
authencate[0] = "";
authencate[1] = "";
System.out.println("xmlString:::::" + xmlString);
retString = masterStateful.processRequest(userInfo, xmlString,true, conn);
System.out.println("ProcessRequest::::::" + retString);
}
catch (Exception e)
{
System.out.println("Exception: EJBName ["+ getClass().getSimpleName() + "] -method [saveData]");
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
private String getHeaderXML(UserInfoBean userInfo,String formNo,String pagContext) throws Exception
{
InitialContext ctx = null;
String retString = "";
MasterDataStatefulLocal masterStateful = null;
AppConnectParm appConnect = new AppConnectParm();
try{
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterDataStatefulLocal) ctx.lookup("ibase/MasterDataStatefulEJB/local");
retString=masterStateful.getBlankDomForAdd("secondory_sale_gwt_wiz", formNo, pagContext, null, userInfo.toString(), "");
}catch(Exception e)
{
e.printStackTrace();
}
return retString;
}
private void writeLog(String fileName, ArrayList<String> logList,String logDate)
{
String jBossHome = CommonConstants.JBOSSHOME;
FileWriter localFileWriter = null;
try {
if(logList.size()>0){
File logDir = new File(jBossHome + File.separator+ "log" + File.separator + "AwacsToEs3GenProcLog");
if (!logDir.exists()) {
logDir.mkdirs();
}
localFileWriter = new FileWriter(new File(jBossHome + File.separator + "log" + File.separator + "AwacsToEs3GenProcLog" + File.separator + fileName + ".log"), true);
localFileWriter.write("Log for AWACS to Seondary Sales Generation Process for date::"+logDate+" \n");
for(int i=0;i<logList.size();i++)
{
localFileWriter.write((logList.get(i)).toString()+"\n");
}
localFileWriter.write("\n\n");
localFileWriter.flush();
localFileWriter.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private int isCustExist(String prdCode, String custCode, String itemSer, PreparedStatement pstmt, ResultSet rs, Connection conn)
{
String sql="";
int custCntr=0;
try
{
sql=" select count(*) as count from cust_stock where cust_code=? and item_ser=? and prd_code=? and pos_code is not null ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, itemSer);
pstmt.setString(3, prdCode);
rs = pstmt.executeQuery();
if(rs.next())
{
custCntr = rs.getInt("count");
}
callPstRs(pstmt, rs);
System.out.println("custCntr>>>>>"+custCntr);
}
catch(SQLException e)
{
e.printStackTrace();
System.out.println("custCnt SQLException"+e);
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return custCntr;
}
private String getTranIdLast(String orderType, String itemSer,String custCode,Connection conn)
{
String sql="",tranIdLast="";
PreparedStatement pstmt=null;
ResultSet rs=null;
Timestamp toDateLast=null;
try
{
sql = " SELECT max(to_date) as to_date FROM CUST_STOCK WHERE CUST_CODE = ? " +
" AND ITEM_SER = ? and order_type=? and pos_code is not null and confirmed='Y' and status='S' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, itemSer);
pstmt.setString(3, orderType);
rs = pstmt.executeQuery();
if (rs.next())
{
toDateLast = rs.getTimestamp("to_date");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " SELECT max(tran_id) as oldTranId FROM CUST_STOCK WHERE CUST_CODE = ? " +
" AND ITEM_SER = ? and order_type=? and pos_code is not null and confirmed='Y' and status='S' and to_date=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, itemSer);
pstmt.setString(3, orderType);
pstmt.setTimestamp(4, toDateLast);
rs = pstmt.executeQuery();
if (rs.next())
{
tranIdLast = checkNull(rs.getString("oldTranId"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return tranIdLast;
}
}// END OF EJB
\ No newline at end of file
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface AwacsToES3PrcLocal extends ProcessLocal{
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface AwacsToES3PrcRemote extends ProcessRemote{
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,6 +3,7 @@ package ibase.webitm.ejb.dis; ...@@ -3,6 +3,7 @@ package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.*; import ibase.webitm.ejb.*;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap;
//import javax.ejb.EJBObject; //import javax.ejb.EJBObject;
import org.w3c.dom.*; import org.w3c.dom.*;
import javax.xml.parsers.*; import javax.xml.parsers.*;
...@@ -26,6 +27,11 @@ public interface CustStockGWTICLocal extends ValidatorLocal//, EJBObject ...@@ -26,6 +27,11 @@ public interface CustStockGWTICLocal extends ValidatorLocal//, EJBObject
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
//Method override for external transaction generation process Added by saurabh[27/03/17|Start]
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams,String objName) throws RemoteException,ITMException;
//Method override for external transaction generation process Added by saurabh[27/03/17|End]
//Method override for external transaction generation process for AWACS Added by saurabh[24/07/17|Start]
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams,String objName,HashMap dataMap) throws RemoteException,ITMException;
//Method override for external transaction generation process for AWACS Added by saurabh[24/07/17|End]
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package ibase.webitm.ejb.dis; ...@@ -3,6 +3,7 @@ package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.*; import ibase.webitm.ejb.*;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap;
//import javax.ejb.EJBObject; //import javax.ejb.EJBObject;
import org.w3c.dom.*; import org.w3c.dom.*;
import javax.xml.parsers.*; import javax.xml.parsers.*;
...@@ -22,5 +23,11 @@ public interface CustStockGWTICRemote extends ValidatorRemote//, EJBObject ...@@ -22,5 +23,11 @@ public interface CustStockGWTICRemote extends ValidatorRemote//, EJBObject
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException; public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException; public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
//Method override for external transaction generation process Added by saurabh[27/03/17|Start]
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams,String objName) throws RemoteException,ITMException;
//Method override for external transaction generation process Added by saurabh[27/03/17|End]
//Method override for external transaction generation process for AWACS Added by saurabh[24/07/17|Start]
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams,String objName,HashMap dataMap) throws RemoteException,ITMException;
//Method override for external transaction generation process for AWACS Added by saurabh[24/07/17|End]
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException; public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ import ibase.webitm.ejb.ITMDBAccessEJB; ...@@ -8,6 +8,7 @@ import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods; import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -15,13 +16,11 @@ import java.sql.ResultSet; ...@@ -15,13 +16,11 @@ import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless @Stateless
public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPostSaveLocal,CustStockGWTPostSaveRemote { public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPostSaveLocal,CustStockGWTPostSaveRemote {
...@@ -55,10 +54,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -55,10 +54,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
ResultSet rs=null; ResultSet rs=null;
PreparedStatement pstmt=null; PreparedStatement pstmt=null;
String sql=""; String sql="";
String errString = ""; String errString = "",isValidCust="";
String invoiceId="",invoiceIdList="",selectedInvList=""; String invoiceId="",invoiceIdList="",selectedInvList="";
ibase.utility.E12GenericUtility genericUtility = null;
genericUtility = new ibase.utility.E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB=new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessEJB=new ITMDBAccessEJB();
try try
{ {
...@@ -81,8 +78,18 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -81,8 +78,18 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
selectedInvList = "' '"; selectedInvList = "' '";
} }
System.out.println("selectedInvList>>>>"+selectedInvList); System.out.println("selectedInvList>>>>"+selectedInvList);
//Added by saurabh for duplicate customer validation[10/03/17|Start]
isValidCust =checkValidCust(tranId,conn);
if(isValidCust== null || isValidCust.trim().length()==0)
{
errString =updateCustStockDet(dom,tranId,selectedInvList,conn); errString =updateCustStockDet(dom,tranId,selectedInvList,conn);
}
else
{
errString=isValidCust;
}
System.out.println("errString>>>>"+errString); System.out.println("errString>>>>"+errString);
//Added by saurabh for duplicate customer validation[10/03/17|End]
} }
catch(Exception e) catch(Exception e)
{ {
...@@ -98,7 +105,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -98,7 +105,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
if(errString != null && errString.trim().length()>0 ) if(errString != null && errString.trim().length()>0 )
{ {
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn); //errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
return errString;
} }
} }
catch(Exception e) catch(Exception e)
...@@ -110,22 +118,76 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -110,22 +118,76 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
return errString; return errString;
} }
//Added by saurabh for duplicate customer validation[10/03/17|Start]
private String checkValidCust(String tranId, Connection conn) {
// TODO Auto-generated method stub
String sql="",custCodeDom="",itemSerHd="",prdCode="",errString="";
int custCnt=0;
PreparedStatement pstmt=null;
ResultSet rs=null;
ITMDBAccessEJB itmDBAccessEJB =new ITMDBAccessEJB();
try
{
sql="select cust_code,item_ser,prd_code from cust_stock where tran_id=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if(rs.next())
{
custCodeDom = rs.getString("cust_code");
itemSerHd = rs.getString("item_ser");
prdCode = rs.getString("prd_code");
}
callPstRs(pstmt, rs);
sql=" select count(*) as count from cust_stock where cust_code=? and item_ser=? and prd_code=? and tran_id!=? and pos_code is not null ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCodeDom);
pstmt.setString(2, itemSerHd);
pstmt.setString(3, prdCode);
pstmt.setString(4, tranId);
rs = pstmt.executeQuery();
if (rs.next())
{
custCnt = rs.getInt("count");
}
callPstRs(pstmt, rs);
if(custCnt>0)
{
errString = itmDBAccessEJB.getErrorString("", "VMINVPRDCU","", "", conn);
}
else
{
errString="";
}
}
catch(Exception e)
{
errString = e.getMessage();
}
return errString;
}
//Added by saurabh for duplicate customer validation[10/03/17|End]
private String updateCustStockDet(Document dom,String tranId,String selectedInvList, Connection conn) throws RemoteException, ITMException private String updateCustStockDet(Document dom,String tranId,String selectedInvList, Connection conn) throws RemoteException, ITMException
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
E12GenericUtility genericUtility =new E12GenericUtility(); E12GenericUtility genericUtility =new E12GenericUtility();
String errString=""; String errString="";
PreparedStatement pstmt,pstmt1,pstmt2=null; PreparedStatement pstmt,pstmt1 = null;
ResultSet rs,rs1,rs2 =null; ResultSet rs,rs1 =null;
String clStockInp="",itemCode1="",custCodeDom="",itemSerHd="",orderType="",itemSerHeaderSplit="",calCriItemSerStr=""; String clStockInp="",itemCode1="",custCodeDom="",itemSerHd="";
String invoiceMonths="",fromdate="",todate="",sql="",priceList="",sysDate="",tarnIdLast=""; String invoiceMonths="",sql="",priceList="",sysDate="",tarnIdLast="";
String calEnablePrice="",calPriceDivision="";
int invoiceMonthsPrevious=0,UpdCnt=0; int invoiceMonthsPrevious=0,UpdCnt=0;
double rcpQtmDom=0,rcpReplQtmDom=0,rcpFreeQtmDom=0,retQtyDom=0,retQtyFreeDom=0,opStkDom=0,rateOld=0,rateOrgOld=0,rcpValue=0,replValue=0,retValue=0,rcpFreeValue=0; double rcpQtmDom=0,rcpReplQtmDom=0,rcpFreeQtmDom=0,retQtyDom=0,retQtyFreeDom=0,opStkDom=0,rateOld=0,rcpValue=0,replValue=0,retValue=0,rcpFreeValue=0;
double clStock=0,formulaValue=0,rateStd=0,quantityStd=0,closingValue=0,rateAll=0,calRate=0,closingRate=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0,grossSecondaryRate=0,salesQtyCal=0; double clStock=0,formulaValue=0,rateStd=0,quantityStd=0,closingValue=0,
rateAll=0,closingRate=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0,
grossSecondaryRate=0,salesQtyCal=0,clValOld=0,clStkOld=0,opValDom=0;
boolean isClStockInt=false,isItemSerLocal=false; boolean isClStockInt=false,isItemSerLocal=false;
Timestamp thirdMonthDay=null,prdFromoDateTmstmp=null,prdtoDateTmstmp=null; Timestamp thirdMonthDay=null,prdFromoDateTmstmp=null,prdtoDateTmstmp=null;
ArrayList calCriItemSerList=null; //ArrayList calCriItemSerList=null;
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon(); ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
UtilMethods utlmethd = new UtilMethods(); UtilMethods utlmethd = new UtilMethods();
Date currentDate = new Date(); Date currentDate = new Date();
...@@ -144,8 +206,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -144,8 +206,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious); System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious);
SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat()); SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate = sdf2.format(currentDate.getTime());
calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn); /*calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn);
if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) ) if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) )
{ {
isItemSerLocal=false; isItemSerLocal=false;
...@@ -153,19 +215,21 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -153,19 +215,21 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
{ {
calCriItemSerList= new ArrayList(Arrays.asList(calCriItemSerStr.split(","))); calCriItemSerList= new ArrayList(Arrays.asList(calCriItemSerStr.split(",")));
} }
System.out.println("isItemSer@@@@@@@after>>>>"+isItemSerLocal); System.out.println("isItemSer@@@@@@@after>>>>"+isItemSerLocal);*/
sql=" select d.item_code,d.cl_stock,d.purc_rcp,d.purc_rcp__repl,d.purc_rcp__free,d.purc_ret,d.purc_ret__repl,d.op_stock," + sql=" select d.item_code,d.cl_stock,d.purc_rcp,d.purc_rcp__repl,d.purc_rcp__free,d.purc_ret,d.purc_ret__repl,d.op_stock,d.op_value, " +
" c.cust_code,c.tran_id__last, " + " c.cust_code,c.tran_id__last, " +
" d.rcp_val,d.rcp_repl_val,d.ret_val,d.rcp_free_val,c.item_ser,c.order_type,c.from_date,c.to_date " + " d.rcp_val,d.rcp_repl_val,d.ret_val,d.rcp_free_val,c.item_ser,c.order_type,c.from_date,c.to_date " +
" from cust_stock_det d,cust_stock c" + " from cust_stock_det d,cust_stock c" +
" where d.tran_id=c.tran_id " + " where d.tran_id=c.tran_id " +
" and d.cl_value=0 and d.rate=0 and d.cl_stock>0 and d.tran_id=? "; //" and d.cl_value=0 and d.rate=0 and d.cl_stock>0 and d.tran_id=? ";
" and d.tran_id=? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId); pstmt.setString(1,tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while(rs.next()) while(rs.next())
{ {
sysDate = sdf2.format(currentDate.getTime());
itemCode1=checkNull(rs.getString("item_code")); itemCode1=checkNull(rs.getString("item_code"));
clStockInp=checkNull(rs.getString("cl_stock")); clStockInp=checkNull(rs.getString("cl_stock"));
rcpQtmDom=rs.getDouble("purc_rcp"); rcpQtmDom=rs.getDouble("purc_rcp");
...@@ -174,6 +238,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -174,6 +238,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
retQtyDom=rs.getDouble("purc_ret"); retQtyDom=rs.getDouble("purc_ret");
retQtyFreeDom=rs.getDouble("purc_ret__repl"); retQtyFreeDom=rs.getDouble("purc_ret__repl");
opStkDom=rs.getDouble("op_stock"); opStkDom=rs.getDouble("op_stock");
opValDom=rs.getDouble("op_value");
custCodeDom=checkNull(rs.getString("cust_code")); custCodeDom=checkNull(rs.getString("cust_code"));
tarnIdLast=checkNull(rs.getString("tran_id__last")); tarnIdLast=checkNull(rs.getString("tran_id__last"));
rcpValue=rs.getDouble("rcp_val"); rcpValue=rs.getDouble("rcp_val");
...@@ -181,14 +246,18 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -181,14 +246,18 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
retValue=rs.getDouble("ret_val"); retValue=rs.getDouble("ret_val");
rcpFreeValue=rs.getDouble("rcp_free_val"); rcpFreeValue=rs.getDouble("rcp_free_val");
itemSerHd = checkNull(rs.getString("item_ser")); itemSerHd = checkNull(rs.getString("item_ser"));
orderType = checkNull(rs.getString("order_type")); System.out.println("@S@itemSerHd"+itemSerHd+"]");
//orderType = checkNull(rs.getString("order_type"));
prdFromoDateTmstmp = rs.getTimestamp("from_date"); prdFromoDateTmstmp = rs.getTimestamp("from_date");
prdtoDateTmstmp = rs.getTimestamp("to_date"); prdtoDateTmstmp = rs.getTimestamp("to_date");
rateOld=0;//rateOrgOld=0;
clValOld=0;clStkOld=0;//added 140617
if(tarnIdLast.length()>0){ if(tarnIdLast.length()>0){
sql = " select CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," + sql = " select CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," +
" CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " + " CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org," +
" NVL(cl_value,0) as cl_value ," +
" NVL(cl_stock,0) as cl_stock from " +
" cust_stock_det where tran_id=? and item_code=? "; " cust_stock_det where tran_id=? and item_code=? ";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tarnIdLast); pstmt1.setString(1, tarnIdLast);
...@@ -197,16 +266,21 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -197,16 +266,21 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
if (rs1.next()) if (rs1.next())
{ {
rateOld = Double.parseDouble(rs1.getString("rate")); rateOld = Double.parseDouble(rs1.getString("rate"));
rateOrgOld = Double.parseDouble(rs1.getString("rate__org")); //rateOrgOld = Double.parseDouble(rs1.getString("rate__org"));
clValOld = Double.parseDouble(rs1.getString("cl_value"));
clStkOld = Double.parseDouble(rs1.getString("cl_stock"));
} }
callPstRs(pstmt1, rs1); callPstRs(pstmt1, rs1);
} }
if(clStkOld>0)
{
opStkDom=clStkOld;
}
System.out.println("prdFromoDateTmstmp :"+prdFromoDateTmstmp); System.out.println("prdFromoDateTmstmp :"+prdFromoDateTmstmp);
System.out.println("prdtoDateTmstmp :"+prdtoDateTmstmp); System.out.println("prdtoDateTmstmp :"+prdtoDateTmstmp);
if(calCriItemSerStr.trim().length()>0) /*if(calCriItemSerStr.trim().length()>0)
{ {
System.out.println("calCriItemSerList.contains(itemSerHd.trim())"+calCriItemSerList.contains(itemSerHd.trim())); System.out.println("calCriItemSerList.contains(itemSerHd.trim())"+calCriItemSerList.contains(itemSerHd.trim()));
if(calCriItemSerList.contains(itemSerHd.trim())) if(calCriItemSerList.contains(itemSerHd.trim()))
...@@ -222,10 +296,11 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -222,10 +296,11 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
else else
{ {
System.out.println("isItemSer:::::"+isItemSerLocal); System.out.println("isItemSer:::::"+isItemSerLocal);
} }*/
itemSerHd=getItemSerList(itemSerHd,conn); //itemSerHd=getItemSerList(itemSerHd,conn);
itemSerHeaderSplit=itemSerHd; System.out.println("@S@ Group item series::"+itemSerHd);
//itemSerHeaderSplit=itemSerHd;
isClStockInt= isValidDouble(clStockInp); isClStockInt= isValidDouble(clStockInp);
System.out.println("isClStockInt>>>>>>"+isClStockInt); System.out.println("isClStockInt>>>>>>"+isClStockInt);
...@@ -250,8 +325,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -250,8 +325,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("formulaValue@@@@@@>>>"+formulaValue); System.out.println("formulaValue@@@@@@>>>"+formulaValue);
System.out.println("isItemSer>>>>>"+isItemSerLocal); System.out.println("isItemSer>>>>>"+isItemSerLocal);
if(!isItemSerLocal) //if(!isItemSerLocal)
{ //{
/*invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS",conn); /*invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS",conn);
System.out.println("invoiceMonths.." + invoiceMonths); System.out.println("invoiceMonths.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0) ) if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0) )
...@@ -263,12 +338,26 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -263,12 +338,26 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
} }
System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious); System.out.println("invoiceMonthsPrevious>>>>>"+invoiceMonthsPrevious);
*/ */
//Modified by santosh to set priceList(14/SEP/2017).[START]
calEnablePrice = dist.getDisparams("999999","ENABLE_SPEC_PRICELIST",conn);
calPriceDivision = dist.getDisparams("999999","SPEC_PRICELIST",conn);
System.out.println("calEnablePrice["+calEnablePrice+"]calPriceDivision["+calPriceDivision+"]");
if (("NULLFOUND".equalsIgnoreCase(calEnablePrice) || calEnablePrice == null || calEnablePrice.trim().length() == 0) )
{
calEnablePrice="N";
}
if (("NULLFOUND".equalsIgnoreCase(calPriceDivision) || calPriceDivision == null || calPriceDivision.trim().length() == 0) )
{
calEnablePrice="N";
}
System.out.println("calEnablePrice["+calEnablePrice+"]calPriceDivision["+calPriceDivision+"]");
//Modified by santosh to set priceList(14/SEP/2017).[END]
thirdMonthDay= utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious); thirdMonthDay= utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay>>>>>>"+thirdMonthDay); System.out.println("thirdMonthDay>>>>>>"+thirdMonthDay);
closingValue=0; closingValue=0;
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as ,itrc.quantity__stduom,inv.tran_date " + sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as quantity__stduom,inv.tran_date " +
"FROM invoice_trace itrc,invoice inv WHERE itrc.item_code=? " + "FROM invoice_trace itrc,invoice inv WHERE itrc.item_code=? " +
"and itrc.invoice_id=inv.invoice_id and inv.tran_date>=? " + "and itrc.invoice_id=inv.invoice_id and inv.tran_date>=? " +
"and inv.tran_date<=? AND itrc.rate__stduom >0.001 and inv.cust_code=? " + "and inv.tran_date<=? AND itrc.rate__stduom >0.001 and inv.cust_code=? " +
...@@ -307,6 +396,22 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -307,6 +396,22 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("closingValue>>>>>>"+closingValue); System.out.println("closingValue>>>>>>"+closingValue);
System.out.println("formulaValue>>>>>>"+formulaValue); System.out.println("formulaValue>>>>>>"+formulaValue);
if(formulaValue>0) if(formulaValue>0)
{
//Modified by santosh to set priceList(14/SEP/2017).[START]
if("Y".equalsIgnoreCase(calEnablePrice))
{
if("BR".equalsIgnoreCase(itemSerHd))
{
priceList = calPriceDivision.substring(calPriceDivision.indexOf(",")+1,calPriceDivision.length());
System.out.println("@S@priceList for division ::BR:: ["+priceList+"]");
}
else
{
priceList= calPriceDivision.substring(0,calPriceDivision.indexOf(","));
System.out.println("@S@priceList for all divisions ["+priceList+"]");
}
}
else
{ {
sql = "select price_list from customer where cust_code =? "; sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
...@@ -318,12 +423,14 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -318,12 +423,14 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("priceList edit :" + priceList); System.out.println("priceList edit :" + priceList);
} }
callPstRs(pstmt1, rs1); callPstRs(pstmt1, rs1);
}
//Modified by santosh to set priceList(14/SEP/2017).[END]
//Added by saurabh to get rate from DDF_PICK_MAX_RATE fuction[18/10/16|Start] //Added by saurabh to get rate from DDF_PICK_MAX_RATE fuction[18/10/16|Start]
sysDate = genericUtility.getValidDateString( sysDate , getApplDateFormat() , getDBDateFormat()); sysDate = genericUtility.getValidDateString( sysDate , getApplDateFormat() , getDBDateFormat());
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, TO_DATE( ? , ? ), ? ) FROM DUAL "; sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, TO_DATE( ? , ? ), ? ) FROM DUAL ";
pstmt1 = conn.prepareStatement( sql ); pstmt1 = conn.prepareStatement( sql );
pstmt1.setString( 1, priceList ); pstmt1.setString( 1, priceList );
pstmt1.setString( 2, sysDate ); pstmt1.setString( 2, sysDate);
pstmt1.setString( 3, getDBDateFormat() ); pstmt1.setString( 3, getDBDateFormat() );
pstmt1.setString( 4, itemCode1 ); pstmt1.setString( 4, itemCode1 );
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
...@@ -340,12 +447,13 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -340,12 +447,13 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
closingValue=getRequiredDcml(closingValue,3); closingValue=getRequiredDcml(closingValue,3);
} }
}else /*}else
{ {
calRate=getOpeningRate(invoiceMonthsPrevious,orderType,itemSerHeaderSplit,selectedInvList,rcpQtmDom,itemCode1,prdtoDateTmstmp,prdFromoDateTmstmp,custCodeDom,conn); calRate=getOpeningRate(invoiceMonthsPrevious,orderType,itemSerHeaderSplit,selectedInvList,rcpQtmDom,itemCode1,prdtoDateTmstmp,prdFromoDateTmstmp,custCodeDom,conn);
calRate=getRequiredDcml(calRate,3); calRate=getRequiredDcml(calRate,3);
closingValue=clStock*calRate; closingValue=clStock*calRate;
} }*/
closingRate=0;
if(clStock>0) if(clStock>0)
{ {
closingRate=closingValue/clStock; closingRate=closingValue/clStock;
...@@ -366,10 +474,24 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -366,10 +474,24 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("rcpValue>>>"+rcpValue+">>replValue>>>"+replValue); System.out.println("rcpValue>>>"+rcpValue+">>replValue>>>"+replValue);
System.out.println("retValue>>>"+retValue+">>closingValue>>>"+closingValue); System.out.println("retValue>>>"+retValue+">>closingValue>>>"+closingValue);
System.out.println("rcpFreeValue>>>>"+rcpFreeValue); System.out.println("rcpFreeValue>>>>"+rcpFreeValue);
netSecondarySalesValue=(opStkDom*rateOld)+rcpValue+replValue-retValue-closingValue; if(clValOld>0)
{
netSecondarySalesValue=(clValOld)+rcpValue+replValue-retValue-closingValue;
}
else
{
netSecondarySalesValue=(opValDom)+rcpValue+replValue-retValue-closingValue;
}
netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3); netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3);
System.out.println("netSecondarySalesValue>>>>>>>"+netSecondarySalesValue); System.out.println("netSecondarySalesValue>>>>>>>"+netSecondarySalesValue);
grossSecondarySalesValue=(opStkDom*rateOrgOld)+rcpValue+replValue+rcpFreeValue-retValue-closingValue; if(clValOld>0)
{
grossSecondarySalesValue=(clValOld)+rcpValue+replValue+rcpFreeValue-retValue-closingValue;
}
else
{
grossSecondarySalesValue=(opValDom)+rcpValue+replValue+rcpFreeValue-retValue-closingValue;
}
grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3); grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3);
System.out.println("grossSecondarySalesValue>>>>"+grossSecondarySalesValue); System.out.println("grossSecondarySalesValue>>>>"+grossSecondarySalesValue);
...@@ -384,7 +506,10 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -384,7 +506,10 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println("grossSecondaryRate>>>"+grossSecondaryRate); System.out.println("grossSecondaryRate>>>"+grossSecondaryRate);
salesQtyCal = opStkDom + (rcpQtmDom + rcpReplQtmDom) - (retQtyDom + retQtyFreeDom) - clStock; salesQtyCal = opStkDom + (rcpQtmDom + rcpReplQtmDom) - (retQtyDom + retQtyFreeDom) - clStock;
System.out.println("salesQtyCal :" + salesQtyCal); System.out.println("salesQtyCal :" + salesQtyCal);
if(grossSecondaryRate<0)
{
grossSecondaryRate=0;
}
sql =" update cust_stock_det set sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? where tran_id=? and item_code=? "; sql =" update cust_stock_det set sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? where tran_id=? and item_code=? ";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
...@@ -394,7 +519,13 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -394,7 +519,13 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
pstmt1.setDouble(4, grossSecondaryQty );//sales__org pstmt1.setDouble(4, grossSecondaryQty );//sales__org
pstmt1.setDouble(5, closingValue );//cl_value pstmt1.setDouble(5, closingValue );//cl_value
pstmt1.setDouble(6, netSecondarySalesValue );//sales_value pstmt1.setDouble(6, netSecondarySalesValue );//sales_value
pstmt1.setDouble(7, getRequiredDcml((opStkDom*rateOld),3) );//op_value if(clValOld>0){
pstmt1.setDouble(7, getRequiredDcml((clValOld),3) );//op_value
}
else
{
pstmt1.setDouble(7, getRequiredDcml((opValDom),3) );//op_value
}
pstmt1.setString(8, tranId); pstmt1.setString(8, tranId);
pstmt1.setString(9, itemCode1); pstmt1.setString(9, itemCode1);
UpdCnt = pstmt1.executeUpdate(); UpdCnt = pstmt1.executeUpdate();
...@@ -416,8 +547,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -416,8 +547,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
catch(Exception e) catch(Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
//errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn); errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
errString=e.getMessage(); //errString=e.getMessage();
} }
finally finally
{ {
...@@ -426,7 +557,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -426,7 +557,8 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
System.out.println(">>>In finally errString:"+errString); System.out.println(">>>In finally errString:"+errString);
if( errString != null && errString.trim().length()>0 ) if( errString != null && errString.trim().length()>0 )
{ {
errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn); //errString = itmDBAccessEJB.getErrorString("", "VTICFAIL","", "", conn);
return errString;
} }
} }
catch(Exception e) catch(Exception e)
...@@ -439,7 +571,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -439,7 +571,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
return errString; return errString;
} }
private double getOpeningRate(int invoiceMonthsPrevious,String orderType,String itemSerHeaderSplit,String selectedInvList ,double rcpQtyDom,String itemCode, Timestamp prdtoDateTmstmp,Timestamp prdFromoDateTmstmp, String custCode, Connection conn) throws ITMException /*private double getOpeningRate(int invoiceMonthsPrevious,String orderType,String itemSerHeaderSplit,String selectedInvList ,double rcpQtyDom,String itemCode, Timestamp prdtoDateTmstmp,Timestamp prdFromoDateTmstmp, String custCode, Connection conn) throws ITMException
{ {
E12GenericUtility genericUtility =new E12GenericUtility(); E12GenericUtility genericUtility =new E12GenericUtility();
UtilMethods utlmethd = new UtilMethods(); UtilMethods utlmethd = new UtilMethods();
...@@ -480,7 +612,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -480,7 +612,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
} }
else else
{ {
/*invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn); invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn);
System.out.println("invoiceMonths>>>>.." + invoiceMonths); System.out.println("invoiceMonths>>>>.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0)) if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0))
{ {
...@@ -489,7 +621,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -489,7 +621,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
{ {
invoiceMonthsPrevious = Integer.parseInt(invoiceMonths); invoiceMonthsPrevious = Integer.parseInt(invoiceMonths);
} }
System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious);*/ System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious);
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious); thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay); System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay);
...@@ -547,7 +679,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo ...@@ -547,7 +679,7 @@ public class CustStockGWTPostSave extends ValidatorEJB implements CustStockGWTPo
} }
System.out.println("return openingRate>>>>"+openingRate); System.out.println("return openingRate>>>>"+openingRate);
return openingRate; return openingRate;
} }*/
public String getItemSerList(String itemser, Connection conn) public String getItemSerList(String itemser, Connection conn)
{ {
String itemSerGrpValue="",itemSerSplit="",resultItemSer=""; String itemSerGrpValue="",itemSerSplit="",resultItemSer="";
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
package ibase.webitm.ejb.dis; package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import javax.ejb.Stateless; import javax.ejb.Stateless;
...@@ -23,7 +23,7 @@ import org.w3c.dom.NodeList; ...@@ -23,7 +23,7 @@ import org.w3c.dom.NodeList;
@Stateless @Stateless
public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDataICLocal { public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDataICLocal {
GenericUtility genericUtility = GenericUtility.getInstance(); E12GenericUtility genericUtility = new E12GenericUtility();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{ {
...@@ -61,14 +61,11 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -61,14 +61,11 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{ {
System.out.println("In validate Data"); System.out.println("In validate Data");
GenericUtility genericUtility = GenericUtility.getInstance();
ArrayList<String> errList = new ArrayList<String>(); ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>(); ArrayList<String> errFields = new ArrayList<String>();
ArrayList<String> errCustList = new ArrayList<String>();
int count = 0; int count = 0;
String errString = ""; String errString = "", errorType = "", errCode = "",custCode="";
String errorType = "";
String errCode = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>"); StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
String childNodeName = ""; String childNodeName = "";
String sql = ""; String sql = "";
...@@ -80,8 +77,12 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -80,8 +77,12 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
int cnt = 0; int cnt = 0;
ConnDriver connDriver = null; ConnDriver connDriver = null;
Node childNode = null; Node childNode = null;
String table_no="",prd_code=""; String itemSer="",prdCode="",fromDateDom="",toDateDom="";
java.sql.Timestamp toDate=null,fromDate=null;
ArrayList<String> custArray=null;
int divCount=0;
try { try {
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
System.out.println("************xtraParams*************" + xtraParams); System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver(); connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
...@@ -116,20 +117,20 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -116,20 +117,20 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
System.out.println("childList = " + childList); System.out.println("childList = " + childList);
if ("prd_code".equalsIgnoreCase(childNodeName) ) if ("prd_code".equalsIgnoreCase(childNodeName) )
{ {
prd_code = checkNull(genericUtility.getColumnValue("prd_code", currDom)); prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(prd_code==null || prd_code.trim().length()==0) if(prdCode==null || prdCode.trim().length()==0)
{ {
errList.add("VTNULLPC");//Invalid-Division can not be blank errList.add("VTNULLPC");//Invalid-Division can not be blank
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break; break;
} }
} }
if ("table_no".equalsIgnoreCase(childNodeName) ) if ("item_ser".equalsIgnoreCase(childNodeName) )
{ {
table_no = checkNull(genericUtility.getColumnValue("table_no", currDom)); itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
prd_code = checkNull(genericUtility.getColumnValue("prd_code", currDom)); prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(table_no==null || table_no.trim().length()==0) if(itemSer==null || itemSer.trim().length()==0)
{ {
errList.add("VTNULLDV");//Invalid-Division can not be blank errList.add("VTNULLDV");//Invalid-Division can not be blank
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
...@@ -139,8 +140,8 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -139,8 +140,8 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
{ {
sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE item_ser = ? and prd_code=? and pos_code is not null "; sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE item_ser = ? and prd_code=? and pos_code is not null ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, table_no); pstmt.setString(1, itemSer);
pstmt.setString(2, prd_code); pstmt.setString(2, prdCode);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
...@@ -155,6 +156,157 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -155,6 +156,157 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
} }
} }
} }
if ("from_date".equalsIgnoreCase(childNodeName) )
{
fromDateDom = checkNull(genericUtility.getColumnValue("from_date", currDom));
if(fromDateDom==null || fromDateDom.trim().length()==0)
{
errList.add("VPBLKFRDT");
errFields.add(childNodeName.toLowerCase());
break;
}
}
if ("to_date".equalsIgnoreCase(childNodeName) )
{
fromDateDom = checkNull(genericUtility.getColumnValue("from_date", currDom));
toDateDom = checkNull(genericUtility.getColumnValue("to_date", currDom));
if(toDateDom==null || toDateDom.trim().length()==0)
{
errList.add("VPBLKTODT");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
fromDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(fromDateDom, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
toDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(toDateDom, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("fromDate>>>>"+fromDate+"toDate::::"+toDate);
if(toDate.before(fromDate))
{
errList.add("INVTODT");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
if ("cust_code".equalsIgnoreCase(childNodeName) )
{
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
custCode = checkNull(genericUtility.getColumnValue("cust_code", currDom));
fromDateDom = checkNull(genericUtility.getColumnValue("from_date", currDom));
toDateDom = checkNull(genericUtility.getColumnValue("to_date", currDom));
fromDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(fromDateDom, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
toDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(toDateDom, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
if(custCode==null || custCode.trim().length()==0)
{
errList.add("VPBLKCUSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
if (!custCode.matches("[A-Za-z0-9, ]*"))
{
errList.add("VPINVCCDS");
errFields.add(childNodeName.toLowerCase());
break;
}
if(custCode.contains(","))
{
custArray= new ArrayList<String>(Arrays.asList(custCode.split(",")));
for (int i=0;i<custArray.size();i++)
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custArray.get(i));
rs = pstmt.executeQuery();
if (rs.next())
{
divCount = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("divCount: " + divCount);
if (divCount == 0)
{
errCustList.add(custArray.get(i));
errList.add("VPINVCSCDM");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE CUST_CODE=? AND PRD_CODE=? AND ITEM_SER=? AND TRAN_DATE BETWEEN ? AND ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custArray.get(i));
pstmt.setString(2, prdCode);
pstmt.setString(3, itemSer);
pstmt.setTimestamp(4, fromDate);
pstmt.setTimestamp(5, toDate);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errCustList.add(custArray.get(i));
errList.add("VPINVCSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
divCount = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("divCount: " + divCount);
if (divCount == 0)
{
errCustList.add(custCode);
errList.add("VPINVCSCDM");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE CUST_CODE=? AND PRD_CODE=? AND ITEM_SER=? AND TRAN_DATE BETWEEN ? AND ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, prdCode);
pstmt.setString(3, itemSer);
pstmt.setTimestamp(4, fromDate);
pstmt.setTimestamp(5, toDate);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errCustList.add(custCode);
errList.add("VPINVCSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
}
} }
} }
...@@ -172,6 +324,19 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -172,6 +324,19 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
errFldName = (String) errFields.get(cnt); errFldName = (String) errFields.get(cnt);
errString = getErrorString(errFldName, errCode, userId); errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode); errorType = errorType(conn, errCode);
if(errCustList.size()>0 && errString.length() > 0 )
{
String begPart = errString.substring( 0, errString.indexOf("]]></description>") );
String mainStr="";
for(int i=0;i<errCustList.size();i++)
{
mainStr=mainStr+ errCustList.get(i)+",";
}
String endPart=errString.substring( errString.indexOf("]]></description>"), errString.length() );
mainStr=" Following customers are invalid :: "+mainStr.substring(0,mainStr.length()-1);
errString = begPart+mainStr + endPart;
}
if (errString.length() > 0) if (errString.length() > 0)
{ {
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>")); String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
...@@ -189,13 +354,10 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -189,13 +354,10 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
errList = null; errList = null;
errFields.clear(); errFields.clear();
errFields = null; errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer("");
} }
errStringXml.append("</Errors></Root>\r\n");
errString = errStringXml.toString(); errString = errStringXml.toString();
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -235,7 +397,6 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -235,7 +397,6 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
Document hdrDom = null; Document hdrDom = null;
Document allDom = null; Document allDom = null;
String errString = null; String errString = null;
GenericUtility genericUtility = GenericUtility.getInstance();
try try
{ {
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0)) if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
...@@ -270,8 +431,7 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -270,8 +431,7 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
String childNodeName = null; String childNodeName = null;
Connection conn = null; Connection conn = null;
StringBuffer valueXmlString = new StringBuffer(); StringBuffer valueXmlString = new StringBuffer();
Date sysdate=null; String fromDateDom="";
String asOnDate="";
try try
{ {
try { try {
...@@ -285,7 +445,6 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -285,7 +445,6 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
NodeList childNodeList = null; NodeList childNodeList = null;
Node parentNode = null; Node parentNode = null;
Node childNode = null; Node childNode = null;
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDispDateFormat());
if ((objContext != null) && (objContext.trim().length() > 0)) if ((objContext != null) && (objContext.trim().length() > 0))
{ {
...@@ -315,18 +474,22 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat ...@@ -315,18 +474,22 @@ public class Es3HDataIC extends ValidatorEJB implements Es3HDataICRemote,Es3HDat
if (currentColumn.equalsIgnoreCase("itm_default")) if (currentColumn.equalsIgnoreCase("itm_default"))
{ {
/*String sql="select sysdate from dual"; valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>\r\n");
PreparedStatement pstmt = conn.prepareStatement(sql); valueXmlString.append("<item_ser>").append("<![CDATA[]]>").append("</item_ser>\r\n");
ResultSet rs = pstmt.executeQuery(); valueXmlString.append("<from_date>").append("").append("</from_date>\r\n");
if (rs.next()) valueXmlString.append("<to_date>").append("").append("</to_date>\r\n");
valueXmlString.append("<cust_code>").append("<![CDATA[]]>").append("</cust_code>\r\n");
}
else if(currentColumn.equalsIgnoreCase("from_date"))
{
fromDateDom = checkNull(genericUtility.getColumnValue("from_date", currDom));
if(fromDateDom!=null && fromDateDom.trim().length()>0){
valueXmlString.append("<to_date>").append(fromDateDom).append("</to_date>\r\n");
}
else
{ {
sysdate = rs.getDate(1); valueXmlString.append("<to_date>").append("").append("</to_date>\r\n");
} }
callPstRs(pstmt,rs);
asOnDate=sdf.format(sysdate).toString();
valueXmlString.append("<chg_date>").append(asOnDate).append("</chg_date>\r\n");*/
valueXmlString.append("<table_no>").append("").append("</table_no>\r\n");
valueXmlString.append("<prd_code>").append("").append("</prd_code>\r\n");
} }
valueXmlString.append("</Detail1>\r\n"); valueXmlString.append("</Detail1>\r\n");
......
...@@ -14,9 +14,6 @@ import java.sql.ResultSet; ...@@ -14,9 +14,6 @@ import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -31,10 +28,6 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -31,10 +28,6 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
E12GenericUtility genericUtility = new E12GenericUtility(); E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
Connection conn = null; Connection conn = null;
String loginCode = null;
StringBuffer retBuf = null;
String errorString = null;
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{ {
...@@ -80,8 +73,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -80,8 +73,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
Node childNode = null; Node childNode = null;
PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null, pstmt3 = null; PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null, pstmt3 = null;
ResultSet rs = null, rs1 = null, rs2 = null, rs3 = null; ResultSet rs = null, rs1 = null, rs2 = null, rs3 = null;
String sql = "", tranId = "", itemCode = "", invoiceId = "", dlvFlag = ""; String sql = "", tranId = "", itemCode = "", invoiceId = "", dlvFlag = "",fromDateStr="",custCodeDom="",toDateStr="";
int sreturnCnt = 0; //int sreturnCnt = 0;
double retQty = 0, retRate = 0,retDiscnt=0,totalRetVal=0; double retQty = 0, retRate = 0,retDiscnt=0,totalRetVal=0;
double recptRetQty = 0, recptRetVal = 0; double recptRetQty = 0, recptRetVal = 0;
double recptReplQty = 0, recptReplVal = 0; double recptReplQty = 0, recptReplVal = 0;
...@@ -94,30 +87,32 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -94,30 +87,32 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
double FreeQty = 0, freeValue = 0; double FreeQty = 0, freeValue = 0;
double recptFreeQty = 0, recptFreeValue = 0; double recptFreeQty = 0, recptFreeValue = 0;
double transitFreeQty = 0, transitFreeValue = 0; double transitFreeQty = 0, transitFreeValue = 0;
String lineType = ""; String lineType = "",calEnablePrice="",calPriceDivision="",checkItemSer="";
double billRetQtyBonusQty = 0, billRetQtyBonusVal = 0,replNetVal=0,totalInvAmt=0,netAmtRet=0,netAmtRep=0; double billRetQtyBonusQty = 0, billRetQtyBonusVal = 0,totalInvAmt=0,netAmtRet=0,netAmtRep=0;//,replNetVal=0;
Timestamp prdFromoDateTmstmp = null, prdtoDateTmstmp = null; Timestamp prdFromoDateTmstmp = null, prdtoDateTmstmp = null;
String custCode = ""; String custCode = "";
double rateStd = 0, quantityStd = 0, formulaValue = 0, closingValue = 0,retQtyFreeDom=0; double rateStd = 0, quantityStd = 0, formulaValue = 0, closingValue = 0,retQtyFreeDom=0;
String priceList = "",tranIdLast=""; String priceList = "",tranIdLast="";
String sysDate = ""; //String sysDate = "";
String invoiceMonths = "",table_no="",prd_code="",invoiceIdList="",selectedInvList=""; String invoiceMonths = "",itemSer="",prdCode="";//,invoiceIdList="",selectedInvList="";
int invoiceMonthsPrevious = 0,retCnt=0,chkCnt=0; int invoiceMonthsPrevious = 0,retCnt=0,chkCnt=0;
Timestamp thirdMonthDay = null; Timestamp thirdMonthDay = null;
Date currentDate = new Date(); //Date currentDate = new Date();
String calCriItemSerStr="", refSer = ""; String refSer = "";// ,calCriItemSerStr="";
double priceListRate = 0, clStock = 0,opStkDom=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0; double priceListRate = 0, clStock = 0,opStkDom=0,grossSecondaryQty=0,netSecondarySalesValue=0,grossSecondarySalesValue=0;
double closingRate = 0,UpdCnt=0,grossSecondaryRate=0,salesQtyCal=0,rcpQtmDom=0; double closingRate = 0,UpdCnt=0,grossSecondaryRate=0,salesQtyCal=0;//,rcpQtmDom=0;
double clStockLast=0.0,rateOld=0.0,rateOrgOld=0.0,opValue=0.0,calRate=0.0; double clStockLast=0.0,rateOld=0.0,rateOrgOld=0.0,opValue=0.0;//,calRate=0.0;
boolean isItemSerLocal=false,isItemFound=false; boolean isItemFound=false;//,isItemSerLocal=false;
ArrayList<String> calCriItemSerList=null; //ArrayList<String> calCriItemSerList=null;
ClosingStockBean closingStockBean=null; ClosingStockBean closingStockBean=null;
HashMap<String,ClosingStockBean> closingStockMap=null; HashMap<String,ClosingStockBean> closingStockMap=null;
UtilMethods utlmethd = new UtilMethods(); UtilMethods utlmethd = new UtilMethods();
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon(); ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode"); String loginCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
String chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
HashSet<String> invoiceItemSet=null; HashSet<String> invoiceItemSet=null;
String invoiceItemKey=""; String invoiceItemKey="";
Timestamp fromDate=null,toDate=null;
try { try {
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
...@@ -128,7 +123,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -128,7 +123,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
} }
try { try {
calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn); /*calCriItemSerStr = dist.getDisparams("999999","CAL_CRIT_ITEMSER",conn);
System.out.println("calCriItemSerStr.." + calCriItemSerStr); System.out.println("calCriItemSerStr.." + calCriItemSerStr);
System.out.println("isItemSer@@@@@@@before>>>>"+isItemSerLocal); System.out.println("isItemSer@@@@@@@before>>>>"+isItemSerLocal);
if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) ) if (("NULLFOUND".equalsIgnoreCase(calCriItemSerStr) || calCriItemSerStr == null || calCriItemSerStr.trim().length() == 0) )
...@@ -140,7 +135,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -140,7 +135,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
calCriItemSerList= new ArrayList<String>(Arrays.asList(calCriItemSerStr.split(","))); calCriItemSerList= new ArrayList<String>(Arrays.asList(calCriItemSerStr.split(",")));
isItemSerLocal=false; isItemSerLocal=false;
System.out.println("isItemSer@@Chk>>>>"+isItemSerLocal); System.out.println("isItemSer@@Chk>>>>"+isItemSerLocal);
} }*/
invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS", conn); invoiceMonths = dist.getDisparams("999999","INVOICE_MONTHS", conn);
System.out.println("invoiceMonths.." + invoiceMonths); System.out.println("invoiceMonths.." + invoiceMonths);
...@@ -154,9 +149,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -154,9 +149,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
} }
// thirdMonthDay= utlmethd.AddMonths(prdtoDateTmstmp, -3); // thirdMonthDay= utlmethd.AddMonths(prdtoDateTmstmp, -3);
System.out.println("invoiceMonthsPrevious>>>>>"+ invoiceMonthsPrevious); System.out.println("invoiceMonthsPrevious>>>>>"+ invoiceMonthsPrevious);
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
SimpleDateFormat sdf2 = new SimpleDateFormat(genericUtility.getApplDateFormat()); //sysDate = sdf2.format(currentDate.getTime());
sysDate = sdf2.format(currentDate.getTime());
parentNodeList = headerDom.getElementsByTagName("Detail1"); parentNodeList = headerDom.getElementsByTagName("Detail1");
parentNodeListLength = parentNodeList.getLength(); parentNodeListLength = parentNodeList.getLength();
...@@ -177,35 +171,77 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -177,35 +171,77 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
System.out.println("childNodeList.item(childRow) : "+ childNode); System.out.println("childNodeList.item(childRow) : "+ childNode);
System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue()); System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue());
if("table_no".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null) if("item_ser".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{ {
table_no=childNode.getFirstChild().getNodeValue(); itemSer=childNode.getFirstChild().getNodeValue();
table_no= table_no==null ? "" : table_no.trim(); itemSer= itemSer==null ? "" : itemSer.trim();
} }
if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null) if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{ {
prd_code=childNode.getFirstChild().getNodeValue(); prdCode=childNode.getFirstChild().getNodeValue();
prd_code= prd_code==null ? "" : prd_code.trim(); prdCode= prdCode==null ? "" : prdCode.trim();
} }
//Two additional filters added to run process as per tran date and cust code which will avoid unnesscary update [25/07/17|Start]
if("from_date".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
fromDateStr=childNode.getFirstChild().getNodeValue();
fromDateStr= fromDateStr==null ? "" : fromDateStr.trim();
}
if("to_date".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
toDateStr=childNode.getFirstChild().getNodeValue();
toDateStr= toDateStr==null ? "" : toDateStr.trim();
}
if("cust_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
custCodeDom=childNode.getFirstChild().getNodeValue();
custCodeDom= custCodeDom==null ? "" : custCodeDom.trim();
}
//Two additional filters added to run process as per tran date and cust code which will avoid unnesscary update [25/07/17|End]
} }
} }
if(calCriItemSerList.contains(table_no.trim())) if(custCodeDom!=null && custCodeDom.trim().length()>0)
{
custCodeDom="'"+custCodeDom+"'";
if(custCodeDom.contains(",")){
custCodeDom = custCodeDom.replaceAll(",", "','");
}
}
fromDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(fromDateStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
toDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString(toDateStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("custCode::::"+custCode+":::fromDate::::"+fromDate+":::toDate::::"+toDate);
/*if(calCriItemSerList.contains(itemSer.trim()))
{ {
System.out.println("Inside ItemSer true::::["+calCriItemSerList.contains(table_no.trim())+"]"); System.out.println("Inside ItemSer true::::["+calCriItemSerList.contains(itemSer.trim())+"]");
isItemSerLocal=true; isItemSerLocal=true;
} }
else else
{ {
System.out.println("Inside ItemSer false::::["+calCriItemSerList.contains(table_no.trim())+"]"); System.out.println("Inside ItemSer false::::["+calCriItemSerList.contains(itemSer.trim())+"]");
isItemSerLocal=false; isItemSerLocal=false;
}*/
//Modified by santosh to set priceList(14/SEP/2017).[START]
calEnablePrice = dist.getDisparams("999999","ENABLE_SPEC_PRICELIST",conn);
calPriceDivision = dist.getDisparams("999999","SPEC_PRICELIST",conn);
System.out.println("calEnablePrice["+calEnablePrice+"]calPriceDivision["+calPriceDivision+"]");
if (("NULLFOUND".equalsIgnoreCase(calEnablePrice) || calEnablePrice == null || calEnablePrice.trim().length() == 0) )
{
calEnablePrice="N";
} }
if (("NULLFOUND".equalsIgnoreCase(calPriceDivision) || calPriceDivision == null || calPriceDivision.trim().length() == 0) )
sql = "select tran_id,from_date,to_date,cust_code,tran_id__last from cust_stock where pos_code is not null and prd_code=? AND ITEM_SER=?"; {
calEnablePrice="N";
}
System.out.println("calEnablePrice["+calEnablePrice+"]calPriceDivision["+calPriceDivision+"]");
//Modified by santosh to set priceList(14/SEP/2017).[END]
sql = " select tran_id,from_date,to_date,cust_code,tran_id__last,item_ser from cust_stock where pos_code is not null and prd_code=? AND ITEM_SER=? " +
" and tran_date between ? and ? and cust_code in ("+custCodeDom+") ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prd_code); pstmt.setString(1, prdCode);
pstmt.setString(2, table_no); pstmt.setString(2, itemSer);
pstmt.setTimestamp(3, fromDate);
pstmt.setTimestamp(4, toDate);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
...@@ -214,11 +250,27 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -214,11 +250,27 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
prdtoDateTmstmp = rs.getTimestamp("to_date"); prdtoDateTmstmp = rs.getTimestamp("to_date");
custCode = checkNull(rs.getString("cust_code")); custCode = checkNull(rs.getString("cust_code"));
tranIdLast = checkNull(rs.getString("tran_id__last")); tranIdLast = checkNull(rs.getString("tran_id__last"));
checkItemSer = checkNull(rs.getString("item_ser"));
System.out.println("tranId>>"+tranId+" prdFromoDateTmstmp>>"+prdFromoDateTmstmp+" prdtoDateTmstmp>>"+prdtoDateTmstmp+" custCode>>"+custCode); System.out.println("tranId>>"+tranId+" prdFromoDateTmstmp>>"+prdFromoDateTmstmp+" prdtoDateTmstmp>>"+prdtoDateTmstmp+" custCode>>"+custCode);
//Modified by saurabh[13/02/17|Start] //Modified by saurabh[13/02/17|Start]
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp,invoiceMonthsPrevious); thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp,invoiceMonthsPrevious);
System.out.println("thirdMonthDay>>>>>>" + thirdMonthDay); System.out.println("thirdMonthDay>>>>>>" + thirdMonthDay);
//Modified by santosh to set priceList(14/SEP/2017).[START]
if("Y".equalsIgnoreCase(calEnablePrice))
{
if("BR".equalsIgnoreCase(checkItemSer))
{
priceList = calPriceDivision.substring(calPriceDivision.indexOf(",")+1,calPriceDivision.length());
System.out.println("@S@priceList["+priceList+"]");
}
else
{
priceList= calPriceDivision.substring(0,calPriceDivision.indexOf(","));
System.out.println("@S@priceList["+priceList+"]");
}
}
else
{
sql = "select price_list from customer where cust_code =? "; sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode); pstmt1.setString(1, custCode);
...@@ -231,6 +283,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -231,6 +283,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
rs1 = null; rs1 = null;
pstmt1.close(); pstmt1.close();
pstmt1 = null; pstmt1 = null;
}
//Modified by santosh to set priceList(14/SEP/2017).[END]
closingStockMap=new HashMap<String, ClosingStockBean>(); closingStockMap=new HashMap<String, ClosingStockBean>();
sql = " select item_code,cl_stock,CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," + sql = " select item_code,cl_stock,CASE WHEN rate IS NULL THEN 0 ELSE rate END as rate," +
" CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " + " CASE WHEN rate__org IS NULL THEN 0 ELSE rate__org END as rate__org from " +
...@@ -340,15 +394,15 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -340,15 +394,15 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
{ {
isItemFound=false; isItemFound=false;
netAmt=0;netAmtRet=0;netAmtRep=0; netAmt=0;netAmtRet=0;netAmtRep=0;
sreturnCnt = 0; //sreturnCnt = 0;
invoiceId = checkNull(rs2.getString("invoice_id")); invoiceId = checkNull(rs2.getString("invoice_id"));
dlvFlag = checkNull(rs2.getString("dlv_flg")); dlvFlag = checkNull(rs2.getString("dlv_flg"));
refSer = checkNull(rs2.getString("ref_ser")); refSer = checkNull(rs2.getString("ref_ser"));
System.out.println("invoiceId>>>"+invoiceId+">>dlvFlag>>>"+dlvFlag+">>refSer>>"+refSer); System.out.println("invoiceId>>>"+invoiceId+">>dlvFlag>>>"+dlvFlag+">>refSer>>"+refSer);
if("Y".equalsIgnoreCase(dlvFlag)) /*if("Y".equalsIgnoreCase(dlvFlag))
{ {
invoiceIdList = invoiceIdList + "'"+invoiceId.trim() + "',"; invoiceIdList = invoiceIdList + "'"+invoiceId.trim() + "',";
} }*/
/*sql = "SELECT tran_id FROM sreturn WHERE tran_id='"+invoiceId+"'"; /*sql = "SELECT tran_id FROM sreturn WHERE tran_id='"+invoiceId+"'";
pstmt3 = conn.prepareStatement(sql); pstmt3 = conn.prepareStatement(sql);
...@@ -557,16 +611,16 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -557,16 +611,16 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
pstmt2.close(); pstmt2.close();
pstmt2 = null; pstmt2 = null;
if(invoiceIdList.trim().length() > 0) /*if(invoiceIdList.trim().length() > 0)
{ {
selectedInvList = invoiceIdList.substring(0,invoiceIdList.length() - 1); selectedInvList = invoiceIdList.substring(0,invoiceIdList.length() - 1);
} }*/
/* if(clStock>0) /* if(clStock>0)
{*/ {*/
formulaValue=clStock; formulaValue=clStock;
if(!isItemSerLocal) //if(!isItemSerLocal)
{ //{
System.out.println("formulaValue>>"+formulaValue); System.out.println("formulaValue>>"+formulaValue);
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as quantity__stduom,inv.tran_date " sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,itrc.quantity__stduom as quantity__stduom,inv.tran_date "
...@@ -657,8 +711,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -657,8 +711,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
closingValue = closingValue + formulaValue * priceListRate; closingValue = closingValue + formulaValue * priceListRate;
closingValue = getRequiredDcml(closingValue, 3);//cl_value closingValue = getRequiredDcml(closingValue, 3);//cl_value
} }
}else //}else
{ /*{
if(recptInvQty > 0) if(recptInvQty > 0)
{ {
...@@ -688,7 +742,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -688,7 +742,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
} }
else else
{ {
/*invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn); invoiceMonths = dist.getDisparams("999999", "INVOICE_MONTHS", conn);
System.out.println("invoiceMonths>>>>.." + invoiceMonths); System.out.println("invoiceMonths>>>>.." + invoiceMonths);
if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0)) if (("NULLFOUND".equalsIgnoreCase(invoiceMonths) || invoiceMonths == null || invoiceMonths.trim().length() == 0))
{ {
...@@ -699,7 +753,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -699,7 +753,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
} }
System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious); System.out.println("invoiceMonthsPrevious>>>>>" + invoiceMonthsPrevious);
thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious); thirdMonthDay = utlmethd.AddMonths(prdFromoDateTmstmp, invoiceMonthsPrevious);
System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay);*/ System.out.println("thirdMonthDay from method>>>>>>" + thirdMonthDay);
sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,inv.tran_date " + sql = "SELECT inv.invoice_id,itrc.rate__stduom as rate__stduom,inv.tran_date " +
"FROM invoice_trace itrc,invoice inv WHERE itrc.invoice_id=inv.invoice_id " + "FROM invoice_trace itrc,invoice inv WHERE itrc.invoice_id=inv.invoice_id " +
...@@ -723,7 +777,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -723,7 +777,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
pstmt = null; pstmt = null;
if (calRate == 0) if (calRate == 0)
{ {
/*sql = "select price_list from customer where cust_code =? "; sql = "select price_list from customer where cust_code =? ";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode); pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
...@@ -735,7 +789,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -735,7 +789,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
rs1.close(); rs1.close();
rs1 = null; rs1 = null;
pstmt1.close(); pstmt1.close();
pstmt1 = null;*/ pstmt1 = null;
//Commented by Manoj dtd 26/10/2016 //Commented by Manoj dtd 26/10/2016
//openingRate = discmn.pickRate(priceList, sysDatetemp, itemCode, conn); //openingRate = discmn.pickRate(priceList, sysDatetemp, itemCode, conn);
//Changed by Manoj dtd 26/10/2016 //Changed by Manoj dtd 26/10/2016
...@@ -743,9 +797,9 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -743,9 +797,9 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, SYSDATE , ? ) FROM DUAL "; sql = "SELECT DDF_PICK_MAX_SLAB_RATE( ?, SYSDATE , ? ) FROM DUAL ";
pstmt1 = conn.prepareStatement( sql ); pstmt1 = conn.prepareStatement( sql );
pstmt1.setString( 1, priceList ); pstmt1.setString( 1, priceList );
/*pstmt1.setString( 2, sysDate ); pstmt1.setString( 2, sysDate );
pstmt1.setString( 3, genericUtility.getDBDateFormat() ); pstmt1.setString( 3, genericUtility.getDBDateFormat() );
*/pstmt1.setString( 2, itemCode ); pstmt1.setString( 2, itemCode );
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if (rs1.next()) if (rs1.next())
{ {
...@@ -766,7 +820,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -766,7 +820,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
} }
calRate=getRequiredDcml(calRate,3); calRate=getRequiredDcml(calRate,3);
closingValue=getRequiredDcml(clStock*calRate,3); closingValue=getRequiredDcml(clStock*calRate,3);
} }*/
if (clStock > 0) if (clStock > 0)
{ {
closingRate = closingValue / clStock; closingRate = closingValue / clStock;
...@@ -803,7 +857,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -803,7 +857,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3);//sales_value netSecondarySalesValue=getRequiredDcml(netSecondarySalesValue,3);//sales_value
System.out.println("netSecondarySalesValue>>>>>"+netSecondarySalesValue); System.out.println("netSecondarySalesValue>>>>>"+netSecondarySalesValue);
grossSecondarySalesValue=(opStkDom*rateOrgOld)+recptInvValue+recptReplVal+recptFreeValue-recptRetVal-closingValue; grossSecondarySalesValue=(opStkDom*rateOld)+recptInvValue+recptReplVal+recptFreeValue-recptRetVal-closingValue;
grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3); grossSecondarySalesValue=getRequiredDcml(grossSecondarySalesValue,3);
System.out.println("grossSecondarySalesValue>>>>>"+grossSecondarySalesValue); System.out.println("grossSecondarySalesValue>>>>>"+grossSecondarySalesValue);
...@@ -814,7 +868,14 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -814,7 +868,14 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
{ {
grossSecondaryRate=0.0; grossSecondaryRate=0.0;
} }
if(grossSecondaryRate<0)
{
grossSecondaryRate=0.0;
}
else
{
grossSecondaryRate=getRequiredDcml(grossSecondaryRate,3);//rate__org grossSecondaryRate=getRequiredDcml(grossSecondaryRate,3);//rate__org
}
System.out.println("grossSecondaryRate>>>"+grossSecondaryRate); System.out.println("grossSecondaryRate>>>"+grossSecondaryRate);
//End by chandrashekar on 29-dec-2015 //End by chandrashekar on 29-dec-2015
salesQtyCal = opStkDom + (recptInvQty + recptReplQty) - (recptRetQty + retQtyFreeDom) - clStock;//sales salesQtyCal = opStkDom + (recptInvQty + recptReplQty) - (recptRetQty + retQtyFreeDom) - clStock;//sales
...@@ -835,7 +896,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -835,7 +896,8 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
" transit_repl_val=? , transit_free_val=? , " + " transit_repl_val=? , transit_free_val=? , " +
" purc_rcp=? ,purc_rcp__repl=? ,purc_rcp__free=? ,purc_ret=? ,purc_ret__free=? , " + " purc_rcp=? ,purc_rcp__repl=? ,purc_rcp__free=? ,purc_ret=? ,purc_ret__free=? , " +
" transit_qty=? ,transit_qty__repl=? ,transit_qty__free=? ," + " transit_qty=? ,transit_qty__repl=? ,transit_qty__free=? ," +
" sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? ,primary_sales=? " + " sales=? ,rate=? ,rate__org=? ,sales__org=? ,cl_value=? ,sales_value=? ,op_value=? ,primary_sales=? ,op_stock=? , " +
" CHG_DATE=SYSDATE ,CHG_TERM=? ,CHG_USER=? " +
" where tran_id=? and item_code=? "; " where tran_id=? and item_code=? ";
pstmt2 = conn.prepareStatement(sql); pstmt2 = conn.prepareStatement(sql);
pstmt2.setDouble(1, recptInvValue);//rcp_val pstmt2.setDouble(1, recptInvValue);//rcp_val
...@@ -862,8 +924,11 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -862,8 +924,11 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
pstmt2.setDouble(22, netSecondarySalesValue );//sales_value pstmt2.setDouble(22, netSecondarySalesValue );//sales_value
pstmt2.setDouble(23, opValue );//op_value pstmt2.setDouble(23, opValue );//op_value
pstmt2.setDouble(24, primarySalesAll );//primary_sales pstmt2.setDouble(24, primarySalesAll );//primary_sales
pstmt2.setString(25, tranId); pstmt2.setDouble(25, opStkDom );//op_stock
pstmt2.setString(26, itemCode); pstmt2.setString(26, chgTerm);
pstmt2.setString(27, loginCode);
pstmt2.setString(28, tranId);
pstmt2.setString(29, itemCode);
UpdCnt = pstmt2.executeUpdate(); UpdCnt = pstmt2.executeUpdate();
if(UpdCnt>0) if(UpdCnt>0)
{ {
...@@ -921,7 +986,6 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -921,7 +986,6 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
errString = itmDBAccessEJB.getErrorString("", "VTES3RLBCK","", "", conn); errString = itmDBAccessEJB.getErrorString("", "VTES3RLBCK","", "", conn);
conn.rollback(); conn.rollback();
} }
retBuf = null;
if (conn != null) if (conn != null)
{ {
conn.close(); conn.close();
...@@ -941,13 +1005,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -941,13 +1005,7 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
private String checkNull(String input) private String checkNull(String input)
{ {
if (input == null) { input = input==null ? "" : input.trim();
input = "";
}
else
{
input = input.trim();
}
return input; return input;
} }
...@@ -991,7 +1049,5 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es ...@@ -991,7 +1049,5 @@ public class Es3HDataUpdPrc extends ProcessEJB implements Es3HDataUpdPrcLocal,Es
public void setOpeningRateOrg(double openingRateOrg) { public void setOpeningRateOrg(double openingRateOrg) {
this.openingRateOrg = openingRateOrg; this.openingRateOrg = openingRateOrg;
} }
} }
}// END OF EJB }// END OF EJB
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class PrimarySalesConsolidationIC extends ValidatorEJB implements PrimarySalesConsolidationICLocal , PrimarySalesConsolidationICRemote
{
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{
System.out.println("In wfValData");
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = wfValData(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception : [PrimarySalesConsolidationIC][wfValData(String currFrmXmlStr)] : ==>\n" + e.getMessage());
}
return errString;
}
public String wfValData(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
E12GenericUtility genericUtility= new E12GenericUtility();
String errString = "" , loginSiteCode = "" , userId ="" , isPrdClosed = "",overWrite="" ;
String childNodeName = "";
String sql = "";
int noOfChilds = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0,count=0,unConfCnt=0,excnt=0;
ConnDriver connDriver = null;
Node childNode = null;
String itemSer="" , prdCode = "" ,maxPrdCode="" ,countryCode="" ;
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
try {
System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData PrimarySalesConsolidationIC :::");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
System.out.println("**************loginCode************" + userId);
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail"+ currentFormNo);
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if ("item_ser".equalsIgnoreCase(childNodeName))
{
itemSer = genericUtility.getColumnValue("item_ser", currDom);
System.out.println("wfValData>>itemSer>>"+itemSer);
if(itemSer == null || itemSer.trim().length()==0 )
{
errString = itmDBAccessEJB.getErrorString("item_ser","VMNULLDIV",userId);
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM ITEMSER WHERE ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errString = itmDBAccessEJB.getErrorString("item_ser","VTINVDIV",userId);
break;
}
}
}
else if ("overwrite".equalsIgnoreCase(childNodeName))
{
overWrite = genericUtility.getColumnValue("overwrite", currDom);
System.out.println("wfValData>>overWrite>>"+overWrite);
if("N".equalsIgnoreCase(overWrite))
{
sql = " SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND ITEM_SER=? AND SOURCE='S' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("COUNT");
}
if(count > 0)
{
errString = itmDBAccessEJB.getErrorString("prd_code","VTDATA",userId);
break ;
}
}
}
else if ("prd_code".equalsIgnoreCase(childNodeName))
{
prdCode = genericUtility.getColumnValue("prd_code", currDom);
itemSer = genericUtility.getColumnValue("item_ser", currDom);
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("wfValData>>prdCode>>"+prdCode+">>itemSer"+itemSer);
if(prdCode == null || prdCode.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("prd_code","VMNULLPRD ",userId);
break ;
}
else
{
sql = " SELECT COUNT(*) FROM PERIOD A , PERIOD_TBL B WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode);
pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (cnt == 0)
{
System.out.println("Error :Period not exist in period_tbl master ");
errString = itmDBAccessEJB.getErrorString("","VMINVPRDTB",userId);
break ;
}
else
{
sql = "SELECT B.PRD_CLOSED FROM PERIOD A , PERIOD_TBL B WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim());
pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
isPrdClosed = rs.getString("PRD_CLOSED");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if("N".equalsIgnoreCase(isPrdClosed))
{
errString = itmDBAccessEJB.getErrorString("","VMPRDNCL",userId);
break ;
}
else
{
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxPrdCode = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(!prdCode.equalsIgnoreCase(maxPrdCode))
{
//max period check
errString = itmDBAccessEJB.getErrorString("","VTINVPCD",userId);
break ;
}
else
{
sql = " SELECT COUNT(*) AS COUNT FROM SALES_FACT WHERE PRD_CODE = ? and ITEM_SER=? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2,itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
excnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (excnt == 0)
{
System.out.println("No record found ");
errString = itmDBAccessEJB.getErrorString("","VTNULLRCD",userId);
break ;
}
}
}
}
}
}
}
}
break;
}
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if ((conn != null) && (!conn.isClosed()))
conn.close();
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
System.out.println("XmlString :::::::::: "+xmlString);
System.out.println("XmlString1 :::::::::: "+xmlString1);
System.out.println("XmlString2 :::::::::: "+xmlString2);
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
System.out.println("Dom ::::::: "+dom);
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
dom1 = parseString(xmlString1);
System.out.println("Dom1 ::::::: "+dom1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
dom2 = parseString(xmlString2);
System.out.println("Dom2 ::::::: "+dom2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext,currentColumn, editFlag, xtraParams);
} catch (Exception e) {
System.out.println("Exception : [SalesConsolidation] :==>\n"+ e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException
{
E12GenericUtility genericUtility= new E12GenericUtility();
int currentFormNo = 0;
StringBuffer valueXmlString = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null, columnValue = "",maxPrdCode="",itemSer="",sql="",countryCode="",loginSiteCode="";
int ctr = 0, childNodeListLength = 0 ;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = null;
try
{
if (objContext != null && objContext.trim().length() > 0) {
currentFormNo = Integer.parseInt(objContext);
}
currentColumn = checkNull(currentColumn);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
switch (currentFormNo)
{
case 1:
{
System.out.println("Inside Case 1 Of Itemchange");
parentNodeList = currDom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
/*do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr++;
}while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));*/
System.out.println(" currentColumn : "+ currentColumn);
System.out.println("current form::::::::::::" + currentFormNo);
if ( "itm_default".equalsIgnoreCase(currentColumn))
{
valueXmlString.append("<prd_code>").append("").append("</prd_code>");
valueXmlString.append("<item_ser>").append("").append("</item_ser>");
valueXmlString.append("<overwrite>").append("<![CDATA[N]]>").append("</overwrite>");
}
else if ("item_ser".equalsIgnoreCase(currentColumn))
{
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
System.out.println("itemSer>>>"+itemSer);
if(itemSer.trim().length()>0){
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxPrdCode = checkNull(rs.getString(1));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(maxPrdCode.length()>0)
{
valueXmlString.append("<prd_code>").append("<![CDATA[" + maxPrdCode + "]]>").append("</prd_code>");
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
valueXmlString.append("</Detail1>\r\n");
}
break;
}
}
catch (Exception e)
{
try
{
e.printStackTrace();
throw new ITMException(e);
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
}
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 e) {
e.printStackTrace();
throw new ITMException(e);
}
}
valueXmlString.append("</Root>\r\n");
return valueXmlString.toString();
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface PrimarySalesConsolidationICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface PrimarySalesConsolidationICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
@Stateless
public class PrimarySalesConsolidationPrc extends ProcessEJB implements PrimarySalesConsolidationPrcLocal , PrimarySalesConsolidationPrcRemote
{
E12GenericUtility genericUtility= new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
@Override
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{
String rtStr = "";
Document dom = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() != 0) {
dom = genericUtility.parseString(xmlString);
System.out.println("Process Dom::::::::::::::::"+dom );
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
dom2 = genericUtility.parseString(xmlString2);
System.out.println("Process Dom2::::::::::::::::"+dom2 );
}
rtStr = process(dom, dom2, windowName, xtraParams);
} catch (Exception e) {
System.out.println("::::"+this.getClass().getSimpleName()+"::processDataString" + e.getMessage());
e.printStackTrace();
}
return rtStr;
}
@Override
public String process(Document dom, Document dom2, String windowName,String xtraParams) throws RemoteException, ITMException {
String errString = "", prdCode = "" , itemSer = "" , tranId = "" , loginSiteCode = "" , sql = "" , sql1 = "" , userId = "" ,
unit = "" , empCode = "" , posCode = "" , custCode = "" , itemCode = "" , versionId = ""
, stanCode = "" , terrCode = "" , terrDescr = "" ,countryCode = "";
double netSalesQty=0.0,netSalesVal=0.0,lycmSalesQty=0.0,lycmSalesVal=0.0;
Connection conn=null;
int cnt = 0 , updCnt = 0 ;
String chgTerm="",chgUser="",overWrite="";
PreparedStatement pstmt = null , pstmt1 = null;
ResultSet rs = null , rs1 = null;
Timestamp frDate = null , toDate = null ;
System.out.println("Current DOM [" + genericUtility.serializeDom(dom) + "]");
System.out.println("Header DOM [" + genericUtility.serializeDom(dom2) + "]");
java.sql.Date sysDate=null;
try {
System.out.println("In process Sales Consolidation:::");
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "userID"));
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom));
itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom));
overWrite = checkNull(genericUtility.getColumnValue("overwrite", dom));
System.out.println("prdCode>>>"+prdCode+">>itemSer>>"+itemSer+">>overWrite>>"+overWrite);
System.out.println("userId : "+userId);
System.out.println("xtraParams ::: "+xtraParams);
ConnDriver con = new ConnDriver();
conn = con.getConnectDB("DriverITM");
sql1 = "select sysdate from dual";
pstmt = conn.prepareStatement(sql1);
rs = pstmt.executeQuery();
if (rs.next()) {
sysDate = rs.getDate(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " SELECT FR_DATE,TO_DATE FROM PERIOD_TBL WHERE PRD_CODE=? AND PRD_TBLNO=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
frDate = rs.getTimestamp("FR_DATE");
toDate = rs.getTimestamp("TO_DATE");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("frDate :::"+frDate+">>toDate :::"+toDate);
sql = "SELECT VERSION_ID FROM VERSION WHERE EFF_FROM < = ? AND VALID_UPTO > = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, frDate);
pstmt.setTimestamp(2, toDate);
rs = pstmt.executeQuery();
if(rs.next())
{
versionId = checkNull(rs.getString("VERSION_ID"));
System.out.println("versionId ::: "+versionId);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if("Y".equalsIgnoreCase(overWrite)){
cnt=0;
sql = "DELETE FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND ITEM_SER=? AND SOURCE='S'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
cnt=pstmt.executeUpdate();
System.out.println("Delete count>>"+cnt);
pstmt.close();
pstmt = null;
}
System.out.println("Inserting data ");
sql=" SELECT S.CUST_CODE,S.PRD_CODE,S.ITEM_CODE,S.ITEM_SER,S.STAN_CODE,S.NET_SALES_QTY,S.NET_SALES_VAL,S.LYCM_SALES_QTY,S.LYCM_SALES_VAL,CS.POS_CODE,CS.EMP_CODE " +
" FROM SALES_FACT S LEFT OUTER JOIN CUST_STOCK CS ON CS.PRD_CODE=S.PRD_CODE AND CS.CUST_CODE=S.CUST_CODE AND CS.ITEM_SER=S.ITEM_SER " +
" WHERE S.PRD_CODE=? AND S.ITEM_SER=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
rs = pstmt.executeQuery();
while(rs.next())
{
custCode = checkNull(rs.getString("CUST_CODE"));
prdCode = checkNull(rs.getString("PRD_CODE"));
itemCode = checkNull(rs.getString("ITEM_CODE"));
itemSer = checkNull(rs.getString("ITEM_SER"));
stanCode = checkNull(rs.getString("STAN_CODE"));
netSalesQty = rs.getDouble("NET_SALES_QTY");
netSalesVal = rs.getDouble("NET_SALES_VAL");
lycmSalesQty = rs.getDouble("LYCM_SALES_QTY");
lycmSalesVal = rs.getDouble("LYCM_SALES_VAL");
posCode = checkNull(rs.getString("POS_CODE"));
empCode = checkNull(rs.getString("EMP_CODE"));
System.out.println("prdCode ::: "+prdCode+">>custCode ::: "+custCode);
System.out.println("itemSer ::: "+itemSer+">>itemCode ::: "+itemCode);
System.out.println("stanCode ::: "+stanCode);
System.out.println("netSalesQty ::: "+netSalesQty+">>netSalesVal ::: "+netSalesVal);
System.out.println("lycmSalesQty ::: "+lycmSalesQty+">>lycmSalesVal ::: "+lycmSalesVal);
System.out.println("posCode :::"+posCode+">>empCode :::"+empCode);
unit="";terrCode="";terrDescr="";
sql1="select UNIT from item where item_code=?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, itemCode);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
unit = checkNull(rs1.getString("UNIT"));
}
System.out.println("unit>>"+unit);
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
sql1 = " SELECT A.POOL_CODE , B.LEVEL_CODE , B.LEVEL_DESCR FROM ORG_STRUCTURE A , HIERARCHY " +
" B WHERE A.POOL_CODE = B.LEVEL_CODE AND A.VERSION_ID = ? AND A.POS_CODE = ? AND A.TABLE_NO = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, versionId);
pstmt1.setString(2, posCode);
pstmt1.setString(3, itemSer);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
terrCode = checkNull(rs1.getString("LEVEL_CODE"));
terrDescr = checkNull(rs1.getString("LEVEL_DESCR"));
System.out.println("terrCode ::: "+terrCode+ " terrDescr :::: "+terrDescr);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
SalesConsolidationPrc scp =new SalesConsolidationPrc();
tranId=scp.generateTranIDForSalesConsolidationProcess("sales_consolidate", loginSiteCode, itemSer, conn);
sql1="insert into SALES_CONSOLIDATION(TRAN_ID,TRAN_DATE,CUST_CODE,PRD_CODE,TERR_CODE,TERR_DESCR,VERSION_ID,POS_CODE," +
"EMP_CODE,SOURCE,ITEM_CODE,UNIT,ITEM_SER,ITEM_SER_NEW,STAN_CODE,STAN_CODE_NEW," +
"NET_SALES_QTY,NET_SALES_VAL,LYCM_SALES_QTY,LYCM_SALES_VAL," +
"ADD_DATE,ADD_USER,ADD_TERM,CHG_DATE,CHG_USER,CHG_TERM)" +
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
pstmt1.setDate(2, sysDate);
pstmt1.setString(3, custCode);
pstmt1.setString(4, prdCode);
pstmt1.setString(5, terrCode);
pstmt1.setString(6, terrDescr);
pstmt1.setString(7, versionId);
pstmt1.setString(8, posCode);
pstmt1.setString(9, empCode);
pstmt1.setString(10, "S");
pstmt1.setString(11, itemCode);
pstmt1.setString(12, unit);
pstmt1.setString(13, itemSer);
pstmt1.setString(14, itemSer);
pstmt1.setString(15, stanCode);
pstmt1.setString(16, stanCode);
pstmt1.setDouble(17, netSalesQty);
pstmt1.setDouble(18, netSalesVal);
pstmt1.setDouble(19, lycmSalesQty);
pstmt1.setDouble(20, lycmSalesVal);
pstmt1.setDate(21, sysDate);
pstmt1.setString(22, chgUser);
pstmt1.setString(23, chgTerm);
pstmt1.setDate(24, sysDate);
pstmt1.setString(25, chgUser);
pstmt1.setString(26, chgTerm);
updCnt = pstmt1.executeUpdate();
if(updCnt>0)
{
errString="";
System.out.println("Data inserted!!!");
}
else
{
System.out.println("Data insertion fail!!!");
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
pstmt1.close();
pstmt1= null;
}
rs.close();
rs=null;
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
System.out.println("::::Exception::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
e.printStackTrace();
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
finally
{
try
{
if (errString == null || errString.trim().length()==0)
{
System.out.println("Connection Commited");
errString = itmDBAccessEJB.getErrorString("", "VTDATASUCC","", "", conn);
conn.commit();
}
else
{
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL","", "", conn);
}
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
}
conn = null;
} catch (Exception d) {
d.printStackTrace();
}
}
return errString;
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface PrimarySalesConsolidationPrcLocal extends ProcessLocal {
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface PrimarySalesConsolidationPrcRemote extends ProcessRemote{
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class SalesConsolidateIC extends ValidatorEJB implements SalesConsolidateICLocal , SalesConsolidateICRemote{
E12GenericUtility genericUtility= new E12GenericUtility();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{
System.out.println("In wfValData");
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = wfValData(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception : [SalesConsolidateIC][wfValData(String currFrmXmlStr)] : ==>\n" + e.getMessage());
}
return errString;
}
public String wfValData(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
int count = 0;
String errString = "" , loginSiteCode = "" , userId ="" , errCode = "" , errorType = "" ;
String custCode = "" , itemCode = "" , unit = "" , posCode = "" , versionId = "" , terrCode = "" , empCode = "" ;
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
String childNodeName = "";
String sql = "";
int noOfChilds = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0;
ConnDriver connDriver = null;
Node childNode = null;
String itemSer="" , prdCode = "" ;
System.out.println("Current DOM [" + genericUtility.serializeDom(currDom) + "]");
System.out.println("Header DOM [" + genericUtility.serializeDom(hdrDom) + "]");
System.out.println("Dom All [" + genericUtility.serializeDom(allDom) + "]");
try {
System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
//conn = getConnection();
System.out.println("In wfValData Secondary Sales Consolidate:::");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
System.out.println("**************loginCode************" + userId);
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail1");
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if("cust_code".equalsIgnoreCase(childNodeName))
{
custCode = genericUtility.getColumnValue("cust_code", currDom);
System.out.println("CustCode :::::: "+custCode);
if(custCode == null || custCode.trim().length() == 0)
{
errList.add("VTNULLCUST");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTERRCUST");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if ("prd_code".equalsIgnoreCase(childNodeName))
{
prdCode = genericUtility.getColumnValue("prd_code", currDom);
System.out.println("Period Code :::::::: "+prdCode);
if(prdCode==null || prdCode.trim().length()==0)
{
errList.add("VMNULLPRD");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM PERIOD WHERE CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTERRPRD");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if("emp_code".equalsIgnoreCase(childNodeName))
{
empCode = genericUtility.getColumnValue("emp_code", currDom);
System.out.println("empCode :::::: "+empCode);
if(empCode == null || empCode.trim().length() == 0)
{
errList.add("VTEMPNUL");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM EMPLOYEE WHERE EMP_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTERREMP");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if("item_ser".equalsIgnoreCase(childNodeName))
{
itemSer = genericUtility.getColumnValue("item_ser", currDom);
System.out.println("itemSer ::::::: "+itemSer);
if(itemSer == null || itemSer.trim().length()==0 )
{
errList.add("VMNULLSER");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM ITEMSER WHERE ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTINVDIV");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if("version_id".equalsIgnoreCase(childNodeName))
{
versionId = checkNull(genericUtility.getColumnValue("version_id", currDom));
posCode = genericUtility.getColumnValue("pos_code", currDom);
itemSer = genericUtility.getColumnValue("item_ser", currDom);
System.out.println("versionId :::::: "+versionId);
if(versionId == null || versionId.length() == 0 )
{
errList.add("VTNULVERID");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM VERSION WHERE VERSION_ID = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, versionId);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTERRVERID");
errFields.add(childNodeName.toLowerCase());
}
else
{
System.out.println("posCode :::::: "+posCode);
System.out.println("itemSer :::::: "+itemSer);
if(posCode != null && itemSer != null)
{
sql = "SELECT COUNT(*) AS COUNT FROM ORG_STRUCTURE WHERE VERSION_ID = ? AND POS_CODE = ? AND TABLE_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, versionId);
pstmt.setString(2, posCode);
pstmt.setString(3, itemSer);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTNULLRCD");
errFields.add(childNodeName.toLowerCase());
}
}
}
}
}
else if("terr_code".equalsIgnoreCase(childNodeName))
{
terrCode = checkNull(genericUtility.getColumnValue("terr_code", currDom));
versionId = checkNull(genericUtility.getColumnValue("version_id", currDom));
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
System.out.println("terrCode>>"+terrCode+">>versionId>>"+versionId+">>itemSer"+itemSer);
System.out.println("terrCode :::::: "+terrCode);
if(terrCode == null || terrCode.trim().length() == 0)
{
errList.add("VTNULTERR");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM HIERARCHY WHERE LEVEL_CODE = ? AND VERSION_ID=? AND TABLE_NO=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, terrCode);
pstmt.setString(2, versionId);
pstmt.setString(3, itemSer);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTNERRTERR");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if("item_code".equalsIgnoreCase(childNodeName))
{
itemCode = genericUtility.getColumnValue("item_code", currDom);
System.out.println("itemCode :::::: "+itemCode);
if(itemCode == null || itemCode.trim().length() == 0)
{
errList.add("VTNULLITCD");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM ITEM WHERE ITEM_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTERRITCD");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if("unit".equalsIgnoreCase(childNodeName))
{
unit = genericUtility.getColumnValue("unit", currDom);
System.out.println("unit :::::: "+unit);
if(unit == null || unit.trim().length() == 0)
{
errList.add("VTUNTNUL");
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM ITEM WHERE UNIT = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, unit);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VTUNTINV");
errFields.add(childNodeName.toLowerCase());
}
}
}
}
}
break;
}
int errListSize = errList.size();
cnt = 0;
String errFldName = "";
if ((errList != null) && (errListSize > 0))
{
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String) errList.get(cnt);
errFldName = (String) errFields.get(cnt);
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........." + errStringXml);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer("");
}
errString = errStringXml.toString();
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if ((conn != null) && (!conn.isClosed()))
conn.close();
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
private String errorType(Connection conn, String errorCode)
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next())
msgType = rs.getString("MSG_TYPE");
}
catch (Exception ex)
{
ex.printStackTrace();
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return msgType;
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
System.out.println("XmlString :::::::::: "+xmlString);
System.out.println("XmlString1 :::::::::: "+xmlString1);
System.out.println("XmlString2 :::::::::: "+xmlString2);
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
System.out.println("Dom ::::::: "+dom);
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
dom1 = parseString(xmlString1);
System.out.println("Dom1 ::::::: "+dom1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
dom2 = parseString(xmlString2);
System.out.println("Dom2 ::::::: "+dom2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext,currentColumn, editFlag, xtraParams);
} catch (Exception e) {
System.out.println("Exception : [SalesConsolidate] :==>\n"+ e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException
{
int currentFormNo = 0;
StringBuffer valueXmlString = null;
String chgDate = "" , chgUser = "" , chgTerm = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null, columnValue = "";
int ctr = 0, childNodeListLength = 0 ;
String empCode = "" , tranDate = "" , unit="", custName = "" , empName="" , custCode = "" , itemCode = "" , terrCode="" , terrDescr="" , itemDescr = "" , sql = "";
String versionId="",itemSer="";
Timestamp sysDate = null ;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = null;
try {
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility.getApplDateFormat());
String sysDateStr = sdf1.format(currentDate.getTime());
sysDate = Timestamp.valueOf(genericUtility.getValidDateString(sysDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat())
+ " 00:00:00.0");
System.out.println("Current DOM [" + genericUtility.serializeDom(dom) + "]");
System.out.println("Header DOM [" + genericUtility.serializeDom(dom1) + "]");
System.out.println("Dom All [" + genericUtility.serializeDom(dom2) + "]");
System.out.println("CURRENT COLUMN:::::" + currentColumn);
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
java.util.Date currDate = new java.util.Date();
chgDate = sdf.format(currDate);
System.out.println("chgDate...[" + chgDate + "");
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
tranDate = sdf.format(currDate);
if (objContext != null && objContext.trim().length() > 0) {
currentFormNo = Integer.parseInt(objContext);
}
currentColumn = checkNull(currentColumn).trim();
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("Driver");
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
switch (currentFormNo) {
case 1:
{
System.out.println("Inside Case 1 Of Itemchange");
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do {
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equals(currentColumn)) {
if (childNode.getFirstChild() != null) {
columnValue = childNode.getFirstChild().getNodeValue().trim();
}
}
ctr++;
} while (ctr < childNodeListLength && !childNodeName.equals(currentColumn));
System.out.println("current form::::::::::::" + currentFormNo);
if ( "itm_default".equalsIgnoreCase(currentColumn))
{
valueXmlString.append("<chg_date>").append("<![CDATA[" + chgDate + "]]>").append("</chg_date>");
valueXmlString.append("<chg_term>").append("<![CDATA[" + chgTerm + "]]>").append("</chg_term>");
valueXmlString.append("<chg_user>").append("<![CDATA[" + chgUser + "]]>").append("</chg_user>");
valueXmlString.append("<tran_date>").append("<![CDATA[" + tranDate + "]]>").append("</tran_date>");
}
else if("emp_code".equalsIgnoreCase(currentColumn))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
System.out.println("empCode ::::: "+empCode);
if( empCode.length() > 0 )
{
sql = " SELECT EMP_FNAME||' '||EMP_MNAME||' '||EMP_LNAME AS EMP_NAME FROM EMPLOYEE WHERE EMP_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if (rs.next())
{
empName = checkNull(rs.getString("EMP_NAME"));
System.out.println("empName :" +empName );
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<emp_name>").append("<![CDATA[" + empName + "]]>").append("</emp_name>");
}
else
{
valueXmlString.append("<emp_name>").append("<![CDATA[]]>").append("</emp_name>");
}
}
else if ("cust_code".equalsIgnoreCase(currentColumn))
{
custCode = checkNull(genericUtility.getColumnValue("cust_code", dom));
System.out.println("custCode ::::: "+custCode);
if( custCode.length() > 0 )
{
sql = " SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
custName = checkNull(rs.getString("CUST_NAME"));
System.out.println("custName :" +custName );
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<cust_name>").append("<![CDATA[" + custName + "]]>").append("</cust_name>");
}
else
{
valueXmlString.append("<cust_name>").append("<![CDATA[]]>").append("</cust_name>");
}
}
else if ("item_code".equalsIgnoreCase(currentColumn))
{
itemCode = checkNull(genericUtility.getColumnValue("item_code", dom));
System.out.println("itemCode ::::: "+itemCode);
if( itemCode.length() > 0 )
{
sql = " SELECT DESCR,UNIT FROM ITEM WHERE ITEM_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
if (rs.next())
{
itemDescr = checkNull(rs.getString("DESCR"));
unit = checkNull(rs.getString("UNIT"));
System.out.println("itemDescr :" +itemDescr );
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<item_descr>").append("<![CDATA[" + itemDescr + "]]>").append("</item_descr>");
valueXmlString.append("<unit>").append("<![CDATA[" + unit + "]]>").append("</unit>");
}
else
{
valueXmlString.append("<item_descr>").append("<![CDATA[]]>").append("</item_descr>");
valueXmlString.append("<unit>").append("<![CDATA[]]>").append("</unit>");
}
}
else if("terr_code".equalsIgnoreCase(currentColumn))
{
terrCode = checkNull(genericUtility.getColumnValue("terr_code", dom));
versionId = checkNull(genericUtility.getColumnValue("version_id", dom));
itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom));
System.out.println("terrCode>>"+terrCode+">>versionId>>"+versionId+">>itemSer"+itemSer);
if(terrCode.length()>0){
sql = "SELECT LEVEL_DESCR FROM HIERARCHY WHERE LEVEL_CODE =? AND VERSION_ID=? AND TABLE_NO=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, terrCode);
pstmt.setString(2, versionId);
pstmt.setString(3, itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
terrDescr = checkNull(rs.getString("LEVEL_DESCR"));
}
System.out.println("terrCode ::: "+terrCode+ " terrDescr :::: "+terrDescr);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
valueXmlString.append("<terr_descr>").append("<![CDATA["+terrDescr+"]]>").append("</terr_descr>");
}
else
{
valueXmlString.append("<terr_descr>").append("<![CDATA[]]>").append("</terr_descr>");
}
}
}
valueXmlString.append("</Detail1>");
break;
}
} catch (Exception e) {
try {
e.printStackTrace();
throw new ITMException(e);
} catch (Exception ex) {
ex.printStackTrace();
throw new ITMException(ex);
}
} 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 e) {
e.printStackTrace();
throw new ITMException(e);
}
}
valueXmlString.append("</Root>\r\n");
return valueXmlString.toString();
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface SalesConsolidateICLocal extends ValidatorLocal{
public String wfValData(String currXmlDataStr, String hdrXmlDataStr, String allXmlDataStr, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currDom, Document hdrDom, Document allDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface SalesConsolidateICRemote extends ValidatorRemote{
public String wfValData(String currXmlDataStr, String hdrXmlDataStr, String allXmlDataStr, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document currDom, Document hdrDom, Document allDom, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class SalesConsolidationIC extends ValidatorEJB implements SalesConsolidationICLocal , SalesConsolidationICRemote
{
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{
System.out.println("In wfValData");
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = wfValData(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception : [SalesConsolidationIC][wfValData(String currFrmXmlStr)] : ==>\n" + e.getMessage());
}
return errString;
}
public String wfValData(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
E12GenericUtility genericUtility= new E12GenericUtility();
String errString = "" , loginSiteCode = "" , userId ="" , isPrdClosed = "",overWrite="" ;
String childNodeName = "";
String sql = "";
int noOfChilds = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0,count=0,unConfCnt=0,excnt=0;
ConnDriver connDriver = null;
Node childNode = null;
String itemSer="" , prdCode = "" ,maxPrdCode="" ,countryCode="" ;
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
try {
System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData SalesConsolidationIC :::");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
System.out.println("**************loginCode************" + userId);
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail"+ currentFormNo);
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if ("item_ser".equalsIgnoreCase(childNodeName))
{
itemSer = genericUtility.getColumnValue("item_ser", currDom);
System.out.println("wfValData>>itemSer>>"+itemSer);
if(itemSer == null || itemSer.trim().length()==0 )
{
errString = itmDBAccessEJB.getErrorString("item_ser","VMNULLDIV",userId);
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM ITEMSER WHERE ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Count: " + count);
if (count == 0)
{
errString = itmDBAccessEJB.getErrorString("item_ser","VTINVDIV",userId);
break;
}
}
}
else if ("overwrite".equalsIgnoreCase(childNodeName))
{
overWrite = genericUtility.getColumnValue("overwrite", currDom);
System.out.println("wfValData>>overWrite>>"+overWrite);
if("N".equalsIgnoreCase(overWrite))
{
sql = " SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND ITEM_SER=? AND SOURCE='E' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt("COUNT");
}
if(count > 0)
{
errString = itmDBAccessEJB.getErrorString("prd_code","VTDATA",userId);
break ;
}
}
}
else if ("prd_code".equalsIgnoreCase(childNodeName))
{
prdCode = genericUtility.getColumnValue("prd_code", currDom);
itemSer = genericUtility.getColumnValue("item_ser", currDom);
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("wfValData>>prdCode>>"+prdCode+">>itemSer"+itemSer);
if(prdCode == null || prdCode.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("prd_code","VMNULLPRD ",userId);
break ;
}
else
{
sql = " SELECT COUNT(*) FROM PERIOD A , PERIOD_TBL B WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode);
pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (cnt == 0)
{
System.out.println("Error :Period not exist in period_tbl master ");
errString = itmDBAccessEJB.getErrorString("","VMINVPRDTB",userId);
break ;
}
else
{
sql = "SELECT B.PRD_CLOSED FROM PERIOD A , PERIOD_TBL B WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim());
pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
isPrdClosed = rs.getString("PRD_CLOSED");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if("N".equalsIgnoreCase(isPrdClosed))
{
errString = itmDBAccessEJB.getErrorString("","VMPRDNCL",userId);
break ;
}
else
{
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxPrdCode = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(!prdCode.equalsIgnoreCase(maxPrdCode))
{
//max period check
errString = itmDBAccessEJB.getErrorString("","VTINVPCD",userId);
break ;
}
else
{
sql = " SELECT COUNT(*) AS COUNT FROM CUST_STOCK A JOIN CUST_STOCK_DET B ON A.TRAN_ID = B.TRAN_ID " +
" JOIN CUSTOMER D ON D.CUST_CODE = A.CUST_CODE WHERE A.PRD_CODE = ? and A.ITEM_SER=? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2,itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
excnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (excnt >= 0)
{
sql = "SELECT COUNT(*) AS COUNT FROM CUST_STOCK WHERE PRD_CODE = ? AND ITEM_SER=? AND STATUS='O' AND CONFIRMED='N'" ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2,itemSer);
rs = pstmt.executeQuery();
if(rs.next())
{
unConfCnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(unConfCnt>0)
{
System.out.println("Unconfirmed records found ");
errString = itmDBAccessEJB.getErrorString("","VTINVRCD",userId);
break ;
}
}
else
{
System.out.println("No record found ");
errString = itmDBAccessEJB.getErrorString("","VTNULLRCD",userId);
break ;
}
}
}
}
}
}
}
}
break;
}
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if ((conn != null) && (!conn.isClosed()))
conn.close();
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
System.out.println("XmlString :::::::::: "+xmlString);
System.out.println("XmlString1 :::::::::: "+xmlString1);
System.out.println("XmlString2 :::::::::: "+xmlString2);
try
{
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
System.out.println("Dom ::::::: "+dom);
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
dom1 = parseString(xmlString1);
System.out.println("Dom1 ::::::: "+dom1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
dom2 = parseString(xmlString2);
System.out.println("Dom2 ::::::: "+dom2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext,currentColumn, editFlag, xtraParams);
} catch (Exception e) {
System.out.println("Exception : [SalesConsolidation] :==>\n"+ e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException
{
E12GenericUtility genericUtility= new E12GenericUtility();
int currentFormNo = 0;
StringBuffer valueXmlString = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null, columnValue = "",maxPrdCode="",itemSer="",sql="",countryCode="",loginSiteCode="";
int ctr = 0, childNodeListLength = 0 ;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = null;
try
{
if (objContext != null && objContext.trim().length() > 0) {
currentFormNo = Integer.parseInt(objContext);
}
currentColumn = checkNull(currentColumn);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
switch (currentFormNo)
{
case 1:
{
System.out.println("Inside Case 1 Of Itemchange");
parentNodeList = currDom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr++;
}while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println(" currentColumn : "+ currentColumn);
System.out.println("current form::::::::::::" + currentFormNo);
if ( "itm_default".equalsIgnoreCase(currentColumn))
{
valueXmlString.append("<prd_code>").append("").append("</prd_code>");
valueXmlString.append("<item_ser>").append("").append("</item_ser>");
valueXmlString.append("<overwrite>").append("<![CDATA[N]]>").append("</overwrite>");
}
else if ("item_ser".equalsIgnoreCase(currentColumn))
{
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
System.out.println("itemSer>>>"+itemSer);
if(itemSer.trim().length()>0){
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxPrdCode = checkNull(rs.getString(1));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(maxPrdCode.length()>0)
{
valueXmlString.append("<prd_code>").append("<![CDATA[" + maxPrdCode + "]]>").append("</prd_code>");
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
valueXmlString.append("</Detail1>\r\n");
}
break;
}
}
catch (Exception e)
{
try
{
e.printStackTrace();
throw new ITMException(e);
}
catch (Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
}
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 e) {
e.printStackTrace();
throw new ITMException(e);
}
}
valueXmlString.append("</Root>\r\n");
return valueXmlString.toString();
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface SalesConsolidationICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface SalesConsolidationICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document currDom, Document hdrDom, Document allDom,String objContext, String currentColumn, String editFlag,String xtraParams) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class SalesConsolidationPrc extends ProcessEJB implements SalesConsolidationPrcLocal , SalesConsolidationPrcRemote
{
E12GenericUtility genericUtility= new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
@Override
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{
String rtStr = "";
Document dom = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() != 0) {
dom = genericUtility.parseString(xmlString);
System.out.println("Process Dom::::::::::::::::"+dom );
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
dom2 = genericUtility.parseString(xmlString2);
System.out.println("Process Dom2::::::::::::::::"+dom2 );
}
rtStr = process(dom, dom2, windowName, xtraParams);
} catch (Exception e) {
System.out.println("::::"+this.getClass().getSimpleName()+"::processDataString" + e.getMessage());
e.printStackTrace();
}
return rtStr;
}
@Override
public String process(Document dom, Document dom2, String windowName,String xtraParams) throws RemoteException, ITMException {
String errString = "", userID = "", prdCode = "" , itemSer = "" , tranId = "" , loginSiteCode = "" , sql = "" , sql1 = "" , userId = "" , xmlInEditMode = "" ,
unit = "" , empCode = "" , posCode = "" , custCode = "" , itemCode = "" , tranDateStr = "" , retString = "" , xmlParseStr = "" , versionId = ""
, stanCode = "" , stanCodeNew = "" , terrCode = "" , terrDescr = "" , lastYrPrdCode = "";
double opStock = 0.0 , clStock = 0.0 , OpValue = 0.0 , clValue = 0.0 , sales = 0.0 , salesValue = 0.0 , rcpBillQty = 0.0 , rcpBillVal = 0.0 , tranBillQty = 0.0,
tranBillVal = 0.0 , retQty = 0.0 , retVal = 0.0 , tranRepQty = 0.0 , tranRepVal = 0.0 , tranBonusQty = 0.0 , lastYrsSale = 0.0 , lastYrsSaleVal = 0.0
, tranBonusVal = 0.0 , rcpBonusQty = 0.0 ,rcpBonusVal=0.0, rcpRplQty = 0.0 , rcpRplVal = 0.0 , grossQty = 0.0 , grossRate=0.0 , grossVal = 0.0;
Connection conn=null;
int ctr = 0 , count = 0 , cnt = 0 , updCnt = 0 , period = 0;
String chgTerm="",chgUser="",overWrite="",countryCode="";
PreparedStatement pstmt = null , pstmt1 = null;
ResultSet rs = null , rs1 = null;
Timestamp tranDate = null , frDate = null , toDate = null ;
StringBuffer xmlBuff = null;
System.out.println("Current DOM [" + genericUtility.serializeDom(dom) + "]");
System.out.println("Header DOM [" + genericUtility.serializeDom(dom2) + "]");
java.sql.Date sysDate=null;
try {
System.out.println("In process Sales Consolidation:::");
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "userID"));
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom));
itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom));
overWrite = checkNull(genericUtility.getColumnValue("overwrite", dom));
System.out.println("prdCode>>>"+prdCode+">>itemSer>>"+itemSer+">>overWrite>>"+overWrite);
System.out.println("userId : "+userId);
System.out.println("xtraParams ::: "+xtraParams);
ConnDriver con = new ConnDriver();
conn = con.getConnectDB("DriverITM");
sql1 = "select sysdate from dual";
pstmt = conn.prepareStatement(sql1);
rs = pstmt.executeQuery();
if (rs.next()) {
sysDate = rs.getDate(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " SELECT FR_DATE,TO_DATE FROM PERIOD_TBL WHERE PRD_CODE=? AND PRD_TBLNO=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
frDate = rs.getTimestamp("FR_DATE");
toDate = rs.getTimestamp("TO_DATE");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("frDate :::"+frDate+">>toDate :::"+toDate);
sql = "SELECT VERSION_ID FROM VERSION WHERE EFF_FROM < = ? AND VALID_UPTO > = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, frDate);
pstmt.setTimestamp(2, toDate);
rs = pstmt.executeQuery();
if(rs.next())
{
versionId = checkNull(rs.getString("VERSION_ID"));
System.out.println("versionId ::: "+versionId);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if("Y".equalsIgnoreCase(overWrite)){
cnt=0;
sql = "DELETE FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND ITEM_SER=? AND SOURCE='E'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
cnt=pstmt.executeUpdate();
System.out.println("Delete count>>"+cnt);
pstmt.close();
pstmt = null;
}
System.out.println("Inserting data ");
sql = " SELECT A.TRAN_ID , A.TRAN_DATE , A.PRD_CODE, A.FROM_DATE , A.TO_DATE , A.CUST_CODE , A.POS_CODE , A.ITEM_SER , A.EMP_CODE , B.ITEM_CODE , B.UNIT , B.OP_STOCK, B.OP_VALUE , " +
" B.PURC_RCP , B.RCP_VAL , B.TRANSIT_QTY , B.TRANSIT_BILL_VAL , B.PURC_RCP__REPL , B.RCP_REPL_VAL , B.TRANSIT_QTY__REPL , B.TRANSIT_REPL_VAL," +
" B.CL_STOCK , B.CL_VALUE , B.PURC_RET , B.RET_VAL , B.SALES , B.SALES_VALUE , B.PURC_RCP__FREE , B.RCP_FREE_VAL , B.TRANSIT_QTY__FREE," +
" B.TRANSIT_FREE_VAL , B.SALES__ORG , B.RATE__ORG , D.STAN_CODE FROM CUST_STOCK A JOIN CUST_STOCK_DET B ON A.TRAN_ID = B.TRAN_ID " +
" JOIN CUSTOMER D ON D.CUST_CODE = A.CUST_CODE WHERE A.PRD_CODE = ? AND A.ITEM_SER=? AND A.POS_CODE IS NOT NULL " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCode);
pstmt.setString(2, itemSer);
rs = pstmt.executeQuery();
while(rs.next())
{
prdCode = checkNull(rs.getString("PRD_CODE"));
custCode = checkNull(rs.getString("CUST_CODE"));
itemSer = checkNull(rs.getString("ITEM_SER"));
empCode = checkNull(rs.getString("EMP_CODE"));
posCode = checkNull(rs.getString("POS_CODE"));
itemCode = checkNull(rs.getString("ITEM_CODE"));
frDate = rs.getTimestamp("FROM_DATE");
toDate = rs.getTimestamp("TO_DATE");
unit = checkNull(rs.getString("UNIT"));
stanCode = checkNull(rs.getString("STAN_CODE"));
opStock = rs.getDouble("OP_STOCK");
OpValue = rs.getDouble("OP_VALUE");
rcpBillQty = rs.getDouble("PURC_RCP");
rcpBillVal = rs.getDouble("RCP_VAL");
tranBillQty = rs.getDouble("TRANSIT_QTY");
tranBillVal = rs.getDouble("TRANSIT_BILL_VAL");
rcpRplQty = rs.getDouble("PURC_RCP__REPL");
rcpRplVal = rs.getDouble("RCP_REPL_VAL");
tranRepQty = rs.getDouble("TRANSIT_QTY__REPL");
tranRepVal = rs.getDouble("TRANSIT_REPL_VAL");
clStock = rs.getDouble("CL_STOCK");
clValue = rs.getDouble("CL_VALUE");
retQty = rs.getDouble("PURC_RET");
retVal = rs.getDouble("RET_VAL");
sales = rs.getDouble("SALES");
salesValue = rs.getDouble("SALES_VALUE");
grossQty = rs.getDouble("SALES__ORG");
grossRate = rs.getDouble("RATE__ORG");
rcpBonusQty = rs.getDouble("PURC_RCP__FREE");
rcpBonusVal = rs.getDouble("RCP_FREE_VAL");
tranBonusQty = rs.getDouble("TRANSIT_QTY__FREE");
tranBonusVal = rs.getDouble("TRANSIT_FREE_VAL");
cnt ++ ;
grossVal=0.0;
grossVal = grossQty*grossRate;
System.out.println("grossVal :::::::: "+grossVal);
System.out.println("grossQty :::::::: "+grossQty);
System.out.println("prdCode ::: "+prdCode);
System.out.println("custCode ::: "+custCode);
System.out.println("itemSer ::: "+itemSer);
System.out.println("empCode ::: "+empCode);
System.out.println("posCode ::: "+posCode);
System.out.println("itemCode ::: "+itemCode);
System.out.println("unit ::: "+unit);
System.out.println("stanCode ::: "+stanCode);
System.out.println("frDate ::: "+frDate);
System.out.println("toDate ::: "+toDate);
/*versionId="";
sql1 = "SELECT VERSION_ID FROM VERSION WHERE EFF_FROM < = ? AND VALID_UPTO > = ?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setTimestamp(1, frDate);
pstmt1.setTimestamp(2, toDate);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
versionId = checkNull(rs1.getString("VERSION_ID"));
System.out.println("versionId ::: "+versionId);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;*/
terrCode="";terrDescr="";
sql1 = " SELECT A.POOL_CODE , B.LEVEL_CODE , B.LEVEL_DESCR FROM ORG_STRUCTURE A , HIERARCHY " +
" B WHERE A.POOL_CODE = B.LEVEL_CODE AND A.VERSION_ID = ? AND A.POS_CODE = ? AND A.TABLE_NO = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, versionId);
pstmt1.setString(2, posCode);
pstmt1.setString(3, itemSer);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
terrCode = checkNull(rs1.getString("LEVEL_CODE"));
terrDescr = checkNull(rs1.getString("LEVEL_DESCR"));
System.out.println("terrCode ::: "+terrCode+ " terrDescr :::: "+terrDescr);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
lastYrsSale=0.0;lastYrsSaleVal=0.0;
period = Integer.parseInt(prdCode);
period = period - 100;
System.out.println("period :::: "+period);
lastYrPrdCode = period+"";
System.out.println("lastYrPrdCode :::: "+lastYrPrdCode);
sql1 = " SELECT B.SALES , B.SALES_VALUE FROM CUST_STOCK A , CUST_STOCK_DET B WHERE A.TRAN_ID = B.TRAN_ID AND " +
" A.CUST_CODE = ? AND B.ITEM_CODE = ? AND A.ITEM_SER = ? AND A.PRD_CODE = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, custCode);
pstmt1.setString(2, itemCode);
pstmt1.setString(3, itemSer);
pstmt1.setString(4, lastYrPrdCode.trim());
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
lastYrsSale = rs.getDouble("SALES");
lastYrsSaleVal = rs.getDouble("SALES_VALUE");
System.out.println("lastYrPrdCode ::::: "+lastYrPrdCode+"lastYrsSale ::: "+lastYrsSale+ "lastYrsSaleVal :::: "+lastYrsSaleVal);
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
lastYrPrdCode = "";
tranId=generateTranIDForSalesConsolidationProcess("sales_consolidate",loginSiteCode,itemSer,conn);
sql1="insert into SALES_CONSOLIDATION(TRAN_ID,TRAN_DATE,CUST_CODE,PRD_CODE,TERR_CODE,TERR_DESCR,VERSION_ID,POS_CODE," +
"EMP_CODE,SOURCE,ITEM_CODE,UNIT,ITEM_SER,ITEM_SER_NEW,STAN_CODE,STAN_CODE_NEW," +
"OP_STOCK,OP_VALUE,PURC_RCP,PUR_VALUE,TRANSIT_QTY,TRANSIT_BILL_VAL,PURC_RCP__REPL,RCP_REPL_VAL,TRANSIT_QTY__REPL," +
"TRANSIT_REPL_VAL,CL_STOCK,CL_VALUE,PURC_RET,RET_VAL,SALES,SALES_VALUE," +
"PURC_RCP__FREE,RCP_FREE_VAL,TRANSIT_QTY__FREE,TRANSIT_FREE_VAL,GROSS_SALES_QTY,GROSS_SALES_VAL," +
//"NET_SALES_QTY,NET_SALES_VAL,LYCM_SALES_QTY,LYCM_SALES_VAL," +
"LYSLS_SALES_QTY,LYSLS_SALES_VAL," +
//"REMARKS1,REMARKS2,REMARKS3,REMARKS4," +
"ADD_DATE,ADD_USER,ADD_TERM,CHG_DATE,CHG_USER,CHG_TERM)" +
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
pstmt1.setDate(2, sysDate);
pstmt1.setString(3, custCode);
pstmt1.setString(4, prdCode);
pstmt1.setString(5, terrCode);
pstmt1.setString(6, terrDescr);
pstmt1.setString(7, versionId);
pstmt1.setString(8, posCode);
pstmt1.setString(9, empCode);
pstmt1.setString(10, "E");
pstmt1.setString(11, itemCode);
pstmt1.setString(12, unit);
pstmt1.setString(13, itemSer);
pstmt1.setString(14, itemSer);
pstmt1.setString(15, stanCode);
pstmt1.setString(16, stanCode);
pstmt1.setDouble(17, opStock);
pstmt1.setDouble(18, OpValue);
pstmt1.setDouble(19, rcpBillQty);
pstmt1.setDouble(20, rcpBillVal);
pstmt1.setDouble(21, tranBillQty);
pstmt1.setDouble(22, tranBillVal);
pstmt1.setDouble(23, rcpRplQty);
pstmt1.setDouble(24, rcpRplVal);
pstmt1.setDouble(25, tranRepQty);
pstmt1.setDouble(26, tranRepVal);
pstmt1.setDouble(27, clStock);
pstmt1.setDouble(28, clValue);
pstmt1.setDouble(29, retQty);
pstmt1.setDouble(30, retVal);
pstmt1.setDouble(31, sales);
pstmt1.setDouble(32, salesValue);
pstmt1.setDouble(33, rcpBonusQty);
pstmt1.setDouble(34, rcpBonusVal);
pstmt1.setDouble(35, tranBonusQty);
pstmt1.setDouble(36, tranBonusVal);
pstmt1.setDouble(37, grossQty);
pstmt1.setDouble(38, grossVal);//
//NET_SALES_QTY,NET_SALES_VAL,LYCM_SALES_QTY,LYCM_SALES_VAL,
pstmt1.setDouble(39, lastYrsSale);
pstmt1.setDouble(40, lastYrsSaleVal);
//REMARKS1,REMARKS2,REMARKS3,REMARKS4,
pstmt1.setDate(41, sysDate);
pstmt1.setString(42, chgUser);
pstmt1.setString(43, chgTerm);
pstmt1.setDate(44, sysDate);
pstmt1.setString(45, chgUser);
pstmt1.setString(46, chgTerm);
updCnt = pstmt1.executeUpdate();
if(updCnt>0)
{
errString="";
System.out.println("Data inserted!!!");
}
else
{
System.out.println("Data insertion fail!!!");
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
pstmt1.close();
pstmt1= null;
}
rs.close();
rs=null;
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
System.out.println("::::Exception::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
e.printStackTrace();
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
finally
{
try
{
if (errString == null || errString.trim().length()==0)
{
System.out.println("Connection Commited");
errString = itmDBAccessEJB.getErrorString("", "VTDATASUCC","", "", conn);
conn.commit();
}
else
{
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL","", "", conn);
}
if (conn != null)
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
conn.close();
}
conn = null;
} catch (Exception d) {
d.printStackTrace();
}
}
return errString;
}
public String generateTranIDForSalesConsolidationProcess(String objName,String loginSiteCode,String itemSer,Connection conn) throws ITMException
{
String retString = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String keyString = "", refSer = "",sysDate="";
E12GenericUtility genericUtility =new E12GenericUtility();
try
{
SimpleDateFormat sdf= new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate = sdf.format(new java.util.Date());
System.out.println("SalesConsolidationProcess-ES3 :: objName =>"+objName);
HashMap<String, String> transetupMap = new HashMap<String, String>();
transetupMap = getTransetupMap("w_"+objName, conn);
keyString = (String)transetupMap.get("key_string");
refSer = (String)transetupMap.get("ref_ser");
String xmlValues = "";
xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<TRAN_ID></TRAN_ID>";
xmlValues = xmlValues + "<TRAN_DATE>"+sysDate+"</TRAN_DATE>";
xmlValues = xmlValues + "<SITE_CODE>"+loginSiteCode+"</SITE_CODE>";
xmlValues = xmlValues + "<ITEM_SER>"+itemSer+"</ITEM_SER>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues for Sales Consolidation :["+xmlValues+"]");
System.out.println("keyString>>>>"+keyString+">>>refSer>>>"+refSer);
TransIDGenerator tranIdGenerator = new TransIDGenerator(xmlValues, "SYSTEM", CommonConstants.DB_NAME);
String tranIdGenerated = tranIdGenerator.generateTranSeqID(refSer, "tran_id", keyString, conn);
System.out.println("tranIdGenerated for SalesConsolidationProcess-ES3 => "+tranIdGenerated);
retString = tranIdGenerated;
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
return retString;
}
private HashMap<String, String> getTransetupMap(String winName, Connection conn) throws ITMException
{
String keyString = "";
String refSer = "";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
HashMap<String, String> transetupMap = null;
try
{
sql = "SELECT KEY_STRING, REF_SER FROM TRANSETUP WHERE TRAN_WINDOW = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, winName);
rs = pstmt.executeQuery();
if(rs.next())
{
keyString = rs.getString("KEY_STRING") ;
refSer = rs.getString("REF_SER");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("ITWizardBean :: getKeyString :: keyString =>"+keyString);
System.out.println("ITWizardBean :: getKeyString :: refSer =>"+refSer);
transetupMap = new HashMap<String, String>();
transetupMap.put("key_string", keyString);
transetupMap.put("ref_ser", refSer);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
return transetupMap;
}
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface SalesConsolidationPrcLocal extends ProcessLocal {
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface SalesConsolidationPrcRemote extends ProcessRemote{
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
}
/**
* @author Saurabh Jarande[24/03/17]
* This component is used to create Secondary sales transactions by process after Period closed.
*
*/
package ibase.webitm.ejb.dis; package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -20,11 +25,10 @@ import org.w3c.dom.Node; ...@@ -20,11 +25,10 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@Stateless @Stateless
public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,SecSalesGenIcLocal { public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,SecSalesGenIcLocal
{
GenericUtility genericUtility = GenericUtility.getInstance(); E12GenericUtility genericUtility =new E12GenericUtility();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException, ITMException
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException
{ {
System.out.println("In wfValData"); System.out.println("In wfValData");
Document currDom = null; Document currDom = null;
...@@ -52,7 +56,8 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -52,7 +56,8 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Exception : [SecSalesGenIc][wfValData(String currFrmXmlStr)] : ==>\n" + e.getMessage()); System.out.println("::::Exception::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
throw new ITMException(e);
} }
return errString; return errString;
} }
...@@ -60,32 +65,22 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -60,32 +65,22 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException public String validate(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{ {
System.out.println("In validate Data"); System.out.println("In validate Data");
GenericUtility genericUtility = GenericUtility.getInstance();
ArrayList<String> errList = new ArrayList<String>(); ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>(); ArrayList<String> errFields = new ArrayList<String>();
int count = 0;
String errString = "";
String errorType = "";
String errCode = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>"); StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
String childNodeName = ""; int noOfChilds = 0,excnt=0,currentFormNo = 0,cnt = 0, count = 0;
String sql = "";
int noOfChilds = 0;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0;
ConnDriver connDriver = null; ConnDriver connDriver = null;
Node childNode = null; Node childNode = null;
Timestamp frDate=null,toDate=null; Timestamp frDate=null,toDate=null;
String itemSer="",prdCode="",loginSiteCode = "",countryCode="",isPrdClosed=""; String errString = "", errorType = "", errCode = "",maxPrdCode="", itemSer="",prdCode="",
loginSiteCode = "",countryCode="",isPrdClosed="",childNodeName = "", sql = "";
try { try {
System.out.println("************xtraParams*************" + xtraParams); System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver(); connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData Distribution receipt:::");
String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode")); loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
System.out.println("**************loginCode************" + userId); System.out.println("**************loginCode************" + userId);
...@@ -114,29 +109,18 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -114,29 +109,18 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
System.out.println("Editflag =" + editFlag); System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList); System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList); System.out.println("childList = " + childList);
if ("prd_code".equalsIgnoreCase(childNodeName) ) if ("item_ser".equalsIgnoreCase(childNodeName))
{
prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom));
if(prdCode==null || prdCode.trim().length()==0)
{
errList.add("VTNULLPCG");//Invalid-Period code can not be blank
errFields.add(childNodeName.toLowerCase());
break;
}
}
if ("item_ser".equalsIgnoreCase(childNodeName) )
{ {
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom)); itemSer = genericUtility.getColumnValue("item_ser", currDom);
prdCode = checkNull(genericUtility.getColumnValue("prd_code", currDom)); System.out.println("wfValData>>itemSer>>"+itemSer);
if(itemSer==null || itemSer.trim().length()==0) if(itemSer == null || itemSer.trim().length()==0 )
{ {
errList.add("VTNULLDVG");//Invalid-Division can not be blank errList.add("VMNULLDIV");
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break; break;
} }
else if(itemSer!=null || itemSer.trim().length()>0) else
{ {
sql = "SELECT COUNT(*) AS COUNT FROM ITEMSER WHERE ITEM_SER = ? "; sql = "SELECT COUNT(*) AS COUNT FROM ITEMSER WHERE ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer); pstmt.setString(1, itemSer);
...@@ -152,11 +136,16 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -152,11 +136,16 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
System.out.println("Count: " + count); System.out.println("Count: " + count);
if (count == 0) if (count == 0)
{ {
errList.add("VTINVDVG");//Invalid-Division Does not exist errList.add("VTINVDIV");
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break; break;
} }
}
}
else if ("prd_code".equalsIgnoreCase(childNodeName))
{
prdCode = genericUtility.getColumnValue("prd_code", currDom);
itemSer = genericUtility.getColumnValue("item_ser", currDom);
sql= "select count_code from state where " + sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)"; "state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -171,14 +160,18 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -171,14 +160,18 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
rs = null; rs = null;
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
System.out.println("wfValData>>prdCode>>"+prdCode+">>itemSer"+itemSer);
sql = "select count(*) from period_appl a,period_tbl b " + if(prdCode == null || prdCode.trim().length() == 0)
"where a.ref_code=a.prd_tblno and a.prd_tblno=b.prd_tblno " + {
" AND b.prd_code = ? " + errList.add("VMNULLPRD");
"and b.prd_tblno=? " + errFields.add(childNodeName.toLowerCase());
"AND case when a.type is null then 'X' else a.type end='S' "; break;
}
else
{
sql = " SELECT COUNT(*) FROM PERIOD A , PERIOD_TBL B WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim()); pstmt.setString(1,prdCode);
pstmt.setString(2,countryCode+"_"+itemSer.trim()); pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
...@@ -192,52 +185,64 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -192,52 +185,64 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
if (cnt == 0) if (cnt == 0)
{ {
System.out.println("Error :Period not exist in period_tbl master "); System.out.println("Error :Period not exist in period_tbl master ");
errCode = "VTINVPCG"; errList.add("VMINVPRDTB");
errList.add(errCode);
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break;
} }
else else
{ {
sql = "select b.FR_DATE as FR_DATE,b.TO_DATE as TO_DATE " + sql = " SELECT B.PRD_CLOSED,B.FR_DATE,B.TO_DATE FROM PERIOD A , PERIOD_TBL B " +
",b.entry_start_dt as entry_start_dt" + " WHERE A.CODE = B.PRD_CODE AND B.PRD_CODE = ? and B.PRD_TBLNO= ? ";
",b.entry_end_dt as entry_end_dt ,b.prd_closed" +
" from period_appl a,period_tbl b " +
"where a.ref_code=a.prd_tblno and a.prd_tblno=b.prd_tblno " +
" AND b.prd_code = ? " +
"and b.prd_tblno=? " +
"AND case when a.type is null then 'X' else a.type end='S' ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim()); pstmt.setString(1,prdCode.trim());
pstmt.setString(2,countryCode+"_"+itemSer.trim()); pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if(rs.next()) if(rs.next())
{ {
isPrdClosed = rs.getString("PRD_CLOSED");
frDate=rs.getTimestamp("FR_DATE"); frDate=rs.getTimestamp("FR_DATE");
toDate=rs.getTimestamp("TO_DATE"); toDate=rs.getTimestamp("TO_DATE");
isPrdClosed = rs.getString("prd_closed");
} }
rs.close(); rs.close();
rs = null; rs = null;
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
if("N".equalsIgnoreCase(isPrdClosed)) if("N".equalsIgnoreCase(isPrdClosed))
{ {
errCode = "VMPRDNCL"; errList.add("VMPRDNCL");
errList.add(errCode);
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break;
} }
else
{
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
maxPrdCode = rs.getString(1);
} }
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(!prdCode.equalsIgnoreCase(maxPrdCode))
{
//max period check
errList.add("VTINVPCD");
errFields.add(childNodeName.toLowerCase());
break;
} }
else
if((itemSer!=null || itemSer.trim().length()>0) && (prdCode!=null || prdCode.trim().length()>0))
{ {
sql = "SELECT count(*) FROM" + sql = " SELECT COUNT(*) AS COUNT FROM ( " +
" (SELECT POS_CODE,CUST_CODE FROM ORG_STRUCTURE_CUST WHERE VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND TABLE_NO= ? " + " SELECT C.CUST_CODE FROM ORG_STRUCTURE A ,ORG_STRUCTURE_CUST C " +
" AND EFF_DATE < ? AND VALID_UPTO > ? and case when source is null then 'Y' else source end <> 'A' " + " WHERE A.VERSION_ID=C.VERSION_ID AND A.TABLE_NO=C.TABLE_NO AND A.POS_CODE=C.POS_CODE " +
" AND C.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND C.TABLE_NO= ? " +
" AND C.EFF_DATE <= ? AND C.VALID_UPTO >= ? AND CASE WHEN C.SOURCE IS NULL THEN 'Y' ELSE C.SOURCE END <> 'A' " +
" MINUS " + " MINUS " +
" SELECT POS_CODE,CUST_CODE FROM CUST_STOCK WHERE PRD_CODE = ? AND POS_CODE IS NOT NULL AND ITEM_SER = ? ) "; " SELECT CUST_CODE FROM CUST_STOCK WHERE PRD_CODE = ? AND POS_CODE IS NOT NULL AND ITEM_SER = ? ) " ;
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer); pstmt.setString(1, itemSer);
pstmt.setTimestamp(2, frDate); pstmt.setTimestamp(2, frDate);
...@@ -245,16 +250,24 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -245,16 +250,24 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
pstmt.setString(4, prdCode); pstmt.setString(4, prdCode);
pstmt.setString(5, itemSer); pstmt.setString(5, itemSer);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if(rs.next())
{ {
count = rs.getInt(1); excnt = rs.getInt(1);
} }
System.out.println("Count: " + count); rs.close();
if (count == 0) rs = null;
pstmt.close();
pstmt = null;
if (excnt == 0)
{ {
errList.add("VTINVSELG");//Record Not found System.out.println("No record found ");
errList.add("VTNULLRCD");
errFields.add(childNodeName.toLowerCase()); errFields.add(childNodeName.toLowerCase());
break; break;
}
}
}
} }
} }
} }
...@@ -278,7 +291,7 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -278,7 +291,7 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>")); String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>")); bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString); errStringXml.append(bifurErrString);
System.out.println("errStringXml .........." + errStringXml); System.out.println("cc" + errStringXml);
errString = ""; errString = "";
} }
if (errorType.equalsIgnoreCase("E")) if (errorType.equalsIgnoreCase("E"))
...@@ -308,9 +321,21 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -308,9 +321,21 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
{ {
try try
{ {
callPstRs(pstmt, rs); if (conn != null)
if ((conn != null) && (!conn.isClosed())) {
conn.close(); conn.close();
conn = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -321,78 +346,221 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S ...@@ -321,78 +346,221 @@ public class SecSalesGenIc extends ValidatorEJB implements SecSalesGenIcRemote,S
return errString; return errString;
} }
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{ {
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = null;
try try
{ {
if (pstmt != null) if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{ {
pstmt.close(); currDom = genericUtility.parseString(currFrmXmlStr);
pstmt = null; System.out.println("currFrmXmlStr : " + currFrmXmlStr);
} }
if (rs != null) if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{ {
rs.close(); hdrDom = genericUtility.parseString(hdrFrmXmlStr);
rs = null; System.out.println("hdrFrmXmlStr : " + hdrFrmXmlStr);
} }
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = genericUtility.parseString(allFrmXmlStr);
System.out.println("allFrmXmlStr : " + allFrmXmlStr);
}
errString = itemChanged(currDom, hdrDom, allDom, objContext,currentColumn, editFlag, xtraParams);
System.out.println("ErrString :" + errString);
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); System.out.println("Exception :"+this.getClass().getSimpleName()+":itemChanged :==>\n" + e.getMessage());
errString = genericUtility.createErrorString(e);
throw new ITMException(e);
} }
return errString;
} }
private String checkNull(String input) public String itemChanged(Document currDom, Document hdrDom,Document allDom, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{ {
return input == null ? "" : input.trim(); int currentFormNo = 0;
String childNodeName = null;
int ctr = 0;
int childNodeListLength = 0;
Connection conn = null;
StringBuffer valueXmlString = new StringBuffer();
String itemSer="",sql="",countryCode="",maxPrdCode="";
PreparedStatement pstmt=null;
ResultSet rs=null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
} }
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</Header>\r\n");
private String errorType(Connection conn, String errorCode) System.out.println("currentFormNo-------*************** = "+ currentFormNo);
switch (currentFormNo)
{ {
String msgType = ""; case 1:
PreparedStatement pstmt = null; parentNodeList = currDom.getElementsByTagName("Detail1");
ResultSet rs = null; parentNode = parentNodeList.item(0);
try childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr++;
}while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println(" currentColumn : "+ currentColumn);
if ( "itm_default".equalsIgnoreCase(currentColumn))
{ {
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? "; valueXmlString.append("<prd_code>").append("").append("</prd_code>");
valueXmlString.append("<item_ser>").append("").append("</item_ser>");
}
else if ("item_ser".equalsIgnoreCase(currentColumn))
{
itemSer = checkNull(genericUtility.getColumnValue("item_ser", currDom));
System.out.println("itemSer>>>"+itemSer);
if(itemSer.trim().length()>0)
{
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode); pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) if(rs.next())
msgType = rs.getString("MSG_TYPE");
}
catch (Exception ex)
{ {
ex.printStackTrace(); countryCode = checkNull(rs.getString("count_code")).trim();
try System.out.println("countryCode >>> :"+countryCode);
}
callPstRs(pstmt, rs);
sql="select max(prd_code) from period_tbl where PRD_TBLNO=? and PRD_CLOSED='Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{ {
maxPrdCode = checkNull(rs.getString(1));
}
callPstRs(pstmt, rs); callPstRs(pstmt, rs);
if(maxPrdCode.length()>0)
{
valueXmlString.append("<prd_code>").append("<![CDATA[" + maxPrdCode + "]]>").append("</prd_code>");
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
else
{
valueXmlString.append("<prd_code>").append("<![CDATA[]]>").append("</prd_code>");
}
}
valueXmlString.append("</Detail1>\r\n");
}
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
System.out.println("Exception :"+this.getClass().getSimpleName()+":itemChanged :==>\n" + e.getMessage());
throw new ITMException(e);
} }
finally
{
try try
{ {
callPstRs(pstmt, rs); if (conn != null)
{
conn.close();
conn = null;
} }
catch (Exception e) if (pstmt != null)
{ {
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e);
} }
} }
finally valueXmlString.append("</Root>\r\n");
System.out.println("\n****ValueXmlString :" + valueXmlString.toString()+ ":********");
return valueXmlString.toString();
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{ {
try try
{ {
callPstRs(pstmt, rs); if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
private String checkNull(String input)
{
return input == null ? "" : input.trim();
}
private String errorType(Connection conn, String errorCode)
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next()){
msgType = rs.getString("MSG_TYPE");
}
callPstRs(pstmt, rs);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return msgType; return msgType;
} }
} }
package ibase.webitm.ejb.dis; package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import javax.ejb.Local; import javax.ejb.Local;
@Local @Local
public interface SecSalesGenIcLocal public interface SecSalesGenIcLocal extends ValidatorLocal
{ {
public abstract String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException; public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException,ITMException;
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
} }
package ibase.webitm.ejb.dis; package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import javax.ejb.Remote; import javax.ejb.Remote;
@Remote @Remote
public interface SecSalesGenIcRemote { public interface SecSalesGenIcRemote extends ValidatorRemote
public abstract String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException; {
public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException,ITMException;
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
} }
...@@ -6,8 +6,10 @@ import ibase.utility.CommonConstants; ...@@ -6,8 +6,10 @@ import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility; import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean; import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ITMDBAccessEJB; import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterDataStatefulLocal;
import ibase.webitm.ejb.MasterStatefulLocal; import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ProcessEJB; import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.ejb.dis.adv.CustStockGWTConf;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.io.File; import java.io.File;
...@@ -16,6 +18,7 @@ import java.rmi.RemoteException; ...@@ -16,6 +18,7 @@ import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -29,14 +32,212 @@ import org.w3c.dom.NamedNodeMap; ...@@ -29,14 +32,212 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
/**
* @author Saurabh Jarande[24/03/17]
* This component is used to create Secondary sales transactions by process after Period closed.
*
*/
@Stateless @Stateless
public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,SecSalesGenPrcRemote { public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,SecSalesGenPrcRemote
{
E12GenericUtility genericUtility = new E12GenericUtility(); E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException, ITMException
{
String rtStr = "";
Document dom = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() != 0) {
dom = genericUtility.parseString(xmlString);
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
dom = genericUtility.parseString(xmlString2);
}
rtStr = getData(dom, dom2, windowName, xtraParams);
} catch (Exception e) {
System.out.println("::::"+this.getClass().getSimpleName()+"::getDataString" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return rtStr;
}
@Override
public String getData(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException, ITMException
{
String errString = "";
String sql = "";
StringBuffer retTabSepStrBuff = new StringBuffer();
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null;
Connection conn = null; Connection conn = null;
String loginCode = null; String custCode="",custName="",prdCode="",sysDate="",itemSer="",countryCode="",empCode="",empName="",posCode="",blacklisted="",posCodeDescr="";
String errorString = null; Timestamp frDate=null,toDate=null;
static String jBossHome = CommonConstants.JBOSSHOME; SimpleDateFormat sdf=null;
String loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
try {
ConnDriver con = new ConnDriver();
conn = con.getConnectDB("DriverITM");
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
System.out.println("In getdata Station update process:::");
prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom));
itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom));
sysDate = sdf.format(Calendar.getInstance().getTime());
retTabSepStrBuff.append("<?xml version=\"1.0\"?>\r\n<DocumentRoot>\r\n<description>Datawindow Root</description>\r\n<group0>\r\n<description>Group0 description</description>\r\n<Header0>\r\n<description>Header0 members</description>\r\n");
sql= "select count_code from state where " +
"state_code in (select state_code from site where site_code=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode );
rs = pstmt.executeQuery();
if(rs.next())
{
countryCode = checkNull(rs.getString("count_code")).trim();
System.out.println("countryCode >>> :"+countryCode);
}
callPstRs(pstmt, rs);
sql = "select b.FR_DATE as FR_DATE,b.TO_DATE as TO_DATE " +
" from period_appl a,period_tbl b " +
"where a.ref_code=a.prd_tblno and a.prd_tblno=b.prd_tblno " +
" AND b.prd_code = ? " +
"and b.prd_tblno=? " +
"AND case when a.type is null then 'X' else a.type end='S' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim());
pstmt.setString(2,countryCode+"_"+itemSer.trim());
rs = pstmt.executeQuery();
if(rs.next())
{
frDate=rs.getTimestamp("FR_DATE");
toDate=rs.getTimestamp("TO_DATE");
}
callPstRs(pstmt, rs);
/*sql = " SELECT POS_CODE,CUST_CODE,EMP_CODE FROM " +
" (SELECT C.POS_CODE,C.CUST_CODE,A.EMP_CODE FROM ORG_STRUCTURE A ,ORG_STRUCTURE_CUST C " +
" WHERE A.VERSION_ID=C.VERSION_ID AND A.TABLE_NO=C.TABLE_NO AND A.POS_CODE=C.POS_CODE " +
" AND C.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND C.TABLE_NO= ? " +
" AND C.EFF_DATE < ? AND C.VALID_UPTO > ? AND CASE WHEN C.SOURCE IS NULL THEN 'Y' ELSE C.SOURCE END <> 'A' " +
" MINUS " +
" SELECT POS_CODE,CUST_CODE,EMP_CODE FROM CUST_STOCK WHERE PRD_CODE = ? AND POS_CODE IS NOT NULL AND ITEM_SER = ? ) ";
*/
sql=" SELECT A.POS_CODE,A.CUST_CODE,A.EMP_CODE FROM " +
" (SELECT ROW_NUMBER() OVER (PARTITION BY C.CUST_CODE ORDER BY C.CUST_CODE) RN,C.POS_CODE,C.CUST_CODE,A.EMP_CODE " +
" FROM ORG_STRUCTURE A INNER JOIN ORG_STRUCTURE_CUST C " +
" ON A.VERSION_ID=C.VERSION_ID AND A.TABLE_NO=C.TABLE_NO AND A.POS_CODE=C.POS_CODE " +
" INNER JOIN " +
" (SELECT D.CUST_CODE FROM ORG_STRUCTURE B ,ORG_STRUCTURE_CUST D " +
" WHERE B.VERSION_ID=D.VERSION_ID AND B.TABLE_NO=D.TABLE_NO AND B.POS_CODE=D.POS_CODE " +
" AND D.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND D.TABLE_NO= ? " +
" AND D.EFF_DATE <= ? AND D.VALID_UPTO >= ? AND CASE WHEN D.SOURCE IS NULL THEN 'Y' ELSE D.SOURCE END <> 'A' " +
" MINUS " +
" SELECT CUST_CODE FROM CUST_STOCK WHERE PRD_CODE = ? AND POS_CODE IS NOT NULL AND ITEM_SER = ? " +
" ) B " +
" ON C.CUST_CODE = B.CUST_CODE WHERE C.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND C.TABLE_NO= ? " +
" ) A WHERE A.RN = 1 ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer);
pstmt.setTimestamp(2, frDate);
pstmt.setTimestamp(3, toDate);
pstmt.setString(4, prdCode);
pstmt.setString(5, itemSer);
pstmt.setString(6, itemSer);
rs = pstmt.executeQuery();
while(rs.next()) {
posCode = checkNull(rs.getString("POS_CODE"));
custCode = checkNull(rs.getString("CUST_CODE"));
empCode = checkNull(rs.getString("EMP_CODE"));
custName="";blacklisted="";empName="";posCodeDescr="";
sql="SELECT CUST_NAME,BLACK_LISTED FROM CUSTOMER WHERE CUST_CODE=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, custCode);
rs1 = pstmt1.executeQuery();
if(rs1.next()){
custName = checkNull(rs1.getString("CUST_NAME"));
blacklisted = checkNull(rs1.getString("BLACK_LISTED"));
}
callPstRs(pstmt1, rs1);
sql="SELECT EMP_FNAME||' '||EMP_LNAME||' '||EMP_LNAME AS EMP_NAME FROM EMPLOYEE WHERE EMP_CODE=? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, empCode);
rs1 = pstmt1.executeQuery();
if(rs1.next()){
empName = checkNull(rs1.getString("EMP_NAME"));
}
callPstRs(pstmt1, rs1);
sql="SELECT DESCR FROM ORG_STRUCTURE WHERE POS_CODE=? AND TABLE_NO=? AND VERSION_ID=(SELECT FN_GET_VERSION_ID FROM DUAL) ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, posCode);
pstmt1.setString(2, itemSer);
rs1 = pstmt1.executeQuery();
if(rs1.next()){
posCodeDescr = checkNull(rs1.getString("DESCR"));
}
callPstRs(pstmt1, rs1);
retTabSepStrBuff.append("<Detail2>\r\n");
retTabSepStrBuff.append("<cust_code>").append("<![CDATA["+custCode+"]]>").append("</cust_code>\r\n");
retTabSepStrBuff.append("<cust_name>").append("<![CDATA["+custName+"]]>").append("</cust_name>\r\n");
retTabSepStrBuff.append("<blacklisted>").append("<![CDATA["+blacklisted+"]]>").append("</blacklisted>\r\n");
retTabSepStrBuff.append("<item_ser>").append("<![CDATA["+itemSer+"]]>").append("</item_ser>\r\n");
retTabSepStrBuff.append("<pos_code>").append("<![CDATA["+posCode+"]]>").append("</pos_code>\r\n");
retTabSepStrBuff.append("<pos_code_descr>").append("<![CDATA["+posCodeDescr+"]]>").append("</pos_code_descr>\r\n");
retTabSepStrBuff.append("<from_date>").append("<![CDATA["+sdf.format(frDate)+"]]>").append("</from_date>\r\n");
retTabSepStrBuff.append("<to_date>").append("<![CDATA["+sdf.format(toDate)+"]]>").append("</to_date>\r\n");
retTabSepStrBuff.append("<stmt_date>").append("<![CDATA["+sysDate+"]]>").append("</stmt_date>\r\n");
retTabSepStrBuff.append("<emp_code>").append("<![CDATA["+empCode+"]]>").append("</emp_code>\r\n");
retTabSepStrBuff.append("<emp_name>").append("<![CDATA["+empName+"]]>").append("</emp_name>\r\n");
retTabSepStrBuff.append("<prd_code>").append("<![CDATA["+prdCode+"]]>").append("</prd_code>\r\n");
retTabSepStrBuff.append("</Detail2>\r\n");
}
callPstRs(pstmt, rs);
retTabSepStrBuff.append("</Header0>\r\n");
retTabSepStrBuff.append("</group0>\r\n");
retTabSepStrBuff.append("</DocumentRoot>\r\n");
errString = retTabSepStrBuff.toString();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(":::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
conn.close();
conn = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException public String process(String xmlString, String xmlString2,String windowName, String xtraParams) throws RemoteException,ITMException
{ {
...@@ -45,7 +246,6 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -45,7 +246,6 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
String retStr = ""; String retStr = "";
System.out.println("windowName[process]::::::::::;;;" + windowName); System.out.println("windowName[process]::::::::::;;;" + windowName);
System.out.println("xtraParams[process]:::::::::;;;" + xtraParams); System.out.println("xtraParams[process]:::::::::;;;" + xtraParams);
try try
{ {
System.out.println("xmlString[process]::::::::::;;;" + xmlString); System.out.println("xmlString[process]::::::::::;;;" + xmlString);
...@@ -63,30 +263,25 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -63,30 +263,25 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Exception :SecSalesGenPrc :process(String xmlString, String xmlString2, String windowName, String xtraParams):"+ e.getMessage() + ":"); System.out.println(":::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
e.printStackTrace(); e.printStackTrace();
retStr = e.getMessage(); throw new ITMException(e);
} }
return retStr; return retStr;
}// END OF PROCESS (1) }// END OF PROCESS (1)
public String process(Document headerDom, Document detailDom,String windowName, String xtraParams) throws RemoteException,ITMException public String process(Document headerDom, Document detailDom,String windowName, String xtraParams) throws RemoteException,ITMException
{ {
int parentNodeListLength = 0; ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
int childNodeListLength = 0; Connection conn = null;
int parentNodeListLength = 0, childNodeListLength = 0;
String childNodeName = ""; String childNodeName = "";
NodeList parentNodeList = null; NodeList parentNodeList = null,childNodeList = null;
NodeList childNodeList = null; Node parentNode = null, childNode = null;
Node parentNode = null; boolean result=false;
Node childNode = null; int custCount=0;
String errString="",sql="",tranId="",tranIdLast="",spCode="",loginPositionCode="",orderType="",custType="",logDate=""; String errString="",itemSer="",prdCode="",custCode="",posCode="",empCode="",
PreparedStatement pstmt=null,pstmt1=null; ResultSet rs=null,rs1=null; fromDateStr="",toDateStr="",stmtDateStr="";
String itemSer="",prdCode="",posCodeL4="",custCode="",countryCode="",retString = "",sysDate="",xmlInEditMode="";
Timestamp frDate=null,toDate=null;
SimpleDateFormat sdf=null,sdflog=null;
CustStockGWTIC custStockGWTIC =new CustStockGWTIC();
StringBuffer xmlBuff=null;
ArrayList<String> logList=null;
String loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"); String loginSiteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
String chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId"); String chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
String chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode"); String chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
...@@ -99,114 +294,231 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -99,114 +294,231 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
userInfo.setProfileId(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "profileId")); userInfo.setProfileId(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "profileId"));
userInfo.setUserType(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "userType")); userInfo.setUserType(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "userType"));
userInfo.setRemoteHost(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId")); userInfo.setRemoteHost(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));
try {
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat()); try
sdflog = new SimpleDateFormat(genericUtility.getApplDateTimeFormat()); {
sysDate = sdf.format(Calendar.getInstance().getTime());
logDate= sdflog.format(Calendar.getInstance().getTime());
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false); conn.setAutoCommit(false);
} catch (Exception e) {
System.out.println("Exception :SecSalesGenPrc :ejbCreate :==>" + e); parentNodeList = detailDom.getElementsByTagName("Detail2");
e.printStackTrace();
}
try
{
parentNodeList = headerDom.getElementsByTagName("Detail1");
parentNodeListLength = parentNodeList.getLength(); parentNodeListLength = parentNodeList.getLength();
System.out.println("::::::parentNodeListLength["+parentNodeListLength+"]"); System.out.println("::::::parentNodeListLength["+parentNodeListLength+"]");
for (int i = 0; i < parentNodeListLength; i++) {
for (int i = 0; i < parentNodeListLength; i++)
{
parentNode = parentNodeList.item(i); parentNode = parentNodeList.item(i);
childNodeList = parentNode.getChildNodes(); childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength(); childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength : "+childNodeListLength+" childNodeList : "+childNodeList); System.out.println("childNodeListLength : "+childNodeListLength+" childNodeList : "+childNodeList);
for (int childRow = 0; childRow < childNodeListLength; childRow++) for (int childRow = 0; childRow < childNodeListLength; childRow++)
{ {
childNode = childNodeList.item(childRow); childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
System.out.println("childNodeList.item(childRow) : "+ childNode); System.out.println("childNodeList.item(childRow) : "+ childNode);
System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue()); System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue());
if("cust_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
custCode=checkNull(childNode.getFirstChild().getNodeValue());
}
if("item_ser".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null) if("item_ser".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{ {
itemSer=checkNull(childNode.getFirstChild().getNodeValue()); itemSer=checkNull(childNode.getFirstChild().getNodeValue());
} }
if("pos_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
posCode=checkNull(childNode.getFirstChild().getNodeValue());
}
if("from_date".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
fromDateStr=checkNull(childNode.getFirstChild().getNodeValue());
}
if("to_date".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
toDateStr=checkNull(childNode.getFirstChild().getNodeValue());
}
if("stmt_date".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
stmtDateStr=checkNull(childNode.getFirstChild().getNodeValue());
}
if("emp_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
empCode=checkNull(childNode.getFirstChild().getNodeValue());
}
if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null) if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{ {
prdCode=checkNull(childNode.getFirstChild().getNodeValue()); prdCode=checkNull(childNode.getFirstChild().getNodeValue());
} }
}
custCount=isCustExist(prdCode,custCode,itemSer,conn);
if(custCount==0)
{
result = pendTranGenProcess(xtraParams,loginSiteCode,chgUser,chgTerm,prdCode,custCode,itemSer,posCode,fromDateStr,toDateStr,stmtDateStr,empCode,userInfo,conn);
System.out.println("result>>"+result);
} }
else
{
errString = itmDBAccessEJB.getErrorString("", "VMINVPRDCU", "","", conn);
return errString;
} }
sql= "select count_code from state where " + }
"state_code in (select state_code from site where site_code=?)"; System.out.println("result>>"+result);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSiteCode ); if(result)
rs = pstmt.executeQuery();
if(rs.next())
{ {
countryCode = checkNull(rs.getString("count_code")).trim(); errString = itmDBAccessEJB.getErrorString("", "VTES3GENS", "","", conn);
System.out.println("countryCode >>> :"+countryCode); }
else
{
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF", "","", conn);
} }
callPstRs(pstmt, rs);
sql = "select b.FR_DATE as FR_DATE,b.TO_DATE as TO_DATE " + }// try end
" from period_appl a,period_tbl b " + catch (Exception e)
"where a.ref_code=a.prd_tblno and a.prd_tblno=b.prd_tblno " + {
" AND b.prd_code = ? " + try
"and b.prd_tblno=? " + {
"AND case when a.type is null then 'X' else a.type end='S' "; System.out.println("inside");
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF","", "", conn);
conn.rollback();
}
catch (Exception d)
{
System.out.println("Exception : SecSalesGenPrc =>"+ d.toString());
d.printStackTrace();
}
e.printStackTrace();
System.out.println(":::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
throw new ITMException(e);
}
finally
{
System.out.println("In finally....");
try
{
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
errString = e.getMessage();
e.printStackTrace();
return errString;
}
}
System.out.println("Error Message=>" + errString);
return errString;
}// END OF PROCESS(2)
private int isCustExist(String prdCode, String custCode, String itemSer,Connection conn)
{
// TODO Auto-generated method stub
String sql="";
PreparedStatement pstmt=null;
ResultSet rs=null;
int custCntr=0;
try
{
sql=" select count(*) as count from cust_stock where cust_code=? and item_ser=? and prd_code=? and pos_code is not null ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,prdCode.trim()); pstmt.setString(1, custCode);
pstmt.setString(2,countryCode+"_"+itemSer.trim()); pstmt.setString(2, itemSer);
pstmt.setString(3, prdCode);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if(rs.next()) if(rs.next())
{ {
frDate=rs.getTimestamp("FR_DATE"); custCntr = rs.getInt("count");
toDate=rs.getTimestamp("TO_DATE");
} }
callPstRs(pstmt, rs); callPstRs(pstmt, rs);
System.out.println("custCntr>>>>>"+custCntr);
}
catch(SQLException e)
{
e.printStackTrace();
System.out.println("custCnt SQLException"+e);
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return custCntr;
}
private boolean pendTranGenProcess(String xtraParams,String loginSiteCode,String chgUser,String chgTerm,String prdCode,String custCode,String itemSer, String posCode,String fromDateStr, String toDateStr, String stmtDateStr,String empCode,UserInfoBean userInfo,Connection conn)
{
boolean result=false;
CustStockGWTIC custStockGWTIC =new CustStockGWTIC();
CustStockGWTConf confTran=new CustStockGWTConf();
ArrayList<String>logList=null;
String xmlInEditMode="",xmlInEditMode2="",xmlInEditMode3="",sql="",orderType="",custType="",tranIdLast="",tranId="",
sysDate="",logDate="",countryCode="",xmlDetail2="",xmlParseStr="",retString="",retString1="",errString="",
custStockItemDetails="",custStockInvDetails="";
StringBuffer xmlBuff=null;
SimpleDateFormat sdf=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
logDate= sdf.format(Calendar.getInstance().getTime());
sysDate = sdf.format(Calendar.getInstance().getTime());
logList=new ArrayList<String>(); logList=new ArrayList<String>();
xmlInEditMode = getHeaderXML(userInfo,"1"); xmlInEditMode = getHeaderXML(userInfo,"1","2");
xmlInEditMode2 = getHeaderXML(userInfo,"2","1");
xmlInEditMode3 = getHeaderXML(userInfo,"3","1");
System.out.println("xmlInEditMode:::"+ xmlInEditMode); System.out.println("xmlInEditMode:::"+ xmlInEditMode);
System.out.println("xmlInEditMode2>>>>"+xmlInEditMode2);
System.out.println("xmlInEditMode3>>>>"+xmlInEditMode3);
StringBuffer xmlDetail1 = new StringBuffer();
sql = " SELECT POS_CODE,CUST_CODE,EMP_CODE FROM " + sql= "select count_code from state where " +
" (SELECT C.POS_CODE,C.CUST_CODE,A.EMP_CODE FROM ORG_STRUCTURE A ,ORG_STRUCTURE_CUST C " + "state_code in (select state_code from site where site_code=?)";
" WHERE A.VERSION_ID=C.VERSION_ID AND A.TABLE_NO=C.TABLE_NO AND A.POS_CODE=C.POS_CODE " +
" AND C.VERSION_ID = (SELECT FN_GET_VERSION_ID FROM DUAL) AND C.TABLE_NO= ? " +
" AND C.EFF_DATE < ? AND C.VALID_UPTO > ? AND CASE WHEN C.SOURCE IS NULL THEN 'Y' ELSE C.SOURCE END <> 'A' " +
" MINUS " +
" SELECT POS_CODE,CUST_CODE,EMP_CODE FROM CUST_STOCK WHERE PRD_CODE = ? AND POS_CODE IS NOT NULL AND ITEM_SER = ? ) ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemSer); pstmt.setString(1, loginSiteCode );
pstmt.setTimestamp(2, frDate);
pstmt.setTimestamp(3, toDate);
pstmt.setString(4, prdCode);
pstmt.setString(5, itemSer);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while(rs.next()) if(rs.next())
{ {
posCodeL4 = checkNull(rs.getString("POS_CODE")); countryCode = checkNull(rs.getString("count_code")).trim();
custCode = checkNull(rs.getString("CUST_CODE")); System.out.println("countryCode >>> :"+countryCode);
spCode=rs.getString("EMP_CODE"); }
System.out.println("posCodeL4>>>"+posCodeL4+">>custCode>>"+custCode+"Employee code>>"+spCode); callPstRs(pstmt, rs);
loginPositionCode=posCodeL4;
StringBuffer xmlDetail1 = new StringBuffer();
//Set Custstock header details
sql= " select order_type,cust_type from customer where cust_code=? "; sql= " select order_type,cust_type from customer where cust_code=? ";
pstmt1 = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt1.setString(1, custCode); pstmt.setString(1, custCode);
rs1 = pstmt1.executeQuery(); rs = pstmt.executeQuery();
if(rs1.next()) if(rs.next())
{ {
orderType=checkNull(rs1.getString("order_type")); orderType=checkNull(rs.getString("order_type"));
custType=checkNull(rs1.getString("cust_type")); custType=checkNull(rs.getString("cust_type"));
} }
callPstRs(pstmt1, rs1); callPstRs(pstmt, rs);
tranIdLast=getTranIdLast(prdCode, orderType, itemSer, custCode);
tranIdLast=getTranIdLast(orderType, itemSer, custCode,conn);
System.out.println("tranIdLast>>>"+tranIdLast+">>orderType>>>"+orderType+"custType>>>"+custType); System.out.println("tranIdLast>>>"+tranIdLast+">>orderType>>>"+orderType+"custType>>>"+custType);
Document detailDom1 = genericUtility.parseString(xmlInEditMode); Document detailDom1 = genericUtility.parseString(xmlInEditMode);
NodeList parentNodeList1 = detailDom1.getElementsByTagName("Detail1"); NodeList parentNodeList1 = detailDom1.getElementsByTagName("Detail1");
...@@ -229,9 +541,9 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -229,9 +541,9 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
} else if ("order_type".equalsIgnoreCase(childNodeName1)) { } else if ("order_type".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(orderType); childNode1.setTextContent(orderType);
} else if ("from_date".equalsIgnoreCase(childNodeName1)) { } else if ("from_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sdf.format(frDate).toString()); childNode1.setTextContent(fromDateStr);
} else if ("to_date".equalsIgnoreCase(childNodeName1)) { } else if ("to_date".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(sdf.format(toDate).toString()); childNode1.setTextContent(toDateStr);
} else if ("site_code".equalsIgnoreCase(childNodeName1)) { } else if ("site_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(loginSiteCode); childNode1.setTextContent(loginSiteCode);
} else if ("tran_id__last".equalsIgnoreCase(childNodeName1)) { } else if ("tran_id__last".equalsIgnoreCase(childNodeName1)) {
...@@ -251,17 +563,17 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -251,17 +563,17 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
} else if ("adm_chk".equalsIgnoreCase(childNodeName1)) { } else if ("adm_chk".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("N"); childNode1.setTextContent("N");
} else if ("login_poscode".equalsIgnoreCase(childNodeName1)) { } else if ("login_poscode".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(loginPositionCode); childNode1.setTextContent(posCode);
} else if ("pos_code".equalsIgnoreCase(childNodeName1)) { } else if ("pos_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(posCodeL4); childNode1.setTextContent(posCode);
} else if ("emp_code".equalsIgnoreCase(childNodeName1)) { } else if ("emp_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(spCode); childNode1.setTextContent(empCode);
} else if ("country_code".equalsIgnoreCase(childNodeName1)) { } else if ("country_code".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(countryCode); childNode1.setTextContent(countryCode);
} else if ("edit_status".equalsIgnoreCase(childNodeName1)) { } else if ("edit_status".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent("A"); childNode1.setTextContent("A");
} else if ("sale_per".equalsIgnoreCase(childNodeName1)) { } else if ("sale_per".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(spCode); childNode1.setTextContent(empCode);
} else if ("chg_user".equalsIgnoreCase(childNodeName1)) { } else if ("chg_user".equalsIgnoreCase(childNodeName1)) {
childNode1.setTextContent(chgUser); childNode1.setTextContent(chgUser);
} else if ("chg_term".equalsIgnoreCase(childNodeName1)) { } else if ("chg_term".equalsIgnoreCase(childNodeName1)) {
...@@ -279,25 +591,38 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -279,25 +591,38 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
xmlDetail1 = xmlDetail1.append(genericUtility.serializeDom(detailDom1)); xmlDetail1 = xmlDetail1.append(genericUtility.serializeDom(detailDom1));
//header details end //header details end
System.out.println("xmlDetail1 final>>>>"+xmlDetail1.toString()); System.out.println("xmlDetail1 final>>>>"+xmlDetail1.toString());
String custStockInvDetails=custStockGWTIC.itemChanged("", xmlDetail1.toString(), xmlDetail1.toString(), "2", "itm_default", "A", xtraParams); custStockInvDetails=custStockGWTIC.itemChanged("", xmlDetail1.toString(), xmlDetail1.toString(), "2", "itm_default", "A", xtraParams);
System.out.println("custStockInvDetails>>>>"+custStockInvDetails); System.out.println("custStockInvDetails>>>>"+custStockInvDetails);
if(custStockInvDetails.contains("Detail2")) if(custStockInvDetails.contains("Detail2"))
{ {
String xmlDetail2=custStockInvDetails.substring(custStockInvDetails.indexOf("<Detail2"), custStockInvDetails.lastIndexOf("</Detail2>")+10); xmlDetail2=custStockInvDetails.substring(custStockInvDetails.indexOf("<Detail2"), custStockInvDetails.lastIndexOf("</Detail2>")+10);
System.out.println("xmlDetail2>>>"+xmlDetail2); System.out.println("xmlDetail2>>>"+xmlDetail2);
xmlBuff = new StringBuffer(); xmlBuff = new StringBuffer();
xmlBuff.append(xmlDetail1.substring(0,xmlDetail1.indexOf("</Header0>"))); xmlBuff.append(xmlDetail1.substring(0,xmlDetail1.indexOf("</Header0>")));
xmlBuff.append(xmlDetail2); xmlBuff.append(xmlDetail2);
xmlBuff.append(xmlDetail1.substring(xmlDetail1.indexOf("</Header0>"))); xmlBuff.append(xmlDetail1.substring(xmlDetail1.indexOf("</Header0>")));
xmlParseStr = xmlBuff.toString();
String xmlParseStr = xmlBuff.toString();
xmlBuff = null; xmlBuff = null;
System.out.println(":::xmlParseStr:::" + xmlParseStr); System.out.println(":::xmlParseStr::with Invoice:" + xmlParseStr);
String custStockItemDetails=custStockGWTIC.itemChanged("", xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams); custStockItemDetails=custStockGWTIC.itemChanged(xmlInEditMode3, xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams,"sec_sale_gen_prc");
System.out.println("custStockItemDetails>>>>>"+custStockItemDetails); }
if(custStockItemDetails.contains("Detail3")) else
{ {
//xmlDetail2=xmlInEditMode2.substring(xmlInEditMode2.indexOf("<Detail2"), xmlInEditMode2.lastIndexOf("</Detail2>")+10);
//System.out.println("xmlDetail2>>>>>"+xmlDetail2);
//xmlBuff = new StringBuffer();
//xmlBuff.append(xmlDetail1.substring(0,xmlDetail1.indexOf("</Header0>")));
//xmlBuff.append(xmlDetail2);
//xmlBuff.append(xmlDetail1.substring(xmlDetail1.indexOf("</Header0>")));
xmlParseStr = xmlDetail1.toString();
//xmlBuff = null;
System.out.println(":::xmlParseStr::without Invoice:" + xmlParseStr);
custStockItemDetails=custStockGWTIC.itemChanged(xmlInEditMode3, xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams,"sec_sale_gen_prc");
}
//String custStockItemDetails=custStockGWTIC.itemChanged(xmlInEditMode3, xmlParseStr, xmlParseStr, "3", "itm_default", "A", xtraParams,"sec_sale_gen_prc");
System.out.println("custStockItemDetails>>>>>"+custStockItemDetails);
String xmlDetail3=custStockItemDetails.substring(custStockItemDetails.indexOf("<Detail3"), custStockItemDetails.lastIndexOf("</Detail3>")+10); String xmlDetail3=custStockItemDetails.substring(custStockItemDetails.indexOf("<Detail3"), custStockItemDetails.lastIndexOf("</Detail3>")+10);
System.out.println("xmlDetail3>>>>"+xmlDetail3); System.out.println("xmlDetail3>>>>"+xmlDetail3);
...@@ -334,20 +659,18 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -334,20 +659,18 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
if(newTranIdGen!=null && newTranIdGen.trim().length()>0) if(newTranIdGen!=null && newTranIdGen.trim().length()>0)
{ {
String sql1 = "update cust_stock set confirmed = 'Y',status='S' where tran_id = ?"; retString1=confTran.submit(newTranIdGen, xtraParams, "");
pstmt1 = conn.prepareStatement(sql1); System.out.println("retString1>>>"+retString1);
pstmt1.setString(1, newTranIdGen); if (retString1.toUpperCase().indexOf("VTSUBM1") > -1)
int count = pstmt1.executeUpdate(); {
System.out.println("Count:::" + count); errString = "Confirmed Transaction "+newTranIdGen+" Created for Customer code >>"+custCode+" of Position code >>"+posCode+" and Employee code >>"+empCode;
if (count > 0) {
conn.commit();
errString = "Confirmed Transaction "+newTranIdGen+" Created for Customer code >>"+custCode+" of Position code >>"+posCodeL4+" and Employee code >>"+spCode;
logList.add(errString); logList.add(errString);
errString=null; errString=null;
result=true;
} }
if (pstmt1 != null) { else
pstmt1.close(); {
pstmt1 = null; result=false;
} }
} }
} }
...@@ -389,81 +712,47 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -389,81 +712,47 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
logList.add(errString); logList.add(errString);
} }
} }
System.out.println("result>>>"+result);
} }
else catch(Exception e)
{
errString="No items present for available invoices of Customer >>"+custCode+" of Position code >>"+posCodeL4+" and Employee code>>"+spCode;
logList.add(errString);
errString=null;
}
}
else
{ {
errString="No invoices present for Customer >>"+custCode+" of Position code >>"+posCodeL4+" and Employee code>>"+spCode; result=false;
logList.add(errString); logList.add(e.getMessage());
errString=null;
}
} }
callPstRs(pstmt, rs); finally
writeLog(this.getClass().getSimpleName()+"_"+itemSer+"_"+prdCode, logList,logDate);
//end
}// try end
catch (Exception e)
{ {
try try
{ {
System.out.println("inside"); if (pstmt != null)
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF","", "", conn);
conn.rollback();
}
catch (Exception d)
{
System.out.println("Exception : SecSalesGenPrc =>"+ d.toString());
d.printStackTrace();
}
e.printStackTrace();
}
finally
{
System.out.println("In finally....");
try {
if (errString == null || errString.trim().length()==0) {
System.out.println("Connection Commited");
errString = itmDBAccessEJB.getErrorString("", "VTES3GENS","", "", conn);
conn.commit();
}
else
{ {
errString = itmDBAccessEJB.getErrorString("", "VTES3GENF","", "", conn); pstmt.close();
pstmt = null;
} }
if (conn != null) if (rs != null)
{ {
conn.close(); rs.close();
conn = null; rs = null;
} }
} }
catch (Exception e) catch (SQLException e)
{ {
errString = e.getMessage();
e.printStackTrace(); e.printStackTrace();
return errString;
} }
} }
System.out.println("Error Message=>" + errString); writeLog(this.getClass().getSimpleName()+"_"+itemSer+"_"+prdCode, logList,logDate);
return errString; return result;
}// END OF PROCESS(2) }
private String getHeaderXML(UserInfoBean userInfo,String formNo) throws Exception { private String getHeaderXML(UserInfoBean userInfo,String formNo,String pagContext) throws Exception
{
InitialContext ctx = null; InitialContext ctx = null;
String retString = ""; String retString = "";
MasterStatefulLocal masterStateful = null; MasterDataStatefulLocal masterStateful = null;
AppConnectParm appConnect = new AppConnectParm(); AppConnectParm appConnect = new AppConnectParm();
try{ try{
ctx = new InitialContext(appConnect.getProperty()); ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal) ctx.lookup("ibase/MasterStatefulEJB/local"); masterStateful = (MasterDataStatefulLocal) ctx.lookup("ibase/MasterDataStatefulEJB/local");
masterStateful.setUserInfo(userInfo); retString=masterStateful.getBlankDomForAdd("secondory_sale_gwt_wiz", formNo, pagContext, null, userInfo.toString(), "");
retString = checkNull(masterStateful.getDetailXMLDomString("secondory_sale_gwt_wiz", formNo, "A","", "", true));
}catch(Exception e) }catch(Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
...@@ -471,7 +760,8 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -471,7 +760,8 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
return retString; return retString;
} }
private String saveData(String xmlString, Connection conn,UserInfoBean userInfo) throws Exception { private String saveData(String xmlString, Connection conn,UserInfoBean userInfo) throws Exception
{
String retString = ""; String retString = "";
InitialContext ctx = null; InitialContext ctx = null;
MasterStatefulLocal masterStateful = null; MasterStatefulLocal masterStateful = null;
...@@ -496,7 +786,7 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -496,7 +786,7 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
return retString; return retString;
} }
private String getTranIdLast(String prdCode,String orderType, String itemSer,String custCode) private String getTranIdLast(String orderType, String itemSer,String custCode,Connection conn)
{ {
String sql="",tranIdLast=""; String sql="",tranIdLast="";
PreparedStatement pstmt=null; PreparedStatement pstmt=null;
...@@ -504,7 +794,6 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -504,7 +794,6 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
Timestamp toDateLast=null; Timestamp toDateLast=null;
try try
{ {
//Added by saurabh 17/01/17 as per discussion with Manoj Sir.--Start
sql = " SELECT max(to_date) as to_date FROM CUST_STOCK WHERE CUST_CODE = ? " + sql = " SELECT max(to_date) as to_date FROM CUST_STOCK WHERE CUST_CODE = ? " +
" AND ITEM_SER = ? and order_type=? and pos_code is not null and confirmed='Y' and status='S' "; " AND ITEM_SER = ? and order_type=? and pos_code is not null and confirmed='Y' and status='S' ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
...@@ -542,6 +831,26 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -542,6 +831,26 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
{ {
e.printStackTrace(); e.printStackTrace();
} }
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return tranIdLast; return tranIdLast;
} }
...@@ -573,6 +882,7 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se ...@@ -573,6 +882,7 @@ public class SecSalesGenPrc extends ProcessEJB implements SecSalesGenPrcLocal,Se
private void writeLog(String fileName, ArrayList<String> logList,String logDate) private void writeLog(String fileName, ArrayList<String> logList,String logDate)
{ {
String jBossHome = CommonConstants.JBOSSHOME;
FileWriter localFileWriter = null; FileWriter localFileWriter = null;
try { try {
File logDir = new File(jBossHome + File.separator+ "log" + File.separator + "SecSalesGenProcLog"); File logDir = new File(jBossHome + File.separator+ "log" + File.separator + "SecSalesGenProcLog");
......
...@@ -9,5 +9,6 @@ import javax.ejb.Local; ...@@ -9,5 +9,6 @@ import javax.ejb.Local;
@Local @Local
public interface SecSalesGenPrcLocal extends ProcessLocal{ public interface SecSalesGenPrcLocal extends ProcessLocal{
public abstract String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException; public String getData(String arg0, String arg1, String arg2, String arg3) throws RemoteException ,ITMException;
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
} }
...@@ -9,5 +9,6 @@ import javax.ejb.Remote; ...@@ -9,5 +9,6 @@ import javax.ejb.Remote;
@Remote @Remote
public interface SecSalesGenPrcRemote extends ProcessRemote{ public interface SecSalesGenPrcRemote extends ProcessRemote{
public abstract String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException; public String getData(String arg0, String arg1, String arg2, String arg3) throws RemoteException ,ITMException;
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
} }
...@@ -76,14 +76,13 @@ public class SecSalesSubIC extends ValidatorEJB implements SecSalesSubICLocal , ...@@ -76,14 +76,13 @@ public class SecSalesSubIC extends ValidatorEJB implements SecSalesSubICLocal ,
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
int currentFormNo = 0; int currentFormNo = 0;
int cnt = 0; int cnt = 0;
//ConnDriver connDriver = null; ConnDriver connDriver = null;
Node childNode = null; Node childNode = null;
String itemSer="" , prdCode = "" ; String itemSer="" , prdCode = "" ;
try { try {
System.out.println("************xtraParams*************" + xtraParams); System.out.println("************xtraParams*************" + xtraParams);
//connDriver = new ConnDriver(); connDriver = new ConnDriver();
conn = getConnection(); conn = connDriver.getConnectDB("DriverITM");
//conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData Secondary Sales Submit:::"); System.out.println("In wfValData Secondary Sales Submit:::");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode")); loginSiteCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode"));
......
...@@ -68,9 +68,9 @@ public class SecSalesSubPrc extends ProcessEJB implements SecSalesSubPrcLocal , ...@@ -68,9 +68,9 @@ public class SecSalesSubPrc extends ProcessEJB implements SecSalesSubPrcLocal ,
int cnt=0; int cnt=0;
try { try {
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDispDateFormat()); SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDispDateFormat());
//ConnDriver con = new ConnDriver(); ConnDriver con = new ConnDriver();
//conn = con.getConnectDB("DriverITM"); conn = con.getConnectDB("DriverITM");
conn = getConnection();
itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom)); itemSer = checkNull(genericUtility.getColumnValue("item_ser", dom));
prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom)); prdCode = checkNull(genericUtility.getColumnValue("prd_code", dom));
System.out.println("itemSer ::::::::"+itemSer + " prdCode :::::::: " +prdCode); System.out.println("itemSer ::::::::"+itemSer + " prdCode :::::::: " +prdCode);
......
/*
* Component created by saurabh[12/07/16] for new station code update process for flat table.
*
* */
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class StanCodeUpdIC extends ValidatorEJB implements StanCodeUpdICRemote,StanCodeUpdICLocal {
E12GenericUtility genericUtility=new E12GenericUtility();
public String wfValData(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String editFlag,String xtraParams) throws RemoteException,ITMException
{
System.out.println("In wfValData");
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = "";
try
{
System.out.println("currFrmXmlStr..." + currFrmXmlStr);
System.out.println("hdrFrmXmlStr..." + hdrFrmXmlStr);
System.out.println("allFrmXmlStr..." + allFrmXmlStr);
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = parseString(currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = parseString(hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = parseString(allFrmXmlStr);
}
errString = wfValData(currDom, hdrDom, allDom, objContext, editFlag, xtraParams);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return errString;
}
public String wfValData(Document currDom, Document hdrDom, Document allDom,String objContext, String editFlag, String xtraParams)throws RemoteException, ITMException
{
System.out.println("In validate Data");
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
int count = 0;
String errString = "",errorType = "",errCode = "",childNodeName = "",sql = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
int noOfChilds = 0;
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
int currentFormNo = 0;
int cnt = 0,divCount=0,totalCount=0;
ConnDriver connDriver = null;
Node childNode = null;
String prdCodeFrom="",prdCodeTo="",custCode="";
ArrayList<String> custArray=null;
ArrayList<String> errCustList=new ArrayList<String>();
try {
System.out.println("************xtraParams*************" + xtraParams);
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
System.out.println("In wfValData Distribution receipt:::");
String userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("**************loginCode************" + userId);
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
NodeList parentList = currDom.getElementsByTagName("Detail"+ currentFormNo);
NodeList childList = null;
System.out.println("hdrDom..." + hdrDom.toString());
switch (currentFormNo)
{
case 1:
{
childList = parentList.item(0).getChildNodes();
noOfChilds = childList.getLength();
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
if (childNode.getNodeType() != 1)
{
continue;
}
childNodeName = childNode.getNodeName();
System.out.println("Editflag =" + editFlag);
System.out.println("parentList = " + parentList);
System.out.println("childList = " + childList);
if ("prd_code_from".equalsIgnoreCase(childNodeName) )
{
prdCodeFrom = checkNull(genericUtility.getColumnValue("prd_code_from", currDom));
if(prdCodeFrom==null || prdCodeFrom.trim().length()==0)
{
errList.add("VPBLKPRCDF");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND SOURCE='E' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeFrom);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VPINVPRCDF");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
else if ("prd_code_to".equalsIgnoreCase(childNodeName) )
{
prdCodeTo = checkNull(genericUtility.getColumnValue("prd_code_to", currDom));
if(prdCodeTo==null || prdCodeTo.trim().length()==0)
{
errList.add("VPBLKPRCDT");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE PRD_CODE = ? AND SOURCE='E' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeTo);
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errList.add("VPINVPRCDT");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
else if ("cust_code".equalsIgnoreCase(childNodeName) )
{
custCode = checkNull(genericUtility.getColumnValue("cust_code", currDom));
prdCodeFrom = checkNull(genericUtility.getColumnValue("prd_code_from", currDom));
prdCodeTo = checkNull(genericUtility.getColumnValue("prd_code_to", currDom));
if(custCode==null || custCode.trim().length()==0)
{
errList.add("VPBLKCUSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
if (!custCode.matches("[A-Za-z0-9, ]*"))
{
errList.add("VPINVCCDS");
errFields.add(childNodeName.toLowerCase());
break;
}
if(custCode.contains(","))
{
custArray= new ArrayList<String>(Arrays.asList(custCode.split(",")));
for (int i=0;i<custArray.size();i++)
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custArray.get(i));
rs = pstmt.executeQuery();
if (rs.next())
{
divCount = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("divCount: " + divCount);
if (divCount == 0)
{
errCustList.add(custArray.get(i));
errList.add("VPINVCSCDM");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE CUST_CODE=? AND SOURCE='E' AND PRD_CODE BETWEEN ? AND ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custArray.get(i));
pstmt.setString(2, prdCodeFrom);
if(prdCodeTo.length()>0){
pstmt.setString(3, prdCodeTo);
}
else
{
pstmt.setString(3, prdCodeFrom);
}
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errCustList.add(custArray.get(i));
errList.add("VPINVCUSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if (rs.next())
{
divCount = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("divCount: " + divCount);
if (divCount == 0)
{
errCustList.add(custCode);
errList.add("VPINVCSCDM");
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
sql = "SELECT COUNT(*) AS COUNT FROM SALES_CONSOLIDATION WHERE CUST_CODE=? AND SOURCE='E' AND PRD_CODE BETWEEN ? AND ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
pstmt.setString(2, prdCodeFrom);
if(prdCodeTo.length()>0){
pstmt.setString(3, prdCodeTo);
}
else
{
pstmt.setString(3, prdCodeFrom);
}
rs = pstmt.executeQuery();
if (rs.next())
{
count = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("Count: " + count);
if (count == 0)
{
errCustList.add(custCode);
errList.add("VPINVCUSCD");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
if((custCode!=null && custCode.trim().length()>0)&&(prdCodeFrom!=null && prdCodeFrom.trim().length()>0))
{
if(custCode.contains(",")){
custCode=custCode.replaceAll(",", "','");
}
sql = "SELECT COUNT(*) AS COUNT " +
" FROM SALES_CONSOLIDATION SC, CUSTOMER C, STATION ST WHERE SC.CUST_CODE = C.CUST_CODE AND ST.STAN_CODE = C.STAN_CODE AND " +
" ST.STAN_CODE <> SC.STAN_CODE_NEW AND SC.SOURCE='E' AND SC.PRD_CODE BETWEEN ? AND ? AND SC.CUST_CODE IN ('"+custCode+"')";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeFrom);
if(prdCodeTo.length()>0){
pstmt.setString(2, prdCodeTo);
}else{
pstmt.setString(2, prdCodeFrom);
}
rs = pstmt.executeQuery();
while(rs.next()) {
totalCount = rs.getInt("COUNT");
}
callPstRs(pstmt, rs);
System.out.println("totalCount: " + totalCount);
if (totalCount == 0)
{
errList.add("VTNODATAFF");
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
}
break;
}
int errListSize = errList.size();
cnt = 0;
String errFldName = "";
if ((errList != null) && (errListSize > 0))
{
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String) errList.get(cnt);
errFldName = (String) errFields.get(cnt);
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
if(errCustList.size()>0 && errString.length() > 0 )
{
String begPart = errString.substring( 0, errString.indexOf("]]></description>") );
String mainStr="";
for(int i=0;i<errCustList.size();i++)
{
mainStr=mainStr+ errCustList.get(i)+",";
}
String endPart=errString.substring( errString.indexOf("]]></description>"), errString.length() );
mainStr=" Following customers are invalid :: "+mainStr.substring(0,mainStr.length()-1);
errString = begPart+mainStr + endPart;
}
if(errString.length() > 0 )
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString = bifurErrString + errString.substring(errString.indexOf("</trace>") + 8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........." + errStringXml);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer("");
}
errString = errStringXml.toString();
}
catch (Exception e)
{
System.out.println("Exception in "+this.getClass().getSimpleName()+" == >");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
callPstRs(pstmt, rs);
if ((conn != null) && (!conn.isClosed())){
conn.close();
}
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":wfValData :==>\n" + e.getMessage());
throw new ITMException(e);
}
}
return errString;
}
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document currDom = null;
Document hdrDom = null;
Document allDom = null;
String errString = null;
try
{
if ((currFrmXmlStr != null) && (currFrmXmlStr.trim().length() != 0))
{
currDom = genericUtility.parseString(currFrmXmlStr);
System.out.println("currFrmXmlStr : " + currFrmXmlStr);
}
if ((hdrFrmXmlStr != null) && (hdrFrmXmlStr.trim().length() != 0))
{
hdrDom = genericUtility.parseString(hdrFrmXmlStr);
System.out.println("hdrFrmXmlStr : " + hdrFrmXmlStr);
}
if ((allFrmXmlStr != null) && (allFrmXmlStr.trim().length() != 0))
{
allDom = genericUtility.parseString(allFrmXmlStr);
System.out.println("allFrmXmlStr : " + allFrmXmlStr);
}
errString = itemChanged(currDom, hdrDom, allDom, objContext,currentColumn, editFlag, xtraParams);
System.out.println("ErrString :" + errString);
}
catch (Exception e)
{
System.out.println("Exception :"+this.getClass().getSimpleName()+":itemChanged :==>\n" + e.getMessage());
errString = genericUtility.createErrorString(e);
}
return errString;
}
public String itemChanged(Document currDom, Document hdrDom,Document allDom, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException
{
int currentFormNo = 0;
String childNodeName = null;
int ctr = 0;
int childNodeListLength = 0;
Connection conn = null;
StringBuffer valueXmlString = new StringBuffer();
String prdCodeFrom="";
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
if ((objContext != null) && (objContext.trim().length() > 0))
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root>\r\n<Header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</Header>\r\n");
System.out.println("currentFormNo-------*************** = "+ currentFormNo);
switch (currentFormNo)
{
case 1:
System.out.println("currentFormNo-------*************** = "+ currentFormNo);
parentNodeList = currDom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
ctr++;
}while ((ctr < childNodeListLength) && (!childNodeName.equals(currentColumn)));
System.out.println(" currentColumn : "+ currentColumn);
if (currentColumn.equalsIgnoreCase("itm_default"))
{
valueXmlString.append("<prd_code_from>").append("").append("</prd_code_from>\r\n");
valueXmlString.append("<prd_code_to>").append("").append("</prd_code_to>\r\n");
valueXmlString.append("<cust_code>").append("").append("</cust_code>\r\n");
}
else if(currentColumn.equalsIgnoreCase("prd_code_from"))
{
prdCodeFrom = checkNull(genericUtility.getColumnValue("prd_code_from", currDom));
if(prdCodeFrom.length()>0)
{
valueXmlString.append("<prd_code_to>").append("<![CDATA["+checkNull(prdCodeFrom)+"]]>").append("</prd_code_to>\r\n");
}
else
{
valueXmlString.append("<prd_code_to>").append("").append("</prd_code_to>\r\n");
}
}
valueXmlString.append("</Detail1>\r\n");
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
valueXmlString.append("</Root>\r\n");
System.out.println("\n****ValueXmlString :" + valueXmlString.toString()+ ":********");
return valueXmlString.toString();
}
public static boolean isNumeric(String str)
{
try
{
int d = Integer.parseInt(str);
}
catch (NumberFormatException nfe)
{
return false;
}
return true;
}
private String errorType(Connection conn, String errorCode)
{
String msgType = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while (rs.next()){
msgType = rs.getString("MSG_TYPE");
}
callPstRs(pstmt, rs);
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
callPstRs(pstmt, rs);
}
catch (Exception e)
{
e.printStackTrace();
}
}
return msgType;
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String checkNull(String inputVal)
{
inputVal = inputVal == null ? "" : inputVal.trim();
return inputVal;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface StanCodeUpdICLocal extends ValidatorLocal
{
public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException,ITMException;
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface StanCodeUpdICRemote extends ValidatorRemote
{
public String wfValData(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6) throws RemoteException,ITMException;
public String itemChanged(String currFrmXmlStr, String hdrFrmXmlStr,String allFrmXmlStr, String objContext, String currentColumn,String editFlag, String xtraParams) throws RemoteException,ITMException;
}
/*
* Component created by saurabh[07/07/16] for new station code update process for flat table.
* */
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class StanCodeUpdPrc extends ProcessEJB implements StanCodeUpdPrcRemote, StanCodeUpdPrcLocal {
E12GenericUtility genericUtility =new E12GenericUtility();
@Override
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException, ITMException {
String rtStr = "";
Document dom = null;
Document dom2 = null;
try {
if (xmlString != null && xmlString.trim().length() != 0) {
dom = genericUtility.parseString(xmlString);
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
dom = genericUtility.parseString(xmlString2);
}
rtStr = getData(dom, dom2, windowName, xtraParams);
} catch (Exception e) {
System.out.println("::::"+this.getClass().getSimpleName()+"::getDataString" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return rtStr;
}
@Override
public String getData(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException, ITMException
{
String errString = "";
String sql = "";
StringBuffer retTabSepStrBuff = new StringBuffer();
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn = null;
String prdCodeFromDom="",prdCodeToDom="",custCodeDom="";
String custCode="",custName="",prdCode="",itemSer="",stanCode="",stanCodeNew="",salesValue="",tranId="";
int cnt=0;
try {
ConnDriver con = new ConnDriver();
conn = con.getConnectDB("DriverITM");
System.out.println("In getdata Station update process:::");
prdCodeFromDom = checkNull(genericUtility.getColumnValue("prd_code_from", dom));
prdCodeToDom = checkNull(genericUtility.getColumnValue("prd_code_to", dom));
custCodeDom = checkNull(genericUtility.getColumnValue("cust_code", dom));
if(custCodeDom.contains(",")){
custCodeDom=custCodeDom.replaceAll(",", "','");
}
retTabSepStrBuff.append("<?xml version=\"1.0\"?>\r\n<DocumentRoot>\r\n<description>Datawindow Root</description>\r\n<group0>\r\n<description>Group0 description</description>\r\n<Header0>\r\n<description>Header0 members</description>\r\n");
sql = "SELECT SC.CUST_CODE, C.CUST_NAME, SC.PRD_CODE, SC.ITEM_SER, SC.STAN_CODE, ST.STAN_CODE AS STAN_CODE_NEW, SC.SALES_VALUE, SC.TRAN_ID " +
" FROM SALES_CONSOLIDATION SC, CUSTOMER C, STATION ST WHERE SC.CUST_CODE = C.CUST_CODE AND ST.STAN_CODE = C.STAN_CODE AND " +
" ST.STAN_CODE <> SC.STAN_CODE_NEW AND SC.SOURCE='E' AND SC.PRD_CODE BETWEEN ? AND ? AND SC.CUST_CODE IN ('"+custCodeDom+"')";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, prdCodeFromDom);
if(prdCodeToDom.length()>0){
pstmt.setString(2, prdCodeToDom);
}else{
pstmt.setString(2, prdCodeFromDom);
}
rs = pstmt.executeQuery();
while(rs.next()) {
custCode = checkNull(rs.getString("CUST_CODE"));
custName = checkNull(rs.getString("CUST_NAME"));
prdCode = checkNull(rs.getString("PRD_CODE"));
itemSer = checkNull(rs.getString("ITEM_SER"));
stanCode = checkNull(rs.getString("STAN_CODE"));
stanCodeNew = checkNull(rs.getString("STAN_CODE_NEW"));
salesValue = checkNull(rs.getString("SALES_VALUE"));
tranId = checkNull(rs.getString("TRAN_ID"));
cnt++;
retTabSepStrBuff.append("<Detail2>\r\n");
retTabSepStrBuff.append("<cust_code>").append("<![CDATA["+custCode+"]]>").append("</cust_code>\r\n");
retTabSepStrBuff.append("<cust_name>").append("<![CDATA["+custName+"]]>").append("</cust_name>\r\n");
retTabSepStrBuff.append("<prd_code>").append("<![CDATA["+prdCode+"]]>").append("</prd_code>\r\n");
retTabSepStrBuff.append("<item_ser>").append("<![CDATA["+itemSer+"]]>").append("</item_ser>\r\n");
retTabSepStrBuff.append("<stan_code>").append("<![CDATA["+stanCode+"]]>").append("</stan_code>\r\n");
retTabSepStrBuff.append("<stan_code_new>").append("<![CDATA["+stanCodeNew+"]]>").append("</stan_code_new>\r\n");
retTabSepStrBuff.append("<sales_value>").append("<![CDATA["+salesValue+"]]>").append("</sales_value>\r\n");
retTabSepStrBuff.append("<tran_id>").append("<![CDATA["+tranId+"]]>").append("</tran_id>\r\n");
retTabSepStrBuff.append("</Detail2>\r\n");
}
retTabSepStrBuff.append("</Header0>\r\n");
retTabSepStrBuff.append("</group0>\r\n");
retTabSepStrBuff.append("</DocumentRoot>\r\n");
errString = retTabSepStrBuff.toString();
callPstRs(pstmt, rs);
} catch (Exception e) {
e.printStackTrace();
System.out.println(":::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
throw new ITMException(e);
} finally {
try {
conn.close();
conn = null;
} catch (Exception e) {
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
@Override
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException, ITMException {
String rtStr = "";
Document dom = null;
Document dom2 = null;
System.out.println("xmlString: "+xmlString);
System.out.println("xmlString2: "+xmlString2);
try {
if (xmlString != null && xmlString.trim().length() != 0) {
dom = genericUtility.parseString(xmlString);
}
if (xmlString2 != null && xmlString2.trim().length() != 0) {
dom2 = genericUtility.parseString(xmlString2);
}
rtStr = process(dom, dom2, windowName, xtraParams);
} catch (Exception e) {
System.out.println("::::"+this.getClass().getSimpleName()+"::processString" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return rtStr;
}
@Override
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException, ITMException {
String errString = "";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
Connection conn=null;
int childNodeListLength = 0, parentNodeListLength = 0;
String childNodeName = "";
boolean result=false;
String custCode="",custName="",prdCode="",itemSer="",stanCode="",stanCodeNew="",salesValue="",tranId="";
String chgTerm="",chgUser="",selectedCheck="";
try {
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
System.out.println("In process pricelist:::");
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"termId");
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
parentNodeList = dom2.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
if(parentNodeListLength == 0)
{
errString = itmDBAccessEJB.getErrorString("","VPSELONERD","","",conn);
return errString;
}
System.out.println("::::::parentNodeListLength["+parentNodeListLength+"]");
for (int i = 0; i < parentNodeListLength; i++)
{
parentNode = parentNodeList.item(i);
System.out.println("parentNodeList>>>>>"+parentNodeList.item(i));
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength : "+childNodeListLength+" childNodeList : "+childNodeList);
for (int childRow = 0; childRow < childNodeListLength; childRow++)
{
childNode = childNodeList.item(childRow);
childNodeName = childNode.getNodeName();
System.out.println("childNodeList.item(childRow) : "+ childNode);
System.out.println("childNode Name : "+childNode.getNodeName()+" value::"+childNode.getNodeValue());
if("cust_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
custCode=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("custCode>>>>>>>"+custCode);
}
else if("cust_name".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
custName=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("custName>>>>>>>"+custName);
}
else if("prd_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
prdCode=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("prdCode>>>>>>>"+prdCode);
}
else if("item_ser".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
itemSer=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("itemSer>>>>>>>"+itemSer);
}
else if("stan_code".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
stanCode=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("stanCode>>>>>>>"+stanCode);
}
else if("stan_code_new".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
stanCodeNew=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("stanCodeNew>>>>>>>"+stanCodeNew);
}
else if("sales_value".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
salesValue=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("salesValue>>>>>>>"+salesValue);
}
else if("tran_id".equalsIgnoreCase(childNodeName) && childNode.getFirstChild()!=null)
{
tranId=checkNull(childNode.getFirstChild().getNodeValue());
System.out.println("tranId>>>>>>>"+tranId);
}
}
System.out.println("tranId>>>"+tranId+">>stanCodeNew>>"+stanCodeNew);
result=updateData(tranId,stanCodeNew,chgTerm,chgUser, conn);
if (!result) {
conn.rollback();
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
else
{
conn.commit();
}
}
if (result) {
//conn.commit();
errString = itmDBAccessEJB.getErrorString("", "VTDATASUCC", "","", conn);
}
else
{
errString = itmDBAccessEJB.getErrorString("", "VTDATAFAIL", "","", conn);
}
} catch (Exception e) {
System.out.println("::::Exception::::"+this.getClass().getSimpleName()+":::::" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return errString;
}
public boolean updateData(String tranId,String stanCodeNew,String chgTerm,String chgUser,Connection conn)
{
String sql = null;
PreparedStatement pstmt = null;
int upd = 0;
try
{
sql = "UPDATE SALES_CONSOLIDATION set STAN_CODE_NEW=?,CHG_DATE=SYSDATE,CHG_TERM=?,CHG_USER=? where tran_id=?";
System.out.println("upd sql............." + sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, stanCodeNew);
pstmt.setString(2, chgTerm);
pstmt.setString(3, chgUser);
pstmt.setString(4, tranId);
upd = pstmt.executeUpdate();
System.out.println("upd count::::"+upd);
pstmt.close();
pstmt = null;
}
catch (Exception ex)
{
ex.printStackTrace();
upd=0;
}
if (upd == 0){
return false;
}
else{
return true;
}
}
public void callPstRs(PreparedStatement pstmt, ResultSet rs)
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String checkNull(String input)
{
input = input == null ? "" : input.trim();
return input;
}
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface StanCodeUpdPrcLocal extends ProcessLocal
{
public String getData(String arg0, String arg1, String arg2, String arg3) throws RemoteException ,ITMException ;
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface StanCodeUpdPrcRemote extends ProcessRemote
{
public String getData(String arg0, String arg1, String arg2, String arg3) throws RemoteException ,ITMException ;
public String process(String arg0, String arg1, String arg2, String arg3) throws RemoteException, ITMException;
}
...@@ -32,34 +32,60 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -32,34 +32,60 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
public String submit(String tranId, String xtraParams, String forcedFlag)throws RemoteException, ITMException public String submit(String tranId, String xtraParams, String forcedFlag)throws RemoteException, ITMException
{ {
System.out.println(">>>>>>>>>>>>>>>>>>CustStockGWTConf submit called>>>>>>>>>>>>>>>>>>>"); System.out.println(">>>>>>>>>>>>>>>>>>CustStockGWTConf submit called>>>>>>>>>>>>>>>>>>>");
String sql = "",status="",confirmed=""; String sql = "",status="",confirmed="",sql1="",sql2="";
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
String errString = null; String errString = null;
ResultSet rs = null; ResultSet rs = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
String methodName = ""; String methodName = "";
String compName = ""; String compName = "";
String retString = ""; String retString = "";
String serviceCode = ""; String serviceCode = "";
String serviceURI = ""; String serviceURI = "";
String actionURI = ""; String actionURI = "";
int cnt = 0; String missingInserted="",transitUpdate="",loginEmpCode="",userId="",empCode="";
String transitFlag="",siteCode="",custCode="",totclValue="",totSalesValue="",tranType="",stockMode="";
String lineNo="",invoiceId="",itemCode="";
double transitQty=0.0,invoiceQty=0.0,clStock=0.0;
int cnt = 0,cnfCnt=0;
Timestamp currDate = null,tranDate=null;
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
E12GenericUtility genericUtility= new E12GenericUtility();
try try
{ {
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
System.out.println("loginEmpCode>>>>"+loginEmpCode+">>>userId>>>"+userId);
SimpleDateFormat sdf1 = new SimpleDateFormat(genericUtility.getDBDateFormat());
currDate = java.sql.Timestamp.valueOf(sdf1.format(new java.util.Date()).toString() + " 00:00:00.0");
System.out.println("currDate>>>>"+currDate);
ConnDriver connDriver = null; ConnDriver connDriver = null;
connDriver = new ConnDriver(); connDriver = new ConnDriver();
//Changes and Commented By Bhushan on 09-06-2016 :START conn = connDriver.getConnectDB("DriverITM");
//conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
//Changes and Commented By Bhushan on 09-06-2016 :END
conn.setAutoCommit(false); conn.setAutoCommit(false);
sql="select emp_code from users where code=? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userId);
rs = pstmt.executeQuery();
if(rs.next())
{
empCode = rs.getString("emp_code");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("empCode>>>>>"+empCode);
if (tranId != null && tranId.trim().length() > 0) if (tranId != null && tranId.trim().length() > 0)
{ {
System.out.println("tranId>>>["+tranId+"]"); System.out.println("tranId>>>["+tranId+"]");
sql = " select status,confirmed from cust_stock where tran_id = ? "; sql = " select status,confirmed,missing_inserted, transit_update from cust_stock where tran_id = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId); pstmt.setString(1, tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
...@@ -67,6 +93,8 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -67,6 +93,8 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
{ {
status = rs.getString("status"); status = rs.getString("status");
confirmed = rs.getString("confirmed"); confirmed = rs.getString("confirmed");
missingInserted = rs.getString("missing_inserted");
transitUpdate = rs.getString("transit_update");
} }
rs.close(); rs.close();
rs = null; rs = null;
...@@ -75,30 +103,177 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -75,30 +103,177 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
System.out.println("status>>>>>>>>"+status); System.out.println("status>>>>>>>>"+status);
if(!"Y".equalsIgnoreCase(confirmed) && !"S".equalsIgnoreCase(status)) if(!"Y".equalsIgnoreCase(confirmed) && !"S".equalsIgnoreCase(status))
{ {
methodName = "gbf_post"; //start added by chandrashekar on 31-dec-2015
actionURI = "http://NvoServiceurl.org/" + methodName;
sql = "SELECT SERVICE_CODE,COMP_NAME FROM SYSTEM_EVENTS WHERE OBJ_NAME = 'cust_stock' AND EVENT_CODE = 'pre_confirm' "; if(!"Y".equalsIgnoreCase(missingInserted))
{
errString = itmDBAccessLocal.getErrorString("", "VTMISSITEM", "");
return errString;
}
if(transitUpdate == null || transitUpdate.trim().length()==0 || "N".equalsIgnoreCase(transitUpdate))
{
sql = " select transit_flag, site_code, cust_code, tran_date, tot_cl_value, tot_sales_value,tran_type" +
" from cust_stock where tran_id = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
serviceCode = rs.getString("SERVICE_CODE"); transitFlag = rs.getString("transit_flag");
compName = rs.getString("COMP_NAME"); siteCode = rs.getString("site_code");
custCode = rs.getString("cust_code");
tranDate = rs.getTimestamp("tran_date");
totclValue = rs.getString("tot_cl_value");
totSalesValue = rs.getString("tot_sales_value");
tranType = rs.getString("tran_type");
} }
System.out.println(">>>cust stock confirmation serviceCode = " + serviceCode + " compName " + compName); rs.close();
// Changed by Manish on 01/04/16 for max cursor issue [start] rs = null;
if (pstmt != null) pstmt.close();
pstmt = null;
sql = " SELECT VAR_VALUE FROM DISPARM WHERE PRD_CODE = '999999' AND VAR_NAME = 'CUST_STOCK_MODE'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{ {
stockMode = checkNull(rs.getString("VAR_VALUE"));
System.out.println("stockMode :" + stockMode);
}
rs.close();
rs = null;
pstmt.close(); pstmt.close();
pstmt=null; pstmt = null;
if(stockMode == null || "NULLFOUND".equalsIgnoreCase(stockMode)|| stockMode.trim().length()==0)
{
stockMode="S";
}
if(transitFlag == null || transitFlag.trim().length()==0)
{
transitFlag="N";
} }
if (rs !=null) if("S".equalsIgnoreCase(tranType))
{ {
sql = "Select line_no, item_code, transit_qty, cl_stock, sales,op_stock, purc_rcp," +
" adj_qty, purc_ret, adhoc_repl_qty, unit " +
"From cust_stock_det Where tran_id = ? " +
"and case when transit_qty is null then 0 else transit_qty end = 0";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
while (rs.next())
{
lineNo = rs.getString("line_no");
clStock = rs.getDouble("cl_stock");
transitQty = rs.getDouble("transit_qty");
itemCode = rs.getString("item_code");
System.out.println("itemcode@@@@@@>>"+itemCode);
sql1 = "update cust_stock_det set original_cl_stock = ? "
+ "where tran_id = ? and line_no = ?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setDouble(1, clStock);
pstmt1.setString(2, tranId);
pstmt1.setString(3, lineNo);
cnt = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
if (transitQty == 0)
{
sql1 = "Select invoice_id From cust_stock_inv Where tran_id = ? and dlv_flg = 'N'";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
invoiceId = checkNull(rs1.getString("invoice_id"));
System.out.println("invoiceId :" + invoiceId);
sql2 = "Select sum(quantity__stduom) as invoice_qty From "
+ "invdet Where invoice_id = ? " + "and item_code = ? ";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, invoiceId);
pstmt2.setString(2, itemCode);
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
invoiceQty = rs2.getDouble("invoice_qty");
System.out.println("invoiceQty :" + invoiceQty);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
transitQty = transitQty + invoiceQty;
}// invoice loop
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
}
if (transitQty != 0)
{
sql = "update cust_stock_det set transit_qty = ? "
+ " where tran_id = ? "
+ " and line_no = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setDouble(1, transitQty);
pstmt1.setString(2, tranId);
pstmt1.setString(3, lineNo);
cnt = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
}
}//cust_stock_det loop
rs.close(); rs.close();
rs=null; rs = null;
pstmt.close();
pstmt = null;
sql = "update cust_stock set transit_upd_flag = 'Y' where tran_id = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, tranId);
cnt = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
}
}
sql = " update cust_stock set confirmed = 'Y', conf_date = ?, emp_code__aprv = ?,status = 'S' " +
" where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, currDate);
//pstmt.setString(2, loginEmpCode);//empCode
pstmt.setString(2, empCode);
pstmt.setString(3, tranId);
cnfCnt = pstmt.executeUpdate();
pstmt.close();
pstmt = null;
if (cnfCnt>0)
{
conn.commit();
errString = itmDBAccessLocal.getErrorString("", "VTSUBM1", "");
}
//End added by chandrashekar on 31-dec-2015
/*
methodName = "gbf_post";
actionURI = "http://NvoServiceurl.org/" + methodName;
sql = "SELECT SERVICE_CODE,COMP_NAME FROM SYSTEM_EVENTS WHERE OBJ_NAME = 'cust_stock' AND EVENT_CODE = 'pre_confirm' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
serviceCode = rs.getString("SERVICE_CODE");
compName = rs.getString("COMP_NAME");
} }
// Changed by Manish on 01/04/16 for max cursor issue [end] System.out.println(">>>cust stock confirmation serviceCode = " + serviceCode + " compName " + compName);
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? "; sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, serviceCode); pstmt.setString(1, serviceCode);
...@@ -108,18 +283,6 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -108,18 +283,6 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
serviceURI = rs.getString("SERVICE_URI"); serviceURI = rs.getString("SERVICE_URI");
} }
System.out.println(">>>cust stock confirmation serviceURI = " + serviceURI + " compName = " + compName); System.out.println(">>>cust stock confirmation serviceURI = " + serviceURI + " compName = " + compName);
// Changed by Manish on 01/04/16 for max cursor issue [start]
if (pstmt != null)
{
pstmt.close();
pstmt=null;
}
if (rs !=null)
{
rs.close();
rs=null;
}
// Changed by Manish on 01/04/16 for max cursor issue [end]
Service service = new Service(); Service service = new Service();
Call call = (Call) service.createCall(); Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI)); call.setTargetEndpointAddress(new java.net.URL(serviceURI));
...@@ -157,7 +320,7 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -157,7 +320,7 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
conn.commit(); conn.commit();
} }
} }*///commented by chandrashekar on 04-01-2016
}else }else
{ {
errString = itmDBAccessLocal.getErrorString("", "VTINVSUB2", ""); errString = itmDBAccessLocal.getErrorString("", "VTINVSUB2", "");
...@@ -233,10 +396,7 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -233,10 +396,7 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
ConnDriver connDriver = null; ConnDriver connDriver = null;
connDriver = new ConnDriver(); connDriver = new ConnDriver();
//Changes and Commented By Bhushan on 09-06-2016 :START conn = connDriver.getConnectDB("DriverITM");
//conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
//Changes and Commented By Bhushan on 09-06-2016 :END
conn.setAutoCommit(false); conn.setAutoCommit(false);
if (tranId != null && tranId.trim().length() > 0) if (tranId != null && tranId.trim().length() > 0)
...@@ -323,5 +483,12 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo ...@@ -323,5 +483,12 @@ public class CustStockGWTConf extends ActionHandlerEJB implements CustStockGWTCo
return errString; return errString;
} }
private String checkNull(String input)
{
if (input == null)
{
input="";
}
return input;
}
} }
\ 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