Commit 7855d186 authored by bpandey's avatar bpandey

add new changes for pdf and scheduler component


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94120 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 09ca60e0
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package ibase.dashboard.mfg.bean; package ibase.dashboard.mfg.bean;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import ibase.dashboard.mfg.ejb.ProductionVsBudgetReportRemote; import ibase.dashboard.mfg.ejb.ProductionVsBudgetReportRemote;
import ibase.system.config.AppConnectParm; import ibase.system.config.AppConnectParm;
...@@ -29,6 +32,7 @@ public class ProductionVsBudgetReportBean ...@@ -29,6 +32,7 @@ public class ProductionVsBudgetReportBean
try try
{ {
InitialContext context=new InitialContext(appConnectParm.getProperty()); InitialContext context=new InitialContext(appConnectParm.getProperty());
budgetReportRemote=(ProductionVsBudgetReportRemote)context.lookup("ibase/ProductionVsBudgetReport/remote"); budgetReportRemote=(ProductionVsBudgetReportRemote)context.lookup("ibase/ProductionVsBudgetReport/remote");
} }
catch (Exception e) catch (Exception e)
...@@ -87,14 +91,16 @@ public class ProductionVsBudgetReportBean ...@@ -87,14 +91,16 @@ public class ProductionVsBudgetReportBean
return xmlDataString; return xmlDataString;
} }
//***************22/11/2013**************************
public String getPDFFormate() throws RemoteException, ITMException
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException
{ {
String strMessage="";
try try
{ {
strMessage = budgetReportRemote.getPDFFormate();
budgetReportRemote.generatePDF(hashMap,exportPDFPath,exportImagePath,preyearMonth,rptTitle,userID);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -102,8 +108,29 @@ public class ProductionVsBudgetReportBean ...@@ -102,8 +108,29 @@ public class ProductionVsBudgetReportBean
e.printStackTrace(); e.printStackTrace();
} }
return strMessage;
} }
public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException
{
boolean isRoleExists=false;
try
{
isRoleExists = budgetReportRemote.getRoleValid(userCode,roleCode);
}
catch (Exception e)
{
System.out.println("ibase.dashboard.mfg.bean :ProductionVsBudgetReportBean "+e.getMessage());
e.printStackTrace();
}
return isRoleExists;
}
} }
package ibase.dashboard.mfg.bean;
import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.utility.ITMException;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ProductionVsBudgetReportSchedule implements Schedule
{
public String schedule(HashMap map) throws Exception
{
System.out.println(schedule((String) map.get("PROCESS_NAME")));
return schedule((String) map.get("PROCESS_NAME"));
}
public String schedule(String schedule) throws Exception
{
System.out.println("inside ProductionVsBudgetReportSchedule.........");
this.runSchedule();
return schedule;
}
public String schedulePriority(String arg0) throws Exception
{
return null;
}
private void runSchedule() throws ITMException
{
// Add new code on dated 10/01/2013
String sql = "";
ResultSet rs = null;
Connection conn = null;
PreparedStatement pstmt = null;
ConnDriver connDriver = new ConnDriver();
String userID = "";
String uri = "";
String finalURI = "";
List<String> sendFinalURIList = null;
try
{
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
sendFinalURIList = new ArrayList<String>();
sql = " select user_id,uri from dashboard_comp where uri like '%ProductionVsBudgetReportExport.jsp%'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
userID = checkNull(rs.getString("user_id"));
uri = checkNull(rs.getString("uri"));
// finalURI = CommonConstants.TOMCAT_HOME + uri + "&userID ="+userID;
finalURI = CommonConstants.TOMCAT_HOME + uri;
System.out.println("finalURI is =" + finalURI);
sendFinalURIList.add(finalURI);
System.out.println("User id is =" + userID);
}
pstmt.close();
rs.close();
pstmt = null;
rs = null;
for (String resourcePath : sendFinalURIList)
{
if (Desktop.isDesktopSupported())
{
Desktop desktop = Desktop.getDesktop();
try
{
desktop.browse(new URI(resourcePath));
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
{
Runtime runtime = Runtime.getRuntime();
try
{
runtime.exec("xdg-open " + resourcePath);
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// String resourcePath = CommonConstants.TOMCAT_HOME + File.separator + "ibase" +File.separator + "dashboard" + File.separator + "mfg" +File.separator+"JSP"+File.separator+"ExportExample"+File.separator +"ProductionVsBudgetReport_export.jsp";
System.out.println("ProductionVsBudgetReportSchedule path =[" + resourcePath + "]");
}// end forloop
}// end try block
catch (Exception e)
{
e.printStackTrace();
} finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception e)
{
e.printStackTrace();
System.out.println("error inside when scheduler invoke ProductionVsBudgetExport.jsp " + e.getMessage());
}
}
}
// This method call for check null
private String checkNull(String input)
{
if (input == null)
{
input = "";
} else
{
input = input.trim();
}
return input;
}
}
package ibase.dashboard.mfg.bean;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@SuppressWarnings("serial")
public class ProductionVsBudgetReportServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost( request, response );
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
ProductionVsBudgetReportBean bean=null;
String exportPDFPath ="";
String exportImagePath ="";
String preyearMonth ="";
String rptTitle ="";
String userID ="";
System.out.println(" ENTER - ProductionVsBudgetReportServlet ***********************");
try
{
bean = new ProductionVsBudgetReportBean();
HttpSession session= request.getSession();
HashMap <String, List<String>> gridDataMap = (HashMap<String, List<String>>) session.getAttribute("gridDataMap");
userID =(String)request.getParameter("userID");
exportPDFPath =(String)request.getParameter("exportPDFPath");
exportImagePath =(String)request.getParameter("exportImagePath");
preyearMonth =(String)request.getParameter("preyearMonth");
rptTitle =(String)request.getParameter("rptTitle");
System.out.println("userID====="+userID);
//System.out.println("exportPDFPath====="+exportPDFPath);
//System.out.println("exportImagePath====="+exportImagePath);
//System.out.println("preyearMonth====="+preyearMonth);
//System.out.println("rptTitle====="+rptTitle);
//call EJB method for PDF creation*******************
bean.generatePDF(gridDataMap, exportPDFPath, exportImagePath, preyearMonth, rptTitle,userID);
response.setContentType("text/html");
response.getWriter().write("PDF Creation");
}
catch (Exception e)
{
System.out.println("Exception :ProductionVsBudgetReportServlet : ProductionVsBudgetReportServlet) :"+e.getMessage()); //$NON-NLS-1$
try
{
throw new ITMException(e);
}
catch (ITMException e1)
{
e1.printStackTrace();
}
}
finally
{
}
}
}
\ No newline at end of file
...@@ -3,8 +3,13 @@ package ibase.dashboard.mfg.ejb; ...@@ -3,8 +3,13 @@ package ibase.dashboard.mfg.ejb;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import ibase.utility.EMail;
import java.awt.Color;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -12,9 +17,15 @@ import java.sql.ResultSet; ...@@ -12,9 +17,15 @@ import java.sql.ResultSet;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.processing.FilerException;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
/** /**
* Session Bean implementation class ProductionVsBudgetReport * Session Bean implementation class ProductionVsBudgetReport
*/ */
...@@ -24,7 +35,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -24,7 +35,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
/** /**
* Default constructor. * Default constructor.
*/ */
List<String> listDate =null; List<String> listDate = null;
StringBuffer xmlDataForGeo = null; StringBuffer xmlDataForGeo = null;
StringBuffer xmlDataForUnit = null; StringBuffer xmlDataForUnit = null;
...@@ -37,97 +48,93 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -37,97 +48,93 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
String firstDateofMonth=""; String firstDateofMonth = "";
String lstDateofMonth=""; String lstDateofMonth = "";
Calendar cal=null; Calendar cal = null;
SimpleDateFormat sdf=null; SimpleDateFormat sdf = null;
try try
{ {
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
connDriver = null; connDriver = null;
/* sql="select to_char ( trunc(sysdate,'Month') + rownum - 1,'DD') as tran_date from item where rownum <= last_day (sysdate) - trunc(sysdate,'Month') + 1 order by 1 "; /*
* sql="select to_char ( trunc(sysdate,'Month') + rownum - 1,'DD') as tran_date from item where rownum <= last_day (sysdate) - trunc(sysdate,'Month') + 1 order by 1 "
pstmt = conn.prepareStatement(sql); * ;
rs = pstmt.executeQuery(); *
* pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery();
while(rs.next()) *
{ * while(rs.next()) { listDate.add(rs.getString(1)); }
listDate.add(rs.getString(1)); * pstmt.close(); rs.close(); pstmt = null; rs = null;
} *
pstmt.close(); * /** Code for get first n last date of month date 17/10/13
rs.close(); */
pstmt = null;
rs = null;
/**
Code for get first n last date of month date 17/10/13 */
cal = Calendar.getInstance(); cal = Calendar.getInstance();
sdf=new SimpleDateFormat("dd-MMM-yy"); sdf = new SimpleDateFormat("dd-MMM-yy");
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
lstDateofMonth=sdf.format(cal.getTime()); lstDateofMonth = sdf.format(cal.getTime());
cal = Calendar.getInstance(); cal = Calendar.getInstance();
//cal.add(cal.MONTH,-1); // cal.add(cal.MONTH,-1);
cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DATE)); cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DATE));
firstDateofMonth= sdf.format(cal.getTime()); firstDateofMonth = sdf.format(cal.getTime());
// This will generated geoLocation droup down changes on dated
// 28/11/2013
// sql(V.1)
// ="select fld_value, descr from gencodes where FLD_NAME ='GEO_LOC' and mod_name='X' ";
// sql(v.2)
// ="select fld_value, descr from gencodes where fld_name = 'GEO_LOC' and mod_name = 'X' and fld_value in (select distinct geo_loc from site where site_code in (select distinct site_code from dwh_production_day_events where tran_date between ? and ? and ref_ser ='W-RCP'))";
//This will generated geoLocation droup down changes on dated 28/11/2013 sql = "select g.fld_value, g.descr from gencodes g where fld_name = 'GEO_LOC' and mod_name = 'X' and instr((select trim(var_value) from disparm where var_name = 'DWH_SITE_GEO_LOC'),trim(g.fld_value)) >0";
//sql(V.1) ="select fld_value, descr from gencodes where FLD_NAME ='GEO_LOC' and mod_name='X' ";
//sql(v.2) ="select fld_value, descr from gencodes where fld_name = 'GEO_LOC' and mod_name = 'X' and fld_value in (select distinct geo_loc from site where site_code in (select distinct site_code from dwh_production_day_events where tran_date between ? and ? and ref_ser ='W-RCP'))";
sql="select g.fld_value, g.descr from gencodes g where fld_name = 'GEO_LOC' and mod_name = 'X' and instr((select trim(var_value) from disparm where var_name = 'DWH_SITE_GEO_LOC'),trim(g.fld_value)) >0";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
//pstmt.setString(1, firstDateofMonth);
//pstmt.setString(2, lstDateofMonth);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
xmlDataForGeo = new StringBuffer("<?xml version=\"1.0\"?><Root>"); xmlDataForGeo = new StringBuffer("<?xml version=\"1.0\"?><Root>");
while(rs.next()) while (rs.next())
{ {
xmlDataForGeo.append("<Detail>"); xmlDataForGeo.append("<Detail>");
xmlDataForGeo.append("<fld_value>").append("<![CDATA[" + checkNull(rs.getString("fld_value"))+"]]>").append("</fld_value>"); xmlDataForGeo.append("<fld_value>").append("<![CDATA[" + checkNull(rs.getString("fld_value")) + "]]>").append("</fld_value>");
xmlDataForGeo.append("<descr>").append("<![CDATA[" + checkNull(rs.getString("descr"))+"]]>").append("</descr>"); xmlDataForGeo.append("<descr>").append("<![CDATA[" + checkNull(rs.getString("descr")) + "]]>").append("</descr>");
xmlDataForGeo.append("</Detail>"); xmlDataForGeo.append("</Detail>");
} }
xmlDataForGeo.append("</Root>"); xmlDataForGeo.append("</Root>");
System.out.println("Geo Location Drop Down List=="+xmlDataForGeo); System.out.println("Geo Location Drop Down List==" + xmlDataForGeo);
pstmt.close(); pstmt.close();
rs.close(); rs.close();
pstmt = null; pstmt = null;
rs = null; rs = null;
//End of geoLoaction with unit_form // End of geoLoaction with unit_form
//coding for gererate unit form drop down // coding for gererate unit form drop down
//sql ="select distinct(unit__form) from item_type where unit__form is not null"; // sql
// ="select distinct(unit__form) from item_type where unit__form is not null";
sql="select distinct (i.unit__form),u.descr from item_type i ,uom u where i.unit__form=u.unit and i.unit__form is not null"; sql = "select distinct (i.unit__form),u.descr from item_type i ,uom u where i.unit__form=u.unit and i.unit__form is not null";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
xmlDataForUnit = new StringBuffer("<?xml version=\"1.0\"?><Root>"); xmlDataForUnit = new StringBuffer("<?xml version=\"1.0\"?><Root>");
while(rs.next()) while (rs.next())
{ {
xmlDataForUnit.append("<Detail>"); xmlDataForUnit.append("<Detail>");
xmlDataForUnit.append("<unit_form>").append("<![CDATA[" + checkNull(rs.getString("unit__form"))+"]]>").append("</unit_form>"); xmlDataForUnit.append("<unit_form>").append("<![CDATA[" + checkNull(rs.getString("unit__form")) + "]]>").append("</unit_form>");
xmlDataForUnit.append("<descr>").append("<![CDATA[" + checkNull(rs.getString("descr"))+"]]>").append("</descr>"); xmlDataForUnit.append("<descr>").append("<![CDATA[" + checkNull(rs.getString("descr")) + "]]>").append("</descr>");
xmlDataForUnit.append("</Detail>"); xmlDataForUnit.append("</Detail>");
} }
xmlDataForUnit.append("</Root>"); xmlDataForUnit.append("</Root>");
System.out.println("unitForm Drop Down List=="+xmlDataForUnit); System.out.println("unitForm Drop Down List==" + xmlDataForUnit);
pstmt.close(); pstmt.close();
rs.close(); rs.close();
pstmt = null; pstmt = null;
rs = null; rs = null;
// End of unit for drop down
//End of unit for drop down } catch (Exception e)
}
catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
throw new ITMException(e); throw new ITMException(e);
...@@ -146,14 +153,12 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -146,14 +153,12 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs = null; rs = null;
} }
if (pstmt != null) if (pstmt != null)
{ {
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
} catch (Exception d) } catch (Exception d)
{ {
d.printStackTrace(); d.printStackTrace();
...@@ -162,7 +167,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -162,7 +167,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} }
} }
// This method will be return xml data for geoLoaction List // This method will be return xml data for geoLoaction List
public String getGeoLoCodeXmlData() public String getGeoLoCodeXmlData()
{ {
return xmlDataForGeo.toString(); return xmlDataForGeo.toString();
...@@ -173,35 +178,31 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -173,35 +178,31 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
return xmlDataForUnit.toString(); return xmlDataForUnit.toString();
} }
// Start main method which are performed to all chart
public String getProductionBudget(String frmDate, String toDate, String geoLoc, String unitForm) throws RemoteException, ITMException
//This is main method which are performed to all chart
public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException
{ {
String sql = ""; String sql = "";
ResultSet rs = null,rs1=null; ResultSet rs = null, rs1 = null;
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null,pstmt1; PreparedStatement pstmt = null, pstmt1;
ConnDriver connDriver = new ConnDriver(); ConnDriver connDriver = new ConnDriver();
StringBuffer xmlData = null; StringBuffer xmlData = null;
String geoLocation=""; String geoLocation = "";
String unit=""; String unit = "";
String previousUnit=""; String previousUnit = "";
String geoLocationPrevious=""; String geoLocationPrevious = "";
int count=0; int count = 0;
double dailyBudgetQty=0; double dailyBudgetQty = 0;
String geol_Descr=""; String geol_Descr = "";
String unit_Descr=""; String unit_Descr = "";
int year=0; int year = 0;
String month=""; String month = "";
String[] tempfrmDate =null; String[] tempfrmDate = null;
String[] temptoDate =null; String[] temptoDate = null;
int firstDayOfMonth=0; int firstDayOfMonth = 0;
int lastDayOfMonth=0; int lastDayOfMonth = 0;
listDate = new ArrayList<String>(); listDate = new ArrayList<String>();
try try
...@@ -209,16 +210,16 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -209,16 +210,16 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
connDriver = null; connDriver = null;
// change on date 11/11/2013 // change on date 11/11/2013
//case1 // case1
System.out.println("from date from jsp ="+frmDate + "To Date from jsp=="+toDate); System.out.println("from date from jsp =" + frmDate + "To Date from jsp==" + toDate);
tempfrmDate =frmDate.split("-"); tempfrmDate = frmDate.split("-");
firstDayOfMonth =Integer.parseInt(tempfrmDate[0]); firstDayOfMonth = Integer.parseInt(tempfrmDate[0]);
month =tempfrmDate[1]; month = tempfrmDate[1];
year =Integer.parseInt(tempfrmDate[2]); year = Integer.parseInt(tempfrmDate[2]);
//case2 // case2
temptoDate =toDate.split("-"); temptoDate = toDate.split("-");
lastDayOfMonth =Integer.parseInt(temptoDate[0]); lastDayOfMonth = Integer.parseInt(temptoDate[0]);
System.out.println("First of Month=="+firstDayOfMonth +"& Last of Month==="+lastDayOfMonth+"Month from jsp =="+month+"Year from jsp =="+year); System.out.println("First of Month==" + firstDayOfMonth + "& Last of Month===" + lastDayOfMonth + "Month from jsp ==" + month + "Year from jsp ==" + year);
for (int i = firstDayOfMonth; i <= lastDayOfMonth; i++) for (int i = firstDayOfMonth; i <= lastDayOfMonth; i++)
{ {
...@@ -226,102 +227,67 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -226,102 +227,67 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} }
//end of changes // end of changes
System.out.println("select Final initGeoLocation inside in EJB ==="+geoLoc +"selected initUnitForm inside in java =="+unitForm +"length of List ===="+listDate.size()+"AND Value of ==="+listDate); System.out.println("select Final initGeoLocation inside in EJB ===" + geoLoc + "selected initUnitForm inside in java ==" + unitForm + "length of List ====" + listDate.size() + "AND Value of ===" + listDate);
/*sql (v.1) = "select geo_loc, unit__form,to_char (tran_date,'DD') as tran_date, day_quantity, pyr_cumqty,cum_budqty "+
"from ("+
"select s.GEO_LOC,p.tran_date, t.unit__form, "+
"fn_get_budgetqty(p.tran_date,s.GEO_LOC,t.unit__form ) as cum_budqty ,"+
"sum(fn_qty_form(p.item_code,p.unit,t.unit__form, p.quantity)) as "+
"day_quantity, fn_get_pyr_cumqty( "+
"to_date(add_months(p.tran_date,-12)),s.geo_loc,t.unit__form ) as pyr_cumqty "+
"from dwh_production_day_events p, item i, item_type t, site s "+
"where p.site_code = s.site_code "+
"and p.item_code = i.item_code "+
"and i.item_type = t.item_type "+
"and p.tran_date >= ? "+
"and p.tran_date <= ? "+
"and p.ref_type like 'P%' "+
"and p.ref_ser = 'W-RCP' "+
"group by s.GEO_LOC, p.tran_date, t.unit__form ) order by geo_loc, unit__form,tran_date ";
*/
sql="select geo_loc, unit__form,to_char (tran_date,'DD') as tran_date, day_quantity, pyr_cumqty, " +
"cum_budqty , sum(day_quantity) over (partition by geo_loc, unit__form order by tran_date) " +
"as cur_cumqty from ( select s.GEO_LOC,p.tran_date, t.unit__form, " +
"sum(fn_qty_form(p.item_code,p.unit,t.unit__form,i.phy_attrib_6, p.quantity)) " +
"as day_quantity, fn_get_pyr_cumqty( to_date(add_months(p.tran_date,-12)),s.geo_loc,t.unit__form ) " +
"as pyr_cumqty, fn_get_budgetqty(p.tran_date,s.GEO_LOC,t.unit__form ) " +
"as cum_budqty from dwh_production_day_events p, item i, item_type t, " +
"site s where p.site_code = s.site_code and p.item_code = i.item_code " +
"and i.item_type = t.item_type and p.tran_date >= ? " +
"and p.tran_date <= ? " +
"and p.ref_type = (case when t.item_type in('AMPOULES','BOTTLES','DROPS','INHALER','POWDER','POUCH','SUSPENSION','TUBE','VIALS') then 'F' when t.item_type in('CAPSULES','TABLETS',' SOFTGELCAP') then 'F' else '' end ) " +
"and p.ref_ser = 'W-RCP' and s.geo_loc in(" + geoLoc +") "+
"and t.unit__form in("+unitForm +") group by s.GEO_LOC, p.tran_date, t.unit__form ) " +
"order by geo_loc, unit__form,tran_date";
sql = "select geo_loc, unit__form,to_char (tran_date,'DD') as tran_date, day_quantity, pyr_cumqty, " + "cum_budqty , sum(day_quantity) over (partition by geo_loc, unit__form order by tran_date) " + "as cur_cumqty from ( select s.GEO_LOC,p.tran_date, t.unit__form, " + "sum(fn_qty_form(p.item_code,p.unit,t.unit__form,i.phy_attrib_6, p.quantity)) " + "as day_quantity, fn_get_pyr_cumqty( to_date(add_months(p.tran_date,-12)),s.geo_loc,t.unit__form ) " + "as pyr_cumqty, fn_get_budgetqty(p.tran_date,s.GEO_LOC,t.unit__form ) " + "as cum_budqty from dwh_production_day_events p, item i, item_type t, " + "site s where p.site_code = s.site_code and p.item_code = i.item_code " + "and i.item_type = t.item_type and p.tran_date >= ? " + "and p.tran_date <= ? " + "and p.ref_type = (case when t.item_type in('AMPOULES','BOTTLES','DROPS','INHALER','POWDER','POUCH','SUSPENSION','TUBE','VIALS') then 'F' when t.item_type in('CAPSULES','TABLETS',' SOFTGELCAP') then 'F' else '' end ) " + "and p.ref_ser = 'W-RCP' and s.geo_loc in(" + geoLoc + ") " + "and t.unit__form in(" + unitForm + ") group by s.GEO_LOC, p.tran_date, t.unit__form ) " + "order by geo_loc, unit__form,tran_date";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1,frmDate); pstmt.setString(1, frmDate);
pstmt.setString(2,toDate); pstmt.setString(2, toDate);
//End of setter statement // End of setter statement
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
xmlData = new StringBuffer("<?xml version=\"1.0\"?><Root>"); xmlData = new StringBuffer("<?xml version=\"1.0\"?><Root>");
xmlData.append("<Detail>"); xmlData.append("<Detail>");
int cntFrBudget=0; int cntFrBudget = 0;
String curCumQty=""; String curCumQty = "";
String missingDate=""; String missingDate = "";
String pyrCumqty="0.0"; String pyrCumqty = "0.0";
int dayCount=0; int dayCount = 0;
while(rs.next()) while (rs.next())
{ {
count++; count++;
geoLocation =checkNull(rs.getString("geo_loc")); geoLocation = checkNull(rs.getString("geo_loc"));
unit =checkNull(rs.getString("unit__form")); unit = checkNull(rs.getString("unit__form"));
if(count > 1 && ((!previousUnit.equals(unit)) || (!geoLocationPrevious.equals(geoLocation))) ) if (count > 1 && ((!previousUnit.equals(unit)) || (!geoLocationPrevious.equals(geoLocation))))
{ {
if(dayCount<=lastDayOfMonth) if (dayCount <= lastDayOfMonth)
{ {
int cntr =dayCount; int cntr = dayCount;
for(int j=0;j<lastDayOfMonth-cntr;j++) for (int j = 0; j < lastDayOfMonth - cntr; j++)
{ {
cntFrBudget++; cntFrBudget++;
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">"); xmlData.append("<tran_date date=\"" + (listDate.get(dayCount)) + "\">");
xmlData.append("<day_quantity quantity=\"0\">"); xmlData.append("<day_quantity quantity=\"0\">");
//Add new Block for preyear Cumulative // Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual "; // sql="select to_date(add_months(?,-12)) from dual ";
missingDate =listDate.get(dayCount)+"-"+month+"-"+year; missingDate = listDate.get(dayCount) + "-" + month + "-" + year;
sql ="select fn_get_pyr_cumqty( to_date(add_months('"+missingDate+"',-12)),"+geoLocationPrevious+",'"+previousUnit +"') as pyr_cumqty from dual"; sql = "select fn_get_pyr_cumqty( to_date(add_months('" + missingDate + "',-12))," + geoLocationPrevious + ",'" + previousUnit + "') as pyr_cumqty from dual";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if(rs1.next()) if (rs1.next())
{ {
if(rs1.getDouble("pyr_cumqty")!=0) if (rs1.getDouble("pyr_cumqty") != 0)
{ {
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ; pyrCumqty = checkNull(rs1.getString("pyr_cumqty"));
System.out.println("preyrcumulative ==="+pyrCumqty); System.out.println("preyrcumulative ===" + pyrCumqty);
System.out.println("preyrcumulative for missing date:"+missingDate+"===geoloc:"+geoLocationPrevious+":previousUnit:"+previousUnit); System.out.println("preyrcumulative for missing date:" + missingDate + "===geoloc:" + geoLocationPrevious + ":previousUnit:" + previousUnit);
} }
} }
pstmt1.close(); pstmt1.close();
rs1.close(); rs1.close();
pstmt1 = null; pstmt1 = null;
rs1 = null; rs1 = null;
//End of preyearCumulative // End of preyearCumulative
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>"); xmlData.append("<pyr_cumqty>").append("<![CDATA[" + pyrCumqty + "]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>"); xmlData.append("<cum_budqty>").append("<![CDATA[" + dailyBudgetQty * (cntFrBudget) + "]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>"); xmlData.append("<cur_cumqty>").append("<![CDATA[" + curCumQty + "]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>"); xmlData.append("</day_quantity>");
xmlData.append("</tran_date>"); xmlData.append("</tran_date>");
dayCount++; dayCount++;
...@@ -331,33 +297,33 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -331,33 +297,33 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
xmlData.append("</unit_form>"); xmlData.append("</unit_form>");
xmlData.append("</geo_loc>"); xmlData.append("</geo_loc>");
//dayCount=0; // dayCount=0;
} }
if((count==1) || (!previousUnit.equals(unit)) ||( !geoLocationPrevious.equals(geoLocation)) ) if ((count == 1) || (!previousUnit.equals(unit)) || (!geoLocationPrevious.equals(geoLocation)))
{ {
//Add here for decr pupose // Add here for decr pupose
sql="select descr from gencodes where FLD_NAME='GEO_LOC' and fld_value= ?"; sql = "select descr from gencodes where FLD_NAME='GEO_LOC' and fld_value= ?";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,geoLocation); pstmt1.setString(1, geoLocation);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if(rs1.next()) if (rs1.next())
{ {
geol_Descr = checkNull(rs1.getString("descr")) ; geol_Descr = checkNull(rs1.getString("descr"));
} }
pstmt1 = null; pstmt1 = null;
rs1 = null; rs1 = null;
//************************************************** // **************************************************
sql="select descr from uom where unit= ?"; sql = "select descr from uom where unit= ?";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1,unit); pstmt1.setString(1, unit);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if(rs1.next()) if (rs1.next())
{ {
unit_Descr = checkNull(rs1.getString("descr")) ; unit_Descr = checkNull(rs1.getString("descr"));
} }
pstmt1.close(); pstmt1.close();
...@@ -365,44 +331,43 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -365,44 +331,43 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs1.close(); rs1.close();
rs1 = null; rs1 = null;
//End here decr pupose for Unit_form and geo_location // End here decr pupose for Unit_form and geo_location
cntFrBudget=0; cntFrBudget = 0;
xmlData.append("<geo_loc location=\""+geoLocation+"\" glocdescr =\""+geol_Descr+"\" >"); xmlData.append("<geo_loc location=\"" + geoLocation + "\" glocdescr =\"" + geol_Descr + "\" >");
xmlData.append("<unit_form unit=\""+checkNull(rs.getString("unit__form"))+"\" unitdescr =\""+unit_Descr+"\">"); xmlData.append("<unit_form unit=\"" + checkNull(rs.getString("unit__form")) + "\" unitdescr =\"" + unit_Descr + "\">");
dayCount=0; dayCount = 0;
curCumQty="0.0"; curCumQty = "0.0";
pyrCumqty="0.0"; pyrCumqty = "0.0";
geoLocationPrevious =geoLocation=checkNull(rs.getString("geo_loc")); geoLocationPrevious = geoLocation = checkNull(rs.getString("geo_loc"));
previousUnit =checkNull(rs.getString("unit__form")); previousUnit = checkNull(rs.getString("unit__form"));
//Add descr // Add descr
geol_Descr=""; geol_Descr = "";
unit_Descr=""; unit_Descr = "";
} }
dailyBudgetQty = rs.getDouble("cum_budqty");
dailyBudgetQty =rs.getDouble("cum_budqty");
cntFrBudget++; cntFrBudget++;
if(!listDate.get(dayCount).equals(rs.getString("tran_date"))) if (!listDate.get(dayCount).equals(rs.getString("tran_date")))
{ {
int cnt= dayCount; int cnt = dayCount;
for(int i=0;i<Integer.parseInt(rs.getString("tran_date"))-(cnt+1);i++) for (int i = 0; i < Integer.parseInt(rs.getString("tran_date")) - (cnt + 1); i++)
{ {
//Add new Block for preyear Cumulative // Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual "; // sql="select to_date(add_months(?,-12)) from dual ";
missingDate=listDate.get(dayCount)+"-"+month+"-"+year; missingDate = listDate.get(dayCount) + "-" + month + "-" + year;
sql="select fn_get_pyr_cumqty( to_date(add_months('"+missingDate+"',-12)),"+geoLocation+",'"+unit +"') as pyr_cumqty from dual"; sql = "select fn_get_pyr_cumqty( to_date(add_months('" + missingDate + "',-12))," + geoLocation + ",'" + unit + "') as pyr_cumqty from dual";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if(rs1.next()) if (rs1.next())
{ {
//Modify by birendra Pandey // Modify by birendra Pandey
if(rs1.getDouble("pyr_cumqty")!=0) if (rs1.getDouble("pyr_cumqty") != 0)
{ {
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ; pyrCumqty = checkNull(rs1.getString("pyr_cumqty"));
System.out.println("preyrcumulative ==="+pyrCumqty); System.out.println("preyrcumulative ===" + pyrCumqty);
} }
} }
...@@ -410,57 +375,55 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -410,57 +375,55 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs1.close(); rs1.close();
pstmt1 = null; pstmt1 = null;
rs1 = null; rs1 = null;
//End of preyearCumulative // End of preyearCumulative
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">"); xmlData.append("<tran_date date=\"" + (listDate.get(dayCount)) + "\">");
xmlData.append("<day_quantity quantity=\"0\">"); xmlData.append("<day_quantity quantity=\"0\">");
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>"); xmlData.append("<pyr_cumqty>").append("<![CDATA[" + pyrCumqty + "]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>"); xmlData.append("<cum_budqty>").append("<![CDATA[" + dailyBudgetQty * (cntFrBudget) + "]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>"); xmlData.append("<cur_cumqty>").append("<![CDATA[" + curCumQty + "]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>"); xmlData.append("</day_quantity>");
xmlData.append("</tran_date>"); xmlData.append("</tran_date>");
dayCount++; dayCount++;
cntFrBudget++; cntFrBudget++;
} }
} }
xmlData.append("<tran_date date=\""+checkNull(rs.getString("tran_date"))+"\">"); xmlData.append("<tran_date date=\"" + checkNull(rs.getString("tran_date")) + "\">");
xmlData.append("<day_quantity quantity=\""+checkNull(rs.getString("day_quantity"))+"\">"); xmlData.append("<day_quantity quantity=\"" + checkNull(rs.getString("day_quantity")) + "\">");
xmlData.append("<pyr_cumqty>").append("<![CDATA[" + checkNull(rs.getString("pyr_cumqty"))+"]]>").append("</pyr_cumqty>"); xmlData.append("<pyr_cumqty>").append("<![CDATA[" + checkNull(rs.getString("pyr_cumqty")) + "]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA[" + dailyBudgetQty*(cntFrBudget) +"]]>").append("</cum_budqty>"); xmlData.append("<cum_budqty>").append("<![CDATA[" + dailyBudgetQty * (cntFrBudget) + "]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA[" + checkNull(rs.getString("cur_cumqty"))+"]]>").append("</cur_cumqty>"); xmlData.append("<cur_cumqty>").append("<![CDATA[" + checkNull(rs.getString("cur_cumqty")) + "]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>"); xmlData.append("</day_quantity>");
xmlData.append("</tran_date>"); xmlData.append("</tran_date>");
curCumQty = checkEmpty(checkNull(rs.getString("cur_cumqty"))); curCumQty = checkEmpty(checkNull(rs.getString("cur_cumqty")));
pyrCumqty =checkEmpty(checkNull(rs.getString("pyr_cumqty"))); pyrCumqty = checkEmpty(checkNull(rs.getString("pyr_cumqty")));
dayCount++; dayCount++;
} }
if(count>0) if (count > 0)
{ {
if(dayCount<lastDayOfMonth) if (dayCount < lastDayOfMonth)
{ {
for(int p=dayCount;p<lastDayOfMonth;p++) for (int p = dayCount; p < lastDayOfMonth; p++)
{ {
cntFrBudget++; cntFrBudget++;
//Add new Block for preyear Cumulative // Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual "; // sql="select to_date(add_months(?,-12)) from dual ";
missingDate=listDate.get(dayCount)+"-"+month+"-"+year; missingDate = listDate.get(dayCount) + "-" + month + "-" + year;
sql="select fn_get_pyr_cumqty( to_date(add_months('"+missingDate+"',-12)),"+geoLocation+",'"+unit +"') as pyr_cumqty from dual"; sql = "select fn_get_pyr_cumqty( to_date(add_months('" + missingDate + "',-12))," + geoLocation + ",'" + unit + "') as pyr_cumqty from dual";
pstmt1 = conn.prepareStatement(sql); pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery(); rs1 = pstmt1.executeQuery();
if(rs1.next()) if (rs1.next())
{ {
if(rs1.getDouble("pyr_cumqty")!=0) if (rs1.getDouble("pyr_cumqty") != 0)
{ {
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ; pyrCumqty = checkNull(rs1.getString("pyr_cumqty"));
System.out.println("pyrCumqty As New ==="+pyrCumqty); System.out.println("pyrCumqty As New ===" + pyrCumqty);
} }
...@@ -469,13 +432,13 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -469,13 +432,13 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs1.close(); rs1.close();
pstmt1 = null; pstmt1 = null;
rs1 = null; rs1 = null;
//End of preyearCumulative // End of preyearCumulative
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">"); xmlData.append("<tran_date date=\"" + (listDate.get(dayCount)) + "\">");
xmlData.append("<day_quantity quantity=\"0\">"); xmlData.append("<day_quantity quantity=\"0\">");
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>"); xmlData.append("<pyr_cumqty>").append("<![CDATA[" + pyrCumqty + "]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>"); xmlData.append("<cum_budqty>").append("<![CDATA[" + dailyBudgetQty * (cntFrBudget) + "]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>"); xmlData.append("<cur_cumqty>").append("<![CDATA[" + curCumQty + "]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>"); xmlData.append("</day_quantity>");
xmlData.append("</tran_date>"); xmlData.append("</tran_date>");
dayCount++; dayCount++;
...@@ -486,7 +449,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -486,7 +449,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
xmlData.append("</geo_loc>"); xmlData.append("</geo_loc>");
} }
xmlData.append("</Detail>"); xmlData.append("</Detail>");
xmlData.append("</Root>"); xmlData.append("</Root>");
...@@ -499,7 +461,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -499,7 +461,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
{ {
e.printStackTrace(); e.printStackTrace();
System.out.println("ibase.dashboard.mfg.ejb :ProductionVsBudgetReport"+e); System.out.println("ibase.dashboard.mfg.ejb :ProductionVsBudgetReport" + e);
throw new ITMException(e); throw new ITMException(e);
} finally } finally
{ {
...@@ -521,13 +483,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -521,13 +483,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} catch (Exception d) } catch (Exception d)
{ {
d.printStackTrace(); d.printStackTrace();
System.out.println("ibase.dashboard.mfg.ejb :ProductionVsBudgetReport"+d); System.out.println("ibase.dashboard.mfg.ejb :ProductionVsBudgetReport" + d);
throw new ITMException(d); throw new ITMException(d);
} }
} }
return xmlData.toString(); return xmlData.toString();
} }
// End main method which are performed to all chart
private String checkNull(String input) private String checkNull(String input)
{ {
...@@ -555,48 +518,352 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -555,48 +518,352 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
return input; return input;
} }
// start method for roule validation
public boolean getRoleValid(String userId, String roleCode) throws RemoteException, ITMException
{
boolean flag = false;
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
//Add PDF Creater method on dated 22/11/2013 conn = connDriver.getConnectDB("DriverITM");
public String getPDFFormate () throws RemoteException, ITMException connDriver = null;
String sql = " SELECT * FROM WF_ROLE_USERS WHERE userid='" + userId + "' AND role_code='" + roleCode + "' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{ {
flag = true;
}
pstmt.close();
pstmt = null;
conn.close();
conn = null;
rs.close();
rs = null;
} catch (Exception e)
{
flag = false;
System.out.println("Is Execute allow 1: "); } finally
System.out.println("Is Write allow 1: "); {
try { try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
} catch (Exception e)
{
flag = false;
File file = new File("/home/base/Desktop/test.sh");
if(file.exists()){
System.out.println("File path========= : " + file);
System.out.println("Is Execute allow : " + file.canExecute());
System.out.println("Is Write allow : " + file.canWrite());
System.out.println("Is Read allow : " + file.canRead());
} }
}
return flag;
}
//end Role validation
//start method for PDF generate
public void generatePDF(HashMap<String, List<String>> hashMap, String exportPDFPath, String exportImagePath, String preyearMonth, String rptTitle,String userID) throws RemoteException, ITMException
{
@SuppressWarnings("unused")
PdfWriter writer = null;
OutputStream file = null;
Document document = null;
ConnDriver connDriver = new ConnDriver();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<String> mailInfo=null;
String imageName = null;
List<String> gridDataList = null;
Image image = null;
File attachFile = null;
String imgFilePath =null;
File existImgFile =null;
int seconds =0;
String pdfFileName =null;
System.out.print("Call for PDF created");
try
{
document = new Document();
seconds = (int) (System.currentTimeMillis() / 1000) % 60 ;
pdfFileName = exportPDFPath+"ProductionVsBudget-"+userID+"-"+seconds+".pdf";
file = new FileOutputStream(new File(pdfFileName));
writer = PdfWriter.getInstance(document, file);
document.open();
Paragraph preface = new Paragraph();
preface.setAlignment(Element.ALIGN_CENTER);
preface.add(new Paragraph(rptTitle, FontFactory.getFont(FontFactory.TIMES_ROMAN, 15)));
preface.add(new Paragraph(" "));
document.add(preface);
file.setExecutable(true); ArrayList<String> keyList=new ArrayList<String>();
file.setWritable(true); ArrayList<List<String>> valueList=new ArrayList<List<String>>();
file.setReadable(true);
System.out.println("Is Execute allow : " + file.canExecute());
System.out.println("Is Write allow : " + file.canWrite());
System.out.println("Is Read allow : " + file.canRead());
if (file.createNewFile()){ for (Map.Entry<String, List<String>> entry : hashMap.entrySet())
System.out.println("File is created!"); {
}else{ keyList.add(entry.getKey());
System.out.println("File already exists."); valueList.add(entry.getValue());
} }
Runtime.getRuntime().exec("/home/base/Desktop/test.sh"); int keyListSize=keyList.size();
} catch (IOException e) { int mod= keyListSize%3;
e.printStackTrace(); int devide=keyListSize/3;
int prntTblNo=mod+devide;
int parentCnt=0;
int childTblCnt=0;
PdfPTable parentTable=null;
int imageCounter=0;
for(int size=1;size<=prntTblNo;size++)
{
parentCnt++;
parentTable = new PdfPTable(3);
parentTable.setWidthPercentage(100);
/*parentTable = new PdfPTable(3);*/
PdfPTable childtable = null;
PdfPTable table = null;
PdfPCell cell = null;
childTblCnt=0;
for(int i= 0; i < 3; i++)
{
if(imageCounter < keyListSize)
{
childTblCnt++;
childtable = new PdfPTable(1);
childtable.setWidthPercentage(90);
imageName=keyList.get(imageCounter);
gridDataList=valueList.get(imageCounter);
imageCounter++;
imgFilePath = exportImagePath+imageName+userID+".png";
image = Image.getInstance(imgFilePath);
System.out.println("Image Present before status=="+imgFilePath);
childtable.addCell(image);
//code for images deleted
existImgFile= new File(imgFilePath);
if(existImgFile.exists()){
existImgFile.delete();
System.out.println("Image Deleted after status *******"+imgFilePath );
}
image.scaleAbsolute(320f, 250f);// image width,height
image.setAlignment(5);
table = new PdfPTable(7);
table.setWidthPercentage(50); // Code 2
table.setHorizontalAlignment(Element.ALIGN_CENTER);
Font font= FontFactory.getFont(FontFactory.TIMES_ROMAN, 5);
cell = new PdfPCell(new Paragraph("Month",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Actual",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("LBE",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Actual/LBE",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Pace(EOM)",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Pace(EOM)/LBE",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(preyearMonth,font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(0),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(1),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(2),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(3),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(4),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(5),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(6),font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell);
childtable.addCell(table);
cell = new PdfPCell(childtable);
cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell);
}
}
if(childTblCnt==1)
{
cell = new PdfPCell();
cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell);
parentTable.addCell(cell);
}
else if(childTblCnt==2)
{
cell = new PdfPCell();
cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell);
}
document.add(parentTable);
}
document.close();
file.close();
System.out.println("PDF Created succesfully");
System.out.println("System goes to connected database table:users");
conn = connDriver.getConnectDB("DriverITM");
connDriver =null;
String toMailId ="";
String ccMailId ="";
String bccAddress ="";
String subject ="Regarding:ProductionVsBudgetReport as PDF ";
String userWiseBodytext = "Plase find attachment of Production Vs BudgetReport PDF";
String sql = "select name,user_type,email_id FROM users WHERE code='"+userID+"'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
toMailId = checkNull(rs.getString("email_id"));
System.out.println("EMAIL ID from table :users=="+toMailId);
} }
pstmt.close();
pstmt = null;
conn.close();
conn = null;
rs.close();
rs = null;
//toMailId ="sachin.shinde57@gmail.com";
System.out.println("Export Pdf path is ="+pdfFileName);
attachFile = new File(pdfFileName);
if(attachFile.exists())
{
mailInfo =new ArrayList<String>();
mailInfo.add(toMailId);
mailInfo.add(ccMailId);
mailInfo.add(bccAddress);
mailInfo.add(subject);
mailInfo.add(userWiseBodytext);
mailInfo.add(attachFile.getPath());
this.sendingMail(mailInfo);
}
System.out.println("All Activity have been completed(PDF,Mail Sending) :Thanks you");
return "Scussefullly";
} catch (Exception e)
{
System.out.println("Exception :ProductionVsBudgetReport :generatePDF(HashMap<String, List<String>>,String,String,String,String"+e.getMessage());
e.printStackTrace();
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
} catch (Exception e)
{
e.printStackTrace();
} }
}
}
//end method for PDF generate
//End of method on dated 22/11/2013 //start method for sending mail***************
public void sendingMail(ArrayList<String> mailInfo)
{
StringBuffer commInfo = new StringBuffer();
commInfo.append("<ROOT>");
commInfo.append("<MAILINFO>");
commInfo.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
commInfo.append("<TO_ADD>").append("<![CDATA[" + mailInfo.get(0) + "]]>").append("</TO_ADD>");
commInfo.append("<CC_ADD>").append("<![CDATA[" + mailInfo.get(1) + "]]>").append("</CC_ADD>");
commInfo.append("<BCC_ADD>").append("<![CDATA[" + mailInfo.get(2) + "]]>").append("</BCC_ADD>");
commInfo.append("<SUBJECT>").append("<![CDATA[" + mailInfo.get(3) + "]]>").append("</SUBJECT>");
commInfo.append("<BODY_TEXT>").append("<![CDATA[" + mailInfo.get(4) + "]]>").append("</BODY_TEXT>");
commInfo.append("<XML_DATA_FILE_PATH>").append("<![CDATA[" + mailInfo.get(5) + "]]>").append("</XML_DATA_FILE_PATH>");
commInfo.append("</MAILINFO>");
commInfo.append("</ROOT>");
EMail email = new EMail();
try
{
System.out.println(" calling sendMail method()");
email.sendMail(commInfo.toString(), "ITM", null);
System.out.println(" Email send succesfully ***********");
} catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception :ProductionVsBudgetReport :sendMail(String ,String)" + e.getMessage());
}
email = null;
}
//End method for sending mail*******
} }
\ No newline at end of file
...@@ -3,6 +3,8 @@ import ibase.webitm.ejb.ValidatorLocal; ...@@ -3,6 +3,8 @@ import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.List;
import javax.ejb.Local; import javax.ejb.Local;
...@@ -12,6 +14,7 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{ ...@@ -12,6 +14,7 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{
public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException; public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException;
public String getGeoLoCodeXmlData() throws RemoteException, ITMException; public String getGeoLoCodeXmlData() throws RemoteException, ITMException;
public String getUnitFormXmlData() throws RemoteException, ITMException; public String getUnitFormXmlData() throws RemoteException, ITMException;
public String getPDFFormate () throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException;
} }
...@@ -3,6 +3,8 @@ import ibase.webitm.ejb.ValidatorRemote; ...@@ -3,6 +3,8 @@ import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.List;
import javax.ejb.Remote; import javax.ejb.Remote;
...@@ -13,6 +15,7 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote ...@@ -13,6 +15,7 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote
public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException; public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException;
public String getGeoLoCodeXmlData() throws RemoteException, ITMException; public String getGeoLoCodeXmlData() throws RemoteException, ITMException;
public String getUnitFormXmlData() throws RemoteException, ITMException; public String getUnitFormXmlData() throws RemoteException, ITMException;
public String getPDFFormate () throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public void generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException;
} }
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