package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.MessageKey;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.hrms.bean.HrmAttEmpDayOffDtlBean;
import wenrgise.hrms.bean.HrmAttEmpDayOffHdrBean;
import wenrgise.hrms.vo.HrmAttEmpDayOffQVO;

public class HrmAttEmpDayOffBO extends HrmBaseBO {
  public HrmAttEmpDayOffBO() {}
  
  public HrmAttEmpDayOffBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrAttEmployeeDayoffDetailMetaInfo(HrmAttEmpDayOffQVO oHrmAttEmpDayOffQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffQVO.getHeaderPrimaryKey())) {
      String[] sPrimaryKey = oHrmAttEmpDayOffQVO.getHeaderPrimaryKey().split(",");
      System.out.println(sPrimaryKey[0]);
      System.out.println(sPrimaryKey[1]);
      oHrmAttEmpDayOffQVO.setEmpId(sPrimaryKey[0]);
      oHrmAttEmpDayOffQVO.setEmployeeNo(sPrimaryKey[1]);
      oHrmAttEmpDayOffQVO.setEmployeeName(sPrimaryKey[2]);
    } 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oHrmAttEmpDayOffQVO.getEmpId()));
    arylstParam.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffQVO.getPeriodStartDate())));
    arylstParam.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffQVO.getPeriodEndDate())));
    arylstParam.add(new DBObject(4, 2, -5));
    arylstParam.add(new DBObject(5, 2, 93));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMATTEMPDAYOFF.procHrAttEmpDayOffDtlCount(?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrAttEmployeeDayoffDetail(HrmAttEmpDayOffQVO oHrmAttEmpDayOffQVO, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffQVO.getHeaderPrimaryKey())) {
      String[] sPrimaryKey = oHrmAttEmpDayOffQVO.getHeaderPrimaryKey().split(",");
      System.out.println(sPrimaryKey[0]);
      System.out.println(sPrimaryKey[1]);
      oHrmAttEmpDayOffQVO.setEmpId(sPrimaryKey[0]);
      oHrmAttEmpDayOffQVO.setEmployeeNo(sPrimaryKey[1]);
      oHrmAttEmpDayOffQVO.setEmployeeName(sPrimaryKey[2]);
    } 
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator itrBean = null;
    ArrayList arylstAttEmpDayoffDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, oHrmAttEmpDayOffQVO.getEmpId()));
    arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffQVO.getPeriodStartDate())));
    arylstParam.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffQVO.getPeriodEndDate())));
    arylstParam.add(new DBObject(6, 2, -10));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 12));
    arylstParam.add(new DBObject(9, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMATTEMPDAYOFF.procHrAttEmpDayOffDtl(?,?,?,?,?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstAttEmpDayoffDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean = new HrmAttEmpDayOffDtlBean();
      oHrmAttEmpDayOffDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmAttEmpDayOffDtlBean.setTxtStartWeekDate(EnrgiseUtil.convertToString(oRow.get("START_EFFECT_DATE").getDate()));
      oHrmAttEmpDayOffDtlBean.setTxtEndWeekDate(EnrgiseUtil.convertToString(oRow.get("END_EFFECT_DATE").getDate()));
      oHrmAttEmpDayOffDtlBean.setTxtFirstRestDay(oRow.get("REST_DAY1").getString());
      oHrmAttEmpDayOffDtlBean.setTxtSecondRestDay(oRow.get("REST_DAY2").getString());
      oHrmAttEmpDayOffDtlBean.setTxtHalfDay1(oRow.get("HALF_DAY1").getString());
      oHrmAttEmpDayOffDtlBean.setTxtHalfDay2(oRow.get("HALF_DAY2").getString());
      oHrmAttEmpDayOffDtlBean.setTxtRestWeek1(oRow.get("REST_WEEK1").getString());
      oHrmAttEmpDayOffDtlBean.setTxtRestWeek2(oRow.get("REST_WEEK2").getString());
      oHrmAttEmpDayOffDtlBean.setTxtRestWeekDay1(oRow.get("REST_WEEK_DAY1").getString());
      oHrmAttEmpDayOffDtlBean.setTxtRestWeekDay2(oRow.get("REST_WEEK_DAY2").getString());
      arylstAttEmpDayoffDetail.add(oHrmAttEmpDayOffDtlBean);
    } 
    return arylstAttEmpDayoffDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_DAY_OFFS";
  }
  
  public void saveDetailImpl(BaseHeaderBean oBaseHeaderBean, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmAttEmpDayOff"))
      saveHrmAttEmpDayoffDetail(oBaseHeaderBean, oDetailBeanArray); 
  }
  
  public String saveHrmAttEmpDayoffDetail(BaseHeaderBean oBaseHeaderBean, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean1 = null;
    DBUtilitiesBean oBean2 = null;
    DBUtilitiesBean oBean3 = null;
    HrmAttEmpDayOffHdrBean oHrmAttEmpDayOffHdrBean = (HrmAttEmpDayOffHdrBean)oBaseHeaderBean;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean = itrBean.next();
      if (oHrmAttEmpDayOffDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMATTEMPDAYOFF.procUpsertAttEmpDayOffDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "N"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmAttEmpDayOffHdrBean.getEmpId()));
        arylstParameters.add(new DBObject(3, 1, 12, null));
        arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate())));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffDtlBean.getTxtEndWeekDate())));
        arylstParameters.add(new DBObject(6, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtFirstRestDay()));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtSecondRestDay()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtHalfDay1()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtHalfDay2()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeek1()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeek2()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay1()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay2()));
        arylstParameters.add(new DBObject(14, 1, 12, this.oUserInfo.getUserId()));
        arylstParameters.add(new DBObject(15, 1, 12, this.oUserInfo.getSiteId()));
        oBean1.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmAttEmpDayOffDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean2 = new DBUtilitiesBean();
          oBean2.createBatch("HRMATTEMPDAYOFF.procUpsertAttEmpDayOffDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmAttEmpDayOffHdrBean.getEmpId()));
        arylstParameters.add(new DBObject(3, 1, 12, oHrmAttEmpDayOffDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate())));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffDtlBean.getTxtEndWeekDate())));
        arylstParameters.add(new DBObject(6, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtFirstRestDay()));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtSecondRestDay()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtHalfDay1()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtHalfDay2()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeek1()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeek2()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay1()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay2()));
        arylstParameters.add(new DBObject(14, 1, 12, this.oUserInfo.getUserId()));
        arylstParameters.add(new DBObject(15, 1, 12, this.oUserInfo.getSiteId()));
        oBean2.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmAttEmpDayOffDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean3 = new DBUtilitiesBean();
          oBean3.createBatch("HRMATTEMPDAYOFF.procDelEmpDayOff(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmAttEmpDayOffDtlBean.getDetailId()));
        oBean3.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean1.executeBatch(); 
    if (bUpdate)
      oBean2.executeBatch(); 
    if (bDelete)
      oBean3.executeBatch(); 
    return String.valueOf(String.valueOf(String.valueOf(String.valueOf(oHrmAttEmpDayOffHdrBean.getEmpId()).concat(String.valueOf(","))).concat(String.valueOf(oHrmAttEmpDayOffHdrBean.getEmployeeNo()))).concat(String.valueOf(","))).concat(String.valueOf(oHrmAttEmpDayOffHdrBean.getEmployeeName()));
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return new String();
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmAttEmpDayOff")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowCount = 1;
        while (oIt1.hasNext()) {
          HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean = oIt1.next();
          if (!oHrmAttEmpDayOffDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatoryDtls(oHrmAttEmpDayOffDtlBean, rowCount, oErrorList); 
          rowCount++;
        } 
      }  
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean, int rowCount, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtFirstRestDay())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.fstRstDay");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.startWeekDt");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeek1()))
      if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay1())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.restWeekDay1");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(new Integer(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeek2()))
      if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay2())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.restWeekDay2");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(new Integer(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay1()))
      if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeek1())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.restWeek1");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(new Integer(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
    if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeekDay2()))
      if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtRestWeek2())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttEmployeeDayOff.restWeek2");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(new Integer(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String param1) throws EnrgiseSystemException {
    return "saveHeaderImpl toBeDone";
  }
  
  public void saveDetailImpl(String param1, String param2, ArrayList param3) {}
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmAttEmpDayOff")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int n = oDetailBeanArray.size();
        int rowCount = 0;
        while (oIt1.hasNext()) {
          System.out.println(rowCount);
          HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean = oIt1.next();
          if (!oHrmAttEmpDayOffDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkDays(oHrmAttEmpDayOffDtlBean, oList);
            if (!EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtEndWeekDate()))
              if (rowCount < n - 1) {
                HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean1 = oDetailBeanArray.get(rowCount + 1);
                if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean1.getTxtStartWeekDate()))
                  oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.period.value")); 
              }  
            if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate()))
              if (rowCount > 0 && rowCount < n) {
                HrmAttEmpDayOffDtlBean oHrmAttEmpDayOffDtlBean1 = oDetailBeanArray.get(rowCount - 1);
                if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean1.getTxtEndWeekDate())) {
                  DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
                  int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate(), oHrmAttEmpDayOffDtlBean1.getTxtEndWeekDate());
                  if (dateFlag == -1 && dateFlag != -2)
                    oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.date.value")); 
                } 
              }  
            if (EnrgiseUtil.checkString(oHrmAttEmpDayOffDtlBean.getTxtEndWeekDate())) {
              DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
              int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmAttEmpDayOffDtlBean.getTxtEndWeekDate(), oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate());
              if (dateFlag == -1 && dateFlag != -2)
                oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.corresdate.value")); 
            } 
          } else if (oHrmAttEmpDayOffDtlBean.getStatus().equalsIgnoreCase("D")) {
            HrmAttEmpDayOffHdrBean oHrmAttEmpDayOffHdrBean = (HrmAttEmpDayOffHdrBean)oBaseHeaderBean;
            DBUtilitiesBean oBean = new DBUtilitiesBean();
            ArrayList arylstParam = new ArrayList();
            arylstParam.add(new DBObject(1, 1, 12, oHrmAttEmpDayOffHdrBean.getEmpId()));
            arylstParam.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpDayOffDtlBean.getTxtStartWeekDate())));
            arylstParam.add(new DBObject(3, 2, -5));
            arylstParam.add(new DBObject(4, 2, 12));
            arylstParam.add(new DBObject(5, 2, 12));
            arylstParam.add(new DBObject(6, 2, 4));
            ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMATTEMPDAYOFF.procGetShiftRstInfo(?,?,?,?,?,?)");
            RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
            DBObject oTotalRecord = arylstOutArray.get(0);
            oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
            if (oRecordMetaInfo.getRecordCount() > 0L)
              oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.rst.value")); 
          } 
          rowCount++;
        } 
        reportError(oList);
      }  
  }
  
  public void checkDays(HrmAttEmpDayOffDtlBean oDtlBean, ArrayList arylstList) throws EnrgiseSystemException, EnrgiseApplicationException {
    String[] dayTypes = { oDtlBean.getTxtFirstRestDay(), oDtlBean.getTxtSecondRestDay(), oDtlBean.getTxtHalfDay1(), oDtlBean.getTxtHalfDay2(), oDtlBean.getTxtRestWeekDay1(), oDtlBean.getTxtRestWeekDay2() };
    System.out.println(dayTypes.length);
    int count = 0;
    for (int i = 0; i < dayTypes.length; i++) {
      count++;
      if (count <= dayTypes.length)
        for (int j = count + 1; j <= dayTypes.length; j++) {
          if (EnrgiseUtil.checkString(dayTypes[count - 1]) && EnrgiseUtil.checkString(dayTypes[j - 1]))
            if (dayTypes[count - 1].equalsIgnoreCase(dayTypes[j - 1]))
              arylstList.add(new EnrgiseApplicationException("wenrgise.hrms.att.holDayType.value"));  
        }  
    } 
  }
  
  public LovVO getHrmAttEmpNoQueryLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("empId");
    oHeaderList.add("hrm.HrmAttEmployeeDayOff.empNo");
    oHeaderList.add("hrm.HrmAttEmployeeDayOff.empName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String siteId = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMATTEMPDAYOFF.procGetHrmAttEmpNoQLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAttEmpNoInsertLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("empId");
    oHeaderList.add("hrm.HrmAttEmployeeDayOff.empNo");
    oHeaderList.add("hrm.HrmAttEmployeeDayOff.empName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String siteId = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMATTEMPDAYOFF.procGetHrmAttEmpNoILOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
}
