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.HrmAttWorkGroupDayOffDtlBean;
import wenrgise.hrms.bean.HrmAttWorkGroupDayOffHdrBean;
import wenrgise.hrms.vo.HrmAttWorkGroupDayOffQVO;

public class HrmAttWorkGroupDayOffBO extends HrmBaseBO {
  public HrmAttWorkGroupDayOffBO() {}
  
  public HrmAttWorkGroupDayOffBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrAttWorkGroupDayOffDetailMetaInfo(HrmAttWorkGroupDayOffQVO oHrmAttWorkGroupDayOffQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffQVO.getHeaderPrimaryKey())) {
      String[] sPrimaryKey = oHrmAttWorkGroupDayOffQVO.getHeaderPrimaryKey().split(",");
      System.out.println(sPrimaryKey[0]);
      System.out.println(sPrimaryKey[1]);
      oHrmAttWorkGroupDayOffQVO.setWorkGroupCode(sPrimaryKey[0]);
      oHrmAttWorkGroupDayOffQVO.setSiteCode(sPrimaryKey[1]);
      oHrmAttWorkGroupDayOffQVO.setWorkGroupDescription(sPrimaryKey[2]);
      oHrmAttWorkGroupDayOffQVO.setSiteDescription(sPrimaryKey[3]);
    } 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oHrmAttWorkGroupDayOffQVO.getWorkGroupCode()));
    arylstParam.add(new DBObject(2, 1, 12, oHrmAttWorkGroupDayOffQVO.getSiteCode()));
    arylstParam.add(new DBObject(3, 2, -5));
    arylstParam.add(new DBObject(4, 2, 93));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMATTWORKGROUPDAYOFF.procHrAttWrkGrpDayOffDtlCount(?,?,?,?,?,?,?)");
    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 getHrAttWorkGroupDayOffDetail(HrmAttWorkGroupDayOffQVO oHrmAttWorkGroupDayOffQVO, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffQVO.getHeaderPrimaryKey())) {
      String[] sPrimaryKey = oHrmAttWorkGroupDayOffQVO.getHeaderPrimaryKey().split(",");
      System.out.println(sPrimaryKey[0]);
      System.out.println(sPrimaryKey[1]);
      oHrmAttWorkGroupDayOffQVO.setWorkGroupCode(sPrimaryKey[0]);
      oHrmAttWorkGroupDayOffQVO.setSiteCode(sPrimaryKey[1]);
      oHrmAttWorkGroupDayOffQVO.setWorkGroupDescription(sPrimaryKey[2]);
      oHrmAttWorkGroupDayOffQVO.setSiteDescription(sPrimaryKey[3]);
    } 
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator itrBean = null;
    ArrayList arylstAttWorkGroupDayoffDetail = 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, oHrmAttWorkGroupDayOffQVO.getWorkGroupCode()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmAttWorkGroupDayOffQVO.getSiteCode()));
    arylstParam.add(new DBObject(5, 2, -10));
    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, "HRMATTWORKGROUPDAYOFF.procHrAttWrkGrpDayOffDtl(?,?,?,?,?,?,?,?)");
    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)
        arylstAttWorkGroupDayoffDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean = new HrmAttWorkGroupDayOffDtlBean();
      oHrmAttWorkGroupDayOffDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtStartWeekDate(EnrgiseUtil.convertToString(oRow.get("START_EFFECT_DATE").getDate()));
      oHrmAttWorkGroupDayOffDtlBean.setTxtEndWeekDate(EnrgiseUtil.convertToString(oRow.get("END_EFFECT_DATE").getDate()));
      oHrmAttWorkGroupDayOffDtlBean.setTxtFirstRestDay(oRow.get("REST_DAY1").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtSecondRestDay(oRow.get("REST_DAY2").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtHalfDay1(oRow.get("HALF_DAY1").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtHalfDay2(oRow.get("HALF_DAY2").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtRestWeek1(oRow.get("REST_WEEK1").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtRestWeek2(oRow.get("REST_WEEK2").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtRestWeekDay1(oRow.get("REST_WEEK_DAY1").getString());
      oHrmAttWorkGroupDayOffDtlBean.setTxtRestWeekDay2(oRow.get("REST_WEEK_DAY2").getString());
      arylstAttWorkGroupDayoffDetail.add(oHrmAttWorkGroupDayOffDtlBean);
    } 
    return arylstAttWorkGroupDayoffDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_WRKGRP_DAY_OFFS";
  }
  
  public void saveDetailImpl(BaseHeaderBean oBaseHeaderBean, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmAttWorkGroupDayOff"))
      saveHrmAttWorkGroupDayOffDetail(oBaseHeaderBean, oDetailBeanArray); 
  }
  
  public String saveHrmAttWorkGroupDayOffDetail(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;
    HrmAttWorkGroupDayOffHdrBean oHrmAttWorkGroupDayOffHdrBean = (HrmAttWorkGroupDayOffHdrBean)oBaseHeaderBean;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean = itrBean.next();
      if (oHrmAttWorkGroupDayOffDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMATTWORKGROUPDAYOFF.procUpsertAttWrkGrpDayOffDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "N"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmAttWorkGroupDayOffHdrBean.getSiteId()));
        arylstParameters.add(new DBObject(3, 1, 12, oHrmAttWorkGroupDayOffHdrBean.getWorkGroupId()));
        arylstParameters.add(new DBObject(4, 1, 12, null));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate())));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttWorkGroupDayOffDtlBean.getTxtEndWeekDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtFirstRestDay()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtSecondRestDay()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtHalfDay1()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtHalfDay2()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek1()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek2()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay1()));
        arylstParameters.add(new DBObject(14, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay2()));
        arylstParameters.add(new DBObject(15, 1, 12, this.oUserInfo.getUserId()));
        arylstParameters.add(new DBObject(16, 1, 12, this.oUserInfo.getSiteId()));
        oBean1.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmAttWorkGroupDayOffDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean2 = new DBUtilitiesBean();
          oBean2.createBatch("HRMATTWORKGROUPDAYOFF.procUpsertAttWrkGrpDayOffDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmAttWorkGroupDayOffHdrBean.getSiteId()));
        arylstParameters.add(new DBObject(3, 1, 12, oHrmAttWorkGroupDayOffHdrBean.getWorkGroupId()));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate())));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttWorkGroupDayOffDtlBean.getTxtEndWeekDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtFirstRestDay()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtSecondRestDay()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtHalfDay1()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtHalfDay2()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek1()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek2()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay1()));
        arylstParameters.add(new DBObject(14, 1, 12, oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay2()));
        arylstParameters.add(new DBObject(15, 1, 12, this.oUserInfo.getUserId()));
        arylstParameters.add(new DBObject(16, 1, 12, this.oUserInfo.getSiteId()));
        oBean2.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmAttWorkGroupDayOffDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean3 = new DBUtilitiesBean();
          oBean3.createBatch("HRMATTWORKGROUPDAYOFF.procDelWrkGrpDayOff(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmAttWorkGroupDayOffDtlBean.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(String.valueOf(String.valueOf(oHrmAttWorkGroupDayOffHdrBean.getWorkGroupCode()).concat(String.valueOf(","))).concat(String.valueOf(oHrmAttWorkGroupDayOffHdrBean.getSiteCode()))).concat(String.valueOf(","))).concat(String.valueOf(oHrmAttWorkGroupDayOffHdrBean.getWorkGroupDescription()))).concat(String.valueOf(","))).concat(String.valueOf(oHrmAttWorkGroupDayOffHdrBean.getSiteDescription()));
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  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 (bHeaderDataChanged) {
      HrmAttWorkGroupDayOffHdrBean oHrmAttWorkGroupDayOffHdrBean = (HrmAttWorkGroupDayOffHdrBean)oBaseHeaderBean;
      checkMandatoryHeader(oHrmAttWorkGroupDayOffHdrBean, oErrorList);
    } 
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmAttWorkGroupDayOff")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowCount = 1;
        while (oIt1.hasNext()) {
          HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean = oIt1.next();
          if (!oHrmAttWorkGroupDayOffDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatoryDtls(oHrmAttWorkGroupDayOffDtlBean, rowCount, oErrorList); 
          rowCount++;
        } 
      }  
    reportError(oErrorList);
  }
  
  private void checkMandatoryHeader(HrmAttWorkGroupDayOffHdrBean oHrmAttWorkGroupDayOffHdrBean, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffHdrBean.getWorkGroupCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttWrkGrpDayOff.wrkGrpCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffHdrBean.getSiteCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttWrkGrpDayOff.siteCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
  }
  
  private void checkMandatoryDtls(HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean, int rowCount, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtFirstRestDay())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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(oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek1()))
      if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay1())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek2()))
      if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay2())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay1()))
      if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek1())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeekDay2()))
      if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtRestWeek2())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmAttWorkGroupDayOff.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("HrmAttWorkGroupDayOff")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int n = oDetailBeanArray.size();
        int rowCount = 0;
        while (oIt1.hasNext()) {
          System.out.println(rowCount);
          HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean = oIt1.next();
          if (!oHrmAttWorkGroupDayOffDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkDays(oHrmAttWorkGroupDayOffDtlBean, oList);
            if (!EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtEndWeekDate()))
              if (rowCount < n - 1) {
                HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean1 = oDetailBeanArray.get(rowCount + 1);
                if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean1.getTxtStartWeekDate()))
                  oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.period.value")); 
              }  
            if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate()))
              if (rowCount > 0 && rowCount < n) {
                HrmAttWorkGroupDayOffDtlBean oHrmAttWorkGroupDayOffDtlBean1 = oDetailBeanArray.get(rowCount - 1);
                if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean1.getTxtEndWeekDate())) {
                  DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
                  int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate(), oHrmAttWorkGroupDayOffDtlBean1.getTxtEndWeekDate());
                  if (dateFlag == -1 && dateFlag != -2)
                    oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.date.value")); 
                } 
              }  
            if (EnrgiseUtil.checkString(oHrmAttWorkGroupDayOffDtlBean.getTxtEndWeekDate())) {
              DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
              int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmAttWorkGroupDayOffDtlBean.getTxtEndWeekDate(), oHrmAttWorkGroupDayOffDtlBean.getTxtStartWeekDate());
              if (dateFlag == -1 && dateFlag != -2)
                oList.add(new EnrgiseApplicationException("wenrgise.hrms.att.corresdate.value")); 
            } 
          } else if (oHrmAttWorkGroupDayOffDtlBean.getStatus().equalsIgnoreCase("D")) {
            HrmAttWorkGroupDayOffHdrBean oHrmAttWorkGroupDayOffHdrBean = (HrmAttWorkGroupDayOffHdrBean)oBaseHeaderBean;
            DBUtilitiesBean oBean = new DBUtilitiesBean();
            ArrayList arylstParam = new ArrayList();
            arylstParam.add(new DBObject(1, 1, 12, oHrmAttWorkGroupDayOffHdrBean.getWorkGroupId()));
            arylstParam.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttWorkGroupDayOffDtlBean.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, "HRMATTWORKGROUPDAYOFF.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(HrmAttWorkGroupDayOffDtlBean 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++) {
          System.out.println(j);
          System.out.println(count);
          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 getHrmAttWorkGroupInsertLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("workGroupId");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.wrkGrpCode");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.wrkGrpDesc");
    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();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    if (oLovQueryVO.getProperty("siteId") != null) {
      siteId = oLovQueryVO.getProperty("siteId");
      System.out.println(siteId);
    } 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, siteId));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(3, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMATTWORKGROUPDAYOFF.procGetAttWGDayOffILOV(?,?,?,?,?,?,?)");
    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("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAttWorkGroupQueryLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("workGroupId");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.wrkGrpCode");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.wrkGrpDesc");
    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();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    if (oLovQueryVO.getProperty("siteId") != null) {
      siteId = oLovQueryVO.getProperty("siteId");
      System.out.println(siteId);
    } 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, siteId));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(3, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMATTWORKGROUPDAYOFF.procGetAttWGDayOffQLOV(?,?,?,?,?,?,?)");
    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("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAttSiteQueryLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("siteId");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.siteCode");
    oHeaderList.add("hrm.HrmAttWrkGrpDayOff.siteDesc");
    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();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    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, "HRMATTWORKGROUPDAYOFF.procGetAttSiteWGDayOffQLOV(?,?,?,?,?,?)");
    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("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
}
