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);
        }
Example #2
0
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                if (LeaveApprovalValidation())
                {
                    Entity.LeaveManagement.LeaveApprovalDetails leaveApprovalDetails = new Entity.LeaveManagement.LeaveApprovalDetails();
                    leaveApprovalDetails.ApproverId         = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                    leaveApprovalDetails.LeaveApplicationId = Business.Common.Context.LeaveApplicationId;
                    leaveApprovalDetails.Status             = (int)LeaveStatusEnum.Approved;
                    leaveApprovalDetails.Remarks            = txtRemarks.Text.Trim();
                    int response = new Business.LeaveManagement.LeaveApprovalDetails().LeaveApprove(leaveApprovalDetails);

                    if (response > 0)
                    {
                        //Fetching Requestor Id
                        Entity.LeaveManagement.LeaveApplicationMaster leaveApplicationMaster = new Entity.LeaveManagement.LeaveApplicationMaster();
                        Business.LeaveManagement.LeaveApplication     objLeaveApplication    = new Business.LeaveManagement.LeaveApplication();
                        leaveApplicationMaster.LeaveApplicationId = Business.Common.Context.LeaveApplicationId;
                        DataTable dtLeaveApplication = objLeaveApplication.LeaveApplicationMaster_GetAll(leaveApplicationMaster);

                        Business.LeaveManagement.LeaveApprovalConfiguration objLeaveApprovalConfiguration = new Business.LeaveManagement.LeaveApprovalConfiguration();
                        DataTable dtLeaveEmployeeWiseApprovalConfiguration = objLeaveApprovalConfiguration.LeaveEmployeeWiseApprovalConfiguration_GetAll(
                            new Entity.LeaveManagement.LeaveApprovalConfiguration()
                        {
                            EmployeeId = (dtLeaveApplication != null && dtLeaveApplication.AsEnumerable().Any()) ? Convert.ToInt32(dtLeaveApplication.Rows[0]["RequestorId"].ToString()) : 0
                        });

                        int currentLeaveApproverLevel = 0;
                        if (dtLeaveEmployeeWiseApprovalConfiguration != null &&
                            dtLeaveEmployeeWiseApprovalConfiguration.AsEnumerable().Any() &&
                            dtLeaveEmployeeWiseApprovalConfiguration.Select("ApproverId = " + HttpContext.Current.User.Identity.Name).Any())
                        {
                            //Fetching the current approver approval level
                            currentLeaveApproverLevel = Convert.ToInt32(dtLeaveEmployeeWiseApprovalConfiguration
                                                                        .Select("ApproverId = " + HttpContext.Current.User.Identity.Name).FirstOrDefault()["ApprovalLevel"].ToString());
                            currentLeaveApproverLevel = currentLeaveApproverLevel + 1;
                        }
                        if (dtLeaveEmployeeWiseApprovalConfiguration != null &&
                            dtLeaveEmployeeWiseApprovalConfiguration.AsEnumerable().Any() &&
                            dtLeaveEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = " + currentLeaveApproverLevel).Any())
                        {
                            Business.LeaveManagement.LeaveApprovalDetails objLeaveApprovalDetails = new Business.LeaveManagement.LeaveApprovalDetails();

                            leaveApprovalDetails.LeaveApprovalDetailId = 0;
                            leaveApprovalDetails.LeaveApplicationId    = Business.Common.Context.LeaveApplicationId;
                            leaveApprovalDetails.Status     = (int)LeaveStatusEnum.Pending;
                            leaveApprovalDetails.ApproverId = Convert.ToInt32(dtLeaveEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = " + currentLeaveApproverLevel).FirstOrDefault()["ApproverId"].ToString());
                            //Assigning Leave Request to next approver
                            int approvalResponse = objLeaveApprovalDetails.LeaveApprovalDetails_Save(leaveApprovalDetails);
                            if (approvalResponse > 0)
                            {
                                GetLeaveApplications_ByApproverId(ckShowAll.Checked ? (int)LeaveStatusEnum.None : (int)LeaveStatusEnum.Pending);
                                MessageSuccess.IsSuccess = true;
                                MessageSuccess.Text      = "Approval moved to next level.";
                                MessageSuccess.Show      = true;
                                ModalPopupExtender1.Hide();
                            }
                        }
                        else
                        {
                            //If final Appoval approved then update status in Master table
                            new Business.LeaveManagement.LeaveApplication().LeaveApplicationMaster_Save(
                                new Entity.LeaveManagement.LeaveApplicationMaster()
                            {
                                LeaveApplicationId = Business.Common.Context.LeaveApplicationId,
                                LeaveStatusId      = (int)LeaveStatusEnum.Approved
                            });
                            int adjustResponse = LeaveAccontBalance_Deduct(Business.Common.Context.LeaveApplicationId);
                            if (adjustResponse > 0)
                            {
                                GetLeaveApplications_ByApproverId(ckShowAll.Checked ? (int)LeaveStatusEnum.None : (int)LeaveStatusEnum.Pending);
                                MessageSuccess.IsSuccess = true;
                                MessageSuccess.Text      = "Leave approved.";
                                MessageSuccess.Show      = true;
                                ModalPopupExtender1.Hide();
                            }
                            else
                            {
                                Message.IsSuccess       = false;
                                Message.Text            = "Something went wrong! Please contact system administrator";
                                Message.Show            = true;
                                TabContainer1.ActiveTab = Approval;
                                ModalPopupExtender1.Show();
                            }
                        }
                    }
                    else
                    {
                        Message.IsSuccess = false;
                        Message.Text      = "Response not given.";
                        Message.Show      = true;

                        TabContainer1.ActiveTab = Approval;
                        ModalPopupExtender1.Show();
                    }
                }
                else
                {
                    TabContainer1.ActiveTab = Approval;
                    ModalPopupExtender1.Show();
                }
            }
            catch (Exception ex)
            {
                ex.WriteException();

                Message.IsSuccess = false;
                Message.Text      = ex.Message;
                Message.Show      = true;
            }
        }