Commit 2a0e6e92 authored by cmahajan's avatar cmahajan

Added new methods for complinace mtd format report.


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@102494 ce508802-f39f-4f6c-b175-0d175dae99d5
parent ce45ee9d
package ibase.dashboard.sfa.ejb;
import ibase.dashboard.Report.Utility.DashboardUtility;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.io.File;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
......@@ -416,4 +423,709 @@ public class ComplianceDB2 extends ValidatorEJB implements ComplianceDB2Local, C
}
}
/*Added by chetan mahajan on 1-July-2016 for compliance dashboard reports - Start*/
@SuppressWarnings("unchecked")
@Override
public JSONObject getComplMTDSummary(String dataSourceName, String fromDate, String toDate, String salePersons, String loginEmpCode) throws RemoteException, ITMException
{
JSONObject rawDataMTDWorkSummJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
int count =0;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String userImagePath ="";
String empFullName = "";
DashboardUtility dashboardUtility = null;
String appendSqlStr = "";
try
{
conn = connDriver.getConnectDB(dataSourceName);
dashboardUtility = new DashboardUtility();
connDriver = null;
loginEmpCode = dashboardUtility.getCommaSeparated(loginEmpCode);
salePersons = dashboardUtility.getCommaSeparated(salePersons);
userImagePath = CommonConstants.JBOSSHOME + File.separator +"server"+File.separator +"default"+File.separator +"deploy"+File.separator +"ibase.ear"+File.separator + "ibase.war" +File.separator + "resource" + File.separator + "images"+ File.separator + "users"+File.separator;
System.out.println("salePersons ="+salePersons+ " salePersons.length = "+salePersons.length());
if(salePersons != null && salePersons.length() != 0)
{
appendSqlStr = "and E.emp_code in ("+salePersons+")";
}
else
{
appendSqlStr = "";
}
System.out.println("appendSqlStr :"+appendSqlStr);
//sql = "select a.emp_code, a.emp_name from (select emp_code, emp_fname ||' '|| emp_lname emp_name from employee where report_to = "+loginEmpCode+" ) a " +
//" " + appendSqlStr + " " ;
sql = "select E.emp_code, CONCAT(CONCAT(E.emp_Fname,' '),E.EMP_LNAME) AS EMP_NAME " +
"FROM EMPLOYEE E WHERE E.emp_code in " +
"( select emp_code from EMPLOYEE WHERE (fn_get_hierarcy_NIGEL(emp_code,"+loginEmpCode+"))>0 ) " +
" " + appendSqlStr + " " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int i = 0;
String dynamicImgColor = "";
while (rs.next())
{
rowData = new JSONObject();
empFullName = checkNull (rs.getString("emp_name"));
rowData.put("emp_name",empFullName);
String empCode = checkNull (rs.getString("emp_code")).trim();
rowData.put("emp_code",empCode);
File file = new File(userImagePath+empCode+".png");
if(file.exists())
{
rowData.put("emp_img", "<div class='defaultUserImgDiv'> <img class='defaultUserImage' src='/ibase/resource/images/users/"+empCode+".png'/> </div>");
}else
{
String[] splited = empFullName.split(" ");
System.out.println("splited :"+splited[0].charAt(0));
String defaultUserImg = ""+splited[0].charAt(0);
if(splited.length>1)
{
System.out.println("splited 1 :"+splited[1]);
defaultUserImg = defaultUserImg + ""+splited[1].charAt(0);
}
if(i == 0)
{
dynamicImgColor = "#EE7A67";
}
else if(i == 1)
{
dynamicImgColor = "#67D7EE";
}
else if(i == 2)
{
dynamicImgColor = "#72A2C3";
}
else if(i == 3)
{
dynamicImgColor = "#B47ABD";
}
rowData.put("emp_img", "<div class='defaultUserImgLbl' style='background-color: "+dynamicImgColor+"!important'> <div class='userImageText'>"+defaultUserImg+" </div></div>");
i++;
if(i == 4)
{
i = 0;
}
}
rawDataMTDWorkSummJson.put(count, rowData);
count++;
}
}
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 :ComplianceDB2 : getComplMTDSummary" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMTDWorkSummJson;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject getComplDayWiseSummary(String dataSourceName, String fromDate, String toDate, String selectedSalePerson) throws RemoteException, ITMException
{
JSONObject rawDataMTDWorkSummJson = new JSONObject();
JSONObject rowData = null;
String sql = "";
int count =0;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
Calendar calendar = null;
try
{
//Code for base Start
/*SimpleDateFormat gridDateFormat = new SimpleDateFormat( "dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat("dd/MM/yy");*/
//Code for base End
//Code for db2 Start
SimpleDateFormat gridDateFormat = new SimpleDateFormat(genericUtility.getDBDateTimeFormat());
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getApplDateFormat());
//Code for db2 End
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
//Code for db2 Start
calendar = Calendar.getInstance();
toDate = convrtToTimStmDate.format(calendar.getTime());
toDate = gridDateFormat.format(convrtToTimStmDate.parse(toDate));
System.out.println(" toDate = "+toDate);
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convrtToTimStmDate.format(calendar.getTime());
fromDate = gridDateFormat.format(convrtToTimStmDate.parse(fromDate));
System.out.println(" fromDate = "+fromDate);
//Code for db2 end
//Code for base Start
/*calendar = Calendar.getInstance();
toDate = convrtToTimStmDate.format(calendar.getTime());
toDate = gridDateFormat.format(convrtToTimStmDate.parse(toDate));
System.out.println(" toDate = "+toDate);
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convrtToTimStmDate.format(calendar.getTime());
fromDate = gridDateFormat.format(convrtToTimStmDate.parse(fromDate));
System.out.println(" fromDate = "+fromDate);*/
//Code for base End
}
else if(fromDate!=null && fromDate.length()>0 && toDate!=null && toDate.length()>0)
{
//Code for db2 Start
fromDate = gridDateFormat.format(convrtToTimStmDate.parse(fromDate));
toDate = gridDateFormat.format(convrtToTimStmDate.parse(toDate));
//Code for db2 End
}
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
System.out.println("In getComplDayWiseSummary selected ==>>fromDate = ["+fromDate+"] toDate = ["+toDate+"] selectedSalePerson = ["+selectedSalePerson+"]" );
//Code for db2 Start
sql = "SELECT M.SALES_PERS " +
",S.SP_NAME " +
",DATE (M.EVENT_DATE) AS EVENT_DATE " +
",(SELECT COUNT(ST.LOCALITY_CODE) FROM SPRS_TRAVEL ST where M.EVENT_DATE= ST.TRAVEL_DATE AND M.SALES_PERS = ST.SALES_PERS) LOCALITY " +
",COUNT(CASE WHEN D.CUST_TYPE = 'D' THEN D.SC_CODE END) DR_CNT " +
",COUNT(CASE WHEN D.CUST_TYPE = 'C' THEN D.SC_CODE END) CHM_CNT " +
"FROM STRG_MEET M " +
" LEFT JOIN SALES_PERS S ON S.SALES_PERS = M.SALES_PERS " +
" LEFT JOIN STRG_CUSTOMER D ON D.SC_CODE = M.STRG_CODE " +
" WHERE M.SALES_PERS = '"+selectedSalePerson+"' AND M.EVENT_DATE BETWEEN TIMESTAMP('"+fromDate+"') AND TIMESTAMP('"+toDate+"') " +
" GROUP BY S.SP_NAME ,M.EVENT_DATE ,M.SALES_PERS ORDER BY M.EVENT_DATE";
//Code for db2 End
//Code for base Start
/*sql = "SELECT S.SALES_PERS, " +
"S.SP_NAME, " +
"to_char(M.EVENT_DATE,'dd/mm/yy') as EVENT_DATE, " +
"COUNT(M.LOCALITY_CODE) LOC_CODE, " +
"COUNT(CASE WHEN D.CUST_TYPE='D' THEN D.SC_CODE END ) DR_CNT, " +
"COUNT(CASE WHEN D.CUST_TYPE='C' THEN D.SC_CODE END ) CHM_CNT " +
"FROM STRG_MEET M " +
"INNER JOIN SALES_PERS S ON S.SALES_PERS = M.SALES_PERS " +
"INNER JOIN STRG_CUSTOMER D ON D.SC_CODE = M.STRG_CODE " +
"WHERE M.SALES_PERS = '"+selectedSalePerson+"' " +
"AND M.EVENT_DATE BETWEEN '"+fromDate+"' AND '"+toDate+"'" +
" AND D.CUST_TYPE != 'S' " +
"GROUP BY S.SP_NAME,M.EVENT_DATE,S.SALES_PERS " +
"ORDER BY M.EVENT_DATE";*/
//Code for base Start
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next())
{
rowData = new JSONObject();
rowData.put("sales_pers", checkNull(rs.getString("SALES_PERS")));
rowData.put("sp_name",checkNull( rs.getString("SP_NAME")));
rowData.put("event_date", checkNull(rs.getString("EVENT_DATE")));
rowData.put("loc_code",checkNull( rs.getString("LOCALITY")));
rowData.put("dr_cnt",checkNull( rs.getString("DR_CNT")));
rowData.put("chm_cnt",checkNull( rs.getString("CHM_CNT")));
rawDataMTDWorkSummJson.put(count, rowData);
count++;
}
}
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 :ComplianceDB2 : getComplDayWiseSummary" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMTDWorkSummJson;
}
@SuppressWarnings("unchecked")
public JSONObject getComplDayWiseDetail(String dataSourceName, String eventDate, String salesPersCode) throws RemoteException, ITMException
{
PreparedStatement pstmt = null;
ConnDriver connDriver = new ConnDriver();
ResultSet rs = null;
Connection conn = null;
String sql = "";
String dcrId = "" ;
String lastDCRDate = "";
String spFullName = "";
String doctorName = "";
String teamName = "" ;
int count = 0;
JSONObject complDayWiseDetailJson = null;
JSONObject rowData = null;
JSONObject complDayWiseDetailFinalJsn = new JSONObject();
try
{
//Code for db2 Start
SimpleDateFormat gridDateFormat = new SimpleDateFormat(genericUtility.getDBDateTimeFormat());
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getApplDateFormat());
//Code for db2 End
//Code for Base Start
/*SimpleDateFormat gridDateFormat = new SimpleDateFormat( "dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat("dd/MM/yy");*/
//Code for Base End
eventDate = gridDateFormat.format(convrtToTimStmDate.parse(eventDate));
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql = " SELECT S.TRAN_ID, " +
" VARCHAR(DATE(S.EVENT_DATE)) AS EVENT_DATE, " +
"S.ACTIVITY_CODE,F.DESCR AS ACTIVITY_DESCR, S.SALES_PERS, S.REMARKS, " +
" E.EMP_FNAME , E.EMP_MNAME, E.EMP_LNAME," +
" S.SPRS_CODE__WW,S.DCR_ID,S.OTH_PARTICIPANT,S.CONFIRMED FROM SPRS_ACT_TRAN S , " +
" EMPLOYEE E, FIELDACTIVITY F WHERE S.SALES_PERS = E.EMP_CODE AND S.ACTIVITY_CODE = F.ACTIVITY_CODE AND " +
" S.SALES_PERS = '"+salesPersCode+"' AND S.EVENT_DATE = TIMESTAMP('"+eventDate+"') ";
//Code for Base Start
/*sql = " SELECT S.TRAN_ID, " +
"to_char(S.EVENT_DATE,'dd/mm/yy') as EVENT_DATE, " +
"S.ACTIVITY_CODE,F.DESCR AS ACTIVITY_DESCR, S.SALES_PERS, S.REMARKS, " +
" E.EMP_FNAME , E.EMP_MNAME, E.EMP_LNAME," +
" S.SPRS_CODE__WW,S.DCR_ID,S.OTH_PARTICIPANT,S.CONFIRMED FROM SPRS_ACT_TRAN S , " +
" EMPLOYEE E, FIELDACTIVITY F WHERE S.SALES_PERS = E.EMP_CODE AND S.ACTIVITY_CODE = F.ACTIVITY_CODE AND " +
" S.SALES_PERS = '"+salesPersCode+"' AND S.EVENT_DATE = '"+eventDate+"' ";*/
//Code for Base End
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
complDayWiseDetailJson = new JSONObject();
count = 0;
if(rs.next())
{
dcrId = rs.getString("DCR_ID") == null ? "" : rs.getString("DCR_ID") ;
spFullName = (rs.getString("EMP_FNAME") == null ? "" : rs.getString("EMP_FNAME")) + " " + (rs.getString("EMP_MNAME") == null ? "" : rs.getString("EMP_MNAME")) + " " + (rs.getString("EMP_MNAME") == null ? "" : rs.getString("EMP_MNAME")) ;
lastDCRDate = this.getSalesPersLastDCRDate(conn, salesPersCode, dcrId);
rowData = new JSONObject();
rowData.put("sales_pers", checkNull(rs.getString("SALES_PERS")));
rowData.put("sp_name", checkNull(spFullName));
rowData.put("event_date", checkNull(rs.getString("EVENT_DATE")));
rowData.put("last_dcr_date", checkNull(lastDCRDate));
rowData.put("oth_participant", checkNull(rs.getString("OTH_PARTICIPANT")));
rowData.put("activity_descr", checkNull(rs.getString("ACTIVITY_DESCR")));
rowData.put("remarks", checkNull(rs.getString("REMARKS")));
complDayWiseDetailJson.put(count, rowData);
count++;
}
complDayWiseDetailFinalJsn.put("1", complDayWiseDetailJson);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " SELECT ST.TRAN_ID, ST.PLAN_ID, ST.SALES_PERS, ST.TRAVEL_DATE, ST.LOCALITY_CODE,L.DESCR AS LOCALITY_DESCR, ST.STAN_CODE, S1.DESCR AS STAN_DESCR, " +
" ST.STAN_CODE__FROM, S2.DESCR AS STAN_CODE__FROM_DESCR, ST.TRAVEL_MODE, ST.OVER_NIGHT, ST.ACTIVITY_CODE, ST.LOCALITY_CODE_FROM," +
" ST.TEMPLATE_FILE, ST.SALES_TEAM, ST.OTH_PARTICIPANT, ST.SPRS_CODE__WW, E.EMP_FNAME,E.EMP_MNAME,E.EMP_LNAME ," +
" ST.ORDER_OF_VISIT, ST.DCR_ID, ST.LINE_NO, ST.DR_VISIT, ST.CHEM_VISIT FROM SPRS_TRAVEL ST " +
" LEFT JOIN LOCALITY L ON L.LOCALITY_CODE = ST.LOCALITY_CODE " +
" LEFT JOIN EMPLOYEE E ON E.EMP_CODE = ST.SPRS_CODE__WW " +
" LEFT JOIN STATION S1 ON S1.STAN_CODE = ST.STAN_CODE " +
" LEFT JOIN STATION S2 ON S2.STAN_CODE = ST.STAN_CODE " +
" WHERE ST.DCR_ID = '"+dcrId+"' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int localityCount = 1;
complDayWiseDetailJson = new JSONObject();
count = 0;
while(rs.next())
{
System.out.println("In Locality localityCount = "+localityCount);
rowData = new JSONObject();
rowData.put("sr_no", localityCount);
rowData.put("locality_descr", checkNull(rs.getString("LOCALITY_DESCR")));
rowData.put("stan_code__from_descr", checkNull(rs.getString("STAN_CODE__FROM_DESCR")));
rowData.put("travel_mode", checkNull(rs.getString("TRAVEL_MODE")));
complDayWiseDetailJson.put(count, rowData);
count++;
localityCount++;
}
complDayWiseDetailFinalJsn.put("2", complDayWiseDetailJson);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//Code for db2 Start
sql = "SELECT SM.TRAN_ID, SM.PLAN_ID, SM.EVENT_DATE, SM.EVENT_TYPE, SM.STRG_CODE,SM.STRG_NAME" +
", CUST1.FIRST_NAME AS CUST_FNAME, SM_ITEM.QUANTITY, SM_ITEM.BRIEFED_DESCR, SM_ITEM.ITEM_CODE" +
", ITEM.DESCR AS ITEM_DESCR, CUST1.MIDDLE_NAME CUST_MNAME , CUST1.LAST_NAME AS CUST_LNAME " +
", SM.STRG_TYPE, SM.STRG_NO_VISIT, SM.EVENT_TIME_START, SM.EVENT_TIME_END, SM.STRG_CLASS_CODE " +
", CUST_CLASS.CLASS_CODE_DESCR, SM.SALES_PERS, E.EMP_FNAME AS SPRS_FNAME, E.EMP_MNAME AS SPRS_MNAME" +
", E.EMP_LNAME AS SPRS_LNAME, SM.SALES_TEAM, E1.EMP_FNAME AS SALES_TEAM_FNAME, E1.EMP_MNAME AS SALES_TEAM_MNAME" +
", E1.EMP_LNAME AS SALES_TEAM_LNAME , SM.OTH_PARTICIPANT, SM.REMARKS,SM.ORDER_BOOKED, SM.MEET_SUMM, SM.LOCALITY_CODE" +
", SM.TEMPLATE_FILE, SM.SPRS_CODE__WW, E2.EMP_FNAME AS SPRS_CODE__WW_FNAME, E2.EMP_MNAME AS SPRS_CODE__WW_MNAME" +
", E2.EMP_LNAME AS SPRS_CODE__WW_LNAME, SM.LAST_MEET_SUMM, SM.LAST_MEET_DATE, SM.LAST_PROD_BRF, SM.REF_TRAN_ID" +
", SM.CONF_DATE, SM.CONFIRMED, SM.EMP_CODE__APRV, SM.SHORT_ID, SM.SC_CODE__REF, SM.MEET_SUMM_MGR, SM.DCR_ID" +
", SM.WORK_TEAM, SM.WORK_WITH_OTHER, SM.POB_VAL " +
" ,SM.LOCALITY_CODE " +
" ,LOCALITY.DESCR AS LOC_DESCR" +
" FROM STRG_MEET SM " +
" LEFT JOIN STRG_CUSTOMER CUST1 ON CUST1.SC_CODE = SM.STRG_CODE " +
" LEFT JOIN EMPLOYEE E ON E.EMP_CODE = SM.SALES_PERS " +
" LEFT JOIN EMPLOYEE E1 ON E1.EMP_CODE = SM.SALES_TEAM " +
" LEFT JOIN EMPLOYEE E2 ON E2.EMP_CODE = SM.SPRS_CODE__WW " +
" LEFT JOIN STRG_CUST_CLASS CUST_CLASS ON CUST_CLASS.CLASS_CODE = SM.STRG_CLASS_CODE " +
" LEFT JOIN STRG_MEET_ITEMS SM_ITEM ON SM_ITEM.DCR_ID = SM.DCR_ID and SM_ITEM.strg_code = SM.strg_code " +
" LEFT JOIN ITEM ITEM ON ITEM.ITEM_CODE = SM_ITEM.ITEM_CODE " +
" LEFT JOIN LOCALITY ON LOCALITY.LOCALITY_CODE=SM.LOCALITY_CODE " +
" WHERE SM.DCR_ID = '"+dcrId+"' AND CUST_CLASS.CUST_TYPE ='D' AND SM.STRG_TYPE = 'D'" +
" ORDER BY SM.STRG_CODE";
//Code for db2 End
//Code for Base Start
//This sql remove some table only For testing purpuse only
/*sql = " SELECT SM.TRAN_ID, SM.PLAN_ID, SM.EVENT_DATE, SM.EVENT_TYPE, " +
//" SM_ITEM.QUANTITY, SM_ITEM.BRIEFED_DESCR, SM_ITEM.ITEM_CODE, ITEM.DESCR AS ITEM_DESCR," +
"SM.STRG_CODE,SM.STRG_NAME, CUST1.FIRST_NAME AS CUST_FNAME," +
" CUST1.MIDDLE_NAME CUST_MNAME , CUST1.LAST_NAME AS CUST_LNAME , " +
"SM.STRG_TYPE, SM.STRG_NO_VISIT, SM.EVENT_TIME_START, " +
" SM.EVENT_TIME_END, SM.STRG_CLASS_CODE , " +
"SM.SALES_PERS, E.EMP_FNAME AS SPRS_FNAME, " +
"E.EMP_MNAME AS SPRS_MNAME," +
" E.EMP_LNAME AS SPRS_LNAME, SM.SALES_TEAM, E1.EMP_FNAME AS SALES_TEAM_FNAME, E1.EMP_MNAME AS SALES_TEAM_MNAME, E1.EMP_LNAME AS SALES_TEAM_LNAME , " +
" SM.OTH_PARTICIPANT, SM.REMARKS,SM.ORDER_BOOKED, SM.MEET_SUMM, SM.LOCALITY_CODE, SM.TEMPLATE_FILE, SM.SPRS_CODE__WW, " +
" E2.EMP_FNAME AS SPRS_CODE__WW_FNAME, E2.EMP_MNAME AS SPRS_CODE__WW_MNAME, E2.EMP_LNAME AS SPRS_CODE__WW_LNAME, SM.LAST_MEET_SUMM," +
" SM.LAST_MEET_DATE, SM.LAST_PROD_BRF, SM.REF_TRAN_ID, SM.CONF_DATE, SM.CONFIRMED, SM.EMP_CODE__APRV, SM.SHORT_ID, SM.SC_CODE__REF," +
" SM.MEET_SUMM_MGR, SM.DCR_ID, SM.WORK_TEAM, SM.WORK_WITH_OTHER, SM.POB_VAL FROM STRG_MEET SM" +
" LEFT JOIN STRG_CUSTOMER CUST1 ON CUST1.SC_CODE = SM.STRG_CODE" +
" LEFT JOIN EMPLOYEE E ON E.EMP_CODE = SM.SALES_PERS" +
" LEFT JOIN EMPLOYEE E1 ON E1.EMP_CODE = SM.SALES_TEAM" +
" LEFT JOIN EMPLOYEE E2 ON E2.EMP_CODE = SM.SPRS_CODE__WW " +
//" LEFT JOIN STRG_MEET_ITEMS SM_ITEM ON SM_ITEM.DCR_ID = SM.DCR_ID " +
//" LEFT JOIN ITEM ITEM ON ITEM.ITEM_CODE = SM_ITEM.ITEM_CODE " +
" WHERE SM.DCR_ID = '"+dcrId+"' AND SM.STRG_TYPE = 'D'";*/
//Code for Base End
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int doctorCount = 1;
complDayWiseDetailJson = new JSONObject();
count = 0;
String briefDescr = "";
String remarksDescr = "";
String strgCode = "";
while(rs.next())
{
System.out.println("In doctor doctorCount = "+doctorCount);
doctorName = (rs.getString("CUST_FNAME") == null ? "" : rs.getString("CUST_FNAME")) + " " + (rs.getString("CUST_MNAME") == null ? "" : rs.getString("CUST_MNAME")) + " " + (rs.getString("CUST_LNAME") == null ? "" : rs.getString("CUST_LNAME")) ;
spFullName = (rs.getString("SPRS_FNAME") == null ? "" : rs.getString("SPRS_FNAME")) + " " + (rs.getString("SPRS_MNAME") == null ? "" : rs.getString("SPRS_MNAME")) + " " + (rs.getString("SPRS_LNAME") == null ? "" : rs.getString("SPRS_LNAME")) ;
teamName = (rs.getString("SALES_TEAM_FNAME") == null ? "" : rs.getString("SALES_TEAM_FNAME")) + " " + (rs.getString("SALES_TEAM_MNAME") == null ? "" : rs.getString("SALES_TEAM_MNAME")) + " " + (rs.getString("SALES_TEAM_LNAME") == null ? "" : rs.getString("SALES_TEAM_LNAME")) ;
rowData = new JSONObject();
rowData.put("sno_doc", doctorCount);
rowData.put("str_class_code_descr", checkNull(rs.getString("CLASS_CODE_DESCR")));
rowData.put("doctor_name", checkNull(doctorName));
if(checkNull(rs.getString("ITEM_CODE")) == "")
{
briefDescr = checkNull(rs.getString("BRIEFED_DESCR"));
}
else
{
briefDescr = checkNull(rs.getString("ITEM_DESCR"));
}
rowData.put("product_name", briefDescr);
rowData.put("quantity", checkNull(rs.getString("QUANTITY")));
//rowData.put("product_name", "-");
//rowData.put("quantity", "-");
rowData.put("ordered_booked", checkNull(rs.getString("ORDER_BOOKED")));
rowData.put("meeting_summ", checkNull(rs.getString("MEET_SUMM")));
rowData.put("other_parti_doctor", checkNull(rs.getString("OTH_PARTICIPANT")));
rowData.put("team_sale_name", checkNull(teamName));
if(checkNull(rs.getString("MEET_SUMM_MGR")) == "")
{
remarksDescr = checkNull(rs.getString("REMARKS"));
}
else
{
remarksDescr = checkNull(rs.getString("MEET_SUMM_MGR"));
}
rowData.put("remrks_doctor", remarksDescr);
rowData.put("locality_doctor", checkNull(rs.getString("LOC_DESCR"))); //Show locality on table
rowData.put("strg_code_doctor", checkNull(rs.getString("STRG_CODE")));
complDayWiseDetailJson.put(count, rowData);
count++;
doctorCount++;
}
complDayWiseDetailFinalJsn.put("3", complDayWiseDetailJson);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
//Code for db2 Start
sql = "SELECT SM.TRAN_ID ,SM.PLAN_ID ,SM.EVENT_DATE ,SM.EVENT_TYPE ,SM.STRG_CODE ,SM.STRG_NAME " +
",CUST1.FIRST_NAME AS CUST_FNAME ,SM_ITEM.QUANTITY ,SM_ITEM.BRIEFED_DESCR ,SM_ITEM.ITEM_CODE " +
",ITEM.DESCR AS ITEM_DESCR ,CUST1.MIDDLE_NAME CUST_MNAME ,CUST1.LAST_NAME AS CUST_LNAME ,SM.STRG_TYPE " +
",SM.STRG_NO_VISIT ,SM.EVENT_TIME_START ,SM.EVENT_TIME_END ,SM.STRG_CLASS_CODE ,CUST_CLASS.CLASS_CODE_DESCR " +
",SM.SALES_PERS ,E.EMP_FNAME AS SPRS_FNAME ,E.EMP_MNAME AS SPRS_MNAME ,E.EMP_LNAME AS SPRS_LNAME ,SM.SALES_TEAM " +
",E1.EMP_FNAME AS SALES_TEAM_FNAME ,E1.EMP_MNAME AS SALES_TEAM_MNAME ,E1.EMP_LNAME AS SALES_TEAM_LNAME ,SM.OTH_PARTICIPANT " +
",SM.REMARKS ,SM.ORDER_BOOKED ,SM.MEET_SUMM ,SM.LOCALITY_CODE ,SM.TEMPLATE_FILE ,SM.SPRS_CODE__WW " +
",E2.EMP_FNAME AS SPRS_CODE__WW_FNAME ,E2.EMP_MNAME AS SPRS_CODE__WW_MNAME ,E2.EMP_LNAME AS SPRS_CODE__WW_LNAME " +
",SM.LAST_MEET_SUMM ,SM.LAST_MEET_DATE ,SM.LAST_PROD_BRF ,SM.REF_TRAN_ID ,SM.CONF_DATE ,SM.CONFIRMED ,SM.EMP_CODE__APRV " +
",SM.SHORT_ID ,SM.SC_CODE__REF ,SM.MEET_SUMM_MGR ,SM.DCR_ID ,SM.WORK_TEAM ,SM.WORK_WITH_OTHER ,SM.POB_VAL " +
" ,SM.LOCALITY_CODE " +
" ,LOCALITY.DESCR AS LOC_DESCR" +
" FROM STRG_MEET SM " +
" LEFT JOIN STRG_CUSTOMER CUST1 ON CUST1.SC_CODE = SM.STRG_CODE " +
" LEFT JOIN EMPLOYEE E ON E.EMP_CODE = SM.SALES_PERS " +
" LEFT JOIN EMPLOYEE E1 ON E1.EMP_CODE = SM.SALES_TEAM " +
" LEFT JOIN EMPLOYEE E2 ON E2.EMP_CODE = SM.SPRS_CODE__WW " +
" LEFT JOIN STRG_CUST_CLASS CUST_CLASS ON CUST_CLASS.CLASS_CODE = SM.STRG_CLASS_CODE " +
" LEFT JOIN STRG_MEET_ITEMS SM_ITEM ON SM_ITEM.DCR_ID = SM.DCR_ID and SM_ITEM.strg_code = SM.strg_code " +
" LEFT JOIN ITEM ITEM ON ITEM.ITEM_CODE = SM_ITEM.ITEM_CODE " +
" LEFT JOIN LOCALITY ON LOCALITY.LOCALITY_CODE=SM.LOCALITY_CODE " +
" WHERE SM.DCR_ID = '"+dcrId+"' AND CUST_CLASS.CUST_TYPE = 'C' AND SM.STRG_TYPE = 'C'" +
" ORDER BY SM.STRG_CODE";
//Code for db2 End
//Code for Base Start
//This sql remove some table only For testing purpuse only
/*sql = " SELECT SM.TRAN_ID, SM.PLAN_ID, SM.EVENT_DATE, SM.EVENT_TYPE, " +
"SM.STRG_CODE,SM.STRG_NAME, CUST1.FIRST_NAME AS CUST_FNAME," +
//" SM_ITEM.QUANTITY, SM_ITEM.BRIEFED_DESCR, SM_ITEM.ITEM_CODE, ITEM.DESCR AS ITEM_DESCR," +
" CUST1.MIDDLE_NAME CUST_MNAME , CUST1.LAST_NAME AS CUST_LNAME , " +
"SM.STRG_TYPE, SM.STRG_NO_VISIT, SM.EVENT_TIME_START, " +
" SM.EVENT_TIME_END, SM.STRG_CLASS_CODE , " +
"SM.SALES_PERS, E.EMP_FNAME AS SPRS_FNAME, E.EMP_MNAME AS SPRS_MNAME," +
" E.EMP_LNAME AS SPRS_LNAME, SM.SALES_TEAM, E1.EMP_FNAME AS SALES_TEAM_FNAME, E1.EMP_MNAME AS SALES_TEAM_MNAME, E1.EMP_LNAME AS SALES_TEAM_LNAME , " +
" SM.OTH_PARTICIPANT, SM.REMARKS,SM.ORDER_BOOKED, SM.MEET_SUMM, SM.LOCALITY_CODE, SM.TEMPLATE_FILE, SM.SPRS_CODE__WW, " +
" E2.EMP_FNAME AS SPRS_CODE__WW_FNAME, E2.EMP_MNAME AS SPRS_CODE__WW_MNAME, E2.EMP_LNAME AS SPRS_CODE__WW_LNAME, SM.LAST_MEET_SUMM," +
" SM.LAST_MEET_DATE, SM.LAST_PROD_BRF, SM.REF_TRAN_ID, SM.CONF_DATE, SM.CONFIRMED, SM.EMP_CODE__APRV, SM.SHORT_ID, SM.SC_CODE__REF," +
" SM.MEET_SUMM_MGR, SM.DCR_ID, SM.WORK_TEAM, SM.WORK_WITH_OTHER, SM.POB_VAL FROM STRG_MEET SM" +
" LEFT JOIN STRG_CUSTOMER CUST1 ON CUST1.SC_CODE = SM.STRG_CODE" +
" LEFT JOIN EMPLOYEE E ON E.EMP_CODE = SM.SALES_PERS" +
" LEFT JOIN EMPLOYEE E1 ON E1.EMP_CODE = SM.SALES_TEAM" +
" LEFT JOIN EMPLOYEE E2 ON E2.EMP_CODE = SM.SPRS_CODE__WW " +
//" LEFT JOIN STRG_MEET_ITEMS SM_ITEM ON SM_ITEM.DCR_ID = SM.DCR_ID " +
//" LEFT JOIN ITEM ITEM ON ITEM.ITEM_CODE = SM_ITEM.ITEM_CODE " +
" WHERE SM.DCR_ID = '"+dcrId+"' AND SM.STRG_TYPE = 'C'";*/
//Code for Base End
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int chemistCount = 1;
complDayWiseDetailJson = new JSONObject();
count = 0;
while(rs.next())
{
System.out.println("In chemist chemistCount = "+chemistCount);
doctorName = (rs.getString("CUST_FNAME") == null ? "" : rs.getString("CUST_FNAME")) + " " + (rs.getString("CUST_MNAME") == null ? "" : rs.getString("CUST_MNAME")) + " " + (rs.getString("CUST_LNAME") == null ? "" : rs.getString("CUST_LNAME")) ;
spFullName = (rs.getString("SPRS_FNAME") == null ? "" : rs.getString("SPRS_FNAME")) + " " + (rs.getString("SPRS_MNAME") == null ? "" : rs.getString("SPRS_MNAME")) + " " + (rs.getString("SPRS_LNAME") == null ? "" : rs.getString("SPRS_LNAME")) ;
teamName = (rs.getString("SALES_TEAM_FNAME") == null ? "" : rs.getString("SALES_TEAM_FNAME")) + " " + (rs.getString("SALES_TEAM_MNAME") == null ? "" : rs.getString("SALES_TEAM_MNAME")) + " " + (rs.getString("SALES_TEAM_LNAME") == null ? "" : rs.getString("SALES_TEAM_LNAME")) ;
rowData = new JSONObject();
rowData.put("srno_chemist", chemistCount);
rowData.put("strgclass_descr_chemist", checkNull(rs.getString("CLASS_CODE_DESCR")));
rowData.put("chemist_name", checkNull(doctorName));
if(checkNull(rs.getString("ITEM_CODE")) == "")
{
briefDescr = checkNull(rs.getString("BRIEFED_DESCR"));
}
else
{
briefDescr = checkNull(rs.getString("ITEM_DESCR"));
}
rowData.put("prod_name", briefDescr);
rowData.put("che_quantity", checkNull(rs.getString("QUANTITY")));
rowData.put("ord_book_chemist", checkNull(rs.getString("ORDER_BOOKED")));
rowData.put("oth_parti_chemist", checkNull(rs.getString("OTH_PARTICIPANT")));
rowData.put("saleteam_name_chemist", checkNull(teamName));
rowData.put("remk_chemist", checkNull(rs.getString("MEET_SUMM")));
rowData.put("loca_chemist", checkNull(rs.getString("LOC_DESCR"))); //Show locality on table
rowData.put("strg_code_chemist", checkNull(rs.getString("STRG_CODE")));
complDayWiseDetailJson.put(count, rowData);
count++;
chemistCount++;
}
complDayWiseDetailFinalJsn.put("4", complDayWiseDetailJson);
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("In getComplDayWiseDetail1 selected ==>>eventDate = ["+eventDate+"] salesPersCode = ["+salesPersCode+"]" );
}
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 :ComplianceDB2 : getComplDayWiseDetail1" + d.getMessage());
throw new ITMException(d);
}
}
return complDayWiseDetailFinalJsn;
}
private String getSalesPersLastDCRDate (Connection conn, String salesPers, String currDCRId)
{
String lastDCRDate = "";
String sql = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
SimpleDateFormat gridDateFormat = new SimpleDateFormat(genericUtility.getDBDateTimeFormat());
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getApplDateFormat());
//Code for Base Start
/*SimpleDateFormat gridDateFormat = new SimpleDateFormat( "dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat("dd/MM/yy");*/
//Code for Base End
//VARCHAR(DATE(S.EVENT_DATE)) AS EVENT_DATE
sql= "SELECT DATE(MAX(EVENT_DATE)) AS LAST_DCR_DATE FROM SPRS_ACT_TRAN WHERE SALES_PERS = ? AND DCR_ID != ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, salesPers);
pstmt.setString(2, currDCRId);
rs = pstmt.executeQuery();
if(rs.next())
{
//eventDate = gridDateFormat.format(convrtToTimStmDate.parse(eventDate));
//lastDCRDate = rs.getString(1) == null ? "" : gridDateFormat.format(convrtToTimStmDate.parse(rs.getString(1)));
lastDCRDate = (rs.getString("LAST_DCR_DATE"));
System.out.println(" last DCR Date = "+lastDCRDate);
}
else
{
System.out.println("No Last DCR date details found for ["+salesPers+"] and DCR ID other than ["+currDCRId+"]");
if(rs != null)
{
rs.close();
rs =null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
sql= "SELECT DATE(MAX(EVENT_DATE)) AS LAST_DCR_DATE FROM SPRS_ACT_TRAN WHERE SALES_PERS = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, salesPers);
pstmt.setString(2, currDCRId);
rs = pstmt.executeQuery();
if(rs.next())
{
//lastDCRDate = rs.getString(1) == null ? "" : gridDateFormat.format(convrtToTimStmDate.parse(rs.getString(1)));
lastDCRDate = (rs.getString("LAST_DCR_DATE"));
}
}
if(rs != null)
{
rs.close();
rs =null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception ex)
{
}
return lastDCRDate;
}
/*Added by chetan mahajan on 1-July-2016 for compliance dashboard reports - End*/
}
......@@ -13,4 +13,9 @@ public interface ComplianceDB2Local extends ValidatorLocal
public JSONObject getComplianceHirarchyDB2(String loginId, String dataSourceName,String month) throws RemoteException, ITMException;
public JSONObject getComplianceSummaryDB2(String firstVal, String cellVal, String dataSourceName) throws RemoteException, ITMException;
public JSONObject getComplianceDetailsDB2(String month, String personName, String dataSourceName) throws RemoteException, ITMException;
/*Added by chetan mahajana on 1-July-2016 for compliance dashboard reports - Start*/
public JSONObject getComplMTDSummary(String dataSourceName, String fromDate, String toDate, String salePersons, String loginUser) throws RemoteException, ITMException;
public JSONObject getComplDayWiseSummary(String dataSourceName, String fromDate, String toDate, String selectedName) throws RemoteException, ITMException;
public JSONObject getComplDayWiseDetail(String dataSourceName, String eventDate, String salesPersCode) throws RemoteException, ITMException;
/*Added by chetan mahajana on 1-July-2016 for compliance dashboard reports - End*/
}
......@@ -12,4 +12,9 @@ public interface ComplianceDB2Remote extends ValidatorRemote
public JSONObject getComplianceHirarchyDB2(String loginId, String dataSourceName,String month) throws RemoteException, ITMException;
public JSONObject getComplianceSummaryDB2(String firstVal, String cellVal, String dataSourceName) throws RemoteException, ITMException;
public JSONObject getComplianceDetailsDB2(String month, String personName, String dataSourceName) throws RemoteException, ITMException;
/*Added by chetan mahajana on 1-July-2016 for compliance dashboard reports - Start*/
public JSONObject getComplMTDSummary(String dataSourceName, String fromDate, String toDate, String salePersons, String loginUser) throws RemoteException, ITMException;
public JSONObject getComplDayWiseSummary(String dataSourceName, String fromDate, String toDate, String selectedName) throws RemoteException, ITMException;
public JSONObject getComplDayWiseDetail(String dataSourceName, String eventDate, String salesPersCode) throws RemoteException, ITMException;
/*Added by chetan mahajana on 1-July-2016 for compliance dashboard reports - End*/
}
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