Commit b52defc5 authored by mjadhav's avatar mjadhav

Create scheduler to generate TAX voucher-F15GSUN010


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98966 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 96b04dc6
/*
* Request Id=F15GSUN010
* developer : mahendra jadhav
* Functinal Impact : Provision to generate scheduler for creation of Tax Voucher for each
* series which mapped with each tax code.
*
*
*/
package ibase.webitm.ejb.fin;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ITMDBAccessLocal;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.sql.Timestamp;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
//import com.sun.jmx.snmp.Timestamp;
import ibase.webitm.ejb.dis.POrderMilestone;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.utility.CommonConstants;
import javax.naming.InitialContext;
import javax.xml.rpc.ParameterMode;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.system.config.AppConnectParm;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.w3c.dom.*;
public class GenTaxVoucherSch extends ValidatorEJB implements Schedule {
E12GenericUtility e12GenericUtility = new E12GenericUtility();
UtilMethods utilmethod = new UtilMethods();
Calendar calendar = Calendar.getInstance();
FileOutputStream fos1 = null;
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
UtilMethods utilMethod = new UtilMethods();
ibase.webitm.ejb.dis.DistCommon dist = new ibase.webitm.ejb.dis.DistCommon();
FinCommon finCommon = new FinCommon();
String startDateStr = null;
String strToWrite="",strToWriteHead="";
@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;
}
@Override
public String schedule(String scheduleParamXML) throws Exception {
// TODO Auto-generated method stub
String siteCode = "",actualLoginSiteCode="",errString="",logFileInit="";
String xtraParams = "",loginSiteCode="";
ibase.utility.UserInfoBean userInfo = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
try
{
System.out.println("Calling GenTaxVoucherSch : ["+scheduleParamXML+"]");
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
loginSiteCode = userInfo.getSiteCode();
System.out.println("loginSiteCode :"+loginSiteCode);
xtraParams = "loginEmpCode="+userInfo.getEmpCode()+"~~loginCode="+userInfo.getLoginCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode;
GenericUtility genericUtility=GenericUtility.getInstance();
Document dom=genericUtility.parseString(scheduleParamXML);
NodeList paramList = dom.getElementsByTagName( "SCHEDULE" );
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
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();
}
}*/
}
logFileInit=intializingLog("Tax_Vou_sch_log");
System.out.println("intializingLog !!!!"+logFileInit);
errString = genTextVouchSch(xtraParams,conn);
if(errString.trim().length() > 0)
{
System.out.println(">>>After Schedulaer Process completed>> strToWrite:"+strToWrite);
strToWrite= "Schedulaer Process completed!!";
fos1.write(strToWrite.getBytes());
}
else
{
System.out.println(">>>No date Found to complete the process:"+strToWrite);
strToWrite = "<?xml version='1.0'?><Root><errors><message>";
strToWrite = strToWrite + "<![CDATA[Error :Data Not Found To Generate Tax Voucher!!]]></message>";
strToWrite= strToWrite + "</errors></Root>";
fos1.write(strToWrite.getBytes());
}
}
catch(Exception e)
{
throw new Exception(e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("errString>>>["+errString+"]");
return errString;
}
/*------------------------------------------------------------------------------------------------------*/
public String genTextVouchSch(String xtraParams,Connection conn)
{
PreparedStatement pstmt = null,pstmt1 = null,pstmt2 = null,pstmt3 = null,pstmt4 = null;
ResultSet rs = null,rs1=null,rs2=null,rs3=null,rs4=null;
java.sql.Timestamp tranDateFrm=null,tranDateTo=null,prdFrom=null,sysDateTstmp=null,frmDateCurr=null,toDateCurr=null,vouchDateFrm=null,vouchDateTo=null;
Map<String,List<String>> taxSiteMap = new HashMap<String,List<String>>();
Date currentDate = new Date();
String sql="",valuexmlString="",retString="",sysDateStr="",taxCode="",siteCode="",vauchDtVar="";
try
{
System.out.println("called genTextVouchSch !!");
SimpleDateFormat sdf= new SimpleDateFormat((GenericUtility.getInstance()).getApplDateFormat());
String seriesArr [] = new String[8];
/*seriesArr[0] = "M-VOUC"; // Misc.Voucher
seriesArr[1] = "VOUCH"; // Purchase Voucher
seriesArr[2] = "S-INV"; // Sales Invoice
seriesArr[3] = "MDRCRD"; // Misc Debit Note
seriesArr[4] = "MDRCRC"; // Misc.Credit Note
seriesArr[5] = "CRNRCP"; // Credit Note
seriesArr[6] = "DRNRCP"; // Debit Note
seriesArr[7] = "DRNPAY"; // Dr Note Payable
seriesArr[8] = "CRNPAY"; // Cr Note Payable
seriesArr[9] = "CRNINV"; // Comm Credit Note
*/
seriesArr[0] = "M-VOUC"; // Misc.Voucher
seriesArr[1] = "VOUCH"; // Purchase Voucher
seriesArr[2] = "S-INV"; // Sales Invoice
seriesArr[3] = "MDRCRD"; // Misc Debit Note
seriesArr[4] = "MDRCRC"; // Misc.Credit Note
seriesArr[5] = "CRNINV"; // Comm Credit Note
seriesArr[6] = "CRNRCP"; // Credit Note
seriesArr[7] = "DRNRCP"; // Debit Note
//seriesArr[8] = "DRNPAY"; // Dr Note Payable(not use)
//seriesArr[9] = "CRNPAY"; // Cr Note Payable(not use)
/*---------------Calculate previous month of first date and last date-------------------------*/
sysDateStr = sdf.format(currentDate);
sysDateTstmp = java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(sysDateStr, e12GenericUtility.getApplDateFormat(),e12GenericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("sysDateTstmp :"+sysDateTstmp);
sql= " select FR_DATE,TO_DATE from period where ? "
+ " between FR_DATE and TO_DATE";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, sysDateTstmp);
rs = pstmt.executeQuery();
if(rs.next())
{
frmDateCurr = rs.getTimestamp("FR_DATE");
toDateCurr = rs.getTimestamp("TO_DATE");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("frmDateCurr :"+frmDateCurr);
System.out.println("toDateCurr :"+toDateCurr);
//frmDateCurr: 1st date of current month
prdFrom = getPreviousDate(frmDateCurr,conn);
System.out.println("prdFrom :"+prdFrom);
sql= " select FR_DATE,TO_DATE from period where ? "
+ " between FR_DATE and TO_DATE";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, prdFrom);
rs = pstmt.executeQuery();
if(rs.next())
{
tranDateFrm = rs.getTimestamp("FR_DATE"); //first date of previous month
tranDateTo = rs.getTimestamp("TO_DATE"); // last date of previous month
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("tranDateFrm :"+tranDateFrm);
System.out.println("tranDateTo :"+tranDateTo);
/*----------------------------------------------------------------------------------------*/
startDateStr = sdf.format(startDate)+" "+calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
System.out.println("seriesArr.length :"+seriesArr.length);
/*String frmdate= "29/06/15";
String todate= "30/06/15";
tranDateFrm = java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(frmdate, e12GenericUtility.getApplDateFormat(),e12GenericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("tranDateFrm :"+tranDateFrm);
tranDateTo = java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(todate, e12GenericUtility.getApplDateFormat(),e12GenericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("tranDateTo :"+tranDateTo);*/
vauchDtVar = checkNull(finCommon.getFinparams("999999", "TAX_VOUCH_DATE", conn));
System.out.println("vauchDtVar="+vauchDtVar);
if(vauchDtVar.equalsIgnoreCase("Y"))
{
vouchDateFrm=tranDateFrm;
vouchDateTo=tranDateTo;
}
else
{
vouchDateFrm=sysDateTstmp;
vouchDateTo=sysDateTstmp;
}
for(int serNo = 0 ; serNo < seriesArr.length ; serNo++ )
{
System.out.println("for count :"+serNo);
System.out.println("Series :"+seriesArr[serNo]);
taxSiteMap=getTaxSiteCodeOfSer(seriesArr[serNo],tranDateFrm,tranDateTo,conn);
for (Map.Entry<String, List<String>> entry : taxSiteMap.entrySet())
{
String key = entry.getKey();
List<String> values = entry.getValue();
System.out.println("Key = " + key);
System.out.println("Values = " + values);
for (String code : values)
{
System.out.println(code);
int pos = code.indexOf("@");
System.out.println(pos);
taxCode = code.substring(0,pos);
System.out.println("taxCode :"+taxCode);
siteCode = code.substring(pos+1);
System.out.println("SiteCode :"+siteCode);
strToWrite="";
strToWriteHead="Series :"+seriesArr[serNo]+" Tax Code:"+taxCode+" Site Code:"+siteCode+" Tran Date From:"+tranDateFrm+" Tran Date To:"+tranDateTo+" Voucher Date:"+tranDateFrm+" Voucher Due on:"+tranDateTo+"\n";
strToWrite=strToWrite + strToWriteHead;
strToWrite=strToWrite+startDateStr+",";
StringBuffer TaxVocStrBuff = new StringBuffer();
TaxVocStrBuff.append(taxCode).append("\t"); //tax_code
TaxVocStrBuff.append(siteCode).append("\t"); //site_code__fr
TaxVocStrBuff.append(siteCode).append("\t"); //site_code__to
TaxVocStrBuff.append(seriesArr[serNo]).append("\t"); //as_transfer
TaxVocStrBuff.append(tranDateFrm).append("\t"); //ad_trandate_fr
TaxVocStrBuff.append(tranDateTo).append("\t"); //ad_trandate_to
TaxVocStrBuff.append(vouchDateFrm).append("\t"); //ad_tran_date
TaxVocStrBuff.append(vouchDateTo).append("\t"); //ad_due_date
TaxVocStrBuff.append("X").append("\t"); //sundry_type
TaxVocStrBuff.append("").append("\t"); //tran_type
TaxVocStrBuff.append("0").append("\t"); //vch_amt
TaxVocStrBuff.append("D").append("\t"); //as_opt
TaxVocStrBuff.append("").append("\t"); //as_id
TaxVocStrBuff.append("").append("\t"); //acct_code
TaxVocStrBuff.append("").append("\t"); //cctr_code
valuexmlString=TaxVocStrBuff.toString();
System.out.println("valuexmlString :"+valuexmlString);
StringBuffer TaxVocStrBuffAll = new StringBuffer();
retString = taxVochProcess("taxpost_chap",valuexmlString, xtraParams, conn);
System.out.println("retString :"+retString);
strToWrite = strToWrite + retString+"\r\n\r\n";
//fos1.write(strToWrite.getBytes());
System.out.println(">>>Before Write to fos1 strToWrite:"+strToWrite);
fos1.write(strToWrite.getBytes());
}
}//end of loop for tax and site code map
System.out.println("000000000000");
System.out.println(serNo);
}//end of for loop for series
System.out.println("end of for loop for series!!!!");
}
catch(Exception e)
{
e.printStackTrace();
}
return retString;
}
public String taxVochProcess(String businessObj, String tabXmlData, String xtraParams, Connection conn) throws ITMException
{
String methodName = "";
String compName = "";
String retString = "";
String serviceCode = "";
String serviceURI = "";
String actionURI = "",compType="";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
System.out.println("Check In taxVochProcess businessObj:"+businessObj);
methodName = "gbf_process";
actionURI = "http://NvoServiceurl.org/" + methodName;
sql = "SELECT SERVICE_CODE,COMP_NAME,COMP_TYPE FROM SYSTEM_EVENTS WHERE OBJ_NAME = ? AND EVENT_CODE = 'process' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,businessObj);
rs = pstmt.executeQuery();
if ( rs.next() )
{
serviceCode = rs.getString("SERVICE_CODE");
compName = rs.getString("COMP_NAME");
compType = rs.getString("COMP_TYPE");
}
System.out.println(">>>In recPayProcess serviceCode = "+serviceCode+" compName "+compName);
sql = "SELECT SERVICE_URI FROM SYSTEM_EVENT_SERVICES WHERE SERVICE_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,serviceCode);
rs = pstmt.executeQuery();
if ( rs.next() )
{
serviceURI = rs.getString("SERVICE_URI");
}
System.out.println(">>>In recPayProcess serviceURI = "+serviceURI+" compName = "+compName);
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(serviceURI));
call.setOperationName( new javax.xml.namespace.QName("http://NvoServiceurl.org", methodName ) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(actionURI);
Object[] aobj = new Object[5];
System.out.println("compType :"+compType);
System.out.println("compName :"+compName);
System.out.println("tabXmlData :"+tabXmlData);
System.out.println("xtraParams :"+xtraParams);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_type"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "component_name"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "tab_xml_data_1"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "dummy"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter( new javax.xml.namespace.QName("http://NvoServiceurl.org", "xtra_params"), XMLType.XSD_STRING, ParameterMode.IN);
aobj[0] = new String(compType);
aobj[1] = new String(compName);
aobj[2] = new String(tabXmlData);
aobj[3] = new String("");
aobj[4] = new String(xtraParams);
System.out.println(">>>>>>call.taxVochProcess(XMLType.XSD_STRING) executed........");
call.setReturnType(XMLType.XSD_STRING);
retString = (String)call.invoke(aobj);
System.out.println(">>>>taxVochProcess Complete Return string from NVO is:"+retString);
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try{
if (pstmt != null )
{
pstmt.close();
pstmt = null;
}
/*if( conn != null ){
conn.close();
conn = null;
}*/
}
catch(Exception e)
{
System.out.println("Exception in taxVochProcess!!!!");
e.printStackTrace();
try
{
conn.rollback();
}
catch (Exception s)
{
System.out.println("Unable to rollback");
s.printStackTrace();
}
throw new ITMException(e);
}
}
return retString;
}
/*----------------Calculate TAX Code for Each Series-------------------------------------------------------*/
public Map getTaxSiteCodeOfSer(String series,java.sql.Timestamp tranDateFrm,java.sql.Timestamp tranDateTo,Connection conn)
{
//List<String> taxCodeList = new ArrayList<String>();
//List<String> siteCodeList = new ArrayList<String>();
List<String> taxSiteList = new ArrayList<String>();
Map<String,List<String>> seriesMap = new HashMap<String,List<String>>();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
String taxCode="",siteCode="";
try
{
/*String frmdate= "29/06/15";
String todate= "30/06/15";
tranDateFrm = java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(frmdate, e12GenericUtility.getApplDateFormat(),e12GenericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("tranDateFrm :"+tranDateFrm);
tranDateTo = java.sql.Timestamp.valueOf(e12GenericUtility.getValidDateString(todate, e12GenericUtility.getApplDateFormat(),e12GenericUtility.getDBDateFormat()) + " 00:00:00.0");
System.out.println("tranDateTo :"+tranDateTo);*/
if(series.equalsIgnoreCase("M-VOUC")) //MISC. Voucher
{
sql = " SELECT distinct taxtran.tax_code, misc_voucher.site_code " +
" FROM misc_voucher,taxtran,tax_authority, tax " +
" WHERE ( taxtran.tran_id = misc_voucher.tran_id ) and " +
"( taxtran.tax_code = tax.tax_code ) and" +
" ( tax.tauth_code = tax_authority.tauth_code ) " +
" and ( taxtran.tran_code = 'M-VOUC' ) AND " +
" (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END)" +
" = 'N' AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0 " +
// "and ( misc_voucher.tran_date between ? and ? )" +
"and ( misc_voucher.tran_date between ? and ? )" +
" AND ( misc_voucher.confirmed = 'Y' )";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
//taxCodeList.add(taxCode);
//siteCodeList.add(siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("m-vouc@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("VOUCH")) // Purchase Voucher
{
sql="SELECT distinct taxtran.tax_code,voucher.site_code " +
" FROM voucher, taxtran, tax_authority,tax WHERE " +
" ( taxtran.tran_id = voucher.tran_id ) and ( taxtran.tax_code = tax.tax_code )" +
" and ( tax.tauth_code = tax_authority.tauth_code ) and ( taxtran.tran_code = 'VOUCH' )" +
" AND (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N' " +
" AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0 " +
//" and ( voucher.tran_date between ? and ? )" +
" and ( voucher.tran_date between ? and ?)" +
" AND ( voucher.confirmed = 'Y' ) " ;
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("vouc@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("S-INV")) // Sales Invoice
{
sql= "SELECT distinct taxtran.tax_code, invoice.site_code FROM invoice,TAXTRAN WHERE " +
" ( TAXTRAN.TRAN_ID = invoice.INVOICE_ID ) and ( taxtran.tran_code ='S-INV' ) " +
" AND (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N' AND " +
" (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0 and " +
" ( invoice.tran_date between ? and ? ) AND ( invoice.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("SINV@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("CRNINV")) //Comm Credit Note
{
sql=" select distinct taxtran.tax_code,drcr_inv.site_code from drcr_inv, " +
" taxtran where ( taxtran.tran_id = drcr_inv.tran_id ) and" +
" ( taxtran.tran_code = 'CRNINV' ) and (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N'" +
" ELSE TAXTRAN.POSTED END) = 'N' AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE " +
" TAXTRAN.TAX_AMT END) <> 0 and ( drcr_inv.tran_date between ? and ? )" +
" and ( drcr_inv.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("CRNINV@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("MDRCRC")) //Misc. Credit Note
{
sql=" select distinct taxtran.tax_code,misc_drcr_rcp.site_code " +
" from misc_drcr_rcp, taxtran where" +
" ( taxtran.tran_id = misc_drcr_rcp.tran_id ) " +
" and ( taxtran.tran_code = 'MDRCRC' ) and " +
" (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N'" +
" AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0 " +
" and ( misc_drcr_rcp.tran_date between ? and ? ) and" +
" ( misc_drcr_rcp.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("MDRCRC@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("MDRCRD")) // Misc.debit Note
{
sql=" select distinct taxtran.tax_code,misc_drcr_rcp.site_code " +
" from misc_drcr_rcp, taxtran where" +
" ( taxtran.tran_id = misc_drcr_rcp.tran_id ) " +
" and ( taxtran.tran_code = 'MDRCRD' ) and " +
" (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N'" +
" AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0 " +
" and ( misc_drcr_rcp.tran_date between ? and ? ) and" +
" ( misc_drcr_rcp.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("MDRCRD@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("DRNRCP")) //Debit Note
{
sql= " select distinct drcr_rcp.site_code,taxtran.tax_code from drcr_rcp," +
" taxtran where ( taxtran.tran_id = drcr_rcp.tran_id ) and " +
" ( taxtran.tran_code = 'DRNRCP' ) and " +
" (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N'" +
" AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0" +
" and ( drcr_rcp.tran_date between ? and ? )" +
" and ( drcr_rcp.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("DRNRCP@Code",taxSiteList);
}
else if(series.equalsIgnoreCase("CRNRCP")) // Credit Note
{
sql= " select distinct drcr_rcp.site_code,taxtran.tax_code from drcr_rcp," +
" taxtran where ( taxtran.tran_id = drcr_rcp.tran_id ) and " +
" ( taxtran.tran_code = 'CRNRCP' ) and " +
" (CASE WHEN TAXTRAN.POSTED IS NULL THEN 'N' ELSE TAXTRAN.POSTED END) = 'N' AND (CASE WHEN TAXTRAN.TAX_AMT IS NULL THEN 0 ELSE TAXTRAN.TAX_AMT END) <> 0" +
" and ( drcr_rcp.tran_date between ? and ? )" +
" and ( drcr_rcp.confirmed = 'Y' ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,tranDateFrm);
pstmt.setTimestamp(2,tranDateTo);
rs = pstmt.executeQuery();
while( rs.next())
{
taxCode = rs.getString("tax_code");
siteCode = rs.getString("site_code");
System.out.print("taxCode :"+taxCode);
System.out.print("siteCode :"+siteCode);
taxSiteList.add(taxCode+"@"+siteCode);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
seriesMap.put("CRNRCP@Code",taxSiteList);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return seriesMap;
}
/*----------------------------------------------------------------------------------------------------------*/
private String intializingLog(String fileName)
{
String log="";
String strToWrite = "";
String currTime = null;
try
{
System.out.println(">>>In intializingLog() fileName:"+fileName);
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);
//strToWrite="\"TRANID\",\"START TIME\",\"END TIME\",\"STATUS\"\r\n";
//fos1.write(strToWrite.getBytes());
log ="IntializingLog_Successesfull";
}
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(("Tax Voucher Scheduler Started At: " + startDateStr +"\r\n").getBytes());
}
catch(Exception e)
{
System.out.println("Exception []::"+e.getMessage());
log="IntializingLog_Failed";
e.printStackTrace();
}
return log;
}
public void writeLog(File f,String Msg,boolean flag) throws Exception
{
try
{
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
String currTime = null;
Calendar calendar = Calendar.getInstance();
currTime = sdf1.format(new Timestamp(System.currentTimeMillis())).toString();
currTime = currTime.replaceAll("-","");
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
if(! CommonConstants.DEBUG_LEVEL.equals("0"))
{
PrintWriter pw = new PrintWriter((new FileOutputStream(f,flag)),flag);
pw.println("{" + currTime + " " + calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE) + "}\t" + Msg);
pw.close();
}
}
catch(Exception exWm){exWm.printStackTrace();}
}
/*--------------------------------------------------------------------------------------------------*/
private String saveData(String siteCode,String xmlString,String xtraParams, Connection conn) throws ITMException
{
System.out.println("saving data...........");
InitialContext ctx = null;
String retString = null;
MasterStatefulLocal masterStateful = null; // for ejb3
ibase.utility.UserInfoBean userInfo;
String chgUser="",chgTerm="",loginEmpCode="";
E12GenericUtility genericUtility=new E12GenericUtility();
try
{ userInfo = new ibase.utility.UserInfoBean();
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
System.out.println("-----------masterStateful------- " + masterStateful);
String [] authencate = new String[2];
authencate[0] = "";
authencate[1] = "";
System.out.println("xmlString to masterstateful [" + xmlString + "]");
chgUser = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"chgUser");
chgTerm = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"chgTerm");
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginEmpCode");
siteCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
userInfo.setEmpCode(loginEmpCode);
userInfo.setLoginCode(chgUser);
userInfo.setRemoteHost(chgTerm);
userInfo.setSiteCode(siteCode);
userInfo.setEntityCode(loginEmpCode);
System.out.println("userInfo>>>>>"+userInfo);
retString = masterStateful.processRequest(userInfo,xmlString,true,conn);
}
catch(ITMException itme)
{
System.out.println("ITMException :CreateDistOrder :saveData :==>");
throw itme;
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception :CreateDistOrder :saveData :==>");
throw new ITMException(e);
}
return retString;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
return input;
}
/*-------------------------------------------------------------------------------------------------*/
private Timestamp getPreviousDate(java.sql.Timestamp FromDate, Connection conn)
{
String varValueStr="";
int varValue = 0;
java.sql.Timestamp compDate=null,ToDate=null,prdFrom=null;
try
{
varValueStr = dist.getDisparams("999999","SSD_TRANSIT_DAYS",conn);
System.out.println("varValue.." + varValueStr);
if( varValueStr.equalsIgnoreCase("NULLFOUND") )
{
System.out.println("varValue is NULLFOUND" + varValueStr);
}
else
{
varValue = Integer.parseInt(varValueStr);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
System.out.println("varValue = .. " + varValue);
varValue = (-1) * varValue;
System.out.println("changed varValue for to date>>>>>>>>>>>>>>>> = .. " + varValue);
/*compDate = utilMethod.RelativeDate(ToDate,varValue);
System.out.println("compDate >>>>>>"+compDate);*/
varValue = (-1) * 1;
System.out.println("changed varValue>>>>>>>>>>>>>>>> = .. " + varValue);
if(FromDate !=null)
{
prdFrom = utilMethod.RelativeDate(FromDate,varValue);
}
System.out.println("prdFrom :"+prdFrom);
}
catch(Exception e)
{
}
return prdFrom;
}
/*--------------------------------------------------------------------------------------------------*/
/*
public static void main(String arg[])
{
System.out.println("@@@@@@@@@@@@@@@");
String xtraParams="";
String empCode="E17532";
String termId="172.16.9.1";
String loginSiteCode="";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.
getConnection("jdbc:oracle:thin:@172.16.10.24:1521:fintest"
,"SUN","LAXMIMATA1234$");
xtraParams = "loginEmpCode="+empCode+"~~termId="+termId+"~~loginSiteCode="+loginSiteCode;
callProcess(xtraParams,con);
//genTextVouchSch(xtraParams,con);
System.out.println("Created DB Connection....");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
/*public static void callProcess(String xtraParams,Connection conn )
{
genTextVouchSch(xtraParams,conn);
}*/
}
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