Commit aa025e73 authored by vdhoble's avatar vdhoble

Scheduler to generate purchase voucher - F15GSUN009


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98963 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 06bb4d2a
This source diff could not be displayed because it is too large. You can view the blob instead.
/********************
* Created By : Vishakha Dhoble
* On : 26/Oct/15
* Req ID - F15GSUN009
*/
package ibase.webitm.ejb.fin;
import ibase.scheduler.utility.interfaces.Schedule;
import java.rmi.RemoteException;
import java.util.*;
import java.util.Date;
import java.sql.*;
import java.io.*;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.omg.CORBA.ORB;
import org.w3c.dom.*;
import java.lang.*;
import javax.xml.rpc.ParameterMode;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.GenericUtility;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.system.config.*;
import java.text.SimpleDateFormat;
public class PorcpVouchCreateSch implements Schedule
{
GenericUtility genericUtility = GenericUtility.getInstance();
FileOutputStream fos1 = null;
java.sql.Timestamp currDate = null;
String currAppdate ="";
E12GenericUtility e12GenericUtility = new E12GenericUtility();
Calendar calendar = Calendar.getInstance();
java.util.Date startDate = new java.util.Date(System.currentTimeMillis());
java.util.Date endDate = new java.util.Date(System.currentTimeMillis());
String strToWrite = "";
String endDateStr = null;
String startDateStr = null;
@Override
public String schedule(String scheduleParamXML)throws Exception
{
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
PreparedStatement pstmt = null,pstmt1 = null,pstmt2 = null,pstmt3 = null;
ResultSet rs = null,rs1 = null,rs2 = null,rs3 = null;
String queryString="";
String siteCode="";
String sql1 ="",tranidRcp = "";
String voucherId = "";
ArrayList tranidBefore = new ArrayList();
String valuexmlString="";
String retString="";
ITMDBAccessEJB itmDBAccessEJB = null;
ibase.utility.UserInfoBean userInfo = null;
String loginSiteCode="";
String siteDescrMst = "";
double qtyPassed=0,qtyRejected=0,qtyReturned=0,qtyReceived=0;
try
{
GenericUtility genericUtility = GenericUtility.getInstance();
SimpleDateFormat sdfdb= new SimpleDateFormat(genericUtility.getDBDateFormat());
Document dom = null;
Timestamp tranDateFromNew = null ;
String xtraParams = "",source="";
Node currDetail = null ;
int noOfParam=0;
System.out.println("************ ["+scheduleParamXML+"]");
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
loginSiteCode = userInfo.getSiteCode();
java.util.Date today=new java.util.Date();
Calendar c = Calendar.getInstance();
c.setTime(today);
//c.add(Calendar.DATE, 1);
today = c.getTime();
System.out.println("Site code======**************====> "+loginSiteCode);
xtraParams = "loginCode="+userInfo.getLoginCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode+"~~loginEmpCode="+userInfo.getEmpCode()+"~~entityCode="+userInfo.getEntityCode()+"~~profileId="+userInfo.getProfileId();
System.out.print("XtraParams ==== "+xtraParams);
itmDBAccessEJB = new ITMDBAccessEJB();
//currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
//currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate);
SimpleDateFormat sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
currAppdate=sdf.format(today);
System.out.println("intializingLog$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$........."+ intializingLog("Porcp_Vouch_Sch"));
String tranDateFrom = "01/04/15";
tranDateFromNew = Timestamp.valueOf(genericUtility.getValidDateString(tranDateFrom, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) + " 00:00:00.0");
java.util.Date currentDate = new java.util.Date();
System.out.println(">>>>>>>>>>currentDate:"+currentDate);
Timestamp sysDate = java.sql.Timestamp.valueOf( sdfdb.format(currentDate)+" 00:00:00.0");
System.out.println(">>>>sysDate is:"+sysDate);
queryString="SELECT tran_id FROM PORCP A WHERE TRAN_DATE >= ? AND confirmed='Y' AND "
+"A.SUPP_CODE NOT IN(SELECT SUPP_CODE FROM SITE_SUPPLIER B WHERE CHANNEL_PARTNER='Y' "
+"AND A.SITE_CODE=B.SITE_CODE UNION ALL "
+"SELECT SUPP_CODE FROM SUPPLIER C WHERE A.SITE_CODE=C.SITE_CODE AND "
+"CHANNEL_PARTNER='Y') AND vouch_created<>'Y' "
+"AND NVL(ret_opt,'X')<>'R' ORDER BY SITE_CODE ";
pstmt=conn.prepareStatement(queryString);
pstmt.setTimestamp(1,tranDateFromNew);
//pstmt.setTimestamp(2,sysDate);
rs=pstmt.executeQuery();
while(rs.next())
{
//siteCode=rs.getString("SITE_CODE");
tranidRcp = rs.getString("tran_id");
double countQC=0,countQCclose=0;
pstmt3=conn.prepareStatement(" select count(*) from qc_order where porcp_no = '"+tranidRcp+"' "
+ " ");
rs3=pstmt3.executeQuery();
if(rs3.next())
{
countQC=rs3.getDouble(1);
}
rs3.close();
rs3=null;
pstmt3=conn.prepareStatement(" select count(*) from qc_order where porcp_no = '"+tranidRcp+"' "
+ " and status = 'C' ");
rs3=pstmt3.executeQuery();
if(rs3.next())
{
countQCclose=rs3.getDouble(1);
}
rs3.close();
rs3=null;
if(countQCclose<countQC)
{
continue;
}
if(countQC>0)
{
qtyPassed=0;
qtyRejected=0;
qtyReturned=0;
qtyReceived=0;
pstmt1=conn.prepareStatement("select sum((case when qty_passed is null"
+ " then 0 else qty_passed end ) +"
+ " (case when qty_sample is null then 0 else qty_sample end )) qty_passed,"
+ " sum(case when qty_rejected is null then 0 else qty_rejected end ) qty_rejected "
+ " from qc_order where porcp_no = ? ");
pstmt1.setString(1,tranidRcp);
rs1=pstmt1.executeQuery();
if(rs1.next())
{
qtyPassed=rs1.getDouble(1);
qtyRejected=rs1.getDouble(2);
}
rs1.close();
pstmt1.close();
pstmt2=conn.prepareStatement("select sum(case when a.quantity__stduom is null then"
+ " 0 else a.quantity__stduom end ) from porcpdet a, porcp b "
+ " where a.tran_id = b.tran_id "
+ " and b.tran_ser = 'P-RET' "
+ " //and nvl(b.confirmed,'N') = 'Y' "
+ " and b.confirmed = 'Y' "
+ " and b.tran_id__ref = '"+tranidRcp+"'");
rs2=pstmt2.executeQuery();
if(rs2.next())
{
qtyReturned=rs2.getDouble(1);
}
rs2.close();
pstmt2.close();
pstmt2=conn.prepareStatement("select sum(case when a.quantity__stduom is null then 0 else a.quantity__stduom end)"
+ " from porcpdet a, porcp b "
+ " where a.tran_id = b.tran_id "
+ " and b.tran_id = '"+tranidRcp+"' "
+ " and b.confirmed = 'Y'");;
rs2=pstmt2.executeQuery();
if(rs2.next())
{
qtyReceived=rs2.getDouble(1);
}
rs2.close();
pstmt2.close();
if ((qtyReceived - qtyReturned) != qtyPassed )
{
continue;
}
}
CreatePoRcpVoucher createVouc = new CreatePoRcpVoucher();
retString = createVouc.createPoRcpVoucher(tranidRcp,xtraParams, conn);
fos1.write(("Status is:: [" + retString +"]\r\n").getBytes());
System.out.println("retString----"+retString);
/***********STR***********/
sql1 = "select tran_id from vouchrcp where prcp_id = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1,tranidRcp);
rs1 = pstmt1.executeQuery();
if ( rs1.next() )
{
voucherId = rs1.getString("tran_id");
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
strToWrite =strToWrite+ "TranID of Receipt : "+tranidRcp+" Voucher No : "+voucherId+"\r\n\r\n";
endDate = new java.util.Date(System.currentTimeMillis());
calendar.setTime(new java.sql.Timestamp(System.currentTimeMillis()));
strToWrite = strToWrite + "Return String : "+retString+"\r\n\r\n";
fos1.write(strToWrite.getBytes());
System.out.println("End Time for transaction"+endDateStr+"string to write"+strToWrite);
if( retString.indexOf("Success") != -1 )
{
conn.commit();
}
else
{
conn.rollback();
}
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}catch(Exception e)
{
if(conn!=null)
{
conn.rollback();
}
e.printStackTrace();
conn.rollback();
}
finally
{
if(conn!=null)
{
conn.commit();
conn.close();
conn=null;
pstmt.close();
pstmt=null;
}
try
{
if(fos1!=null)
{
fos1.close();
fos1=null;
}
}
catch(Exception e)
{
System.out.println( "Exception"+e.getMessage());
}
}
return "";
}
@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;
}
private String intializingLog(String fileName)
{
String log="intializingLog_Failed";
String currTime = null;
try{
SimpleDateFormat sdf1 = new SimpleDateFormat(e12GenericUtility.getDBDateFormat());
try
{
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)+".log";
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();
}
}
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