Commit d218a3d3 authored by sbade's avatar sbade

updated aql for dashboard data as per given bye client


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@97780 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 85c104c8
package ibase.dashboard.scm.ejb; package ibase.dashboard.scm.ejb;
import ibase.dashboard.Report.Utility.DashboardUtility; import ibase.dashboard.Report.Utility.DashboardUtility;
import ibase.system.config.ConnDriver; import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB; import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility; import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashMap; import java.util.Map;
import java.util.List;
import java.util.Map; import javax.ejb.Stateless;
import javax.ejb.Stateless; import org.json.simple.JSONObject;
import org.json.simple.JSONObject; /**
* Session Bean implementation class CustomerInfoEJB
/** */
* Session Bean implementation class CustomerInfoEJB @Stateless
*/ public class CustomerInfoEJB extends ValidatorEJB implements CustomerInfoRemote, CustomerInfoLocal {
@Stateless
public class CustomerInfoEJB extends ValidatorEJB implements CustomerInfoRemote, CustomerInfoLocal { /**
* Default constructor.
/** */
* Default constructor. public CustomerInfoEJB() {
*/
public CustomerInfoEJB() { }
GenericUtility genericUtility = GenericUtility.getInstance();
} @SuppressWarnings("unchecked")
GenericUtility genericUtility = GenericUtility.getInstance(); @Override
@SuppressWarnings("unchecked") public JSONObject getCurrentReceivable(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@Override {
public JSONObject getCurrentReceivable(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException JSONObject rawDataCurntRecvbleJson = null;
{ JSONObject rowData = null;
JSONObject rawDataCurntRecvbleJson = null; String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; //DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); Date frmDate = null;
DashboardUtility dashbordUtil = null; Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try System.out.println(" Inside CustomerInfoEJB for getCurrentReceivable Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
{ DashboardUtility dashbordUtil = new DashboardUtility();
System.out.println(" Inside CustomerInfoEJB for getCurrentReceivable Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); conn = connDriver.getConnectDB(dataSourceName);
dashbordUtil = new DashboardUtility(); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName); rawDataCurntRecvbleJson = new JSONObject();
connDriver = null; SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
rawDataCurntRecvbleJson = new JSONObject(); SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat()); if(lastMonth!=null && lastMonth.trim().length()>0 )
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat()); {
if(lastMonth!=null && lastMonth.trim().length()>0 ) Calendar cal = Calendar.getInstance();
{ toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Calendar cal = Calendar.getInstance(); cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
cal.get(Calendar.MONTH + 1); int month = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE)); }
/** start of Customer name top custoer code conversion**/
} custCode = dashbordUtil.getCommaSeparated(custCode);
/** start of Customer name top custoer code conversion**/ System.out.println("in recceivalble:"+custCode+":");
custCode = dashbordUtil.getCommaSeparated(custCode); /** end of Customer name top custoer code conversion**/
System.out.println("in recceivalble:"+custCode+":");
/** end of Customer name top custoer code conversion**/ if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null)
{
if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null) sql = " SELECT A.SITE_CODE,A.CUST_CODE,B.CUST_NAME,A.TRAN_SER,A.REF_NO,A.REF_DATE,A.CURR_CODE, "
{ +" A.EXCH_RATE,TOT_AMT,ADJ_AMT,(TOT_AMT-ADJ_AMT) BAL_AMT, DUE_DATE,trunc(sysdate-DUE_DATE ) as days,A.CR_TERM "
sql = " SELECT A.SITE_CODE,A.CUST_CODE,B.CUST_NAME,A.TRAN_SER,A.REF_NO,A.REF_DATE,A.CURR_CODE, " +" FROM RECEIVABLES A,CUSTOMER B WHERE A.CUST_CODE=B.CUST_CODE AND "
+" A.EXCH_RATE,TOT_AMT,ADJ_AMT,(TOT_AMT-ADJ_AMT) BAL_AMT, DUE_DATE,trunc(sysdate-DUE_DATE ) as days,A.CR_TERM " +" A.CUST_CODE IN ("+custCode+") AND A.REF_DATE between ? and ? "
+" FROM RECEIVABLES A,CUSTOMER B WHERE A.CUST_CODE=B.CUST_CODE AND " +" and TOT_AMT-ADJ_AMT<>0";
+" A.CUST_CODE IN ("+custCode+") AND A.REF_DATE between ? and ? "
+" and TOT_AMT-ADJ_AMT<>0"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
int count = 0;
rs = pstmt.executeQuery(); while (rs.next())
int count = 0; {
while (rs.next()) rowData = new JSONObject();
{ rowData.put("site_code", checkNull(rs.getString("SITE_CODE")));
rowData = new JSONObject(); rowData.put("cust_code", checkNull(rs.getString("CUST_CODE")));
rowData.put("site_code", checkNull(rs.getString("SITE_CODE"))); rowData.put("cust_name", checkNull(rs.getString("CUST_NAME")));
rowData.put("cust_code", checkNull(rs.getString("CUST_CODE"))); rowData.put("tran_ser", checkNull(rs.getString("TRAN_SER")));
rowData.put("cust_name", checkNull(rs.getString("CUST_NAME"))); rowData.put("ref_no", checkNull(rs.getString("REF_NO")));
rowData.put("tran_ser", checkNull(rs.getString("TRAN_SER"))); String refDate =checkNull(rs.getString("REF_DATE"));
rowData.put("ref_no", checkNull(rs.getString("REF_NO")));
String refDate =checkNull(rs.getString("REF_DATE")); if(refDate.trim().length()>0)
{
if(refDate.trim().length()>0) rowData.put("ref_date", gridDateFormat.format(convrtToTimStmDate.parse(refDate)));
{ }
rowData.put("ref_date", gridDateFormat.format(convrtToTimStmDate.parse(refDate))); else
} {
else rowData.put("ref_date",checkNull(rs.getString("REF_DATE")));
{ }
rowData.put("ref_date",checkNull(rs.getString("REF_DATE"))); rowData.put("curr_code",checkNull( rs.getString("CURR_CODE")));
} rowData.put("exch_rate", checkNull(rs.getString("EXCH_RATE")));
rowData.put("curr_code",checkNull( rs.getString("CURR_CODE"))); rowData.put("tot_amt", checkNull(rs.getString("TOT_AMT")));
rowData.put("exch_rate", checkNull(rs.getString("EXCH_RATE"))); rowData.put("adj_amt",checkNull( rs.getString("ADJ_AMT")));
rowData.put("tot_amt", checkNull(rs.getString("TOT_AMT"))); rowData.put("bal_amt", checkNull(rs.getString("BAL_AMT")));
rowData.put("adj_amt",checkNull( rs.getString("ADJ_AMT"))); String dueDate =checkNull(rs.getString("due_date"));
rowData.put("bal_amt", checkNull(rs.getString("BAL_AMT"))); if(dueDate.trim().length()>0)
String dueDate =checkNull(rs.getString("due_date")); {
if(dueDate.trim().length()>0) rowData.put("due_date", gridDateFormat.format(convrtToTimStmDate.parse(dueDate)));
{ }
rowData.put("due_date", gridDateFormat.format(convrtToTimStmDate.parse(dueDate))); else
} {
else rowData.put("due_date",checkNull (rs.getString("DUE_DATE")));
{ }
rowData.put("due_date",checkNull (rs.getString("DUE_DATE"))); rowData.put("cr_term", checkNull(rs.getString("CR_TERM")));
} rawDataCurntRecvbleJson.put(count, rowData);
rowData.put("cr_term", checkNull(rs.getString("CR_TERM"))); count++;
rawDataCurntRecvbleJson.put(count, rowData); }
count++; }
} }
} catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getCurrentReceivable Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getCurrentReceivable Method :" + d.getMessage()); }
throw new ITMException(d); }
} return rawDataCurntRecvbleJson;
}
return rawDataCurntRecvbleJson; }
} //Add new method for create a Pie chart
//Add new method for create a Pie chart
@SuppressWarnings("unchecked")
public JSONObject getCurrentReceivableChartView(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@SuppressWarnings("unchecked") {
public JSONObject getCurrentReceivableChartView(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException JSONObject rawDataCurntRecvbleChartJson = null;
{ JSONObject rowData = null;
JSONObject rawDataCurntRecvbleChartJson = null; String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); Date frmDate = null;
DashboardUtility dashbordUtil = null; Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try System.out.println(" Inside CustomerInfoEJB for getCurrentReceivableChartView Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
{ conn = connDriver.getConnectDB(dataSourceName);
System.out.println(" Inside CustomerInfoEJB for getCurrentReceivableChartView Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName); rawDataCurntRecvbleChartJson = new JSONObject();
connDriver = null;
rawDataCurntRecvbleChartJson = new JSONObject(); SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat()); if(lastMonth!=null && lastMonth.trim().length()>0 )
{
if(lastMonth!=null && lastMonth.trim().length()>0 ) Calendar cal = Calendar.getInstance();
{ toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Calendar cal = Calendar.getInstance(); cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
cal.get(Calendar.MONTH + 1); int month = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE)); }
//end date conversion form
}
//end date conversion form dashbordUtil = new DashboardUtility();
dashbordUtil = new DashboardUtility(); /** start of Customer name top custoer code conversion**/
custCode = dashbordUtil.getCommaSeparated(custCode);
/** start of Customer name top custoer code conversion**/ System.out.println("in recceivalble:"+custCode+":");
custCode = dashbordUtil.getCommaSeparated(custCode); /** end of Customer name top custoer code conversion**/
System.out.println("in recceivalble:"+custCode+":");
/** end of Customer name top custoer code conversion**/ if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null)
{
if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null) sql = " SELECT sum (bal_amt) as balAmt,days from (SELECT A.SITE_CODE,A.CUST_CODE,B.CUST_NAME,A.TRAN_SER,A.REF_NO,A.REF_DATE,A.CURR_CODE, "
{ +" A.EXCH_RATE,TOT_AMT,ADJ_AMT,(TOT_AMT-ADJ_AMT) BAL_AMT, DUE_DATE,trunc(sysdate-DUE_DATE ) as days,A.CR_TERM "
sql = " SELECT sum (bal_amt) as balAmt,days from (SELECT A.SITE_CODE,A.CUST_CODE,B.CUST_NAME,A.TRAN_SER,A.REF_NO,A.REF_DATE,A.CURR_CODE, " +" FROM RECEIVABLES A,CUSTOMER B WHERE A.CUST_CODE=B.CUST_CODE "
+" A.EXCH_RATE,TOT_AMT,ADJ_AMT,(TOT_AMT-ADJ_AMT) BAL_AMT, DUE_DATE,trunc(sysdate-DUE_DATE ) as days,A.CR_TERM " +" and A.CUST_CODE IN ("+custCode+") AND A.REF_DATE between ? and ? "
+" FROM RECEIVABLES A,CUSTOMER B WHERE A.CUST_CODE=B.CUST_CODE " +" and TOT_AMT-ADJ_AMT<>0) group by days order by days";
+" and A.CUST_CODE IN ("+custCode+") AND A.REF_DATE between ? and ? "
+" and TOT_AMT-ADJ_AMT<>0) group by days order by days"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); int count = 0;
rs = pstmt.executeQuery(); int dueDays=0;
int count = 0; double thirthySlab=0.0;
int dueDays=0; double sixthySlab=0.0;
double thirthySlab=0.0; double ninthySlab=0.0;
double sixthySlab=0.0; double oneTwinthySlab=0.0;
double ninthySlab=0.0; double oneTwinthyPlus=0.0;
double oneTwinthySlab=0.0; double balAmt=0.0;
double oneTwinthyPlus=0.0; while (rs.next())
double balAmt=0.0; {
while (rs.next()) rowData = new JSONObject();
{
rowData = new JSONObject(); //start code for Pie chart creation
balAmt = Double.parseDouble(rs.getString("balAmt"));
//start code for Pie chart creation dueDays = Integer.parseInt(rs.getString("days"));
balAmt = Double.parseDouble(rs.getString("balAmt"));
dueDays = Integer.parseInt(rs.getString("days")); if(dueDays >=0 && dueDays<=30)
{
if(dueDays >=0 && dueDays<=30) thirthySlab = thirthySlab+balAmt;
{ }
thirthySlab = thirthySlab+balAmt; else if(dueDays>30 && dueDays<=60)
} {
else if(dueDays>30 && dueDays<=60) sixthySlab = sixthySlab +balAmt;
{ }
sixthySlab = sixthySlab +balAmt; else if(dueDays>60 && dueDays<=90)
} {
else if(dueDays>60 && dueDays<=90) ninthySlab = ninthySlab +balAmt;
{ }
ninthySlab = ninthySlab +balAmt; else if(dueDays>90 && dueDays<=120)
} {
else if(dueDays>90 && dueDays<=120) oneTwinthySlab = oneTwinthySlab +balAmt;
{ }
oneTwinthySlab = oneTwinthySlab +balAmt; else
} {
else oneTwinthyPlus = oneTwinthyPlus +balAmt;
{ }
oneTwinthyPlus = oneTwinthyPlus +balAmt; }
} rowData = new JSONObject();
} rowData.put("thirty", "0-30");
rowData = new JSONObject(); rowData .put("thirty_slab", thirthySlab);
rowData.put("thirty", "0-30"); rawDataCurntRecvbleChartJson.put(count, rowData);
rowData .put("thirty_slab", thirthySlab);
rawDataCurntRecvbleChartJson.put(count, rowData); count++;
rowData = new JSONObject();
count++; rowData.put("thirty", "30-60");
rowData = new JSONObject(); rowData.put("thirty_slab", sixthySlab);
rowData.put("thirty", "30-60"); rawDataCurntRecvbleChartJson.put(count, rowData);
rowData.put("thirty_slab", sixthySlab); count++;
rawDataCurntRecvbleChartJson.put(count, rowData); rowData = new JSONObject();
count++; rowData.put("thirty", "60-90");
rowData = new JSONObject(); rowData.put("thirty_slab", ninthySlab);
rowData.put("thirty", "60-90"); rawDataCurntRecvbleChartJson.put(count, rowData);
rowData.put("thirty_slab", ninthySlab); count++;
rawDataCurntRecvbleChartJson.put(count, rowData); rowData = new JSONObject();
count++; rowData.put("thirty","90-120");
rowData = new JSONObject(); rowData.put("thirty_slab",oneTwinthySlab);
rowData.put("thirty","90-120"); rawDataCurntRecvbleChartJson.put(count, rowData);
rowData.put("thirty_slab",oneTwinthySlab); count++;
rawDataCurntRecvbleChartJson.put(count, rowData); rowData = new JSONObject();
count++; rowData.put("thirty", "120 +");
rowData = new JSONObject(); rowData.put("thirty_slab", oneTwinthyPlus);
rowData.put("thirty", "120 +"); rawDataCurntRecvbleChartJson.put(count, rowData);
rowData.put("thirty_slab", oneTwinthyPlus); System.out.println("rawDataCurntRecvbleChartJson:"+rawDataCurntRecvbleChartJson);
rawDataCurntRecvbleChartJson.put(count, rowData); }
System.out.println("rawDataCurntRecvbleChartJson:"+rawDataCurntRecvbleChartJson); }
} catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getCurrentReceivableChartView Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getCurrentReceivableChartView Method :" + d.getMessage()); }
throw new ITMException(d); }
} return rawDataCurntRecvbleChartJson;
}
return rawDataCurntRecvbleChartJson; }
} //end of create pie char
//end of create pie char
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked") public JSONObject getPendingOrder(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@Override {
public JSONObject getPendingOrder(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException JSONObject rawDataPendingOrderJson = null;
{ JSONObject rowData = null;
JSONObject rawDataPendingOrderJson = null; String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); double pendingValue=0.0;
DashboardUtility dashbordUtil = null; String qntyStduom="";
double pendingValue=0.0; String qntyDesp="";
String qntyStduom=""; String rate="";
String qntyDesp=""; String unit="";
String rate=""; String preUnit="";
String unit=""; double netPendingValue=0.0;
String preUnit=""; double backOrderValue=0.0;
double netPendingValue=0.0; double totBackOrderValue=0.0;
double backOrderValue=0.0; String month1="";
double totBackOrderValue=0.0; String itemType="";
String month1=""; String key="";
String itemType=""; ArrayList<String> values = null;
String key=""; LinkedHashMap<String, Double> catValues = null;
ArrayList<String> values = null; LinkedHashMap<String, Double> graphDataMap = new LinkedHashMap<String, Double>();
LinkedHashMap<String, Double> catValues = null; LinkedHashMap<String, Double> sortedGraphDataMap = new LinkedHashMap<String, Double>();
LinkedHashMap<String, Double> graphDataMap = new LinkedHashMap<String, Double>(); int totMonth=0;
LinkedHashMap<String, Double> sortedGraphDataMap = new LinkedHashMap<String, Double>(); int frmMonth=0;
int totMonth=0; int toMonth=0;
int frmMonth=0; ArrayList<String> itemTypeList = new ArrayList<String>();
int toMonth=0; ArrayList<String> monthList = new ArrayList<String> ();
ArrayList<String> itemTypeList = new ArrayList<String>(); Date frmDate = null;
ArrayList<String> monthList = new ArrayList<String> (); Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try System.out.println(" Inside CustomerInfoEJB for getPendingOrder Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
{ conn = connDriver.getConnectDB(dataSourceName);
System.out.println(" Inside CustomerInfoEJB for getPendingOrder Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName); rawDataPendingOrderJson = new JSONObject();
connDriver = null; dashbordUtil = new DashboardUtility();
rawDataPendingOrderJson = new JSONObject(); //start date conversion form
dashbordUtil = new DashboardUtility(); SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
//start date conversion form
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat()); SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat()); Calendar cal = Calendar.getInstance();
if(lastMonth!=null && lastMonth.trim().length()>0 )
Calendar cal = Calendar.getInstance(); {
if(lastMonth!=null && lastMonth.trim().length()>0 ) toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
{ cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); toMonth=cal.get(Calendar.MONTH);
cal.get(Calendar.MONTH + 1); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
toMonth=cal.get(Calendar.MONTH); frmMonth = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, frmMonth, cal.get(Calendar.DATE));
frmMonth = cal.get(Calendar.MONTH); totMonth = (toMonth-frmMonth);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, frmMonth, cal.get(Calendar.DATE)); }
totMonth = (toMonth-frmMonth);
} //end date conversion form
//end date conversion form /** start of Customer name top custoer code conversion**/
custCode = dashbordUtil.getCommaSeparated(custCode);
/** start of Customer name top custoer code conversion**/ /** end of Customer name top custoer code conversion**/
custCode = dashbordUtil.getCommaSeparated(custCode);
/** end of Customer name top custoer code conversion**/ /*if(custCode!=null && custCode.trim().length()>0)
{
/*if(custCode!=null && custCode.trim().length()>0) custCode = dashbordUtil.getCommaSeparated(custCode);
{ custCodeSorder ="and A.CUST_CODE IN ("+custCode+")";
custCode = dashbordUtil.getCommaSeparated(custCode); System.out.println("in custcode block :: custCodeSorder-->"+custCodeSorder );
custCodeSorder ="and A.CUST_CODE IN ("+custCode+")"; }*/
System.out.println("in custcode block :: custCodeSorder-->"+custCodeSorder );
}*/ if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null )
{
if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null ) /** Start of rawDataPendingOrderJson object for GRID Chart**/
{
/** Start of rawDataPendingOrderJson object for GRID Chart**/ sql = " SELECT A.SITE_CODE,A.SALE_ORDER,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,A.CUST_ORDER__NO, "
+" CASE WHEN A.ORDER_STATUS='O' THEN 'Open' WHEN A.ORDER_STATUS='S' THEN 'Submit' WHEN A.ORDER_STATUS='P' THEN 'Partially Shipped' END ORDER_STATUS, "
sql = " SELECT A.SITE_CODE,A.SALE_ORDER,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,A.CUST_ORDER__NO, " +" A.CONFIRMED,A.CONF_DATE, CASE WHEN A.STATUS='P' THEN 'Pending' WHEN A.STATUS='U' THEN 'Under Shipment' WHEN A.STATUS='H' THEN 'Hold' END STATUS,A.STATUS_DATE, "
+" CASE WHEN A.ORDER_STATUS='O' THEN 'Open' WHEN A.ORDER_STATUS='S' THEN 'Submit' WHEN A.ORDER_STATUS='P' THEN 'Partially Shipped' END ORDER_STATUS, " +" B.ITEM_CODE__ORD,D.DESCR,D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM, "
+" A.CONFIRMED,A.CONF_DATE, CASE WHEN A.STATUS='P' THEN 'Pending' WHEN A.STATUS='U' THEN 'Under Shipment' WHEN A.STATUS='H' THEN 'Hold' END STATUS,A.STATUS_DATE, " +" B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,B.HOLD_FLAG , A.CUST_CODE__DLV,f.cust_name cust_name_dlv, "
+" B.ITEM_CODE__ORD,D.DESCR,D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM, " +" a.DLV_CITY,a.CUST_PORD,a.PORD_DATE,e.QTY_DESP,d.site_code,d.item_type, "
+" B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,B.HOLD_FLAG , A.CUST_CODE__DLV,f.cust_name cust_name_dlv, " +" (select count(1) from despatch des where des.sord_no = a.sale_order) no_of_ship,b.rate, "
+" a.DLV_CITY,a.CUST_PORD,a.PORD_DATE,e.QTY_DESP,d.site_code,d.item_type, " +" DDF_STOCK_PICK_RATE((select var_value from disparm where prd_code = '999999' and var_name = 'NET_REAL_PRICE_LIST'), "
+" (select count(1) from despatch des where des.sord_no = a.sale_order) no_of_ship,b.rate, " +" a.pl_date, B.ITEM_CODE__ORD, null, null, null, A.SITE_CODE) net_rate "
+" DDF_STOCK_PICK_RATE((select var_value from disparm where prd_code = '999999' and var_name = 'NET_REAL_PRICE_LIST'), " +" FROM SORDER A,SORDDET B,CUSTOMER C,ITEM D, SORDITEM E, CUSTOMER F "
+" a.pl_date, B.ITEM_CODE__ORD, null, null, null, A.SITE_CODE) net_rate " +" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE__ORD=D.ITEM_CODE "
+" FROM SORDER A,SORDDET B,CUSTOMER C,ITEM D, SORDITEM E, CUSTOMER F " +" AND F.CUST_CODE = A.CUST_CODE__DLV AND e.sale_order = a.sale_order and e.line_no = b.line_no "
+" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE__ORD=D.ITEM_CODE " +" and e.item_code = B.ITEM_CODE__ORD and e.ITEM_FLAG = 'I' and A.CUST_CODE IN ("+custCode+") "
+" AND F.CUST_CODE = A.CUST_CODE__DLV AND e.sale_order = a.sale_order and e.line_no = b.line_no " +" and A.ORDER_DATE between ? and ? AND B.sordform_no IS NOT NULL AND A.STATUS NOT IN('C','D','X') AND A.ORDER_STATUS NOT IN('C') "
+" and e.item_code = B.ITEM_CODE__ORD and e.ITEM_FLAG = 'I' and A.CUST_CODE IN ("+custCode+") " +" UNION ALL "
+" and A.ORDER_DATE between ? and ? AND B.sordform_no IS NOT NULL AND A.STATUS NOT IN('C','D','X') AND A.ORDER_STATUS NOT IN('C') " +" SELECT A.SITE_CODE,A.TRAN_ID,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,'' CUST_ORDER__NO, "
+" UNION ALL " +" '' ORDER_STATUS,'N' CONFIRMED,NULL CONF_DATE,A.STATUS,NULL STATUS_DATE,B.ITEM_CODE,D.DESCR, "
+" SELECT A.SITE_CODE,A.TRAN_ID,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,'' CUST_ORDER__NO, " +" D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM,B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,'N' HOLD_FLAG , "
+" '' ORDER_STATUS,'N' CONFIRMED,NULL CONF_DATE,A.STATUS,NULL STATUS_DATE,B.ITEM_CODE,D.DESCR, " +" A.CUST_CODE__DLV,f.cust_name cust_name_dlv,a.DLV_CITY,a.CUST_PORD,a.PORD_DATE,0,d.site_code,d.item_type,0,b.rate, "
+" D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM,B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,'N' HOLD_FLAG , " +" DDF_STOCK_PICK_RATE((select var_value from disparm where prd_code = '999999' and var_name = 'NET_REAL_PRICE_LIST'), "
+" A.CUST_CODE__DLV,f.cust_name cust_name_dlv,a.DLV_CITY,a.CUST_PORD,a.PORD_DATE,0,d.site_code,d.item_type,0,b.rate, " +" a.pl_date, B.ITEM_CODE, null, null, null, A.SITE_CODE) net_rate "
+" DDF_STOCK_PICK_RATE((select var_value from disparm where prd_code = '999999' and var_name = 'NET_REAL_PRICE_LIST'), " +" FROM SORDFORM A,SORDFORMDET B,CUSTOMER C,ITEM D, customer f WHERE A.TRAN_ID=B.TRAN_ID "
+" a.pl_date, B.ITEM_CODE, null, null, null, A.SITE_CODE) net_rate " +" AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE=D.ITEM_CODE and f.cust_code = a.cust_code__dlv "
+" FROM SORDFORM A,SORDFORMDET B,CUSTOMER C,ITEM D, customer f WHERE A.TRAN_ID=B.TRAN_ID " +" AND STATUS <> 'S' and A.CUST_CODE IN ("+custCode+") and A.ORDER_DATE between ? and ? ORDER BY ITEM_TYPE,UNIT";
+" AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE=D.ITEM_CODE and f.cust_code = a.cust_code__dlv "
+" AND STATUS <> 'S' and A.CUST_CODE IN ("+custCode+") and A.ORDER_DATE between ? and ? ORDER BY ITEM_TYPE,UNIT"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); int count = 0;
rs = pstmt.executeQuery(); while (rs.next())
int count = 0; {
while (rs.next()) rowData = new JSONObject();
{ qntyStduom=(checkNull( rs.getString("QUANTITY__STDUOM")));
rowData = new JSONObject(); qntyDesp=(checkNull(rs.getString("QTY_DESP")));
qntyStduom=(checkNull( rs.getString("QUANTITY__STDUOM"))); rate =(checkNull(rs.getString("rate")));
qntyDesp=(checkNull(rs.getString("QTY_DESP")));
rate =(checkNull(rs.getString("rate"))); rowData.put("site_code", checkNull(rs.getString("SITE_CODE")));
rowData.put("sale_order", checkNull(rs.getString("SALE_ORDER")));
rowData.put("site_code", checkNull(rs.getString("SITE_CODE"))); String ordDate=checkNull(rs.getString("ORDER_DATE"));
rowData.put("sale_order", checkNull(rs.getString("SALE_ORDER"))); if(ordDate!=null && ordDate.trim().length()>0)
String ordDate=checkNull(rs.getString("ORDER_DATE")); {
if(ordDate!=null && ordDate.trim().length()>0) rowData.put("order_date", gridDateFormat.format(convrtToTimStmDate.parse(ordDate)));
{ rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(0, 6));
rowData.put("order_date", gridDateFormat.format(convrtToTimStmDate.parse(ordDate))); }
rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(0, 6)); else
} {
else rowData.put("order_date",checkNull (rs.getString("ORDER_DATE")));
{ }
rowData.put("order_date",checkNull (rs.getString("ORDER_DATE"))); rowData.put("cust_code", checkNull(rs.getString("CUST_CODE")));
} rowData.put("cust_name", checkNull(rs.getString("CUST_NAME")));
rowData.put("cust_code", checkNull(rs.getString("CUST_CODE"))); rowData.put("cust_order__no", checkNull(rs.getString("CUST_ORDER__NO")));
rowData.put("cust_name", checkNull(rs.getString("CUST_NAME"))); rowData.put("order_status",checkNull (rs.getString("ORDER_STATUS")));
rowData.put("cust_order__no", checkNull(rs.getString("CUST_ORDER__NO"))); rowData.put("confirmed", checkNull(rs.getString("CONFIRMED")));
rowData.put("order_status",checkNull (rs.getString("ORDER_STATUS"))); String confDate=checkNull(rs.getString("CONF_DATE"));
rowData.put("confirmed", checkNull(rs.getString("CONFIRMED"))); if(confDate!=null && confDate.trim().length()>0)
String confDate=checkNull(rs.getString("CONF_DATE")); {
if(confDate!=null && confDate.trim().length()>0) rowData.put("conf_date", gridDateFormat.format(convrtToTimStmDate.parse(confDate)));
{ }
rowData.put("conf_date", gridDateFormat.format(convrtToTimStmDate.parse(confDate))); else
} {
else rowData.put("conf_date",checkNull (rs.getString("CONF_DATE")));
{ }
rowData.put("conf_date",checkNull (rs.getString("CONF_DATE"))); rowData.put("status", checkNull(rs.getString("STATUS")));
} rowData.put("status_date", checkNull(rs.getString("STATUS_DATE")));
rowData.put("status", checkNull(rs.getString("STATUS"))); rowData.put("item_code__ord", checkNull(rs.getString("ITEM_CODE__ORD")));
rowData.put("status_date", checkNull(rs.getString("STATUS_DATE"))); rowData.put("descr", checkNull(rs.getString("DESCR")));
rowData.put("item_code__ord", checkNull(rs.getString("ITEM_CODE__ORD"))); rowData.put("item_ser", checkNull(rs.getString("ITEM_SER")));
rowData.put("descr", checkNull(rs.getString("DESCR"))); rowData.put("unit", checkNull(rs.getString("UNIT")));
rowData.put("item_ser", checkNull(rs.getString("ITEM_SER"))); rowData.put("quantity__stduom",checkNull( rs.getString("QUANTITY__STDUOM")));
rowData.put("unit", checkNull(rs.getString("UNIT"))); String dispDate=checkNull(rs.getString("DSP_DATE"));
rowData.put("quantity__stduom",checkNull( rs.getString("QUANTITY__STDUOM"))); if(dispDate!=null && dispDate.trim().length()>0)
String dispDate=checkNull(rs.getString("DSP_DATE")); {
if(dispDate!=null && dispDate.trim().length()>0) rowData.put("dsp_date", gridDateFormat.format(convrtToTimStmDate.parse(dispDate)));
{ }
rowData.put("dsp_date", gridDateFormat.format(convrtToTimStmDate.parse(dispDate))); else
} {
else rowData.put("dsp_date",checkNull (rs.getString("DSP_DATE")));
{ }
rowData.put("dsp_date",checkNull (rs.getString("DSP_DATE"))); rowData.put("delay_days",checkNull( rs.getString("DELAY_DAYS")));
} rowData.put("hold_flag", checkNull(rs.getString("HOLD_FLAG")));
rowData.put("delay_days",checkNull( rs.getString("DELAY_DAYS")));
rowData.put("hold_flag", checkNull(rs.getString("HOLD_FLAG"))); /***************start of newly added arguments*/
rowData.put("cust_code__dlv", checkNull(rs.getString("CUST_CODE__DLV")));
/***************start of newly added arguments*/ rowData.put("cust_name_dlv", checkNull(rs.getString("cust_name_dlv")));
rowData.put("cust_code__dlv", checkNull(rs.getString("CUST_CODE__DLV"))); rowData.put("dlv_city", checkNull(rs.getString("DLV_CITY")));
rowData.put("cust_name_dlv", checkNull(rs.getString("cust_name_dlv"))); rowData.put("cust_pord", checkNull(rs.getString("CUST_PORD")));
rowData.put("dlv_city", checkNull(rs.getString("DLV_CITY"))); rowData.put("pord_date", checkNull(rs.getString("PORD_DATE")));
rowData.put("cust_pord", checkNull(rs.getString("CUST_PORD"))); rowData.put("qty_desp", checkNull(rs.getString("QTY_DESP")));
rowData.put("pord_date", checkNull(rs.getString("PORD_DATE"))); rowData.put("site_code", checkNull(rs.getString("site_code")));
rowData.put("qty_desp", checkNull(rs.getString("QTY_DESP"))); rowData.put("item_type", checkNull(rs.getString("item_type")));
rowData.put("site_code", checkNull(rs.getString("site_code"))); rowData.put("no_of_ship", checkNull(rs.getString("no_of_ship")));
rowData.put("item_type", checkNull(rs.getString("item_type"))); rowData.put("rate", checkNull(rs.getString("rate")));
rowData.put("no_of_ship", checkNull(rs.getString("no_of_ship")));
rowData.put("rate", checkNull(rs.getString("rate"))); /*start of pending value and net pending value calculation*/
if(qntyStduom != null && qntyStduom.trim().length()>0 && qntyDesp != null && qntyDesp.trim().length()>0)
/*start of pending value and net pending value calculation*/ {
if(qntyStduom != null && qntyStduom.trim().length()>0 && qntyDesp != null && qntyDesp.trim().length()>0) pendingValue = (Double.parseDouble(qntyStduom) - Double.parseDouble(qntyDesp));
{ }
pendingValue = (Double.parseDouble(qntyStduom) - Double.parseDouble(qntyDesp)); rowData.put("pending_value", pendingValue);
} if(rate != null && rate.trim().length()>0)
rowData.put("pending_value", pendingValue); {
if(rate != null && rate.trim().length()>0) netPendingValue = (pendingValue*Double.parseDouble(rate));
{ }
netPendingValue = (pendingValue*Double.parseDouble(rate)); rowData.put("net_pending_value", netPendingValue);
} /*end of pending value and net pending value calculation*/
rowData.put("net_pending_value", netPendingValue);
/*end of pending value and net pending value calculation*/ /*start of Back order value calculation*/
unit = checkNull(rs.getString("UNIT"));
/*start of Back order value calculation*/ if(("").equalsIgnoreCase(preUnit) && unit != null && unit.trim().length()>0)
unit = checkNull(rs.getString("UNIT")); {
if(("").equalsIgnoreCase(preUnit) && unit != null && unit.trim().length()>0) backOrderValue = pendingValue;
{ }
backOrderValue = pendingValue; if(!("").equalsIgnoreCase(preUnit) && preUnit.equalsIgnoreCase(unit))
} {
if(!("").equalsIgnoreCase(preUnit) && preUnit.equalsIgnoreCase(unit)) backOrderValue =backOrderValue + pendingValue;
{ }
backOrderValue =backOrderValue + pendingValue; if( !("").equalsIgnoreCase(preUnit) && !preUnit.equalsIgnoreCase(unit) )
} {
if( !("").equalsIgnoreCase(preUnit) && !preUnit.equalsIgnoreCase(unit) ) backOrderValue = pendingValue;
{ }
backOrderValue = pendingValue; rowData.put("back_order_value", backOrderValue);
} preUnit=unit;
rowData.put("back_order_value", backOrderValue); /*end of Back order value calculation*/
preUnit=unit;
/*end of Back order value calculation*/ rowData.put("month","");
rowData.put("product_category","");
rowData.put("month",""); rowData.put("category_value","");
rowData.put("product_category",""); /********************end of newly added arguments*/
rowData.put("category_value","");
/********************end of newly added arguments*/ rawDataPendingOrderJson.put(count, rowData);
count++;
rawDataPendingOrderJson.put(count, rowData);
count++; //start of code for stack chart hashmap
month1 =String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(3, 9);
//start of code for stack chart hashmap itemType = checkNull(rs.getString("item_type"));
month1 =String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(3, 9); if(! itemTypeList.contains(itemType))
itemType = checkNull(rs.getString("item_type")); {
if(! itemTypeList.contains(itemType)) itemTypeList.add(itemType);
{ }
itemTypeList.add(itemType); key = (month1.trim()+"@"+itemType.trim());
} if(graphDataMap.size()==0)
key = (month1.trim()+"@"+itemType.trim()); {
if(graphDataMap.size()==0) graphDataMap.put(key, pendingValue);
{ }
graphDataMap.put(key, pendingValue); if(graphDataMap !=null && graphDataMap.size()>0)
} {
if(graphDataMap !=null && graphDataMap.size()>0) if(graphDataMap.containsKey(key))
{ {
if(graphDataMap.containsKey(key)) totBackOrderValue = pendingValue + graphDataMap.get(key);
{ }
totBackOrderValue = pendingValue + graphDataMap.get(key); else if(! graphDataMap.containsKey(key))
} {
else if(! graphDataMap.containsKey(key)) totBackOrderValue = pendingValue;
{ }
totBackOrderValue = pendingValue; graphDataMap.put(key, totBackOrderValue);
} }
graphDataMap.put(key, totBackOrderValue); //end of code for stack chart hashmap
} }
//end of code for stack chart hashmap //start of list of month
} ArrayList<String> sortMonth = new ArrayList<String>();
//start of list of month cal = Calendar.getInstance();
ArrayList<String> sortMonth = new ArrayList<String>(); for(int i=0;i<=totMonth;i++)
cal = Calendar.getInstance(); {
for(int i=0;i<=totMonth;i++) monthList.add(String.valueOf(graphDateFormat.format(cal.getTime())).substring(3, 9));
{ cal.add(Calendar.MONTH,-(1));
monthList.add(String.valueOf(graphDateFormat.format(cal.getTime())).substring(3, 9)); sortMonth.add(monthList.get(i));
cal.add(Calendar.MONTH,-(1)); }
sortMonth.add(monthList.get(i));
} System.out.println("sortMonth:;;;"+sortMonth);
for(int k=1;k<=monthList.size();k++)
System.out.println("sortMonth:;;;"+sortMonth); {
for(int k=1;k<=monthList.size();k++) sortMonth.set(k-1, monthList.get(monthList.size()-k));
{ }
sortMonth.set(k-1, monthList.get(monthList.size()-k)); // end of list of month
} //start of graphDataMap in sorted format
// end of list of month String itType="";
//start of graphDataMap in sorted format String grpKey="";
String itType=""; for(int itmCtr=0;itmCtr<itemTypeList.size();itmCtr++)
String grpKey=""; {
for(int itmCtr=0;itmCtr<itemTypeList.size();itmCtr++) itType = itemTypeList.get(itmCtr);
{ for (Map.Entry<String, Double> grpentry : graphDataMap.entrySet())
itType = itemTypeList.get(itmCtr); {
for (Map.Entry<String, Double> grpentry : graphDataMap.entrySet()) String mapGrpKey = grpentry.getKey();
{ for(int mnthCtr=0;mnthCtr<sortMonth.size();mnthCtr++)
String mapGrpKey = grpentry.getKey(); {
for(int mnthCtr=0;mnthCtr<sortMonth.size();mnthCtr++) grpKey = (sortMonth.get(mnthCtr).trim()+"@"+itType.trim());
{ if(graphDataMap.containsKey(grpKey))
grpKey = (sortMonth.get(mnthCtr).trim()+"@"+itType.trim()); {
if(graphDataMap.containsKey(grpKey)) sortedGraphDataMap.put(grpKey, graphDataMap.get(grpKey));
{ }
sortedGraphDataMap.put(grpKey, graphDataMap.get(grpKey)); if(!graphDataMap.containsKey(grpKey) )
} {
if(!graphDataMap.containsKey(grpKey) ) sortedGraphDataMap.put(grpKey, 0.0);
{ }
sortedGraphDataMap.put(grpKey, 0.0); }
} }
} }
} //end of graphDataMap in sorted format
}
//end of graphDataMap in sorted format //start of code for stack chart hashmap to json
rowData = new JSONObject();
//start of code for stack chart hashmap to json String mnth="";
rowData = new JSONObject(); String itmType="",prvItmType="";
String mnth=""; values = new ArrayList<String>();
String itmType="",prvItmType=""; catValues = new LinkedHashMap<String, Double>();
values = new ArrayList<String>(); int cnt=0;
catValues = new LinkedHashMap<String, Double>(); for (Map.Entry<String, Double> entry : sortedGraphDataMap.entrySet())
int cnt=0; {
for (Map.Entry<String, Double> entry : sortedGraphDataMap.entrySet()) cnt++;
{ String mapKey = entry.getKey();
cnt++; double value = entry.getValue();
String mapKey = entry.getKey(); String[] temp;
double value = entry.getValue(); temp = mapKey.split("@");
String[] temp; mnth = temp[0].trim();
temp = mapKey.split("@"); itmType = temp[1].trim();
mnth = temp[0].trim();
itmType = temp[1].trim(); if( itmType != null && ("").equals(prvItmType) && itmType.trim().length()>0)
{
if( itmType != null && ("").equals(prvItmType) && itmType.trim().length()>0) catValues.put(mnth,value);
{ rowData.put("month",cnt);
catValues.put(mnth,value); rowData.put("product_category",itmType);
rowData.put("month",cnt); rowData.put("category_value",catValues);
rowData.put("product_category",itmType); rowData.put("pending_value", "");
rowData.put("category_value",catValues); }
rowData.put("pending_value", ""); else if(!("").equals(prvItmType) && prvItmType.equals(itmType))
} {
else if(!("").equals(prvItmType) && prvItmType.equals(itmType)) catValues.put(mnth,value);
{ }
catValues.put(mnth,value); if(!("").equals(prvItmType) && ! prvItmType.equals(itmType))
} {
if(!("").equals(prvItmType) && ! prvItmType.equals(itmType)) rowData.put("month",cnt);
{ rowData.put("product_category",prvItmType);
rowData.put("month",cnt); rowData.put("category_value",catValues);
rowData.put("product_category",prvItmType); rowData.put("pending_value", "");
rowData.put("category_value",catValues); rawDataPendingOrderJson.put(count, rowData);
rowData.put("pending_value", ""); count++;
rawDataPendingOrderJson.put(count, rowData); rowData = new JSONObject();
count++; catValues = new LinkedHashMap<String, Double>();
rowData = new JSONObject(); catValues.put(mnth,value);
catValues = new LinkedHashMap<String, Double>(); }
catValues.put(mnth,value); if(cnt==sortedGraphDataMap.size())
} {
if(cnt==sortedGraphDataMap.size()) rowData.put("month",cnt);
{ rowData.put("product_category",prvItmType);
rowData.put("month",cnt); rowData.put("category_value",catValues);
rowData.put("product_category",prvItmType); rowData.put("pending_value", "");
rowData.put("category_value",catValues); rawDataPendingOrderJson.put(count, rowData);
rowData.put("pending_value", ""); }
rawDataPendingOrderJson.put(count, rowData); prvItmType=itmType;
} }
prvItmType=itmType; System.out.println("rawData in pending order for stack chart:\n"+rawDataPendingOrderJson);
} //end of code for stack chart hashmap to json
System.out.println("rawData in pending order for stack chart:\n"+rawDataPendingOrderJson);
//end of code for stack chart hashmap to json /** End of rawDataPendingOrderJson object for GRID Chart**/
}
/** End of rawDataPendingOrderJson object for GRID Chart**/
} }
catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getPendingOrder Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getPendingOrder Method :" + d.getMessage()); }
throw new ITMException(d); }
} return rawDataPendingOrderJson;
} }
return rawDataPendingOrderJson;
}
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked") public JSONObject getOrderHistory(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@Override {
public JSONObject getOrderHistory(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException JSONObject rawDataOrderHistoryJson = new JSONObject();
{ JSONObject rowData = null;
JSONObject rawDataOrderHistoryJson = new JSONObject(); String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); Date frmDate = null;
DashboardUtility dashbordUtil = null; Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try
{ System.out.println(" Inside CustomerInfoEJB for getOrderHistory Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
conn = connDriver.getConnectDB(dataSourceName);
System.out.println(" Inside CustomerInfoEJB for getOrderHistory Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null; //start date conversion form
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
//start date conversion form SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat()); SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy"); if(lastMonth!=null && lastMonth.trim().length()>0 )
{
if(lastMonth!=null && lastMonth.trim().length()>0 ) Calendar cal = Calendar.getInstance();
{ toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Calendar cal = Calendar.getInstance(); cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
cal.get(Calendar.MONTH + 1); int month = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE)); }
//end date conversion form
} dashbordUtil = new DashboardUtility();
//end date conversion form
dashbordUtil = new DashboardUtility(); /** start of Customer name top custoer code conversion**/
/** start of Customer name top custoer code conversion**/ custCode = dashbordUtil.getCommaSeparated(custCode);
System.out.println("in recceivalble:"+custCode+":");
custCode = dashbordUtil.getCommaSeparated(custCode); /** end of Customer name top custoer code conversion**/
System.out.println("in recceivalble:"+custCode+":");
/** end of Customer name top custoer code conversion**/ if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null)
{
if (custCode != null && custCode.trim().length() > 0 && frmDate != null && toDate != null) sql = " SELECT A.SITE_CODE,A.SALE_ORDER,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,A.CUST_ORDER__NO, "
{ +" CASE WHEN A.ORDER_STATUS='O' THEN 'Open' WHEN A.ORDER_STATUS='S' THEN 'Submit' WHEN A.ORDER_STATUS='P' THEN 'Partially Shipped' WHEN A.ORDER_STATUS='C' THEN 'Fully Shipped' END ORDER_STATUS "
sql = " SELECT A.SITE_CODE,A.SALE_ORDER,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,A.CUST_ORDER__NO, " +" ,A.CONFIRMED,A.CONF_DATE,CASE WHEN A.STATUS='P' THEN 'Pending' WHEN A.STATUS='U' THEN 'Under Shipment' WHEN A.STATUS='H' THEN 'Hold' "
+" CASE WHEN A.ORDER_STATUS='O' THEN 'Open' WHEN A.ORDER_STATUS='S' THEN 'Submit' WHEN A.ORDER_STATUS='P' THEN 'Partially Shipped' WHEN A.ORDER_STATUS='C' THEN 'Fully Shipped' END ORDER_STATUS " +" WHEN A.STATUS='C' THEN 'Closed' WHEN A.STATUS='D' THEN 'Despatched' END STATUS ,A.STATUS_DATE, B.ITEM_CODE__ORD, "
+" ,A.CONFIRMED,A.CONF_DATE,CASE WHEN A.STATUS='P' THEN 'Pending' WHEN A.STATUS='U' THEN 'Under Shipment' WHEN A.STATUS='H' THEN 'Hold' " +" D.DESCR,D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM, B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,B.HOLD_FLAG "
+" WHEN A.STATUS='C' THEN 'Closed' WHEN A.STATUS='D' THEN 'Despatched' END STATUS ,A.STATUS_DATE, B.ITEM_CODE__ORD, " +" FROM SORDER A,SORDDET B,CUSTOMER C,ITEM D "
+" D.DESCR,D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM, B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,B.HOLD_FLAG " +" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE__ORD=D.ITEM_CODE "
+" FROM SORDER A,SORDDET B,CUSTOMER C,ITEM D " +" and A.CUST_CODE IN ("+custCode+") AND B.sordform_no IS NOT NULL AND A.STATUS NOT IN('X') AND A.ORDER_STATUS NOT IN('C') "
+" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE__ORD=D.ITEM_CODE " +" AND A.ORDER_DATE BETWEEN ? AND ? "
+" and A.CUST_CODE IN ("+custCode+") AND B.sordform_no IS NOT NULL AND A.STATUS NOT IN('X') AND A.ORDER_STATUS NOT IN('C') " +" UNION ALL "
+" AND A.ORDER_DATE BETWEEN ? AND ? " +" SELECT A.SITE_CODE,A.TRAN_ID,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,'' CUST_ORDER__NO, "
+" UNION ALL " +" '' ORDER_STATUS,'N' CONFIRMED,NULL CONF_DATE,A.STATUS,NULL STATUS_DATE,B.ITEM_CODE,D.DESCR,"
+" SELECT A.SITE_CODE,A.TRAN_ID,A.ORDER_DATE,A.CUST_CODE,C.CUST_NAME,'' CUST_ORDER__NO, " +" D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM,B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,'N' HOLD_FLAG "
+" '' ORDER_STATUS,'N' CONFIRMED,NULL CONF_DATE,A.STATUS,NULL STATUS_DATE,B.ITEM_CODE,D.DESCR," +" FROM SORDFORM A,SORDFORMDET B,CUSTOMER C,ITEM D "
+" D.ITEM_SER,B.UNIT,B.QUANTITY__STDUOM,B.DSP_DATE,B.DSP_DATE-A.ORDER_DATE DELAY_DAYS,'N' HOLD_FLAG " +" WHERE A.TRAN_ID=B.TRAN_ID AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE=D.ITEM_CODE AND STATUS<>'S' "
+" FROM SORDFORM A,SORDFORMDET B,CUSTOMER C,ITEM D " +" and A.CUST_CODE IN ("+custCode+") AND A.ORDER_DATE BETWEEN ? AND ? ORDER BY ORDER_DATE";
+" WHERE A.TRAN_ID=B.TRAN_ID AND A.CUST_CODE=C.CUST_CODE AND B.ITEM_CODE=D.ITEM_CODE AND STATUS<>'S' "
+" and A.CUST_CODE IN ("+custCode+") AND A.ORDER_DATE BETWEEN ? AND ? ORDER BY ORDER_DATE"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); int count = 0;
rs = pstmt.executeQuery(); while (rs.next())
int count = 0; {
while (rs.next()) rowData = new JSONObject();
{ rowData.put("site_code",checkNull (rs.getString("SITE_CODE")));
rowData = new JSONObject(); rowData.put("sale_order", checkNull(rs.getString("SALE_ORDER")));
rowData.put("site_code",checkNull (rs.getString("SITE_CODE"))); String ordDate=checkNull(rs.getString("ORDER_DATE"));
rowData.put("sale_order", checkNull(rs.getString("SALE_ORDER"))); if(ordDate.trim().length()>0)
String ordDate=checkNull(rs.getString("ORDER_DATE")); {
if(ordDate.trim().length()>0) rowData.put("order_date", gridDateFormat.format(convrtToTimStmDate.parse(ordDate)));
{ rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(0, 6));
rowData.put("order_date", gridDateFormat.format(convrtToTimStmDate.parse(ordDate))); }
rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("ORDER_DATE"))).substring(0, 6)); else{
}
else{ rowData.put("order_date",checkNull (rs.getString("ORDER_DATE")));
}
rowData.put("order_date",checkNull (rs.getString("ORDER_DATE"))); rowData.put("CUST_CODE_SUNUSA", checkNull(rs.getString("CUST_CODE")));
} rowData.put("cust_name", checkNull(rs.getString("CUST_NAME")));
rowData.put("CUST_CODE_SUNUSA", checkNull(rs.getString("CUST_CODE"))); rowData.put("cust_order__no", checkNull(rs.getString("CUST_ORDER__NO")));
rowData.put("cust_name", checkNull(rs.getString("CUST_NAME"))); rowData.put("order_status", checkNull(rs.getString("ORDER_STATUS")));
rowData.put("cust_order__no", checkNull(rs.getString("CUST_ORDER__NO"))); rowData.put("status", checkNull(rs.getString("STATUS")));
rowData.put("order_status", checkNull(rs.getString("ORDER_STATUS"))); rowData.put("status_date", checkNull(rs.getString("STATUS_DATE")));
rowData.put("status", checkNull(rs.getString("STATUS"))); rowData.put("item_code__ord", checkNull(rs.getString("ITEM_CODE__ORD")));
rowData.put("status_date", checkNull(rs.getString("STATUS_DATE"))); rowData.put("descr", checkNull(rs.getString("DESCR")));
rowData.put("item_code__ord", checkNull(rs.getString("ITEM_CODE__ORD"))); rowData.put("item_ser", checkNull(rs.getString("ITEM_SER")));
rowData.put("descr", checkNull(rs.getString("DESCR"))); rowData.put("unit",checkNull( rs.getString("UNIT")));
rowData.put("item_ser", checkNull(rs.getString("ITEM_SER"))); rowData.put("quantity__stduom", checkNull(rs.getString("QUANTITY__STDUOM")));
rowData.put("unit",checkNull( rs.getString("UNIT"))); String dispDate=checkNull(rs.getString("DSP_DATE"));
rowData.put("quantity__stduom", checkNull(rs.getString("QUANTITY__STDUOM"))); if(dispDate.trim().length()>0)
String dispDate=checkNull(rs.getString("DSP_DATE")); {
if(dispDate.trim().length()>0) rowData.put("dsp_date", gridDateFormat.format(convrtToTimStmDate.parse(dispDate)));
{ }
rowData.put("dsp_date", gridDateFormat.format(convrtToTimStmDate.parse(dispDate))); else{
}
else{ rowData.put("dsp_date",checkNull(rs.getString("DSP_DATE")));
}
rowData.put("dsp_date",checkNull(rs.getString("DSP_DATE"))); rowData.put("delay_days","100");
} //rowData.put("delay_days",checkNull(rs.getString("DELAY_DAYS")));
rowData.put("delay_days","100"); rowData.put("hold_flag", checkNull(rs.getString("HOLD_FLAG")));
//rowData.put("delay_days",checkNull(rs.getString("DELAY_DAYS"))); rawDataOrderHistoryJson.put(count, rowData);
rowData.put("hold_flag", checkNull(rs.getString("HOLD_FLAG"))); count++;
rawDataOrderHistoryJson.put(count, rowData); }
count++; }
} }
} catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getOrderHistory Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getOrderHistory Method :" + d.getMessage()); }
throw new ITMException(d); }
} System.out.println("rawDataOrderHistoryJson--["+rawDataOrderHistoryJson.toString()+"]");
} return rawDataOrderHistoryJson;
System.out.println("rawDataOrderHistoryJson--["+rawDataOrderHistoryJson.toString()+"]");
return rawDataOrderHistoryJson; }
}
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked") public JSONObject getSalesHistory(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@Override {
public JSONObject getSalesHistory(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException JSONObject rawDataSalesHistoryJson = new JSONObject();
{ JSONObject rowData = null;
JSONObject rawDataSalesHistoryJson = new JSONObject(); String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); Date frmDate = null;
DashboardUtility dashbordUtil = null; Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try
{ System.out.println(" Inside CustomerInfoEJB for getSalesHistory Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
conn = connDriver.getConnectDB(dataSourceName);
System.out.println(" Inside CustomerInfoEJB for getSalesHistory Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName); dashbordUtil = new DashboardUtility();
connDriver = null; //start date conversion form
dashbordUtil = new DashboardUtility(); SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
//start date conversion form SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat()); SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy"); if(lastMonth!=null && lastMonth.trim().length()>0 )
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat()); {
if(lastMonth!=null && lastMonth.trim().length()>0 ) Calendar cal = Calendar.getInstance();
{ toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Calendar cal = Calendar.getInstance(); cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
cal.get(Calendar.MONTH + 1); int month = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE)); }
//end date conversion form
}
//end date conversion form /** start of Customer name top custoer code conversion**/
/** start of Customer name top custoer code conversion**/ custCode = dashbordUtil.getCommaSeparated(custCode);
System.out.println("in recceivalble:"+custCode+":");
custCode = dashbordUtil.getCommaSeparated(custCode); /** end of Customer name top custoer code conversion**/
System.out.println("in recceivalble:"+custCode+":");
/** end of Customer name top custoer code conversion**/ if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null)
{
if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null) sql = " SELECT A.SITE_CODE,A.SORD_NO,B.LINE_NO__SORD,SORD_DATE,A.DESP_DATE,A.CUST_CODE, "
{ +" C.CUST_NAME,A.CUST_CODE__DLV,A.CURR_CODE,A.EXCH_RATE,B.ITEM_CODE,D.DESCR,D.ITEM_SER, "
sql = " SELECT A.SITE_CODE,A.SORD_NO,B.LINE_NO__SORD,SORD_DATE,A.DESP_DATE,A.CUST_CODE, " +" B.LOT_NO,B.LOT_SL,B.QUANTITY,B.UNIT,B.QUANTITY__STDUOM,B.RATE__STDUOM, "
+" C.CUST_NAME,A.CUST_CODE__DLV,A.CURR_CODE,A.EXCH_RATE,B.ITEM_CODE,D.DESCR,D.ITEM_SER, " +" B.QUANTITY__STDUOM*B.RATE__STDUOM AMOUNT,B.NO_ART,B.MFG_DATE,B.EXP_DATE, "
+" B.LOT_NO,B.LOT_SL,B.QUANTITY,B.UNIT,B.QUANTITY__STDUOM,B.RATE__STDUOM, " +" B.SITE_CODE__MFG FROM DESPATCH A,DESPATCHDET B,CUSTOMER C,ITEM D "
+" B.QUANTITY__STDUOM*B.RATE__STDUOM AMOUNT,B.NO_ART,B.MFG_DATE,B.EXP_DATE, " +" WHERE A.DESP_ID=B.DESP_ID AND A.CUST_CODE=C.CUST_CODE "
+" B.SITE_CODE__MFG FROM DESPATCH A,DESPATCHDET B,CUSTOMER C,ITEM D " +" AND B.ITEM_CODE=D.ITEM_CODE and A.CUST_CODE IN ("+custCode+") AND "
+" WHERE A.DESP_ID=B.DESP_ID AND A.CUST_CODE=C.CUST_CODE " +" A.DESP_DATE BETWEEN ? AND ? order by DESP_DATE,SORD_NO";
+" AND B.ITEM_CODE=D.ITEM_CODE and A.CUST_CODE IN ("+custCode+") AND "
+" A.DESP_DATE BETWEEN ? AND ? order by DESP_DATE,SORD_NO"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); int count = 0;
rs = pstmt.executeQuery(); while (rs.next())
int count = 0; {
while (rs.next()) rowData = new JSONObject();
{ rowData.put("site_code", checkNull(rs.getString("SITE_CODE")));
rowData = new JSONObject(); rowData.put("sord_no", checkNull(rs.getString("SORD_NO")));
rowData.put("site_code", checkNull(rs.getString("SITE_CODE"))); rowData.put("line_no__sord", checkNull(rs.getString("LINE_NO__SORD")));
rowData.put("sord_no", checkNull(rs.getString("SORD_NO")));
rowData.put("line_no__sord", checkNull(rs.getString("LINE_NO__SORD")));
String sordDate=checkNull(rs.getString("SORD_DATE"));
String despDate=checkNull(rs.getString("DESP_DATE"));
String sordDate=checkNull(rs.getString("SORD_DATE")); if(sordDate.trim().length()>0)
String despDate=checkNull(rs.getString("DESP_DATE")); {
if(sordDate.trim().length()>0) rowData.put("sord_date", gridDateFormat.format(convrtToTimStmDate.parse(sordDate)));
{ }
rowData.put("sord_date", gridDateFormat.format(convrtToTimStmDate.parse(sordDate))); else{
}
else{ rowData.put("sord_date",checkNull(rs.getString("SORD_DATE")));
}
rowData.put("sord_date",checkNull(rs.getString("SORD_DATE")));
} System.out.println("despDate in sales hisotry : "+despDate);
if(despDate.trim().length()>0)
System.out.println("despDate in sales hisotry : "+despDate); {
if(despDate.trim().length()>0) rowData.put("desp_date", gridDateFormat.format(convrtToTimStmDate.parse(despDate)));
{ rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("DESP_DATE"))).substring(0, 6));
rowData.put("desp_date", gridDateFormat.format(convrtToTimStmDate.parse(despDate))); }
rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("DESP_DATE"))).substring(0, 6)); else{
}
else{ rowData.put("desp_date",checkNull(rs.getString("DESP_DATE")));
}
rowData.put("desp_date",checkNull(rs.getString("DESP_DATE"))); rowData.put("cust_code",checkNull (rs.getString("CUST_CODE")));
} rowData.put("cust_name",checkNull( rs.getString("CUST_NAME")));
rowData.put("cust_code",checkNull (rs.getString("CUST_CODE"))); rowData.put("cust_code__dlv",checkNull( rs.getString("CUST_CODE__DLV")));
rowData.put("cust_name",checkNull( rs.getString("CUST_NAME"))); rowData.put("curr_code", checkNull(rs.getString("CURR_CODE")));
rowData.put("cust_code__dlv",checkNull( rs.getString("CUST_CODE__DLV"))); rowData.put("exch_rate", checkNull(rs.getString("EXCH_RATE")));
rowData.put("curr_code", checkNull(rs.getString("CURR_CODE"))); rowData.put("item_code", checkNull(rs.getString("ITEM_CODE")));
rowData.put("exch_rate", checkNull(rs.getString("EXCH_RATE"))); rowData.put("descr", checkNull(rs.getString("DESCR")));
rowData.put("item_code", checkNull(rs.getString("ITEM_CODE"))); rowData.put("item_ser",checkNull( rs.getString("ITEM_SER")));
rowData.put("descr", checkNull(rs.getString("DESCR"))); rowData.put("lot_no",checkNull( rs.getString("LOT_NO")));
rowData.put("item_ser",checkNull( rs.getString("ITEM_SER"))); rowData.put("lot_sl", checkNull(rs.getString("LOT_SL")));
rowData.put("lot_no",checkNull( rs.getString("LOT_NO"))); rowData.put("quantity", checkNull(rs.getString("QUANTITY")));
rowData.put("lot_sl", checkNull(rs.getString("LOT_SL"))); rowData.put("unit", checkNull(rs.getString("UNIT")));
rowData.put("quantity", checkNull(rs.getString("QUANTITY"))); rowData.put("quantity__stduom", checkNull(rs.getString("QUANTITY__STDUOM")));
rowData.put("unit", checkNull(rs.getString("UNIT"))); rowData.put("rate__stduom", checkNull(rs.getString("RATE__STDUOM")));
rowData.put("quantity__stduom", checkNull(rs.getString("QUANTITY__STDUOM"))); rowData.put("amount", checkNull(rs.getString("AMOUNT")));
rowData.put("rate__stduom", checkNull(rs.getString("RATE__STDUOM"))); rowData.put("no_art", checkNull(rs.getString("NO_ART")));
rowData.put("amount", checkNull(rs.getString("AMOUNT"))); rowData.put("mfg_date", checkNull(rs.getString("MFG_DATE")));
rowData.put("no_art", checkNull(rs.getString("NO_ART"))); rowData.put("exp_date", checkNull(rs.getString("EXP_DATE")));
rowData.put("mfg_date", checkNull(rs.getString("MFG_DATE"))); rowData.put("site_code__mfg",checkNull(rs.getString("SITE_CODE__MFG")));
rowData.put("exp_date", checkNull(rs.getString("EXP_DATE"))); rawDataSalesHistoryJson.put(count, rowData);
rowData.put("site_code__mfg",checkNull(rs.getString("SITE_CODE__MFG"))); count++;
rawDataSalesHistoryJson.put(count, rowData); }
count++; }
} }
} catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getSalesHistory Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getSalesHistory Method :" + d.getMessage()); }
throw new ITMException(d); }
} return rawDataSalesHistoryJson;
} }
return rawDataSalesHistoryJson; @SuppressWarnings("unchecked")
} @Override
@SuppressWarnings("unchecked") public JSONObject getTransactionSummary(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
@Override {
public JSONObject getTransactionSummary(String custCode, String lastMonth,String dataSourceName) throws RemoteException, ITMException
{ JSONObject rawDataTrnsctionSumryJson = new JSONObject();
JSONObject rowData = null;
JSONObject rawDataTrnsctionSumryJson = new JSONObject(); String sql = "";
JSONObject rowData = null; ResultSet rs = null;
String sql = ""; PreparedStatement pstmt = null;
ResultSet rs = null; Connection conn = null;
PreparedStatement pstmt = null; ConnDriver connDriver = new ConnDriver();
Connection conn = null; DashboardUtility dashbordUtil = null;
ConnDriver connDriver = new ConnDriver(); Date frmDate = null;
DashboardUtility dashbordUtil = null; Date toDate = null;
Date frmDate = null; try
Date toDate = null; {
try
{ System.out.println(" Inside CustomerInfoEJB for getTransactionSummary Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth);
conn = connDriver.getConnectDB(dataSourceName);
System.out.println(" Inside CustomerInfoEJB for getTransactionSummary Method Data Soruc Name ="+dataSourceName+" custCode:"+custCode+" lastMonth is =" + lastMonth); connDriver = null;
conn = connDriver.getConnectDB(dataSourceName); //start date conversion form
connDriver = null; SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat());
//start date conversion form
SimpleDateFormat gridDateFormat = new SimpleDateFormat( genericUtility.getApplDateFormat()); SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat());
SimpleDateFormat graphDateFormat = new SimpleDateFormat("dd-MMM-yy");
SimpleDateFormat convrtToTimStmDate= new SimpleDateFormat(genericUtility.getDBDateFormat()); if(lastMonth!=null && lastMonth.trim().length()>0 )
{
if(lastMonth!=null && lastMonth.trim().length()>0 ) Calendar cal = Calendar.getInstance();
{ toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
Calendar cal = Calendar.getInstance(); cal.get(Calendar.MONTH + 1);
toDate = new Date(cal.get(Calendar.YEAR) - 1900, cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth)));
cal.get(Calendar.MONTH + 1); int month = cal.get(Calendar.MONTH);
cal.add(Calendar.MONTH,-(Integer.parseInt(lastMonth))); frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE));
int month = cal.get(Calendar.MONTH);
frmDate = new Date(cal.get(Calendar.YEAR) - 1900, month, cal.get(Calendar.DATE)); }
//end date conversion form
} dashbordUtil = new DashboardUtility();
//end date conversion form
dashbordUtil = new DashboardUtility(); /** start of Customer name top custoer code conversion**/
/** start of Customer name top custoer code conversion**/ custCode = dashbordUtil.getCommaSeparated(custCode);
System.out.println("in recceivalble:"+custCode+":");
custCode = dashbordUtil.getCommaSeparated(custCode); /** end of Customer name top custoer code conversion**/
System.out.println("in recceivalble:"+custCode+":");
/** end of Customer name top custoer code conversion**/ if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null)
{
if (custCode!=null && custCode.trim().length()>0 && frmDate != null && toDate != null) sql = " SELECT SDATE,SUM(NO_OF_ORDER) as NO_OF_ORDER ,SUM(ORDER_VALUE) as ORDER_VALUE,SUM(NO_OF_SALES) as NO_OF_SALES,SUM(SALES_VALUE) as SALES_VALUE, "
{ +" SUM(RECEIVABLES) as RECEIVABLES ,SUM(COLLECTION) as COLLECTION ,SUM(NO_OF_DN) as NO_OF_DN,SUM(DN_VALUE) as DN_VALUE,SUM(NO_OF_CN) as NO_OF_CN, "
sql = " SELECT SDATE,SUM(NO_OF_ORDER) as NO_OF_ORDER ,SUM(ORDER_VALUE) as ORDER_VALUE,SUM(NO_OF_SALES) as NO_OF_SALES,SUM(SALES_VALUE) as SALES_VALUE, " +" SUM(CN_VALUE) as CN_VALUE ,SUM(NO_OF_SR) as NO_OF_SR ,SUM(SR_VALUE) as SR_VALUE FROM ( SELECT A.ORDER_DATE SDATE, "
+" SUM(RECEIVABLES) as RECEIVABLES ,SUM(COLLECTION) as COLLECTION ,SUM(NO_OF_DN) as NO_OF_DN,SUM(DN_VALUE) as DN_VALUE,SUM(NO_OF_CN) as NO_OF_CN, " +" 1 NO_OF_ORDER,B.QUANTITY__STDUOM*B.RATE__STDUOM ORDER_VALUE,0 NO_OF_SALES,"
+" SUM(CN_VALUE) as CN_VALUE ,SUM(NO_OF_SR) as NO_OF_SR ,SUM(SR_VALUE) as SR_VALUE FROM ( SELECT A.ORDER_DATE SDATE, " +" 0 SALES_VALUE,0 RECEIVABLES,0 COLLECTION,0 NO_OF_DN,0 DN_VALUE,0 NO_OF_CN, "
+" 1 NO_OF_ORDER,B.QUANTITY__STDUOM*B.RATE__STDUOM ORDER_VALUE,0 NO_OF_SALES," +" 0 CN_VALUE,0 NO_OF_SR,0 SR_VALUE FROM SORDER A,SORDDET B "
+" 0 SALES_VALUE,0 RECEIVABLES,0 COLLECTION,0 NO_OF_DN,0 DN_VALUE,0 NO_OF_CN, " +" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE IN ("+custCode+") AND A.ORDER_DATE "
+" 0 CN_VALUE,0 NO_OF_SR,0 SR_VALUE FROM SORDER A,SORDDET B " +" BETWEEN ? AND ? AND A.STATUS NOT IN('X') "
+" WHERE A.SALE_ORDER=B.SALE_ORDER AND A.CUST_CODE IN ("+custCode+") AND A.ORDER_DATE " +" UNION ALL SELECT A.REF_DATE SDATE,0 NO_OF_ORDER,0 ORDER_VALUE,0 NO_OF_SALES,0 "
+" BETWEEN ? AND ? AND A.STATUS NOT IN('X') " +" SALES_VALUE,(TOT_AMT-ADJ_AMT) RECEIVABLES,0 COLLECTION,0 NO_OF_DN,0 DN_VALUE,0 "
+" UNION ALL SELECT A.REF_DATE SDATE,0 NO_OF_ORDER,0 ORDER_VALUE,0 NO_OF_SALES,0 " +" NO_OF_CN,0 CN_VALUE,0 NO_OF_SR,0 SR_VALUE "
+" SALES_VALUE,(TOT_AMT-ADJ_AMT) RECEIVABLES,0 COLLECTION,0 NO_OF_DN,0 DN_VALUE,0 " +" FROM RECEIVABLES A where A.CUST_CODE IN ("+custCode+") AND REF_DATE BETWEEN "
+" NO_OF_CN,0 CN_VALUE,0 NO_OF_SR,0 SR_VALUE " +" ? AND ? ) GROUP BY SDATE order by SDATE";
+" FROM RECEIVABLES A where A.CUST_CODE IN ("+custCode+") AND REF_DATE BETWEEN "
+" ? AND ? ) GROUP BY SDATE order by SDATE"; pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt = conn.prepareStatement(sql); pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(1,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(2,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0"));
pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(frmDate).toString() + " 00:00:00.0")); rs = pstmt.executeQuery();
pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(convrtToTimStmDate.format(toDate).toString() + " 00:00:00.0")); int count = 0;
rs = pstmt.executeQuery(); while (rs.next())
int count = 0; {
while (rs.next()) rowData = new JSONObject();
{ String sdate=checkNull(rs.getString("SDATE"));
rowData = new JSONObject(); if(sdate.trim().length()>0)
String sdate=checkNull(rs.getString("SDATE")); {
if(sdate.trim().length()>0) rowData.put("sdate", gridDateFormat.format(convrtToTimStmDate.parse(sdate)));
{ rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("SDATE"))).substring(0, 6));
rowData.put("sdate", gridDateFormat.format(convrtToTimStmDate.parse(sdate))); }
rowData.put("graphdate", String.valueOf(graphDateFormat.format(rs.getDate("SDATE"))).substring(0, 6)); else{
}
else{ rowData.put("sdate",checkNull(rs.getString("SDATE")));
}
rowData.put("sdate",checkNull(rs.getString("SDATE"))); /*rowData.put("sdate", sdf1.format(checkNull(rs.getString("SDATE"))));*/
} System.out.println("DATE===="+String.valueOf(graphDateFormat.format(rs.getDate("SDATE"))).substring(0, 6));
/*rowData.put("sdate", sdf1.format(checkNull(rs.getString("SDATE"))));*/ /*rowData.put("graphdate", String.valueOf(sdf.format(rs.getDate("SDATE"))).substring(0, 6));*/
System.out.println("DATE===="+String.valueOf(graphDateFormat.format(rs.getDate("SDATE"))).substring(0, 6)); rowData.put("no_of_order", checkNull(rs.getString("NO_OF_ORDER")));
/*rowData.put("graphdate", String.valueOf(sdf.format(rs.getDate("SDATE"))).substring(0, 6));*/ rowData.put("order_value", checkNull(rs.getString("ORDER_VALUE")));
rowData.put("no_of_order", checkNull(rs.getString("NO_OF_ORDER"))); rowData.put("no_of_sales", checkNull(rs.getString("NO_OF_SALES")));
rowData.put("order_value", checkNull(rs.getString("ORDER_VALUE"))); rowData.put("sales_value", checkNull(rs.getString("SALES_VALUE")));
rowData.put("no_of_sales", checkNull(rs.getString("NO_OF_SALES"))); rowData.put("receivables", checkNull(rs.getString("RECEIVABLES")));
rowData.put("sales_value", checkNull(rs.getString("SALES_VALUE"))); rowData.put("collection", checkNull(rs.getString("COLLECTION")));
rowData.put("receivables", checkNull(rs.getString("RECEIVABLES"))); rowData.put("no_of_dn", checkNull(rs.getString("NO_OF_DN")));
rowData.put("collection", checkNull(rs.getString("COLLECTION"))); rowData.put("dn_value", checkNull(rs.getString("DN_VALUE")));
rowData.put("no_of_dn", checkNull(rs.getString("NO_OF_DN"))); rowData.put("no_of_cn", checkNull(rs.getString("NO_OF_CN")));
rowData.put("dn_value", checkNull(rs.getString("DN_VALUE"))); rowData.put("cn_value", checkNull(rs.getString("CN_VALUE")));
rowData.put("no_of_cn", checkNull(rs.getString("NO_OF_CN"))); rowData.put("no_of_sr",checkNull( rs.getString("NO_OF_SR")));
rowData.put("cn_value", checkNull(rs.getString("CN_VALUE"))); rowData.put("sr_value", checkNull(rs.getString("SR_VALUE")));
rowData.put("no_of_sr",checkNull( rs.getString("NO_OF_SR"))); rawDataTrnsctionSumryJson.put(count, rowData);
rowData.put("sr_value", checkNull(rs.getString("SR_VALUE"))); count++;
rawDataTrnsctionSumryJson.put(count, rowData); }
count++; }
} }
} catch (Exception e)
} {
catch (Exception e) e.printStackTrace();
{ throw new ITMException(e);
e.printStackTrace(); }
throw new ITMException(e); finally
} {
finally try
{ {
try if (conn != null)
{ {
if (conn != null) if (rs != null)
{ rs.close();
if (rs != null) rs = null;
rs.close(); if (pstmt != null)
rs = null; pstmt.close();
if (pstmt != null) pstmt = null;
pstmt.close(); conn.close();
pstmt = null; conn = null;
conn.close(); }
conn = null; conn = null;
} } catch (Exception d)
conn = null; {
} catch (Exception d) d.printStackTrace();
{ System.out.println("Exception in :CustomerInfoEJB for getTransactionSummary Method :" + d.getMessage());
d.printStackTrace(); throw new ITMException(d);
System.out.println("Exception in :CustomerInfoEJB for getTransactionSummary Method :" + d.getMessage()); }
throw new ITMException(d); }
} return rawDataTrnsctionSumryJson;
}
return rawDataTrnsctionSumryJson;
}
} private String checkNull(String str)
{
private String checkNull(String str) if(str == null)
{ {
if(str == null) return "";
{ }
return ""; else
} {
else return str ;
{ }
return str ;
} }
} }
}
...@@ -21,7 +21,7 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote ...@@ -21,7 +21,7 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
//1.This is the main method to show the parent graph //1.This is the main method to show the parent graph
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject getSalesInventoryDivWise(String dataSourceName, String month, String from_mns, String to_mns ) throws RemoteException, ITMException public JSONObject getSalesInventoryDivWise(String dataSourceName, String month, String nomns) throws RemoteException, ITMException
{ {
JSONObject rawDataJson = new JSONObject(); JSONObject rawDataJson = new JSONObject();
...@@ -40,7 +40,7 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote ...@@ -40,7 +40,7 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote
int count=0; int count=0;
if(month!=null && month.trim().length()>0) if(month!=null && month.trim().length()>0)
{ {
System.out.println("month inside EJB SalesInventory.getSalesInventoryDivWise(String dataSourceName, String month) ==="+month); System.out.println("month inside EJB SalesInventory.getSalesInventoryDivWise(String dataSourceName, String month) ==="+month+"and Nomns==="+nomns);
String selectedmonth = month.substring(4, 6); String selectedmonth = month.substring(4, 6);
if(selectedmonth.trim().equalsIgnoreCase("01") ||selectedmonth.trim().equalsIgnoreCase("02") ||selectedmonth.trim().equalsIgnoreCase("03")) if(selectedmonth.trim().equalsIgnoreCase("01") ||selectedmonth.trim().equalsIgnoreCase("02") ||selectedmonth.trim().equalsIgnoreCase("03"))
{ {
...@@ -79,7 +79,8 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote ...@@ -79,7 +79,8 @@ public class SalesInventory extends ValidatorEJB implements SalesInventoryRemote
" GROUP BY item_code UNION ALL SELECT item_code, SUM(cl_stk_qty) AS cl_stk FROM sun.inventory_spl WHERE inv_date= LAST_DAY(TO_DATE('"+month+"','yyyymm')) AND loc_code " + " GROUP BY item_code UNION ALL SELECT item_code, SUM(cl_stk_qty) AS cl_stk FROM sun.inventory_spl WHERE inv_date= LAST_DAY(TO_DATE('"+month+"','yyyymm')) AND loc_code " +
" IN ( SELECT loc_code FROM LOC_SALABLE) GROUP BY item_code ) GROUP BY item_code ) CLSTK WHERE Sl.item_code= i.item_code AND ('"+month+"' = '"+month+"') AND i.item_sub_group NOT " + " IN ( SELECT loc_code FROM LOC_SALABLE) GROUP BY item_code ) GROUP BY item_code ) CLSTK WHERE Sl.item_code= i.item_code AND ('"+month+"' = '"+month+"') AND i.item_sub_group NOT " +
" IN ('CU','BJ') AND sl.item_code=clstk.item_code(+) GROUP BY sl.item_ser, trim(i.item_sub_group_descr) HAVING SUM(sl.ytdsl)>0 ) GROUP BY item_ser,brand,ytdsl,ytdach,cl_stk,nomn HAVING " + " IN ('CU','BJ') AND sl.item_code=clstk.item_code(+) GROUP BY sl.item_ser, trim(i.item_sub_group_descr) HAVING SUM(sl.ytdsl)>0 ) GROUP BY item_ser,brand,ytdsl,ytdach,cl_stk,nomn HAVING " +
" ( ROUND(cl_stk/(ytdsl/nomn),1) >= '"+from_mns+"' and ROUND(cl_stk/(ytdsl/nomn),1) <= '"+to_mns+"' ) ) A , ITEMSER WHERE a.item_ser=ITEMSER.item_ser AND a.brand NOT LIKE 'DUMMY%'"; " ( ROUND(cl_stk/(ytdsl/nomn),1) "+nomns +") ) A , ITEMSER WHERE a.item_ser=ITEMSER.item_ser AND a.brand NOT LIKE 'DUMMY%'";
//" ( ROUND(cl_stk/(ytdsl/nomn),1) >= '"+from_mns+"' and ROUND(cl_stk/(ytdsl/nomn),1) <= '"+to_mns+"' ) ) A , ITEMSER WHERE a.item_ser=ITEMSER.item_ser AND a.brand NOT LIKE 'DUMMY%'";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
......
...@@ -8,7 +8,7 @@ import org.json.simple.JSONObject; ...@@ -8,7 +8,7 @@ import org.json.simple.JSONObject;
@Local @Local
public interface SalesInventoryLocal extends ValidatorLocal public interface SalesInventoryLocal extends ValidatorLocal
{ {
public JSONObject getSalesInventoryDivWise(String dataSourceName,String month,String from_mns, String to_mns) throws RemoteException, ITMException; public JSONObject getSalesInventoryDivWise(String dataSourceName,String month,String nomns) throws RemoteException, ITMException;
public JSONObject getSalesInventoryBrandWise(String dataSourceName,String month,String brandName) throws RemoteException, ITMException; public JSONObject getSalesInventoryBrandWise(String dataSourceName,String month,String brandName) throws RemoteException, ITMException;
} }
...@@ -10,7 +10,7 @@ import org.json.simple.JSONObject; ...@@ -10,7 +10,7 @@ import org.json.simple.JSONObject;
@Remote @Remote
public interface SalesInventoryRemote extends ValidatorRemote public interface SalesInventoryRemote extends ValidatorRemote
{ {
public JSONObject getSalesInventoryDivWise(String dataSourceName,String month,String from_mns, String to_mns) throws RemoteException, ITMException; public JSONObject getSalesInventoryDivWise(String dataSourceName,String month,String nomns) throws RemoteException, ITMException;
public JSONObject getSalesInventoryBrandWise(String dataSourceName,String month,String brandName) throws RemoteException, ITMException; public JSONObject getSalesInventoryBrandWise(String dataSourceName,String month,String brandName) throws RemoteException, ITMException;
} }
...@@ -1209,13 +1209,26 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -1209,13 +1209,26 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+" ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN " +" ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN "
+" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) " +" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) "
+" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, " +" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, "
+" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,ROUND(SUM (a.sale_mth_cy)/ SUM (a.hotrgt_mth_cy)* 100,2) AS MTH_ACH_PER,(CASE WHEN SUM(a.sale_mth_ly)<>0 " +" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,"
+" THEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) " +" (case when SUM (a.hotrgt_mth_cy) <>0 then "
+" ELSE ROUND(0*100,1) END) AS MTH_GR,ROUND(SUM(a.sale_ytd_cy)/10000000,1) " +" (case when ROUND(SUM (a.sale_mth_cy)/ SUM (a.hotrgt_mth_cy)* 100,1) <-200 THEN -200 "
+" when ROUND(SUM (a.sale_mth_cy)/ SUM (a.hotrgt_mth_cy)* 100,1) >200 THEN 200 ELSE "
+" ROUND(SUM (a.sale_mth_cy)/ SUM (a.hotrgt_mth_cy)* 100,1) end )"
+" ELSE ROUND(0*100,1) END) AS MTH_ACH_PER, "
+"(CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR, "
+" ROUND(SUM(a.sale_ytd_cy)/10000000,1) "
+" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, " +" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, "
+" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT,(CASE WHEN SUM(a.sale_ytd_ly)<>0 " +" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT,"
+" THEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) " +"(CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+" ELSE ROUND(0*100,1) END) AS YTD_GR,ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, " +" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR,"
+" ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, "
+" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, " +" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, "
+" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/" +" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/"
+" SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 " +" SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 "
...@@ -1455,18 +1468,28 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -1455,18 +1468,28 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+" ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN " +" ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN "
+" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) " +" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) "
+" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, " +" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, "
+" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,(CASE WHEN SUM(a.sale_mth_ly)<>0 " +" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,"
+" THEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) " +" (CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" ELSE ROUND(0*100,1) END) AS MTH_GR,ROUND(SUM(a.sale_ytd_cy)/10000000,1) " +" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR,"
+ "ROUND(SUM(a.sale_ytd_cy)/10000000,1) "
+" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, " +" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, "
+" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT, " +" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT, "
+" (CASE WHEN SUM (a.hotrgt_ytd_cy)= 0 THEN 0 ELSE ROUND(SUM (a.sale_ytd_cy)/SUM (a.hotrgt_ytd_cy)* 100,1) END) AS YTD_ACH_PER, " +" (CASE WHEN SUM (a.hotrgt_ytd_cy)= 0 THEN 0 ELSE "
+" (CASE WHEN SUM(a.sale_ytd_ly)<>0 " +" (CASE WHEN ROUND(SUM (a.sale_ytd_cy)/SUM (a.hotrgt_ytd_cy)* 100,1) <-200 THEN -200 "
+" THEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) " +" WHEN ROUND(SUM (a.sale_ytd_cy)/SUM (a.hotrgt_ytd_cy)* 100,1) >200 THEN 200 ELSE "
+" ELSE ROUND(0*100,1) END) AS YTD_GR,ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, " +" ROUND(SUM (a.sale_ytd_cy)/SUM (a.hotrgt_ytd_cy)* 100,1) END) end) AS YTD_ACH_PER, "
+" (CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR,"
+" ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, "
+" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, " +" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, "
+" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/" +" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/"
+" SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 " +" MAX(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 "
+" ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,2) AS PMPM,round(SUM(b.pmpm_ly),2) AS PMPM_LY, " +" ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,2) AS PMPM,round(SUM(b.pmpm_ly),2) AS PMPM_LY, "
+" ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA, " +" ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA, "
+" (CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/" +" (CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/"
...@@ -1728,20 +1751,31 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -1728,20 +1751,31 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) " +" SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) "
+" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, " +" AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES, "
+" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT, " +" ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT, "
+" CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE ROUND(SUM (a.sale_mth_cy)/SUM (a.hotrgt_mth_cy)*100,2) END AS MTH_ACH_PER, " +" (CASE WHEN SUM (a.hotrgt_mth_cy)= 0 THEN 0 ELSE "
+" (CASE WHEN ROUND(SUM (a.sale_mth_cy)/SUM (a.hotrgt_mth_cy)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM (a.sale_mth_cy)/SUM (a.hotrgt_mth_cy)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM (a.sale_mth_cy)/SUM (a.hotrgt_mth_cy)*100,1) END) end) AS MTH_ACH_PER, "
+" (CASE WHEN SUM(a.sale_mth_ly)<>0 " +" (CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" THEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) " +" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" ELSE ROUND(0*100,1) END) AS MTH_GR,ROUND(SUM(a.sale_ytd_cy)/10000000,1) " +" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR,"
+" ROUND(SUM(a.sale_ytd_cy)/10000000,1) "
+" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, " +" AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES, "
+" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT,(CASE WHEN SUM(a.sale_ytd_ly)<>0 " +" ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT,(CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+" THEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) " +" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR,ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, " +" ELSE ROUND(0*100,1) END) AS YTD_GR,ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1, "
+" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, " +" ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3, "
+" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/" +" ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/"
+" SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 " +" MAX(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 "
+" ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,1) AS PMPM,SUM(b.pmpm_ly) AS PMPM_LY, " +" ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,1) AS PMPM,SUM(b.pmpm_ly) AS PMPM_LY, "
+" ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA, " +" ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA, "
+" CASE WHEN SUM (a.hotrgt_YTD_cy) = 0 THEN 0 ELSE ROUND(SUM (a.sale_YTD_cy)/SUM (a.hotrgt_YTD_cy)*100,2) END AS YTD_ACH_PER, " +" CASE WHEN SUM (a.hotrgt_YTD_cy) = 0 THEN 0 ELSE "
+" (CASE WHEN ROUND(SUM (a.sale_YTD_cy)/SUM (a.hotrgt_YTD_cy)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM (a.sale_YTD_cy)/SUM (a.hotrgt_YTD_cy)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM (a.sale_YTD_cy)/SUM (a.hotrgt_YTD_cy)*100,1) END) END AS YTD_ACH_PER, "
+" (CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/" +" (CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/"
+" SUM(a.sale_ytd_cy)*100,1) ELSE ROUND(0*100,1) END) AS RETU_YTD_PRCT " +" SUM(a.sale_ytd_cy)*100,1) ELSE ROUND(0*100,1) END) AS RETU_YTD_PRCT "
+" FROM (SELECT dwh.fin_year , dwh.item_ser,SUM(sale_mth_cy) AS sale_mth_cy, " +" FROM (SELECT dwh.fin_year , dwh.item_ser,SUM(sale_mth_cy) AS sale_mth_cy, "
...@@ -1994,11 +2028,17 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -1994,11 +2028,17 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ "ROUND(hotrgt_ytd_cy/10000000,2) AS hotrgt_ytd_cy," + "ROUND(hotrgt_ytd_cy/10000000,2) AS hotrgt_ytd_cy,"
+ "ROUND(sale_YTD_cy/10000000,2) AS sale_YTD_cy, " + "ROUND(sale_YTD_cy/10000000,2) AS sale_YTD_cy, "
+ "ROUND(sale_YTD_ly/10000000,2) AS sale_YTD_ly," + "ROUND(sale_YTD_ly/10000000,2) AS sale_YTD_ly,"
+ "(CASE WHEN NVL(hotrgt_ytd_cy,0) = 0 THEN 0" +" CASE WHEN NVL(hotrgt_ytd_cy,0) = 0 THEN 0 ELSE "
+ "ELSE ROUND(sale_YTD_cy/hotrgt_ytd_cy * 100,1) END ) AS ho_ach_prcnt," +" (CASE WHEN ROUND(sale_YTD_cy/hotrgt_ytd_cy * 100,1) <-200 THEN -200 "
+ "(CASE WHEN NVL(sale_YTD_ly,0) = 0 THEN 0" +" WHEN ROUND(sale_YTD_cy/hotrgt_ytd_cy * 100,1) >200 THEN 200 ELSE "
+ "ELSE ROUND((sale_YTD_cy -sale_YTD_ly)/ sale_YTD_ly* 100,1) END) AS gr_prcnt," +" ROUND(sale_YTD_cy/hotrgt_ytd_cy * 100,1) END) END AS ho_ach_prcnt, "
+ "c.psr AS NO_OF_SO," + "(CASE WHEN NVL(sale_YTD_ly,0) <> 0 "
+" THEN (CASE WHEN ROUND((sale_YTD_cy -sale_YTD_ly)/ sale_YTD_ly* 100,1) <-200 THEN -200 "
+" WHEN ROUND((sale_YTD_cy -sale_YTD_ly)/ sale_YTD_ly* 100,1) >200 THEN 200 ELSE "
+" ROUND((sale_YTD_cy -sale_YTD_ly)/ sale_YTD_ly* 100,1) END )"
+" ELSE ROUND(0*100,1) END) AS gr_prcnt, "
+ "c.psr AS NO_OF_SO,"
+ "ROUND(DWH.sale_ytd_cy/10000000/c.psr/(CASE WHEN SUBSTR('"+month+"',5,2)<4 THEN SUBSTR('"+month+"',5,2)+9 ELSE SUBSTR('"+month+"',5,2)-3 END) ,2) AS PMPM," + "ROUND(DWH.sale_ytd_cy/10000000/c.psr/(CASE WHEN SUBSTR('"+month+"',5,2)<4 THEN SUBSTR('"+month+"',5,2)+9 ELSE SUBSTR('"+month+"',5,2)-3 END) ,2) AS PMPM,"
+ "ROUND(terr100/totterr*100,1) AS terr100prcnt" + "ROUND(terr100/totterr*100,1) AS terr100prcnt"
+ " FROM (" + " FROM ("
...@@ -2196,10 +2236,16 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -2196,10 +2236,16 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ " ROUND(hotrgt_MTH_cy/10000000,2) AS hotrgt_MTH_cy, " + " ROUND(hotrgt_MTH_cy/10000000,2) AS hotrgt_MTH_cy, "
+ " ROUND(sale_MTH_cy/10000000,2) AS sale_MTH_cy," + " ROUND(sale_MTH_cy/10000000,2) AS sale_MTH_cy,"
+ " ROUND(sale_MTH_ly/10000000,2) AS sale_MTH_ly, " + " ROUND(sale_MTH_ly/10000000,2) AS sale_MTH_ly, "
+ " (CASE WHEN NVL(hotrgt_MTH_cy,0) = 0 THEN 0 " + " (CASE WHEN NVL(hotrgt_MTH_cy,0) <> 0 THEN "
+ " ELSE ROUND(sale_MTH_cy/hotrgt_MTH_cy * 100,1) END ) AS ho_ach_prcnt, " +" (CASE WHEN ROUND(sale_MTH_cy/hotrgt_MTH_cy * 100,1) <-200 THEN -200 "
+ " (CASE WHEN NVL(sale_MTH_ly,0) = 0 THEN 0 " +" WHEN ROUND(sale_MTH_cy/hotrgt_MTH_cy * 100,1) >200 THEN 200 ELSE "
+ " ELSE ROUND((sale_MTH_cy -sale_MTH_ly)/ sale_MTH_ly* 100,1) END) AS gr_prcnt, " +" ROUND(sale_MTH_cy/hotrgt_MTH_cy * 100,1) END ) "
+" ELSE ROUND(0*100,1) END ) AS ho_ach_prcnt, "
+ " (CASE WHEN NVL(sale_MTH_ly,0) <> 0 "
+" THEN (CASE WHEN ROUND((sale_MTH_cy -sale_MTH_ly)/ sale_MTH_ly* 100,1) <-200 THEN -200 "
+" WHEN ROUND((sale_MTH_cy -sale_MTH_ly)/ sale_MTH_ly* 100,1) >200 THEN 200 ELSE "
+" ROUND((sale_MTH_cy -sale_MTH_ly)/ sale_MTH_ly* 100,1) END )"
+" ELSE ROUND(0*100,1) END) AS gr_prcnt, "
+ " c.psr AS NO_OF_SO, " + " c.psr AS NO_OF_SO, "
+ " ROUND(DWH.sale_MTH_cy/10000000/c.psr/ " + " ROUND(DWH.sale_MTH_cy/10000000/c.psr/ "
+ " (CASE WHEN SUBSTR('"+month+"',5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END) " + " (CASE WHEN SUBSTR('"+month+"',5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END) "
...@@ -2416,24 +2462,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -2416,24 +2462,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END)/ 10000000,1) AS avg_mthly, " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END)/ 10000000,1) AS avg_mthly, "
+ " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, " + " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, "
+ " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, " + " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, "
+ " (CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 2) END) AS mth_ach_per, " + " (CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE "
+ " (CASE WHEN SUM (a.sale_mth_ly) <> 0 THEN ROUND (SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly) * 100,1) " +" (CASE WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) <-200 THEN -200 "
+ " ELSE ROUND (0 * 100, 1) END ) AS mth_gr, " +" WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) END) end) AS MTH_ACH_PER, "
+" (CASE WHEN SUM (a.sale_mth_ly) <> 0 "
+" THEN (CASE WHEN ROUND (SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly) * 100,1) <-200 THEN -200 "
+" WHEN ROUND (SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly) * 100,1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly) * 100,1) END )"
+ " ELSE ROUND (0 * 100, 1) END ) AS mth_gr, "
+ " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, " + " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, "
+ " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, " + " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, "
+ " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt," + " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt,"
+ " (CASE WHEN SUM (a.sale_ytd_ly) <> 0 THEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) " + " (CASE WHEN SUM (a.sale_ytd_ly) <> 0 "
+" THEN (CASE WHEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) <-200 THEN -200 "
+" WHEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) >200 THEN 200 ELSE "
+" ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) END )"
+ " ELSE ROUND (0 * 100, 1) END ) AS ytd_gr, " + " ELSE ROUND (0 * 100, 1) END ) AS ytd_gr, "
+ " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, " + " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, "
+ " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, " + " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, "
+ " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, " + " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, "
+ " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, " + " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, "
+ " ROUND ( SUM (a.sale_ytd_cy) / 100000/ SUM (c.psr)/ (CASE " + " ROUND ( SUM (a.sale_ytd_cy) / 100000/ MAX (c.psr)/ (CASE "
+ " WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 " + " WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 "
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END),1) AS pmpm, " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END),1) AS pmpm, "
+ " SUM (b.pmpm_ly) AS pmpm_ly, " + " SUM (b.pmpm_ly) AS pmpm_ly, "
+ " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra," + " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra,"
+" (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 2) END) AS YTD_ach_per, " +" (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE "
+" (CASE WHEN ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) <-200 THEN -200 "
+" WHEN ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) END) end) AS YTD_ACH_PER, "
+ " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) " + " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) "
+ " ELSE ROUND (0 * 100, 1) END) AS retu_ytd_prct " + " ELSE ROUND (0 * 100, 1) END) AS retu_ytd_prct "
+ " FROM (SELECT dwh.fin_year, dwh.item_ser,DWH.TERR_CODE,DWH.ZONE_DESCR, " + " FROM (SELECT dwh.fin_year, dwh.item_ser,DWH.TERR_CODE,DWH.ZONE_DESCR, "
...@@ -2711,26 +2769,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -2711,26 +2769,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ " END)/ 10000000,1) AS avg_mthly, " + " END)/ 10000000,1) AS avg_mthly, "
+ " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, " + " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, "
+ " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, " + " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, "
+ " (CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 2) END) AS mth_ach_per, " + " (CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE "
+ " (CASE WHEN SUM (a.sale_mth_ly) <> 0 THEN ROUND ( SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly)* 100,1) " +" (CASE WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) <-200 THEN -200 "
+ " ELSE ROUND (0 * 100, 1) " +" WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) >200 THEN 200 ELSE "
+ " END) AS mth_gr, " +" ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) END) end) AS MTH_ACH_PER, "
+" (CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR,"
+ " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, " + " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, "
+ " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, " + " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, "
+ " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt, " + " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt, "
+ " (CASE WHEN SUM (a.sale_ytd_ly) <> 0 THEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) " +"(CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+ " ELSE ROUND (0 * 100, 1) " +" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+ " END) AS ytd_gr, " +" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR, "
+ " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, " + " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, "
+ " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, " + " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, "
+ " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, " + " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, "
+ " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, " + " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, "
+ " ROUND ( SUM (a.sale_ytd_cy)/ 100000/ SUM (c.psr)/ (CASE WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 " + " ROUND ( SUM (a.sale_ytd_cy)/ 100000/ MAX (c.psr)/ (CASE WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 "
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 "
+ " END),1) AS pmpm, " + " END),1) AS pmpm, "
+ " SUM (b.pmpm_ly) AS pmpm_ly, " + " SUM (b.pmpm_ly) AS pmpm_ly, "
+ " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra, " + " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra, "
+ " (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 2) END) AS YTD_ach_per, " + " (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE "
+" (CASE WHEN ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) <-200 THEN -200 "
+" WHEN ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 1) END) end) AS YTD_ach_per, "
+ " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) " + " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) "
+ " ELSE ROUND (0 * 100, 1) " + " ELSE ROUND (0 * 100, 1) "
+ " END) AS retu_ytd_prct " + " END) AS retu_ytd_prct "
...@@ -3009,20 +3077,32 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -3009,20 +3077,32 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END)/ 10000000,1) AS avg_mthly, " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END)/ 10000000,1) AS avg_mthly, "
+ " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, " + " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, "
+ " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, " + " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, "
+ "(CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 2) END) AS mth_ach_per, " + "(CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE "
+ " (CASE WHEN SUM (a.sale_mth_ly) <> 0 THEN ROUND (SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly) * 100,1) " +" (CASE WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) <-200 THEN -200 "
+ " ELSE ROUND (0 * 100, 1) END ) AS mth_gr, " +" WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) END) end) AS MTH_ACH_PER, "
+" (CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR,"
+ " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, " + " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, "
+ " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, " + " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, "
+ " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt," + " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt,"
+ "(CASE WHEN SUM (a.hotrgt_ytd_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 2) END) AS ytd_ach_per, " + "(CASE WHEN SUM (a.hotrgt_ytd_cy) =0 THEN 0 ELSE "
+ " (CASE WHEN SUM (a.sale_ytd_ly) <> 0 THEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) " +" (CASE WHEN ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) <-200 THEN -200 "
+ " ELSE ROUND (0 * 100, 1) END ) AS ytd_gr, " +" WHEN ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) END) end) AS YTD_ACH_PER, "
+"(CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR, "
+ " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, " + " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, "
+ " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, " + " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, "
+ " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, " + " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, "
+ " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, " + " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, "
+ " ROUND ( SUM (a.sale_ytd_cy) / 100000/ SUM (c.psr)/ (CASE " + " ROUND ( SUM (a.sale_ytd_cy) / 100000/ MAX (c.psr)/ (CASE "
+ " WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 " + " WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 "
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END),1) AS pmpm, " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 END),1) AS pmpm, "
+ " SUM (b.pmpm_ly) AS pmpm_ly, " + " SUM (b.pmpm_ly) AS pmpm_ly, "
...@@ -3308,26 +3388,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -3308,26 +3388,36 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
+ " END)/ 10000000,1) AS avg_mthly, " + " END)/ 10000000,1) AS avg_mthly, "
+ " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, " + " ROUND (SUM (a.sale_mth_cy) / 10000000, 1) AS mth_cy_sales, "
+ " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, " + " ROUND (SUM (a.hotrgt_mth_cy) / 10000000, 1) AS mth_ho_trgt, "
+ "( CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 2) END) AS mth_ach_per, " + "( CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE "
+ " (CASE WHEN SUM (a.sale_mth_ly) <> 0 THEN ROUND ( SUM (a.sale_mth_cy - a.sale_mth_ly)/ SUM (a.sale_mth_ly)* 100,1) " + " (CASE WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) <-200 THEN -200 "
+ " ELSE ROUND (0 * 100, 1) " +" WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) >200 THEN 200 ELSE "
+ " END) AS mth_gr, " +" ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) END) end) AS MTH_ACH_PER, "
+" (CASE WHEN SUM(a.sale_mth_ly)<>0 "
+" THEN (CASE WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) <-200 THEN -200 "
+" WHEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS MTH_GR,"
+ " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, " + " ROUND (SUM (a.sale_ytd_cy) / 10000000, 1) AS ytd_cy_sales, "
+ " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, " + " ROUND (SUM (a.sale_ytd_ly) / 10000000, 1) AS ytd_ly_sales, "
+ " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt, " + " ROUND (SUM (a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ho_trgt, "
+ " (CASE WHEN SUM (a.sale_ytd_ly) <> 0 THEN ROUND ( SUM (a.sale_ytd_cy - a.sale_ytd_ly)/ SUM (a.sale_ytd_ly)* 100,1) " +"(CASE WHEN SUM(a.sale_ytd_ly)<>0 "
+ " ELSE ROUND (0 * 100, 1) " +" THEN (CASE WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) <-200 THEN -200 "
+ " END) AS ytd_gr, " +" WHEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) >200 THEN 200 ELSE "
+" ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) END )"
+" ELSE ROUND(0*100,1) END) AS YTD_GR, "
+ " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, " + " ROUND (SUM (a.sale_qrt1_cy) / 10000000, 1) AS q1, "
+ " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, " + " ROUND (SUM (a.sale_qrt2_cy) / 10000000, 1) AS q2, "
+ " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, " + " ROUND (SUM (a.sale_qrt3_cy) / 10000000, 1) AS q3, "
+ " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, " + " ROUND (SUM (a.sale_qrt4_cy) / 10000000, 1) AS q4, "
+ " ROUND (SUM (a.sale_ytd_cy)/ 100000/ SUM (c.psr)/ (CASE WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 " + " ROUND (SUM (a.sale_ytd_cy)/ 100000/ MAX (c.psr)/ (CASE WHEN SUBSTR ('"+month+"', 5, 2) < 4 THEN SUBSTR ('"+month+"', 5, 2) + 9 "
+ " ELSE SUBSTR ('"+month+"', 5, 2) - 3 " + " ELSE SUBSTR ('"+month+"', 5, 2) - 3 "
+ " END),1) AS pmpm, " + " END),1) AS pmpm, "
+ " SUM (b.pmpm_ly) AS pmpm_ly, " + " SUM (b.pmpm_ly) AS pmpm_ly, "
+ " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra, " + " ROUND (SUM (a.sale_ytd_cy - a.hotrgt_ytd_cy) / 10000000, 1) AS ytd_ach_extra, "
+ " (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE ROUND (SUM (a.sale_YTD_cy) / SUM (a.hotrgt_YTD_cy) * 100, 2) END) AS YTD_ach_per, " + " (CASE WHEN SUM (a.hotrgt_YTD_cy) =0 THEN 0 ELSE "
+" (CASE WHEN ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) <-200 THEN -200 "
+" WHEN ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_ytd_cy) / SUM (a.hotrgt_ytd_cy) * 100, 1) END) end) AS YTD_ACH_PER, "
+ " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) " + " (CASE WHEN SUM (a.sale_ytd_cy) <> 0 THEN ROUND (SUM (a.retu_ytd_cy) / SUM (a.sale_ytd_cy) * 100,1) "
+ " ELSE ROUND (0 * 100, 1) " + " ELSE ROUND (0 * 100, 1) "
+ " END) AS retu_ytd_prct " + " END) AS retu_ytd_prct "
...@@ -3597,7 +3687,13 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe ...@@ -3597,7 +3687,13 @@ public class SalesPerformance extends ValidatorEJB implements SalesPerformanceRe
} }
System.out.println("updates month and year from dcoding in getMnthSalesDivWiseGraphData =="+month+"finYear =="+finYear); System.out.println("updates month and year from dcoding in getMnthSalesDivWiseGraphData =="+month+"finYear =="+finYear);
sql =" SELECT b.DIV_NO, b.DIV_DESCR,( CASE WHEN SUBSTR('"+month+"' ,5,2) =3 THEN ROUND(0 ,1) WHEN SUBSTR('"+month+"' ,5,2) <3 THEN ROUND(SUM(a.hotrgt_annual_cy-a.sale_ytd_cy)/(12- SUBSTR('"+month+"' ,5,2)-9) /10000000,1) ELSE ROUND(SUM(a.hotrgt_annual_cy-a.sale_ytd_cy)/(12- SUBSTR('"+month+"' ,5,2)+3) /10000000,1) END ) AS REQD_MTHLY,ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES,ROUND(SUM(a.sale_mth_ly)/10000000,1) AS MTH_LY_SALES,ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,(CASE WHEN SUM(a.sale_mth_ly)<>0 THEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) ELSE ROUND(9.99*100,1) END) AS MTH_GR,ROUND(SUM (a.sale_mth_cy)/ SUM (a.hotrgt_mth_cy)* 100,2) AS MTH_ACH_PER,ROUND(SUM(a.sale_ytd_cy)/10000000,1) AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES,ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT, (CASE WHEN SUM(a.sale_ytd_ly)<>0 THEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) ELSE ROUND(9.99*100,1) END) AS YTD_GR, ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1,ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3,ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,2) AS PMPM,round(SUM(b.pmpm_ly),2) AS PMPM_LY,ROUND(SUM(a.sale_ytd_cy)/100000/SUM(c.psr)/(CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END),2) - round(SUM(b.pmpm_ly),2) AS INC_PMPM,ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA,(CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/SUM(a.sale_ytd_cy)*100,1) ELSE ROUND(9.99*100,1) END) AS RETU_YTD_PRCT,sum(b.bud_inc_pmpm) as bud_inc_pmpm FROM (SELECT dwh.fin_year , dwh.item_ser,SUM(sale_mth_cy) AS sale_mth_cy,SUM(sale_mth_ly) AS sale_mth_ly,SUM(trgt_mth_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_mth_cy,SUM(sale_YTD_cy) AS sale_YTD_cy,SUM(sale_YTD_ly) AS sale_YTD_ly,SUM(trgt_YTD_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_ytd_cy,SUM(sale_Qrt1_cy) AS sale_Qrt1_cy, " sql =" SELECT b.DIV_NO, b.DIV_DESCR,( CASE WHEN SUBSTR('"+month+"' ,5,2) =3 THEN ROUND(0 ,1) WHEN SUBSTR('"+month+"' ,5,2) <3 THEN ROUND(SUM(a.hotrgt_annual_cy-a.sale_ytd_cy)/(12- SUBSTR('"+month+"' ,5,2)-9) /10000000,1) ELSE ROUND(SUM(a.hotrgt_annual_cy-a.sale_ytd_cy)/(12- SUBSTR('"+month+"' ,5,2)+3) /10000000,1) END ) AS REQD_MTHLY,ROUND(SUM(a.sale_ytd_cy)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END)/10000000,1) AS AVG_MTHLY,ROUND(SUM(a.sale_mth_cy)/10000000,1) AS MTH_CY_SALES,ROUND(SUM(a.sale_mth_ly)/10000000,1) AS MTH_LY_SALES,ROUND(SUM(a.hotrgt_mth_cy)/10000000,1) AS MTH_HO_TRGT,"
+" (CASE WHEN SUM(a.sale_mth_ly)<>0 THEN ROUND(SUM(a.sale_mth_cy - a.sale_mth_ly)/SUM(a.sale_mth_ly)*100,1) ELSE ROUND(9.99*100,1) END) AS MTH_GR,"
+ "( CASE WHEN SUM (a.hotrgt_mth_cy) =0 THEN 0 ELSE "
+" (CASE WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) <-200 THEN -200 "
+" WHEN ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) >200 THEN 200 ELSE "
+" ROUND (SUM (a.sale_mth_cy) / SUM (a.hotrgt_mth_cy) * 100, 1) END) end) AS MTH_ACH_PER, "
+" ROUND(SUM(a.sale_ytd_cy)/10000000,1) AS YTD_CY_SALES,ROUND(SUM(a.sale_ytd_ly)/10000000,1) AS YTD_LY_SALES,ROUND(SUM(a.hotrgt_ytd_cy)/10000000,1) AS YTD_HO_TRGT, (CASE WHEN SUM(a.sale_ytd_ly)<>0 THEN ROUND(SUM(a.sale_ytd_cy - a.sale_ytd_ly)/SUM(a.sale_ytd_ly)*100,1) ELSE ROUND(9.99*100,1) END) AS YTD_GR, ROUND(SUM(a.sale_Qrt1_cy)/10000000,1) AS Q1,ROUND(SUM(a.sale_Qrt2_cy)/10000000,1) AS Q2,ROUND(SUM(a.sale_Qrt3_cy)/10000000,1) AS Q3,ROUND(SUM(a.sale_Qrt4_cy)/10000000,1) AS Q4,ROUND(SUM(a.sale_ytd_cy)/100000/SUM(c.psr)/ (CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END) ,2) AS PMPM,round(SUM(b.pmpm_ly),2) AS PMPM_LY,ROUND(SUM(a.sale_ytd_cy)/100000/SUM(c.psr)/(CASE WHEN SUBSTR('"+month+"' ,5,2)<4 THEN SUBSTR('"+month+"' ,5,2)+9 ELSE SUBSTR('"+month+"' ,5,2)-3 END),2) - round(SUM(b.pmpm_ly),2) AS INC_PMPM,ROUND(SUM(a.sale_ytd_cy-a.hotrgt_ytd_cy)/10000000,1) AS YTD_ACH_EXTRA,(CASE WHEN SUM(a.sale_ytd_cy)<>0 THEN ROUND(SUM(a.retu_ytd_cy)/SUM(a.sale_ytd_cy)*100,1) ELSE ROUND(9.99*100,1) END) AS RETU_YTD_PRCT,sum(b.bud_inc_pmpm) as bud_inc_pmpm FROM (SELECT dwh.fin_year , dwh.item_ser,SUM(sale_mth_cy) AS sale_mth_cy,SUM(sale_mth_ly) AS sale_mth_ly,SUM(trgt_mth_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_mth_cy,SUM(sale_YTD_cy) AS sale_YTD_cy,SUM(sale_YTD_ly) AS sale_YTD_ly,SUM(trgt_YTD_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_ytd_cy,SUM(sale_Qrt1_cy) AS sale_Qrt1_cy, "
+" SUM(sale_Qrt2_cy) AS sale_Qrt2_cy,SUM(sale_Qrt3_cy) AS sale_Qrt3_cy,SUM(sale_Qrt4_cy) AS sale_Qrt4_cy,SUM(trgt_annual_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_annual_cy,SUM(retu_ytd_cy) AS retu_ytd_cy FROM(SELECT fin_year , SM_SALES_SUMM_WIDE.item_ser, " +" SUM(sale_Qrt2_cy) AS sale_Qrt2_cy,SUM(sale_Qrt3_cy) AS sale_Qrt3_cy,SUM(sale_Qrt4_cy) AS sale_Qrt4_cy,SUM(trgt_annual_cy * (100+ NVL(brnd.HO_TRGT_INCR_PRCNT,0)) /100) AS hotrgt_annual_cy,SUM(retu_ytd_cy) AS retu_ytd_cy FROM(SELECT fin_year , SM_SALES_SUMM_WIDE.item_ser, "
+" sales_item.item_sub_group AS sub_grp, (CASE WHEN SUBSTR('"+month+"' ,5,2) ='04' THEN SUM(CY_SALE_MTH_APR) WHEN SUBSTR('"+month+"' ,5,2) ='05' THEN SUM(CY_SALE_MTH_MAY) WHEN SUBSTR('"+month+"' ,5,2) ='06' THEN SUM(CY_SALE_MTH_JUN)WHEN SUBSTR('"+month+"' ,5,2) ='07' THEN SUM(CY_SALE_MTH_JUL) WHEN SUBSTR('"+month+"' ,5,2) ='08' THEN SUM(CY_SALE_MTH_AUG) WHEN SUBSTR('"+month+"' ,5,2) ='09' THEN SUM(CY_SALE_MTH_SEP) WHEN SUBSTR('"+month+"' ,5,2) ='10' THEN SUM(CY_SALE_MTH_OCT) WHEN SUBSTR('"+month+"' ,5,2) ='11' THEN SUM(CY_SALE_MTH_NOV) WHEN SUBSTR('"+month+"' ,5,2) ='12' THEN SUM(CY_SALE_MTH_DEC) WHEN SUBSTR('"+month+"' ,5,2) ='01' THEN SUM(CY_SALE_MTH_JAN) WHEN SUBSTR('"+month+"' ,5,2) ='02' THEN SUM(CY_SALE_MTH_FEB) WHEN SUBSTR('"+month+"' ,5,2) ='03' THEN SUM(CY_SALE_MTH_MAR) END ) AS sale_mth_cy, " +" sales_item.item_sub_group AS sub_grp, (CASE WHEN SUBSTR('"+month+"' ,5,2) ='04' THEN SUM(CY_SALE_MTH_APR) WHEN SUBSTR('"+month+"' ,5,2) ='05' THEN SUM(CY_SALE_MTH_MAY) WHEN SUBSTR('"+month+"' ,5,2) ='06' THEN SUM(CY_SALE_MTH_JUN)WHEN SUBSTR('"+month+"' ,5,2) ='07' THEN SUM(CY_SALE_MTH_JUL) WHEN SUBSTR('"+month+"' ,5,2) ='08' THEN SUM(CY_SALE_MTH_AUG) WHEN SUBSTR('"+month+"' ,5,2) ='09' THEN SUM(CY_SALE_MTH_SEP) WHEN SUBSTR('"+month+"' ,5,2) ='10' THEN SUM(CY_SALE_MTH_OCT) WHEN SUBSTR('"+month+"' ,5,2) ='11' THEN SUM(CY_SALE_MTH_NOV) WHEN SUBSTR('"+month+"' ,5,2) ='12' THEN SUM(CY_SALE_MTH_DEC) WHEN SUBSTR('"+month+"' ,5,2) ='01' THEN SUM(CY_SALE_MTH_JAN) WHEN SUBSTR('"+month+"' ,5,2) ='02' THEN SUM(CY_SALE_MTH_FEB) WHEN SUBSTR('"+month+"' ,5,2) ='03' THEN SUM(CY_SALE_MTH_MAR) END ) AS sale_mth_cy, "
+" (CASE WHEN SUBSTR('"+month+"' ,5,2) ='04' THEN SUM(LY_SALE_MTH_APR) WHEN SUBSTR('"+month+"' ,5,2) ='05' THEN SUM(LY_SALE_MTH_MAY) WHEN SUBSTR('"+month+"' ,5,2) ='06' THEN SUM(LY_SALE_MTH_JUN) WHEN SUBSTR('"+month+"' ,5,2) ='07' THEN SUM(lY_SALE_MTH_JUL) WHEN SUBSTR('"+month+"' ,5,2) ='08' THEN SUM(lY_SALE_MTH_AUG) WHEN SUBSTR('"+month+"' ,5,2) ='09' THEN SUM(lY_SALE_MTH_SEP) WHEN SUBSTR('"+month+"' ,5,2) ='10' THEN SUM(lY_SALE_MTH_OCT) WHEN SUBSTR('"+month+"' ,5,2) ='11' THEN SUM(lY_SALE_MTH_NOV) WHEN SUBSTR('"+month+"' ,5,2) ='12' THEN SUM(lY_SALE_MTH_DEC) WHEN SUBSTR('"+month+"' ,5,2) ='01' THEN SUM(lY_SALE_MTH_JAN) WHEN SUBSTR('"+month+"' ,5,2) ='02' THEN SUM(lY_SALE_MTH_FEB) WHEN SUBSTR('"+month+"' ,5,2) ='03' THEN SUM(lY_SALE_MTH_MAR) END ) AS sale_mth_ly, " +" (CASE WHEN SUBSTR('"+month+"' ,5,2) ='04' THEN SUM(LY_SALE_MTH_APR) WHEN SUBSTR('"+month+"' ,5,2) ='05' THEN SUM(LY_SALE_MTH_MAY) WHEN SUBSTR('"+month+"' ,5,2) ='06' THEN SUM(LY_SALE_MTH_JUN) WHEN SUBSTR('"+month+"' ,5,2) ='07' THEN SUM(lY_SALE_MTH_JUL) WHEN SUBSTR('"+month+"' ,5,2) ='08' THEN SUM(lY_SALE_MTH_AUG) WHEN SUBSTR('"+month+"' ,5,2) ='09' THEN SUM(lY_SALE_MTH_SEP) WHEN SUBSTR('"+month+"' ,5,2) ='10' THEN SUM(lY_SALE_MTH_OCT) WHEN SUBSTR('"+month+"' ,5,2) ='11' THEN SUM(lY_SALE_MTH_NOV) WHEN SUBSTR('"+month+"' ,5,2) ='12' THEN SUM(lY_SALE_MTH_DEC) WHEN SUBSTR('"+month+"' ,5,2) ='01' THEN SUM(lY_SALE_MTH_JAN) WHEN SUBSTR('"+month+"' ,5,2) ='02' THEN SUM(lY_SALE_MTH_FEB) WHEN SUBSTR('"+month+"' ,5,2) ='03' THEN SUM(lY_SALE_MTH_MAR) END ) AS sale_mth_ly, "
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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