Commit 1c44492e 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@98609 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 35ed6823
/********************************************************
Title : MiscPaySubAct[F14FSUN003]
Date : 17/SEP/14
Developer: Sagar M.
********************************************************/
package ibase.webitm.ejb.fin.adv; package ibase.webitm.ejb.fin.adv;
import ibase.webitm.utility.*; import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.*; import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.system.config.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ITMDBAccessEJB; import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.fin.FinCommon; 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.rmi.RemoteException;
import java.sql.*; import java.sql.Connection;
import java.text.SimpleDateFormat; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import javax.ejb.Stateless; import javax.ejb.Stateless;
@Stateless @Stateless
public class MiscPaySubAct extends ActionHandlerEJB
public class MiscPaySubAct extends ActionHandlerEJB implements MiscPaySubActLocal, MiscPaySubActRemote implements MiscPaySubActLocal, MiscPaySubActRemote
{ {
/** String userId = ""; String termId = "";
* 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 = "";
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
@Override public String actionHandler(String tranId, String xtraParams, String forcedFlag)
public String actionHandler(String tranId, String xtraParams, String forcedFlag) throws RemoteException, ITMException throws RemoteException, ITMException
{ {
System.out.println("---ActionHandler---@@@@@@@@xtraParams["+xtraParams+"]@@@@@@forcedFlag["+forcedFlag+"]"); System.out.println("---ActionHandler---@@@@@@@@xtraParams[" + xtraParams + "]@@@@@@forcedFlag[" + forcedFlag + "]");
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null,pstmt1 = null; PreparedStatement pstmt = null; PreparedStatement pstmt1 = null; PreparedStatement pstmt2 = null;
ResultSet rs = null,rs1 = null; ResultSet rs = null; ResultSet rs1 = null; ResultSet rs2 = null;
String retString = ""; String retString = "";
String sql = "",sql1 = ""; String sql = ""; String sql1 = ""; String sql2 = "";
String confStatus="",wfStatus=""; String confStatus = ""; String wfStatus = ""; String sundryType = ""; String sundryCode = ""; String payMode = ""; String supPayMod = ""; String bankCode = ""; String chqNo = "";
/*String currAppdate =""; int cnt = 0; int cnt1 = 0;
String tranIdTest="",todayStr="";*/
java.sql.Timestamp datesubmit=null; 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; double totAmt = 0.0D; double totAmtMiscPay = 0.0D; double adjAmtMiscPay = 0.0D; double payAmt = 0.0D;
// String ignorechklimit ="",tranKeyFld = "",bankCode = "",siteCode = "",payType = ""; ArrayList stnCdList = new ArrayList();
boolean stanCdBlank = false; boolean stanCdDupl = false; boolean stanCodeInv = false;
Timestamp tranDate = null; Timestamp tranDate = null;
String refNo = "",tranSer = ""; String refNo = ""; String tranSer = "";
FinCommon fin = new FinCommon(); FinCommon fin = new FinCommon();
try try
{ {
...@@ -61,283 +54,379 @@ public class MiscPaySubAct extends ActionHandlerEJB implements MiscPaySubActLoca ...@@ -61,283 +54,379 @@ public class MiscPaySubAct extends ActionHandlerEJB implements MiscPaySubActLoca
connDriver = null; connDriver = null;
ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB(); ITMDBAccessEJB itmDBAccessLocal = new ITMDBAccessEJB();
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"); this.userId = this.genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
termId = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"); this.termId = this.genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId");
if (userId == null || userId.trim().length() == 0) 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); 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= ? "; 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 = conn.prepareStatement(sql);
pstmt.setString(1, tranId); pstmt.setString(1, tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if ( rs.next() ) if (rs.next())
{ {
confStatus = rs.getString("CONFIRMED").trim(); confStatus = rs.getString("CONFIRMED").trim();
wfStatus = rs.getString("WF_STATUS").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.close();
pstmt = null; pstmt = null;
rs.close(); rs.close();
rs = null; rs = null;
String str1;
if( "Y".equalsIgnoreCase(confStatus) ) if ("Y".equalsIgnoreCase(confStatus))
{ {
retString = itmDBAccessLocal.getErrorString("","VTDIST26",""); retString = itmDBAccessLocal.getErrorString("", "VTDIST26", "");
return retString; str1 = retString;
return str1;
} }
if( "S".equalsIgnoreCase(wfStatus) ) if ("S".equalsIgnoreCase(wfStatus))
{ {
retString = itmDBAccessLocal.getErrorString("","ALRDYSUBMT",""); retString = itmDBAccessLocal.getErrorString("", "ALRDYSUBMT", "");
return retString; 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 = ? "; sql = "select sum(pay_amt) as totAmt from misc_paydet where tran_id = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId); pstmt.setString(1, tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if ( rs.next() ) if (rs.next())
{ {
totAmt = rs.getDouble("totAmt");//fetching totalAmount from details totAmt = rs.getDouble("totAmt");
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
rs.close(); rs.close();
rs = null; rs = null;
if(totAmt < 0.0)//total amount should not be negative if (totAmt < 0.0D)
{ {
retString = itmDBAccessLocal.getErrorString("","VTAMTMIS1",""); retString = itmDBAccessLocal.getErrorString("", "VTAMTMIS1", "");
return retString; str1 = retString;
return str1;
} }
sql1 = "select TRAN_SER,vouch_no,pay_amt from misc_paydet where tran_id = ?"; sql1 = "select TRAN_SER,vouch_no,pay_amt from misc_paydet where tran_id = ?";
pstmt1 = conn.prepareStatement(sql1); pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId); pstmt1.setString(1, tranId);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
while ( rs1.next() ) while (rs1.next())
{ {
tranSer = checkNull(rs1.getString("TRAN_SER")); tranSer = checkNull(rs1.getString("TRAN_SER"));
refNo = checkNull(rs1.getString("vouch_no")); refNo = checkNull(rs1.getString("vouch_no"));
payAmt = rs1.getDouble("pay_amt"); 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 = ? "; 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 = conn.prepareStatement(sql);
pstmt.setString(1,tranSer); pstmt.setString(1, tranSer);
pstmt.setString(2,refNo); pstmt.setString(2, refNo);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while ( rs.next() ) while (rs.next())
{ {
totAmtMiscPay = rs.getDouble("tot_amt"); totAmtMiscPay = rs.getDouble("tot_amt");
adjAmtMiscPay = rs.getDouble("adj_amt"); adjAmtMiscPay = rs.getDouble("adj_amt");
System.out.println("totAmtMiscPay ========="+ totAmtMiscPay); System.out.println("totAmtMiscPay =========" + totAmtMiscPay);
System.out.println("adjAmtMiscPay ========="+ adjAmtMiscPay); System.out.println("adjAmtMiscPay =========" + adjAmtMiscPay);
System.out.println("Pay Amount ============ "+ payAmt); System.out.println("Pay Amount ============ " + payAmt);
if(Math.abs(totAmtMiscPay - adjAmtMiscPay) < Math.abs(payAmt))//if there is no balance in misc_payables if (Math.abs(totAmtMiscPay - adjAmtMiscPay) >= Math.abs(payAmt))
{ {
System.out.println("Entering the if condition Pay Amount ============ "+ payAmt); continue;
retString = itmDBAccessLocal.getErrorString("","VTBAL1","");
return retString;
} }
System.out.println("Entering the if condition Pay Amount ============ " + payAmt);
retString = itmDBAccessLocal.getErrorString("", "VTBAL1", "");
str1 = retString;
return str1;
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
rs.close(); rs.close();
rs = null; rs = null;
} }
pstmt1.close(); pstmt1.close();
pstmt1 = null; pstmt1 = null;
rs1.close(); rs1.close();
rs1 = null; 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 = conn.prepareStatement(sql);
pstmt.setString(1,userId); pstmt.setString(1, sundryCode);
datesubmit=new java.sql.Timestamp(System.currentTimeMillis());
pstmt.setTimestamp(2,datesubmit); rs = pstmt.executeQuery();
pstmt.setString(3,tranId); if (rs.next())
int rowcnt = pstmt.executeUpdate(); {
supPayMod = checkNull(rs.getString("pay_mode"));
}
pstmt.close(); pstmt.close();
pstmt = null; 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("@V@ Pay Mode not matching");
System.out.println(">>>>>>>>>>>>>>>Before conn.commit()"); retString = itmDBAccessLocal.getErrorString("", "VTPYMDDIFF", "");
conn.commit(); str1 = retString;
//return retString; return str1;
} }
} }
sql = "select stan_code from misc_paydet where tran_id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
} while (rs.next())
catch(Exception e)
{ {
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(); pstmt2.close();
System.out.println("Exception ::"+e.getMessage()); pstmt2 = null;
throw new ITMException(e); rs2.close();
} rs2 = null;
finally
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(); System.out.println("@V@ Stan code match found");
pstmt1 = null; stanCdDupl = true;
break;
} }
if(pstmt != null)
{ System.out.println("@V@ Stan code added in list");
pstmt.close(); stnCdList.add(rs.getString("stan_code"));
pstmt = null;
} }
if( conn != null && ! conn.isClosed() ) else
{ {
conn.close(); System.out.println("@V@ First Stan code added in list");
conn = null; stnCdList.add(rs.getString("stan_code"));
} }
} }
catch(Exception ef)
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (stanCdBlank)
{ {
System.out.println(ef.getMessage()); System.out.println("@V@ Station code null found");
ef.printStackTrace(); retString = itmDBAccessLocal.getErrorString("", "VTSTNCDBLK", "");
throw new ITMException(ef); 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); if (!"E".equalsIgnoreCase(sundryType))
return retString;
}
private String checkNull( String input )
{ {
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'*********/ sql = "select count(*) AS CNT from misc_payment a,misc_paydet b where a.tran_id=b.tran_id and wf_status='S'"
/*public String getBalChk(String bankCode,String siteCode,Timestamp tranDate,double netAmt,Connection conn)throws Exception + " AND CONFIRMED='N' and b.tran_id <> ? and b.VOUCH_NO in(select VOUCH_NO from misc_paydet where tran_id=?)";
{
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 = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,bankCode); pstmt.setString(1, tranId);
pstmt.setString(2, tranId);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if ( rs.next() ) if (rs.next())
{ {
bankType = checkNull(rs.getString("ls_type")); cnt = rs.getInt("CNT");
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
rs.close(); rs.close();
rs = null; 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 = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDate); pstmt.setString(1, bankCode);
pstmt.setString(2, chqNo);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if ( rs.next() ) if (rs.next())
{ {
acctprd = rs.getString("ls_acctprd"); cnt = rs.getInt("CNT");
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
rs.close(); rs.close();
rs = null; rs = null;
if(bankType == "C")
{ if (cnt > 0)
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() )
{ {
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.close();
pstmt = null; pstmt = null;
rs.close(); if (rowcnt > 0)
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 )
{ {
errCode = itmDBAccessLocal.getErrorString("","VTPAYAMT",""); retString = itmDBAccessLocal.getErrorString("", "SUBMITSUCC", "");
return errCode; System.out.println(">>>>>>>>>>>>>>>Before conn.commit()");
conn.commit();
} }
} }
return errCode;
} }
catch (Exception e)
{
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"; try
pstmt = conn.prepareStatement(sql); {
pstmt.setString(1, tranId); conn.rollback();
rs = pstmt.executeQuery(); }
if ( rs.next() ) 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")); pstmt1.close();
bankCode = checkNull(rs.getString("ls_bank")); pstmt1 = null;
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"));
} }
if (pstmt != null)
{
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
rs.close(); }
rs = null; if ((conn != null) && (!conn.isClosed()))
ignorechklimit = fin.getFinparams("999999","IGNORE_WARNINGS",conn);
System.out.println("Value of Ignore chk limit ===="+ignorechklimit);
if("NULLFOUND".equals(ignorechklimit ) || ignorechklimit == null)
{ {
ignorechklimit = "N"; conn.close();
System.out.println("Value of Ignore chk limit ===="+ignorechklimit); 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"); pstmt1.close();
retString = getBalChk(bankCode,siteCode,tranDate,netAmt,conn); pstmt1 = null;
if(retString.trim().length() > 0) }
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; 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