Commit 8722fbb6 authored by sshinde's avatar sshinde

Modify ProductionVsBudget Report For Showing Graph CountryWise


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@97443 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1f26aff2
...@@ -2,15 +2,12 @@ ...@@ -2,15 +2,12 @@
* *
*/ */
package ibase.dashboard.mfg.bean; package ibase.dashboard.mfg.bean;
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;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.List;
import javax.naming.InitialContext; import javax.naming.InitialContext;
...@@ -93,14 +90,12 @@ public class ProductionVsBudgetReportBean ...@@ -93,14 +90,12 @@ public class ProductionVsBudgetReportBean
public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID,HashMap<String,List<String>> chartNameMap,HashMap<String, String> cntryIdNDescrMap) throws RemoteException, ITMException
{ {
String resultString="false"; String resultString="false";
try try
{ {
resultString= budgetReportRemote.generatePDF(hashMap,exportPDFPath,exportImagePath,preyearMonth,rptTitle,userID,chartNameMap,cntryIdNDescrMap);
resultString= budgetReportRemote.generatePDF(hashMap,exportPDFPath,exportImagePath,preyearMonth,rptTitle,userID);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -111,9 +106,6 @@ public class ProductionVsBudgetReportBean ...@@ -111,9 +106,6 @@ public class ProductionVsBudgetReportBean
return resultString; return resultString;
} }
public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException
{ {
boolean isRoleExists=false; boolean isRoleExists=false;
...@@ -127,10 +119,7 @@ public class ProductionVsBudgetReportBean ...@@ -127,10 +119,7 @@ public class ProductionVsBudgetReportBean
System.out.println("ibase.dashboard.mfg.bean :ProductionVsBudgetReportBean "+e.getMessage()); System.out.println("ibase.dashboard.mfg.bean :ProductionVsBudgetReportBean "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
return isRoleExists; return isRoleExists;
} }
} }
package ibase.dashboard.mfg.bean; package ibase.dashboard.mfg.bean;
import ibase.scheduler.utility.interfaces.Schedule; import ibase.scheduler.utility.interfaces.Schedule;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants; import ibase.utility.CommonConstants;
......
package ibase.dashboard.mfg.ejb; package ibase.dashboard.mfg.ejb;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.utility.EMail; import ibase.utility.EMail;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
...@@ -67,10 +68,9 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -67,10 +68,9 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
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 = "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);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
xmlDataForGeo = new StringBuffer("<?xml version=\"1.0\"?><Root>"); xmlDataForGeo = new StringBuffer("<?xml version='1.0' encoding='ISO-8859-1'?><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>");
...@@ -86,7 +86,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -86,7 +86,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
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' encoding='ISO-8859-1'?><Root>");
while (rs.next()) while (rs.next())
{ {
xmlDataForUnit.append("<Detail>"); xmlDataForUnit.append("<Detail>");
...@@ -95,7 +95,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -95,7 +95,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
xmlDataForUnit.append("</Detail>"); xmlDataForUnit.append("</Detail>");
} }
xmlDataForUnit.append("</Root>"); xmlDataForUnit.append("</Root>");
System.out.println("unitForm Drop Down List==" + xmlDataForUnit);
pstmt.close(); pstmt.close();
rs.close(); rs.close();
pstmt = null; pstmt = null;
...@@ -161,7 +160,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -161,7 +160,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
String unit = ""; String unit = "";
String previousUnit = ""; String previousUnit = "";
String geoLocationPrevious = ""; String geoLocationPrevious = "";
int count = 0;
double dailyBudgetQty = 0; double dailyBudgetQty = 0;
String geol_Descr = ""; String geol_Descr = "";
String unit_Descr = ""; String unit_Descr = "";
...@@ -169,18 +168,39 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -169,18 +168,39 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
String month = ""; String month = "";
String[] tempfrmDate = null; String[] tempfrmDate = null;
String[] temptoDate = null; String[] temptoDate = null;
ArrayList<String> countryList = new ArrayList<String>();
ArrayList<String> countryDescrList = new ArrayList<String>();
int firstDayOfMonth = 0; int firstDayOfMonth = 0;
int lastDayOfMonth = 0; int lastDayOfMonth = 0;
listDate = new ArrayList<String>(); listDate = new ArrayList<String>();
xmlData = new StringBuffer("<?xml version='1.0' encoding='ISO-8859-1'?><Root>");
xmlData.append("<Detail>");
String country = "";
String varValue = "";
int count = 0;
String geoLocationArr[] = null;
String varValueArr[] = null;
StringBuffer prsntGeoLocForCntry = null;
int cntFrBudget = 0;
String curCumQty = "";
String missingDate = "";
String pyrCumqty = "0.0";
int dayCount = 0;
String descr="";
try try
{ {
countryList.add("DWH_GEOLOC_IND");
countryList.add("DWH_GEOLOC_US");
countryList.add("DWH_GEOLOC_ROW");
countryDescrList.add("INDIA");
countryDescrList.add("UNITED STATES");
countryDescrList.add("ROW");
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
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];
...@@ -188,33 +208,77 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -188,33 +208,77 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
// 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);
for (int i = firstDayOfMonth; i <= lastDayOfMonth; i++) for (int i = firstDayOfMonth; i <= lastDayOfMonth; i++)
{ {
listDate.add(String.valueOf(i)); listDate.add(String.valueOf(i));
} }
// 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);
// geoLoc = "'105','110','117','145','120','129','130'";
geoLocationArr = geoLoc.replace("'", "").split(",");
//////****Added new code by sachin on 06-02-15***\\\\\\\\\\
for (int countryCnt = 0; countryCnt < countryList.size(); countryCnt++)
{
count = 0;
country = countryList.get(countryCnt);
descr="";
sql = "select trim(var_value) as var_value, descr from disparm where var_name = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, country);
// End of setter statement
rs = pstmt.executeQuery();
if (rs.next())
{
varValue = checkNull(rs.getString("var_value"));
//descr=checkNull(rs.getString("descr"));
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
descr=countryDescrList.get(countryCnt);
//varValue = "110,105,200";
varValueArr = varValue.split(",");
prsntGeoLocForCntry = new StringBuffer();
for (int i = 0; i < geoLocationArr.length; i++)
{
for (int j = 0; j < varValueArr.length; j++)
{
if (geoLocationArr[i].equalsIgnoreCase(varValueArr[j]))
{
if (prsntGeoLocForCntry.length() != 0)
{
prsntGeoLocForCntry.append(",'" + varValueArr[j] + "'");
} else
{
prsntGeoLocForCntry.append("'" + varValueArr[j] + "'");
}
}
}
}
geoLoc = prsntGeoLocForCntry.toString();
if(geoLoc!=null && geoLoc.trim().length() > 0)
{
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','GRANULES') 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','GRANULES') 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>"); cntFrBudget = 0;
xmlData.append("<Detail>"); curCumQty = "";
int cntFrBudget = 0; missingDate = "";
String curCumQty = ""; pyrCumqty = "0.0";
String missingDate = ""; dayCount = 0;
String pyrCumqty = "0.0";
int dayCount = 0;
xmlData.append("<country_code id=\"" + country + "\" descr=\"" + descr + "\">");
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"));
...@@ -311,7 +375,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -311,7 +375,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
// Add descr // Add descr
geol_Descr = ""; geol_Descr = "";
unit_Descr = ""; unit_Descr = "";
} }
dailyBudgetQty = rs.getDouble("cum_budqty"); dailyBudgetQty = rs.getDouble("cum_budqty");
...@@ -368,8 +431,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -368,8 +431,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
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++;
} }
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if (count > 0) if (count > 0)
{ {
...@@ -379,7 +445,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -379,7 +445,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
for (int p = dayCount; p < lastDayOfMonth; p++) for (int p = dayCount; p < lastDayOfMonth; p++)
{ {
cntFrBudget++; cntFrBudget++;
// 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";
...@@ -415,14 +480,13 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -415,14 +480,13 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
xmlData.append("</unit_form>"); xmlData.append("</unit_form>");
xmlData.append("</geo_loc>"); xmlData.append("</geo_loc>");
} }
xmlData.append("</country_code>");
}
}
xmlData.append("</Detail>"); xmlData.append("</Detail>");
xmlData.append("</Root>"); xmlData.append("</Root>");
pstmt.close();
pstmt = null;
rs.close();
rs = null;
} catch (Exception e) } catch (Exception e)
{ {
...@@ -454,6 +518,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -454,6 +518,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
throw new ITMException(d); throw new ITMException(d);
} }
} }
System.out.println("xmlData.toString() is" + xmlData.toString());
return xmlData.toString(); return xmlData.toString();
} }
...@@ -485,7 +551,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -485,7 +551,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
return input; return input;
} }
// start method for roule validation // start method for roule validation
public boolean getRoleValid(String userId, String roleCode) throws RemoteException, ITMException public boolean getRoleValid(String userId, String roleCode) throws RemoteException, ITMException
{ {
boolean flag = false; boolean flag = false;
...@@ -533,12 +599,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -533,12 +599,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
return flag; return flag;
} }
//end Role validation //end Role validation
//start method for PDF generate //start method for PDF generate
public String generatePDF(HashMap<String, List<String>> hashMap, String exportPDFPath, String exportImagePath, String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException public String generatePDF(HashMap<String, List<String>> hashMap, String exportPDFPath, String exportImagePath, String preyearMonth, String rptTitle, String userID, HashMap<String, List<String>> chartNameMap,HashMap<String, String> cntryIdNDescrMap) throws RemoteException, ITMException
{ {
// System.out.print("Country list in generate pdf="+countryList );
System.out.print("hashMap is=" + hashMap);
System.out.print("chartNameMap is =" + chartNameMap);
@SuppressWarnings("unused") @SuppressWarnings("unused")
PdfWriter writer = null; PdfWriter writer = null;
OutputStream file = null; OutputStream file = null;
...@@ -547,89 +615,123 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -547,89 +615,123 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
ArrayList<String> mailInfo=null; ArrayList<String> mailInfo = null;
String imageName = null; String imageName = null;
List<String> gridDataList = null; List<String> gridDataList = null;
Image image = null; Image image = null;
File attachFile = null; File attachFile = null;
String imgFilePath =null; String imgFilePath = null;
File existImgFile =null; File existImgFile = null;
String pdfFileName =null; String pdfFileName = null;
String toMailId =""; String toMailId = "";
String ccMailId =""; String ccMailId = "";
String bccAddress =""; String bccAddress = "";
String subject =""; String subject = "";
String userWiseBodytext=""; String userWiseBodytext = "";
String resultFlage ="false"; String resultFlage = "false";
System.out.print("Call for PDF created"); int keyListSize = 0;
int mod = 0;
int devide = 0;
int prntTblNo = 0;
int parentCnt = 0;
int childTblCnt = 0;
PdfPTable parentTable = null;
int imageCounter = 0;
String country = "";
SimpleDateFormat simpleDateFormat = null;
Calendar calendar = null;
String currDate = "";
Paragraph preface = null;
Paragraph countryTitle = null;
List<String> countyWiseDataList = new ArrayList<String>();
System.out.print("Calling for PDF created step1");
try try
{ {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy"); simpleDateFormat = new SimpleDateFormat("dd-MMM-yy");
Calendar calendar = Calendar.getInstance(); calendar = Calendar.getInstance();
String currDate = simpleDateFormat.format(calendar.getTime()); currDate = simpleDateFormat.format(calendar.getTime());
System.out.println("Current date is="+currDate);
document = new Document(); document = new Document();
pdfFileName = exportPDFPath+"ActualVsPlan-"+userID+"-"+currDate+".pdf"; pdfFileName = exportPDFPath + rptTitle + "-" + userID + ".pdf";
System.out.println("modify PDF file name " + pdfFileName + " current date formate===" + currDate);
file = new FileOutputStream(new File(pdfFileName)); file = new FileOutputStream(new File(pdfFileName));
writer = PdfWriter.getInstance(document, file); writer = PdfWriter.getInstance(document, file);
document.open(); document.open();
Paragraph preface = new Paragraph(); preface = new Paragraph();
preface.setAlignment(Element.ALIGN_CENTER); preface.setAlignment(Element.ALIGN_CENTER);
preface.add(new Paragraph(rptTitle, FontFactory.getFont(FontFactory.TIMES_ROMAN, 15))); preface.add(new Paragraph(rptTitle, FontFactory.getFont(FontFactory.TIMES_ROMAN, 15)));
preface.add(new Paragraph(" ")); preface.add(new Paragraph(" "));
document.add(preface); document.add(preface);
System.out.println(" size of HashMap is="+hashMap.size());
ArrayList<String> keyList=new ArrayList<String>(); //ArrayList<List<String>> valueList = new ArrayList<List<String>>();
ArrayList<List<String>> valueList=new ArrayList<List<String>>();
for (Map.Entry<String, List<String>> entry : hashMap.entrySet()) for (Map.Entry<String, List<String>> entry : chartNameMap.entrySet())
{ {
keyList.add(entry.getKey()); country = entry.getKey();
valueList.add(entry.getValue()); String countryDescr=cntryIdNDescrMap.get(country);
} countryTitle = new Paragraph();
int keyListSize =keyList.size(); countryTitle.setAlignment(Element.ALIGN_CENTER);
int mod =keyListSize%3; // countryTitle.add(new Paragraph(countryDescr, FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
int devide =keyListSize/3; countryTitle.add(new Paragraph(countryDescr, FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
int prntTblNo =mod+devide; countryTitle.add(new Paragraph(" "));
int parentCnt=0; //PdfPTable countryLblTbl = new PdfPTable(1);
int childTblCnt=0; //countryLblTbl.addCell(countryTitle);
PdfPTable parentTable=null;
int imageCounter=0; document.add(countryTitle);
System.out.println(" countryDescr is = " + countryDescr);
countyWiseDataList = entry.getValue();
//keyList.add(entry.getKey());
//countyWiseDataList.add(hashMap.get(entry.getKey()));
for(int size=1;size<=prntTblNo;size++) keyListSize = countyWiseDataList.size();
System.out.println(" keyListSize is = " + keyListSize);
mod = keyListSize % 3;
devide = keyListSize / 3;
prntTblNo = mod + devide;
parentCnt = 0;
childTblCnt = 0;
imageCounter = 0;
System.out.println("prntTblNo is = " + prntTblNo);
for (int size = 1; size <= prntTblNo; size++)
{ {
parentCnt++; parentCnt++;
parentTable = new PdfPTable(3); parentTable = new PdfPTable(3);
parentTable.setWidthPercentage(100); parentTable.setWidthPercentage(100);
/*parentTable = new PdfPTable(3);*/
PdfPTable childtable = null; PdfPTable childtable = null;
PdfPTable table = null; PdfPTable table = null;
PdfPCell cell = null; PdfPCell cell = null;
childTblCnt=0; childTblCnt = 0;
for(int i= 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
if(imageCounter < keyListSize) if (imageCounter < keyListSize)
{ {
childTblCnt++; childTblCnt++;
childtable = new PdfPTable(1); childtable = new PdfPTable(1);
childtable.setWidthPercentage(90); childtable.setWidthPercentage(90);
imageName = countyWiseDataList.get(imageCounter);
imageName =keyList.get(imageCounter); System.out.println("imageName is ==" + imageName);
gridDataList =valueList.get(imageCounter); gridDataList = hashMap.get(imageName);
//Add by Birendra Pandey //Add by Birendra Pandey
imageCounter++; imageCounter++;
imgFilePath = exportImagePath+imageName+userID+".png";
//imgFilePath = exportImagePath + imageName + userID + ".png";
imgFilePath = exportImagePath + imageName + ".png";
System.out.println("Image name with image path ==" + imageName + " imgFilePath==" + imgFilePath);
image = Image.getInstance(imgFilePath); image = Image.getInstance(imgFilePath);
System.out.println("Image name with image path =="+imageName+"imgFilePath=="+imgFilePath);
childtable.addCell(image); childtable.addCell(image);
//code for images deleted //code for images deleted
existImgFile= new File(imgFilePath); existImgFile = new File(imgFilePath);
if(existImgFile.exists()){ if (existImgFile.exists())
{
existImgFile.delete(); existImgFile.delete();
System.out.println("Image Deleted after status *******"+imgFilePath ); System.out.println("Image Deleted after status *******" + imgFilePath);
} }
image.scaleAbsolute(320f, 250f);// image width,height image.scaleAbsolute(320f, 250f);// image width,height
image.setAlignment(5); image.setAlignment(5);
...@@ -637,74 +739,73 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -637,74 +739,73 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
table = new PdfPTable(7); table = new PdfPTable(7);
table.setWidthPercentage(50); // Code 2 table.setWidthPercentage(50); // Code 2
table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setHorizontalAlignment(Element.ALIGN_CENTER);
Font font= FontFactory.getFont(FontFactory.TIMES_ROMAN, 5); Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 5);
cell = new PdfPCell(new Paragraph("Month",font)); cell = new PdfPCell(new Paragraph("Month", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph("Actual", font));
cell = new PdfPCell(new Paragraph("Actual",font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph("Work Plan",font)); cell = new PdfPCell(new Paragraph("Work Plan", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph("Actual/Work Plan",font)); cell = new PdfPCell(new Paragraph("Actual/Work Plan", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph("Pace(EOM)",font)); cell = new PdfPCell(new Paragraph("Pace(EOM)", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph("Pace(EOM)/Work Plan",font)); cell = new PdfPCell(new Paragraph("Pace(EOM)/Work Plan", font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(preyearMonth,font)); cell = new PdfPCell(new Paragraph(preyearMonth, font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.GREEN); cell.setBackgroundColor(Color.GREEN);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(0),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(0), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(1),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(1), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(2),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(2), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(3),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(3), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(4),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(4), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(5),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(5), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
cell = new PdfPCell(new Paragraph(gridDataList.get(6),font)); cell = new PdfPCell(new Paragraph(gridDataList.get(6), font));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(Color.YELLOW); cell.setBackgroundColor(Color.YELLOW);
table.addCell(cell); table.addCell(cell);
...@@ -715,40 +816,42 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -715,40 +816,42 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
parentTable.addCell(cell); parentTable.addCell(cell);
} }
} }
if(childTblCnt==1)
if (childTblCnt == 1)
{ {
cell = new PdfPCell(); cell = new PdfPCell();
cell.setBorder(Rectangle.NO_BORDER); cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell); parentTable.addCell(cell);
parentTable.addCell(cell); parentTable.addCell(cell);
} } else if (childTblCnt == 2)
else if(childTblCnt==2)
{ {
cell = new PdfPCell(); cell = new PdfPCell();
cell.setBorder(Rectangle.NO_BORDER); cell.setBorder(Rectangle.NO_BORDER);
parentTable.addCell(cell); parentTable.addCell(cell);
} }
document.add(parentTable); document.add(parentTable);
} }
document.newPage();
}
document.close(); document.close();
file.close(); file.close();
System.out.println("PDF Created succesfully"); System.out.println("PDF Created succesfully");
conn = connDriver.getConnectDB("DriverITM"); conn = connDriver.getConnectDB("DriverITM");
connDriver =null; connDriver = null;
toMailId =""; toMailId = "";
ccMailId =""; ccMailId = "";
bccAddress =""; bccAddress = "";
subject ="Daily Output:Actual Vs.Plan"; subject = rptTitle;
userWiseBodytext ="Dear Sir, Please find attached herewith is the Daily Output:Actual Vs.Plan Report in PDF format."; userWiseBodytext = "Dear Sir, Please find attached herewith is the Daily Output:" + rptTitle + " Report in PDF format.";
String sql = "select name,user_type,email_id FROM users WHERE code='"+userID+"'"; String sql = "select name,user_type,email_id FROM users WHERE code='" + userID + "'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
toMailId = checkNull(rs.getString("email_id")); toMailId = checkNull(rs.getString("email_id"));
System.out.println("No of Users ="+userID +"AND According to Email ID======="+toMailId); System.out.println("No of Users =" + userID + "AND According to Email ID=======" + toMailId);
} }
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
...@@ -758,11 +861,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -758,11 +861,11 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs = null; rs = null;
//toMailId ="sachin.shinde57@gmail.com"; //toMailId ="sachin.shinde57@gmail.com";
System.out.println("Export Pdf path is ="+pdfFileName); System.out.println("Export Pdf path is =" + pdfFileName);
attachFile = new File(pdfFileName); attachFile = new File(pdfFileName);
if(attachFile.exists() && attachFile.length()>0) if (attachFile.exists() && attachFile.length() > 0)
{ {
mailInfo =new ArrayList<String>(); mailInfo = new ArrayList<String>();
mailInfo.add(toMailId); mailInfo.add(toMailId);
mailInfo.add(ccMailId); mailInfo.add(ccMailId);
mailInfo.add(bccAddress); mailInfo.add(bccAddress);
...@@ -770,15 +873,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -770,15 +873,14 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
mailInfo.add(userWiseBodytext); mailInfo.add(userWiseBodytext);
mailInfo.add(attachFile.getPath()); mailInfo.add(attachFile.getPath());
this.sendingMail(mailInfo); this.sendingMail(mailInfo);
resultFlage="true"; resultFlage = "true";
} }
System.out.println("*********** Pdf and sending mail done succesfully (Final)**************"); System.out.println("*********** Pdf and sending mail done succesfully (Final)**************");
} catch (Exception e) } catch (Exception e)
{ {
System.out.println("Exception :ProductionVsBudgetReport :generatePDF(HashMap<String, List<String>>,String,String,String,String"+e.getMessage()); System.out.println("Exception :ProductionVsBudgetReport :generatePDF(HashMap<String, List<String>>,String,String,String,String" + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} } finally
finally
{ {
try try
{ {
...@@ -795,6 +897,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production ...@@ -795,6 +897,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
} }
return resultFlage; return resultFlage;
} }
//end method for PDF generate //end method for PDF generate
//start method for sending mail*************** //start method for sending mail***************
......
...@@ -15,6 +15,6 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{ ...@@ -15,6 +15,6 @@ public interface ProductionVsBudgetReportLocal extends ValidatorLocal{
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 boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException; public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID,HashMap<String,List<String>> chartNameMap,HashMap<String, String> cntryIdNDescrMap) throws RemoteException, ITMException;
} }
...@@ -16,6 +16,6 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote ...@@ -16,6 +16,6 @@ public interface ProductionVsBudgetReportRemote extends ValidatorRemote
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 boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException; public boolean getRoleValid(String userCode, String roleCode) throws RemoteException, ITMException;
public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID) throws RemoteException, ITMException; public String generatePDF(HashMap<String, List<String>> hashMap ,String exportPDFPath,String exportImagePath,String preyearMonth,String rptTitle,String userID,HashMap<String,List<String>> chartNameMap,HashMap<String, String> cntryIdNDescrMap) throws RemoteException, ITMException;
} }
package ibase.dashboard.mfg.bean; package ibase.dashboard.mfg.servlet;
import ibase.dashboard.mfg.bean.ProductionVsBudgetReportBean;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
...@@ -17,8 +18,6 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -17,8 +18,6 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
{ {
doPost( request, response ); doPost( request, response );
} }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{ {
ProductionVsBudgetReportBean bean=null; ProductionVsBudgetReportBean bean=null;
...@@ -27,14 +26,16 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -27,14 +26,16 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
String preyearMonth =""; String preyearMonth ="";
String rptTitle =""; String rptTitle ="";
String userID =""; String userID ="";
System.out.println(" ENTER - ProductionVsBudgetReportServlet ***********************"); System.out.println(" ENTER - ProductionVsBudgetReportServlet ***********************");
try try
{ {
bean = new ProductionVsBudgetReportBean(); bean = new ProductionVsBudgetReportBean();
HttpSession session= request.getSession(); HttpSession session= request.getSession();
HashMap <String, List<String>> gridDataMap = (HashMap<String, List<String>>) session.getAttribute("gridDataMap"); HashMap <String, List<String>> gridDataMap = (HashMap<String, List<String>>) session.getAttribute("gridDataMap");
HashMap <String, List<String>> cntryWiseChrtNameMap = (HashMap<String, List<String>>) session.getAttribute("cntryWiseChrtNameMap");
HashMap <String,String> cntryIdNDescrMap=(HashMap<String,String>) session.getAttribute("cntryIdNDescrMap");
userID =(String)request.getParameter("userID"); userID =(String)request.getParameter("userID");
exportPDFPath =(String)request.getParameter("exportPDFPath"); exportPDFPath =(String)request.getParameter("exportPDFPath");
exportImagePath =(String)request.getParameter("exportImagePath"); exportImagePath =(String)request.getParameter("exportImagePath");
...@@ -42,8 +43,7 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -42,8 +43,7 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
rptTitle =(String)request.getParameter("rptTitle"); rptTitle =(String)request.getParameter("rptTitle");
System.out.println("userID inside servlet====="+userID); System.out.println("userID inside servlet====="+userID);
//call EJB method for PDF creation******************* //call EJB method for PDF creation*******************
String resultString= bean.generatePDF(gridDataMap, exportPDFPath, exportImagePath, preyearMonth, rptTitle,userID,cntryWiseChrtNameMap,cntryIdNDescrMap);
String resultString= bean.generatePDF(gridDataMap, exportPDFPath, exportImagePath, preyearMonth, rptTitle,userID);
response.setContentType("text/html"); response.setContentType("text/html");
System.out.println("resultString is ="+resultString); System.out.println("resultString is ="+resultString);
if(resultString.equals("false")) if(resultString.equals("false"))
...@@ -55,6 +55,7 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -55,6 +55,7 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
response.getWriter().write("true"); response.getWriter().write("true");
} }
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("Exception :ProductionVsBudgetReportServlet : ProductionVsBudgetReportServlet) :"+e.getMessage()); //$NON-NLS-1$ System.out.println("Exception :ProductionVsBudgetReportServlet : ProductionVsBudgetReportServlet) :"+e.getMessage()); //$NON-NLS-1$
...@@ -73,8 +74,4 @@ public class ProductionVsBudgetReportServlet extends HttpServlet ...@@ -73,8 +74,4 @@ public class ProductionVsBudgetReportServlet extends HttpServlet
userID=""; userID="";
} }
} }
} }
\ No newline at end of file
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