private int LeaveApprovalDetails_Save(int leaveApplicationId)
        {
            int response = 0;

            Business.LeaveManagement.LeaveApprovalConfiguration objLeaveApprovalConfiguration = new Business.LeaveManagement.LeaveApprovalConfiguration();
            DataTable dtLeaveEmployeeWiseApprovalConfiguration = objLeaveApprovalConfiguration.LeaveEmployeeWiseApprovalConfiguration_GetAll(
                new Entity.LeaveManagement.LeaveApprovalConfiguration()
            {
                EmployeeId = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
            });


            Business.LeaveManagement.LeaveApprovalDetails objLeaveApprovalDetails = new Business.LeaveManagement.LeaveApprovalDetails();
            Entity.LeaveManagement.LeaveApprovalDetails   leaveApprovalDetails    = new Entity.LeaveManagement.LeaveApprovalDetails();

            //If LeaveEmployeeWiseApprovalConfiguration is configured
            if (dtLeaveEmployeeWiseApprovalConfiguration != null &&
                dtLeaveEmployeeWiseApprovalConfiguration.AsEnumerable().Any() &&
                dtLeaveEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = 1").Any())
            {
                leaveApprovalDetails.ApproverId = Convert.ToInt32(dtLeaveEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = 1").FirstOrDefault()["ApproverId"].ToString());
            }
            else //If not confiured then send approval to Reporting employee
            {
                DataTable dtEmployee = new Business.HR.EmployeeMaster().EmployeeMaster_ById(new Entity.HR.EmployeeMaster()
                {
                    EmployeeMasterId = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
                });
                if (dtEmployee != null && dtEmployee.AsEnumerable().Any())
                {
                    leaveApprovalDetails.ApproverId = Convert.ToInt32(dtEmployee.Rows[0]["ReportingEmployeeId"].ToString());
                }
            }
            leaveApprovalDetails.LeaveApprovalDetailId = 0;
            leaveApprovalDetails.LeaveApplicationId    = leaveApplicationId;
            leaveApprovalDetails.Status  = (int)LeaveStatusEnum.Pending;
            leaveApprovalDetails.Remarks = "APPROVAL PENDING";

            response = objLeaveApprovalDetails.LeaveApprovalDetails_Save(leaveApprovalDetails);


            return(response);
        }
        private bool LeaveApplyValidation()
        {
            if (!LeaveApplicationControlValidation())
            {
                return(false);
            }
            DataTable dtLeaveConfigurations = GlobalCache.ExecuteCache <DataTable>(typeof(Business.LeaveManagement.LeaveConfiguration), "LeaveConfigurations_GetAll", new Entity.LeaveManagement.LeaveConfiguration()
            {
            });

            Entity.LeaveManagement.LeaveApplicationMaster leaveApplicationMaster = new Entity.LeaveManagement.LeaveApplicationMaster();
            leaveApplicationMaster.RequestorId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
            DataTable dtLeaveApplicationMaster = new Business.LeaveManagement.LeaveApplication().LeaveApplicationMaster_GetAll(leaveApplicationMaster);

            if (dtLeaveConfigurations != null && dtLeaveConfigurations.AsEnumerable().Any())
            {
                DataRow drLeaveConfiguration = dtLeaveConfigurations.Select("LeaveTypeId = " + ddlLeaveType.SelectedValue).FirstOrDefault();

                if (drLeaveConfiguration == null)
                {
                    Message.Text      = "Leave Configuration not found";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }

                if (!(DateTime.Now.Date >= Convert.ToDateTime(drLeaveConfiguration["LeaveAccrueDate"].ToString())))
                {
                    Message.Text      = "Leave Not Yet Applicable";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }
                if (dtLeaveApplicationMaster != null && dtLeaveApplicationMaster.AsEnumerable().Any())
                {
                    if (dtLeaveApplicationMaster.Select("LeaveStatusId = " + ((int)LeaveStatusEnum.Pending).ToString()).Any())
                    {
                        Message.Text      = "You already have leave approval pending.";
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }
                }
            }
            else
            {
                Message.Text      = "Leave Configuration not found";
                Message.IsSuccess = false;
                Message.Show      = true;
                return(false);
            }

            DataTable dtEmployee = new Business.HR.EmployeeMaster().EmployeeMaster_ById(new Entity.HR.EmployeeMaster()
            {
                EmployeeMasterId = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
            });

            if (dtEmployee != null && dtEmployee.AsEnumerable().Any())
            {
                if (dtEmployee.Rows[0]["ReportingEmployeeId"] == DBNull.Value)
                {
                    Message.Text      = "Please update reporting person.";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }

                Entity.LeaveManagement.LeaveDesignationWiseConfiguration leaveDesignationWiseConfiguration = new Entity.LeaveManagement.LeaveDesignationWiseConfiguration();
                leaveDesignationWiseConfiguration.LeaveTypeId   = Convert.ToInt32(ddlLeaveType.SelectedValue);
                leaveDesignationWiseConfiguration.DesignationId = Convert.ToInt32(dtEmployee.Rows[0]["DesignationMasterId_FK"].ToString());
                DataTable dtLeaveDesignationConfiguration = new Business.LeaveManagement.LeaveDesignationWiseConfiguration().LeaveDesignationConfig_GetAll(leaveDesignationWiseConfiguration);
                if (dtLeaveDesignationConfiguration != null && dtLeaveDesignationConfiguration.AsEnumerable().Any())
                {
                    decimal totalDays = Convert.ToDecimal(lbTotalCount.Text.Trim());
                    if (totalDays < Convert.ToDecimal(dtLeaveDesignationConfiguration.Rows[0]["MinApplyDays"].ToString()))
                    {
                        Message.Text      = "Min leave should be more than " + dtLeaveDesignationConfiguration.Rows[0]["MinApplyDays"].ToString() + " days";
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }
                    else if (totalDays > Convert.ToDecimal(dtLeaveDesignationConfiguration.Rows[0]["MaxApplyDays"].ToString()))
                    {
                        Message.Text      = "Max leave should be less than " + dtLeaveDesignationConfiguration.Rows[0]["MaxApplyDays"].ToString() + " days";
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }

                    //if (Convert.ToDecimal(lbTotalCount.Text.Trim()) > Convert.ToDecimal(dtLeaveDesignationConfiguration.Rows[0]["LeaveCount"].ToString()))
                    //{
                    //    Message.Text = "Maximum Leave you can apply is " + dtLeaveDesignationConfiguration.Rows[0]["LeaveCount"].ToString() + " days in a year";
                    //    Message.IsSuccess = false;
                    //    Message.Show = true;
                    //    return false;
                    //}
                }
                else
                {
                    Message.Text      = "Leave designation configuration not found";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }


                DataTable dtLeaveAccountBalance = new Business.LeaveManagement.LeaveAccountBalance().LeaveAccountBalance_ByEmployeeId(Convert.ToInt32(HttpContext.Current.User.Identity.Name), Convert.ToInt32(ddlLeaveType.SelectedValue)).Tables[0];
                if (dtLeaveAccountBalance != null && dtLeaveAccountBalance.AsEnumerable().Any())
                {
                    if (Convert.ToInt32(lbTotalCount.Text.Trim()) > Convert.ToDecimal(dtLeaveAccountBalance.Rows[0]["Amount"].ToString()))
                    {
                        Message.Text      = "Your Leave Balance is low.";
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }
                    if (Convert.ToBoolean(dtLeaveAccountBalance.Rows[0]["LeaveBlocked"].ToString()))
                    {
                        Message.Text      = "Your leaves are blocked. Please contact to HR.";
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }
                }
                else
                {
                    Message.Text      = "You do not have any Leave Balance.";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }

                //Checking leave date overlapping
                DataTable dtLeaveApplicationDetails = new Business.LeaveManagement.LeaveApplication().LeaveApplicationDetails_GetByDate(new Entity.LeaveManagement.LeaveApplicationMaster()
                {
                    RequestorId   = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                    FromLeaveDate = Convert.ToDateTime(lbFromDate.Text.Trim()),
                    ToLeaveDate   = Convert.ToDateTime(lbToDate.Text.Trim()),
                    LeaveStatuses = Convert.ToString((int)LeaveStatusEnum.Approved) + "," + Convert.ToString((int)LeaveStatusEnum.Pending)
                });
                if (dtLeaveApplicationDetails != null && dtLeaveApplicationDetails.AsEnumerable().Any())
                {
                    Message.Text      = "Your leave dates are overlapping. Please check your Approved/Pending list.";
                    Message.IsSuccess = false;
                    Message.Show      = true;
                    return(false);
                }

                if (!string.IsNullOrEmpty(hdnHalfDayList.Value.Replace(',', ' ').Trim()))
                {
                    if (!(ddlLeaveType.SelectedValue == ((int)LeaveTypeEnum.CL).ToString()) && !(ddlLeaveType.SelectedValue == ((int)LeaveTypeEnum.LWP).ToString()))
                    {
                        Message.Text      = "You cannot apply half day with leave type " + ddlLeaveType.SelectedItem.Text;
                        Message.IsSuccess = false;
                        Message.Show      = true;
                        return(false);
                    }
                }
            }
            else
            {
                Message.Text      = "Employee Details not found.";
                Message.IsSuccess = false;
                Message.Show      = true;
                return(false);
            }
            return(true);
        }
        private bool ClaimAddValidation()
        {
            int       designationId = 0;
            DataTable dtEmployee    = new Business.HR.EmployeeMaster().EmployeeMaster_ById(new EmployeeMaster()
            {
                EmployeeMasterId = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
            });

            if (dtEmployee != null && dtEmployee.AsEnumerable().Any())
            {
                designationId = Convert.ToInt32(dtEmployee.Rows[0]["DesignationMasterId_FK"].ToString());
            }
            else
            {
                Message.IsSuccess = false;
                Message.Text      = "Employee details not found!  Contact administrator.";
                Message.Show      = true;
                return(false);
            }
            DataTable dtClaimDesignationWiseConfiguration = GlobalCache.ExecuteCache <DataTable>(typeof(Business.ClaimManagement.ClaimDesignationWiseConfiguration), "ClaimDesignationConfig_GetAllCached", new Entity.ClaimManagement.ClaimDesignationWiseConfiguration());

            if (dtClaimDesignationWiseConfiguration != null && dtClaimDesignationWiseConfiguration.AsEnumerable().Any())
            {
                using (DataView dvClaimDesignationWiseConfiguration = new DataView(dtClaimDesignationWiseConfiguration))
                {
                    dvClaimDesignationWiseConfiguration.RowFilter = "DesignationId = " + designationId + " AND ClaimCategoryId = " + ddlCategory.SelectedValue + "";
                    dtClaimDesignationWiseConfiguration           = dvClaimDesignationWiseConfiguration.ToTable();
                }
            }
            else
            {
                Message.IsSuccess = false;
                Message.Text      = "Claim configuration for your designation not found! Contact administrator.";
                Message.Show      = true;
                return(false);
            }
            if (dtClaimDesignationWiseConfiguration != null && dtClaimDesignationWiseConfiguration.AsEnumerable().Any())
            {
                decimal totalCost = Convert.ToDecimal(txtCost.Text);

                if (_ClaimDetails != null && _ClaimDetails.AsEnumerable().Any())
                {
                    using (DataView dvClaimDetails = new DataView(_ClaimDetails))
                    {
                        dvClaimDetails.RowFilter = "CategoryId = " + ddlCategory.SelectedValue;
                        if (dvClaimDetails.ToTable() != null && dvClaimDetails.ToTable().AsEnumerable().Any())
                        {
                            totalCost += Convert.ToDecimal(dvClaimDetails.ToTable().Compute("SUM(Cost)", string.Empty));
                        }
                    }
                }
                if (totalCost > Convert.ToDecimal(dtClaimDesignationWiseConfiguration.Rows[0]["Limit"].ToString()))
                {
                    Message.IsSuccess = false;
                    Message.Text      = "Your claim limit exceeded.";
                    Message.Show      = true;
                    return(false);
                }
            }
            else
            {
                Message.IsSuccess = false;
                Message.Text      = "Claim configuration for your designation not found! Contact administrator.";
                Message.Show      = true;
                return(false);
            }

            return(true);
        }