Commit 23241126 authored by kmandhre's avatar kmandhre

source added for commission master


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@92735 ce508802-f39f-4f6c-b175-0d175dae99d5
parent d19cf56d
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.StringTokenizer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless; // added for ejb3
import ibase.webitm.ejb.ITMDBAccessEJB;
@Stateless // added for ejb3
public class CommissiondetIC extends ValidatorEJB implements CommissiondetICLocal,CommissiondetICRemote
{
GenericUtility genericUtility = GenericUtility.getInstance();
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
System.out.println("@@@@@@@@ wfValData called");
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
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;
int ctr=0;
String childNodeName = null;
String errString = "";
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null;
String sql = "";
int cnt=0;
int currentFormNo=0;
int childNodeListLength;
ConnDriver connDriver = new ConnDriver();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String userId="";
Timestamp validUpto = null ,effFrom2=null;
Timestamp effDate = null, newSysdate = null;
String lineNo="",commTable="",itemSer="",itemCode="",effDateStr="",validUptoStr="",commType="",commPercOn="",commPerc="";
String effDateTemp=null ;
String descr = "";
Timestamp effDateTemp2=null ,ValidUptoLastTemp=null, ValidUptoLastTemp2=null;
int ctr1=0,k=0,l=1;
String dateStr=null,itemCodeTemp="",itemSerTemp="",validUptoTemp="",itemSerTempLast="",itemCodeTempLast="";
java.sql.Timestamp validUptoTemp2=null;
try
{
System.out.println("@@@@@@@@ wfvaldata called");
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equalsIgnoreCase("comm_table") && ("A".equalsIgnoreCase(editFlag)) )
{
System.out.println("validation comm_table executed");
commTable = genericUtility.getColumnValue("comm_table",dom);
if(commTable == null || commTable.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMCOMTBNUL",userId);
break ;
}
else
{
sql = "SELECT COUNT(1) FROM COMM_HDR WHERE COMM_TABLE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, commTable );
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( cnt > 0 )
{
errString = itmDBAccessEJB.getErrorString("","VMCOMTBINV",userId);
break ;
}
}
}
if(childNodeName.equalsIgnoreCase("descr") )
{
descr = genericUtility.getColumnValue("descr",dom);
System.out.println("descr === "+descr);
if(descr == null || descr.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMDESCR",userId);
break ;
}
}
} // end for
break;
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equalsIgnoreCase("comm_table"))
{
System.out.println("validation comm_table executed");
commTable = genericUtility.getColumnValue("comm_table",dom);
if(commTable == null || commTable.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMCOMTBNUL",userId);
break ;
}
}
if(childNodeName.equalsIgnoreCase("line_no"))
{
System.out.println("validation line no executed");
lineNo = genericUtility.getColumnValue("line_no",dom);
if(lineNo == null || lineNo.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VNLINENONU",userId);
break ;
}
}
else if(childNodeName.equalsIgnoreCase("item_ser"))
{
System.out.println("validation item series executed");
itemSer = genericUtility.getColumnValue("item_ser",dom);
if( itemSer == null || itemSer.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMITMSERN",userId);
break ;
}
else
{
sql = "SELECT COUNT(1) FROM ITEM WHERE ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, itemSer );
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( cnt == 0 )
{
errString = itmDBAccessEJB.getErrorString("","VMITMSRIN2",userId);
break ;
}
}
}
else if(childNodeName.equalsIgnoreCase("item_code"))
{
System.out.println("validation item_code executed");
itemCode = genericUtility.getColumnValue("item_code",dom);
itemSer = genericUtility.getColumnValue("item_ser",dom);
if( itemCode == null || itemCode.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMITMCODNU",userId);
break ;
}
else
{
if( itemSer != null && itemSer.trim().length() > 0 )
{
sql = "SELECT COUNT(1) FROM ITEM WHERE ITEM_CODE = ? AND ITEM_SER = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, itemCode );
pstmt.setString( 2, itemSer );
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if( cnt == 0 )
{
errString = itmDBAccessEJB.getErrorString("","VMITMSRINV",userId);
break ;
}
}
}
}
else if(childNodeName.equalsIgnoreCase("eff_date"))
{
effDateStr =genericUtility.getColumnValue("eff_date",dom);
validUptoStr =genericUtility.getColumnValue("valid_upto",dom);
System.out.println("@@@@@@@@@@ date validation : eff date");
if(effDateStr==null || effDateStr.trim().length()==0)
{
errString = getErrorString("eff_from","VMEFFDTNUL",userId);
break;
}
else
{
if(validUptoStr == null || validUptoStr.trim().length()==0)
{
errString = itmDBAccessEJB.getErrorString("","VMVALDTNUL",userId);
break ;
}
effDate= Timestamp.valueOf(genericUtility.getValidDateString(effDateStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
validUpto= Timestamp.valueOf(genericUtility.getValidDateString(validUptoStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
commTable = genericUtility.getColumnValue("comm_table", dom);
lineNo = genericUtility.getColumnValue("line_no",dom);
System.out.println("effDate date is :=> " + effDate);
System.out.println("validUpto date is :=> " + validUpto);
if( !validUpto.after(effDate) )
{
System.out.println("effFrom.after(validUpto");
errString = getErrorString("","INVEFDATE ",userId);
System.out.println("errString befor break" +errString);
break;
}
}
}
else if(childNodeName.equalsIgnoreCase("valid_upto"))
{
System.out.println("@@@@@@@@@@ date validation : valid upto");
effDateStr =genericUtility.getColumnValue("eff_date",dom);
validUptoStr =genericUtility.getColumnValue("valid_upto",dom);
if((effDateStr != null) && (validUptoStr != null))
{
effDate= Timestamp.valueOf(genericUtility.getValidDateString(effDateStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
validUpto= Timestamp.valueOf(genericUtility.getValidDateString(validUptoStr, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("effDate date is :=> " + effDate);
System.out.println("validUpto date is :=> " + validUpto);
if( !validUpto.after(effDate) )
{
//Valid upto cannot be less than effective date
errString = itmDBAccessEJB.getErrorString("","INVEFDATE",userId);
break ;
}
}
else
{
//Date cannot be empty. Please enter valid date.
errString = itmDBAccessEJB.getErrorString("","VMVALDTNUL",userId);
break ;
}
}
else if(childNodeName.equalsIgnoreCase("comm_type"))
{
System.out.println("validation comm_type executed");
commType = genericUtility.getColumnValue("comm_type",dom);
if(commType == null || commType.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMCOMTYPNU",userId);
break ;
}
}
else if(childNodeName.equalsIgnoreCase("comm_perc"))
{
System.out.println("validation comm perc executed");
commPerc = genericUtility.getColumnValue("comm_perc",dom);
if(commPerc == null || commPerc.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMCOMPERNU",userId);
break ;
}
}
else if(childNodeName.equalsIgnoreCase("comm_perc__on"))
{
System.out.println("validation comm_perc__on executed");
commPercOn = genericUtility.getColumnValue("comm_perc__on",dom);
if(commPercOn == null || commPercOn.trim().length() == 0)
{
errString = itmDBAccessEJB.getErrorString("","VMCOPONNUL",userId);
break ;
}
}
}
} //END switch
/*boolean res = dateCheck (dom,dom2,itemCode,itemSer); //comment by kunal on 22/02/13
System.out.println("@@@@ res::"+res);
if( res == true )
{
errString = itmDBAccessEJB.getErrorString("","VMVALDTWR",userId);
return errString;
}*/
}//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();
rs = null;
if(pstmt != null )pstmt.close();
pstmt =null;
conn.close();
}
conn = null;
}
catch(Exception d)
{
d.printStackTrace();
}
}
System.out.println("ErrString ::"+errString);
return errString;
}//END OF VALIDATION
public String itemChanged(String xmlString, String xmlString1, String xmlString2,String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("@@@@@@@ default itemChanged called");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [TrainingEJB][itemChanged(String,String)] :==>\n"+e.getMessage());
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("@@@@@@@ itemChanged called");
StringBuffer valueXmlString = new StringBuffer();
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null ;
String childNodeName = null;
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
String sql="";
int currentFormNo =0;
String columnValue="",chgUser="",chgTerm="",itemCode="",itemDescr="", fSysDate = "";
//String custCode="",custDescr="";
//String col_name,scustName="",custType="",crTerm="",Descr="",custName="";
int ctr=0;
try
{
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver=null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext.trim());
}
chgTerm = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "chgTerm" );
chgUser = genericUtility.getValueFromXTRA_PARAMS( xtraParams, "chgUser" );
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("**********ITEMCHANGE FOR CASE"+currentFormNo+"**************");
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
valueXmlString.append("<Detail1>");
int 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("[" + currentColumn + "] ==> '" + columnValue + "'");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ) )
{
System.out.println("--------------------ITM_DEFAULT-----------------------");
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String sysDate = sdf.format(currentDate.getTime());
System.out.println("Now the date is :=> " + sysDate);
valueXmlString.append( "<chg_date><![CDATA[" ).append(sysDate).append( "]]></chg_date>\r\n" );
valueXmlString.append( "<chg_term><![CDATA[" ).append( chgTerm ).append( "]]></chg_term>\r\n" );
valueXmlString.append( "<chg_user><![CDATA[" ).append( chgUser ).append( "]]></chg_user>\r\n" );
}
valueXmlString.append("</Detail1>");
break;
// case 2 start
case 2 :
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
valueXmlString.append("<Detail2>");
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("[" + currentColumn + "] ==> '" + columnValue + "'");
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ) )
{
System.out.println("--------------------ITM_DEFAULT-----------------------");
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String sysDate = sdf.format(currentDate.getTime());
System.out.println("Now the date is :=> " + sysDate);
currentDate.add(Calendar.DAY_OF_MONTH, +1);
fSysDate = sdf.format(currentDate.getTime());
System.out.println("Now the future date is :=> " + fSysDate);
valueXmlString.append( "<eff_date><![CDATA[" ).append(sysDate).append( "]]></eff_date>\r\n" );
valueXmlString.append( "<valid_upto><![CDATA[" ).append( fSysDate ).append( "]]></valid_upto>\r\n" );
}
valueXmlString.append("</Detail2>");
break;
// case 2 end
}
valueXmlString.append("</Root>");
}// end try
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
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 valueXmlString.toString();
}//End of itemChanged
public boolean dateCheck (Document dom,Document dom2,String pitemCode,String pitemSer) throws Exception
{
String lineNo="",commTable="",itemSer="",itemCode="",effDateStr="",validUptoStr="";
String effDateTemp=null ;
Timestamp effDateTemp2=null ,ValidUptoLastTemp=null, ValidUptoLastTemp2=null;
String errString = "";
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
//String userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
int ctr1=0,k=0,l=1,noOfParent=0;
String dateStr=null,itemCodeTemp="",itemSerTemp="",validUptoTemp="",itemSerTempLast="",itemCodeTempLast="";
java.sql.Timestamp validUptoTemp2=null;
NodeList detail2List = dom2.getElementsByTagName("Detail2");
NodeList detail1List = dom2.getElementsByTagName("Detail1");
ArrayList arrLstDate=new ArrayList();
if(detail2List != null && detail2List.getLength() > 0)
{
noOfParent = detail2List.getLength();
System.out.println("@@@@@@@@ noOfParent [["+noOfParent +"]]");
System.out.println("@@@@ pitemCode:["+pitemCode+"]::::pitemSer["+pitemSer+"]");
for ( ctr1 = 0; ctr1 < noOfParent; ctr1++ ) //Loop for each node of current detail
{
itemCode = genericUtility.getColumnValueFromNode( "item_code", detail2List.item(ctr1) );
effDateStr = genericUtility.getColumnValueFromNode( "eff_date", detail2List.item(ctr1) );
validUptoStr = genericUtility.getColumnValueFromNode( "valid_upto", detail2List.item(ctr1) );
itemSer = genericUtility.getColumnValueFromNode( "item_ser", detail2List.item(ctr1) );
System.out.println("@@@@ itemCode:["+itemCode+"]::::itemSer["+itemSer+"]");
dateStr = validUptoStr+"@"+effDateStr ;
System.out.println("dateStr[[[[[[[["+dateStr+"]]]]]]]]]");
if( ( pitemCode.trim().equalsIgnoreCase( itemCode.trim() )) && ( pitemSer.trim().equalsIgnoreCase(itemSer.trim() ) ))
{
arrLstDate.add(dateStr);
System.out.println("@@@@ added in arraylist");
}
}
Collections.sort(arrLstDate);
System.out.println("@@@@@arrLstDate.size()["+arrLstDate.size()+"]]]:: Sorted::::"+arrLstDate);
for( k=0;k< arrLstDate.size();k++)
{
String temp = (String) arrLstDate.get(k);
StringTokenizer st = new StringTokenizer(temp,"@");
while(st.hasMoreTokens())
{
if( l== 1)
{
validUptoTemp = st.nextToken();
l++;
}
else if( l== 2)
{
effDateTemp = st.nextToken();
l=1;
}
}
effDateTemp2 = Timestamp.valueOf(genericUtility.getValidDateString(effDateTemp, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
validUptoTemp2 = Timestamp.valueOf(genericUtility.getValidDateString(validUptoTemp, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("@@@@@date111@@@ValidUptoLastTemp["+ValidUptoLastTemp+"] ::validUptoTemp2["+validUptoTemp2+"]");
if( ValidUptoLastTemp != null )
{
SimpleDateFormat sdf = new SimpleDateFormat(getApplDateFormat());
Calendar c = Calendar.getInstance();
c.setTime((effDateTemp2));
c.add(Calendar.DATE, -1);
effDateTemp2 = new Timestamp( c.getTimeInMillis());
System.out.println("@@@@@date@@@effDateTemp2["+effDateTemp2+"] ::ValidUptoLastTemp["+ValidUptoLastTemp+"]");
if( !(effDateTemp2.equals( ValidUptoLastTemp )))
{
System.out.println("@@@@@@@ error in date");
return true;
}
}
//else
//{
// itemCodeTempLast = itemCodeTemp;
// itemSerTempLast = itemSerTemp;
//}
ValidUptoLastTemp = validUptoTemp2;
}
}
return false;
}
}
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local; // added for ejb3
//public interface SOrderForm extends ValidatorLocal,EJBObject
@Local // added for ejb3
public interface CommissiondetICLocal
{
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 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 org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote; // added for ejb3
//public interface SOrderForm extends ValidatorLocal,EJBObject
@Remote // added for ejb3
public interface CommissiondetICRemote
{
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 dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
//import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
@javax.ejb.Stateless
public class CommissiondetPos extends ValidatorEJB implements CommissiondetPosLocal, CommissiondetPosRemote
{
public String postSave()throws RemoteException,ITMException
{
return "";
}
public String postSave(String domString, String tranId,String editFlag, String xtraParams, Connection conn ) throws RemoteException,ITMException
//public String postSave(String domString, String tranId, String objContext, String editFlag, String xtraParams ) throws RemoteException,ITMException
{
String errString = "";
Document dom = null;
PreparedStatement pstmt = null,pstmt1= null,pstmt2= null;
ResultSet rs = null,rs1 = null,rs2 = null;
String sql = "",sql1="",sql2="";
String itemCode = "";
System.out.println(" Tran id = "+tranId);
System.out.println("dom Strig = "+domString);
int noOfParent = 0,i = 0;
boolean found = false,isError = false;
java.sql.Timestamp effDate = null,effDateLast = null;
java.sql.Timestamp validUpto = null, validUptoLast=null;
SimpleDateFormat sdf1 = null;
String effDateStr="",itemSer="",validUptostr="",commTable="",retString="",lineNo="",lineNoLast="";
String customError = "",mainStr = "", begPart = "" ,endPart = "";
int cnt=0;
//ConnDriver connDriver = null;
//Connection conn=null;
System.out.println("Connection = "+conn);
try
{
conn.setAutoCommit(false);
GenericUtility genericUtility = GenericUtility.getInstance();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
sdf1 = new SimpleDateFormat(genericUtility.getDBDateFormat());
dom = genericUtility.parseString(domString);
NodeList detail3List = dom.getElementsByTagName("Detail2");
NodeList detail1List = dom.getElementsByTagName("Detail1");
System.out.println("@@@@@ postSave called");
System.out.println("@@@@@@@@ detail3List [[[[[[[["+detail3List.toString()+"]]]]]]]]]]]]]");
System.out.println("@@@@@@@@ detail1List [[[[[[[["+detail1List.toString()+"]]]]]]]]]]]]]");
if(detail3List != null && detail3List.getLength() > 0)
{
commTable = genericUtility.getColumnValueFromNode("comm_table", dom.getElementsByTagName("Detail2").item(0));
//effDateStr = genericUtility.getColumnValueFromNode("eff_date", dom.getElementsByTagName("Detail2").item(0));
//validUptostr = genericUtility.getColumnValueFromNode("valid_upto", dom.getElementsByTagName("Detail2").item(0));
//lineNo = genericUtility.getColumnValueFromNode("line_no", dom.getElementsByTagName("Detail2").item(0));
//itemCode = genericUtility.getColumnValueFromNode("item_code", dom.getElementsByTagName("Detail2").item(0));
//itemSer = genericUtility.getColumnValueFromNode("item_ser", dom.getElementsByTagName("Detail2").item(0));
noOfParent = detail3List.getLength();
sql2 = " select distinct item_code, item_ser from comm_det where comm_table= ? ";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1,commTable);
rs2 = pstmt2.executeQuery();
while(rs2.next())
{
itemCode = rs2.getString("item_code");
itemSer= rs2.getString("item_ser");
validUptoLast = null;
lineNoLast = null;
sql = " select line_no,eff_date,valid_upto FROM comm_det where comm_table = ? and item_code=? and item_ser= ? order by eff_date asc " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,commTable);
pstmt.setString(2,itemCode);
pstmt.setString(3,itemSer);
rs = pstmt.executeQuery();
while(rs.next())
{
// int cnt = rs.getInt(1);
lineNo = rs.getString("line_no");
effDate = rs.getTimestamp("eff_date");
validUpto = rs.getTimestamp("valid_upto");
if( validUptoLast != null && ( lineNoLast != null ) )
{
System.out.println("EffDate = "+effDate +" valid up last = "+validUptoLast+" valid Upto="+validUpto);
if(! (validUpto.after(validUptoLast)) )
{
conn.rollback();
customError = "Invalid Effective Date and Valid Upto Date for Line No = "+lineNo+" .";
retString = itmDBAccessEJB.getErrorString("","INVLDT01","","",conn);
begPart = retString.substring( 0, retString.indexOf("<trace>") + 7 );
endPart = retString.substring( retString.indexOf("</trace>"));
mainStr = begPart + customError + endPart;
errString = mainStr;
System.out.println("mainStr-----"+mainStr);
return errString;
}
if( effDate.before(validUptoLast) || ((int)( (effDate.getTime() - validUptoLast.getTime()) / (1000 * 60 * 60 * 24))) == 0 )
{
Calendar c = Calendar.getInstance();
c.setTime((effDate));
c.add(Calendar.DATE, -1);
validUptoLast = new Timestamp( c.getTimeInMillis());
System.out.println("@@@@@@@@@@@@ new date into validUpto new : ["+validUptoLast+"]");
// System.out.println("@@@@@updating:::.["+commTable+"]...["+lineNo+"]....["+validUptoLast+"]....["+ cnt+"]record update successfully.");
sql1="UPDATE COMM_DET SET valid_upto= ? WHERE COMM_TABLE= ? and LINE_NO = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,validUptoLast);
pstmt1.setString(2,commTable);
pstmt1.setString(3,lineNoLast);
cnt = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
if ( cnt > 0 )
{
System.out.println("@@@@@@update sucess:::.["+commTable+"]...["+lineNoLast+"]....["+validUptoLast+"]....["+ cnt+"]record update successfully.");
}
}
if(effDate.after(validUptoLast))
{
int diffInDays = (int)( (effDate.getTime() - validUptoLast.getTime()) / (1000 * 60 * 60 * 24) );
System.out.println("Diff Days="+diffInDays);
if(diffInDays > 1)
{
Calendar c = Calendar.getInstance();
c.setTime((validUptoLast));
c.add(Calendar.DATE, (diffInDays - 1));
validUptoLast = new Timestamp( c.getTimeInMillis());
System.out.println("@@@@@@@@@@@@ new date into validUpto new 2: ["+validUptoLast+"]");
sql1="UPDATE COMM_DET SET valid_upto= ? WHERE COMM_TABLE= ? and LINE_NO = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,validUptoLast);
pstmt1.setString(2,commTable);
pstmt1.setString(3,lineNoLast);
cnt = pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
if ( cnt > 0 )
{
System.out.println("@@@@@@update sucess2::record update successfully.");
}
}
}
}
validUptoLast = validUpto;
effDateLast = effDate;//added by kunal on 22/02/13
lineNoLast = lineNo;
System.out.println("@@@@ validUptoLast"+validUptoLast+"::::lineNoLast"+lineNoLast);
} // inside querry
rs.close();
rs = null;
pstmt.close();
pstmt = null;
} // outside querry
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
}
}
catch(Exception e)
{
try
{
isError = true;
if(conn != null)
{
conn.rollback();
}
System.out.println("Exception.. "+e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
catch (Exception e1)
{
e1.printStackTrace();
throw new ITMException(e1);
}
}
finally
{
try
{
if(isError)
{
conn.rollback();
System.out.println("Transaction rollback... ");
}
else
{
conn.commit();
System.out.println("@@@@ Transaction commit... ");
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
}
/* This file is Cteated it incorporate the Pre Save logic from Window
* Gulzar 08/09/06
*/
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.sql.Connection;
import javax.ejb.Local; // added for ejb3
//public interface SReturnPrs extends ValidatorLocal, EJBObject
@Local // added for ejb3
public interface CommissiondetPosLocal extends ValidatorLocal
{
//public String preSaveRec()throws RemoteException,ITMException;
//public String preSaveRec(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
public String postSave()throws RemoteException,ITMException;
//public String postSave( String domString,String tranId, String objContext, String editFlag, String xtraParams ) throws RemoteException,ITMException;
public String postSave( String domString,String tranId, String editFlag, String xtraParams, Connection conn ) throws RemoteException,ITMException;
}
/* This file is Cteated it incorporate the Pre Save logic from Window
* Gulzar 08/09/06
*/
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
//import javax.ejb.EJBObject;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.sql.Connection;
import javax.ejb.Remote; // added for ejb3
//public interface SReturnPrs extends ValidatorRemote, EJBObject
@Remote // added for ejb3
public interface CommissiondetPosRemote extends ValidatorRemote
{
//public String preSaveRec()throws RemoteException,ITMException;
//public String preSaveRec(String xmlString1,String domID,String objContext,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException;
public String postSave()throws RemoteException,ITMException;
//public String postSave( String domString,String tranId, String objContext, String editFlag, String xtraParams ) throws RemoteException,ITMException;
public String postSave( String domString,String tranId, String editFlag, String xtraParams, Connection conn ) throws RemoteException,ITMException;
}
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