Commit c5962b71 authored by vkadam's avatar vkadam

Add validation for cheque no, station code blank, station code duplicate,...

Add validation for cheque no, station code blank, station code duplicate, voucher duplicate, and payment mode different for sundry type [F14FSUN003].


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@36840 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 0c388a83
/********************************************************
Title : MiscPaySubAct[F14FSUN003]
Date : 17/SEP/14
Developer: Sagar M.
********************************************************/
package ibase.webitm.ejb.fin.adv;
import ibase.webitm.utility.*;
import ibase.webitm.ejb.*;
import ibase.system.config.*;
import ibase.webitm.utility.ITMException;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.io.PrintStream;
import java.rmi.RemoteException;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import javax.ejb.Stateless;
@Stateless
public class MiscPaySubAct extends ActionHandlerEJB implements MiscPaySubActLocal, MiscPaySubActRemote
public class MiscPaySubAct extends ActionHandlerEJB
implements MiscPaySubActLocal, MiscPaySubActRemote
{
/**
* The public method is used for update the Workflow status
* @param tranId
* @param xtraParams contais additional information such as loginEmpCode,loginCode,chgTerm etc
* @param forcedFlag (true or false)
*/
String userId = "", termId = "";
String userId = ""; String termId = "";
GenericUtility genericUtility = GenericUtility.getInstance();
@Override
public String actionHandler(String tranId, String xtraParams, String forcedFlag) throws RemoteException, ITMException
public String actionHandler(String tranId, String xtraParams, String forcedFlag)
throws RemoteException, ITMException
{
System.out.println("---ActionHandler---@@@@@@@@xtraParams["+xtraParams+"]@@@@@@forcedFlag["+forcedFlag+"]");
System.out.println("---ActionHandler---@@@@@@@@xtraParams[" + xtraParams + "]@@@@@@forcedFlag[" + forcedFlag + "]");
Connection conn = null;
PreparedStatement pstmt = null,pstmt1 = null;
ResultSet rs = null,rs1 = null;
PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; PreparedStatement pstmt2 = null;
ResultSet rs = null; ResultSet rs1 = null; ResultSet rs2 = null;
String retString = "";
String sql = "",sql1 = "";
String confStatus="",wfStatus="";
/*String currAppdate ="";
String tranIdTest="",todayStr="";*/
java.sql.Timestamp datesubmit=null;
//added by vishakha on 03/Aug/2015 for validations on Submit button.
double totAmt = 0.0,totAmtMiscPay = 0.0,adjAmtMiscPay = 0.0,payAmt = 0.0;
// String ignorechklimit ="",tranKeyFld = "",bankCode = "",siteCode = "",payType = "";
String sql = ""; String sql1 = ""; String sql2 = "";
String confStatus = ""; String wfStatus = ""; String sundryType = ""; String sundryCode = ""; String payMode = ""; String supPayMod = ""; String bankCode = ""; String chqNo = "";
int cnt = 0; int cnt1 = 0;
Timestamp datesubmit = null;
double totAmt = 0.0D; double totAmtMiscPay = 0.0D; double adjAmtMiscPay = 0.0D; double payAmt = 0.0D;
ArrayList stnCdList = new ArrayList();
boolean stanCdBlank = false; boolean stanCdDupl = false; boolean stanCodeInv = false;
Timestamp tranDate = null;
String refNo = "",tranSer = "";
String refNo = ""; String tranSer = "";
FinCommon fin = new FinCommon();
try
{
......@@ -61,283 +54,379 @@ public class MiscPaySubAct extends ActionHandlerEJB implements MiscPaySubActLoca
connDriver = null;
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
termId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
if (userId == null || userId.trim().length() == 0)
this.userId = this.genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
this.termId = this.genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
if ((this.userId == null) || (this.userId.trim().length() == 0))
{
userId = "SYSTEM";
this.userId = "SYSTEM";
}
if (termId == null || termId.trim().length() == 0)
if ((this.termId == null) || (this.termId.trim().length() == 0))
{
termId = "SYSTEM";
this.termId = "SYSTEM";
}
System.out.println(">>>>>>>>>>tranId:"+tranId);
sql = "SELECT CONFIRMED,CASE WHEN WF_STATUS IS NULL THEN 'O' ELSE WF_STATUS END AS WF_STATUS FROM MISC_PAYMENT WHERE TRAN_ID= ? ";
System.out.println(">>>>>>>>>>tranId:" + tranId);
sql = "SELECT CONFIRMED,CASE WHEN WF_STATUS IS NULL THEN 'O' ELSE WF_STATUS END AS WF_STATUS,SUNDRY_CODE,SUNDRY_TYPE,PAY_MODE,BANK_CODE,REF_NO FROM MISC_PAYMENT WHERE TRAN_ID= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if ( rs.next() )
if (rs.next())
{
confStatus = rs.getString("CONFIRMED").trim();
wfStatus = rs.getString("WF_STATUS").trim();
sundryCode = checkNull(rs.getString("SUNDRY_CODE"));
sundryType = checkNull(rs.getString("SUNDRY_TYPE"));
payMode = checkNull(rs.getString("PAY_MODE"));
bankCode = checkNull(rs.getString("BANK_CODE"));
chqNo = checkNull(rs.getString("REF_NO"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if( "Y".equalsIgnoreCase(confStatus) )
String str1;
if ("Y".equalsIgnoreCase(confStatus))
{
retString = itmDBAccessLocal.getErrorString("","VTDIST26","");
return retString;
retString = itmDBAccessLocal.getErrorString("", "VTDIST26", "");
str1 = retString;
return str1;
}
if( "S".equalsIgnoreCase(wfStatus) )
if ("S".equalsIgnoreCase(wfStatus))
{
retString = itmDBAccessLocal.getErrorString("","ALRDYSUBMT","");
return retString;
retString = itmDBAccessLocal.getErrorString("", "ALRDYSUBMT", "");
str1 = retString;
return str1;
}
if( "N".equalsIgnoreCase(confStatus) && "O".equalsIgnoreCase(wfStatus))
if (("N".equalsIgnoreCase(confStatus)) && ("O".equalsIgnoreCase(wfStatus)))
{
//added by vishakha on 03/Aug/2015 as to incorporate the validations on submit button like those on commit button.
sql = "select sum(pay_amt) as totAmt from misc_paydet where tran_id = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if ( rs.next() )
if (rs.next())
{
totAmt = rs.getDouble("totAmt");//fetching totalAmount from details
totAmt = rs.getDouble("totAmt");
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(totAmt < 0.0)//total amount should not be negative
if (totAmt < 0.0D)
{
retString = itmDBAccessLocal.getErrorString("","VTAMTMIS1","");
return retString;
retString = itmDBAccessLocal.getErrorString("", "VTAMTMIS1", "");
str1 = retString;
return str1;
}
sql1 = "select TRAN_SER,vouch_no,pay_amt from misc_paydet where tran_id = ?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
rs1 = pstmt1.executeQuery();
while ( rs1.next() )
while (rs1.next())
{
tranSer = checkNull(rs1.getString("TRAN_SER"));
refNo = checkNull(rs1.getString("vouch_no"));
payAmt = rs1.getDouble("pay_amt");
sql = "SELECT tot_amt as tot_amt, adj_amt as adj_amt , sundry_type as sundrytype from misc_payables where tran_ser = ? and ref_no = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranSer);
pstmt.setString(2,refNo);
pstmt.setString(1, tranSer);
pstmt.setString(2, refNo);
rs = pstmt.executeQuery();
while ( rs.next() )
while (rs.next())
{
totAmtMiscPay = rs.getDouble("tot_amt");
adjAmtMiscPay = rs.getDouble("adj_amt");
System.out.println("totAmtMiscPay ========="+ totAmtMiscPay);
System.out.println("adjAmtMiscPay ========="+ adjAmtMiscPay);
System.out.println("Pay Amount ============ "+ payAmt);
if(Math.abs(totAmtMiscPay - adjAmtMiscPay) < Math.abs(payAmt))//if there is no balance in misc_payables
System.out.println("totAmtMiscPay =========" + totAmtMiscPay);
System.out.println("adjAmtMiscPay =========" + adjAmtMiscPay);
System.out.println("Pay Amount ============ " + payAmt);
if (Math.abs(totAmtMiscPay - adjAmtMiscPay) >= Math.abs(payAmt))
{
System.out.println("Entering the if condition Pay Amount ============ "+ payAmt);
retString = itmDBAccessLocal.getErrorString("","VTBAL1","");
return retString;
continue;
}
System.out.println("Entering the if condition Pay Amount ============ " + payAmt);
retString = itmDBAccessLocal.getErrorString("", "VTBAL1", "");
str1 = retString;
return str1;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
}
pstmt1.close();
pstmt1 = null;
rs1.close();
rs1 = null;
//SQL for update the work flow status/..........
sql = "UPDATE MISC_PAYMENT SET WF_STATUS='S',emp_code__submit=?,submit_date=? WHERE tran_id = ?";
System.out.println("@V@ Sundry Type :- [" + sundryType + "]");
System.out.println("@V@ Sundry Code :- [" + sundryCode + "]");
if ("S".equalsIgnoreCase(sundryType))
{
System.out.println("@V@ Pay Mode :- [" + payMode + "]");
sql = "select pay_mode from SUPPLIER where supp_code=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,userId);
datesubmit=new java.sql.Timestamp(System.currentTimeMillis());
pstmt.setTimestamp(2,datesubmit);
pstmt.setString(3,tranId);
int rowcnt = pstmt.executeUpdate();
pstmt.setString(1, sundryCode);
rs = pstmt.executeQuery();
if (rs.next())
{
supPayMod = checkNull(rs.getString("pay_mode"));
}
pstmt.close();
pstmt = null;
if(rowcnt > 0)
rs.close();
rs = null;
System.out.println("@V@ Supplier Pay Mode :- [" + supPayMod + "]");
if (("N".equalsIgnoreCase(supPayMod)) && (!supPayMod.equalsIgnoreCase(payMode)))
{
retString = itmDBAccessLocal.getErrorString("","SUBMITSUCC","");
System.out.println(">>>>>>>>>>>>>>>Before conn.commit()");
conn.commit();
//return retString;
System.out.println("@V@ Pay Mode not matching");
retString = itmDBAccessLocal.getErrorString("", "VTPYMDDIFF", "");
str1 = retString;
return str1;
}
}
sql = "select stan_code from misc_paydet where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
}
catch(Exception e)
rs = pstmt.executeQuery();
while (rs.next())
{
try
if ((rs.getString("stan_code") == null) || (checkNull(rs.getString("stan_code")).length() == 0))
{
conn.rollback();
stanCdBlank = true;
break;
}
catch (Exception e1)
System.out.println("@V@ Stan code not blank");
sql2 = "select count(*) a cnt from station where stan_code=?";
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, checkNull(rs.getString("stan_code")));
rs2 = pstmt2.executeQuery();
if (rs2.next())
{
cnt1 = rs2.getInt("cnt");
}
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
finally
pstmt2.close();
pstmt2 = null;
rs2.close();
rs2 = null;
if (cnt1 == 0)
{
try
stanCodeInv = true;
break;
}
if ("E".equalsIgnoreCase(sundryType))
continue;
System.out.println("@V@ Sundry type NOT 'E'");
if (stnCdList.size() > 0)
{
if(pstmt1 != null)
System.out.println("@V@ List size is NOT 0 :-[" + stnCdList.size() + "]");
if (!stnCdList.contains(rs.getString("stan_code")))
{
pstmt1.close();
pstmt1 = null;
System.out.println("@V@ Stan code match found");
stanCdDupl = true;
break;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
System.out.println("@V@ Stan code added in list");
stnCdList.add(rs.getString("stan_code"));
}
if( conn != null && ! conn.isClosed() )
else
{
conn.close();
conn = null;
System.out.println("@V@ First Stan code added in list");
stnCdList.add(rs.getString("stan_code"));
}
}
catch(Exception ef)
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (stanCdBlank)
{
System.out.println(ef.getMessage());
ef.printStackTrace();
throw new ITMException(ef);
System.out.println("@V@ Station code null found");
retString = itmDBAccessLocal.getErrorString("", "VTSTNCDBLK", "");
str1 = retString;
return str1;
}
if (stanCodeInv)
{
System.out.println("@V@ Station code invalid");
retString = itmDBAccessLocal.getErrorString("", "VTSTNCDINV", "");
str1 = retString;
return str1;
}
System.out.println("Returning Result ::"+retString);
return retString;
}
private String checkNull( String input )
if (!"E".equalsIgnoreCase(sundryType))
{
if ( input == null )
if (stanCdDupl)
{
input = "";
System.out.println("@V@ Station code Duplicate found");
retString = itmDBAccessLocal.getErrorString("", "VTSTNCDDPL", "");
str1 = retString;
return str1;
}
return input;
}
}
/********CODE COMMENTED as it only checks the balance for bank_type = 'B'*********/
/*public String getBalChk(String bankCode,String siteCode,Timestamp tranDate,double netAmt,Connection conn)throws Exception
{
System.out.println("@@@@@@getBalChk method@@@@@@@");
String errCode = "";
double bal = 0.0;
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "",bankType = "",acctprd = "";
sql = "select bank_type as ls_type from bank where bank_code = ? ";
sql = "select count(*) AS CNT from misc_payment a,misc_paydet b where a.tran_id=b.tran_id and wf_status='S'"
+ " AND CONFIRMED='N' and b.tran_id <> ? and b.VOUCH_NO in(select VOUCH_NO from misc_paydet where tran_id=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,bankCode);
pstmt.setString(1, tranId);
pstmt.setString(2, tranId);
rs = pstmt.executeQuery();
if ( rs.next() )
if (rs.next())
{
bankType = checkNull(rs.getString("ls_type"));
cnt = rs.getInt("CNT");
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
sql = "select code as ls_acctprd from acctprd where ? between fr_date and to_date ";
if (cnt > 0)
{
System.out.println("@V@ Voucher Duplicate found in 'misc_payment'");
retString = itmDBAccessLocal.getErrorString("", "VTVCHNODPL", "");
str1 = retString;
return str1;
}
sql = "SELECT COUNT(*) AS CNT FROM BANKTRAN_LOG WHERE BANK_CODE=? AND TRAN_TYPE='P' AND TRAN_SER <> 'R-DIS' AND REF_NO=?";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDate);
pstmt.setString(1, bankCode);
pstmt.setString(2, chqNo);
rs = pstmt.executeQuery();
if ( rs.next() )
if (rs.next())
{
acctprd = rs.getString("ls_acctprd");
cnt = rs.getInt("CNT");
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(bankType == "C")
{
sql = "select sum(dr_amt - cr_amt) as lc_bal from sundrybal where acct_prd = ? and prd_code = 'zzzzzz' and site_code = ? and sundry_type = 'B' and sundry_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,acctprd);
pstmt.setString(2,siteCode);
pstmt.setString(3,bankCode);
rs = pstmt.executeQuery();
if ( rs.next() )
if (cnt > 0)
{
bal = rs.getDouble("lc_bal");
System.out.println("@V@ Duplicate cheque found");
retString = itmDBAccessLocal.getErrorString("", "VTCHQ3", "");
str1 = retString;
return str1;
}
sql = "UPDATE MISC_PAYMENT SET WF_STATUS='S',emp_code__submit=?,submit_date=? WHERE tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, this.userId);
datesubmit = new Timestamp(System.currentTimeMillis());
pstmt.setTimestamp(2, datesubmit);
pstmt.setString(3, tranId);
int rowcnt = pstmt.executeUpdate();
pstmt.close();
pstmt = null;
rs.close();
rs = null;
System.out.println("Value of sum(dr_amt - cr_amt)"+bal);
System.out.println("Value of net amount ==========="+netAmt);
if(netAmt > 0.0 && netAmt > bal )
if (rowcnt > 0)
{
errCode = itmDBAccessLocal.getErrorString("","VTPAYAMT","");
return errCode;
retString = itmDBAccessLocal.getErrorString("", "SUBMITSUCC", "");
System.out.println(">>>>>>>>>>>>>>>Before conn.commit()");
conn.commit();
}
}
return errCode;
}
sql = "select tran_id as ls_keyfld, bank_code as ls_bank, net_amt as lc_net, site_code as ls_site, tran_date as ld_tran_date,ref_no , pay_type as ls_pay_type from misc_payment where tran_id = ? for update nowait";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if ( rs.next() )
catch (Exception e)
{
try
{
conn.rollback();
}
catch (Exception localException1) {
}
e.printStackTrace();
System.out.println("Exception ::" + e.getMessage());
throw new ITMException(e);
}
finally
{
try {
if (pstmt1 != null)
{
tranKeyFld = checkNull(rs.getString("ls_keyfld"));
bankCode = checkNull(rs.getString("ls_bank"));
netAmt = rs.getDouble("lc_net");
tranDate = rs.getTimestamp("ld_tran_date");
siteCode = checkNull(rs.getString("ls_site"));
payType = checkNull(rs.getString("ls_pay_type"));
refNo = checkNull(rs.getString("ref_no"));
pstmt1.close();
pstmt1 = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
rs.close();
rs = null;
ignorechklimit = fin.getFinparams("999999","IGNORE_WARNINGS",conn);
System.out.println("Value of Ignore chk limit ===="+ignorechklimit);
if("NULLFOUND".equals(ignorechklimit ) || ignorechklimit == null)
}
if ((conn != null) && (!conn.isClosed()))
{
ignorechklimit = "N";
System.out.println("Value of Ignore chk limit ===="+ignorechklimit);
conn.close();
conn = null;
}
}
if("N".equalsIgnoreCase(ignorechklimit))
catch (Exception ef) {
System.out.println(ef.getMessage());
ef.printStackTrace();
throw new ITMException(ef);
}
}
try
{
if (pstmt1 != null)
{
System.out.println("Insiding****BalChk condition");
retString = getBalChk(bankCode,siteCode,tranDate,netAmt,conn);
if(retString.trim().length() > 0)
pstmt1.close();
pstmt1 = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if ((conn != null) && (!conn.isClosed()))
{
conn.close();
conn = null;
}
}
catch (Exception ef) {
System.out.println(ef.getMessage());
ef.printStackTrace();
throw new ITMException(ef);
}
System.out.println("Returning Result ::" + retString);
return retString;
}
}*/
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
return input;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment