Commit d7234d5b authored by prumde's avatar prumde

Added for Sells Planning Review - Summary

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@217346 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 97dba965
package ibase.dashboard.common.bean;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import javax.ejb.Stateless;
import org.json.JSONArray;
import ibase.ejb.CommonDBAccessEJB;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class SellsPlanSummary extends ValidatorEJB
{
public String getPlanSummaryData(String xmlData) throws RemoteException, ITMException
{
JSONArray finalPlanSummaryData = new JSONArray();
PreparedStatement pStmt = null;
ResultSet rs = null;
Connection conn = null;
try
{
System.out.println("INSIDE SellsPlanSummary ::::::::::::::: getPlanSummaryData ["+xmlData+"]" + getUserInfo());
UserInfoBean userInfo = getUserInfo();
if( userInfo != null )
{
String maxLevel = "";
String tranDb= userInfo.getTransDB();
String empCode= userInfo.getEmpCode();
E12GenericUtility genericUtility = new E12GenericUtility();
System.out.println("getPlanSummaryData tranDb:::: "+tranDb+" empCode "+empCode);
StringBuffer planDataSql = new StringBuffer();
StringBuffer teamMaxLvlSql = new StringBuffer();
if( tranDb != null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB(tranDb );
teamMaxLvlSql.append("SELECT MAX(LVL) AS MAX_LVL FROM ( SELECT POS_CODE, POS_CODE__REPTO, EMP_CODE, " )
.append(" (SELECT EMP_CODE FROM ORG_STRUCTURE WHERE POS_CODE = O1.POS_CODE__REPTO) AS REPORT_TO, " )
.append(" LEVEL as LVL " )
.append(" FROM ORG_STRUCTURE O1 " )
.append(" START WITH EMP_CODE = '"+ empCode + "' " )
.append(" CONNECT BY PRIOR POS_CODE = POS_CODE__REPTO )" );
pStmt = conn.prepareStatement( teamMaxLvlSql.toString() );
rs = pStmt.executeQuery();
while(rs.next())
{
maxLevel = rs.getString("MAX_LVL");
System.out.println("maxLevel " + maxLevel);
}
pStmt.close();
pStmt = null;
rs.close();
rs = null;
planDataSql.append(" SELECT POS_CODE, POS_CODE__REPTO, EMP_CODE, " )
.append(" (SELECT EMP_CODE FROM ORG_STRUCTURE WHERE POS_CODE = O1.POS_CODE__REPTO) AS REPORT_TO, " )
.append(" LEVEL as LVL " )
.append(" FROM ORG_STRUCTURE O1 " )
.append(" START WITH EMP_CODE = '"+ empCode + "' " )
.append(" CONNECT BY PRIOR POS_CODE = POS_CODE__REPTO " );
System.out.println("SQL QUERY EXECUTED ::::::::::::::::: " + planDataSql );
CommonDBAccessEJB commonDBAccessEJB = new CommonDBAccessEJB();
HashMap teamListLevelWise = commonDBAccessEJB.getSQLResultMapData(planDataSql.toString(), tranDb);
System.out.println("SQL RESULT AFTER EXECUTED ::::::::::::::::: " + ( teamListLevelWise != null ? teamListLevelWise.size() : 0 ) );
if( teamListLevelWise != null )
{
ArrayList<HashMap<String, String>> teamData = (ArrayList<HashMap<String, String>>) teamListLevelWise.get("ROWS");
System.out.println("SQL RESULT AFTER EXECUTED ::::::::teamData::::::::: " + teamData );
ArrayList<HashMap<String, String>> allLevelData = new ArrayList<HashMap<String, String>>();
int maxLevelInt = parseInt(maxLevel);
while( maxLevelInt > 0 )
{
System.out.println("SQL RESULT AFTER EXECUTED ::::::::maxLevel::::::::: " + maxLevelInt );
ArrayList<HashMap<String, String>> currentLevelData = getCurrentLevelData( teamData, tranDb, ( maxLevelInt - 1 ) );
allLevelData.addAll(currentLevelData);
maxLevelInt--;
}
finalPlanSummaryData = new JSONArray(allLevelData);
}
}
}
}
catch (Exception e)
{
System.out.println("Exception in getPlanSummaryData tranDb:::: "+e.getMessage());
e.printStackTrace();
}
finally
{
try
{
if( pStmt != null )
{
pStmt.close();
pStmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if ( conn != null )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("finalPlanSummaryData:: "+finalPlanSummaryData);
return finalPlanSummaryData.toString();
}
private ArrayList<HashMap<String, String>> getCurrentLevelData( ArrayList<HashMap<String, String>> currentLevelAllEmp, String tranDb, int currentLevel )
{
ArrayList<HashMap<String, String>> currentLevelSummary = new ArrayList<HashMap<String, String>>();
ArrayList<String> empCodes = new ArrayList<String>();
for( HashMap<String, String> currentLevelEmp : currentLevelAllEmp )
{
int hierLevel = parseInt(currentLevelEmp.get("LVL"));
if( hierLevel == currentLevel )
{
String empCode = checkNull(currentLevelEmp.get("EMP_CODE"), false);
empCodes.add(empCode);
}
}
for(String empCode : empCodes )
{
ArrayList<HashMap<String, String>> empSellSummData = getSummarySellsData(empCode, tranDb);
currentLevelSummary.addAll(empSellSummData);
}
return currentLevelSummary;
}
private ArrayList<HashMap<String, String>> getSummarySellsData(String empCode, String tranDb)
{
StringBuffer summaryDataSql = new StringBuffer();
summaryDataSql.append("SELECT ")
.append(" '" + empCode + "' AS EMP_CODE, ")
.append(" I.ITEM_CODE, ")
.append(" I.PRODUCT_CODE, ")
.append(" (SELECT DESCR FROM ITEM WHERE ITEM_CODE = I.ITEM_CODE) PRODUCT_NAME, ")
.append(" SUM(SPD.SELL_IN_QTY) AS SELL_IN_QTY, ")
.append(" SUM(SPD.SELL_OUT_QTY) AS SELL_OUT_QTY, ")
.append(" SUM(SPD.SELL_IN_VALUE) AS SELL_IN_VALUE, ")
.append(" SUM(SPD.SELL_OUT_VALUE) AS SELL_OUT_VALUE ")
.append("FROM SELLS_PLANNING SP ")
.append("LEFT OUTER JOIN SELLS_PLANNING_DET SPD ON SP.TRAN_ID = SPD.TRAN_ID ")
.append("LEFT OUTER JOIN ITEM I ON SPD.ITEM_CODE = I.ITEM_CODE ")
.append("WHERE SP.PRD_CODE = TO_CHAR(SYSDATE, 'YYYYMM') ")
.append("AND SP.STATUS = 'S' ")
.append("AND SP.SALES_PERS IN ( ")
.append(" SELECT EMP_CODE ")
.append(" FROM ORG_STRUCTURE O1 ")
.append(" START WITH EMP_CODE = '" + empCode + "' ")
.append(" CONNECT BY PRIOR POS_CODE = POS_CODE__REPTO ")
.append(") ")
.append("GROUP BY I.ITEM_CODE, I.PRODUCT_CODE ");
CommonDBAccessEJB commonDBAccessEJB = new CommonDBAccessEJB();
HashMap empSellSummData = commonDBAccessEJB.getSQLResultMapData(summaryDataSql.toString(), tranDb);
System.out.println("SQL RESULT AFTER EXECUTED ::::::::::::::::: " + ( empSellSummData != null ? empSellSummData.size() : 0 ) );
ArrayList<HashMap<String, String>> _empSellSummData = new ArrayList<HashMap<String, String>>();
if( empSellSummData != null )
{
_empSellSummData = (ArrayList<HashMap<String, String>>) empSellSummData.get("ROWS");
}
return _empSellSummData;
}
/*
private ArrayList<HashMap<String, String>> calculateCumulativeSum( ArrayList<HashMap<String, String>> sprsDataRows, int maxLevel )
{
for( HashMap<String, String> sprsDataRow : sprsDataRows )
{
try
{
int currentLevel = parseInt(sprsDataRow.get("LVL"));
System.out.println("For currentLevel [" + currentLevel + "] maxLevel[" + maxLevel + "]");
if( currentLevel == maxLevel )
{
String posCode = checkNull(sprsDataRow.get("POS_CODE"));
String itemCode = checkNull(sprsDataRow.get("ITEM_CODE"));
//System.out.println("For poscode [" + posCode + "]");
int sell_in_qty = parseInt(sprsDataRow.get("SELL_IN_QTY"));
int sell_out_qty = parseInt(sprsDataRow.get("SELL_OUT_QTY"));
int sell_in_value = parseInt(sprsDataRow.get("SELL_IN_VALUE"));
int sell_out_value = parseInt(sprsDataRow.get("SELL_OUT_VALUE"));
for( HashMap<String, String> _sprsDataRow : sprsDataRows )
{
String posCodeRep = checkNull(_sprsDataRow.get("POS_CODE__REPTO"));
String itemCodeRep = checkNull(_sprsDataRow.get("ITEM_CODE"));
if( posCode.equalsIgnoreCase(posCodeRep) && itemCode.equalsIgnoreCase(itemCodeRep) )
{
System.out.println("Match posCode [" + posCode + "] posCodeRep[" + posCodeRep + "]");
System.out.println("Match posCode [" + itemCode + "] posCodeRep[" + itemCodeRep + "]");
int _sell_in_qty = parseInt(_sprsDataRow.get("SELL_IN_QTY"));
int _sell_out_qty = parseInt(_sprsDataRow.get("SELL_OUT_QTY"));
int _sell_in_value = parseInt(_sprsDataRow.get("SELL_IN_VALUE"));
int _sell_out_value = parseInt(_sprsDataRow.get("SELL_OUT_VALUE"));
sell_in_qty += _sell_in_qty;
sell_out_qty += _sell_out_qty;
sell_in_value += _sell_in_value;
sell_out_value += _sell_out_value;
}
}
//Set Sum of Fields
// SELL_IN_QTY
// SELL_OUT_QTY
// SELL_IN_VALUE
// SELL_OUT_VALUE
sprsDataRow.put("SELL_IN_QTY", sell_in_qty+"");
sprsDataRow.put("SELL_OUT_QTY", sell_out_qty+"");
sprsDataRow.put("SELL_IN_VALUE", sell_in_value+"");
sprsDataRow.put("SELL_OUT_VALUE", sell_out_value+"");
}
}
catch(Exception e)
{
}
}
return sprsDataRows;
}
*/
private String checkNull(String input)
{
return checkNull(input, true);
}
private String checkNull(String input, boolean isTrim)
{
if (input == null || "null".equalsIgnoreCase(input))
{
input= "";
}
return isTrim ? input.trim() : input;
}
private int parseInt(String input)
{
try
{
return Integer.parseInt(checkNull(input));
}
catch(Exception e)
{
}
return 0;
}
}
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