Commit 0cb6b1dc authored by prahate's avatar prahate

Added Logistic component.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@195695 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4a04a573
/**
* Author : Saiprasad G.
* Date :
*
* */
package ibase.webitm.ejb.wms;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.text.SimpleDateFormat;
import org.w3c.dom.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import ibase.utility.E12GenericUtility;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.dis.*;
import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
@javax.ejb.Stateless
public class LGSTContractIc extends ValidatorEJB
{
/**
* The method defined with no paramter and returns nothing
*/
E12GenericUtility genericUtility=new E12GenericUtility();
public String wfValData() throws RemoteException, ITMException
{
return "";
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("*************LGSTContractIc wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams)********");
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
System.out.println("xmlString:-" + xmlString );
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
System.out.println("xmlString1:-"+xmlString1);
dom2=parseString(xmlString2);
System.out.println("xmlString2:-"+xmlString2);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
System.out.println("errString[" + errString+"]" );
}
catch(Exception e)
{
throw new ITMException( e );
}
return (errString);
}
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
NodeList parentNodeList = null;NodeList childNodeList = null;
Node parentNode = null;Node childNode = null;
String childNodeName = null;
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null , rs1 = null;
int cnt = 0, currentFormNo=0,childNodeListLength ,ctr=0;
ConnDriver connDriver = new ConnDriver();
String sql = "",errString = "", errCode = "",userId = "", tranId = "";
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
String errorType = "";
String custCode = "", effFrom="",effUpto="";
String rate="",itemCode="",itemType="",rateBasis;
Timestamp eff_from=null,eff_upto=null,fromDate=null,toDate=null;
//String rate=null,unit=null;
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
try
{
connDriver = null;
conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("userId:- " + userId);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
System.out.println("current Form No:"+currentFormNo);
}
switch (currentFormNo)
{
case 1:
parentNodeList = dom.getElementsByTagName("Detail1");
int parentNodeListLen = parentNodeList.getLength();
System.out.println("Number of node in parentNodeListLen : "+parentNodeListLen);
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("childNodeName R : "+childNodeName);
if (childNodeName.equalsIgnoreCase("cust_code"))
{
custCode = E12GenericUtility.checkNull(genericUtility.getColumnValue("cust_code", dom));
System.out.println("Customer code:"+custCode);
if(E12GenericUtility.checkNull(custCode).length() <= 0)
{
errCode = "VTCUSTBLNK";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
String str = "select count(1) from customer where cust_code = ?";
int count = 0;
pstmt = conn.prepareStatement(str);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
System.out.println("count : "+count);
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(count == 0)
{
errCode = "CUSTNOTEXT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
else if (childNodeName.equalsIgnoreCase("eff_from"))
{
effFrom = E12GenericUtility.checkNull(genericUtility.getColumnValue("eff_from", dom));
System.out.println("EffFrom:"+effFrom);
if(effFrom.length() <= 0 )
{
errCode = "VTINVFRDAT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
fromDate = Timestamp.valueOf(genericUtility.getValidDateString(effFrom,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
System.out.println("from Date"+fromDate);
if(fromDate == null)
{
errCode = "VTINVFRDAT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("valid_upto"))
{
effFrom = E12GenericUtility.checkNull(genericUtility.getColumnValue("eff_from", dom));
System.out.println("EffFrom:"+effFrom);
effUpto = E12GenericUtility.checkNull(genericUtility.getColumnValue("valid_upto", dom));
System.out.println("Effupto:"+effUpto);
if(effFrom.length() <= 0 || effUpto.length() <= 0)
{
errCode = "VTINVVLDAT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
fromDate = Timestamp.valueOf(genericUtility.getValidDateString(effFrom,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
System.out.println("from Date"+fromDate);
toDate = Timestamp.valueOf(genericUtility.getValidDateString(effUpto,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
System.out.println("to Date"+toDate);
if(toDate == null || fromDate == null)
{
errCode = "VTINVVLDAT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
if(toDate.before(fromDate))
{
errCode = "INVFROMUP";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
break;
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
int parentNodeListLen1 = parentNodeList.getLength();
//ArrayList<String> itemSer=new ArrayList<>();
NodeList itemCodeSer=null;
String itemCodeSer1="";
for ( int rowCnt=0; rowCnt < parentNodeListLen1; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("childnodename"+childNodeName);
if(childNodeName.equalsIgnoreCase("item_code__srv"))
{
itemCode = E12GenericUtility.checkNull(genericUtility.getColumnValue("item_code__srv", dom));
System.out.println("Item Code"+itemCode);
if(E12GenericUtility.checkNull(itemCode).length() <= 0)
{
errCode = "VTSERVICE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
String str = "SELECT COUNT(1) FROM ITEM WHERE ITEM_TYPE='LGST_SRV' AND ITEM_CODE = ?";
System.out.println("String of the item Code srv:"+str);
int count = 0;
pstmt = conn.prepareStatement(str);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
System.out.println("count : "+count);
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(count == 0)
{
errCode = "SERVICEBLK";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
if("A".equalsIgnoreCase(editFlag))
{
int ctr2=0;
int childNodeListLength2 = 0;
ArrayList<String> itemSer=new ArrayList<>();
System.out.println("array list of item code:"+itemSer);
itemCodeSer=dom2.getElementsByTagName("Detail2");
System.out.println("itemCodeser"+itemCodeSer);
for(ctr2=0;ctr2<itemCodeSer.getLength();ctr2++)
{
Node parentNode2 = itemCodeSer.item(ctr2);
System.out.println("5 parentNode= parentNodeList.item(0) = "+parentNode2);
System.out.println();
NodeList childNodeList2 = parentNode2.getChildNodes();
System.out.println("6 childNodeList= parentNode.getChildNodes(); = "+childNodeList2);
System.out.println();
childNodeListLength2 = childNodeList2.getLength();
for (int ctr3 = 0; ctr3 < childNodeListLength2; ctr3++)
{
Node childNode2 = childNodeList2.item(ctr3);
System.out.println("childNode= childNodeList.item(ctr3) = "+childNode2);
System.out.println();
String childNodeName2 = childNode2.getNodeName();
System.out.println("current column "+ctr3+" " + childNodeName2 );
System.out.println();
if ( childNode2.getFirstChild()!=null && childNode2.getFirstChild().getNodeValue()!=null )
{
itemCodeSer1=childNode2.getFirstChild().getNodeValue();
System.out.println("current value " + itemCodeSer1 );
System.out.println();
}
if (childNodeName2.equalsIgnoreCase("item_code__srv"))
{
System.out.println("Final Array "+itemSer);
System.out.println("itemCodeSer1"+itemCodeSer1);
if(itemSer.contains(itemCodeSer1))
{
System.out.println("Start INSIDE invoc_order 1 Error ");
errList.add( "CHECKVALUE" );
errFields.add( childNodeName.toLowerCase() );
System.out.println("0 invoc_order should not be duplicate dom");
break;
}
else
{
itemSer.add(itemCodeSer1);
System.out.println("array of the item code srv:"+itemSer);
System.out.println("In Else add in array so now array "+itemCodeSer1);
}
}
}
}
}
}
else if (childNodeName.equalsIgnoreCase("rate"))
{
rate = E12GenericUtility.checkNull(genericUtility.getColumnValue("rate", dom));
System.out.println("rate"+rate);
Double rateDouble=0.0;
System.out.println("rate in double");
if(rate.length()>0)
{
try
{
rateDouble=Double.parseDouble(rate);
System.out.println("rate for the validation"+rateDouble);
}
catch(NumberFormatException nm)
{
errCode = "VMINVRATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
catch(Exception e)
{
errCode = "VMINVRATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
if(E12GenericUtility.checkNull(rate).length() <= 0)
{
errCode = "VMINVRATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("rate_basis"))
{
rateBasis = E12GenericUtility.checkNull(genericUtility.getColumnValue("rate_basis", dom));
System.out.println("rate basis"+rateBasis);
if(E12GenericUtility.checkNull(rateBasis).length() <= 0)
{
errCode = "RATEBBLANK";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else
{
String str = "SELECT COUNT(1) FROM GENCODES WHERE MOD_NAME='W_LGST_CONTRACT' AND FLD_VALUE=?";
int count = 0;
pstmt = conn.prepareStatement(str);
pstmt.setString(1, rateBasis);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
System.out.println("count : "+count);
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(count == 0)
{
errCode = "RATEBAINV";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
}
break;
}
//}
int errListSize = errList.size();
cnt =0;
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
System.out.println("Inside errList >"+errList);
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String)errList.get(cnt);
System.out.println("errCode :"+errCode);
int pos = errCode.indexOf("~");
System.out.println("pos :"+pos);
if(pos>-1)
{
errCode=errCode.substring(0,pos);
}
System.out.println("error code is :"+errCode);
errFldName = (String)errFields.get(cnt);
System.out.println(" cnt [" + cnt + "] errCode [" + errCode + "] errFldName [" + errFldName + "]");
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
System.out.println("errorType :"+errorType);
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);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
//END TRY
}
catch(Exception e)
{
System.out.println("Exception ::"+e);
e.printStackTrace();
errString=e.getMessage();
throw new ITMException( e );
}
finally
{
try
{
if(conn!=null)
{
if(rs != null )rs.close();
if(rs1 != null )rs.close();
rs = null;
rs1 = null;
if(pstmt != null )pstmt.close();
pstmt =null;
conn.close();
}
conn = null;
}catch(Exception d)
{
d.printStackTrace();
throw new ITMException( d );
}
}
System.out.println("ErrString ::[ "+errStringXml.toString()+" ]");
return errStringXml.toString();
}
public String itemChanged() throws RemoteException, ITMException
{
return "";
}
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 errString = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
if ( xmlString != null && xmlString.trim().length()!=0 )
{
dom = genericUtility.parseString(xmlString);
}
if ( xmlString1 != null && xmlString1.trim().length()!=0 )
{
dom1 = genericUtility.parseString(xmlString1);
}
if ( xmlString2 != null && xmlString2.trim().length()!=0 )
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = itemChanged( dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
System.out.println ( "ErrString :" + errString);
}
catch ( Exception e )
{
System.out.println ( "Exception :itemChanged(String,String):" + e.getMessage() + ":" );
errString = genericUtility.createErrorString(e);
}
System.out.println ( "returning from AsnLotStatIC itemChanged" );
return (errString);
}
public String itemChanged( Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String sql = "",sql1="";
String columnValue = "";
String loginSiteCode = "";
String custName="",itemTypeDescr="",itemCodeDescr="",gencodeDescr="",itemCode="",rateBasis="";
String userId="";
Date currentDate = null;
SimpleDateFormat sdf = null;
Connection conn = null;
PreparedStatement pStmt = null,pstmt1=null;
ResultSet rs = null,rs1=null;
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
userId = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginCode" );
columnValue = genericUtility.getColumnValue( currentColumn, dom );
conn = getConnection();
//Changed and Commented By Santosh on 14-06-2016 :[END]
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" );
switch( currentFormNo )
{
case 1:
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
valueXmlString.append( "<Detail1>\r\n" );
String loginCode=getValueFromXTRA_PARAMS(xtraParams,"loginCode");
String chg_term=getValueFromXTRA_PARAMS( xtraParams, "chgTerm" );
if("itm_default".equalsIgnoreCase(currentColumn))
{
currentDate = new Date();
valueXmlString.append( "<contract_date protect= \"1\"><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></contract_date>\r\n" );
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term).append( "]]></chg_term>\r\n" );
}
else if("itm_defaultedit".equalsIgnoreCase(currentColumn))
{
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term).append( "]]></chg_term>\r\n" );
}
else if( "cust_code".equalsIgnoreCase(currentColumn) )
{
sql = "select cust_name from customer where cust_code =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if( rs.next() )
{
custName = checkNull(rs.getString("cust_name"));
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
}
valueXmlString.append( "</Detail1>\r\n" );
break;
case 2:
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
//System.out.println("In the 2 form for the itemchange"+formName);
String dummy="";
Double rate=0.0;
valueXmlString.append( "<Detail2>\r\n" );
String loginCode1=getValueFromXTRA_PARAMS(xtraParams,"loginCode");
String chg_term1=getValueFromXTRA_PARAMS( xtraParams, "chgTerm" );
currentDate = new Date();
if("itm_default".equalsIgnoreCase(currentColumn))
{
valueXmlString.append("<item_type>").append("LGST_SRV").append("</item_type>\r\n");
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode1).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term1).append( "]]></chg_term>\r\n" );
valueXmlString.append("<rate><![CDATA[").append(rate).append("]]></rate>");
}
else if("itm_defaultedit".equalsIgnoreCase(currentColumn))
{
itemCode=E12GenericUtility.checkNull(genericUtility.getColumnValue("item_code__srv", dom));
sql = "select descr from item where item_code =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, itemCode);
rs = pStmt.executeQuery();
if( rs.next())
{
itemCodeDescr = checkNull(rs.getString("descr"));
}
closeStatementResultSet(pStmt, rs);
System.out.println("description of the item code"+itemCode+"itemCodeDescr"+itemCodeDescr);
valueXmlString.append( "<item_descr><![CDATA[" ).append(itemCodeDescr).append( "]]></item_descr>\r\n" );
rateBasis=E12GenericUtility.checkNull(genericUtility.getColumnValue("rate_basis", dom));
sql1 = "select descr from gencodes where mod_name='W_LGST_CONTRACT' and fld_value =?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, rateBasis);
rs1 = pstmt1.executeQuery();
if( rs1.next())
{
gencodeDescr = checkNull(rs1.getString("descr"));
}
closeStatementResultSet(pstmt1, rs1);
System.out.println("description of the rate basis"+rateBasis+"itemCodeDescr"+gencodeDescr);
valueXmlString.append("<gencodes_descr><![CDATA[" ).append(gencodeDescr).append( "]]></gencodes_descr>\r\n" );
valueXmlString.append( "<item_descr><![CDATA[" ).append(itemCodeDescr).append( "]]></item_descr>\r\n" );
valueXmlString.append("<item_type>").append("LGST_SRV").append("</item_type>\r\n");
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode1).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term1).append( "]]></chg_term>\r\n" );
}
else if( "item_code__srv".equalsIgnoreCase(currentColumn) )
{
sql = "select descr from item where item_code =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
String itemCodeSrv=genericUtility.getColumnValue("item_code__srv", dom);
rs = pStmt.executeQuery();
if( rs.next())
{
itemCodeDescr = checkNull(rs.getString("descr"));
}
closeStatementResultSet(pStmt, rs);
/*if(itemCodeSrv.equalsIgnoreCase("SPACE_UTIL"))
{
System.out.println("item_code_srv for the space util"+itemCodeSrv);
valueXmlString.append( "<item_descr><![CDATA[" ).append(itemCodeDescr).append( "]]></item_descr>\r\n" );
valueXmlString.append("<rate_basis protect =\"1\"><![CDATA[" ).append("PER_CUBIC").append( "]]></rate_basis>\r\n" );
valueXmlString.append("<gencodes_descr><![CDATA[" ).append("PER_CUBIC").append( "]]></gencodes_descr>\r\n" );
}*/
/*else
{
*/ System.out.println("item_code_srv for the other than that space util"+columnValue);
valueXmlString.append( "<item_descr><![CDATA[" ).append(itemCodeDescr).append( "]]></item_descr>\r\n" );
valueXmlString.append("<rate_basis protect =\"0\"><![CDATA[" ).append(dummy).append( "]]></rate_basis>\r\n" );
valueXmlString.append("<gencodes_descr><![CDATA[" ).append(dummy).append( "]]></gencodes_descr>\r\n" );
//}
}
else if( "rate_basis".equalsIgnoreCase(currentColumn) )
{
sql = "select descr from gencodes where mod_name='W_LGST_CONTRACT' and fld_value =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if( rs.next())
{
gencodeDescr = checkNull(rs.getString("descr"));
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append("<gencodes_descr><![CDATA[" ).append(gencodeDescr).append( "]]></gencodes_descr>\r\n" );
}
valueXmlString.append( "</Detail2>\r\n" );
break;
}
}//end of second form
catch( Exception e )
{
throw new ITMException(e);
}
finally
{
try
{
if( rs != null )
{
rs.close();
rs = null;
}
if( pStmt != null && !pStmt.isClosed() )
{
pStmt.close();
pStmt = null;
}
if( conn != null && !conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch( Exception e )
{
System.out.println( "Exception :AsnLotStatIC:itemChanged :==>\n"+e.getMessage());
throw new ITMException(e);
}
}
valueXmlString.append( "</Root>\r\n" );
return valueXmlString.toString();
}//end of itemchange
private String checkNull( String input )
{
if ( input == null )
{
input = "";
}
return input;
}
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();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
private void closeStatementResultSet(PreparedStatement pstmt, ResultSet resultSet)
{
try
{
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
System.out.println("LGSTContractIc.closeStatementResultSet() : "+e);
}
}
}
/**
* Author :Mr.Vikas Lagad
* Date :
*
* */
package ibase.webitm.ejb.wms;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.text.SimpleDateFormat;
import org.w3c.dom.*;
import ibase.system.config.*;
import ibase.webitm.ejb.*;
import ibase.utility.E12GenericUtility;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.dis.*;
import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
@javax.ejb.Stateless
public class LGSTServiceIC extends ValidatorEJB
{
/**
* The method defined with no paramter and returns nothing
*/
public String wfValData() throws RemoteException, ITMException
{
return "";
}
/**
* The public method is used for validation of required fields which inturn called overloded method
* Returns validation string in XML format if exist otherwise returns null
* @param xmlString contains the current form data in XML format
* @param xmlString1 contains always header form data in XML format
* @param xmlString2 contains all forms data in XML format
* @param objContext represents form no
* @param editFlag the mode of the transaction(A-Add or E-Edit)
* @param xtraParams contains additional information such as loginCode etc
*/
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String errString = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
System.out.println("xmlString [" + xmlString + "]");
System.out.println("xmlString1 [" + xmlString1 + "]");
System.out.println("xmlString2 [" + xmlString2 + "]");
if( xmlString != null && xmlString.trim().length()!=0 )
{
dom = genericUtility.parseString(xmlString);
}
if( xmlString1 != null && xmlString1.trim().length()!=0 )
{
dom1 = genericUtility.parseString(xmlString1);
}
if( xmlString2 != null && xmlString2.trim().length()!=0 )
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = wfValData( dom, dom1, dom2, objContext, editFlag, xtraParams );
System.out.println ( "ErrString: " + errString);
}
catch(Exception e)
{
System.out.println ( "Exception: AsnLotStatIC: wfValData(String xmlString): " + e.getMessage() + ":" );
errString = genericUtility.createErrorString(e);
e.printStackTrace();
}
System.out.println ( "Returning from AsnLotStatIC wfValData" );
return ( errString );
}
/**
* The public overloded method is used for validation of required fields
* Returns validation string if exist otherwise returns null in XML format
* @param dom contains the current form data
* @param dom1 contains always header form data
* @param dom2 contains all forms data
* @param objContext represents form no
* @param editFlag the mode of the transaction(A-Add or E-Edit)
* @param xtraParams contais additional information such as loginEmpCode,loginCode,chgTerm etc
*/
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String columnValue = "";
String errString = "";
int currentFormNo = 0;
int count = 0;
String columnName = "";
String sql = "";
ResultSet rs = null;
Connection conn = null;
PreparedStatement pStmt = null;
E12GenericUtility genericUtility = new E12GenericUtility();
StringBuffer valueXmlString = new StringBuffer();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
String errorType = "", errCode = "";
ArrayList errList = new ArrayList();
ArrayList errFields = new ArrayList();
try
{
SimpleDateFormat sdft = new SimpleDateFormat( genericUtility.getApplDateFormat() );
//Commented by Santosh on 14-06-2016
/*ConnDriver connDriver = null;
connDriver = new ConnDriver();*/
//Changed and Commented By Santosh on 14-06-2016 :[START]
//conn = connDriver.getConnectDB("DriverITM");
conn = getConnection();
//Changed and Commented By Santosh on 14-06-2016 :[END]
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
int noOfChilds = 0;
String userId = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginCode" );
if ( objContext != null && objContext.trim().length() > 0 )
{
currentFormNo = Integer.parseInt( objContext );
}
switch( currentFormNo )
{
case 1 :
{
parentList = dom.getElementsByTagName( "Detail" + currentFormNo );
for ( int pctr = 0; pctr < parentList.getLength(); pctr++ )
{
parentNode = parentList.item( pctr);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
for ( int ctr = 0; ctr < childList.getLength(); ctr++ )
{
childNode = childList.item(ctr);
if( childNode.getNodeType() != Node.ELEMENT_NODE )
{
continue;
}
String childNodeName = childNode.getNodeName();
if ( childNode != null && childNode.getFirstChild() != null )
{
columnValue = childNode.getFirstChild().getNodeValue();
}
columnName = childNode.getNodeName();
if( "CONTRACT_NO".equalsIgnoreCase(columnName) )
{
if ( childNode == null || childNode.getFirstChild() == null )
{
errList.add( "VTLGSTCN" );
errFields.add( childNodeName.toLowerCase() );
}
else
{
sql = "select count(*) from LGST_CONTRACT where contract_no =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if( rs.next() )
{
count = rs.getInt(1);
}
rs.close();rs = null;
pStmt.close();pStmt = null;
if( count == 0 )
{
errList.add( "VTLGSTCNDX" );
errFields.add( childNodeName.toLowerCase());
}
}
}
/*if("ref_ser".equalsIgnoreCase(columnName))
{
if ( childNode == null || childNode.getFirstChild() == null )
{
errList.add( "VTREFSER" );
errFields.add( childNodeName.toLowerCase() );
}
}
if("ref_id".equalsIgnoreCase(columnName))
{
if ( childNode == null || childNode.getFirstChild() == null )
{
errList.add( "VTREFID" );
errFields.add( childNodeName.toLowerCase() );
}
}*/
}
}
}//end of case 1
break;
case 2:
{
parentList = dom.getElementsByTagName( "Detail" + currentFormNo );
for ( int pctr = 0; pctr < parentList.getLength(); pctr++ )
{
parentNode = parentList.item( pctr);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
for ( int ctr = 0; ctr < childList.getLength(); ctr++ )
{
childNode = childList.item(ctr);
if( childNode.getNodeType() != Node.ELEMENT_NODE )
{
continue;
}
String childNodeName = childNode.getNodeName();
if ( childNode != null && childNode.getFirstChild() != null )
{
columnValue = childNode.getFirstChild().getNodeValue();
}
columnName = childNode.getNodeName();
if("item_code__srv".equalsIgnoreCase(columnName))
{
if ( childNode == null || childNode.getFirstChild() == null )
{
errList.add( "VTICCBL" );
errFields.add( childNodeName.toLowerCase() );
break;
}
else
{
sql = "select count(*) from LGST_CONTRACT_DET where item_code__srv =?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if( rs.next() )
{
count = rs.getInt(1);
}
if( count == 0 )
{
errList.add( "VTICDNX" );
errFields.add( childNodeName.toLowerCase() );
break;
}
rs.close();rs = null;
pStmt.close();pStmt = null;
}
}
if("quantity".equalsIgnoreCase(columnName))
{
if ( childNode == null || childNode.getFirstChild() == null )
{
errList.add( "VMQCQTN" );
errFields.add( childNodeName.toLowerCase() );
break;
}
}
}
}
}
}//end of switch
int errListSize = errList.size();
int cnt =0;
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
for (cnt = 0; cnt < errListSize; cnt++ )
{
errCode = (String)errList.get(cnt);
errFldName = (String)errFields.get(cnt);
System.out.println("errCode .........."+errCode);
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;//+"<trace>"+errMsg+"</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();
}//end of try block
catch( Exception e )
{
throw new ITMException(e);
}//end of catch block
finally
{
try
{
if( rs != null )
{
rs.close();
rs = null;
}
if( pStmt != null && !pStmt.isClosed() )
{
pStmt.close();
pStmt = null;
}
if( conn != null && !conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch( Exception e )
{
System.out.println( "Exception :AsnLotStatIC:wfValData :==>\n"+e.getMessage());
throw new ITMException(e);
}
}//end of finally block
return ( errString );
}//
/**
* The method defined with no paramter and returns nothing
*/
public String itemChanged() throws RemoteException, ITMException
{
return "";
}
/**
* The public method is used for itemchange of required fields which inturn called overloded method
* Returns itemchange string in XML format
* @param xmlString contains the current form data in XML format
* @param xmlString1 contains always header form data in XML format
* @param xmlString2 contains all forms data in XML format
* @param objContext represents form no
* @param editFlag the mode of the transaction(A-Add or E-Edit)
* @param xtraParams contains additional information such as loginEmpCode,loginCode,chgTerm etc
*/
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 errString = null;
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
if ( xmlString != null && xmlString.trim().length()!=0 )
{
dom = genericUtility.parseString(xmlString);
}
if ( xmlString1 != null && xmlString1.trim().length()!=0 )
{
dom1 = genericUtility.parseString(xmlString1);
}
if ( xmlString2 != null && xmlString2.trim().length()!=0 )
{
dom2 = genericUtility.parseString(xmlString2);
}
errString = itemChanged( dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams );
System.out.println ( "ErrString :" + errString);
}
catch ( Exception e )
{
System.out.println ( "Exception :itemChanged(String,String):" + e.getMessage() + ":" );
errString = genericUtility.createErrorString(e);
}
System.out.println ( "returning from AsnLotStatIC itemChanged" );
return (errString);
}
/**
* The public overloded method is used for itemchange of required fields
* Returns itemchange string in XML format
* @param dom contains the current form data
* @param dom1 contains always header form data
* @param dom2 contains all forms data
* @param objContext represents form no
* @param editFlag the mode of the transaction(A-Add or E-Edit)
* @param xtraParams contains additional information such as loginCode etc
*/
public String itemChanged( Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams ) throws RemoteException,ITMException
{
String sql = "";
String columnValue = "";
String loginCode="";
String chg_term="";
String rate="";
String quantity="";
String area="";
String Description="";
String item_code ="";
Date currentDate = null;
SimpleDateFormat sdf = null;
Connection conn = null;
Statement stmt=null;
PreparedStatement pStmt = null;
ResultSet rs = null;
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0;
String custName="",refDescr="",custCode="";
E12GenericUtility genericUtility = new E12GenericUtility();
try
{
sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String userId = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginCode" );
columnValue = genericUtility.getColumnValue( currentColumn, dom );
//Commented by Santosh on 14-06-2016
/*ConnDriver connDriver = null;
connDriver = new ConnDriver();*/
//Changed and Commented By Santosh on 14-06-2016 :[START]
//conn = connDriver.getConnectDB("DriverValidator");
conn = getConnection();
//Changed and Commented By Santosh on 14-06-2016 :[END]
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" );
switch( currentFormNo )
{
case 1:
{
valueXmlString.append( "<Detail1>\r\n" );
if("itm_default".equalsIgnoreCase(currentColumn))
{
String refSer1=genericUtility.getColumnValue("ref_ser", dom,"1");
System.out.println("refeser1"+refSer1);
sql="SELECT DESCR FROM REFSER WHERE REF_SER=?";
System.out.println("sql in ref_ser"+sql);
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, refSer1);
rs = pStmt.executeQuery();
if(rs.next())
{
refDescr=rs.getString("DESCR");
System.out.println("DESCR:"+refDescr);
}
valueXmlString.append( "<refser_descr><![CDATA[" ).append(refDescr).append( "]]></refser_descr>\r\n" );
loginCode=getValueFromXTRA_PARAMS(xtraParams,"loginCode");
chg_term=getValueFromXTRA_PARAMS( xtraParams, "chgTerm" );
currentDate = new Date();
valueXmlString.append( "<tran_date protect = \"1\"><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></tran_date>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term).append( "]]></chg_term>\r\n" );
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
closeStatementResultSet(pStmt, rs);
}
else if("itm_defaultedit".equalsIgnoreCase(currentColumn))
{
String contractNo=E12GenericUtility.checkNull(genericUtility.getColumnValue("contract_no", dom,"1"));
System.out.println("contract no:"+contractNo);
sql="SELECT CUST_CODE FROM LGST_CONTRACT WHERE CONTRACT_NO=?";
pStmt=conn.prepareStatement(sql);
pStmt.setString(1,contractNo);
rs=pStmt.executeQuery();
if(rs.next())
{
custCode=rs.getString("CUST_CODE");
System.out.println("customer code:"+custCode);
}
rs.close();
pStmt.close();
sql="select cust_name from customer where cust_code=?";
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, custCode);
rs=pStmt.executeQuery();
if(rs.next())
{
custName=rs.getString("cust_name");
System.out.println("customer name:"+custName);
}
valueXmlString.append( "<cust_code><![CDATA[" ).append(custCode).append( "]]></cust_code>\r\n" );
valueXmlString.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
closeStatementResultSet(pStmt, rs);
String refSer1=genericUtility.getColumnValue("ref_ser", dom,"1");
System.out.println("refeser1"+refSer1);
sql="SELECT DESCR FROM REFSER WHERE REF_SER=?";
System.out.println("sql in ref_ser"+sql);
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, refSer1);
rs = pStmt.executeQuery();
if(rs.next())
{
refDescr=rs.getString("DESCR");
System.out.println("DESCR:"+refDescr);
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append( "<refser_descr><![CDATA[" ).append(refDescr).append( "]]></refser_descr>\r\n" );
}
else if("cust_code".equalsIgnoreCase(currentColumn))
{
sql="SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE=?";
System.out.println("sql in cust_code"+sql);
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if(rs.next())
{
custName=rs.getString("CUST_NAME");
System.out.println("Customer name:"+custName);
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
valueXmlString.append( "<contract_no><![CDATA[" ).append("").append( "]]></contract_no>\r\n" );
}
else if("contract_no".equalsIgnoreCase(currentColumn))
{
sql="SELECT CUST_CODE FROM LGST_CONTRACT WHERE CONTRACT_NO=?";
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs=pStmt.executeQuery();
if(rs.next())
{
custCode=rs.getString("CUST_CODE");
System.out.println("customer code:"+custCode);
}
rs.close();
pStmt.close();
System.out.println("2nd time cust name");
sql="SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE=?";
System.out.println("sql in cust_code"+sql);
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, custCode);
rs = pStmt.executeQuery();
if(rs.next())
{
custName=rs.getString("CUST_NAME");
System.out.println("Customer name:"+custName);
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append( "<cust_code><![CDATA[" ).append(custCode).append( "]]></cust_code>\r\n" );
valueXmlString.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
}
else if("ref_ser".equalsIgnoreCase(currentColumn))
{
sql="SELECT DESCR FROM REFSER WHERE REF_SER=?";
System.out.println("sql in ref_ser"+sql);
pStmt=conn.prepareStatement(sql);
pStmt.setString(1, columnValue);
rs = pStmt.executeQuery();
if(rs.next())
{
refDescr=rs.getString("DESCR");
System.out.println("DESCR:"+refDescr);
}
closeStatementResultSet(pStmt, rs);
valueXmlString.append( "<refser_descr><![CDATA[" ).append(refDescr).append( "]]></refser_descr>\r\n" );
}
valueXmlString.append( "</Detail1>\r\n" );
}
break;
case 2:
{
valueXmlString.append( "<Detail2>\r\n" );
if("itm_default".equalsIgnoreCase(currentColumn))
{
String REF_SER =checkNull(genericUtility.getColumnValue( "ref_ser", dom1 )).trim();
String REF_ID = checkNull(genericUtility.getColumnValue( "ref_id", dom1 ));
System.out.println("REF_SER 1234 :["+REF_SER+"]");
System.out.println("REF_ID 1234 :["+REF_ID+"]");
currentDate = new Date();
valueXmlString.append( "<chg_user><![CDATA[" ).append(loginCode).append( "]]></chg_user >\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append(chg_term).append( "]]></chg_term>\r\n" );
valueXmlString.append( "<chg_date><![CDATA[" ).append(sdf.format(currentDate).toString()).append( "]]></chg_date>\r\n" );
/*if( "".equalsIgnoreCase(REF_SER) && "".equalsIgnoreCase(REF_ID) )
{
sql="select SUM(PCK.LENGTH * PCK.WIDTH * PCK.HEIGHT *INV.NO_ART) As Total_Area "
+ "FROM INVTRACE INV "
+ "LEFT JOIN ITEM ITM "
+ "ON INV.ITEM_CODE=ITM.ITEM_CODE "
+ "LEFT JOIN PACKING PCK "
+ "ON ITM.PACK_CODE=PCK.PACK_CODE "
+ "where INV.REF_SER='ADJRCP' and INV.REF_ID='618ARD0002'";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
area=rs.getString("Total_Area");
}
//rs=null;
System.out.println("Area Occupied 1234 : "+area);
int amount=Integer.parseInt(area)*10;
System.out.println("Amount 1234: "+amount);
valueXmlString.append("<quantity protect = \"1\"><![CDATA[" + "0" + "]]></quantity>");
valueXmlString.append( "<rate><![CDATA[" ).append("10").append( "]]></rate>\r\n" );
valueXmlString.append( "<amount><![CDATA[" ).append(amount).append( "]]></amount>\r\n" );
valueXmlString.append( "<item_code__srv><![CDATA[" ).append("SPACE_UTIL").append( "]]></item_code__srv>\r\n" );
}
else */if( "S-ORD".equalsIgnoreCase(REF_SER))
{
sql = "select sum(QUANTITY) AS QUANTITY from sorddet where SALE_ORDER=?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, REF_ID);
rs = pStmt.executeQuery();
if( rs.next() )
{
quantity = checkNull(rs.getString("quantity"));
}
closeStatementResultSet(pStmt, rs);
System.out.println("S-ORD QUANTITY : "+quantity);
valueXmlString.append( "<quantity><![CDATA[" ).append(quantity).append( "]]></quantity>\r\n" );
}
else if( "P-ORD".equalsIgnoreCase(REF_SER))
{
sql = "select sum(QUANTITY) AS QUANTITY from PORDDET where PURC_ORDER=?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, REF_ID);
rs = pStmt.executeQuery();
if( rs.next() )
{
quantity = checkNull(rs.getString("quantity"));
}
closeStatementResultSet(pStmt, rs);
System.out.println("P-ORD QUANTITY : "+quantity);
valueXmlString.append( "<quantity><![CDATA[" ).append(quantity).append( "]]></quantity>\r\n" );
}
}
if( "ITEM_CODE__SRV".equalsIgnoreCase(currentColumn) )
{
String ITEM_CODE__SRV = genericUtility.getColumnValue( "item_code__srv", dom ).trim();
String Contract_no= genericUtility.getColumnValue( "contract_no", dom1);
System.out.println("ITEM_CODE__SRV 1234 :["+ITEM_CODE__SRV+"]");
System.out.println("LGST Descr123 :"+Description);
/*if( "SPACE_UTIL".equalsIgnoreCase(ITEM_CODE__SRV) )
{
sql="select SUM(PCK.LENGTH * PCK.WIDTH * PCK.HEIGHT *INV.NO_ART) As Total_Area "
+ "FROM INVTRACE INV "
+ "LEFT JOIN ITEM ITM "
+ "ON INV.ITEM_CODE=ITM.ITEM_CODE "
+ "LEFT JOIN PACKING PCK "
+ "ON ITM.PACK_CODE=PCK.PACK_CODE "
+ "where INV.REF_SER='ADJRCP' and INV.REF_ID='618ARD0002'";
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
area=rs.getString("Total_Area");
}
rs=null;
System.out.println("Area Occupied 1234 : "+area);
sql = "select rate from LGST_CONTRACT_DET where ITEM_CODE__SRV =? AND CONTRACT_NO=?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, ITEM_CODE__SRV);
pStmt.setString(2, Contract_no);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = checkNull(rs.getString("rate"));
System.out.println(rate);
}
System.out.println("rate 1234 : "+rate);
double amount=Double.parseDouble(area)*Double.parseDouble(rate);
System.out.println("Amount 1234: "+amount);
valueXmlString.append("<quantity protect = \"1\"><![CDATA[" + "0" + "]]></quantity>");
valueXmlString.append( "<rate><![CDATA[" ).append(rate).append( "]]></rate>\r\n" );
valueXmlString.append( "<amount><![CDATA[" ).append(amount).append( "]]></amount>\r\n" );
valueXmlString.append( "<item_code__srv><![CDATA[" ).append("SPACE_UTIL").append( "]]></item_code__srv>\r\n" );
}*/
//else
//{
sql = "select rate from LGST_CONTRACT_DET where ITEM_CODE__SRV =? AND CONTRACT_NO=?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, ITEM_CODE__SRV);
pStmt.setString(2, Contract_no);
rs = pStmt.executeQuery();
if( rs.next() )
{
rate = checkNull(rs.getString("rate"));
System.out.println(rate);
}
closeStatementResultSet(pStmt, rs);
quantity = checkNull(genericUtility.getColumnValue( "quantity", dom ));
System.out.println("Rate 1234 : "+rate);
System.out.println("Quantity 1234 : "+quantity);
if( !"".equalsIgnoreCase(quantity) )
{
int amt=Integer.parseInt(rate)*Integer.parseInt(quantity);
valueXmlString.append( "<amount><![CDATA[" ).append(amt).append( "]]></amount>\r\n" );
}
valueXmlString.append( "<rate><![CDATA[" ).append(rate).append( "]]></rate>\r\n" );
//}
sql="";
pStmt=null;
sql = "select descr from item where item_code=?";
pStmt = conn.prepareStatement(sql);
pStmt.setString(1, ITEM_CODE__SRV);
rs = pStmt.executeQuery();
if( rs.next() )
{
Description = checkNull(rs.getString("descr"));
System.out.println(Description);
}
closeStatementResultSet(pStmt, rs);
System.out.println("LGST Descr321 :"+Description);
valueXmlString.append( "<descr><![CDATA[" ).append(Description).append( "]]></descr>\r\n" );
}
else if( "quantity".equalsIgnoreCase(currentColumn) )
{
quantity = genericUtility.getColumnValue( "quantity", dom );
rate = genericUtility.getColumnValue( "rate", dom );
System.out.println("Rate 111: "+rate);
System.out.println("Rate 12345: "+rate);
int amt=Integer.parseInt(rate)*Integer.parseInt(quantity);
valueXmlString.append( "<amount><![CDATA[" ).append(amt).append( "]]></amount>\r\n" );
}
valueXmlString.append( "</Detail2>\r\n" );
}//end of case 2
break;
}//End of Switch
}//end of try block
catch( Exception e )
{
throw new ITMException(e);
}
finally
{
try
{
if( rs != null )
{
rs.close();
rs = null;
}
if( pStmt != null && !pStmt.isClosed() )
{
pStmt.close();
pStmt = null;
}
if( conn != null && !conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch( Exception e )
{
System.out.println( "Exception :AsnLotStatIC:itemChanged :==>\n"+e.getMessage());
}
}
valueXmlString.append( "</Root>\r\n" );
return valueXmlString.toString();
}//end of itemchange
private String checkNull( String input )
{
if ( input == null )
{
input = "";
}
return input;
}
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();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
private void closeStatementResultSet(PreparedStatement pstmt, ResultSet resultSet)
{
try
{
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
System.out.println("LGSTServiceIC.closeStatementResultSet() : "+e);
}
}
}
/**
* Author :Saiprasad G.
* Date :
*/
package ibase.webitm.ejb.wms;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import org.apache.commons.net.ntp.TimeStamp;
import org.w3c.dom.Document;
import org.w3c.dom.css.CSSUnknownRule;
import com.ibm.db2.jcc.b.SQLException;
import com.itextpdf.text.pdf.hyphenation.TernaryTree.Iterator;
import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
public class LgstProcess extends ProcessEJB
{
E12GenericUtility genericUtility=new E12GenericUtility();
public String process(String xmlString,String xmlString1,String windowName,String xtraParams) throws RemoteException,ITMException
{
Document detailDom = null;
Document headerDom = null;
String retStr = "";
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
System.out.println("headerDom" + headerDom);
}
if(xmlString1 != null && xmlString1.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString1);
System.out.println("detailDom" + detailDom);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
return retStr;
}
@Override
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams)throws RemoteException, ITMException
{
String retStr="",retCal="";
Connection con=null;
try
{
if(con==null)
{
con=getConnection();
con.setAutoCommit(false);
}
retStr=processData(headerDom, detailDom, windowName, xtraParams, con);
}
catch(Exception e)
{
System.out.println("Exception e1"+e);
}
return retStr;
}
public String processData(Document headerDom, Document detailDom, String windowName, String xtraParams,Connection con)throws RemoteException,ITMException
{
System.out.println("Inside the processdata method");
Timestamp effdate=null,validDate=null;
String userId=genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
String reString="";
ResultSet rs=null,rs1=null,stockRs=null;
PreparedStatement pStmt=null,pStmt1=null;
String siteSql="",packingSql="",itemCodeSql="",lotSl="",lotNo="",locCode="";
String quantity="",noArt="",itemType="",packCode="P001",volume="",siteCode="",itemCode="",facilitCode="",custCode="",fromDate="",toDate="",itemCode2="";
Double qty1=0.0;
Double qtyInv=0.0,qtyStock1=0.0,noOfArtInv=0.0,qtyHashMap=0.0;
String chgUserInv="";
String lotSlStok="",lotNoStock="",locCodeStock="",chgUserStok="",actItemCode="";
Timestamp trandate=null,ltranDate=null;
HashMap<String, Double> stockHashMap = new HashMap<>();
HashMap<Timestamp, HashMap<String, Double>> map = new HashMap<>();
HashMap<String,Double> qtyItemMap=new HashMap<>();
PreparedStatement stockPstmt = null;
try
{
siteCode=genericUtility.getColumnValue("site_code", headerDom);
fromDate=genericUtility.getColumnValue("fr_date",headerDom);
System.out.println("fromDate:"+fromDate);
SimpleDateFormat sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
Date frDate=sdf.parse(fromDate);
effdate = Timestamp.valueOf(genericUtility.getValidDateString(fromDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
System.out.println("effective from"+effdate);
toDate=genericUtility.getColumnValue("to_date",headerDom);
System.out.println("to date:"+toDate);
Date toDate1=sdf.parse(toDate);
validDate = Timestamp.valueOf(genericUtility.getValidDateString(toDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
Calendar toDatecal = Calendar.getInstance();
toDatecal.setTime(toDate1);
Calendar fromDatecal = Calendar.getInstance();
fromDatecal.setTime(frDate);
System.out.println("toDate in timestamp:"+validDate);
long diff=toDate1.getTime()-frDate.getTime();
long actualDiff=diff/ (24 * 60 * 60 * 1000);
int act=(int)actualDiff;
double stockQuantItem = 0.0;
for (int i = 0; i <= act; i++)
{
Date curDate = toDatecal.getTime();
Timestamp currDateTs=new Timestamp(curDate.getTime());
String currDateStr = sdf.format(curDate);
System.out.println("currdate:"+currDateTs);
String sql="SELECT NO_ART,ITEM_CODE,EFF_QTY,TRAN_DATE,LOC_CODE,LOT_NO,LOT_SL,CHG_USER,SITE_CODE FROM INVTRACE WHERE SITE_CODE=? "
+ "AND TRAN_DATE>=? AND TRAN_DATE<=?";
pStmt=con.prepareStatement(sql);
pStmt.setString(1, siteCode);
pStmt.setTimestamp(2, currDateTs);
pStmt.setTimestamp(3, currDateTs);
rs=pStmt.executeQuery();
stockQuantItem = 0;
HashMap<String, Double> hashMap = new HashMap<>();
while(rs.next())
{
noOfArtInv=rs.getDouble("NO_ART");
itemCode=rs.getString("ITEM_CODE");
qtyInv=rs.getDouble("EFF_QTY");
trandate=rs.getTimestamp("TRAN_DATE");
lotSl=rs.getString("LOT_SL");
lotNo=rs.getString("LOT_NO");
locCode=rs.getString("LOC_CODE");
chgUserInv=rs.getString("CHG_USER");
siteCode=rs.getString("SITE_CODE");
String key = itemCode.trim()+"_"+lotNo.trim()+"_"+locCode.trim()+"_"+lotSl.trim();
String getStockData = "select quantity from stock where item_code =? and lot_no = ? and site_code = ? and loc_code = ? and lot_sl = ?";
stockPstmt = con.prepareStatement(getStockData);
stockPstmt.setString(1, itemCode);
stockPstmt.setString(2, lotNo);
stockPstmt.setString(3, siteCode);
stockPstmt.setString(4, locCode);
stockPstmt.setString(5, lotSl);
stockRs = stockPstmt.executeQuery();
while(stockRs.next())
{
qtyStock1 = stockRs.getDouble("quantity");
if( ! stockHashMap.containsKey(key))
{
stockHashMap.put(key, qtyStock1);
}
}
if(qtyInv < 0)
{
stockQuantItem = stockHashMap.get(key)+Math.abs(qtyInv);
stockHashMap.put(key, stockQuantItem);;
}
else
{
stockQuantItem = stockHashMap.get(key)-qtyInv;
stockHashMap.put(key, stockQuantItem);;
}
if(hashMap.containsKey(key))
{
hashMap.put(key, stockHashMap.get(key));
}
else
{
hashMap.put(key, stockHashMap.get(key));
}
}
toDatecal.add(Calendar.DATE, -1);
if(!hashMap.isEmpty())
{
Timestamp frdate2 = new Timestamp(toDatecal.getTimeInMillis());
map.put(frdate2, hashMap);
}
System.out.println("final map:"+map);
}
for (Map.Entry<Timestamp, HashMap<String,Double>> entry : map.entrySet())
{
Timestamp timeKey = entry.getKey();
System.out.println("TimeKey:"+timeKey);
HashMap<String, Double> valueHashMap=new HashMap<>();
valueHashMap=entry.getValue();
System.out.println("valuehashmap:"+valueHashMap);
qtyItemMap.clear();
for (Map.Entry<String,Double> entry1 : valueHashMap.entrySet())
{
String allfields=entry1.getKey();
System.out.println("allfields:"+allfields);
String itemCodeArray[]=allfields.split("_");
actItemCode=itemCodeArray[0];
System.out.println("actual item code from hashmap"+actItemCode);
qtyHashMap=entry1.getValue();
if(!(qtyItemMap.containsKey(actItemCode)))
{
qtyItemMap.put(actItemCode,qtyHashMap);
System.out.println("qty item map:"+qtyItemMap);
}
else
{
double qty2=qtyItemMap.get(actItemCode);
System.out.println("qty2:"+qty2);
System.out.println("qtyHashMap :"+qtyHashMap);
qtyItemMap.put(actItemCode, qtyHashMap+qty2);
System.out.println("qtyItemMap:"+qtyItemMap);
}
itemCodeSql="SELECT ITEM_TYPE FROM ITEM WHERE ITEM_CODE=?";
pStmt=con.prepareStatement(itemCodeSql);
pStmt.setString(1,actItemCode);
rs=pStmt.executeQuery();
if(rs.next())
{
itemType=rs.getString("ITEM_TYPE");
//System.out.println("item type of item table:"+itemType);
}
rs.close();
pStmt.close();
packingSql="SELECT (LENGTH*WIDTH*HEIGHT) AS VOLUME FROM PACKING WHERE PACK_CODE=?";
pStmt=con.prepareStatement(packingSql);
pStmt.setString(1, packCode);
rs=pStmt.executeQuery();
if(rs.next())
{
volume=rs.getString("VOLUME");
//System.out.println("volume of the packing:"+volume);
}
rs.close();
pStmt.close();
siteSql="SELECT FACILITY_CODE FROM SITE WHERE SITE_CODE=?";
pStmt=con.prepareStatement(siteSql);
pStmt.setString(1,siteCode);
rs=pStmt.executeQuery();
if(rs.next())
{
facilitCode=rs.getString("FACILITY_CODE");
//System.out.println("facility code from the site "+facilitCode);
}
custCode=siteCode;
rs.close();
pStmt.close();
System.out.println("customer code for the wms_spac_uutl:"+custCode);
}//calculation
//getting the value of hasmap one by one and getting item code and actual qty of item
for(Map.Entry<String,Double> entryItemQty:qtyItemMap.entrySet())
{
String itemKeyInsert=entryItemQty.getKey();
System.out.println("itemKeyInsert"+itemKeyInsert);
Double qtyInsert=entryItemQty.getValue();
System.out.println("qtyInsert"+qtyInsert);
System.out.println("Getting the item code as key:"+itemKeyInsert);
System.out.println("Getting the qty against Quantity:"+qtyInsert);
System.out.println("---Inserting the data into the wms_space_utl----------");
StringBuilder wmsSpaceInsert=new StringBuilder();
wmsSpaceInsert.append("INSERT INTO WM_SPACE_UTIL(SITE_CODE,FACILITY_CODE,CUST_CODE,");
wmsSpaceInsert.append("ITEM_CODE,ITEM_TYPE,PACK_CODE,NO_ART,VOLUME,QUANTITY,TRAN_DATE)");
wmsSpaceInsert.append("VALUES(?,?,?,?,?,?,?,?,?,?)");
System.out.println("query for the inserting the data:"+wmsSpaceInsert);
pStmt=con.prepareStatement(wmsSpaceInsert.toString());
pStmt.setString(1, siteCode);
pStmt.setString(2,facilitCode );
pStmt.setString(3, custCode);
pStmt.setString(4, itemKeyInsert);
pStmt.setString(5, itemType);
pStmt.setString(6, packCode);
pStmt.setString(7, noArt);
pStmt.setString(8, volume);
pStmt.setDouble(9, Math.abs(qtyInsert));
pStmt.setTimestamp(10, timeKey);
int j=pStmt.executeUpdate();
System.out.println("Data inserted:"+j);
if (j > 0)
{
con.commit();
}
else
{
con.rollback();
}
}
}
}
catch(Exception e)
{
System.out.println("In the error2"+e);
}
finally
{
try
{
if(con!=null)
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pStmt != null)
{
pStmt.close();
pStmt =null;
con.close();
}
}
con = null;
}
catch(Exception d)
{
d.printStackTrace();
throw new ITMException( d );
}
}
return reString;
}
}
......@@ -237,6 +237,9 @@ Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,AR
Insert into SYSTEM_SERVICE_ARGS (SERVICE_CODE,LINE_NO,ARG_NAME,ARG_MODE,DESCR,ARG_TYPE,ARG_XFRM,CHG_DATE,CHG_USER,CHG_TERM,ARG_VALUE) values ('prc_lgst_process',6,'XTRA_PARAMS','I','Extra Arguments','S',null,sysdate,'BASE','BASE',null);
update transetup set brow_data_def = 'Y' where tran_window = 'w_lgst_contract';
update transetup set brow_data_def = 'Y' where tran_window = 'w_lgst_service';
--creation of the WM_SPACE_UTIL table structure
create table WM_SPACE_UTIL
(
......
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