Commit 6b5dd4ee authored by pshinde's avatar pshinde

Source code of Automatic Payment Scheduler


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@97841 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 30dcd2cd
......@@ -11,7 +11,6 @@ import java.util.*;
import java.util.Date;
import java.sql.*;
import java.text.*;
import java.text.SimpleDateFormat;
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
......@@ -25,6 +24,7 @@ import javax.naming.InitialContext;
//import ibase.webitm.ejb.MasterStatefulHome;// commented for ejb3
import ibase.webitm.ejb.MasterStatefulLocal;//added for ejb3
import ibase.webitm.ejb.MasterStatefulEJB;//addes for ejb3
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import java.io.File;
......@@ -46,6 +46,8 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
// Connection conn = null;
ResultSet rs1 = null;
PreparedStatement pstmt1 = null;
ResultSet rs2 = null;
PreparedStatement pstmt2 = null;
String Sql1="";
java.sql.Timestamp dateTo = null;
java.sql.Timestamp dateFr = null;
......@@ -100,6 +102,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
detailDom = genericUtility.parseString(xmlString2);
}
rtrStr = getData(headerDom, detailDom, windowName, xtraParams);
//System.out.println("rtrStr================"+rtrStr);
}
catch (Exception e)
{
......@@ -126,6 +129,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
String entryBatchNo = null;
String chqSplit = null;
String bankAdd = null;
String dueDate="";
String errCode = "";
String resultString = "";
String getSql= null ;
......@@ -290,7 +294,9 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
refNo = rs.getString("ref_no");
payAmt = rs.getDouble("pay_amt");
netPayable = rs.getDouble("net_payable");
tempSql= "SELECT sum(case when auto_pay_det.pay_amt is null then 0 else auto_pay_det.pay_amt end) as pay_amt "
dueDate = rs.getString("due_date");
/*tempSql= "SELECT sum(case when auto_pay_det.pay_amt is null then 0 else auto_pay_det.pay_amt end) as pay_amt "
+"FROM auto_pay_hdr, auto_pay_det "
+"WHERE ( auto_pay_det.tran_ser = '" + tranSer + "') AND "
+"( auto_pay_det.ref_no = '" + refNo + "' ) AND "
......@@ -319,9 +325,11 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
{
unapprovedPayAmt = netPayable;
}
}
//payAmt = netPayable - unapprovedPayAmt;
}*/
payAmt = netPayable - unapprovedPayAmt;
payAmt = netPayable;
//Add ended by Raj (FI78DIS032)- 29/12/2007
......@@ -467,11 +475,11 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
ResultSet rs = null;
PreparedStatement pstmt = null;
String refNo = "";
String miscPayablesTranDate = "";
// String miscPayablesTranDate = "";
String chgDate = "";
String sDate= "";
String refDate = "";
String fromDate = "";
// String fromDate = "";
String billNo = "";
String billDate = "";
String currCode = "";
......@@ -487,6 +495,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
String bankCode = "";
String bankCodeAdd = "";
String payMode = "";
String drawnAt="";
String advAmt = "";
String tranId = "";
String tranSer = "";
......@@ -504,11 +513,16 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
String chgUser = "";
String xmlOutString = "";
String payDate = "";
String wfStatus="";
String stanCode="";
String tranDate="";
double diffAmt=0;
String retString = "";
String lastChq = ""; //Added by Jaimin 06/08/2007
String uptoChq = "";//Added by Jaimin 06/08/2007
String errString = "";
StringBuffer retBuf;
String tranDt="";
//StringBuffer refNoBuff = null, tranSerBuff = null, payAmtBuff = null, netPayableBuff = null;//Added by jaimin 17/08/02007
StringBuffer errStringBuff = null;//Added by jaimin 17/08/02007
boolean validEntry = true;
......@@ -522,7 +536,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
Statement statement = null;
ResultSet resultSet = null;
String sql = "";
String siteDescr = "",finentDescr = "",bankName = "";
String siteDescr = "",finentDescr = "",bankName = "",chgFrm="",chgTo="";
//End Jaimin 25/07/2007
NodeList parentNodeList = null;
NodeList childNodeList = null;
......@@ -531,12 +545,27 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
int updCnt = 0;
int parentNodeListLength = 0;
int childNodeListLength = 0;
String acctCodeBal="",cctrCodeBal="",acctCodeBc="",cctrCodeBc="",acctCodeCf="",acctCodeCfAp="",cctrCodeCf="",cctrCodeCfAp="";
String currCodeBc="",porder="",sfld1="",acctCodeDisc="",cctrCodeDisc="",startFrom="";
double excRateBc=0,discount=0,mexrate=0,disAmt=0,payAmt1=0;
Date effDate=null,billDt=null,ldStartDate=null,reDate1=null;
Date ldStartDate1=null,payDate1=null,mPayDate=null;
String transactionDate="";//added by priyanka
long datediff=0;
FinCommon fin=new FinCommon();
DistCommon dist=new DistCommon();
try
{
retBuf = new StringBuffer();
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
System.out.println("AutoPmtGenPrcEJB ejbCreate called.........");
Date currentDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
//writeLog(filePtr,"AutoPmtGenPrcEJB ejbCreate called.........",true);
//For logonoff
sql = "select var_value from finparm where prd_code='999999' and var_name='AUTOPAYGEN_LOG_FLAG'";
......@@ -582,6 +611,29 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
lastChq = genericUtility.getColumnValue("ref_no",headerDom);
//writeLog(filePtr,"lastChq-->"+lastChq,true);
uptoChq = genericUtility.getColumnValue("ref_no__upto",headerDom);
System.out.println("chgDate========"+chgDate);
payMode = genericUtility.getColumnValue("pay_mode",headerDom);
System.out.println("Getting pay Mode================"+payMode);
sundryCode = genericUtility.getColumnValue("sundry_code",headerDom);
System.out.println("Getting sundry_code================"+sundryCode);
sundryType = genericUtility.getColumnValue("sundry_type",headerDom);
System.out.println("Getting sundryType================"+sundryType);
refNo = genericUtility.getColumnValue("ref_no",headerDom);
System.out.println("Getting ref_no================"+refNo);
dueDate = genericUtility.getColumnValue("due_date",headerDom);
System.out.println("Getting dueDate=============="+dueDate);
wfStatus = genericUtility.getColumnValue("wf_status",headerDom);
System.out.println("Getting wfStatus=============="+wfStatus);
/* acctCode = genericUtility.getColumnValue("acct_code",headerDom);
System.out.println("Getting acct_code__bal================"+acctCode);*/
//writeLog(filePtr,"uptoChq-->"+uptoChq,true);
//chgDate = java.sql.Timestamp.valueOf(sDate + " 00:00:00");
//Added by Jaimin 25/07/2007
......@@ -619,25 +671,93 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
pstmt = null;
if ( bankCode != null )
{
sql = "SELECT BANK_NAME FROM BANK WHERE BANK_CODE ='" + bankCode +"'";
sql = "SELECT BANK_NAME,chq1,chq3 FROM BANK WHERE BANK_CODE ='" + bankCode +"'";
//writeLog(filePtr,"sql-->"+sql,true);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
bankName= rs.getString(1);
bankName= checkNull(rs.getString(1));
//chgFrm= checkNull(rs.getString(2));
//chgTo= checkNull(rs.getString(3));
}
//writeLog(filePtr,"bankName-->"+bankName,true);
}
rs.close();
pstmt.close();
pstmt = null;
System.out.println("Bank Code====="+bankCode);
sql="select acct_code__bal, cctr_code__bal, acct_code__bc, cctr_code__bc," +
" acct_code__cf, acct_code__cf_ap, cctr_code__cf, cctr_code__cf_ap " +
"from bank where bank_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,bankCode);
rs = pstmt.executeQuery();
if(rs.next())
{
acctCodeBal=checkNull(rs.getString("acct_code__bal"));
cctrCodeBal=checkNull(rs.getString("cctr_code__bal"));
acctCodeBc=checkNull(rs.getString("acct_code__bc"));
cctrCodeBc=checkNull(rs.getString("cctr_code__bc"));
acctCodeCf=checkNull(rs.getString("acct_code__cf"));
acctCodeCfAp=checkNull(rs.getString("acct_code__cf_ap"));
cctrCodeCf=checkNull(rs.getString("cctr_code__cf"));
cctrCodeCfAp=checkNull(rs.getString("acct_code__cf_ap"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Site Code>>>>>>>>>>"+siteCode);
sql="select curr_code from site, finent " +
"where site.fin_entity = finent.fin_entity and site_code =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
currCodeBc=checkNull(rs.getString("curr_code"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("currCodeBc=========="+currCodeBc);
sql="select std_exrt from currency where curr_code =? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,currCodeBc);
rs = pstmt.executeQuery();
if(rs.next())
{
excRateBc=rs.getDouble("std_exrt");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("excRateBc=========="+excRateBc);
mexrate=fin.getDailyExchRateSellBuy(currCode, "", siteCode, payDate, "B", conn);//through itemchange
System.out.println("ExcRate from getDailyExchRateSellBuy========="+mexrate);
//End by Jaimin 25/07/2007
xmlString = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlString.append("<DocumentRoot><description>Datawindow Root</description><group0><description>Group0 escription</description>");
xmlString.append("<Header0>");
xmlString.append("<description>Header0 members</description>");
xmlString.append("<objName><![CDATA[").append("auto_pay").append("]]></objName>");//"auto_pay" Added by Jaimin 25/07/2007
xmlString.append("<objName><![CDATA[").append("misc_pay").append("]]></objName>");//"auto_pay" Added by Jaimin 25/07/2007
xmlString.append("<pageContext><![CDATA[").append("1").append("]]></pageContext>");
xmlString.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
xmlString.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
......@@ -649,19 +769,42 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
xmlString.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
xmlString.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
xmlString.append("<taxInFocus><![CDATA[").append(false).append("]]></taxInFocus>");
xmlString.append("<Detail1 dbID='' domID=\"1\" objName=\"auto_pay\" objContext=\"1\">");//"auto_pay" Added by Jaimin 25/07/2007
xmlString.append("<Detail1 dbID='' domID=\"1\" objName=\"misc_pay\" objContext=\"1\">");//"auto_pay" Added by Jaimin 25/07/2007
xmlString.append("<attribute pkNames=\"tran_id:\" status=\"N\" updateFlag=\"A\" selected=\"N\" />");
xmlString.append("<tran_id><![CDATA[]]></tran_id>");
xmlString.append("<tran_date><![CDATA[" + payDate + "]]></tran_date>");
xmlString.append("<tran_type><![CDATA[" + tranType + "]]></tran_type>");
xmlString.append("<sundry_type><![CDATA[" + sundryType + "]]></sundry_type>");
xmlString.append("<sundry_code><![CDATA[" + sundryCode + "]]></sundry_code>");
xmlString.append("<pay_mode><![CDATA[" + payMode + "]]></pay_mode>");
xmlString.append("<bank_code><![CDATA[" + bankCode + "]]></bank_code>");
xmlString.append("<ref_no><![CDATA[" + refNo + "]]></ref_no>");
xmlString.append("<ref_date>").append("<![CDATA[").append(sdf.format(currentDate).toString()).append("]]></ref_date>\r\n");
//xmlString.append("<ref_date><![CDATA[" + dueDate + "]]></ref_date>");
xmlString.append("<remarks><![CDATA[" + "Generate Automatic payment from scheduler" + "]]></remarks>");
xmlString.append("<net_amt><![CDATA[" + 0 + "]]></net_amt>");
xmlString.append("<curr_code><![CDATA[" + currCode + "]]></curr_code>");
xmlString.append("<exch_rate><![CDATA[" + mexrate + "]]></exch_rate>");
xmlString.append("<net_amt__bc><![CDATA[" + 0 + "]]></net_amt__bc>");
xmlString.append("<site_code><![CDATA[" + siteCode + "]]></site_code>");
xmlString.append("<site_descr><![CDATA[" + siteDescr + "]]></site_descr>");//Added by Jaimin 25/07/2007
xmlString.append("<fin_entity><![CDATA[" + finEntity + "]]></fin_entity>");
xmlString.append("<finent_descr><![CDATA[" + finentDescr + "]]></finent_descr>");//Added by Jaimin 25/07/2007
xmlString.append("<bank_code><![CDATA[" + bankCode + "]]></bank_code>");
xmlString.append("<acct_code__bal><![CDATA[" + acctCodeBal + "]]></acct_code__bal>");
xmlString.append("<cctr_code__bal><![CDATA[" + cctrCodeBal + "]]></cctr_code__bal>");
xmlString.append("<auto_paid><![CDATA[" + "Y" + "]]></auto_paid>");
xmlString.append("<bank_charges><![CDATA[" + 0 + "]]></bank_charges>");
xmlString.append("<acct_code__bc><![CDATA[" + acctCodeBc + "]]></acct_code__bc>");
xmlString.append("<cctr_code__bc><![CDATA[" + cctrCodeBc + "]]></cctr_code__bc>");
xmlString.append("<curr_code__bc><![CDATA[" + currCodeBc + "]]></curr_code__bc>");
xmlString.append("<exch_rate__bc><![CDATA[" + excRateBc + "]]></exch_rate__bc>");
xmlString.append("<acct_code__cf><![CDATA[" + acctCodeCf + "]]></acct_code__cf>");
xmlString.append("<cctr_code__cf><![CDATA[" + cctrCodeCf + "]]></cctr_code__cf>");
xmlString.append("<tax_amt><![CDATA[" + 0 + "]]></tax_amt>");
xmlString.append("<tax_date><![CDATA[" + payDate + "]]></tax_date>");
xmlString.append("<WF_STATUS ><![CDATA[" + wfStatus + "]]></WF_STATUS >");
xmlString.append("<bank_name><![CDATA[" + bankName + "]]></bank_name>");//Added by Jaimin 25/07/2007
xmlString.append("<exch_rate><![CDATA[" + exchRate + "]]></exch_rate>");
xmlString.append("<curr_code><![CDATA[" + currCode + "]]></curr_code>");
if (bankCodeAdd==null)
{bankCodeAdd = "";}
xmlString.append("<bank_code__add><![CDATA[" + bankCodeAdd + "]]></bank_code__add>");
......@@ -671,9 +814,12 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
xmlString.append("<chg_user><![CDATA[" + chgUser + "]]></chg_user>");
xmlString.append("<chg_term><![CDATA[" + chgTerm + "]]></chg_term>");
xmlString.append("<chg_date><![CDATA[" + chgDate + "]]></chg_date>");
xmlString.append("<chq_no__fr><![CDATA[" + lastChq + "]]></chq_no__fr>");
xmlString.append("<chq_no__to><![CDATA[" + uptoChq + "]]></chq_no__to>");
//xmlString.append("<chq_no__fr><![CDATA[" + chgFrm + "]]></chq_no__fr>");
//xmlString.append("<chq_no__to><![CDATA[" + chgTo + "]]></chq_no__to>");
xmlString.append("</Detail1>");
System.out.println("XmlString Header======"+xmlString.toString());
parentNodeList = detailDom.getElementsByTagName("Detail2");
parentNodeListLength = parentNodeList.getLength();
System.out.println("parentNodeListLength:::::::::"+parentNodeListLength);
......@@ -696,6 +842,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
refNo = childNode.getFirstChild().getNodeValue();
}
}
if (childNodeName.equals("ref_date"))
{
if(childNode.getFirstChild()!=null)
......@@ -770,12 +917,15 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
if(childNode.getFirstChild()!=null)
{
String tmpDate = childNode.getFirstChild().getNodeValue();
System.out.println("before tmpDate==========="+tmpDate);
if (tmpDate.length()>10)
{
tmpDate = tmpDate.substring(0,9);
}
System.out.println("after tmpDate==========="+tmpDate);
//dueDate = childNode.getFirstChild().getNodeValue();
dueDate = genericUtility.getValidDateString(tmpDate,genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
System.out.println(" dueDate==========="+dueDate);
}
}
if (childNodeName.equals("tot_amt"))
......@@ -862,8 +1012,164 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
netPayable = childNode.getFirstChild().getNodeValue();
}
}
if (childNodeName.equals("tran_date"))
{
if(childNode.getFirstChild()!=null)
{
tranDate = childNode.getFirstChild().getNodeValue();
}
transactionDate = genericUtility.getValidDateString(tranDate,genericUtility.getDBDateFormat(),genericUtility.getApplDateFormat());
}
} // For inner loop
//if (Double.parseDouble(netPayable) != 0 ) // Condition added by jaimin 16/08/2007 // Remarked by Raj - 29/12/2007
//added on 30/mar by priyanka
System.out.println("Getting RefNo Detail================="+refNo);
System.out.println("Getting tranDate================"+tranDate);
System.out.println(" transactionDate==========="+transactionDate);
sql="select purc_order,eff_date,bill_date from voucher where tran_id = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,refNo);
rs = pstmt.executeQuery();
if(rs.next())
{
porder=checkNull(rs.getString("purc_order"));
effDate=rs.getDate("eff_date");
billDt=rs.getDate("bill_date");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Purchase order========="+porder);
System.out.println("effDate========="+effDate);
System.out.println("billDt========="+billDt);
sql="select cr_term from porder where purc_order =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,porder);
rs = pstmt.executeQuery();
if(rs.next())
{
sfld1=rs.getString("cr_term");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("sfld1========="+sfld1);
sql="select crtermfc.fin_chg,crterm.acct_code__disc,crterm.cctr_code__disc,crterm.start_from from crterm,crtermfc " +
"where crtermfc.cr_term = crterm.cr_term and crterm.cr_term = ? and trim(crtermfc.line_no) = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,sfld1);
rs = pstmt.executeQuery();
if(rs.next())
{
discount=rs.getDouble("fin_chg");
acctCodeDisc=checkNull(rs.getString("acct_code__disc"));
cctrCodeDisc=checkNull(rs.getString("cctr_code__disc"));
startFrom=checkNull(rs.getString("start_from"));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("discount========="+discount);
System.out.println("acctCodeDisc========="+acctCodeDisc);
System.out.println("cctrCodeDisc========="+cctrCodeDisc);
System.out.println("startFrom========="+startFrom);
reDate1 = sdf.parse(refDate);
Date discdt=getDiscountdate(sfld1, reDate1, effDate, billDt, conn);
System.out.println("Getting discdt======"+discdt);
if(discdt!=null)
{
System.out.println("Getting discdt not null==");
String discdt1=sdf.format(discdt);
System.out.println("Getting discdt================"+discdt1);
mPayDate=sdf.parse(transactionDate);
System.out.println("mPayDate============"+mPayDate);
long diff = discdt.getTime() - mPayDate.getTime();
datediff = diff / (24 * 60 * 60 * 1000);
System.out.println("CurrDtae======================="+datediff);
}
sql="select fin_chg from crtermfc where ? between min_day and max_day and cr_term = ? and trim(line_no) = '1'";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1,datediff);
pstmt.setString(2,sfld1);
rs = pstmt.executeQuery();
if(rs.next())
{
discount=rs.getDouble("fin_chg");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("Get Discount======="+discount);
if(discount==0)
{
discount=0;
}
System.out.println(">>>>>>>>startFrom==="+startFrom);
if((startFrom!=null && startFrom.trim().length()>0) && "R".equalsIgnoreCase(startFrom))
{
ldStartDate=reDate1;
}
else if((startFrom!=null && startFrom.trim().length()>0) && "D".equalsIgnoreCase(startFrom) && "Q".equalsIgnoreCase(startFrom))
{
ldStartDate=effDate;
}
else if((startFrom!=null && startFrom.trim().length()>0) && "B".equalsIgnoreCase(startFrom) )
{
ldStartDate=billDt;
}
if((payDate!=null && payDate.trim().length()>0) && ldStartDate!=null)
{
payDate1 = sdf.parse(payDate);
if((payDate1.compareTo(ldStartDate)>0)&& payDate1.compareTo(discdt)<0)
{
if(discount!=0)
{System.out.println("Discount not equals to Zerooooooooooooo");
payAmt1=Double.parseDouble(payAmt);
disAmt= payAmt1 *(discount/100);
}
}
}
System.out.println("disAmount=========="+disAmt);
System.out.println("PayMAode======="+payMode);
System.out.println("BankCode>>>>>==="+bankCode);
if("D".equalsIgnoreCase(payMode)||"P".equalsIgnoreCase(payMode))
{
System.out.println("payMode<<<<<<<<");
drawnAt=checkNull(getpayablesAt(sundryType, sundryCode, bankCode, conn));
}
if("D".equalsIgnoreCase(payMode)||"P".equalsIgnoreCase(payMode)||"T".equalsIgnoreCase(payMode)||"N".equalsIgnoreCase(payMode))
{
System.out.println("payMode========>>>>");
stanCode=checkNull(getStanDraw(sundryType, sundryCode, conn));
System.out.println("Getting stanCode=============="+stanCode);
}
if (Double.parseDouble(payAmt) != 0 ) // Condition added by jaimin 16/08/2007 // Changed by Raj - 29/12/2007
{
System.out.println("--------------> if payAmt>0 :: "+payAmt);
......@@ -872,36 +1178,68 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
|| (Double.parseDouble(netPayable) < 0 && Double.parseDouble(payAmt) <= 0 && Double.parseDouble(payAmt) >= Double.parseDouble(netPayable)) )
{ // End by Jaimin 16/08/2007
System.out.println("----------------In condition--------------");
System.out.println("vouch_no============"+refNo);
System.out.println("vouch_date============"+refDate);
System.out.println("payAmt============"+payAmt);
System.out.println("acct_code__ap========="+acctCode);
System.out.println("cctr_code__ap========="+cctrCode);
double payAmount=Double.parseDouble(payAmt);
double exchRate1=Double.parseDouble(exchRate);
diffAmt=((payAmount * exchRate1)-(payAmount*mexrate));
System.out.println("diff_amt__exch========="+diffAmt);
lineNo++;
xmlString.append("<Detail2 dbID=':' domID='1' objName='auto_pay' objContext='2'>");
xmlString.append("<Detail2 dbID=':' domID='1' objName='misc_pay' objContext='2'>");
xmlString.append("<attribute pkNames='tran_id:line_no:' status='N' updateFlag='A' selected='N' />");
xmlString.append("<tran_id><![CDATA[]]></tran_id>");
xmlString.append("<line_no><![CDATA["+lineNo+"]]></line_no>");
xmlString.append("<tran_ser><![CDATA["+tranSer+"]]></tran_ser>");
xmlString.append("<ref_no><![CDATA["+refNo+"]]></ref_no>");
xmlString.append("<tran_date><![CDATA[" + payDate + "]]></tran_date>");//Added by Jaimin 25/07/2007
xmlString.append("<ref_date><![CDATA["+refDate+"]]></ref_date>");
xmlString.append("<line_no><![CDATA["+lineNo+"]]></line_no>");
xmlString.append("<vouch_no><![CDATA["+refNo+"]]></vouch_no>");
xmlString.append("<vouch_date><![CDATA[" + refDate + "]]></vouch_date>");//Added by Jaimin 25/07/2007
xmlString.append("<net_amt><![CDATA["+payAmt+"]]></net_amt>");
xmlString.append("<pay_amt><![CDATA["+payAmt+"]]></pay_amt>");
xmlString.append("<curr_code><![CDATA["+currCodeBc+"]]></curr_code>");
xmlString.append("<exch_rate__vouch><![CDATA["+exchRate+"]]></exch_rate__vouch>");
xmlString.append("<diff_amt__exch><![CDATA["+diffAmt+"]]></diff_amt__exch>");
xmlString.append("<acct_code__ap><![CDATA["+acctCode+"]]></acct_code__ap>");//
xmlString.append("<cctr_code__ap><![CDATA["+cctrCode+"]]></cctr_code__ap>");//
xmlString.append("<sundry_type><![CDATA["+sundryType+"]]></sundry_type>");//
xmlString.append("<sundry_code><![CDATA["+sundryCode+"]]></sundry_code>");//
xmlString.append("<bank_charges><![CDATA["+0+"]]></bank_charges>");//
xmlString.append("<stan_code><![CDATA["+stanCode+"]]></stan_code>");
xmlString.append("<drawn_at><![CDATA["+drawnAt+"]]></drawn_at>");
xmlString.append("<tax_amt><![CDATA["+0+"]]></tax_amt>");//
xmlString.append("<net_pay_amt><![CDATA["+payAmt+"]]></net_pay_amt>");//
xmlString.append("<acct_code__disc><![CDATA["+acctCodeDisc+"]]></acct_code__disc>");//
xmlString.append("<cctr_code__disc><![CDATA["+cctrCodeDisc+"]]></cctr_code__disc>");//
//xmlString.append("<tax_env><![CDATA["+exchRate+"]]></tax_env>");//doubtremaining
xmlString.append("<bill_no><![CDATA["+billNo+"]]></bill_no>");
xmlString.append("<bill_date><![CDATA["+billDate+"]]></bill_date>");
xmlString.append("<curr_code><![CDATA["+currCode+"]]></curr_code>");
xmlString.append("<exch_rate><![CDATA["+exchRate+"]]></exch_rate>");
xmlString.append("<sundry_type><![CDATA["+sundryType+"]]></sundry_type>");
xmlString.append("<sundry_code><![CDATA["+sundryCode+"]]></sundry_code>");
xmlString.append("<acct_code><![CDATA["+acctCode+"]]></acct_code>");
xmlString.append("<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>");
xmlString.append("<due_date><![CDATA["+dueDate+"]]></due_date>");
xmlString.append("<discount_amt><![CDATA["+disAmt+"]]></discount_amt>");
xmlString.append("<discount><![CDATA["+discount+"]]></discount>"); // remaining
xmlString.append("<tot_amt><![CDATA["+totAmt+"]]></tot_amt>");
xmlString.append("<pay_mode><![CDATA["+payMode+"]]></pay_mode>");
xmlString.append("<adv_amt><![CDATA["+advAmt+"]]></adv_amt>");
xmlString.append("<adj_amt><![CDATA["+adjAmt+"]]></adj_amt>");
xmlString.append("<hold_amt><![CDATA["+holdAmt+"]]></hold_amt>");
xmlString.append("<net_payable><![CDATA["+netPayable+"]]></net_payable>");
xmlString.append("<pay_amt><![CDATA["+payAmt+"]]></pay_amt>");
xmlString.append("<tran_id__pay><![CDATA[]]></tran_id__pay>");
xmlString.append("<tran_id__miscpay><![CDATA["+tranId+"]]></tran_id__miscpay>");
xmlString.append("<sundry_name><![CDATA["+sundryName+"]]></sundry_name>");
//xmlString.append("<pay_mode><![CDATA["+payMode+"]]></pay_mode>");
//xmlString.append("<adv_amt><![CDATA["+advAmt+"]]></adv_amt>");
//xmlString.append("<adj_amt><![CDATA["+adjAmt+"]]></adj_amt>");
//xmlString.append("<hold_amt><![CDATA["+holdAmt+"]]></hold_amt>");
//xmlString.append("<net_payable><![CDATA["+netPayable+"]]></net_payable>");
//xmlString.append("<curr_code><![CDATA["+currCode+"]]></curr_code>");
//xmlString.append("<exch_rate><![CDATA["+exchRate+"]]></exch_rate>");
//xmlString.append("<acct_code><![CDATA["+acctCode+"]]></acct_code>");
//xmlString.append("<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>");
//xmlString.append("<due_date><![CDATA["+dueDate+"]]></due_date>");
//xmlString.append("<pay_amt><![CDATA["+payAmt+"]]></pay_amt>");
//xmlString.append("<tran_id__pay><![CDATA[]]></tran_id__pay>");
//xmlString.append("<tran_id__miscpay><![CDATA["+tranId+"]]></tran_id__miscpay>");
//xmlString.append("<sundry_name><![CDATA["+sundryName+"]]></sundry_name>");*/
xmlString.append("</Detail2>");
System.out.println("XmlString Detail======"+xmlString.toString());
}
else
{//case added by Jaimin 17/08/2007
......@@ -915,7 +1253,10 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
}
}
} //FOR OUTER LOOP
}
System.out.println("XmlString ======"+xmlString.toString());
System.out.println("Getting erroe-------"+errString);
//FOR OUTER LOOP
if (errString.trim().length()>0 )
{
err = errMsg("","","",errString);
......@@ -924,6 +1265,7 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
{
xmlString.append("</Header0></group0></DocumentRoot>");
xmlOutString = xmlString.toString();
System.out.println("xmlOutString============="+xmlOutString);
//writeLog(filePtr,"xmlString-->\n"+xmlString,true);
String [] authencate = new String[2];
authencate[0] = "";
......@@ -935,6 +1277,8 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");// added for ejb3
//MasterStateful masterStateful = masterStatefulHome.create(); //commented for ejb3
retString = masterStateful.processRequest(authencate, siteCode, true,xmlOutString);
System.out.println("After save data ======================="+retString);
//Added - Gulzar - 25/01/08
if ( retString.indexOf("Success") > 0 )
{
......@@ -1138,4 +1482,488 @@ public class AutoPmtGenPrc extends ProcessEJB implements AutoPmtGenPrcLocal,Auto
return errStringXml.toString();
}
private String checkNull(String str)
{
if(str == null)
{
return "";
}
else
{
return str ;
}
}
public String getStanDraw(String sundryType ,String sundryCode,Connection conn) throws ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql="",stanCode="",empCode="";
try
{
System.out.println(">>>>>>>>>Enter in getStanDraw method");
System.out.println(">>>>>>>>sundryType==="+sundryType);
System.out.println(">>>>>>>>sundryCode==="+sundryCode);
if((sundryType!=null && sundryType.trim().length()>0) && "E".equalsIgnoreCase(sundryType))
{
sql="select stan_code from employee where emp_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type=E>>>>>>"+stanCode);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "S".equalsIgnoreCase(sundryType))
{
sql="select stan_code from supplier where supp_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type= S>>>>>>"+stanCode);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "C".equalsIgnoreCase(sundryType))
{
sql="select stan_code from customer where cust_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type=C>>>>>>"+stanCode);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "P".equalsIgnoreCase(sundryType))
{
sql="select emp_code from sales_pers where sales_pers = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
empCode = checkNull(rs.getString("emp_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("empCode from Sundry type=P>>>>>>"+empCode);
if(empCode!=null && empCode.trim().length()>0)
{
sql="select stan_code from employee where emp_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type=P>>>>>>"+stanCode);
}
}
else if((sundryType!=null && sundryType.trim().length()>0) && "T".equalsIgnoreCase(sundryType))
{
sql="select stan_code from transporter where tran_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type= T>>>>>>"+stanCode);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "X".equalsIgnoreCase(sundryType))
{
sql="select stan_code from tax_authority where tauth_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("StanCode from Sundry type= X>>>>>>"+stanCode);
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
throw new ITMException(e);
}
return stanCode;
}
public String getpayablesAt(String sundryType ,String sundryCode,String bankCode,Connection conn) throws ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql="",payables="",empCode="",stanCode="",bankRef="";
try
{
System.out.println(">>>>>>>>>Enter in getStanDraw method");
System.out.println(">>>>>>>>sundryType==="+sundryType);
System.out.println(">>>>>>>>sundryCode==="+sundryCode);
System.out.println(">>>>>>>>bankCode==="+bankCode);
if((sundryType!=null && sundryType.trim().length()>0) && "E".equalsIgnoreCase(sundryType))
{
sql="select dd_payable_bank,stan_code from employee where emp_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("dd_payable_bank"));
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type=E>>>>>>"+payables);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "S".equalsIgnoreCase(sundryType))
{
sql="select bank_ref,stan_code from supplier where supp_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("bank_ref"));
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type= S>>>>>>"+payables);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "C".equalsIgnoreCase(sundryType))
{
sql="select bank_name ,stan_code from customer where cust_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("bank_name"));
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type=C>>>>>>"+payables);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "T".equalsIgnoreCase(sundryType))
{
sql="select payable_ref,stan_code from transporter where tran_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("payable_ref"));
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type= T>>>>>>"+payables);
}
else if((sundryType!=null && sundryType.trim().length()>0) && "X".equalsIgnoreCase(sundryType))
{
sql="select bank_ref,stan_code from tax_authority where tauth_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,sundryCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("bank_ref"));
stanCode = checkNull(rs.getString("stan_code"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type= X>>>>>>"+payables);
}
if(payables!=null && payables.trim().length()>0)
{
sql="select drawn_at, bank_ref from bank_stan_serv where bank_code = ? and stan_code = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,bankCode);
pstmt.setString(2,stanCode);
rs = pstmt.executeQuery();
if(rs.next())
{
payables = checkNull(rs.getString("drawn_at"));
bankRef = checkNull(rs.getString("bank_ref"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println("payables from Sundry type= X>>>>>>"+payables);
System.out.println("bankRef from Sundry type= X>>>>>>"+bankRef);
if(bankRef!=null && bankRef.trim().length()>0)
{
payables=payables.trim() +","+bankRef.trim();
System.out.println("Payables final====="+payables);
}
}
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
throw new ITMException(e);
}
return payables;
}
public Date getDiscountdate(String crTerm ,Date vochurDate,Date effDate,Date billDt,Connection conn) throws ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql="",startFrom="",empCode="",stanCode="",bankRef="";
Date tranDt=null,toDate=null,dueDate=null,newDate=null;
String month1="",overrideDiscountDate="",liCrDays="";
long maxDay=0,liDays=0,liDueDays=0,liCrDays1=0;
long currDays=0;
int liDays1=0;
try
{
System.out.println(">>>>>>>>>Enter in getDiscountdate");
System.out.println(">>>>>>>>crTerm==="+crTerm);
System.out.println(">>>>>>>>vochurDate==="+vochurDate);
System.out.println(">>>>>>>>effDate==="+effDate);
System.out.println(">>>>>>>>billDt==="+billDt);
sql="select start_from from crterm where cr_term = ?";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,crTerm);
rs = pstmt.executeQuery();
if(rs.next())
{
startFrom = checkNull(rs.getString("start_from"));
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
System.out.println(">>>>>>>>startFrom==="+startFrom);
if((startFrom!=null && startFrom.trim().length()>0) && "R".equalsIgnoreCase(startFrom))
{
tranDt=vochurDate;
}
else if((startFrom!=null && startFrom.trim().length()>0) && "D".equalsIgnoreCase(startFrom) && "Q".equalsIgnoreCase(startFrom))
{
tranDt=effDate;
}
else if((startFrom!=null && startFrom.trim().length()>0) && "B".equalsIgnoreCase(startFrom) )
{
tranDt=billDt;
}
SimpleDateFormat sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
//newDate=sdf.format(tranDt);
//newDate=sdf.parse(tranDt);
// Date date1 = sdf.parse(newDate);
if(tranDt!=null)
{
Calendar cal = Calendar.getInstance();
//cal.setTime(date1);
cal.setTime(tranDt);
int month = cal.get(Calendar.MONTH);
System.out.println("Getting Month============="+month);
if(month==12)
{
month=1;
month1="01";
}
else
{
month=month+1;
if(month>9)
{
month1=Integer.toString(month);
}
else
{
month1="0"+Integer.toString(month);
}
}
}
sql="select override_discount_date from crterm_disc where cr_term = ? and cr_month= ? and override_discount_date is not null";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,crTerm);
pstmt.setString(2,month1);
rs = pstmt.executeQuery();
if(rs.next())
{
System.out.println("Data found>>>>>.");
overrideDiscountDate = checkNull(rs.getString("override_discount_date"));
System.out.println("Getting overrideDiscountDate============="+overrideDiscountDate);
liCrDays=overrideDiscountDate.substring(3, 2);
System.out.println("Getting liDays============="+liDays);
}
else
{
System.out.println("<<<<<,,,Data not found");
sql="select crtermfc.max_day,crterm_disc.override_discount_date from crterm_disc,crtermfc " +
"where crterm_disc.cr_term = crtermfc.cr_term and trim(crtermfc.line_no) = '1' and crterm_disc.cr_term = ? and crterm_disc.cr_month = '99' and crterm_disc.override_discount_date is not null";
pstmt1= conn.prepareStatement(sql);
pstmt1.setString(1,crTerm);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
maxDay = rs1.getInt("max_day");
overrideDiscountDate = checkNull(rs1.getString("override_discount_date"));
liCrDays=overrideDiscountDate.substring(3, 2);
liCrDays1=Integer.parseInt(liCrDays);
System.out.println("Getting liDays============="+liDays);
}
else
{
sql="select max_day from crtermfc where cr_term = ? and trim(crtermfc.line_no) = '1'";
pstmt2= conn.prepareStatement(sql);
pstmt2.setString(1,crTerm);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
liDays = rs2.getInt("max_day");
}
rs2.close();
pstmt2.close();
pstmt2 = null;
rs2 = null;
if(liDays==0)
{
liDays=0;
}
}
rs1.close();
pstmt1.close();
pstmt1 = null;
rs1= null;
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if(liDays==0)
{
liDays=0;
}
sql="select cr_days from crterm where cr_term = ? ";
pstmt= conn.prepareStatement(sql);
pstmt.setString(1,crTerm);
rs = pstmt.executeQuery();
if(rs.next())
{
liDueDays = rs.getInt("cr_days");
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
if(overrideDiscountDate!=null && overrideDiscountDate.trim().length()>0)
{
sql="select to_date from period where fr_date <= ? and to_date >=?";
pstmt= conn.prepareStatement(sql);
pstmt.setDate(1,(java.sql.Date) vochurDate);
pstmt.setDate(2,(java.sql.Date) vochurDate);
rs = pstmt.executeQuery();
if(rs.next())
{
toDate = rs.getDate("to_date");
}
rs.close();
pstmt.close();
pstmt = null;
rs = null;
long diff = vochurDate.getTime() - toDate.getTime();
currDays = diff / (24 * 60 * 60 * 1000);
System.out.println("CurrDtae======================="+currDays);
liDays=currDays+liCrDays1;
liDays1 = (int) liDays;
System.out.println("final liDays1======== "+liDays1);
}
if(tranDt!=null)
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(tranDt);
// add one day to the date/calendar
calendar.add(Calendar.DAY_OF_YEAR, liDays1);
// now get "tomorrow"
dueDate = calendar.getTime();
}
// print out tomorrow's date
System.out.println("dueDate: " + dueDate);
}
catch (Exception e)
{
System.out.println("Exception ::" + e);
throw new ITMException(e);
}
return dueDate;
}
}
\ No newline at end of file
/********************************************************
Title : AutoPmtPrcSch
Date : 20/FEB/15
Developer: Priyanka Shinde
********************************************************/
package ibase.webitm.ejb.fin;
import ibase.scheduler.utility.interfaces.Schedule;
//import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.*;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
import ibase.utility.E12GenericUtility;
import ibase.utility.CommonConstants;
import java.text.SimpleDateFormat;
public class AutoPmtPrcSch implements Schedule
{
//GenericUtility genericUtility = GenericUtility.getInstance();
Calendar calendar = Calendar.getInstance();
E12GenericUtility e12GenericUtility = new E12GenericUtility();
String startDateStr = null;
FileOutputStream fos1 = null;
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
@Override
public String schedule(String scheduleParamXML)throws Exception
{
int childNodeListLength = 0;
String childNodeName = null;
String tranId="",loginSiteCode="";
ibase.utility.UserInfoBean userInfo = null;
int noOfParam=0;
String sysDate ="";
String retString="";
String xtraParams = "",siteCode="",sundryType="",sundryCode="";
String actualLoginSiteCode="";
String getString="";
String due_date_from="",wfStatus="";
try
{
System.out.println("In try@@@@@@@########@@@");
System.out.println("************ ["+scheduleParamXML+"]");
Document dom = null;
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
loginSiteCode = userInfo.getSiteCode();
xtraParams = "loginCode="+userInfo.getLoginCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode+"~~loginEmpCode="+userInfo.getEmpCode();
System.out.println("XTRAPARAMS@@@@@@@@@@@######:"+xtraParams);
GenericUtility genericUtility=GenericUtility.getInstance();
System.out.println("scheduleParamXML-----"+scheduleParamXML);
dom=genericUtility.parseString(scheduleParamXML);
java.util.Date today=new java.util.Date();
Calendar c = Calendar.getInstance();
c.setTime(today);
today = c.getTime();
SimpleDateFormat sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
sysDate=sdf.format(today);
NodeList paramList = dom.getElementsByTagName( "SCHEDULE" );
noOfParam = paramList.getLength();
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("childNodeListLength !!!!!"+childNodeListLength);
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
actualLoginSiteCode = childNode.getFirstChild().getNodeValue();
System.out.println("actualLoginSiteCode======"+actualLoginSiteCode);
}
if(ctr==1)
{
due_date_from = childNode.getFirstChild().getNodeValue();
System.out.println("due_date_from======"+due_date_from);
}
if(ctr==2)
{
wfStatus = childNode.getFirstChild().getNodeValue();
System.out.println("status======"+wfStatus);
}
if(ctr==3)
{
sundryType = childNode.getFirstChild().getNodeValue();
System.out.println("sundryType======"+sundryType);
}
if(ctr==4)
{
sundryCode = childNode.getFirstChild().getNodeValue();
System.out.println("sundryCode======"+sundryCode);
}
}
}
System.out.println("intializingLog$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$........."+ intializingLog("Gen_bank_payment_log"));
getString= autoPayment(actualLoginSiteCode,sundryType,due_date_from,wfStatus,sundryCode,scheduleParamXML);
}
catch(Exception e)
{
System.out.println(">>>>>>>>>>>>>In catch:");
System.out.println(e);
}
System.out.println("");
return retString;
}
@Override
public String schedule(HashMap arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public String schedulePriority(String arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
public String autoPayment(String siteCode,String sundryType,String dueDateFrom,String wfStatus,String sundryCodeParam,String scheduleParamXML ) throws Exception
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//PreparedStatement pstmt1 = null;
//ResultSet rs1 = null;
boolean isError = false;
String retString="";
String sql="";
String sundryFieldName="",sundryTableName="",sundryCode="";
String tranId="",loginSiteCode="",xtraParams = "";
String vouchurNo="";
String miscPaytranDate="",effDate="",billNo="",billDate="",currCode="",exchRate="",acctrCode="",cctrCode="";
String dueOn="",finEntity="",siteCd="",totAmt="",sundryTyp="",bankCode="",payMode="";
String advAmt="",tranSer="",adjAmt="",holdAmt="",userName="",payAmt="",sundryName="",netPay="";
String xmlString4="", retString1="";
String bankName = "",refNo="",refNoupto="";
String sysDate ="";
String trantype="";
String strToWrite = "";
String endDateStr = null;
String errString ="";
boolean flag=false;
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
java.util.Date endDate = new java.util.Date(System.currentTimeMillis());
ArrayList<String> sundryCodeList = new ArrayList<String>();
AutoPmtGenPrc aPayPrc=new AutoPmtGenPrc();
FinCommon fin =new FinCommon();
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
conn.setAutoCommit(false);
ibase.utility.UserInfoBean userInfo = null;
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
loginSiteCode = userInfo.getSiteCode();
String windowName="w_miscpay_auto,";
xtraParams = "loginCode="+userInfo.getLoginCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode+"~~loginEmpCode="+userInfo.getEmpCode();
java.util.Date today=new java.util.Date();
Calendar c = Calendar.getInstance();
c.setTime(today);
today = c.getTime();
SimpleDateFormat sdf=new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
sysDate=sdf.format(today);
Date currentDate = new Date();
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
System.out.println("XTRAPARAMS@@@@@@@@@@@######:"+xtraParams);
sql="select bank_code from site where site_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
bankCode=rs.getString("bank_code");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "SELECT BANK_NAME,chq1,chq3 FROM BANK WHERE BANK_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,bankCode);
rs = pstmt.executeQuery();
if (rs.next())
{
bankName= checkNull(rs.getString(1));
refNo= checkNull(rs.getString(2));
refNoupto= checkNull(rs.getString(3));
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql="select fin_entity from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,siteCode);
rs = pstmt.executeQuery();
if(rs.next())
{
finEntity=rs.getString("fin_entity");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("finEntity========="+finEntity);
sql="select curr_code from finent where fin_entity = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,finEntity);
rs = pstmt.executeQuery();
if(rs.next())
{
currCode=rs.getString("curr_code");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("currCode========="+currCode);
trantype=fin.getFinparams("999999", "TRAN_TYPE_AUTO_PAY", conn);
System.out.println("trantype========="+trantype);
if(trantype==null||trantype.trim().length()==0||trantype.equalsIgnoreCase("NULLFOUND"))
{
trantype="O";
}
if(sundryType!=null && sundryType.trim().length()>0 &&("C".equalsIgnoreCase(sundryType)))
{
sundryTableName="customer";
sundryFieldName="cust_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("S".equalsIgnoreCase(sundryType)))
{
sundryTableName="supplier";
sundryFieldName="supp_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("B".equalsIgnoreCase(sundryType)))
{
sundryTableName="bank";
sundryFieldName="bank_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("T".equalsIgnoreCase(sundryType)))
{
sundryTableName="transporter";
sundryFieldName="tran_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("E".equalsIgnoreCase(sundryType)))
{
sundryTableName="employee";
sundryFieldName="emp_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("L".equalsIgnoreCase(sundryType)))
{
sundryTableName="loanparty";
sundryFieldName="party_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("P".equalsIgnoreCase(sundryType)))
{
sundryTableName="sales_pers";
sundryFieldName="sales_pers";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("R".equalsIgnoreCase(sundryType)))
{
sundryTableName="strg_customer";
sundryFieldName="sc_code";
}
else if(sundryType!=null && sundryType.trim().length()>0 &&("X".equalsIgnoreCase(sundryType)))
{
sundryTableName="tax_authority";
sundryFieldName="tauth_code";
}
if(("null".equals(sundryCodeParam) || sundryCodeParam.trim().length() == 0 ))
{
sql="select "+sundryFieldName+" from "+sundryTableName;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
sundryCode = rs.getString(1);
//System.out.println("sundryCode>>..>>>>>"+sundryCode);
sundryCodeList.add(sundryCode);
}
}
else
{
String[] arrStr =sundryCodeParam.split(",");
int len =arrStr.length;
for(int i =0;i<len;i++)
{
sundryCode =arrStr[i];
// System.out.println("sundryCode>>>>>>>>"+sundryCode);
sundryCodeList.add(sundryCode);
}
}
System.out.println("list Size========="+sundryCodeList.size());
int itr=0;
while(itr < sundryCodeList.size())
{
sundryCode = sundryCodeList.get(itr);
System.out.println("------------->sundryCode" +sundryCode);
payMode="%";
String xmlString1=" <Detail1 dbID=\"\" domID=\"1\" objContext=\"1\" objName=\"miscpay_auto\"><attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\"/>"+
"<date__pay><![CDATA["+sdf1.format(currentDate).toString()+"]]></date__pay>" +
"<vouch_no__fr><![CDATA[]]></vouch_no__fr>" +
"<vouch_no__to><![CDATA[]]></vouch_no__to>" +
"<date__fr><![CDATA["+dueDateFrom+"]]></date__fr>" +
"<date__to><![CDATA["+sysDate+"]]></date__to>" +
"<site_code__fr><![CDATA["+siteCode+"]]></site_code__fr>" +
"<bank_code><![CDATA["+bankCode+"]]></bank_code>" +
"<ref_no><![CDATA["+refNo+"]]></ref_no>" +
"<post><![CDATA[]]></post>" +
"<bank_name><![CDATA[]]></bank_name>" +
"<sundry_type><![CDATA["+sundryType+"]]></sundry_type>" +
"<sundry_code><![CDATA["+sundryCode+"]]></sundry_code>" +
"<ref_no__upto><![CDATA["+refNoupto+"]]></ref_no__upto>" +
"<pay_mode><![CDATA["+payMode+"]]></pay_mode>" +
"<entry_batch_no><![CDATA[]]></entry_batch_no>" +
"<chq_split><![CDATA[]]></chq_split>" +
"<bank_code__add><![CDATA[]]></bank_code__add>" +
"<bank_name__add><![CDATA[]]></bank_name__add>" +
"<exch_rate><![CDATA[]]></exch_rate>" +
"<noof_confirmed><![CDATA[]]></noof_confirmed>" +
"<noof_rejected><![CDATA[]]></noof_rejected>" +
"<tax_env><![CDATA[]]></tax_env>" +
"<tran_type><![CDATA["+trantype+"]]></tran_type>" +
"<curr_code><![CDATA["+currCode+"]]></curr_code>" +
"<bank_flag><![CDATA[]]></bank_flag>"+
"<wf_status><![CDATA["+wfStatus+"]]></wf_status></Detail1>";
String xmlString2="<DocumentRoot><description>Datawindow Root</description><group0><description>Group0 description</description><Header0><description>Header0 members</description>" +
"<Detail1 dbID=\"\" domID=\"1\" objContext=\"1\" objName=\"miscpay_auto\"><attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\"/>"+
"<date__pay><![CDATA["+sdf1.format(currentDate).toString()+"]]></date__pay>" +
"<vouch_no__fr><![CDATA[]]></vouch_no__fr>" +
"<vouch_no__to><![CDATA[]]></vouch_no__to>" +
"<date__fr><![CDATA["+sysDate+"]]></date__fr>" +
"<date__to><![CDATA["+sysDate+"]]></date__to>" +
"<site_code__fr><![CDATA["+siteCode+"]]></site_code__fr>" +
"<bank_code><![CDATA["+bankCode+"]]></bank_code>" +
"<ref_no><![CDATA["+refNo+"]]></ref_no>" +
"<post><![CDATA[]]></post>" +
"<bank_name><![CDATA[]]></bank_name>" +
"<sundry_type><![CDATA["+sundryType+"]]></sundry_type>" +
"<sundry_code><![CDATA["+sundryCode+"]]></sundry_code>" +
"<ref_no__upto><![CDATA["+refNoupto+"]]></ref_no__upto>" +
"<pay_mode><![CDATA["+payMode+"]]></pay_mode>" +
"<entry_batch_no><![CDATA[]]></entry_batch_no>" +
"<chq_split><![CDATA[]]></chq_split>" +
"<bank_code__add><![CDATA[]]></bank_code__add>" +
"<bank_name__add><![CDATA[]]></bank_name__add>" +
"<exch_rate><![CDATA[]]></exch_rate>" +
"<noof_confirmed><![CDATA[]]></noof_confirmed>" +
"<noof_rejected><![CDATA[]]></noof_rejected>" +
"<tax_env><![CDATA[]]></tax_env>" +
"<tran_type><![CDATA["+trantype+"]]></tran_type>" +
"<curr_code><![CDATA["+currCode+"]]></curr_code>" +
"<bank_flag><![CDATA[]]></bank_flag></Detail1></Header0></group0></DocumentRoot>";
System.out.println("xmlString1@@@@@@@@@@@@@@@@:"+xmlString1);
System.out.println("xmlString2@@@@@@@@@@@@@@@@:"+xmlString2);
System.out.println("Calling getData() Method@@@@@@@@@@@");
retString=aPayPrc.getData(xmlString1, xmlString2, windowName, xtraParams);
System.out.println("ResultString....." + retString);
/**
* Check for Null return
* */
if(retString!=null && retString.trim().length()>0)
{
// Start Process
System.out.println("Processing DATA *****");
startDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
startDateStr = sdf1.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
strToWrite=strToWrite+startDateStr+",";
System.out.println("STARTING DATE"+startDateStr +"STRING TO WRITE"+strToWrite);
System.out.println("getData Method Finished@@@@@@@@@@@2");
xmlString4="<DocumentRoot><description>Datawindow Root</description><group0><description>Group0 description</description><Header0><description>Header0 members</description>";
String lineArr[]=retString.split("\n");
for(int ctr=0;ctr<lineArr.length;ctr++)
{
String arr[]=lineArr[ctr].split("\t");
vouchurNo=arr[0];
miscPaytranDate=arr[1];
effDate=arr[2];
billNo=arr[3];
billDate=arr[4];
currCode=arr[5];
exchRate=arr[6];
sundryCode=arr[7];
acctrCode=arr[8];
cctrCode=arr[9];
dueOn=arr[10];
siteCd=arr[11];
finEntity=arr[12];
totAmt=arr[13];
sundryTyp=arr[14];
bankCode=arr[15];
payMode=arr[16];
advAmt=arr[17];
tranId=arr[18];
tranSer=arr[19];
adjAmt=arr[20];
holdAmt=arr[21];
userName=arr[22];
payAmt=arr[23];
sundryName=arr[24];
netPay=arr[25];
xmlString4=xmlString4+"<Detail2 dbID=\"\" domID='"+ctr+"' objContext=\"2\" objName=\"miscpay_auto\"><attribute pkNames=\"\" selected=\"N\" status=\"N\" updateFlag=\"A\"/>null"+
"<ref_no><![CDATA["+vouchurNo+"]]></ref_no>"+
"<tran_date><![CDATA["+miscPaytranDate+"]]></tran_date>"+
"<ref_date><![CDATA["+effDate+"]]></ref_date>"+
"<bill_no><![CDATA["+billNo+"]]></bill_no>"+
"<bill_date><![CDATA["+billDate+"]]></bill_date>"+
"<curr_code><![CDATA["+currCode+"]]></curr_code>"+
"<exch_rate><![CDATA["+exchRate+"]]></exch_rate>"+
"<sundry_code><![CDATA["+sundryCode+"]]></sundry_code>"+
"<acct_code><![CDATA["+acctrCode+"]]></acct_code>"+
"<cctr_code><![CDATA["+cctrCode+"]]></cctr_code>"+
"<due_date><![CDATA["+dueOn+"]]></due_date>"+
"<site_code><![CDATA["+siteCode+"]]></site_code>"+
"<fin_entity><![CDATA["+finEntity+"]]></fin_entity>"+
"<tot_amt><![CDATA["+totAmt+"]]></tot_amt>"+
"<sundry_type><![CDATA["+sundryTyp+"]]></sundry_type>"+
"<bank_code><![CDATA["+bankCode+"]]></bank_code>"+
"<pay_mode><![CDATA["+payMode+"]]></pay_mode>"+
"<adv_amt><![CDATA["+advAmt+"]]></adv_amt>"+
"<tran_id><![CDATA["+tranId+"]]></tran_id>"+
"<tran_ser><![CDATA["+tranSer+"]]></tran_ser>"+
"<adj_amt><![CDATA["+adjAmt+"]]></adj_amt>"+
"<hold_amt><![CDATA["+holdAmt+"]]></hold_amt>"+
"<username><![CDATA["+userName+"]]></username>"+
"<pay_amt><![CDATA["+payAmt+"]]></pay_amt>"+
"<sundry_name><![CDATA["+sundryName+"]]></sundry_name>"+
"<net_payable><![CDATA["+netPay+"]]></net_payable>"+
"</Detail2>";
}
xmlString4=xmlString4+"</Header0></group0></DocumentRoot>";
System.out.println("xmlString4@@@@@@@@@@@@@@@@:"+xmlString4);
System.out.println("Calling process() Method@@@@@@@@@@@@");
retString1 = aPayPrc.process(xmlString1, xmlString4, windowName, xtraParams);
endDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
endDateStr = sdf1.format(endDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
strToWrite=strToWrite+endDateStr+",";
strToWrite = strToWrite + retString+"\r\n\r\n"+xmlString1+"\r\n\r\n"+xmlString4+"\r\n\r\n"+retString1+"\r\n\r\n";
fos1.write(strToWrite.getBytes());
System.out.println("End Time for transaction"+endDateStr+"string to write"+strToWrite);
System.out.println("ResultString1....." + retString1);
System.out.println("-----Process() called successfully-------");
strToWrite="";
//Increment itr
itr++;
}
else
{
//Increment itr
System.out.println("*******No data found GOING ahead*******");
itr++;
endDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
endDateStr = sdf1.format(endDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
strToWrite=strToWrite+endDateStr+",";
strToWrite = strToWrite + "No Data Found"+"\r\n\r\n"+xmlString1+"\r\n\r\n";
fos1.write(strToWrite.getBytes());
System.out.println("End Time for transaction"+endDateStr+"string to write"+strToWrite);
System.out.println("ResultString1....." + retString1);
System.out.println("-----No data found------");
strToWrite="";
}
System.out.println("Iteration COUNT :- ["+itr+"]");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(SQLException se)
{
isError = true;
System.out.println("Exception : : AutoPmtPrcSch" +se.getMessage());
try
{
conn.rollback();
}
catch(Exception se1){}
throw new ITMException(se);
}finally
{
if(conn != null)
{
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(rs!=null)
{
rs.close();
rs=null;
}
conn.close();
conn= null;
}
}
return retString;
}
private String checkNull(String str)
{
if(str == null)
{
return "";
}
else
{
return str ;
}
}
private String intializingLog(String fileName)
{
String log="intializingLog_Failed";
String strToWrite = "";
String currTime = null;
try{
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
try
{
currTime = sdf1.format(new Timestamp(System.currentTimeMillis())).toString();
currTime = currTime.replaceAll("-","");
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
fileName = fileName+currTime+calendar.get(Calendar.HOUR)+""+calendar.get(Calendar.MINUTE)+".csv";
fos1 = new FileOutputStream(CommonConstants.JBOSSHOME + File.separator +"EDI"+File.separator+fileName);
}
catch(Exception e)
{
System.out.println("Exception []::"+e.getMessage());
e.printStackTrace();
}
startDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
startDateStr = sdf1.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
fos1.write(("Fetching Records Started At " + startDateStr +"\r\n").getBytes());
}
catch(Exception e)
{
System.out.println("Exception []::"+e.getMessage());
e.printStackTrace();
}
log ="intializingLog_Successesfull";
return log;
}
}
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