protected override double LoadProrata(ELeaveBalance balanceItem, DateTime AsOfDate)
        {
            double prorata = base.LoadProrata(balanceItem, AsOfDate);

            // if CAT2 is enabled...
            if (leaveTypeDisabledSLCat2 == false && balanceItem.LeaveTypeID != leaveTypeIDSLCat2 && currentSLCat2balanceItem != null)
            {
                double maxBF = MaximumBroughtForward(balanceItem.LeaveBalanceEffectiveDate);
                if (balanceItem.getBalance() > maxBF && maxBF >= 0)
                {
                    double difference = balanceItem.getBalance() - maxBF;
                    balanceItem.LeaveBalanceEntitled -= difference;

                    currentSLCat2balanceItem.LeaveBalanceEntitled += difference;
                }
            }
            return(prorata);
        }
        protected override ELeaveBalance CreateNextLeaveBalanceItem(ELeaveBalance lastLeaveBalanceItem)
        {
            if (leaveTypeDisabledSLCat2 == false)
            {
                ELeaveBalance        lastSLCat2balanceItem  = currentSLCat2balanceItem;
                ELeaveBalance        SLCat1balanceItem      = base.CreateNextLeaveBalanceItem(lastLeaveBalanceItem);
                ELeaveBalanceEntitle leaveBalanceEntitleSL2 = null;

                if (lastSLCat2balanceItem != null && lastLeaveBalanceItem != null)
                {
                    currentSLCat2balanceItem.LeaveBalanceBF = lastSLCat2balanceItem.getBalance();
                    if (SLCat1balanceItem.LeaveBalanceForfeiture > 0)
                    {
                        SLCat1balanceItem.LeaveBalanceBF        -= SLCat1balanceItem.LeaveBalanceForfeiture;
                        currentSLCat2balanceItem.LeaveBalanceBF += SLCat1balanceItem.LeaveBalanceForfeiture;
                        SLCat1balanceItem.LeaveBalanceForfeiture = 0;
                    }

                    if (lastSLCat2balanceItem.LeaveBalanceEntitled > 0)
                    {
                        leaveBalanceEntitleSL2 = new ELeaveBalanceEntitle();
                        leaveBalanceEntitleSL2.LeaveBalanceEntitleEffectiveDate   = currentSLCat2balanceItem.LeaveBalanceEffectiveDate;
                        leaveBalanceEntitleSL2.LeaveBalanceEntitleGrantPeriodFrom = lastSLCat2balanceItem.LeaveBalanceEffectiveDate;
                        leaveBalanceEntitleSL2.LeaveBalanceEntitleGrantPeriodTo   = lastSLCat2balanceItem.LeaveBalanceEffectiveEndDate;
                        leaveBalanceEntitleSL2.EmpID                   = currentSLCat2balanceItem.EmpID;
                        leaveBalanceEntitleSL2.LeaveTypeID             = currentSLCat2balanceItem.LeaveTypeID;
                        leaveBalanceEntitleSL2.LeaveBalanceEntitleDays = lastSLCat2balanceItem.LeaveBalanceEntitled;
                    }

                    //  Initial Forfeiture
                    currentSLCat2balanceItem.LeaveBalanceForfeiture = 0;
                    int MaxBF = MaximumBroughtForwardForSLCat2(currentSLCat2balanceItem.LeaveBalanceEffectiveDate);

                    if (MaxBF >= 0)
                    {
                        currentSLCat2balanceItem.LeaveBalanceForfeiture = currentSLCat2balanceItem.LeaveBalanceBF - MaxBF;
                        if (currentSLCat2balanceItem.LeaveBalanceForfeiture < 0)
                        {
                            currentSLCat2balanceItem.LeaveBalanceForfeiture = 0;
                        }
                    }
                }

                balanceItemListSLCat2.Insert(0, currentSLCat2balanceItem);
                submit(currentSLCat2balanceItem, leaveBalanceEntitleSL2);
                return(SLCat1balanceItem);
            }
            else
            {
                return(base.CreateNextLeaveBalanceItem(lastLeaveBalanceItem));
            }
        }
Пример #3
0
        public ArrayList getCurrentBalanceList(bool forESSOnly)
        {
            ArrayList balanceList = new ArrayList();


            foreach (LeaveBalanceProcess balanceProcess in leaveBalanceProcessList.Values)
            {
                ELeaveBalance leaveBalance = balanceProcess.getLatestLeaveBalance();
                if (leaveBalance != null)
                {
                    //bool addToList = true;
                    if (forESSOnly)
                    {
                        ELeaveType leaveType = new ELeaveType();
                        leaveType.LeaveTypeID = leaveBalance.LeaveTypeID;
                        if (!ELeaveType.db.select(dbConn, leaveType))
                        {
                            continue;
                        }
                        if (leaveType.LeaveTypeIsESSHideLeaveBalance)
                        {
                            continue;
                        }
                        DBFilter countESSLeaveCodeFilter = new DBFilter();
                        countESSLeaveCodeFilter.add(new Match("LeaveTypeID", leaveBalance.LeaveTypeID));
                        countESSLeaveCodeFilter.add(new Match("LeaveCodeHideInESS", false));
                        if (ELeaveCode.db.count(dbConn, countESSLeaveCodeFilter) <= 0)
                        {
                            continue;
                        }
                        //addToList = false;
                    }

                    //if (addToList)
                    {
                        LoadLeaveTypeAndRounding(leaveBalance);
                        if (leaveBalance.LeaveBalanceEntitled != 0 || leaveBalance.getBalance() != 0 || leaveBalance.Taken != 0 || leaveBalance.Reserved != 0)
                        {
                            balanceList.Add(leaveBalance);
                        }
                    }
                }

                // Start 2013-12-02, Ricky So, Avoid showing CAT2 Sick Leave entry
                if ((ELeaveType.SLCAT2_LEAVE_TYPE(dbConn)).LeaveTypeIsDisabled == false)
                {
                    if (balanceProcess is SickLeaveBalanceProcess)
                    {
                        leaveBalance = ((SickLeaveBalanceProcess)balanceProcess).getLatestCAT2LeaveBalance();
                        if (leaveBalance != null)
                        {
                            bool addToList = true;
                            if (forESSOnly)
                            {
                                DBFilter countESSLeaveCodeFilter = new DBFilter();
                                countESSLeaveCodeFilter.add(new Match("LeaveTypeID", leaveBalance.LeaveTypeID));
                                countESSLeaveCodeFilter.add(new Match("LeaveCodeHideInESS", false));
                                if (ELeaveCode.db.count(dbConn, countESSLeaveCodeFilter) <= 0)
                                {
                                    addToList = false;
                                }
                            }

                            if (addToList)
                            {
                                LoadLeaveTypeAndRounding(leaveBalance);
                                if (leaveBalance.LeaveBalanceEntitled != 0 || leaveBalance.getBalance() != 0 || leaveBalance.Taken != 0 || leaveBalance.Reserved != 0)
                                {
                                    balanceList.Add(leaveBalance);
                                }
                            }
                        }
                    }
                }
                //if (balanceProcess is SickLeaveBalanceProcess)
                //{
                //    leaveBalance = ((SickLeaveBalanceProcess)balanceProcess).getLatestCAT2LeaveBalance();
                //    if (leaveBalance != null)
                //    {
                //        bool addToList = true;
                //        if (forESSOnly)
                //        {
                //            DBFilter countESSLeaveCodeFilter = new DBFilter();
                //            countESSLeaveCodeFilter.add(new Match("LeaveTypeID", leaveBalance.LeaveTypeID));
                //            countESSLeaveCodeFilter.add(new Match("LeaveCodeHideInESS", false));
                //            if (ELeaveCode.db.count(dbConn, countESSLeaveCodeFilter) <= 0)
                //                addToList = false;
                //        }

                //        if (addToList)
                //        {
                //            LoadLeaveTypeAndRounding(leaveBalance);
                //            if (leaveBalance.LeaveBalanceEntitled != 0 || leaveBalance.getBalance() != 0 || leaveBalance.Taken != 0 || leaveBalance.Reserved != 0)
                //                balanceList.Add(leaveBalance);
                //        }
                //    }
                //}


                // End 2013-12-02, Ricky So, Avoid showing CAT2 Sick Leave entry
            }

            return(balanceList);
        }
    // End 0000008, Ricky So, 2014-11-21

    protected void Save_Click(object sender, EventArgs e)
    {
        // speciailzed for TakYue only
        double m;

        try
        {
            m = Convert.ToDouble(RequestLeaveDays.Text);
        }
        catch
        {
            PageErrors invalideInputError = PageErrors.getErrors(db, Page);
            invalideInputError.clear();
            invalideInputError.addError("Invalid Days Taken value.");
            return;
        }

        if (!applicableDays.Value.Equals("") && !applicableDays.Value.Contains(m.ToString("0.00")))
        {
            PageErrors invalideInputError = PageErrors.getErrors(db, Page);
            invalideInputError.clear();
            invalideInputError.addError("Days Taken must be in this range : " + applicableDays.Value);
            return;
        }
        // end specializations

        ERequestLeaveApplication c = new ERequestLeaveApplication();

        if (!RequestLeaveAppUnit.SelectedValue.Equals("D"))
        {
            RequestLeaveAppDateTo.Value = RequestLeaveAppDateFrom.Value;
        }

        Hashtable values = new Hashtable();

        binding.toValues(values);

        PageErrors errors = PageErrors.getErrors(db, Page);

        errors.clear();


        db.validate(errors, values);

        if (!errors.isEmpty())
        {
            return;
        }


        db.parse(values, c);

        if (c.RequestLeaveAppUnit.Equals("D"))
        {
            // the following 2 fields are not bind to controls
            c.RequestLeaveAppDateFromAM = this.RequestLeaveAppDateFromAM.SelectedValue;
            c.RequestLeaveAppDateToAM   = this.RequestLeaveAppDateToAM.SelectedValue;
        }

        if (!c.RequestLeaveAppUnit.Equals("D"))
        {
            //c.RequestLeaveAppDateTo = c.RequestLeaveAppDateFrom;
            if (c.RequestLeaveAppTimeTo < c.RequestLeaveAppTimeFrom)
            {
                errors.addError("RequestLeaveAppTimeFrom", "Invald hours");
            }
        }
        else
        {
            if (c.RequestLeaveAppDateTo < c.RequestLeaveAppDateFrom)
            {
                errors.addError("RequestLeaveAppDateFrom", "Date To cannot be earlier than Date From");
            }
            // Start 0000201, Ricky So, 2015-05-29
            else if (c.RequestLeaveAppDateTo == c.RequestLeaveAppDateFrom)
            {
                if (c.RequestLeaveAppDateFromAM.CompareTo(c.RequestLeaveAppDateToAM) > 0)
                {
                    errors.addError("RequestLeaveAppDateFrom", "Date To cannot be earlier/equal than Date From");
                }
                else if (c.RequestLeaveAppDateFromAM.CompareTo(c.RequestLeaveAppDateToAM) == 0)
                {
                    // Convert to Half Day application if only AM/PM is applied
                    c.RequestLeaveAppUnit       = c.RequestLeaveAppDateFromAM.Substring(0, 1);
                    c.RequestLeaveAppDateFromAM = null;
                    c.RequestLeaveAppDateToAM   = null;
                    c.RequestLeaveDays          = 0.5;
                }
            }
            // End 0000201, Ricky So, 2015-05-29
            else
            {
                TimeSpan ts = c.RequestLeaveAppDateTo.Subtract(c.RequestLeaveAppDateFrom);
                if (c.RequestLeaveDays > ts.Days + 1)
                {
                    errors.addError("RequestLeaveDays", "Days taken is too large");
                }
            }
        }
        if (c.RequestLeaveAppDateFrom.Month != c.RequestLeaveAppDateTo.Month || c.RequestLeaveAppDateFrom.Year != c.RequestLeaveAppDateTo.Year)
        {
            errors.addError("Leave application must be within the same month");
        }

        if (HoursClaimPanel.Visible)
        {
            if (c.RequestLeaveAppHours <= 0)
            {
                errors.addError(string.Format(HROne.Translation.PageErrorMessage.ERROR_FIELD_REQUIRED, new string[] { lblLeaveAppHours.Text }));
            }
        }

        ELeaveCode curreintLeaveCode = new ELeaveCode();

        curreintLeaveCode.LeaveCodeID = c.RequestLeaveCodeID;
        if (ELeaveCode.db.select(dbConn, curreintLeaveCode))
        {
            ELeaveType leaveType = new ELeaveType();
            leaveType.LeaveTypeID = curreintLeaveCode.LeaveTypeID;
            if (ELeaveType.db.select(dbConn, leaveType))
            {
                // Start 0000008, Ricky So, 2014-11-21
                double m_hours = 0;
                double m_days  = 0;
                GetPendingLeaveBalance(c.EmpID, leaveType.LeaveTypeID, out m_hours, out m_days);
                // End 0000008, Ricky So, 2014-11-21

                if (leaveType.LeaveTypeIsESSIgnoreEntitlement)
                {
                    HROne.LeaveCalc.LeaveBalanceCalc    calc           = new HROne.LeaveCalc.LeaveBalanceCalc(dbConn, c.EmpID);
                    HROne.LeaveCalc.LeaveBalanceProcess balanceProcess = calc.getLeaveBalanceProcess(leaveType.LeaveTypeID);
                    // assume as at today (since entitlement is ignored, as-at-date doesn't make any difference
                    balanceProcess.LoadData(AppUtils.ServerDateTime().Date);
                    ELeaveBalance balance = balanceProcess.getLatestLeaveBalance();

                    // Start 0000008, Ricky So, 2014-11-21
                    //if (balance == null
                    //    || (balance.getBalance() - balance.LeaveBalanceEntitled < c.RequestLeaveDays && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day)
                    //    || (balance.getBalance() - balance.LeaveBalanceEntitled < c.RequestLeaveAppHours && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                    //    )
                    if (balance == null ||
                        (balance.getBalance() - m_days - balance.LeaveBalanceEntitled < c.RequestLeaveDays && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                        (balance.getBalance() - m_hours - balance.LeaveBalanceEntitled < c.RequestLeaveAppHours && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        )
                    // Start 0000008, Ricky So, 2014-11-21
                    {
                        errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                    }
                }
                else if (leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfApplicationDateFrom ||
                         leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfApplicationDateTo ||
                         leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfEndOfLeaveYear ||
                         leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfToday)
                {
                    HROne.LeaveCalc.LeaveBalanceCalc    calc           = new HROne.LeaveCalc.LeaveBalanceCalc(dbConn, c.EmpID);
                    HROne.LeaveCalc.LeaveBalanceProcess balanceProcess = calc.getLeaveBalanceProcess(leaveType.LeaveTypeID);

                    if (leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfToday)
                    {
                        balanceProcess.LoadData(AppUtils.ServerDateTime().Date);
                        ELeaveBalance balance = balanceProcess.getLatestLeaveBalance();
                        // Start 0000093, Ricky So, 2014-09-06
                        if (balance == null)
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        // Start 0000008, Ricky So, 2014-11-21
                        //else if ((balance.getBalance() - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                        //          (balance.getBalance() - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //         )
                        else if ((balance.getBalance() - m_days - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                                 (balance.getBalance() - m_hours - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                                 )
                        // End 0000008, Ricky So, 2014-11-21
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }

                        //if (balance == null
                        //    || (balance.getBalance() < c.RequestLeaveDays && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day)
                        //    || (balance.getBalance() < c.RequestLeaveAppHours && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //    )
                        //{
                        //    errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        //}
                        // End 0000093, Ricky So, 2014-09-06
                    }
                    if (errors.isEmpty() && leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfApplicationDateFrom)
                    {
                        balanceProcess.LoadData(c.RequestLeaveAppDateFrom);
                        ELeaveBalance balance = balanceProcess.getLatestLeaveBalance();
                        // Start 0000093, Ricky So, 2014-09-06
                        if (balance == null)
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        // Start 0000008, Ricky So, 2014-11-21
                        //else if ((balance.getBalance() - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                        //          (balance.getBalance() - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //         )
                        else if ((balance.getBalance() - m_days - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                                 (balance.getBalance() - m_hours - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                                 )
                        // End 0000008, Ricky So, 2014-11-21
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }

                        //if (balance == null
                        //    || (balance.getBalance() < c.RequestLeaveDays && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day)
                        //    || (balance.getBalance() < c.RequestLeaveAppHours && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //    )
                        //{
                        //    errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        //}
                        // End 0000093, Ricky So, 2014-09-06
                    }
                    if (errors.isEmpty() && leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfApplicationDateTo)
                    {
                        balanceProcess.LoadData(c.RequestLeaveAppDateTo);
                        ELeaveBalance balance = balanceProcess.getLatestLeaveBalance();
                        // Start 0000093, Ricky So, 2014-09-06
                        if (balance == null)
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        // Start 0000008, Ricky So, 2014-11-21
                        //else if ((balance.getBalance() - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                        //          (balance.getBalance() - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //         )
                        else if ((balance.getBalance() - m_days - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                                 (balance.getBalance() - m_hours - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                                 )
                        // End 0000008, Ricky So, 2014-11-21
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        //if (balance == null
                        //    || (balance.getBalance() < c.RequestLeaveDays && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day)
                        //    || (balance.getBalance() < c.RequestLeaveAppHours && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //    )
                        //{
                        //    errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        //}
                        // End 0000093, Ricky So, 2014-09-06
                    }
                    if (errors.isEmpty() && leaveType.LeaveTypeIsESSRestrictNegativeBalanceAsOfEndOfLeaveYear)
                    {
                        balanceProcess.LoadData(AppUtils.ServerDateTime().Date);
                        ELeaveBalance balance = balanceProcess.getLatestLeaveBalance();

                        if (!balance.LeaveBalanceEffectiveEndDate.Ticks.Equals(0))
                        {
                            balanceProcess.LoadData(balance.LeaveBalanceEffectiveEndDate);
                            balance = balanceProcess.getLatestLeaveBalance();
                        }
                        // Start 0000093, Ricky So, 2014-09-06
                        if (balance == null)
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        // Start 0000008, Ricky So, 2014-11-21
                        //else if ((balance.getBalance() - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                        //          (balance.getBalance() - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //         )
                        else if ((balance.getBalance() - m_days - c.RequestLeaveDays < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day) ||
                                 (balance.getBalance() - m_hours - c.RequestLeaveAppHours < -1 * leaveType.LeaveTypeIsESSAllowableAdvanceBalance && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                                 )
                        // End 0000008, Ricky So, 2014-11-21
                        {
                            errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        }
                        //if (balance == null
                        //    || (balance.getBalance() < c.RequestLeaveDays  && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Day)
                        //    || (balance.getBalance() < c.RequestLeaveAppHours  && balanceProcess.BalanceUnit == ELeaveBalance.LeaveBalanceUnit.Hour)
                        //    )
                        //{
                        //    errors.addError(ERROR_MESSAGE_BALANCE_NOT_ENOUGH);
                        //}
                        // End 0000093, Ricky So, 2014-09-06
                    }
                }
            }
        }

        if (!errors.isEmpty())
        {
            return;
        }

        ArrayList overlapLeaveAppList = new ArrayList();

        if (c.IsOverlapLeaveApplication(dbConn, out overlapLeaveAppList))
        {
            string strDailyOverlapMessage  = string.Empty;
            string strHourlyOverlapMessage = string.Empty;

            foreach (BaseObject overlapLeaveApp in overlapLeaveAppList)
            {
                if (overlapLeaveApp is ELeaveApplication)
                {
                    ELeaveApplication previousLeaveApp = (ELeaveApplication)overlapLeaveApp;
                    if (previousLeaveApp.LeaveAppUnit.Equals("D") || c.RequestLeaveAppUnit.Equals("D"))
                    {
                        if (string.IsNullOrEmpty(strDailyOverlapMessage))
                        {
                            strDailyOverlapMessage = "Leave dates cannot overlap with previous leave applications";
                        }
                        ELeaveCode leaveCode = new ELeaveCode();
                        leaveCode.LeaveCodeID = previousLeaveApp.LeaveCodeID;
                        if (ELeaveCode.db.select(dbConn, leaveCode))
                        {
                            // Start 0000201, Ricky So, 2015-06-02
                            //strDailyOverlapMessage += "\r\n- " + previousLeaveApp.LeaveAppDateFrom.ToString("yyyy-MM-dd") + (previousLeaveApp.LeaveAppDateFrom.Equals(previousLeaveApp.LeaveAppDateTo) ? "" : " To " + previousLeaveApp.LeaveAppDateTo.ToString("yyyy-MM-dd")) + " " + leaveCode.LeaveCodeDesc;
                            strDailyOverlapMessage += "\r\n- " + previousLeaveApp.LeaveAppDateFrom.ToString("yyyy-MM-dd");

                            if (previousLeaveApp.LeaveAppUnit == "A")
                            {
                                strDailyOverlapMessage += "AM";
                            }
                            else if (previousLeaveApp.LeaveAppUnit == "P")
                            {
                                strDailyOverlapMessage += "PM";
                            }
                            else if (previousLeaveApp.LeaveAppUnit == "D" && !string.IsNullOrEmpty(previousLeaveApp.LeaveAppDateFromAM))
                            {
                                strDailyOverlapMessage += previousLeaveApp.LeaveAppDateFromAM;
                            }
                            else
                            if (previousLeaveApp.LeaveAppDateFrom.Equals(previousLeaveApp.LeaveAppDateTo))
                            {
                                strDailyOverlapMessage += " To " + previousLeaveApp.LeaveAppDateTo.ToString("yyyy-MM-dd");
                            }

                            if (previousLeaveApp.LeaveAppUnit == "D" && !string.IsNullOrEmpty(previousLeaveApp.LeaveAppDateToAM))
                            {
                                strDailyOverlapMessage += previousLeaveApp.LeaveAppDateToAM;
                            }
                            else
                            {
                                strDailyOverlapMessage += "   " + leaveCode.LeaveCodeDesc;
                            }
                            // End 0000201, Ricky So, 2015-06-02
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(strHourlyOverlapMessage))
                        {
                            strHourlyOverlapMessage = "Leave time cannot overlap with previous leave applications";
                        }
                    }
                }
                else if (overlapLeaveApp is ERequestLeaveApplication)
                {
                    ERequestLeaveApplication previousRequestLeaveApp = (ERequestLeaveApplication)overlapLeaveApp;

                    if (previousRequestLeaveApp.RequestLeaveAppUnit.Equals("D") || c.RequestLeaveAppUnit.Equals("D"))
                    {
                        if (string.IsNullOrEmpty(strDailyOverlapMessage))
                        {
                            strDailyOverlapMessage = "Leave dates cannot overlap with previous leave applications";
                        }
                        ELeaveCode leaveCode = new ELeaveCode();
                        leaveCode.LeaveCodeID = previousRequestLeaveApp.RequestLeaveCodeID;
                        if (ELeaveCode.db.select(dbConn, leaveCode))
                        {
                            // Start 0000201, Ricky So, 2015-06-02
                            //strDailyOverlapMessage += "\r\n- " + previousRequestLeaveApp.RequestLeaveAppDateFrom.ToString("yyyy-MM-dd") + (previousRequestLeaveApp.RequestLeaveAppDateFrom.Equals(previousRequestLeaveApp.RequestLeaveAppDateTo) ? "" : " To " + previousRequestLeaveApp.RequestLeaveAppDateTo.ToString("yyyy-MM-dd")) + " " + leaveCode.LeaveCodeDesc;
                            strDailyOverlapMessage += "\r\n- " + previousRequestLeaveApp.RequestLeaveAppDateFrom.ToString("yyyy-MM-dd");

                            if (previousRequestLeaveApp.RequestLeaveAppUnit == "A")
                            {
                                strDailyOverlapMessage += "AM";
                            }
                            else if (previousRequestLeaveApp.RequestLeaveAppUnit == "P")
                            {
                                strDailyOverlapMessage += "PM";
                            }
                            else if (previousRequestLeaveApp.RequestLeaveAppUnit == "D" && !string.IsNullOrEmpty(previousRequestLeaveApp.RequestLeaveAppDateFromAM))
                            {
                                strDailyOverlapMessage += previousRequestLeaveApp.RequestLeaveAppDateFromAM;
                            }
                            else
                            if (previousRequestLeaveApp.RequestLeaveAppDateFrom.Equals(previousRequestLeaveApp.RequestLeaveAppDateTo))
                            {
                                strDailyOverlapMessage += " To " + previousRequestLeaveApp.RequestLeaveAppDateTo.ToString("yyyy-MM-dd");
                            }

                            if (previousRequestLeaveApp.RequestLeaveAppUnit == "D" && !string.IsNullOrEmpty(previousRequestLeaveApp.RequestLeaveAppDateToAM))
                            {
                                strDailyOverlapMessage += previousRequestLeaveApp.RequestLeaveAppDateToAM;
                            }
                            else
                            {
                                strDailyOverlapMessage += "   " + leaveCode.LeaveCodeDesc;
                            }
                            // End 0000201, Ricky So, 2015-06-02
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(strHourlyOverlapMessage))
                        {
                            strHourlyOverlapMessage = "Leave time cannot overlap with previous leave applications";
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(strDailyOverlapMessage))
            {
                errors.addError(strDailyOverlapMessage);
            }
            if (!string.IsNullOrEmpty(strHourlyOverlapMessage))
            {
                errors.addError(strHourlyOverlapMessage);
            }
        }

        if (!errors.isEmpty())
        {
            return;
        }

        try
        {
            ESSAuthorizationProcess authorization = new ESSAuthorizationProcess(dbConn);
            authorization.SubmitLeaveApplication(c);
        }
        catch (Exception ex)
        {
            errors.addError(ex.Message);
        }

        if (!errors.isEmpty())
        {
            return;
        }
        if (c.RequestLeaveAppHasMedicalCertificate)
        {
            string message = ESystemParameter.getParameter(dbConn, ESystemParameter.PARAM_CODE_ESS_LEAVE_MEDICIAL_CERT_ALERT);
            if (!string.IsNullOrEmpty(message))
            {
                message = message.Replace("\r", "\\r").Replace("\n", "\\n");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "leaveAppAlert", "alert(\"" + message + "\"); window.location=\"./ESS_EmpRequestStatus.aspx\";", true);
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "errorMessage", "popupDialog(\"testing\");", true);

                return;
            }
        }
        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/ESS_EmpRequestStatus.aspx");
    }