private int ClaimApprovalDetails_Save(int claimApplicationId)
        {
            int response = 0;

            Business.ClaimManagement.ClaimApprovalConfiguration objClaimApprovalConfiguration = new Business.ClaimManagement.ClaimApprovalConfiguration();
            DataTable dtClaimEmployeeWiseApprovalConfiguration = objClaimApprovalConfiguration.ClaimEmployeeWiseApprovalConfiguration_GetAll(
                new Entity.ClaimManagement.ClaimApprovalConfiguration()
            {
                EmployeeId = Convert.ToInt32(HttpContext.Current.User.Identity.Name)
            });


            Business.ClaimManagement.ClaimApprovalDetails objClaimApprovalDetails = new Business.ClaimManagement.ClaimApprovalDetails();
            Entity.ClaimManagement.ClaimApprovalDetails   ClaimApprovalDetails    = new Entity.ClaimManagement.ClaimApprovalDetails();

            //If ClaimEmployeeWiseApprovalConfiguration is configured
            if (dtClaimEmployeeWiseApprovalConfiguration != null &&
                dtClaimEmployeeWiseApprovalConfiguration.AsEnumerable().Any() &&
                dtClaimEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = 1").Any())
            {
                ClaimApprovalDetails.ApproverId = Convert.ToInt32(dtClaimEmployeeWiseApprovalConfiguration.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())
                {
                    ClaimApprovalDetails.ApproverId = Convert.ToInt32(dtEmployee.Rows[0]["ReportingEmployeeId"].ToString());
                }
            }
            ClaimApprovalDetails.ClaimApprovalDetailId = 0;
            ClaimApprovalDetails.ClaimApplicationId    = claimApplicationId;
            ClaimApprovalDetails.Status  = (int)ClaimStatusEnum.Pending;
            ClaimApprovalDetails.Remarks = "APPROVAL PENDING";

            response = objClaimApprovalDetails.ClaimApprovalDetails_Save(ClaimApprovalDetails);


            return(response);
        }
Exemple #2
0
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                if (ClaimApprovalValidation())
                {
                    Entity.ClaimManagement.ClaimApprovalDetails ClaimApprovalDetails = new Entity.ClaimManagement.ClaimApprovalDetails();
                    ClaimApprovalDetails.ApproverId         = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                    ClaimApprovalDetails.ClaimApplicationId = Business.Common.Context.ClaimApplicationId;
                    ClaimApprovalDetails.Status             = (int)ClaimStatusEnum.Approved;
                    ClaimApprovalDetails.Remarks            = txtRemarks.Text.Trim();
                    int response = new Business.ClaimManagement.ClaimApprovalDetails().Claim_Approve(ClaimApprovalDetails);

                    if (response > 0)
                    {
                        //Fetching Requestor Id
                        Entity.ClaimManagement.ClaimApplicationMaster ClaimApplicationMaster = new Entity.ClaimManagement.ClaimApplicationMaster();
                        Business.ClaimManagement.ClaimApplication     objClaimApplication    = new Business.ClaimManagement.ClaimApplication();
                        ClaimApplicationMaster.ClaimApplicationId = Business.Common.Context.ClaimApplicationId;
                        DataTable dtClaimApplication = objClaimApplication.ClaimApplication_GetAll(ClaimApplicationMaster);

                        Business.ClaimManagement.ClaimApprovalConfiguration objClaimApprovalConfiguration = new Business.ClaimManagement.ClaimApprovalConfiguration();
                        DataTable dtClaimEmployeeWiseApprovalConfiguration = objClaimApprovalConfiguration.ClaimEmployeeWiseApprovalConfiguration_GetAll(
                            new Entity.ClaimManagement.ClaimApprovalConfiguration()
                        {
                            EmployeeId = (dtClaimApplication != null && dtClaimApplication.AsEnumerable().Any()) ? Convert.ToInt32(dtClaimApplication.Rows[0]["EmployeeId"].ToString()) : 0
                        });

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

                            ClaimApprovalDetails.ClaimApprovalDetailId = 0;
                            ClaimApprovalDetails.ClaimApplicationId    = Business.Common.Context.ClaimApplicationId;
                            ClaimApprovalDetails.Status     = (int)ClaimStatusEnum.Pending;
                            ClaimApprovalDetails.ApproverId = Convert.ToInt32(dtClaimEmployeeWiseApprovalConfiguration.Select("ApprovalLevel = " + currentClaimApproverLevel).FirstOrDefault()["ApproverId"].ToString());
                            //Assigning Claim Request to next approver
                            int approvalResponse = objClaimApprovalDetails.ClaimApprovalDetails_Save(ClaimApprovalDetails);
                            if (approvalResponse > 0)
                            {
                                GetClaimApplications_ByApproverId(ckShowAll.Checked ? (int)ClaimStatusEnum.None : (int)ClaimStatusEnum.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.ClaimManagement.ClaimApplication().ClaimApplicationMaster_Save(
                                new Entity.ClaimManagement.ClaimApplicationMaster()
                            {
                                ClaimApplicationId = Business.Common.Context.ClaimApplicationId,
                                Status             = (int)ClaimStatusEnum.Approved,
                                ApprovedAmount     = Convert.ToDecimal(lblTotalApprovedAmount.Text.Trim())
                            });

                            GetClaimApplications_ByApproverId(ckShowAll.Checked ? (int)ClaimStatusEnum.None : (int)ClaimStatusEnum.Pending);
                            MessageSuccess.IsSuccess = true;
                            MessageSuccess.Text      = "Claim approved.";
                            MessageSuccess.Show      = true;
                            ModalPopupExtender1.Hide();
                            txtRemarks.Text = string.Empty;
                            Message.Show    = false;
                        }
                        Claim_Heading_Update(Business.Common.Context.ClaimApplicationId, txtClaimHeader.Text.Trim());
                        Claim_Adjust_Update();
                    }
                    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;
            }
        }