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.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
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.HrmAttEmpShiftRosterDtlBean;
import wenrgise.hrms.vo.HrmAttEmpShiftRosterQVO;

public class HrmAttEmployeeShiftRosterBO extends HrmBaseBO {
  public HrmAttEmployeeShiftRosterBO() {}
  
  public HrmAttEmployeeShiftRosterBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {}
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String sScreenMode) throws EnrgiseSystemException {
    return null;
  }
  
  public RecordMetaInfo getAttEmpshiftRosterDetailMetaInfo(HrmAttEmpShiftRosterQVO oHrmAttEmpShiftRosterQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnWorkId()));
    oParameters.add(new DBObject(2, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnEmpId()));
    oParameters.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpShiftRosterQVO.getPeriodStartDate())));
    oParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpShiftRosterQVO.getPeriodEndDate())));
    oParameters.add(new DBObject(5, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnSiteId()));
    oParameters.add(new DBObject(6, 2, -5));
    oParameters.add(new DBObject(7, 2, 93));
    oParameters.add(new DBObject(8, 2, 12));
    oParameters.add(new DBObject(9, 2, 12));
    oParameters.add(new DBObject(10, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMATTENDENCE.proc_getDetailSftRosterCount(?,?,?,?,?,?,?,?,?,?)");
    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 getAttEmpshiftRosterDetail(HrmAttEmpShiftRosterQVO oHrmAttEmpShiftRosterQVO, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    Iterator oIt = null;
    ArrayList oHrmAttEmpShiftRosterDtl = null;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnWorkId()));
    oParameters.add(new DBObject(4, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnEmpId()));
    oParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpShiftRosterQVO.getPeriodStartDate())));
    oParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAttEmpShiftRosterQVO.getPeriodEndDate())));
    oParameters.add(new DBObject(7, 1, 12, oHrmAttEmpShiftRosterQVO.getHdnSiteId()));
    oParameters.add(new DBObject(8, 2, -10));
    oParameters.add(new DBObject(9, 2, 12));
    oParameters.add(new DBObject(10, 2, 12));
    oParameters.add(new DBObject(11, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMATTENDENCE.proc_GetSftRosterHdr(?,?,?,?,?,?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.common.norecordfound", "M"); 
    count = 0;
    oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oHrmAttEmpShiftRosterDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAttEmpShiftRosterDtlBean oHrmAttEmpShiftRosterDtlBean = new HrmAttEmpShiftRosterDtlBean();
      oHrmAttEmpShiftRosterDtlBean.setDetailId(oRow.get("id").getString());
      oHrmAttEmpShiftRosterDtlBean.setTxtWorkDate(EnrgiseUtil.convertToString(oRow.get("Wdate").getDate()));
      oHrmAttEmpShiftRosterDtlBean.setTxtEmpNo(oRow.get("emp_no").getString());
      oHrmAttEmpShiftRosterDtlBean.setTxtMandatoryHoliady(oRow.get("MENDATORY").getString());
      oHrmAttEmpShiftRosterDtlBean.setTxtAvailability(oRow.get("AVAILIBILITY").getString());
      oHrmAttEmpShiftRosterDtlBean.setTxtShiftCode(oRow.get("SHIFTCODE").getString());
      oHrmAttEmpShiftRosterDtlBean.setDetailId(oRow.get("id").getString());
      oHrmAttEmpShiftRosterDtlBean.setStatus("Q");
      oHrmAttEmpShiftRosterDtl.add(oHrmAttEmpShiftRosterDtlBean);
    } 
    return oHrmAttEmpShiftRosterDtl;
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return null;
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public void saveDetailImpl(String sHeaderPrimaryKey, BaseHeaderBean oBaseHeaderBean, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {}
  
  public void initializeBOImpl() {
    this.headerTable = "PAY_FIXED_PROFTAX_RATES";
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  public void additionalTimestampValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {}
}
