public static int LeaveApprove(Entity.LeaveManagement.LeaveApprovalDetails leaveApprovalDetails)
        {
            int retValue = 0;

            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "usp_LeaveApprove";

                    cmd.Parameters.AddWithValue("@LeaveApplicationId", leaveApprovalDetails.LeaveApplicationId);
                    cmd.Parameters.AddWithValue("@ApproverId", leaveApprovalDetails.ApproverId);
                    cmd.Parameters.AddWithValue("@StatusId", leaveApprovalDetails.Status);
                    cmd.Parameters.AddWithValue("@Remarks", leaveApprovalDetails.Remarks);

                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    retValue = cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
            return(retValue);
        }
Esempio n. 2
0
        protected void btnCancel_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.Cancelled;
                    leaveApprovalDetails.Remarks            = txtRemarks.Text.Trim();
                    int response = new Business.LeaveManagement.LeaveApprovalDetails().LeaveApprove(leaveApprovalDetails);

                    if (response > 0)
                    {
                        //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.Cancelled
                        });
                        //Leave Balance reverting
                        LeaveAccontBalance_Revert(Business.Common.Context.LeaveApplicationId);

                        GetLeaveApplications_ByApproverId(ckShowAll.Checked ? (int)LeaveStatusEnum.None : (int)LeaveStatusEnum.Pending);
                        MessageSuccess.IsSuccess = true;
                        MessageSuccess.Text      = "Leave cancelled.";
                        MessageSuccess.Show      = true;
                        ModalPopupExtender1.Hide();
                    }
                    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;
            }
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dtApprovalDetails = new Business.LeaveManagement.LeaveApprovalDetails().LeaveApprovalDetails_ByRequestorId(
                    Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                    (int)LeaveStatusEnum.Pending);

                if (dtApprovalDetails != null && dtApprovalDetails.AsEnumerable().Any())
                {
                    foreach (DataRow drApproval in dtApprovalDetails.Rows)
                    {
                        Entity.LeaveManagement.LeaveApprovalDetails leaveApprovalDetails = new Entity.LeaveManagement.LeaveApprovalDetails();
                        leaveApprovalDetails.ApproverId         = Convert.ToInt32(drApproval["ApproverId"].ToString());
                        leaveApprovalDetails.LeaveApplicationId = Business.Common.Context.LeaveApplicationId;
                        leaveApprovalDetails.Status             = (int)LeaveStatusEnum.Cancelled;
                        leaveApprovalDetails.Remarks            = "CANCELLED BY USER";
                        int response = new Business.LeaveManagement.LeaveApprovalDetails().LeaveApprove(leaveApprovalDetails);
                    }

                    //If final all Approvals Cancelled then update status in Master table
                    new Business.LeaveManagement.LeaveApplication().LeaveApplicationMaster_Save(
                        new Entity.LeaveManagement.LeaveApplicationMaster()
                    {
                        LeaveApplicationId = Business.Common.Context.LeaveApplicationId,
                        LeaveStatusId      = (int)LeaveStatusEnum.Cancelled
                    });


                    MessageSuccess.IsSuccess = true;
                    MessageSuccess.Text      = "Leave is cancelled.";
                    MessageSuccess.Show      = true;
                    ModalPopupExtender1.Hide();
                    LeaveApplicationMaster_GetAll();
                }
                else
                {
                    Message.IsSuccess = false;
                    Message.Text      = "Leave Cancel is not allowed.";
                    Message.Show      = true;
                }
            }
            catch (Exception ex)
            {
                ex.WriteException();

                Message.IsSuccess = false;
                Message.Text      = ex.Message;
                Message.Show      = true;
            }
        }
        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);
        }
 public int LeaveApprovalDetails_Save(Entity.LeaveManagement.LeaveApprovalDetails leaveApprovalDetails)
 {
     return(DataAccess.LeaveManagement.LeaveApprovalDetails.LeaveApprovalDetails_Save(leaveApprovalDetails));
 }
Esempio n. 6
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;
            }
        }