Commit 9d2acd7f authored by nsawalakhe's avatar nsawalakhe

Added Ejb in mfg module


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@104111 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4062477a
package ibase.dashboard.mfg.ejb;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedHashMap;
import javax.ejb.Stateless;
import org.json.simple.JSONObject;
/**
* Session Bean implementation class ProfitLossBalSheet
*/
@Stateless
public class MFGDashboard extends ValidatorEJB implements MFGDashboardLocal, MFGDashboardRemote {
/**
* Default constructor.
*/
JSONObject rawDataJson = new JSONObject();
String codes[]=new String[20];
String signs[] =new String[20];
public MFGDashboard()
{
}
@SuppressWarnings("unchecked")
@Override
public JSONObject getDelayProductionSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataMfgDelaySummJson = new JSONObject();
JSONObject rowData = null;
String fromDate = "";
String toDate = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
//businessType="T";
//facilityCode="FC001";
String delayProductOrderWise="";
String delayProductValueWise ="";
String delayProductQtyWise ="";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select u.descr as unit_form, count(distinct w.work_order) as value " + //no_orders
"from workorder w, workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser " +
"and u.unit = t.unit__form and s.site_code = w.site_code " +
"and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
delayProductValueWise = "select u.descr as unit_form, sum(fn_production_value(r.tran_id)) as value from workorder w, " + //production_value
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type "+
"and its.item_ser = i.item_ser " +
"and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
delayProductQtyWise = "select u.descr as unit_form, sum(fn_qty_form(r.item_code,w.unit,t.unit__form, r.quantity)) as value from workorder w, " + //quantity
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type "+
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("label",rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rawDataMfgDelaySummJson.put(count, rowData);
count++;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMfgDelaySummJson;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject getProductDeviationSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataJsonForDeviationSumm = null;
JSONObject rowData = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String sql = "";
String fromDate = "";
String toDate = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
double percntVal = 0.0;
double dashOffSet = 0.0;
int nooforder=0;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
e12GenericUtility = new E12GenericUtility();
System.out.println("getApplDateFormat()======="+e12GenericUtility.getApplDateFormat());
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
double percentage = 0.0D; double totalCircle = 629.0D;
double order = 0.0D; double value = 0.0D;
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("Excution of SQL");
rawDataJsonForDeviationSumm =new JSONObject();
//This SQL used for Deviation issue and passing parameter from and toDate
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
sql = "select count(iss.item_code) no_issues, count(distinct w.work_order) no_orders from workorder w, workorder_iss iss, site s, item i, itemser its where iss.work_order = w.work_order " +
"and s.site_code = w.site_code " +
"and i.item_code = w.item_code " +
"and its.item_ser = i.item_ser "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(iss.conf_date) between '"+fromDate+"' and '"+toDate+"' ";
pstmt= conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int count=0;
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
value = Double.parseDouble(checkNull(rs.getString("no_issues")));
rowData.put("title","Deviation Issue");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Issue");
rowData.put("order",rs.getString("no_orders"));
nooforder=rs.getInt("no_orders");
rowData.put("value",rs.getString("no_issues"));
percntVal = order / value * 100.0D;
dashOffSet = totalCircle * percentage / 100.0D;
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationSumm.put(count, rowData);
count++;
}
//End the Deviation issue task
pstmt.close();
pstmt = null;
rs.close();
rs = null;
//Start the SQL for Rework order
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
sql = "select count(distinct w.work_order) rework_orders from workorder w, site s, item i, itemser its " +
"where s.site_code = w.site_code and i.item_code = w.item_code and its.item_ser = i.item_ser " +
"and w.ord_type = 'R' "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(iss.conf_date) between '"+fromDate+"' and '"+toDate+"' ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
value = Double.parseDouble(checkNull(rs.getString("rework_orders")));
percntVal = order / value * 100.0D;
dashOffSet = totalCircle * percentage / 100.0D;
rowData.put("title","Rework Order");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Rework");
rowData.put("order",nooforder);
rowData.put("value",rs.getString("rework_orders"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationSumm.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
//Start the SQL for Yeild loss
sql = "select sum(o.quantity / (i.receipt_quantity) - 100) as yield_gain, count(distinct o.work_order) " +
"as no_orders from ( select w.work_order, sum(r.quantity) as receipt_quantity from workorder w," +
" workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and r.tran_type = 'F' " +
"and s.site_code = w.site_code and sum(r.quantity) < w.quantity "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.work_order ) i, workorder o where o.work_order = i.work_order " +
"and i.receipt_quantity < o.quantity ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
rowData.put("title","Yeild Loss");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Loss");
rowData.put("order",rs.getString("no_orders"));
rowData.put("value",rs.getString("yield_gain") == null ? "0" : rs.getString("yield_gain"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationSumm.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
//Start the SQL for Yeild Gain
sql = "select sum(o.quantity / (i.receipt_quantity) - 100) as yield_gain, count(distinct o.work_order) " +
"as no_orders from ( select w.work_order, sum(r.quantity) as receipt_quantity from workorder w, " +
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and r.tran_type = 'F' " +
"and s.site_code = w.site_code and sum(r.quantity) > w.quantity "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.work_order ) i, workorder o where o.work_order = i.work_order " +
"and i.receipt_quantity > o.quantity ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
rowData.put("title","Yeild Gain");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Gain");
rowData.put("order",rs.getString("no_orders"));
rowData.put("value",rs.getString("yield_gain") == null ? "0" : rs.getString("yield_gain"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationSumm.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataJsonForDeviationSumm;
}
/*@SuppressWarnings("unchecked")
@Override
public JSONObject getWtNGainLossSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataWtGainLossSummJson = new JSONObject();
JSONObject rowData = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String delayProductOrderWise = "";
String delayProductValueWise = "";
String delayProductQtyWise = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
String fromDate = "";
String toDate = "";
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select u.descr as unit_form, count(distinct w.work_order) as value " + //no_orders
"from workorder w, workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser " +
"and u.unit = t.unit__form and s.site_code = w.site_code " +
"and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
delayProductValueWise = "select u.descr as unit_form, 100 as value from workorder w, " + //production_value
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
delayProductQtyWise = "select u.descr as unit_form, 400 as value from workorder w, " + //quantity
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
rowData = new JSONObject();
rowData.put("label",rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rowData.put("yield_gain",rs.getString("YIELD_GAIN"));
rowData.put("no_orders",rs.getString("NO_ORDERS"));
rawDataWtGainLossSummJson.put(count, rowData);
count++;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataWtGainLossSummJson;
}*/
@SuppressWarnings("unchecked")
@Override
public JSONObject getProcessStageSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataProcessStageSummJson = new JSONObject();
JSONObject rowData = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String delayProductOrderWise = "";
String delayProductValueWise = "";
String delayProductQtyWise = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
String fromDate = "";
String toDate = "";
LinkedHashMap<String, String> catValues = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select u.descr as product_form, p.descr as process_descr, " +
"count(distinct f.work_order) no_order from workorder_feedback f, workorder w, " +
"item i, item_type t, itemser its, procroute pr,process p, uom u " +
"where f.work_order = w.work_order and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation and w.status = 'P' " +
"and f.operation = (select max(fb.operation) " +
"from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr ";
/*Dummy SQL */
delayProductValueWise = "select u.descr as product_form, p.descr as process_descr, count(distinct f.work_order) no_order " +
"from workorder_feedback f, workorder w, item i, item_type t, itemser its, procroute pr,process p, " +
"uom u where f.work_order = w.work_order " +
"and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser " +
"and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation " +
"and w.status = 'P' " +
"and f.operation = (select max(fb.operation) from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr ";
/* Dummy SQL */
delayProductQtyWise = "select u.descr as product_form, p.descr as process_descr, count(distinct f.work_order) no_order " +
"from workorder_feedback f, workorder w, item i, item_type t, itemser its, procroute pr,process p, " +
"uom u where f.work_order = w.work_order " +
"and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser " +
"and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation " +
"and w.status = 'P' " +
"and f.operation = (select max(fb.operation) from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr ";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
while (rs.next())
{
catValues = new LinkedHashMap<String, String>();
rowData = new JSONObject();
rowData.put("product_form",count);
rowData.put("product_category", rs.getString("process_descr"));
catValues.put(rs.getString("process_descr"), rs.getString("no_order"));
rowData.put("category_value",catValues);
rawDataProcessStageSummJson.put(count, rowData);
count++;
}
System.out.println("************ rawDataProcessStageSummJson :"+rawDataProcessStageSummJson);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataProcessStageSummJson;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject getDelayProductionDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataMfgDelayDetJsonOuter = new JSONObject();
JSONObject rawDataMfgDelayDetJson = new JSONObject();
JSONObject rowData = null;
String fromDate = "";
String toDate = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
//businessType="T";
//facilityCode="FC001";
String delayProductOrderWise = "";
String delayProductValueWise = "";
String delayProductQtyWise = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select w.site_code,u.descr as unit_form, count(distinct w.work_order) as value " + //no_orders
"from workorder w, workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser " +
"and u.unit = t.unit__form and s.site_code = w.site_code " +
"and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
delayProductValueWise = "select w.site_code,u.descr as unit_form, sum(fn_production_value(r.tran_id)) as value from workorder w, " + //production_value
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
delayProductQtyWise = "select w.site_code,u.descr as unit_form, sum(fn_qty_form(r.item_code,w.unit,t.unit__form, r.quantity)) as value from workorder w, " + //quantity
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type "+
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in Details order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in Details quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in Details value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
String siteCode = "";
String prvSitecode = "";
while (rs.next())
{
siteCode = rs.getString("site_code");
if(!siteCode.equalsIgnoreCase(prvSitecode))
{
rawDataMfgDelayDetJson = new JSONObject();
rowData = new JSONObject();
count = 0;
rowData.put("label", rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rawDataMfgDelayDetJson.put(count, rowData);
count++;
prvSitecode = siteCode;
rawDataMfgDelayDetJsonOuter.put(prvSitecode, rawDataMfgDelayDetJson);
}
else
{
rowData = new JSONObject();
rowData.put("label", rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rawDataMfgDelayDetJson.put(count, rowData);
count++;
}
}
//rawDataMfgDelayDetJsonOuter.put(siteCode, rawDataMfgDelayDetJson);
System.out.println("rawDataMfgDelayDetJsonOuter :"+rawDataMfgDelayDetJsonOuter);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataMfgDelayDetJsonOuter;
}
@SuppressWarnings("unchecked")
@Override
public JSONObject getProductDeviationDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataJsonForDeviationDet = null;
JSONObject rowData = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String sql = "";
String fromDate = "";
String toDate = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
double percntVal = 0.0;
double dashOffSet = 0.0;
int nooforder=0;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
e12GenericUtility = new E12GenericUtility();
System.out.println("getApplDateFormat()======="+e12GenericUtility.getApplDateFormat());
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
double percentage = 0.0D; double totalCircle = 629.0D;
double order = 0.0D; double value = 0.0D;
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("Excution of SQL");
rawDataJsonForDeviationDet =new JSONObject();
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
//This SQL used for Deviation issue and passing parameter from and toDate
sql = "SELECT w.site_code, COUNT(iss.item_code) no_issues, COUNT(DISTINCT w.work_order) no_orders " +
"FROM workorder w, workorder_iss iss, site s, item i, itemser its " +
"WHERE iss.work_order = w.work_order AND s.site_code = w.site_code " +
"AND i.item_code = w.item_code AND its.item_ser = i.item_ser "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(iss.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.site_code " ;
pstmt= conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int count=0;
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
value = Double.parseDouble(checkNull(rs.getString("no_issues")));
rowData.put("title","Deviation Issue");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Issue");
rowData.put("order",rs.getString("no_orders"));
nooforder=rs.getInt("no_orders");
rowData.put("value",rs.getString("no_issues"));
percntVal = order / value * 100.0D;
dashOffSet = totalCircle * percentage / 100.0D;
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationDet.put(count, rowData);
count++;
}
//End the Deviation issue task
pstmt.close();
pstmt = null;
rs.close();
rs = null;
//Start the SQL for Rework order
sql = "select w.site_code,count(distinct w.work_order) rework_orders from workorder w, site s, item i, " +
"itemser its where s.site_code = w.site_code and i.item_code = w.item_code " +
"and its.item_ser = i.item_ser " +
"and w.ord_type = 'R' "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(iss.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.site_code ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
value = Double.parseDouble(checkNull(rs.getString("rework_orders")));
percntVal = order / value * 100.0D;
dashOffSet = totalCircle * percentage / 100.0D;
rowData.put("title","Rework Order");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Rework");
rowData.put("order",nooforder);
rowData.put("value",rs.getString("rework_orders"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationDet.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
//Start the SQL for Yeild loss
sql = "select sum(o.quantity / (i.receipt_quantity) - 100) as yield_gain, count(distinct o.work_order) " +
"as no_orders from ( select w.work_order, sum(r.quantity) as receipt_quantity from workorder w," +
" workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and r.tran_type = 'F' " +
"and s.site_code = w.site_code and sum(r.quantity) < w.quantity '"+facilityCode+"' " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.work_order ) i, workorder o where o.work_order = i.work_order " +
"and i.receipt_quantity < o.quantity ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
rowData.put("title","Yeild Loss");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Loss");
rowData.put("order",rs.getString("no_orders"));
rowData.put("value",rs.getString("yield_gain") == null ? "0" : rs.getString("yield_gain"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationDet.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
//Start the SQL for Yeild Gain
sql = "select sum(o.quantity / (i.receipt_quantity) - 100) as yield_gain, count(distinct o.work_order) " +
"as no_orders from ( select w.work_order, sum(r.quantity) as receipt_quantity from workorder w, " +
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and r.tran_type = 'F' " +
"and s.site_code = w.site_code and sum(r.quantity) > w.quantity '"+facilityCode+"' " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by w.work_order ) i, workorder o where o.work_order = i.work_order " +
"and i.receipt_quantity > o.quantity ";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next())
{
rowData = new JSONObject();
order = Double.parseDouble(checkNull(rs.getString("no_orders")));
rowData.put("title","Yeild Gain");
rowData.put("no. of orderlabel","Order");
rowData.put("valuelabel","Gain");
rowData.put("order",rs.getString("no_orders"));
rowData.put("value",rs.getString("yield_gain") == null ? "0" : rs.getString("yield_gain"));
rowData.put("spanvalue", Math.round(percntVal) + "%");
rowData.put("percentage", Long.valueOf(Math.round(percntVal)));
rowData.put("dashOffSet", Double.valueOf(dashOffSet));
rowData.put("tbldisplay", "style='display: visible'");
rowData.put("circledisplay", "c100");
rawDataJsonForDeviationDet.put(count, rowData);
count++;
}
pstmt.close();
pstmt = null;
rs.close();
rs = null;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataJsonForDeviationDet;
}
/*@SuppressWarnings("unchecked")
@Override
public JSONObject getWtNGainLossDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataWtGainLossDetJsonOuter = new JSONObject();
JSONObject rawDataWtGainLossDetJson = new JSONObject();
JSONObject rowData = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String delayProductOrderWise = "";
String delayProductValueWise = "";
String delayProductQtyWise = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
String fromDate = "";
String toDate = "";
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
//End the code of MTD format
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select w.site_code,u.descr as unit_form, count(distinct w.work_order) as value " + //no_orders
"from workorder w, workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser " +
"and u.unit = t.unit__form and s.site_code = w.site_code " +
"and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
delayProductValueWise = "select w.site_code,u.descr as unit_form, 100 as value from workorder w, " + //production_value
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
delayProductQtyWise = "select w.site_code,u.descr as unit_form, 400 as value from workorder w, " + //quantity
"workorder_receipt r, item i, item_type t, uom u, site s, itemser its " +
"where r.work_order = w.work_order and i.item_code = r.item_code " +
"and t.item_type = i.item_type " +
"and its.item_ser = i.item_ser and u.unit = t.unit__form " +
"and s.site_code = w.site_code and (to_date(r.conf_date) - to_date(w.due_date) + 1) > 0 "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr ,w.site_code order by w.site_code ";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in Details order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in Details quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in Details value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
String siteCode = "";
String prvSitecode = "";
while (rs.next())
{
siteCode = rs.getString("site_code");
if(!siteCode.equalsIgnoreCase(prvSitecode))
{
rawDataWtGainLossDetJson = new JSONObject();
rowData = new JSONObject();
count = 0;
rowData.put("label", rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rawDataWtGainLossDetJson.put(count, rowData);
count++;
prvSitecode = siteCode;
rawDataWtGainLossDetJsonOuter.put(prvSitecode, rawDataWtGainLossDetJson);
}
else
{
rowData = new JSONObject();
rowData.put("label", rs.getString("unit_form"));
rowData.put("value",rs.getString("value"));
rawDataWtGainLossDetJson.put(count, rowData);
count++;
}
}
//rawDataMfgDelayDetJsonOuter.put(siteCode, rawDataMfgDelayDetJson);
System.out.println("rawDataWtGainLossDetJsonOuter :"+rawDataWtGainLossDetJsonOuter);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataWtGainLossDetJsonOuter;
}*/
@SuppressWarnings("unchecked")
@Override
public JSONObject getProcessStageDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException
{
JSONObject rawDataProcessStageDetJsonOuter = new JSONObject();
JSONObject rawDataProcessStageDetJson = new JSONObject();
JSONObject rowData = null;
JSONObject rawJson = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
String delayProductOrderWise = "";
String delayProductValueWise = "";
String delayProductQtyWise = "";
E12GenericUtility e12GenericUtility = null;
SimpleDateFormat convertToDBDate = null;
Calendar calendar = null;
String fromDate = "";
String toDate = "";
LinkedHashMap<String, String> catValues = null;
try
{
conn = connDriver.getConnectDB(dataSourceName);
connDriver = null;
//Add code of MTD for default on loading case
if((fromDate==null) ||(fromDate.equals("")) && (toDate==null) || (toDate.equals("")))
{
e12GenericUtility = new E12GenericUtility();
convertToDBDate = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate = convertToDBDate.format(calendar.getTime());
toDate = convertToDBDate.format(Calendar.getInstance().getTime());
System.out.println("In facilityCode==="+facilityCode +"frmDate ====" + fromDate+" toDate==="+toDate);
}
else
{
e12GenericUtility = new E12GenericUtility();
fromDate = e12GenericUtility.getValidDateString(fromDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
toDate = e12GenericUtility.getValidDateString(toDate, "dd/MM/yyyy", e12GenericUtility.getApplDateFormat());
}
String appendSql = "";
if(businessType.length()>0)
{
appendSql = " and its.business_type ='"+businessType+"' ";
}
if(facilityCode == null || ("".equalsIgnoreCase(facilityCode)))
{
facilityCode = getFacilityCode(sessionSiteCode, dataSourceName);
System.out.println("facilityCode from session getSkuFillRateDet :"+facilityCode);
}
delayProductOrderWise = "select w.site_code,u.descr as product_form, p.descr as process_descr, " +
"count(distinct f.work_order) no_order from workorder_feedback f, workorder w, " +
"item i, item_type t, itemser its, procroute pr,process p, uom u " +
"where f.work_order = w.work_order and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation and w.status = 'P' " +
"and f.operation = (select max(fb.operation) " +
"from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr,w.site_code ";
/*Dummy SQL */
delayProductValueWise = "select w.site_code,u.descr as product_form, p.descr as process_descr, count(distinct f.work_order) no_order " +
"from workorder_feedback f, workorder w, item i, item_type t, itemser its, procroute pr,process p, " +
"uom u where f.work_order = w.work_order " +
"and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser " +
"and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation " +
"and w.status = 'P' " +
"and f.operation = (select max(fb.operation) from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr ,w.site_code";
/* Dummy SQL */
delayProductQtyWise = "select w.site_code,u.descr as product_form, p.descr as process_descr, count(distinct f.work_order) no_order " +
"from workorder_feedback f, workorder w, item i, item_type t, itemser its, procroute pr,process p, " +
"uom u where f.work_order = w.work_order " +
"and i.item_code = w.item_code " +
"and t.item_type = i.item_type " +
"and u.unit = t.unit__form " +
"and its.item_ser = i.item_ser " +
"and p.proc_code = pr.proc_code " +
"and pr.operation = f.operation " +
"and w.status = 'P' " +
"and f.operation = (select max(fb.operation) from workorder_feedback fb where fb.work_order = w.work_order) "+appendSql+" " +
"and s.facility_code = '"+facilityCode+"' " +
"and to_date(r.conf_date) between '"+fromDate+"' and '"+toDate+"' " +
"group by u.descr, p.descr,w.site_code";
if("Order".equalsIgnoreCase(selectedView))
{
System.out.println("in order");
pstmt = conn.prepareStatement(delayProductOrderWise);
}
else if ("Quantity".equalsIgnoreCase(selectedView))
{
System.out.println("in quantity");
pstmt = conn.prepareStatement(delayProductQtyWise);
}
else if ("Value".equalsIgnoreCase(selectedView))
{
System.out.println("in value");
pstmt = conn.prepareStatement(delayProductValueWise);
}
rs = pstmt.executeQuery();
int count = 0;
String siteCode = "";
String prvSitecode = "";
while (rs.next())
{
siteCode = rs.getString("site_code");
if(!siteCode.equalsIgnoreCase(prvSitecode))
{
catValues = new LinkedHashMap<String, String>();
rawDataProcessStageDetJson = new JSONObject();
rowData = new JSONObject();
count = 0;
rowData.put("month",count);
rowData.put("product_category", rs.getString("product_form"));
catValues.put(rs.getString("process_descr"),rs.getString("no_order"));
rowData.put("category_value",catValues);
rawDataProcessStageDetJson.put(count, rowData);
count++;
prvSitecode = siteCode;
rawDataProcessStageDetJsonOuter.put(prvSitecode, rawDataProcessStageDetJson);
}
else
{
rowData = new JSONObject();
rowData.put("month",count);
rowData.put("product_category",rs.getString("product_form"));
catValues.put(rs.getString("process_descr"),rs.getString("no_order"));
rowData.put("category_value",catValues);
rawDataProcessStageDetJson.put(count, rowData);
count++;
}
/*catValues = new LinkedHashMap<String, String>();
rowData = new JSONObject();
rowData.put("month",count);
rowData.put("product_category", rs.getString("product_form"));
catValues.put(rs.getString("process_descr"), rs.getString("no_order"));
rowData.put("category_value",catValues);
rawDataProcessStageDetJson.put(count, rowData);
count++;*/
}
System.out.println("************ rawDataProcessStageDetJson :"+rawDataProcessStageDetJson);
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :MFGDashboard:" + d.getMessage());
throw new ITMException(d);
}
}
return rawDataProcessStageDetJsonOuter;
}
@SuppressWarnings("unused")
private String getFacilityCode(String siteCode, String dataSourceName) throws ITMException
{
String facilityCode = "";
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try {
conn= connDriver.getConnectDB(dataSourceName);
connDriver = null;
sql = "Select facility_code from site where site_code='"+siteCode+"'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
facilityCode = checkNull(rs.getString("facility_code")).trim();
}
} catch (Exception e) {
e.printStackTrace();
throw new ITMException(e);
}finally
{
try
{
if (conn != null)
{
if (rs != null)
rs.close();
rs = null;
if (pstmt != null)
pstmt.close();
pstmt = null;
conn.close();
conn = null;
}
conn = null;
} catch (Exception d)
{
d.printStackTrace();
System.out.println("Exception in :getFacilityCode:" + d.getMessage());
throw new ITMException(d);
}
}
return facilityCode;
}
private String checkNull(String str)
{
if(str == null)
{
return "";
}
else
{
return str ;
}
}
}
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.json.simple.JSONObject;
@Local
public interface MFGDashboardLocal extends ValidatorLocal {
public JSONObject getDelayProductionSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProductDeviationSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
//public JSONObject getWtNGainLossSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProcessStageSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getDelayProductionDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode ) throws RemoteException, ITMException;
public JSONObject getProductDeviationDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
//public JSONObject getWtNGainLossDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProcessStageDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
}
package ibase.dashboard.mfg.ejb;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.json.simple.JSONObject;
@Remote
public interface MFGDashboardRemote extends ValidatorRemote{
public JSONObject getDelayProductionSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProductDeviationSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
//public JSONObject getWtNGainLossSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProcessStageSumm(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getDelayProductionDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode ) throws RemoteException, ITMException;
public JSONObject getProductDeviationDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
//public JSONObject getWtNGainLossDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
public JSONObject getProcessStageDet(String dataSourceName,String businessType,String facilityCode,String selectedView, String sessionSiteCode) throws RemoteException, ITMException;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment