Commit 478eb3ef authored by bpandey's avatar bpandey

added new method in main and local


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93749 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 8a1575e9
......@@ -25,9 +25,17 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
* Default constructor.
*/
List<String> listDate =null;
StringBuffer xmlDataForGeo = null;
StringBuffer xmlDataForUnit = null;
String initGeoLocation ="";
String initUnitForm ="";
public ProductionVsBudgetReport() throws RemoteException, ITMException
{
// TODO Auto-generated constructor stub
// TODO Auto-generated constructor stub
String sql = "";
ResultSet rs = null;
......@@ -35,6 +43,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
PreparedStatement pstmt = null;
ConnDriver connDriver = new ConnDriver();
listDate = new ArrayList<String>();
try
{
conn = connDriver.getConnectDB("DriverITM");
......@@ -48,6 +57,61 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
{
listDate.add(rs.getString(1));
}
pstmt.close();
rs.close();
pstmt = null;
rs = null;
//coding for generate geoLocation combo box with unit_form
sql ="select fld_value, descr from gencodes where FLD_NAME='GEO_LOC' and mod_name='X' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
xmlDataForGeo = new StringBuffer("<?xml version=\"1.0\"?><Root>");
int count=1;
while(rs.next())
{
if(count==1){
initGeoLocation =checkNull(rs.getString("fld_value"));
}
xmlDataForGeo.append("<Detail>");
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("</Detail>");
count++;
}
xmlDataForGeo.append("</Root>");
System.out.println("Geo Location Drop Down List=="+xmlDataForGeo);
pstmt.close();
rs.close();
pstmt = null;
rs = null;
//End of geoLoaction with unit_form
//coding for gererate unit form drop down
sql ="select distinct(unit__form) from item_type where unit__form is not null";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
xmlDataForUnit = new StringBuffer("<?xml version=\"1.0\"?><Root>");
int count2=1;
while(rs.next())
{
if(count2==1){
initUnitForm =checkNull(rs.getString("unit__form"));
}
xmlDataForUnit.append("<Detail>");
xmlDataForUnit.append("<unit_form>").append("<![CDATA[" + checkNull(rs.getString("unit__form"))+"]]>").append("</unit_form>");
xmlDataForUnit.append("</Detail>");
count2++;
}
xmlDataForUnit.append("</Root>");
System.out.println("unitForm Drop Down List=="+xmlDataForUnit);
pstmt.close();
rs.close();
pstmt = null;
rs = null;
//End of unit for drop down
}
catch (Exception e)
......@@ -60,16 +124,23 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
{
if (conn != null)
{
conn.close();
conn = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
......@@ -78,8 +149,21 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
}
}
// This method will be return xml data for geoLoaction List
public String getGeoLoCodeXmlData()
{
return xmlDataForGeo.toString();
}
public String getUnitFormXmlData()
{
return xmlDataForUnit.toString();
}
//This is main method which are performed to all chart
public String getProductionBudget(String frmDate,String toDate) throws RemoteException, ITMException
public String getProductionBudget(String frmDate,String toDate,String geoLoc,String unitForm) throws RemoteException, ITMException
{
String sql = "";
ResultSet rs = null,rs1=null;
......@@ -97,6 +181,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
double dailyBudgetQty=0;
String geol_Descr="";
String unit_Descr="";
int year=0;
String month="";
try
{
conn = connDriver.getConnectDB("DriverITM");
......@@ -104,16 +190,27 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
todaysDay =Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
lastDayOfMonth = Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
year =calendar.get(Calendar.YEAR);
month = new SimpleDateFormat("MMM").format(calendar.getTime());
// change on item changes of GeoLocation code
if((geoLoc!=null && geoLoc.trim().length()>0)&& (unitForm!=null && unitForm.trim().length()>0)){
initGeoLocation =geoLoc;
initUnitForm =unitForm;
System.out.println("select geoLoc inside in java ==="+geoLoc +"selected unitForm inside in java =="+unitForm);
/*sql = "select geo_loc, unit__form,to_char (tran_date,'DD') as tran_date, day_quantity, pyr_cumqty,daily_budqty "+
}
/*sql = "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 daily_budqty ,"+
"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 "+
......@@ -130,55 +227,80 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
sql="select geo_loc, unit__form,to_char (tran_date,'DD') as tran_date, day_quantity, pyr_cumqty, " +
"daily_budqty , sum(day_quantity) over (partition by geo_loc, unit__form order by tran_date) " +
"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, 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 daily_budqty from dwh_production_day_events p, item i, item_type t, " +
"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 like 'P%' " +
"and p.ref_ser = 'W-RCP' group by s.GEO_LOC, p.tran_date, t.unit__form ) " +
"and p.tran_date <= ? " +
"and p.ref_type = (case when t.item_type in('AMPOULES','BOTTLES','DROPS','GRANULES','INHALER','POWDER','POUCH','PELLETS','SUSPENSION','SYRINGE','TUBE','VIALS') then 'P' when t.item_type in('CAPSULES','TABLETS',' SOFTGELCAP') then 'F' else '' end ) " +
"and p.ref_ser = 'W-RCP' and s.geo_loc in(" + initGeoLocation +") "+
"and t.unit__form in("+initUnitForm +") group by s.GEO_LOC, p.tran_date, t.unit__form ) " +
"order by geo_loc, unit__form,tran_date";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,frmDate);
pstmt.setString(2,toDate);
//End of setter statement
rs = pstmt.executeQuery();
xmlData = new StringBuffer("<?xml version=\"1.0\"?><Root>");
xmlData.append("<Detail>");
int cntFrBudget=0;
String preCumQty="";
String prePyrDayQty="";
String curCumQty="";
String missingDate="";
String pyrCumqty="0.0";
int dayCount=0;
while (rs.next())
while(rs.next())
{
count++;
geoLocation =checkNull(rs.getString("geo_loc"));
unit =checkNull(rs.getString("unit__form"));
if(count > 1 && ((!previousUnit.equals(unit)) || (!geoLocationPrevious.equals(geoLocation))) )
{
//System.out.println("last dayCount outside:"+dayCount);
if(dayCount<=lastDayOfMonth)
{
int cntr =dayCount;
for(int j=0;j<lastDayOfMonth-cntr;j++)
{
cntFrBudget++;
//System.out.println("Budget Counter remaining last dated ===="+cntFrBudget);
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">");
//System.out.println("listDate.get(dayCount) case of after date ==="+listDate.get(dayCount));
xmlData.append("<day_quantity quantity=\"0\">");
xmlData.append("<pyr_dayqty>").append("<![CDATA["+prePyrDayQty+"]]>").append("</pyr_dayqty>");
xmlData.append("<daily_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</daily_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+preCumQty+"]]>").append("</cur_cumqty>");
//Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual ";
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";
pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
if(rs1.getDouble("pyr_cumqty")!=0)
{
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ;
System.out.println("preyrcumulative ==="+pyrCumqty);
System.out.println("preyrcumulative for missing date:"+missingDate+"===geoloc:"+geoLocationPrevious+":previousUnit:"+previousUnit);
}
}
pstmt1.close();
rs1.close();
pstmt1 = null;
rs1 = null;
//End of preyearCumulative
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>");
xmlData.append("</tran_date>");
dayCount++;
......@@ -195,9 +317,6 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
{
//Add here for decr pupose
//sql="select g.descr as geol_descr, u.descr as unit_descr from gencodes g , uom u where g.FLD_NAME='GEO_LOC' and g.fld_value= ? and u.unit= ?";
sql="select descr from gencodes where FLD_NAME='GEO_LOC' and fld_value= ?";
pstmt1 = conn.prepareStatement(sql);
......@@ -205,10 +324,7 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
geol_Descr = checkNull(rs1.getString("descr")) ;
}
pstmt1 = null;
rs1 = null;
......@@ -236,8 +352,8 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
xmlData.append("<geo_loc location=\""+geoLocation+"\" glocdescr =\""+geol_Descr+"\" >");
xmlData.append("<unit_form unit=\""+checkNull(rs.getString("unit__form"))+"\" unitdescr =\""+unit_Descr+"\">");
dayCount=0;
preCumQty="0.0";
prePyrDayQty="0.0";
curCumQty="0.0";
pyrCumqty="0.0";
geoLocationPrevious =geoLocation=checkNull(rs.getString("geo_loc"));
previousUnit =checkNull(rs.getString("unit__form"));
//Add descr
......@@ -247,59 +363,104 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
}
dailyBudgetQty =rs.getDouble("daily_budqty");
dailyBudgetQty =rs.getDouble("cum_budqty");
cntFrBudget++;
//System.out.println("Budget Counter===="+cntFrBudget);
if(!listDate.get(dayCount).equals(rs.getString("tran_date")))
{
int cnt= dayCount;
for(int i=0;i<Integer.parseInt(rs.getString("tran_date"))-(cnt+1);i++)
{
//System.out.println("before day count:"+dayCount);
//Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual ";
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";
pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
//Modify by birendra Pandey
if(rs1.getDouble("pyr_cumqty")!=0)
{
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ;
System.out.println("preyrcumulative ==="+pyrCumqty);
}
}
pstmt1.close();
rs1.close();
pstmt1 = null;
rs1 = null;
//End of preyearCumulative
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">");
xmlData.append("<day_quantity quantity=\"0\">");
xmlData.append("<pyr_dayqty>").append("<![CDATA["+prePyrDayQty+"]]>").append("</pyr_dayqty>");
xmlData.append("<daily_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</daily_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+preCumQty+"]]>").append("</cur_cumqty>");
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>");
xmlData.append("</tran_date>");
dayCount++;
cntFrBudget++;
//System.out.println("Budget Counter in empty tag for loop===="+cntFrBudget);
}
}
xmlData.append("<tran_date date=\""+checkNull(rs.getString("tran_date"))+"\">");
xmlData.append("<day_quantity quantity=\""+checkNull(rs.getString("day_quantity"))+"\">");
xmlData.append("<pyr_dayqty>").append("<![CDATA[" + checkNull(rs.getString("pyr_cumqty"))+"]]>").append("</pyr_dayqty>");
xmlData.append("<daily_budqty>").append("<![CDATA[" + dailyBudgetQty*(cntFrBudget) +"]]>").append("</daily_budqty>");
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("<cur_cumqty>").append("<![CDATA[" + checkNull(rs.getString("cur_cumqty"))+"]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>");
xmlData.append("</tran_date>");
preCumQty = checkEmpty(checkNull(rs.getString("cur_cumqty")));
prePyrDayQty =checkEmpty(checkNull(rs.getString("pyr_cumqty")));
curCumQty = checkEmpty(checkNull(rs.getString("cur_cumqty")));
pyrCumqty =checkEmpty(checkNull(rs.getString("pyr_cumqty")));
dayCount++;
}
if(count>0)
{
if(dayCount<lastDayOfMonth){
for(int p=dayCount;p<lastDayOfMonth;p++){
if(dayCount<lastDayOfMonth)
{
for(int p=dayCount;p<lastDayOfMonth;p++)
{
cntFrBudget++;
//Add new Block for preyear Cumulative
//sql="select to_date(add_months(?,-12)) from dual ";
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";
pstmt1 = conn.prepareStatement(sql);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
if(rs1.getDouble("pyr_cumqty")!=0)
{
pyrCumqty = checkNull(rs1.getString("pyr_cumqty")) ;
System.out.println("pyrCumqty As New ==="+pyrCumqty);
}
}
pstmt1.close();
rs1.close();
pstmt1 = null;
rs1 = null;
//End of preyearCumulative
xmlData.append("<tran_date date=\""+(listDate.get(dayCount))+"\">");
xmlData.append("<day_quantity quantity=\"0\">");
xmlData.append("<pyr_dayqty>").append("<![CDATA["+prePyrDayQty+"]]>").append("</pyr_dayqty>");
xmlData.append("<daily_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</daily_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+preCumQty+"]]>").append("</cur_cumqty>");
xmlData.append("<pyr_cumqty>").append("<![CDATA["+pyrCumqty+"]]>").append("</pyr_cumqty>");
xmlData.append("<cum_budqty>").append("<![CDATA["+dailyBudgetQty*(cntFrBudget)+"]]>").append("</cum_budqty>");
xmlData.append("<cur_cumqty>").append("<![CDATA["+curCumQty+"]]>").append("</cur_cumqty>");
xmlData.append("</day_quantity>");
xmlData.append("</tran_date>");
dayCount++;
}
}
xmlData.append("</unit_form>");
......@@ -374,4 +535,34 @@ public class ProductionVsBudgetReport extends ValidatorEJB implements Production
return input;
}
public String getInitGeoLocation()
{
return initGeoLocation;
}
public void setInitGeoLocation(String initGeoLocation)
{
this.initGeoLocation = initGeoLocation;
}
public String getInitUnitForm()
{
return initUnitForm;
}
public void setInitUnitForm(String initUnitForm)
{
this.initUnitForm = initUnitForm;
}
}
......@@ -9,6 +9,9 @@ import javax.ejb.Local;
@Local
public interface ProductionVsBudgetReportLocal extends ValidatorLocal{
public String getProductionBudget(String frmDate,String toDate) 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 getUnitFormXmlData() throws RemoteException, ITMException;
public String getInitUnitForm()throws RemoteException, ITMException;
public String getInitGeoLocation()throws RemoteException, ITMException;
}
......@@ -10,5 +10,9 @@ import javax.ejb.Remote;
public interface ProductionVsBudgetReportRemote extends ValidatorRemote
{
public String getProductionBudget(String frmDate,String toDate) 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 getUnitFormXmlData() throws RemoteException, ITMException;
public String getInitGeoLocation() throws RemoteException, ITMException;
public String getInitUnitForm()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