Commit b3e1fac6 authored by dpawar's avatar dpawar

added validation for bill no and bill date


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94043 ce508802-f39f-4f6c-b175-0d175dae99d5
parent f4627904
package ibase.webitm.ejb.dis; package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility; import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
...@@ -21,6 +22,7 @@ import java.util.HashMap; ...@@ -21,6 +22,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
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.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
...@@ -29,6 +31,8 @@ import org.w3c.dom.NodeList; ...@@ -29,6 +31,8 @@ import org.w3c.dom.NodeList;
public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLocal,ProofOfDeliveryRemote public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLocal,ProofOfDeliveryRemote
{ {
String str,confirmedInv=""; String str,confirmedInv="";
boolean isError=false;
GenericUtility genericUtility = GenericUtility.getInstance();
public static ProofOfDelivery getInstance() public static ProofOfDelivery getInstance()
{ {
return new ProofOfDelivery(); return new ProofOfDelivery();
...@@ -61,13 +65,15 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -61,13 +65,15 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
public String wfValData(Document dom, Document dom1, Document dom2,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
{ {
isError=false;
NodeList parentNodeList = null; NodeList parentNodeList = null;
NodeList childNodeList = null; NodeList childNodeList = null;
Node parentNode = null; Node parentNode = null;
Node childNode = null; Node childNode = null;
int ctr=0; int ctr=0;
String childNodeName = null; String childNodeName = null;
String errString = "",errorType="",loginSite="",status="",invoiceID="",sreturnTranID="",sql1=""; String errString = "",errorType="",loginSite="",status="",invoiceID="",sreturnTranID="",sql1="",userId="";
String errCode="";
Connection conn = null; Connection conn = null;
PreparedStatement pstmt; PreparedStatement pstmt;
ResultSet rs=null; ResultSet rs=null;
...@@ -79,13 +85,9 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -79,13 +85,9 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
ArrayList <String> errList = new ArrayList<String>(); ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> (); ArrayList <String>errFields = new ArrayList <String> ();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>"); StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
try try
{ {
String userId=null,errCode=null;
GenericUtility genericUtility = GenericUtility.getInstance();
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode"); userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
...@@ -164,7 +166,6 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -164,7 +166,6 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
} }
} }
//------------------------------------------------------
if(cnt == 0) if(cnt == 0)
{ {
errCode = "VTINVIDNE"; errCode = "VTINVIDNE";
...@@ -206,8 +207,6 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -206,8 +207,6 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
errFields.add( childNodeName.toLowerCase() ); errFields.add( childNodeName.toLowerCase() );
} }
} }
} }
if (childNodeName.equalsIgnoreCase("cust_code")) if (childNodeName.equalsIgnoreCase("cust_code"))
...@@ -421,7 +420,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -421,7 +420,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
aprvRateD=Double.parseDouble(apprvRate); aprvRateD=Double.parseDouble(apprvRate);
rateResaleD=Double.parseDouble(rateResale); rateResaleD=Double.parseDouble(rateResale);
System.out.println("Approve rate---->>>["+aprvRateD+"]"); System.out.println("Approve rate---->>>["+aprvRateD+"]");
System.out.println("Approve rate---->>>["+rateResaleD+"]"); System.out.println("rateResaleD---->>>["+rateResaleD+"]");
if(aprvRateD > rateResaleD) if(aprvRateD > rateResaleD)
{ {
...@@ -437,6 +436,19 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -437,6 +436,19 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
} }
} }
if(childNodeName.equalsIgnoreCase("bill_no"))
{
String billNo="";
billNo=genericUtility.getColumnValue("bill_no", dom);
billNo=billNo==null ? "" :billNo.trim();
System.out.println("Bill no--------->>["+billNo+"]");
if(billNo.length() == 0)
{
errCode = "VTBILNNN";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
if(childNodeName.equalsIgnoreCase("bil_date")) if(childNodeName.equalsIgnoreCase("bil_date"))
{ {
String billDate="",billNo="",sql="",invID="",custCodeCurr="",invoiceDate="",tranId=""; String billDate="",billNo="",sql="",invID="",custCodeCurr="",invoiceDate="",tranId="";
...@@ -453,7 +465,14 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -453,7 +465,14 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
custCodeCurr=custCodeCurr==null ? "" :custCodeCurr.trim(); custCodeCurr=custCodeCurr==null ? "" :custCodeCurr.trim();
System.out.println("customer Code Current--------->>["+custCodeCurr+"]"); System.out.println("customer Code Current--------->>["+custCodeCurr+"]");
if(billDate.length() == 0)
{
errCode = "VTBILDNN";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
else
{
if(invID.length() > 0 && billDate.length() > 0){ if(invID.length() > 0 && billDate.length() > 0){
sql="select conf_date from invoice where invoice_id = ?"; sql="select conf_date from invoice where invoice_id = ?";
pstmt=conn.prepareStatement(sql); pstmt=conn.prepareStatement(sql);
...@@ -484,31 +503,30 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -484,31 +503,30 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
{ {
diffDays=rs.getInt(1); diffDays=rs.getInt(1);
} }
rs.close();
rs=null;
pstmt.close();
pstmt=null;
System.out.println("Difference in days for validation--->>["+diffDays+"]"); System.out.println("Difference in days for validation--->>["+diffDays+"]");
if(diffDays < 0) if(isBillNoRepeatedInYear(conn,billNo,billDate,custCodeCurr))
{ {
errCode = "VTINDLSTD"; System.out.println("------bill and stockist and year matched-----------");
errCode = "VTBLBDNRP";
errList.add( errCode ); errList.add( errCode );
errFields.add( childNodeName.toLowerCase() ); errFields.add( childNodeName.toLowerCase() );
} }
if(diffDays <= 365) if(diffDays < 0)
{
isDateAft=true;
}
}
if(billNo.length() > 0){
if(isBilNoBilDtStkRepeted(conn,billNo,custCodeCurr,isDateAft))
{ {
errCode = "VTBLBDNRP"; //Bill no., bill date can not be repeated for this invoice errCode = "VTINDLSTD";
errList.add( errCode ); errList.add( errCode );
errFields.add( childNodeName.toLowerCase() ); errFields.add( childNodeName.toLowerCase() );
}
}
} }
}
}
} //end else
} }
...@@ -583,6 +601,10 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -583,6 +601,10 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
rs.close(); rs.close();
rs=null; rs=null;
} }
if(isError)
{
return itmDBAccessEJB.getErrorString("", "VTTNSVD", "", "", conn);
}
} }
catch(Exception d) catch(Exception d)
...@@ -596,6 +618,146 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -596,6 +618,146 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
} }
private boolean isBillNoRepeatedInYear(Connection conn,String billNoL,String stockistDateL,String currCustCode)
{
System.out.println("--------in isBillNoRepeated method-------");
billNoL=billNoL==null ? "" :billNoL.trim();
System.out.println("BollNoL-------->>"+billNoL);
ResultSet rs=null,rs1=null;
PreparedStatement pstmt=null,pstmt1=null;
int currStkYear=0,actStkYear=0;
ArrayList <String> BillNo=new ArrayList<String>();
String sql="",sql1="",billNo="",custCode="",tranId="";
Timestamp stockistDate=null;
try{
SimpleDateFormat sdf = new SimpleDateFormat((genericUtility.getApplDateFormat()));
java.util.Date date = sdf.parse(stockistDateL);
java.sql.Timestamp stkTimest = new java.sql.Timestamp(date.getTime());
System.out.println("Stockist Date current---->>"+stkTimest);
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
String CurrYear=sdf1.format(date);
System.out.println("Current stk Year------>>["+CurrYear+"]");
currStkYear=Integer.parseInt(CurrYear);
sql="select tran_id,cust_code from spl_sales_por_hdr";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
tranId=rs.getString(1);
custCode=rs.getString(2);
tranId=tranId==null ?"" :tranId.trim();
custCode=custCode==null ?"" :custCode.trim();
sql1="select bill_no,bil_date from spl_sales_por_det where tran_id = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
rs1=pstmt1.executeQuery();
while (rs1.next()){
billNo=rs1.getString(1);
stockistDate=rs1.getTimestamp(2);
billNo=billNo==null ?"" :billNo.trim();
if(stockistDate!=null){
if(custCode.equalsIgnoreCase(currCustCode)){
System.out.println("currCustCode Condition true--->>["+billNo+"]["+currCustCode+"]");
if(billNo.equalsIgnoreCase(billNoL)){
System.out.println("billNo Condition true--->>333["+billNo+"]");
String year1=sdf1.format(stockistDate);
System.out.println("stkDate Sting-------->>["+year1+"]");
actStkYear=Integer.parseInt(year1);
if(currStkYear == actStkYear){
System.out.println("$$$$---Return true from isBillNoRepeatedInYear method--%%%%");
return true;
}
}
}}
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
catch(Exception e)
{
System.out.println("--------Exception : in isBillNoRepeated method----------");
isError=true;
e.printStackTrace();
}
return false;
}
protected int getDBRowCount(Connection conn, String table_name, String whrCondCol, String whrCondVal)
{
int count=-1;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="select count(1) from "+table_name+" where "+whrCondCol+" = ?";
System.out.println("SQL in getDBRowCount method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception In getDBRowCount method of ProofOfDelivery Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getDBRowCount method of ProofOfDelivery Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("Connection passed to ProofOfDelivery.getDBRowCount() method is null");
} catch (SQLException e) {
e.printStackTrace();
isError=true;
}
}
return count;
}
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
{ {
System.out.println("------------------ itemChanged called------------------"); System.out.println("------------------ itemChanged called------------------");
...@@ -619,6 +781,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -619,6 +781,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
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
{ {
isError=false;
System.out.println("@@@@@@@ itemChanged called"); System.out.println("@@@@@@@ itemChanged called");
StringBuffer valueXmlString = new StringBuffer(); StringBuffer valueXmlString = new StringBuffer();
Connection conn = null; Connection conn = null;
...@@ -904,6 +1067,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -904,6 +1067,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
{ {
e.printStackTrace(); e.printStackTrace();
System.out.println("Exception ::"+e.getMessage()); System.out.println("Exception ::"+e.getMessage());
isError=true;
throw new ITMException(e); throw new ITMException(e);
} }
finally finally
...@@ -943,133 +1107,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -943,133 +1107,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
return str; return str;
} }
private boolean isBilNoBilDtStkRepeted(Connection conn,String billNoCurr,String custCodeCurr,boolean isDateAft1Yr)
{
System.out.println("--------------------in isBilNoBilDtStkNotRepeted method------------------");
System.out.println("Bill No. Current--->>["+billNoCurr+"]");
System.out.println("customer Code Current--->>["+custCodeCurr+"]");
System.out.println("isDateAft1Yr--->>["+isDateAft1Yr+"]");
ResultSet rs=null,rs1=null;
PreparedStatement pstmt=null,pstmt1=null;
String sql="",sql1="",invoiceId="",tranId="",billNo="",custCode="",custCodeBil="";
try{
sql="select tran_id,invoice_id,cust_code from spl_sales_por_hdr";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
tranId=rs.getString(1);
invoiceId=rs.getString(2);
tranId=tranId==null ?"" :tranId.trim();
invoiceId=invoiceId==null ?"" :invoiceId.trim();
System.out.println("Invoice id spl_sales_por_hdr--->>["+invoiceId+"]");
custCodeBil=getNameOrDescrForCode(conn, "invoice", "cust_code__bil", "invoice_id", invoiceId);
custCodeBil=custCodeBil==null ? "" :custCodeBil.trim();
System.out.println("custCodeBil--->>["+custCodeBil+"]");
sql1="select bill_no from spl_sales_por_det where tran_id = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
rs1=pstmt1.executeQuery();
while (rs1.next()){
billNo=rs1.getString(1);
billNo=billNo==null ?"" :billNo.trim();
System.out.println("billNor--->>1111["+billNo+"]");
System.out.println("billNoCurr--->>111["+billNoCurr+"]");
System.out.println("isDateAft1Yr--->>1111["+isDateAft1Yr+"]");
if(isDateAft1Yr){
System.out.println("Condition true--->>1111["+custCodeBil+"]["+custCodeCurr+"]");
if(custCodeBil.equalsIgnoreCase(custCodeCurr)){
System.out.println("Condition true--->>2222["+billNo+"]["+billNoCurr+"]");
if(billNo.equalsIgnoreCase(billNoCurr)){
System.out.println("Condition true--->>333["+billNo+"]");
return true;
}
}
}
}
pstmt1.close();
pstmt1=null;
rs1.close();
rs1=null;
}
pstmt.close();
pstmt=null;
rs.close();
rs=null;
}//end try
catch(Exception e){
e.printStackTrace();
}
return false;
}
protected int getDBRowCount(Connection conn, String table_name, String whrCondCol, String whrCondVal)
{
int count=-1;
if(conn!=null){
ResultSet rs=null;
PreparedStatement pstmt = null;
String sql="select count(1) from "+table_name+" where "+whrCondCol+" = ?";
System.out.println("SQL in getDBRowCount method : "+sql);
try
{
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,whrCondVal);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
}
catch(SQLException e)
{
System.out.println("SQL Exception In getDBRowCount method of ProofOfDelivery Class : "+e.getMessage());
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println("Exception In getDBRowCount method of ProofOfDelivery Class : "+ex.getMessage());
ex.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
pstmt = null;
}
if(rs!=null){
rs.close();
rs = null;
}
}catch (SQLException se) {
se.printStackTrace();
}
}
}else{
try {
throw new SQLException("Connection passed to ProofOfDelivery.getDBRowCount() method is null");
} catch (SQLException e) {
e.printStackTrace();
}
}
return count;
}
private boolean isTotalAmountPodQtyGrt(Connection conn,String invID,double actualInvQty,double currentPodQty,String itemCodeSret) private boolean isTotalAmountPodQtyGrt(Connection conn,String invID,double actualInvQty,double currentPodQty,String itemCodeSret)
...@@ -1202,6 +1240,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -1202,6 +1240,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
{ {
System.out.println("Exception : In finally block "); System.out.println("Exception : In finally block ");
e.printStackTrace(); e.printStackTrace();
isError=true;
} }
} }
...@@ -1291,6 +1330,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca ...@@ -1291,6 +1330,7 @@ public class ProofOfDelivery extends ValidatorEJB implements ProofOfDeliveryLoca
{ {
System.out.println("Exception : In finally block "); System.out.println("Exception : In finally block ");
e.printStackTrace(); e.printStackTrace();
isError=true;
} }
} }
......
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