Commit ed8a604a authored by prumde's avatar prumde

Added method getPlaceWorkDetails

Changes for setting dateCondition depending on FromDate and ToDate provided

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@211137 ce508802-f39f-4f6c-b175-0d175dae99d5
parent fd66b90c
...@@ -39,6 +39,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -39,6 +39,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
JSONArray workSummary = new JSONArray(); JSONArray workSummary = new JSONArray();
JSONObject workData = null; JSONObject workData = null;
String sql = ""; String sql = "";
String dateCondition = "";
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
Connection conn = null; Connection conn = null;
...@@ -53,7 +54,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -53,7 +54,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
salePerson = dashboardUtility.getCommaSeparated(salePerson); salePerson = dashboardUtility.getCommaSeparated(salePerson);
fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); dateCondition = " = TO_DATE('"+fromDate+"','YYYY-MM-dd') ";
if( toDate != null )
{
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
dateCondition = " BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')";
}
System.out.println("In ConsumerGoodsCRM getWorkSummary After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]"); System.out.println("In ConsumerGoodsCRM getWorkSummary After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]");
...@@ -70,7 +77,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -70,7 +77,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" And Sc_Code in (Select sC_cODE From STRG_CUSTOMER_RETAIL " + " And Sc_Code in (Select sC_cODE From STRG_CUSTOMER_RETAIL " +
" Where Locality_Code In (Select locality_Code From sPRS_TRAVEL " + " Where Locality_Code In (Select locality_Code From sPRS_TRAVEL " +
" Where Sales_Pers = SM.Sales_Pers " + " Where Sales_Pers = SM.Sales_Pers " +
" AND travel_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND travel_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND travel_date " + dateCondition +
" )) ),0) AS To_Calls , " + " )) ),0) AS To_Calls , " +
" nvl((select count(*) from STRG_MEET_ORDER SMO " + " nvl((select count(*) from STRG_MEET_ORDER SMO " +
" where SMO.dcr_id=SM.dcr_id and SMO.Quantity > 0),0) as TLSD , " + " where SMO.dcr_id=SM.dcr_id and SMO.Quantity > 0),0) as TLSD , " +
...@@ -81,7 +89,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -81,7 +89,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" nvl((select count(distinct strg_code) from STRG_ITEM_DISPLAY SID " + " nvl((select count(distinct strg_code) from STRG_ITEM_DISPLAY SID " +
" where SID.dcr_id=SM.dcr_id),0) as Display " + " where SID.dcr_id=SM.dcr_id),0) as Display " +
" FROM Strg_Meet SM ,Sales_Pers SP Where SM.Sales_Pers = SP.Sales_Pers " + " FROM Strg_Meet SM ,Sales_Pers SP Where SM.Sales_Pers = SP.Sales_Pers " +
" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND SM.event_date " + dateCondition +
" And SM.Sales_Pers In ( Select Emp_Code " + " And SM.Sales_Pers In ( Select Emp_Code " +
" From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " + " From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " +
" Connect By Prior Emp_Code =Report_To )" + " Connect By Prior Emp_Code =Report_To )" +
...@@ -148,11 +157,22 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -148,11 +157,22 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
workDetail.put("color", "#c26be9"); workDetail.put("color", "#c26be9");
workDetails.add(workDetail); workDetails.add(workDetail);
workDetail = new JSONObject(); if( toDate != null )
workDetail.put("count", checkNull(callBal)); {
workDetail.put("value", "Call Balance"); workDetail = new JSONObject();
workDetail.put("color", "#ffca3b"); workDetail.put("count", checkNull(callBal));
workDetails.add(workDetail); workDetail.put("value", "Eco");
workDetail.put("color", "#ffca3b");
workDetails.add(workDetail);
}
else
{
workDetail = new JSONObject();
workDetail.put("count", checkNull(callBal));
workDetail.put("value", "Call Balance");
workDetail.put("color", "#ffca3b");
workDetails.add(workDetail);
}
workData.put("workDetails", workDetails); workData.put("workDetails", workDetails);
...@@ -202,6 +222,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -202,6 +222,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
{ {
JSONArray kpiSummary = new JSONArray(); JSONArray kpiSummary = new JSONArray();
String sql = ""; String sql = "";
String dateCondition = "";
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
Connection conn = null; Connection conn = null;
...@@ -216,7 +237,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -216,7 +237,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
salePerson = dashboardUtility.getCommaSeparated(salePerson); salePerson = dashboardUtility.getCommaSeparated(salePerson);
fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); dateCondition = " = TO_DATE('"+fromDate+"','YYYY-MM-dd') ";
if( toDate != null )
{
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
dateCondition = " BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd') ";
}
System.out.println("In ConsumerGoodsCRM getKPISummary After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]"); System.out.println("In ConsumerGoodsCRM getKPISummary After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]");
...@@ -241,7 +268,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -241,7 +268,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" Sales_Pers SP , " + " Sales_Pers SP , " +
" FieldActivity FA " + " FieldActivity FA " +
" Where SM.Sales_Pers = SP.Sales_Pers And FA.Activity_Code = SM.Event_Type " + " Where SM.Sales_Pers = SP.Sales_Pers And FA.Activity_Code = SM.Event_Type " +
" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND SM.event_date " + dateCondition +
" And SM.Sales_Pers In ( Select Emp_Code " + " And SM.Sales_Pers In ( Select Emp_Code " +
" From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " + " From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " +
" Connect By Prior Emp_Code =Report_To )" + " Connect By Prior Emp_Code =Report_To )" +
...@@ -261,7 +289,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -261,7 +289,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" Strg_Meet_Order SMO " + " Strg_Meet_Order SMO " +
" Where SM.Sales_Pers = SP.Sales_Pers " + " Where SM.Sales_Pers = SP.Sales_Pers " +
" And SM.Strg_Code = SMO.Strg_Code And SM.Dcr_Id = SMO.DCR_Id " + " And SM.Strg_Code = SMO.Strg_Code And SM.Dcr_Id = SMO.DCR_Id " +
" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND SM.event_date " + dateCondition +
" And SM.Sales_Pers In ( Select Emp_Code " + " And SM.Sales_Pers In ( Select Emp_Code " +
" From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " + " From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " +
" Connect By Prior Emp_Code =Report_To )" + " Connect By Prior Emp_Code =Report_To )" +
...@@ -279,11 +308,12 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -279,11 +308,12 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
JSONObject kpiInfo = null; JSONObject kpiInfo = null;
JSONObject summary = null; JSONObject summary = null;
JSONObject detail = null; JSONObject detail = null;
JSONObject workDtl = getWorkDtl(dataSourceName, fromDate, toDate, salePerson); //JSONObject workDtl = getWorkDtl(dataSourceName, fromDate, toDate, salePerson);
JSONObject workDtl = getWorkDtl(dataSourceName, dateCondition, salePerson);
kpiInfo = new JSONObject(); kpiInfo = new JSONObject();
detail = new JSONObject(); detail = new JSONObject();
detail.put("keyName", "Todays Calls"); detail.put("keyName", "Total Calls");
detail.put("keyValue", checkNull(rs.getString("TOT_CALLS"))); detail.put("keyValue", checkNull(rs.getString("TOT_CALLS")));
detail.put("color", "#89cbfc"); detail.put("color", "#89cbfc");
kpiInfo.put("detail",detail); kpiInfo.put("detail",detail);
...@@ -302,12 +332,27 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -302,12 +332,27 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
detail.put("color", "#86e8c6"); detail.put("color", "#86e8c6");
kpiInfo.put("detail",detail); kpiInfo.put("detail",detail);
summary = new JSONObject(); if( toDate != null )
summary.put("keyName", "Call Balance"); {
summary.put("keyValue", String.valueOf(totalCallBal)); summary = new JSONObject();
summary.put("color", "#ffca3b"); summary.put("keyName", "Eco");
kpiInfo.put("summary",summary); String economy = checkNull(rs.getString("ECO"));
kpiSummary.add(kpiInfo); economy = economy.length() == 0 ? "0" : economy;
detail.put("keyValue", economy );
summary.put("color", "#ffca3b");
kpiInfo.put("summary",summary);
kpiSummary.add(kpiInfo);
}
else
{
summary = new JSONObject();
summary.put("keyName", "Call Balance");
summary.put("keyValue", String.valueOf(totalCallBal));
summary.put("color", "#ffca3b");
kpiInfo.put("summary",summary);
kpiSummary.add(kpiInfo);
}
kpiInfo = new JSONObject(); kpiInfo = new JSONObject();
detail = new JSONObject(); detail = new JSONObject();
...@@ -374,7 +419,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -374,7 +419,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
return kpiSummary; return kpiSummary;
} }
public JSONObject getWorkDtl(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException //public JSONObject getWorkDtl(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException
public JSONObject getWorkDtl(String dataSourceName, String dateCondition, String salePerson) throws RemoteException, ITMException
{ {
JSONObject workDetl = new JSONObject(); JSONObject workDetl = new JSONObject();
String sql = ""; String sql = "";
...@@ -387,7 +433,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -387,7 +433,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
{ {
conn = connDriver.getConnectDB(dataSourceName); conn = connDriver.getConnectDB(dataSourceName);
connDriver = null; connDriver = null;
System.out.println("In ConsumerGoodsCRM getWorkDtl After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]"); //System.out.println("In ConsumerGoodsCRM getWorkDtl After format :: fromDate:["+fromDate+"] toDate:["+toDate+"]");
System.out.println("In ConsumerGoodsCRM getWorkDtl After format :: dateCondition:["+dateCondition+"]");
sql = " Select count(Sku_Name) as Sku_Name , nvl(sum(outlet_booked),0) as outlet_booked " + sql = " Select count(Sku_Name) as Sku_Name , nvl(sum(outlet_booked),0) as outlet_booked " +
" from( " + " from( " +
...@@ -403,7 +450,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -403,7 +450,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" And SM.Strg_Code = SMO.Strg_Code " + " And SM.Strg_Code = SMO.Strg_Code " +
" And SM.Dcr_Id = SMO.DCR_Id " + " And SM.Dcr_Id = SMO.DCR_Id " +
" And I.Item_Code = SMO.Item_Code " + " And I.Item_Code = SMO.Item_Code " +
" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND SM.event_date " + dateCondition +
" And SM.Sales_Pers In ( Select Emp_Code " + " And SM.Sales_Pers In ( Select Emp_Code " +
" From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " + " From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+") " +
" Connect By Prior Emp_Code =Report_To )" + " Connect By Prior Emp_Code =Report_To )" +
...@@ -462,12 +510,14 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -462,12 +510,14 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public JSONArray getWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException //public JSONArray getWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException
public JSONArray getItemWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException
{ {
JSONArray workDetails = new JSONArray(); JSONArray workDetails = new JSONArray();
JSONArray finalWorkDetails = new JSONArray(); JSONArray finalWorkDetails = new JSONArray();
JSONObject salesPersDetails = new JSONObject(); JSONObject salesPersDetails = new JSONObject();
String sql = ""; String sql = "";
String dateCondition = "";
ResultSet rs = null; ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
Connection conn = null; Connection conn = null;
...@@ -482,7 +532,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -482,7 +532,13 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
salePerson = dashboardUtility.getCommaSeparated(salePerson); salePerson = dashboardUtility.getCommaSeparated(salePerson);
fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() ); dateCondition = " = TO_DATE('"+fromDate+"','YYYY-MM-dd') ";
if( toDate != null )
{
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
dateCondition = " BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd') ";
}
sql = " Select sm.sales_pers ,SP.SP_Name as SalesPerson_Name, I.Descr AS Sku_Name" + sql = " Select sm.sales_pers ,SP.SP_Name as SalesPerson_Name, I.Descr AS Sku_Name" +
" ,Sum(SMO.Quantity) as Qty_Booked" + " ,Sum(SMO.Quantity) as Qty_Booked" +
...@@ -495,7 +551,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -495,7 +551,8 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" And SM.Strg_Code = SMO.Strg_Code" + " And SM.Strg_Code = SMO.Strg_Code" +
" And SM.Dcr_Id = SMO.DCR_Id" + " And SM.Dcr_Id = SMO.DCR_Id" +
" And I.Item_Code = SMO.Item_Code" + " And I.Item_Code = SMO.Item_Code" +
" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" + //" AND SM.event_date BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd')" +
" AND SM.event_date " + dateCondition +
" And SM.Sales_Pers In ( Select Emp_Code" + " And SM.Sales_Pers In ( Select Emp_Code" +
" From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+")" + " From Employee Start With Emp_code = (Select Emp_Code From Users Where Code = "+salePerson+")" +
" Connect By Prior Emp_Code =Report_To )" + " Connect By Prior Emp_Code =Report_To )" +
...@@ -503,7 +560,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -503,7 +560,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
" Group By sm.sales_pers ,SP.SP_Name ,I.Descr" + " Group By sm.sales_pers ,SP.SP_Name ,I.Descr" +
" Order By SalesPerson_Name,Sku_Name"; " Order By SalesPerson_Name,Sku_Name";
System.out.println("In ConsumerGoodsCRM getWorkDetail sql: ---- ["+sql+"]"); System.out.println("In ConsumerGoodsCRM getItemWorkDetails sql: ---- ["+sql+"]");
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
...@@ -587,7 +644,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -587,7 +644,7 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
} catch (Exception d) } catch (Exception d)
{ {
d.printStackTrace(); d.printStackTrace();
System.out.println("Exception in ConsumerGoodsCRM:getWorkDetail" + d.getMessage()); System.out.println("Exception in ConsumerGoodsCRM:getItemWorkDetails" + d.getMessage());
throw new ITMException(d); throw new ITMException(d);
} }
} }
...@@ -595,6 +652,186 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo ...@@ -595,6 +652,186 @@ public class ConsumerGoodsCRM extends ValidatorEJB implements ConsumerGoodsCRMLo
return finalWorkDetails; return finalWorkDetails;
} }
public JSONArray getPlaceWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException
{
JSONArray finalWorkDetails = new JSONArray();
String sql = "";
String dateCondition = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
DashboardUtility dashboardUtility = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
dashboardUtility = new DashboardUtility();
salePerson = dashboardUtility.getCommaSeparated(salePerson);
fromDate = genericUtility.getValidDateString( fromDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
dateCondition = " = TO_DATE('"+fromDate+"','YYYY-MM-dd') ";
if( toDate != null )
{
toDate = genericUtility.getValidDateString( toDate, genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat() );
dateCondition = " BETWEEN TO_DATE('"+fromDate+"','YYYY-MM-dd') and TO_DATE('"+toDate+"','YYYY-MM-dd') ";
}
StringBuffer sqlBuff = new StringBuffer();
sqlBuff.append(" SELECT ");
sqlBuff.append(" STRG_MEET.SALES_PERS AS SALESPERSONCODE, ");
sqlBuff.append(" SALES_PERS.SP_NAME AS SALESPERSON, ");
sqlBuff.append(" TO_CHAR(TO_DATE(STRG_MEET.EVENT_DATE),'DD-MON-YYYY') AS EVENT_DATE, ");
sqlBuff.append(" LOC.DESCR AS LOCALITY, ");
sqlBuff.append(" COALESCE( (SELECT EMPLOYEE.NAME_PREFIX || ' ' || EMPLOYEE.EMP_FNAME || ' ' || EMPLOYEE.EMP_LNAME FROM EMPLOYEE WHERE EMPLOYEE.EMP_CODE = SALES_PERS1.SALES_PERS ),'Self') AS VISITED_WITH, ");
sqlBuff.append(" LISTAGG(STRG_MEET.STRG_CODE, ',') WITHIN GROUP (ORDER BY STRG_MEET.STRG_CODE) AS STRG_CODE, ");
sqlBuff.append(" NVL(COUNT(STRG_MEET.STRG_CODE),0) AS TOT_CALLS , ");
sqlBuff.append(" NVL((SELECT COUNT(DISTINCT STRG_CODE) FROM STRG_ITEM_DISPLAY SID WHERE SID.DCR_ID=STRG_MEET.DCR_ID),0) AS DISPLAY , ");
sqlBuff.append(" FN_R_TOT_PC(STRG_MEET.DCR_ID,STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS,STRG_MEET.LOCALITY_CODE) AS TOT_PC , ");
sqlBuff.append(" ROUND(( CASE WHEN FN_R_FW_CUMM_DAYS(STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS) = 0 THEN 0 ");
sqlBuff.append(" ELSE FN_R_CUMM_SMO(STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS)/FN_R_FW_CUMM_DAYS(STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS) END),2) AS TLSD , ");
sqlBuff.append(" FN_R_CUMM_SMO(STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS) AS DAY_TLSD, ");
sqlBuff.append(" FN_R_FW_CUMM_DAYS(STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS) AS DAY_COUNT, ");
sqlBuff.append(" FN_R_ORD_VAL(STRG_MEET.DCR_ID,STRG_MEET.EVENT_DATE,STRG_MEET.SALES_PERS,STRG_MEET.LOCALITY_CODE) AS ORD_VAL ");
sqlBuff.append(" FROM SALES_PERS ");
sqlBuff.append(" INNER JOIN STRG_MEET ON SALES_PERS.SALES_PERS = STRG_MEET.SALES_PERS ");
sqlBuff.append(" INNER JOIN LOCALITY LOC ON LOC.LOCALITY_CODE = STRG_MEET.LOCALITY_CODE ");
sqlBuff.append(" LEFT JOIN SPRS_TRAVEL SPT ON STRG_MEET.DCR_ID = SPT.DCR_ID AND STRG_MEET.SALES_PERS = SPT.SALES_PERS AND SPT.LOCALITY_CODE = STRG_MEET.LOCALITY_CODE ");
sqlBuff.append(" LEFT JOIN SALES_PERS SALES_PERS1 ON SALES_PERS1.SALES_PERS = SPT.SPRS_CODE__WW ");
sqlBuff.append(" WHERE SALES_PERS.SALES_PERS IN (SELECT EMP_CODE FROM EMPLOYEE START WITH EMP_CODE = (SELECT EMP_CODE FROM USERS WHERE CODE = " + salePerson + ") CONNECT BY PRIOR EMP_CODE =REPORT_TO ) ");
sqlBuff.append(" AND STRG_MEET.EVENT_DATE ").append( dateCondition );
sqlBuff.append(" GROUP BY STRG_MEET.SALES_PERS, SALES_PERS.SP_NAME, STRG_MEET.EVENT_DATE, STRG_MEET.DCR_ID, STRG_MEET.LOCALITY_CODE, LOC.DESCR, SALES_PERS1.SALES_PERS ");
sqlBuff.append(" ORDER BY SALESPERSON, EVENT_DATE, VISITED_WITH, LOCALITY ");
sql = sqlBuff.toString();
System.out.println("In ConsumerGoodsCRM getPlaceWorkDetails sql: ---- ["+sql+"]");
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
/*
SALESPERSONCODE,
SALESPERSON,
EVENT_DATE,
LOCALITY,
VISITED_WITH,
STRG_CODE,
TOT_CALLS,
DISPLAY,
TOT_PC,
TLSD,
DAY_TLSD,
DAY_COUNT,
ORD_VAL
*/
while (rs.next())
{
JSONObject workDetail = new JSONObject();
String salesPers = checkNull(rs.getString("SALESPERSONCODE"));
String salesPersName = checkNull(rs.getString("SALESPERSON"));
String eventDate = checkNull(rs.getString("EVENT_DATE"));
String locality = checkNull(rs.getString("LOCALITY"));
String visitedWith = checkNull(rs.getString("VISITED_WITH"));
String strgCode = checkNull(rs.getString("STRG_CODE"));
String totalCalls = checkNull(rs.getString("TOT_CALLS"));
String display = checkNull(rs.getString("DISPLAY"));
String totalProdCalls = checkNull(rs.getString("TOT_PC"));
String tlsdVal = checkNull(rs.getString("TLSD"));
String tlsdDays = checkNull(rs.getString("DAY_TLSD"));
String dayCount = checkNull(rs.getString("DAY_COUNT"));
String orderVal = checkNull(rs.getString("ORD_VAL"));
String hostUrl = CommonConstants.TOMCAT_HOME;
String salesPersImg = hostUrl+"/ibase/CustomMenuImageServlet?fldValue="+salesPers+"&ALT_FLD_VALUE="+salesPersName;
workDetail.put("salesPers", salesPers);
workDetail.put("salesPersName", salesPersName);
workDetail.put("salesPersImg", salesPersImg);
workDetail.put("eventDate", eventDate);
workDetail.put("locality", locality);
workDetail.put("visitedWith", visitedWith);
workDetail.put("strgCode", strgCode);
//workDetail.put("totalCalls", totalCalls);
//workDetail.put("display", display);
//workDetail.put("totalProdCalls", totalProdCalls);
workDetail.put("tlsdVal", tlsdVal);
workDetail.put("tlsdDays", tlsdDays);
workDetail.put("dayCount", dayCount);
//workDetail.put("orderVal", orderVal);
JSONArray workDetailsKPI = new JSONArray();
JSONObject workDetailKPI = null;
workDetailKPI = new JSONObject();
workDetailKPI.put("count", totalCalls);
workDetailKPI.put("value", "TC");
workDetailKPI.put("color", "#89cbfc");
workDetailsKPI.add(workDetailKPI);
workDetailKPI = new JSONObject();
workDetailKPI.put("count", totalProdCalls);
workDetailKPI.put("value", "PC");
workDetailKPI.put("color", "#86e8c6");
workDetailsKPI.add(workDetailKPI);
workDetailKPI = new JSONObject();
workDetailKPI.put("count", orderVal);
workDetailKPI.put("value", "Orders");
workDetailKPI.put("color", "#c0b9f6");
workDetailsKPI.add(workDetailKPI);
workDetailKPI = new JSONObject();
workDetailKPI.put("count", checkNull(display));
workDetailKPI.put("value", "Display");
workDetailKPI.put("color", "#f9af92");
workDetailsKPI.add(workDetailKPI);
workDetail.put("workDetailsKPI", workDetailsKPI);
finalWorkDetails.add(workDetail);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
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 ConsumerGoodsCRM:getPlaceWorkDetails" + d.getMessage());
throw new ITMException(d);
}
}
return finalWorkDetails;
}
private String getProductInitals(String productName) private String getProductInitals(String productName)
{ {
String[] myName = productName.split(" "); String[] myName = productName.split(" ");
......
...@@ -13,5 +13,6 @@ public interface ConsumerGoodsCRMLocal extends ValidatorLocal ...@@ -13,5 +13,6 @@ public interface ConsumerGoodsCRMLocal extends ValidatorLocal
{ {
public JSONArray getWorkSummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getWorkSummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getKPISummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getKPISummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getItemWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getPlaceWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
} }
...@@ -12,5 +12,6 @@ public interface ConsumerGoodsCRMRemote extends ValidatorRemote ...@@ -12,5 +12,6 @@ public interface ConsumerGoodsCRMRemote extends ValidatorRemote
{ {
public JSONArray getWorkSummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getWorkSummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getKPISummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getKPISummary(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException; public JSONArray getItemWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) throws RemoteException, ITMException;
public JSONArray getPlaceWorkDetails(String dataSourceName, String fromDate, String toDate, String salePerson) 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