Commit f860c4ac authored by sbalip's avatar sbalip

Variance report related changes

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@183897 ce508802-f39f-4f6c-b175-0d175dae99d5
parent baf2a0c4
......@@ -9,11 +9,9 @@ import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
......@@ -29,10 +27,10 @@ public class VarianceReportMR extends ValidatorEJB implements VarianceReportMRLo
}
@Override
public String getVarianceReportOnGeoPos(String loginCode, String dataSourceName, String fromDateStr, String toDateStr, String dist, String profileId)throws RemoteException, ITMException
public String getVarianceReportOnGeoPos(String loginCode, String dataSourceName, String fromDateStr, String toDateStr, String dist, String teamArgs, String profileId )throws RemoteException, ITMException
{
JSONArray returnJsonArr = new JSONArray();
System.out.println("In getVarianceReportOnGeoPos loginCode["+loginCode+"] dataSourceName["+dataSourceName+"] fromDateStr["+fromDateStr+"] toDateStr["+toDateStr+"] dist["+dist+"] profileId["+profileId+"]");
System.out.println("In getVarianceReportOnGeoPos loginCode["+loginCode+"] dataSourceName["+dataSourceName+"] fromDateStr["+fromDateStr+"] toDateStr["+toDateStr+"] dist["+dist+"] teamArgs["+teamArgs+"] profileId["+profileId+"]");
Connection mConnection = null;
PreparedStatement mStatement = null;
......@@ -68,100 +66,187 @@ public class VarianceReportMR extends ValidatorEJB implements VarianceReportMRLo
toDateStr = e12genericUtil.getValidDateString(toDateStr, e12genericUtil.getApplDateFormat(), e12genericUtil.getDBDateFormat());
System.out.println("fromDateStr["+fromDateStr+"] toDateStr["+toDateStr+"]");
String query = ""; //$NON-NLS-1$
if( "ADMIN".equalsIgnoreCase( profileId.trim() ) )
if( "ADMIN".equalsIgnoreCase( profileId.trim() ) && teamArgs.length() == 0)
{
query = "select s.event_date as EVENT_DATE, f.descr as EVENT, sr.station_type as STATION_TYPE, s.strg_code as CUSTOMER_CODE, c.first_name || ' ' || c.last_name as CUSTOMER_NAME, s.sales_pers as SP_CODE, sp.sp_name as SP_NAME, c.addr1 || ' ' || c.addr2 || ' ' || c.addr3 || ', ' || c.city as ACTUAL_CUSTOMER_ADDRESS, c.geo_pos as GEO_POS, s.chg_geopos as CHG_GEOPOS "+
"from strg_meet s left join strg_customer c on s.strg_code=c.sc_code, sprs_route sr, fieldactivity f, sales_pers sp "+
"where s.event_date between ? and ? and s.event_type='FW' and s.locality_code=sr.locality_code and s.sales_pers=sr.sprs_code and s.event_type = f.activity_code and s.sales_pers = sp.sales_pers order by s.event_date";
query = "SELECT employee.hobby1 as REGION, "+
"(select "+
"emp_fname "+
"||' ' "+
"|| emp_lname from employee where emp_code = supervisor.emp_code) as SUPERVISOR_NAME, "+
"(select descr from station where stan_code = abm.stan_code__hq) as ABM_HQ, "+
"(select descr from station where stan_code = emp.stan_code__hq) as ESI_HQ, "+
"sm.sales_pers as ESI_EMP_CODE, "+
"employee.designation AS ESI_DSG, "+
"employee.emp_fname ||' '|| employee.emp_lname as MR_NAME, "+
"sm.event_date as EVENT_DATE, "+
"sm.strg_code AS CUSTOMER_CODE, "+
"sc.first_name || ' ' || sc.last_name as CUSTOMER_NAME, "+
"custype.sh_descr AS CUSTOMER_TYPE, "+
"sc.addr1 "+
"|| ' ' "+
"|| sc.addr2 "+
"|| ' ' "+
"|| sc.addr3 "+
"|| ', ' "+
"|| sc.city AS ACTUAL_LOCATION, "+
"sc.geo_pos, "+
"sm.chg_geopos, "+
"sm.geo_pos_name AS REPORTED_LOCATION, "+
"sm.chg_date AS REPORTED_DATE, "+
"sm.event_time_end as REPORTED_TIME "+
"FROM strg_meet sm "+
"LEFT JOIN strg_customer sc "+
"ON sm.strg_code=sc.sc_code, "+
"sprs_route sr, "+
"employee employee LEFT OUTER JOIN "+
"org_structure emp on employee.emp_code = emp.emp_code "+
"LEFT OUTER JOIN org_structure abm "+
"ON emp.pos_code__repto = abm.pos_code "+
"LEFT OUTER JOIN org_structure supervisor "+
"ON abm.pos_code__repto = supervisor.pos_code, "+
"strg_cust_type custype "+
"WHERE sm.sales_pers =emp.emp_code "+
"AND sm.locality_code=sr.locality_code "+
"AND sm.sales_pers =sr.sprs_code "+
"AND sm.event_date BETWEEN ? AND ? "+
"AND sm.event_type ='FW' "+
"AND employee.emp_code = sm.sales_pers "+
"AND sm.strg_type = custype.type "+
"ORDER BY sm.event_date";
mStatement = mConnection.prepareStatement(query);
mStatement.setDate(1, java.sql.Date.valueOf(fromDateStr) );
mStatement.setDate(2, java.sql.Date.valueOf(toDateStr) );
}
else
{
query = "select code from users where report_to = ?";
mStatement = mConnection.prepareStatement(query);
mStatement.setString(1,loginCode);
mResultSet = mStatement.executeQuery();
ArrayList<String> subordinateUsers = new ArrayList<String>();
while(mResultSet.next())
{
subordinateUsers.add( mResultSet.getString(1) );
}
if(mStatement!=null)
{
mStatement=null;
}
if(mResultSet!=null)
if( teamArgs.length() == 0 )
{
mResultSet = null;
teamArgs = loginCode;
}
if( subordinateUsers != null && !subordinateUsers.isEmpty() )
{
System.out.println("subordinateUsers:::["+subordinateUsers+"]");
query = "select s.event_date as EVENT_DATE, f.descr as EVENT, sr.station_type as STATION_TYPE, s.strg_code as CUSTOMER_CODE, c.first_name || ' ' || c.last_name as CUSTOMER_NAME, s.sales_pers as SP_CODE, sp.sp_name as SP_NAME, c.addr1 || ' ' || c.addr2 || ' ' || c.addr3 || ', ' || c.city as ACTUAL_CUSTOMER_ADDRESS, c.geo_pos as GEO_POS, s.chg_geopos as CHG_GEOPOS "+
"from strg_meet s left join strg_customer c on s.strg_code=c.sc_code, sprs_route sr, fieldactivity f, sales_pers sp "+
"where s.event_date between ? and ? and s.sales_pers IN ";
String queryIN = "(";
for( int i = 0; i < subordinateUsers.size(); i++)
{
if( i == subordinateUsers.size() -1 )
{
queryIN += "'"+ subordinateUsers.get(i) +"'";
}
else
{
queryIN += "'"+ subordinateUsers.get(i) +"',";
}
}
queryIN += ")";
query += queryIN + " and s.event_type='FW' and s.locality_code=sr.locality_code and s.sales_pers=sr.sprs_code and s.event_type = f.activity_code and s.sales_pers = sp.sales_pers order by s.event_date";
// query = "select code from users where report_to = ?";
// mStatement = mConnection.prepareStatement(query);
// mStatement.setString(1,loginCode);
// mResultSet = mStatement.executeQuery();
// ArrayList<String> subordinateUsers = new ArrayList<String>();
// while(mResultSet.next())
// {
// subordinateUsers.add( mResultSet.getString(1) );
// }
// if(mStatement!=null)
// {
// mStatement.close();
// mStatement=null;
// }
// if(mResultSet!=null)
// {
// mResultSet.close();
// mResultSet = null;
// }
// if( subordinateUsers != null && !subordinateUsers.isEmpty() )
// {
// System.out.println("subordinateUsers:::["+subordinateUsers+"]");
query = "SELECT employee.hobby1 as REGION, "+
"(select "+
"emp_fname "+
"||' ' "+
"|| emp_lname from employee where emp_code = supervisor.emp_code) as SUPERVISOR_NAME, "+
"(select descr from station where stan_code = abm.stan_code__hq) as ABM_HQ, "+
"(select descr from station where stan_code = emp.stan_code__hq) as ESI_HQ, "+
"sm.sales_pers as ESI_EMP_CODE, "+
"employee.designation AS ESI_DSG, "+
"employee.emp_fname ||' '|| employee.emp_lname as MR_NAME, "+
"sm.event_date as EVENT_DATE, "+
"sm.strg_code AS CUSTOMER_CODE, "+
"sc.first_name || ' ' || sc.last_name as CUSTOMER_NAME, "+
"custype.sh_descr AS CUSTOMER_TYPE, "+
"sc.addr1 "+
"|| ' ' "+
"|| sc.addr2 "+
"|| ' ' "+
"|| sc.addr3 "+
"|| ', ' "+
"|| sc.city AS ACTUAL_LOCATION, "+
"sc.geo_pos, "+
"sm.chg_geopos, "+
"sm.geo_pos_name AS REPORTED_LOCATION, "+
"sm.chg_date AS REPORTED_DATE, "+
"sm.event_time_end as REPORTED_TIME "+
"FROM strg_meet sm "+
"LEFT JOIN strg_customer sc "+
"ON sm.strg_code=sc.sc_code, "+
"sprs_route sr, "+
"employee employee LEFT OUTER JOIN "+
"org_structure emp on employee.emp_code = emp.emp_code "+
"LEFT OUTER JOIN org_structure abm "+
"ON emp.pos_code__repto = abm.pos_code "+
"LEFT OUTER JOIN org_structure supervisor "+
"ON abm.pos_code__repto = supervisor.pos_code, "+
"strg_cust_type custype "+
"WHERE sm.sales_pers =emp.emp_code "+
"AND sm.locality_code=sr.locality_code "+
"AND sm.sales_pers =sr.sprs_code "+
"AND sm.event_date BETWEEN ? AND ? "+
"AND emp.emp_code IN "+E12GenericUtility.getFormattedProfileId(teamArgs)+" "+
" AND sm.event_type ='FW' "+
"AND employee.emp_code = sm.sales_pers "+
"AND sm.strg_type = custype.type "+
"ORDER BY sm.event_date";
// String queryIN = "(";
// for( int i = 0; i < subordinateUsers.size(); i++)
// {
// if( i == subordinateUsers.size() -1 )
// {
// queryIN += "'"+ subordinateUsers.get(i) +"'";
// }
// else
// {
// queryIN += "'"+ subordinateUsers.get(i) +"',";
// }
// }
// queryIN += ")";
// query += queryIN + " AND sm.event_type ='FW' "+
// "AND employee.emp_code = sm.sales_pers "+
// "AND sm.strg_type = custype.type "+
// "ORDER BY sm.event_date";
mStatement = mConnection.prepareStatement(query);
mStatement.setDate(1, java.sql.Date.valueOf(fromDateStr) );
mStatement.setDate(2, java.sql.Date.valueOf(toDateStr) );
}
// }
}
mResultSet = mStatement.executeQuery();
//ResultSetMetaData rsmd = mResultSet.getMetaData();
//int colCount = rsmd.getColumnCount();
while (mResultSet.next())
{
String geo_pos = "";
String chg_geopos = "";
JSONObject rowDataVar = new JSONObject();
/*for (int i = 1; i <= colCount; i++)
{
String columnName = rsmd.getColumnName(i);
System.out.println("columnName in loop:::"+columnName);
String value = E12GenericUtility.checkNull(mResultSet.getString(i));
System.out.println("Value in loop:::"+value);
if( "GEO_POS".equalsIgnoreCase( columnName ) )
{
geo_pos = value;
}
if( "CHG_GEOPOS".equalsIgnoreCase( columnName ) )
{
chg_geopos = value;
}
rowDataVar.put(columnName, value);
}*/
rowDataVar.put("EVENT_DATE", e12genericUtil.getValidDateString( E12GenericUtility.checkNull(mResultSet.getDate("EVENT_DATE").toString()), e12genericUtil.getDBDateFormat(), e12genericUtil.getApplDateFormat()) );
rowDataVar.put("EVENT", E12GenericUtility.checkNull(mResultSet.getString("EVENT")));
rowDataVar.put("STATION_TYPE", E12GenericUtility.checkNull(mResultSet.getString("STATION_TYPE")));
rowDataVar.put("CUSTOMER_CODE", E12GenericUtility.checkNull(mResultSet.getString("CUSTOMER_CODE")));
rowDataVar.put("CUSTOMER_NAME", E12GenericUtility.checkNull(mResultSet.getString("CUSTOMER_NAME")));
rowDataVar.put("SP_CODE", E12GenericUtility.checkNull(mResultSet.getString("SP_CODE")));
rowDataVar.put("SP_NAME", E12GenericUtility.checkNull(mResultSet.getString("SP_NAME")));
rowDataVar.put("ACTUAL_CUSTOMER_ADDRESS", E12GenericUtility.checkNull(mResultSet.getString("ACTUAL_CUSTOMER_ADDRESS")));
geo_pos = E12GenericUtility.checkNull(mResultSet.getString("GEO_POS"));
chg_geopos = E12GenericUtility.checkNull(mResultSet.getString("CHG_GEOPOS"));
if( geo_pos.trim().length() > 0 && chg_geopos.trim().length() > 0 )
{
double lat1 = Double.parseDouble( geo_pos.split(",")[0] );
double lng1 = Double.parseDouble( geo_pos.split(",")[1] );
double lat2 = Double.parseDouble( chg_geopos.split(",")[0] );
double lng2 = Double.parseDouble( chg_geopos.split(",")[1] );
if( getLatLngInMtr( lat1, lng1, lat2, lng2 ) > Double.parseDouble( dist ) )
double lat1 = Double.parseDouble( geo_pos.split(",")[0] );
double lng1 = Double.parseDouble( geo_pos.split(",")[1] );
double lat2 = Double.parseDouble( chg_geopos.split(",")[0] );
double lng2 = Double.parseDouble( chg_geopos.split(",")[1] );
long distanceInMtrs = (long) getLatLngInMtr( lat1, lng1, lat2, lng2 );
rowDataVar.put("REGION", E12GenericUtility.checkNull(mResultSet.getString("REGION")));
rowDataVar.put("SUPERVISOR_NAME", E12GenericUtility.checkNull(mResultSet.getString("SUPERVISOR_NAME")));
rowDataVar.put("ABM_HQ", E12GenericUtility.checkNull(mResultSet.getString("ABM_HQ")));
rowDataVar.put("ESI_HQ", E12GenericUtility.checkNull(mResultSet.getString("ESI_HQ")));
rowDataVar.put("ESI_EMP_CODE", E12GenericUtility.checkNull(mResultSet.getString("ESI_EMP_CODE")));
rowDataVar.put("ESI_DSG", E12GenericUtility.checkNull(mResultSet.getString("ESI_DSG")));
rowDataVar.put("MR_NAME", E12GenericUtility.checkNull(mResultSet.getString("MR_NAME")));
rowDataVar.put("EVENT_DATE", e12genericUtil.getValidDateString( E12GenericUtility.checkNull(mResultSet.getDate("EVENT_DATE").toString()), e12genericUtil.getDBDateFormat(), e12genericUtil.getApplDateFormat()) );
rowDataVar.put("CUSTOMER_CODE", E12GenericUtility.checkNull(mResultSet.getString("CUSTOMER_CODE")));
rowDataVar.put("CUSTOMER_NAME", E12GenericUtility.checkNull(mResultSet.getString("CUSTOMER_NAME")));
rowDataVar.put("CUSTOMER_TYPE", E12GenericUtility.checkNull(mResultSet.getString("CUSTOMER_TYPE")));
rowDataVar.put("ACTUAL_LOCATION", E12GenericUtility.checkNull(mResultSet.getString("ACTUAL_LOCATION")));
rowDataVar.put("REPORTED_LOCATION", E12GenericUtility.checkNull(mResultSet.getString("REPORTED_LOCATION")));
rowDataVar.put("DEVIATION_IN_MTRS", E12GenericUtility.checkNull(Long.toString( distanceInMtrs )));
rowDataVar.put("REPORTED_DATE", e12genericUtil.getValidDateString( E12GenericUtility.checkNull(mResultSet.getDate("REPORTED_DATE").toString()), e12genericUtil.getDBDateFormat(), e12genericUtil.getApplDateFormat()) );
rowDataVar.put("REPORTED_TIME", E12GenericUtility.checkNull(mResultSet.getString("REPORTED_TIME")));
if( distanceInMtrs > Double.parseDouble( dist ) )
{
returnJsonArr.add(rowDataVar);
}
......
......@@ -8,7 +8,7 @@ import javax.ejb.Local;
@Local
public abstract interface VarianceReportMRLocal extends ValidatorLocal
{
public String getVarianceReportOnGeoPos(String loginCode,String dataSourceName,String fromDate,String toDate, String dist, String profileId)throws RemoteException, ITMException;
public String getVarianceReportOnGeoPos(String loginCode,String dataSourceName,String fromDate,String toDate, String dist, String teamArgs, String profileId)throws RemoteException, ITMException;
}
......@@ -8,6 +8,6 @@ import javax.ejb.Remote;
@Remote
public abstract interface VarianceReportMRRemote extends ValidatorRemote
{
public String getVarianceReportOnGeoPos(String loginCode,String dataSourceName,String fromDate,String toDate, String dist, String profileId)throws RemoteException, ITMException;
public String getVarianceReportOnGeoPos(String loginCode,String dataSourceName,String fromDate,String toDate, String dist, String teamArgs, String profileId)throws RemoteException, ITMException;
}
......@@ -2,6 +2,7 @@ package ibase.dashboard.sfa.servlet;
import ibase.dashboard.sfa.ejb.VarianceReportMRLocal;
import ibase.system.config.AppConnectParm;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
......@@ -39,6 +40,7 @@ public class MeetVarianceServlet extends HttpServlet
String fromDate = "";
String dist = "";
String profileId = "";
String teamArgs = "";
try
{
......@@ -52,12 +54,13 @@ public class MeetVarianceServlet extends HttpServlet
{
dataSourceName = userInfo.getTransDB();
}
fromDate = request.getParameter("from_date");
toDate = request.getParameter("to_date");
dist = request.getParameter("min_distance");
fromDate = E12GenericUtility.checkNull(request.getParameter("from_date"));
toDate = E12GenericUtility.checkNull(request.getParameter("to_date"));
dist = E12GenericUtility.checkNull(request.getParameter("min_distance"));
teamArgs = E12GenericUtility.checkNull(request.getParameter("my_team"));
context = new InitialContext(appConnectParm.getProperty());
meetVarianceLocal = (VarianceReportMRLocal) context.lookup("ibase/VarianceReportMR/local");
jsonObjData = (String) meetVarianceLocal.getVarianceReportOnGeoPos(loginCode,dataSourceName,fromDate,toDate,dist,profileId);
jsonObjData = (String) meetVarianceLocal.getVarianceReportOnGeoPos(loginCode,dataSourceName,fromDate,toDate,dist,teamArgs,profileId);
outputStream = response.getOutputStream();
outputStream.write(jsonObjData.getBytes());
outputStream.flush();
......
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