package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
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.DateUtility;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.MessageKey;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.vo.BaseDetailVO;
import wenrgise.common.vo.BaseHeaderVO;
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.HrmClaimMstDtlBean;
import wenrgise.hrms.bean.HrmClaimMstHdrBean;
import wenrgise.hrms.vo.HrmClaimMstQVO;

public class HrmClaimMstBO extends HrmBaseBO {
  public HrmClaimMstBO() {}
  
  public HrmClaimMstBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmClaimMstHdrMetaInfo(HrmClaimMstQVO oHrmClaimMstQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oHrmClaimMstQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(2, 1, 12, oHrmClaimMstQVO.getClaimCodeId()));
    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 oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procHrmClaimMstHdrCount(?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmClaimMstHdrInfo(HrmClaimMstQVO oHrmClaimMstQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList oHeaderList = null;
    if (oHrmClaimMstQVO == null)
      oHrmClaimMstQVO = new HrmClaimMstQVO(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, oHrmClaimMstQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmClaimMstQVO.getClaimCodeId()));
    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 oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procGetHrmClaimMstHdr(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oHeaderList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmClaimMstHdrBean oHrmClaimMstHdrBean = new HrmClaimMstHdrBean();
      oHrmClaimMstHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmClaimMstHdrBean.setClaimCode(oRow.get("CODE").getString());
      oHrmClaimMstHdrBean.setClaimName(oRow.get("NAME").getString());
      oHrmClaimMstHdrBean.setClaimCodeId(oRow.get("ID").getString());
      oHrmClaimMstHdrBean.setCalendarId(oRow.get("CAL_ID").getString());
      oHrmClaimMstHdrBean.setCalendarName(oRow.get("CALENDAR_TYPE").getString());
      oHrmClaimMstHdrBean.setDocReqFlag(String.valueOf(oRow.get("DOC_REQUIRED_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmClaimMstHdrBean.setPayrollFlag(oRow.get("PAYROLL_FLAG").getString());
      oHeaderList.add(oHrmClaimMstHdrBean);
    } 
    return oHeaderList;
  }
  
  public RecordMetaInfo getHrmClaimMstDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procHrmClaimMstDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmClaimMstDtlInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList oHrmClaimMstDtl = 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, lPrimaryKey));
    arylstParam.add(new DBObject(4, 2, -10));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procGetHrmClaimMstDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oHrmClaimMstDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = new HrmClaimMstDtlBean();
      oHrmClaimMstDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmClaimMstDtlBean.setTxtClaimDetailCode(oRow.get("DESCRIPTION").getString());
      oHrmClaimMstDtlBean.setTxtMaxCalLimit(oRow.get("MAX_CAL_LIMIT").getString());
      oHrmClaimMstDtlBean.setTxtGreaterLesserFlag(oRow.get("GREATER_LESSER_FLAG").getString());
      oHrmClaimMstDtlBean.setTxtMaxLimit(oRow.get("MAX_LIMIT").getString());
      oHrmClaimMstDtlBean.setTxtFlatAmount(oRow.get("FLAT_AMOUNT").getString());
      oHrmClaimMstDtlBean.setTxtEffectFromDate(EnrgiseUtil.convertToString(oRow.get("EFFECT_DATE").getDate()));
      oHrmClaimMstDtlBean.setTxtEffectToDate(EnrgiseUtil.convertToString(oRow.get("TO_DATE").getDate()));
      oHrmClaimMstDtlBean.setTxtAppliedToAll(String.valueOf(oRow.get("ALL_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmClaimMstDtl.add(oHrmClaimMstDtlBean);
    } 
    return oHrmClaimMstDtl;
  }
  
  public LovVO getHrmClaimCodeLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmClaimMst.claimCode");
    oHeaderList.add("hrm.HrmClaimMst.claimName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = 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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 2, -10));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procGetClaimCodeLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = 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());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public void updateClaimMst(String sSql, String sId, String sUserId, String sUserSiteId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sSql));
    arylstParam.add(new DBObject(2, 1, 12, sId));
    arylstParam.add(new DBObject(3, 1, 12, sUserId));
    arylstParam.add(new DBObject(4, 1, 12, sUserSiteId));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procUpdateHrmClaimDtl(?,?,?,?,?,?,?)");
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_CLAIM_MST";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmClaimMstHdrBean oHrmClaimMstHdrBean = (HrmClaimMstHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "N"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmClaimMstHdrBean.getClaimCode()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmClaimMstHdrBean.getClaimName()));
      arylstParam.add(new DBObject(4, 1, 12, oHrmClaimMstHdrBean.getCalendarId()));
      arylstParam.add(new DBObject(5, 1, 12, oHrmClaimMstHdrBean.getPayrollFlag()));
      arylstParam.add(new DBObject(6, 1, 12, String.valueOf(oHrmClaimMstHdrBean.getDocReqFlag()).equalsIgnoreCase("on") ? "Y" : "N"));
      arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(9, 1, 12, null));
      arylstParam.add(new DBObject(10, 2, 12));
      arylstParam.add(new DBObject(11, 2, 12));
      arylstParam.add(new DBObject(12, 2, 12));
      arylstParam.add(new DBObject(13, 2, 4));
      ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procUpsertHrmClaimMstHdr(?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "U"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmClaimMstHdrBean.getClaimCode()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmClaimMstHdrBean.getClaimName()));
      arylstParam.add(new DBObject(4, 1, 12, oHrmClaimMstHdrBean.getCalendarId()));
      arylstParam.add(new DBObject(5, 1, 12, oHrmClaimMstHdrBean.getPayrollFlag()));
      arylstParam.add(new DBObject(6, 1, 12, String.valueOf(oHrmClaimMstHdrBean.getDocReqFlag()).equalsIgnoreCase("on") ? "Y" : "N"));
      arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(9, 1, 12, oHrmClaimMstHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(10, 2, 12));
      arylstParam.add(new DBObject(11, 2, 12));
      arylstParam.add(new DBObject(12, 2, 12));
      arylstParam.add(new DBObject(13, 2, 4));
      ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST.procUpsertHrmClaimMstHdr(?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      arylstParam.add(new DBObject(1, 1, 12, oHrmClaimMstHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(2, 2, 12));
      arylstParam.add(new DBObject(3, 2, 12));
      arylstParam.add(new DBObject(4, 2, 4));
      ArrayList oOutArray = oBean.callProc(arylstParam, "HRMCLAIMMST. (?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmClaimMst"))
      saveHrmClaimMstDetail(sHeaderPrimaryKey, oDetailBeanArray); 
  }
  
  private void saveHrmClaimMstDetail(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    String applToEmp = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt.next();
      if (oHrmClaimMstDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMCLAIMMST.procUpsertHrmClaimDetail(?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "N"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, String.valueOf(oHrmClaimMstDtlBean.getTxtAppliedToAll()).equalsIgnoreCase("on") ? "Y" : "N"));
        arylstParam.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmClaimMstDtlBean.getTxtEffectFromDate())));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmClaimMstDtlBean.getTxtEffectToDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmClaimMstDtlBean.getTxtGreaterLesserFlag()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmClaimMstDtlBean.getTxtClaimDetailCode()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmClaimMstDtlBean.getTxtMaxCalLimit()));
        arylstParam.add(new DBObject(10, 1, 12, oHrmClaimMstDtlBean.getTxtMaxLimit()));
        arylstParam.add(new DBObject(11, 1, 12, oHrmClaimMstDtlBean.getTxtFlatAmount()));
        arylstParam.add(new DBObject(12, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(13, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmClaimMstDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMCLAIMMST.procUpsertHrmClaimDetail(?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmClaimMstDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, String.valueOf(oHrmClaimMstDtlBean.getTxtAppliedToAll()).equalsIgnoreCase("Y") ? "Y" : "N"));
        arylstParam.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmClaimMstDtlBean.getTxtEffectFromDate())));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmClaimMstDtlBean.getTxtEffectToDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmClaimMstDtlBean.getTxtGreaterLesserFlag()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmClaimMstDtlBean.getTxtClaimDetailCode()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmClaimMstDtlBean.getTxtMaxCalLimit()));
        arylstParam.add(new DBObject(10, 1, 12, oHrmClaimMstDtlBean.getTxtMaxLimit()));
        arylstParam.add(new DBObject(11, 1, 12, oHrmClaimMstDtlBean.getTxtFlatAmount()));
        arylstParam.add(new DBObject(12, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(13, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmClaimMstDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMCLAIMMST.procDeleteClaimMstDtl(?)");
          bDelete = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, oHrmClaimMstDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParam);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  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();
    HrmClaimMstHdrBean oHrmClaimMstHdrBean = (HrmClaimMstHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmClaimMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmClaimMst")) {
          Iterator oIt1 = oDetailBeanArray.iterator();
          int rowCount = 1;
          while (oIt1.hasNext()) {
            HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
            if (!oHrmClaimMstDtlBean.getStatus().equalsIgnoreCase("D"))
              checkMandatoryDtls(oHrmClaimMstDtlBean, rowCount, oErrorList); 
            rowCount++;
          } 
        }   
    reportError(oErrorList);
  }
  
  private void checkMandatoryHeader(HrmClaimMstHdrBean oHrmClaimMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmClaimMstHdrBean.getClaimCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.claimCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmClaimMstHdrBean.getPayrollFlag())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.payrollFlag");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmClaimMstDtlBean oHrmClaimMstDtlBean, int rowCount, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtClaimDetailCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.claimDetailCode");
      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(oHrmClaimMstDtlBean.getTxtGreaterLesserFlag())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.greaterLesserFlag");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (oHrmClaimMstDtlBean.getTxtGreaterLesserFlag().equalsIgnoreCase("G") || oHrmClaimMstDtlBean.getTxtGreaterLesserFlag().equalsIgnoreCase("L")) {
      if (!EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtMaxLimit())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.maxLimit");
        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(oHrmClaimMstDtlBean.getTxtFlatAmount())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.amount");
        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(oHrmClaimMstDtlBean.getTxtEffectFromDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.effectFromDate");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (oHrmClaimMstDtlBean.getTxtGreaterLesserFlag().equalsIgnoreCase("F"))
      if (!EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtFlatAmount())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.amount");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(new Integer(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
    reportError(oErrorList);
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  private void checkDatesConstraint(HrmClaimMstDtlBean oHrmClaimMstDtlBean, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    if (EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtEffectToDate())) {
      int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmClaimMstDtlBean.getTxtEffectToDate(), oHrmClaimMstDtlBean.getTxtEffectFromDate());
      if (dateFlag == -1 && dateFlag != -2)
        oErrorList.add(new EnrgiseApplicationException("hrm.HrmClaimMst.dateError")); 
    } 
    reportError(oErrorList);
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    HrmClaimMstHdrBean oHrmClaimMstHdrBean = (HrmClaimMstHdrBean)oBaseHeaderBean;
    if (sScreenMode.equalsIgnoreCase("D"))
      ArrayList arrayList = new ArrayList(); 
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D")) {
        checkUniqueHeader((HrmClaimMstHdrBean)oBaseHeaderBean);
      } else {
        checkIfDetailExist((HrmClaimMstHdrBean)oBaseHeaderBean);
      }  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmClaimMst")) {
          Iterator oIt1 = oDetailBeanArray.iterator();
          while (oIt1.hasNext()) {
            HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
            if (!oHrmClaimMstDtlBean.getStatus().equalsIgnoreCase("D")) {
              EnrgiseUtil.checkDuplicate(oDetailBeanArray, "txtClaimDetailCode", "hrm.HrmClaimMst.claimDetailCode", oErrorList, true);
              checkUniqueDtl(oBaseHeaderBean.getHeaderPrimaryKey(), oDetailBeanArray, oErrorList);
              checkMaxLimit(oBaseHeaderBean.getHeaderPrimaryKey(), oDetailBeanArray, oErrorList);
              checkDatesConstraint(oHrmClaimMstDtlBean, oErrorList);
              checkAllEmployee(oBaseHeaderBean.getHeaderPrimaryKey(), oDetailBeanArray, oErrorList);
              checkNumericDtlFields(oDetailBeanArray, oErrorList);
              continue;
            } 
            checkDetailChildRecord(oHrmClaimMstDtlBean);
          } 
          reportError(oErrorList);
        }   
  }
  
  private void checkAllEmployee(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    Iterator oIt1 = oDetailBeanArray.iterator();
    int rowCount = 1;
    int allEmp = 1;
    while (oIt1.hasNext()) {
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
      if (oHrmClaimMstDtlBean.getTxtAppliedToAll().equalsIgnoreCase("Y"))
        allEmp++; 
      if (allEmp > 1 && rowCount > 1) {
        ArrayList oParam = new ArrayList();
        throw new EnrgiseApplicationException("hrm.loan.detail.allemployeeerror", oParam, "E");
      } 
      rowCount++;
    } 
    reportError(oErrorList);
  }
  
  private void checkNumericDtlFields(ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    int count = 1;
    Iterator oIt1 = oDetailBeanArray.iterator();
    while (oIt1.hasNext()) {
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
      if (EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtMaxLimit())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.maxLimit");
        ArrayList oParam = new ArrayList();
        oParam.add(oMessageKey);
        oParam.add(new Integer(count));
        if (!EnrgiseUtil.checkNumber(oHrmClaimMstDtlBean.getTxtMaxLimit(), 8, 9, "P")) {
          oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.invalidNumber", oParam));
        } else if (Double.parseDouble(oHrmClaimMstDtlBean.getTxtMaxLimit()) <= false) {
          oErrorList.add(new EnrgiseMessageKeyException("hrm.recadvattrwork.numberZero", oParam));
        } 
      } 
      count++;
    } 
    reportError(oErrorList);
  }
  
  private void checkDetailChildRecord(HrmClaimMstDtlBean oHrmClaimMstDtlBean) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkUniqueHeader(HrmClaimMstHdrBean oHrmClaimMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(String.valueOf(" Select ID as ID from hrm_claim_mst where code= '").concat(String.valueOf(oHrmClaimMstHdrBean.getClaimCode()))).concat(String.valueOf("'"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oList = oBean.executeQuery(sQuery);
    Iterator oIt = oList.iterator();
    if (oIt.hasNext()) {
      QueryRow oRow = oIt.next();
      if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmClaimMstHdrBean.getHeaderPrimaryKey())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.claimCode");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        throw new EnrgiseMessageKeyException("wenrgise.common.header.uniqueConstraintViolated", oParams, "E");
      } 
    } 
  }
  
  private void checkIfDetailExist(HrmClaimMstHdrBean oHrmClaimMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(" Select claim_mst_id as ID from hrm_claim_dtl where claim_mst_id= ").concat(String.valueOf(oHrmClaimMstHdrBean.getHeaderPrimaryKey()));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oList = oBean.executeQuery(sQuery);
    if (oList.size() > 0) {
      ArrayList oParam = new ArrayList();
      throw new EnrgiseApplicationException("hrm.loan.hdr.detailFound", oParam, "E");
    } 
  }
  
  private void checkUniqueDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    Iterator oIt1 = oDetailBeanArray.iterator();
    int rowCount = 1;
    while (oIt1.hasNext()) {
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
      if (!EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getDetailId())) {
        String sQuery = String.valueOf(String.valueOf(String.valueOf(" Select id as ID from hrm_claim_dtl where description= '").concat(String.valueOf(oHrmClaimMstDtlBean.getTxtClaimDetailCode()))).concat(String.valueOf("' and claim_mst_id="))).concat(String.valueOf(sHeaderPrimaryKey));
        DBUtilitiesBean oBean = new DBUtilitiesBean();
        ArrayList oList = oBean.executeQuery(sQuery);
        Iterator oIt = oList.iterator();
        if (oIt.hasNext()) {
          ArrayList oParams = new ArrayList();
          MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.loanDetailCode");
          oParams.add(oMessageKey);
          oParams.add(new Integer(rowCount));
          oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.uniqueKeyViolated", oParams));
        } 
      } 
      rowCount++;
    } 
  }
  
  private void checkMaxLimit(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    Iterator oIt1 = oDetailBeanArray.iterator();
    int rowCount = 1;
    int iMaxLimit = 0;
    int iFlatAmount = 0;
    while (oIt1.hasNext()) {
      HrmClaimMstDtlBean oHrmClaimMstDtlBean = oIt1.next();
      if (!EnrgiseUtil.checkString(oHrmClaimMstDtlBean.getTxtFlatAmount())) {
        iMaxLimit = Integer.parseInt(oHrmClaimMstDtlBean.getTxtMaxCalLimit());
        iFlatAmount = Integer.parseInt(oHrmClaimMstDtlBean.getTxtFlatAmount());
        if (iMaxLimit < iFlatAmount) {
          ArrayList oParams = new ArrayList();
          MessageKey oMessageKey = new MessageKey("hrm.HrmClaimMst.maxCalLimit");
          oParams.add(oMessageKey);
          oParams.add(new Integer(rowCount));
          oErrorList.add(new EnrgiseMessageKeyException("hrm.HrmClaimMst.amountError", oParams));
        } 
      } 
      rowCount++;
    } 
  }
}
