Commit e371f90f authored by nsawalakhe's avatar nsawalakhe

Added Ejb component for All India QTQ dashboard report


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104229 ce508802-f39f-4f6c-b175-0d175dae99d5
parent c33319f6
package ibase.dashboard.sfa.ejb;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
@Stateless
public class AllIndiaQTQ extends ValidatorEJB implements AllIndiaQTQLocal,AllIndiaQTQRemote
{
public AllIndiaQTQ()
{
}
@SuppressWarnings("unchecked")
public JSONObject getAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)throws RemoteException, ITMException
{
JSONObject rowDataAllIndiaQTQJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
int count = 0;
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
DecimalFormat df =new DecimalFormat("#.##");
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat("dd-MMM-yy");
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("From date inside in ALL India QTQ when From and To Date is null ===="+fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", "dd-MMM-yy");
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", "dd-MMM-yy");
}
//End the code of MTD format
if(fromDate!=null && toDate!=null&& loginCode!=null)
{
sql = "select " +
"a.month, " +
"a.year, " +
"a.monthname, " +
"round(sum(a.daysinfield)/sum(a.availdaysinfield),2) *100 as DAYINFIELD, " +
"round(sum(A.DrMetCalls)/sum(a.daysinfield),2) as call_avg, " +
"round(sum(STPERCENTPROD)/ sum(salesd_count),2) as STPERCENTPROD, " +
"round(sum(T1PERCENTPROD) / sum(salesd_count),2)as T1PERCENTPROD, " +
"round(sum(STPERCENTDRMET)/ sum(salesd_count),2) as STPERCENTDRMET , " +
"ROUND(((B.daysinfield/B.availdaysinfield)*100),2)AS FLM_time " +
"from " +
" ( " +
"select " +
"count(*) as salesd_count, " +
"vqt.DrMetCalls, " +
"VQT.sales_pers, " +
"VQT.month, " +
"VQT.year, " +
"VQT.monthname, " +
"VQT.daysinfield, " +
"VQT.availdaysinfield, " +
"sm.mt, " +
"VQT.STPERCENTPROD, " +
"VQT.T1PERCENTPROD, " +
"VQT.STPERCENTDRMET " +
"from VW_QTQ_TEAMWISE VQT " +
"INNER JOIN USERS ON USERS.CODE=VQT.SALES_PERS " +
"inner join ( " +
"SELECT " +
"sales_pers," +
"count( distinct strg_code) as mt, " +
"TO_CHAR(event_date,'mm') mm, " +
"TO_CHAR(event_date,'YYYY') year " +
"FROM strg_meet " +
"where strg_meet.sales_pers in (Select " +
"Emp_Code " +
"From " +
"Employee " +
"Start With " +
"Emp_Code =(select emp_code from users where code='"+loginCode+"') " + //pass user id
"Connect By Prior " +
"Emp_Code = Report_To) " +
"and strg_meet.locality_code<>'DUM' " +
"and (strg_code <> '-NA-' or strg_code is not null) " +
"group by sales_pers, " +
" TO_CHAR(event_date,'mm'), " +
" TO_CHAR(event_date,'YYYY') " +
" ) sm " +
" on VQT.sales_pers=sm.sales_pers and VQT.month=sm.mm and VQT.year=sm.year " +
" inner join sales_pers sp on sp.sales_pers=VQT.sales_pers " +
" inner join sub_bu_master sbm on sbm.sub_bu_code=sp.sub_bu_code " +
"where VQT.sales_pers in (Select " +
"Emp_Code " +
"From " +
"Employee " +
"Start With " +
"Emp_Code =(select emp_code from users where code ='"+loginCode+"') " +
"Connect By Prior " +
"Emp_Code = Report_To) " +
//"and VQT.year='2015' " +
"and VQT.month >= to_char(to_date('"+fromDate+"') ,'MM') " +
"and VQT.month <= to_char(to_date('"+toDate+"') ,'MM') " +
"and VQT.year >= to_char(to_date('"+fromDate+"') ,'YYYY') " +
"and VQT.year <= to_char(to_date('"+toDate+"') ,'YYYY') " +
//"and sbm.sub_bu_code='T2' " +
"AND SP.sub_bu_code<>'OSTEO'" +
"AND USERS.PROFILE_ID<>'FLM1'" +
"group by " +
"VQT.sales_pers,vqt.DrMetCalls, " +
"VQT.month, " +
"VQT.year, " +
"VQT.monthname, " +
"VQT.daysinfield, " +
"VQT.availdaysinfield, " +
"sm.mt, " +
"VQT.STPERCENTPROD, " +
"VQT.T1PERCENTPROD, " +
"VQT.STPERCENTDRMET " +
")A INNER JOIN " +
"( " +
"select " +
"sum(daysinfield) as daysinfield, " +
"sum(availdaysinfield) as availdaysinfield, " +
"month, " +
"year " +
"from VW_FLM_QTQ_TEAMWISE VQT " +
"inner join sales_pers sp on sp.sales_pers=VQT.sales_pers " +
"LEFT join sub_bu_master sbm on sbm.sub_bu_code=sp.sub_bu_code " +
"INNER JOIN EMPLOYEE E ON VQT.SALES_PERS=E.EMP_CODE " +
"INNER JOIN USERS U ON U.CODE=E.EMP_CODE " +
"where VQT.sales_pers in ( " +
"Select " +
"EMPLOYEE.Emp_Code " +
"From " +
"Employee " +
"Start With " +
"EMPLOYEE.Emp_Code =(select emp_code from users where code='"+loginCode+"') " +
"Connect By Prior " +
"EMPLOYEE.Emp_Code = EMPLOYEE.Report_To " +
") " +
//"and VQT.year='2015' " +
"and VQT.month >= to_char(to_date('"+fromDate+"') ,'MM') " +
"and VQT.month <= to_char(to_date('"+toDate+"') ,'MM') " +
"and VQT.year >= to_char(to_date('"+fromDate+"') ,'YYYY') " +
"and VQT.year <= to_char(to_date('"+toDate+"') ,'YYYY') " +
//"and sp.sub_bu_code='T2' "+ //--filter
"AND U.PROFILE_ID='FLM1'" +
"group by month, " +
"year " +
")b ON A.MONTH=b.month AND a.year=B.YEAR " +
"group by " +
"a.month, " +
"a.year, " +
"a.monthname, " +
"B.daysinfield, " +
"B.availdaysinfield order by a.month " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
StringBuffer monthNameBuffer = new StringBuffer ();
StringBuffer daysInFieldBuffer = new StringBuffer ();
StringBuffer callAverageBuffer = new StringBuffer ();
StringBuffer doctorVisitBuffer = new StringBuffer ();
StringBuffer doctorVisitPFBuffer = new StringBuffer ();
StringBuffer supertargetBuffer = new StringBuffer ();
StringBuffer flmCoachingBuffer = new StringBuffer ();
rowData = new JSONObject();
String ytdYear = "";
double daysInFieldAvg =0.0;
double callAverageAvg =0.0;
double doctorVisitAvg =0.0;
double doctorVisitPFAvg =0.0;
double supertargetAvg =0.0;
double flmCoachingAvg =0.0;
int avgCount=0;
while (rs.next())
{
ytdYear =rs.getString("YEAR").substring(2);
monthNameBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+rs.getString("MONTHNAME")+"- "+ytdYear+"</td>");
if(Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))>=90)
{
daysInFieldBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))+"</td>");
daysInFieldAvg=daysInFieldAvg+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))<90 && Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))>=80)
{
daysInFieldBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))+"</td>");
daysInFieldAvg=daysInFieldAvg+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))<80)
{
daysInFieldBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")))+"</td>");
daysInFieldAvg=daysInFieldAvg+Double.parseDouble(checkDouble(rs.getString("DAYINFIELD")));
}
if(Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))>=10)
{
callAverageBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))+"</td>");
callAverageAvg =callAverageAvg+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")));
}
else if(Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))<10 && Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))>=8)
{
callAverageBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))+"</td>");
callAverageAvg =callAverageAvg+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")));
}
else if(Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))<8)
{
callAverageBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")))+"</td>");
callAverageAvg =callAverageAvg+Double.parseDouble(checkDouble(rs.getString("CALL_AVG")));
}
if(Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))>=85)
{
doctorVisitBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))+"</td>");
doctorVisitAvg=doctorVisitAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))<85 && Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))>=65)
{
doctorVisitBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))+"</td>");
doctorVisitAvg=doctorVisitAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))<65)
{
doctorVisitBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")))+"</td>");
doctorVisitAvg=doctorVisitAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTPROD")));
}
if(Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))>=80)
{
doctorVisitPFBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))+"</td>");
doctorVisitPFAvg=doctorVisitPFAvg+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))<80 && Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))>=60)
{
doctorVisitPFBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))+"</td>");
doctorVisitPFAvg=doctorVisitPFAvg+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")));
}
else if(Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))<60)
{
doctorVisitPFBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")))+"</td>");
doctorVisitPFAvg=doctorVisitPFAvg+Double.parseDouble(checkDouble(rs.getString("T1PERCENTPROD")));
}
if(Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))>=90)
{
supertargetBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))+"</td>");
supertargetAvg=supertargetAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")));
}
else if(Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))<90 && Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))>=80)
{
supertargetBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))+"</td>");
supertargetAvg=supertargetAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")));
}
else if(Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))<80)
{
supertargetBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")))+"</td>");
supertargetAvg=supertargetAvg+Double.parseDouble(checkDouble(rs.getString("STPERCENTDRMET")));
}
if(Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))>=70)
{
flmCoachingBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))+"</td>");
flmCoachingAvg=flmCoachingAvg+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")));
}
else if(Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))<70 && Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))>=60)
{
flmCoachingBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))+"</td>");
flmCoachingAvg=flmCoachingAvg+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")));
}
else if(Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))<60)
{
flmCoachingBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")))+"</td>");
flmCoachingAvg=flmCoachingAvg+Double.parseDouble(checkDouble(rs.getString("FLM_TIME")));
}
avgCount++;
}
monthNameBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+"YTD "+"- "+ytdYear+"</td>");
daysInFieldBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(daysInFieldAvg/avgCount)+"</td>");
callAverageBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(callAverageAvg/avgCount)+"</td>");
doctorVisitBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(doctorVisitAvg/avgCount)+"</td>");
doctorVisitPFBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(doctorVisitPFAvg/avgCount)+"</td>");
supertargetBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(supertargetAvg/avgCount)+"</td>");
flmCoachingBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%'>"+df.format(flmCoachingAvg/avgCount)+"</td>");
rowData.put("monname", monthNameBuffer.toString());
rowData.put("diffield", daysInFieldBuffer.toString());
rowData.put("callavg", callAverageBuffer.toString());
rowData.put("stperprod", doctorVisitBuffer.toString());
rowData.put("tperprod", doctorVisitPFBuffer.toString());
rowData.put("stperdrmet", supertargetBuffer.toString());
rowData.put("flmtime", flmCoachingBuffer.toString());
rowData.put("exporttoExcel", CommonConstants.TOMCAT_HOME+"/ibase/dwh/FusionChart/images/excel.png");
rowDataAllIndiaQTQJson.put(count, rowData);
count++;
}//closed the if block
System.out.println(" rowDataAllIndiaQTQJson is =" + rowDataAllIndiaQTQJson);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
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 d)
{
d.printStackTrace();
System.out.println("Exception in :getTask():" + d.getMessage());
throw new ITMException(d);
}
}
return rowDataAllIndiaQTQJson;
}
private String checkDouble(String str)
{
if (str == null)
{
return "0";
} else
{
return str;
}
}
}
package ibase.dashboard.sfa.ejb;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public abstract interface AllIndiaQTQLocal extends ValidatorLocal
{
public JSONObject getAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)throws RemoteException, ITMException;
}
package ibase.dashboard.sfa.ejb;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public abstract interface AllIndiaQTQRemote extends ValidatorRemote
{
public JSONObject getAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)throws RemoteException, ITMException;
}
package ibase.dashboard.sfa.ejb;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedHashMap;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
@Stateless
public class ZoneWiseQTQ extends ValidatorEJB implements ZoneWiseQTQLocal,ZoneWiseQTQRemote
{
public ZoneWiseQTQ()
{
}
@SuppressWarnings("unchecked")
public JSONObject getDifAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)throws RemoteException, ITMException
{
JSONObject rowDataZoneWiseQTQ = new JSONObject();
JSONObject rowData = new JSONObject();
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
int count = 0;
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat("dd-MMM-yy");
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("frmDate inside in ZoneWise EJB Dashboard==" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", "dd-MMM-yy");
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", "dd-MMM-yy");
}
if(fromDate!=null && toDate!=null&& loginCode!=null)
{
sql = " select " +
" vw_sales_hier.ZONE, " +
" a.month, " +
" a.year, " +
" a.monthname, " +
" round(sum(a.daysinfield)/sum(a.availdaysinfield),2) *100 as DAYINFIELD, " +
" round(sum(A.DrMetCalls)/sum(a.daysinfield),2) as CALL_AVG, " +
" round(sum(STPERCENTPROD)/ sum(salesd_count),2) as STPERCENTPROD, " +
" round(sum(T1PERCENTPROD) / sum(salesd_count),2)as T1PERCENTPROD, " +
" round(sum(STPERCENTDRMET)/ sum(salesd_count),2) as STPERCENTDRMET , " +
" ROUND(((B.daysinfield / B.availdaysinfield )*100),2)AS FLM_time " +
" from " +
" ( " +
" select " +
" count(*) as salesd_count, " +
" vqt.DrMetCalls, " +
" VQT.sales_pers, " +
" VQT.month, " +
" VQT.year, " +
" VQT.monthname, " +
" VQT.daysinfield, " +
" VQT.availdaysinfield, " +
" sm.mt, " +
" VQT.STPERCENTPROD, " +
" VQT.T1PERCENTPROD, " +
" VQT.STPERCENTDRMET " +
" from VW_QTQ_TEAMWISE VQT " +
" left JOIN USERS ON USERS.CODE=VQT.SALES_PERS " +
" left join ( " +
" SELECT " +
" sales_pers, " +
" count( distinct strg_code) as mt, " +
" TO_CHAR(event_date,'mm') mm, " +
" TO_CHAR(event_date,'YYYY') year " +
" FROM strg_meet " +
" where strg_meet.sales_pers in (Select " +
" Emp_Code " +
" From " +
" Employee " +
" Start With " +
" Emp_Code =(select emp_code from users where code='"+loginCode+"') " + //---pass user id
" " +
" Connect By Prior " +
" Emp_Code = Report_To) " +
" and strg_meet.locality_code<>'DUM' " +
" and (strg_code <> '-NA-' or strg_code is not null) " +
" group by sales_pers, " +
" TO_CHAR(event_date,'mm'), " +
" TO_CHAR(event_date,'YYYY') " +
" " +
" ) sm " +
" on VQT.sales_pers=sm.sales_pers and VQT.month=sm.mm and VQT.year=sm.year " +
" left join sales_pers sp on sp.sales_pers=VQT.sales_pers " +
" left join sub_bu_master sbm on sbm.sub_bu_code=sp.sub_bu_code " +
" where VQT.sales_pers in (Select " +
" Emp_Code " +
" From " +
" Employee " +
" Start With " +
" Emp_Code =(select emp_code from users where code='"+loginCode+"') " +
" " +
" Connect By Prior " +
" Emp_Code = Report_To) " +
//" and VQT.year='2015' " +
" and VQT.month >= to_char(to_date('"+fromDate+"') ,'MM') " +
" and VQT.month <= to_char(to_date('"+toDate+"') ,'MM') " +
" and VQT.year >= to_char(to_date('"+fromDate+"') ,'YYYY') " +
" and VQT.year <= to_char(to_date('"+toDate+"') ,'YYYY') " +
// " and sbm.sub_bu_code='T2' " +
" AND SP.sub_bu_code<>'OSTEO' " +
" AND USERS.PROFILE_ID<>'FLM1' " +
" group by " +
" VQT.sales_pers,vqt.DrMetCalls, " +
" VQT.month, " +
" VQT.year, " +
" VQT.monthname, " +
" VQT.daysinfield, " +
" VQT.availdaysinfield, " +
" sm.mt, " +
" VQT.STPERCENTPROD, " +
" VQT.T1PERCENTPROD, " +
" VQT.STPERCENTDRMET " +
" )A left JOIN " +
" ( " +
" select " +
" sum(daysinfield) as daysinfield, " +
" sum(availdaysinfield) as availdaysinfield, " +
" month, " +
" year " +
" from VW_FLM_QTQ_TEAMWISE VQT " +
" left join sales_pers sp on sp.sales_pers=VQT.sales_pers " +
" LEFT join sub_bu_master sbm on sbm.sub_bu_code=sp.sub_bu_code " +
" left JOIN EMPLOYEE E ON VQT.SALES_PERS=E.EMP_CODE " +
" left JOIN USERS U ON U.CODE=E.EMP_CODE " +
" where VQT.sales_pers in ( " +
" Select " +
" EMPLOYEE.Emp_Code " +
" From " +
" Employee " +
" Start With " +
" EMPLOYEE.Emp_Code =(select emp_code from users where code='"+loginCode+"') " +
" Connect By Prior " +
" EMPLOYEE.Emp_Code = EMPLOYEE.Report_To " +
" ) " +
// " and VQT.year='2015' " +
" and VQT.month >= to_char(to_date('"+fromDate+"') ,'MM') " +
" and VQT.month <= to_char(to_date('"+toDate+"') ,'MM') " +
" and VQT.year >= to_char(to_date('"+fromDate+"') ,'YYYY') " +
" and VQT.year <= to_char(to_date('"+toDate+"') ,'YYYY') " +
// " and sp.sub_bu_code='T2' " +
" AND U.PROFILE_ID='FLM1' " +
" group by month, " +
" year " +
" )b ON A.MONTH=b.month AND a.year=B.YEAR " +
" left join vw_sales_hier on vw_sales_hier.repcode=A.sales_pers " +
" group by " +
" a.month,vw_sales_hier.ZONE, " +
" a.year, " +
" a.monthname, " +
" B.daysinfield, " +
" B.availdaysinfield " +
" order by month " ;
pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = pstmt.executeQuery();
String daysInFeild = getJSONForField("DAYINFIELD",rs);
rs.beforeFirst();
String callAverage = getJSONForField("CALL_AVG",rs);
rs.beforeFirst();
String docVisitedAtPf = getJSONForField("STPERCENTPROD",rs);
rs.beforeFirst();
String docVisitedInT1 = getJSONForField("T1PERCENTPROD",rs);
rs.beforeFirst();
String superTarget = getJSONForField("STPERCENTDRMET",rs);
rs.beforeFirst();
String flmCoaching = getJSONForField("FLM_TIME",rs);
rs.beforeFirst();
rowData.put("diffield", daysInFeild);
rowData.put("callavg", callAverage);
rowData.put("docvisitatpf", docVisitedAtPf);
rowData.put("docvisitint1", docVisitedInT1);
rowData.put("supertarget", superTarget);
rowData.put("flm", flmCoaching);
rowData.put("exporttoExcel", CommonConstants.TOMCAT_HOME+"/ibase/dwh/FusionChart/images/excel.png");
rowDataZoneWiseQTQ.put(count, rowData);
count++;
}//closed if block
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
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 d)
{
d.printStackTrace();
System.out.println("Exception in :getTask():" + d.getMessage());
throw new ITMException(d);
}
}
return rowDataZoneWiseQTQ;
}
@SuppressWarnings("unchecked")
private String getJSONForField(String columnName, ResultSet rs) {
LinkedHashMap<String, StringBuffer> zonewiseDataMap = null;
LinkedHashMap<String, Double> monthDataMap = null;
LinkedHashMap<String, Double> ytdDataMap = null;
String zoneName = "",monthName = "",ytdYear = "",month = "",columnValue = "";
StringBuffer zoneValueBuffer = null,monthBuffer = null,finalBuffer = null,monthAvgValBuffer = null;
DecimalFormat df =new DecimalFormat("#.##");
double monthAvgValue =0.0D, ytdValue = 0.0D;
try
{
zonewiseDataMap = new LinkedHashMap<String, StringBuffer>();
monthDataMap = new LinkedHashMap<String, Double>();
ytdDataMap = new LinkedHashMap<String, Double>();
while(rs.next())
{
columnValue = checkDouble(rs.getString(columnName));
zoneName = checkNull(rs.getString("ZONE"));
ytdYear =rs.getString("YEAR").substring(2);
month = rs.getString("MONTHNAME");
monthName = month+"- "+ytdYear;
System.out.println("columnValue"+columnValue);
System.out.println("zoneName"+zoneName);
if (ytdDataMap.containsKey(zoneName))
{
ytdValue = ytdDataMap.get(zoneName);
ytdValue = ytdValue + Double.parseDouble(columnValue);
ytdDataMap.put(zoneName, ytdValue);
}
else
{
ytdDataMap.put(zoneName, Double.parseDouble(columnValue));
}
if (monthDataMap.containsKey(monthName))
{
monthAvgValue = monthDataMap.get(monthName);
monthAvgValue = monthAvgValue + Double.parseDouble(columnValue);
monthDataMap.put(monthName, monthAvgValue);
}
else
{
monthDataMap.put(monthName, Double.parseDouble(columnValue));
}
if (zonewiseDataMap.containsKey(zoneName))
{
zoneValueBuffer = zonewiseDataMap.get(zoneName);
//zoneValueBuffer.append("<td>"+columnValue+"</td>");
zoneValueBuffer.append(getColValWithImg(columnName,columnValue));
monthBuffer.append("<td class='cardHtmlTableHeaderAlignLft' width='7%'>"+monthName+"</td>");
zonewiseDataMap.put(zoneName, zoneValueBuffer);
}
else
{
zoneValueBuffer = new StringBuffer();
monthBuffer = new StringBuffer();
zoneValueBuffer.append("<td class='cardHtmlTableHeaderAlignLft' width='15%'>"+zoneName+"</td>"+getColValWithImg(columnName,columnValue));
monthBuffer.append("<td class='cardHtmlTableHeaderAlignLft' width='7%'>"+monthName+"</td>");
zonewiseDataMap.put(zoneName, zoneValueBuffer);
}
finalBuffer = new StringBuffer();
finalBuffer.append("<tr><td class='cardHtmlTableHeaderAlignLft' width='15%'>ZONES</td>"+monthBuffer.toString()+" <td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"YTD "+"- "+ytdYear+"</td></tr>");
for (String key : zonewiseDataMap.keySet())
{
finalBuffer.append("<tr>"+zonewiseDataMap.get(key).toString()+"<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+df.format((ytdDataMap.get(key))/monthDataMap.size())+"</td></tr>");
}
}
monthAvgValBuffer = new StringBuffer();
for (String key : monthDataMap.keySet())
{
System.out.println("Size of map=="+zonewiseDataMap.size()+"monthDataMap.get(key)=="+monthDataMap.get(key)+"monthDataMap=="+monthDataMap);
monthAvgValBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='5%' background-color='antiquewhite'>"+df.format((monthDataMap.get(key))/zonewiseDataMap.size())+"</td>");
}
double allIndiaSum = 0.0;
for (String key : ytdDataMap.keySet())
{
double ytdsum=0.0;
ytdsum = Double.parseDouble(df.format((ytdDataMap.get(key))/monthDataMap.size()));
allIndiaSum = allIndiaSum + ytdsum ;
}
finalBuffer.append("<tr style='background-color: #EAECEE;'><td class='cardHtmlTableHeaderAlignLft' width='15%' background-color='antiquewhite'>ALL INDIA</td>"+monthAvgValBuffer.toString()+"<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+df.format(allIndiaSum/zonewiseDataMap.size())+"</td></tr>");
}
catch (SQLException e)
{
e.printStackTrace();
}
return finalBuffer.toString();
}
private String getColValWithImg(String columnName, String columnValue) {
StringBuffer colValWithImgBuffer = new StringBuffer();
double colValue = Double.parseDouble(columnValue);
if ("DAYINFIELD".equalsIgnoreCase(columnName)) {
if(colValue>=90)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<90 && colValue>=80)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<80)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
else if ("CALL_AVG".equalsIgnoreCase(columnName)) {
if(colValue >=10)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<10 && colValue>=8)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<8)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
else if ("STPERCENTPROD".equalsIgnoreCase(columnName)) {
if(colValue >=85)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<85 && colValue>=65)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<65)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
else if ("T1PERCENTPROD".equalsIgnoreCase(columnName)) {
if(colValue >=80)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<80 && colValue>=60)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<60)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
else if ("STPERCENTDRMET".equalsIgnoreCase(columnName)) {
if(colValue >=90)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<90 && colValue>=80)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<80)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
else if ("FLM_TIME".equalsIgnoreCase(columnName)) {
if(colValue >=70)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/green.png'/>"+" "+colValue+"</td>");
}
else if(colValue<70 && colValue>=60)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/yellow.png'/>"+" "+colValue+"</td>");
}
else if(colValue<60)
{
colValWithImgBuffer.append("<td class='cardHtmlTableBodyAlignRgt' width='7%'>"+"<img src='"+CommonConstants.TOMCAT_HOME+"/ibase/resource/images/users/red.png'/>"+" "+colValue+"</td>");
}
}
return colValWithImgBuffer.toString();
}
private String checkNull(String str)
{
if (str == null)
{
return "";
} else
{
return str;
}
}
private String checkDouble(String str)
{
if (str == null)
{
return "0";
} else
{
return str;
}
}
}
package ibase.dashboard.sfa.ejb;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public abstract interface ZoneWiseQTQLocal extends ValidatorLocal
{
public JSONObject getDifAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)throws RemoteException, ITMException;
}
package ibase.dashboard.sfa.ejb;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public abstract interface ZoneWiseQTQRemote extends ValidatorRemote
{
public JSONObject getDifAllIndiaQTQ(String loginCode,String dataSourceName,String fromDate,String toDate)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