package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.ejb.common.business.BaseBO;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.utility.DBUtilitiesBean;

public class HrmReportBO extends BaseBO {
  public void saveDetailImpl(String sHeaderPrimaryKey, BaseHeaderBean oBaseHeaderBean, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {}
  
  public void initializeBOImpl(String sScreenName) {
    String sDetailTable = null;
    if (sScreenName.equals("EnqPayImgScreen"))
      sDetailTable = "aaa_myadd"; 
    initializeBO("aaa_myself", sDetailTable);
  }
  
  public LovVO getYYMMReportLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select distinct pim.yyyymm  from pay_image pim where 1=1";
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and  pim.yyyymm LIKE '%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%' ")); 
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" ORDER BY pim.yyyymm"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("yyyymm");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    QueryRow oRow = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("yyyymm").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getDesigIdReportLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "SELECT DISTINCT CDTL1.CODE AS DESIG_CODE, CDTL1.NAME AS DESIG_NAME";
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" FROM HRM_EMP_CLASS_MAP ECL1,HRM_CLASS_DTL CDTL1,HRM_CLASS_MST CMST1 WHERE 1=1"));
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" AND ECL1.CLS_DT_ID = CDTL1.ID AND CDTL1.CLS_MST_ID = CMST1.ID AND CMST1.CODE = '10'"));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and  CDTL1.CODE LIKE '%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%' ")); 
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" ORDER BY CDTL1.CODE"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("CODE");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    QueryRow oRow = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("CODE").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getITForecastEmp(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "SELECT distinct it.emp_num FROM npcil.pay_it_forecast it where 1=1";
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and  it.emp_num LIKE '%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%' ")); 
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" ORDER BY it.emp_num"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("emp_num");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    QueryRow oRow = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("emp_num").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {}
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    System.out.println("Save Ille!");
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    return new String();
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {}
}
