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
......@@ -15,7 +15,7 @@ import java.util.*;
import java.util.HashMap;
import javax.naming.InitialContext;
import org.w3c.dom.*;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.sys.UtilMethods;
......@@ -1737,15 +1737,51 @@ public class CreatePoRcpVoucher
{
return errString;
}
/**
* Vishakha Dhoble 02-Nov-15 (F15GSUN009)
* */
masterStatefulLocal = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
String retString = masterStatefulLocal.processRequest( authencate, siteCode, true, xmlBuff.toString());
ValidatorEJB validatorEJB = new ValidatorEJB();
userId = validatorEJB.getValueFromXTRA_PARAMS(xtraParams, "loginCode");
// siteCode = validatorEJB.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
DBAccessLocal dbAccess = (DBAccessLocal) ctx.lookup("ibase/DBAccessEJB/local");
String[] userInfoArray = dbAccess.getEmpInfo(userId, siteCode);
System.out.println("^^^^^^^ UserInfo ..> " + Arrays.toString(userInfoArray));
UserInfoBean userInfoBean = new UserInfoBean();
userInfoBean.setLoginCode(userId);
userInfoBean.setEmpCode(userInfoArray[0]);
userInfoBean.setEmpName(userInfoArray[1]);
userInfoBean.setReportTo(userInfoArray[2]);
userInfoBean.setDeptCode(userInfoArray[3]);
userInfoBean.setDeptDescr(userInfoArray[4]);
userInfoBean.setSiteCode(siteCode);
userInfoBean.setSiteDescr(userInfoArray[6]);
userInfoBean.setUserLevel(userInfoArray[7]);
userInfoBean.setUserType(userInfoArray[8]);
userInfoBean.setEntityCode(userInfoArray[9]);
userInfoBean.setProfileId(userInfoArray[10]);
userInfoBean.setItemSer(userInfoArray[11]);
userInfoBean.setEmailIdOff(userInfoArray[12]);
userInfoBean.setLoggerType(userInfoArray[13]);
userInfoBean.setStanCode(userInfoArray[14]);
userInfoBean.setDesignation(userInfoArray[15]);
userInfoBean.setDateJoin(userInfoArray[16]);
userInfoBean.setDivision(userInfoArray[17]);
userInfoBean.setUserLanguage(userInfoArray[18]);
userInfoBean.setUserCountry(userInfoArray[19]);
//masterStatefulLocal = (MasterStatefulLocal) ctx.lookup("ibase/MasterStatefulEJB/local");
//String retString = masterStatefulLocal.processRequest(userInfoBean, xmlString, true, conn);
String retString =saveData(userInfoBean,siteCode, xmlBuff.toString(), conn);
/**
* Vishakha Dhoble 02-Nov-15 (F15GSUN009)
* */
System.out.println("retString.:: "+retString);
// String tranIdVoucher = retString.substring( retString.indexOf("<TranID>")+8, retString.indexOf("</TranID>"));
// System.out.println("tranIdVoucher is :"+tranIdVoucher);
if( retString.indexOf("Success") != -1 )
{
errString = retString;
/**
* VALLABH KADAM [07/JUL/15]
* */
......@@ -2345,5 +2381,35 @@ public class CreatePoRcpVoucher
}
return errCode;
}
private String saveData(UserInfoBean userInfoBean,String siteCode, String xmlString, Connection conn) throws ITMException
{
System.out.println("saving data...........");
InitialContext ctx = null;
String retString = null;
MasterStatefulLocal masterStateful = null; // for ejb3
try
{
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 + "]");
retString=masterStateful.processRequest(userInfoBean,xmlString,true,conn);
//retString = masterStateful.processRequest(authencate, siteCode, true, 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;
}
}
\ No newline at end of file
/********************
* 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