package WEB-INF.classes.wenrgise.hrms.webtier.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.hrms.bean.HrmLvApplnDtlBean;
import wenrgise.hrms.businessdelegate.HrmLvApplnBD;
import wenrgise.hrms.webtier.action.BaseAction;
import wenrgise.hrms.webtier.form.HrmLvApplnForm;

public class HrmLvApplAction extends BaseAction {
  public ActionForward executeImpl(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
    HrmLvApplnBD oBd = new HrmLvApplnBD();
    HrmLvApplnForm oForm = (HrmLvApplnForm)form;
    String sFormName = oForm.getClass().getName();
    BaseHeaderBean oBaseHeaderBean = getBaseHeaderBean(sFormName);
    BeanUtils.copyProperties(oBaseHeaderBean, oForm);
    ArrayList arylstDtl = oBd.getLeaveBreakup(oBaseHeaderBean);
    BeanUtils.setProperty(oForm, "arylstLvAppln", arylstDtl);
    oForm.setDays(getHolidayCount(arylstDtl));
    throw new EnrgiseApplicationException("hrm.HrmLvAppln.breakUp", "M");
  }
  
  private String getHolidayCount(ArrayList arylstDtl) {
    double dHolidayCount = 0.0D;
    if (arylstDtl != null) {
      Iterator itrDtlList = arylstDtl.iterator();
      while (itrDtlList.hasNext()) {
        HrmLvApplnDtlBean oDtlBean = itrDtlList.next();
        if (!oDtlBean.getTxtHolidayFlag().equalsIgnoreCase("H")) {
          if (!oDtlBean.getTxtHalfDayFlag().equalsIgnoreCase("3")) {
            dHolidayCount += 0.5D;
            continue;
          } 
          dHolidayCount++;
        } 
      } 
    } 
    return Double.toString(dHolidayCount);
  }
}
