コード例 #1
0
    /// <summary>
    /// Show Approve Popup
    /// </summary>
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        bool IsFinalAproved = false;

        try
        {
            string QuotationCode = "";
            string SupplierCode  = "";

            DataTable dtQuotationList_ForTopApprover = new DataTable();
            dtQuotationList_ForTopApprover.Columns.Add("Qtncode");
            dtQuotationList_ForTopApprover.Columns.Add("amount");

            DataTable dtQuotationList = new DataTable();
            dtQuotationList.Columns.Add("Qtncode");
            dtQuotationList.Columns.Add("amount");

            DataTable dtBudgetCode = new DataTable();
            dtBudgetCode.Columns.Add("Qtncode");
            dtBudgetCode.Columns.Add("amount");
            TechnicalBAL objTechBAL = new TechnicalBAL();

            string[] Attchment = new string[10];


            // check for provision's approval limit for items
            bool isProvisionLimitsts = isProvisionLimitExceeding();


            //Get Approval Amount

            BLL_PURC_Purchase objApproval = new BLL_PURC_Purchase();
            DataTable         dtApproval  = objApproval.Get_Approval_Limit(Convert.ToInt32(User), ViewState["Dept_Code"].ToString());
            if (dtApproval.Rows.Count < 1)
            {
                String msgApp = String.Format("alert('Approval limit does not exist for you.Please contact admin.');RefreshPendingDetails();window.close();");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg99011a", msgApp, true);
                //divApprove.Visible = false;
                String msgmodal = String.Format("hideModal('divApprove');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodalhide", msgmodal, true);
                return;
            }

            decimal dblPOAprLimitAmt = decimal.Parse(dtApproval.Rows[0]["Approval_Limit"].ToString());
            if (dblPOAprLimitAmt < 1)
            {
                String msgApp = String.Format("alert('Approval limit does not exist for you.Please contact admin.');RefreshPendingDetails() ;window.close();");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg660081g", msgApp, true);
                String msgmodal = String.Format("hideModal('divApprove');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodalhide", msgmodal, true);
                return;
            }

            TechnicalBAL objtechBAL = new TechnicalBAL();
            objtechBAL.Update_ReqsnType(Requisitioncode, UDFLib.ConvertToInteger(ddlReqsnType.SelectedValue), "", UDFLib.ConvertToInteger(User));

            decimal Supp_Total_Amount = 0;
            decimal approvedAmount    = 0;
            dicTotalAmount.Clear();

            CheckBox Chk = new CheckBox();
            foreach (GridViewRow gr in Grid_RqsnDtl.Rows)
            {
                Chk = (CheckBox)gr.FindControl("Chk_Item");

                if (Chk.Checked)
                {
                    Label lbl_Qnty = (Label)gr.FindControl("lbl_TotalPrice");
                    approvedAmount = Convert.ToDecimal(lbl_Qnty.Text) + approvedAmount;
                }
            }


            // add the orderedamount from existing POs in approved amount(amount going to be approved)
            approvedAmount = approvedAmount + Convert.ToDecimal(hdfOrderAmounts.Value);

            Supp_Total_Amount = decimal.Parse(hdfMaxQuotedAmount.Value);


            SupplierCode  = hdfSupplierBeingApproved.Value;
            QuotationCode = hdfQTNCode.Value;

            BLL_PURC_Purchase objTechService = new BLL_PURC_Purchase();

            string retval = "TRUE";
            if (hdnBudgetCode.Value.ToString() == "1")
            {
                DataRow dtrow = dtBudgetCode.NewRow();
                dtrow[0] = QuotationCode;
                dtrow[1] = dicTotalAmount[QuotationCode].ToString();
                dtBudgetCode.Rows.Add(dtrow);
                retval = objTechService.Check_Update_BudgetCode(Requisitioncode, Vessel_Code, ddlBudgetCode.SelectedValue, dtBudgetCode);
            }

            if (retval == "TRUE")
            {
                if (Supp_Total_Amount > dblPOAprLimitAmt || approvedAmount > dblPOAprLimitAmt)// supplier code is zero in this case
                {
                    objApproval.POApproving(Requisitioncode, QuotationCode, "0", User, "", Vessel_Code, ddlBudgetCode.SelectedValue.ToString());

                    // store the qtn code and supp amount for top approver
                    DataRow dtrow = dtQuotationList_ForTopApprover.NewRow();
                    dtrow[0] = QuotationCode;
                    dtrow[1] = dicTotalAmount[QuotationCode].ToString();
                    dtQuotationList_ForTopApprover.Rows.Add(dtrow);
                }

                else if (Supp_Total_Amount <= dblPOAprLimitAmt && approvedAmount <= dblPOAprLimitAmt && (isProvisionLimitsts == false))//The actual approval
                {
                    //qtnbased

                    DataRow dtrow = dtQuotationList.NewRow();
                    dtrow[0] = QuotationCode;
                    dtrow[1] = dicTotalAmount[QuotationCode].ToString();
                    dtQuotationList.Rows.Add(dtrow);

                    /// begin insert the records for final PO
                    DataTable dtReqInfo = new DataTable();
                    dtReqInfo = objTechService.SelectSupplierToSendOrderEval(Requisitioncode, Vessel_Code, QuotationCode);
                    SavePurchasedOrder(dtReqInfo.DefaultView.ToTable());

                    objTechService.POApproving(Requisitioncode, QuotationCode, SupplierCode, User, txtComment.Text, Vessel_Code, ddlBudgetCode.SelectedValue.ToString());


                    IsFinalAproved = true;
                }
            }
            else
            {
                //btnRequestAmount.Visible = true;
                String msg1 = String.Format("alert('A.Total Approval amount is greater than Budget limit,Please request for increase Budget limit.');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg1, true);
                String msgmodal = String.Format("showModal('divApprove');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodal", msgmodal, true);
            }
            //}
            // }

            if (IsFinalAproved)
            {
                //Requisition stage status update
                // BLL_PURC_Purchase objTechService = new BLL_PURC_Purchase();
                //Check Budget Code and Update
                retval = "TRUE";
                if (hdnBudgetCode.Value.ToString() == "1")
                {
                    retval = objTechService.Check_Update_BudgetCode(Requisitioncode, Vessel_Code, ddlBudgetCode.SelectedValue, dtBudgetCode);
                }

                if (retval == "TRUE")
                {
                    //btnRequestAmount.Visible = false;
                    // SAVE APPROVAL
                    objTechBAL.InsertUserApprovalEntries(Requisitioncode, Document_Code, Vessel_Code, User, User, Supp_Total_Amount, approvedAmount, "0", txtComment.Text.Trim(), dtQuotationList);

                    BLL_PURC_Common.INS_Remarks(Document_Code, Convert.ToInt32(User), txtComment.Text.Trim(), 303);
                    objTechService.InsertRequisitionStageStatus(Requisitioncode, Vessel_Code, Document_Code, "RPO", " ", Convert.ToInt32(User), dtQuotationList);

                    String msg1 = String.Format("alert('Approved successfully.'); RefreshPendingDetails(); window.close();");
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg1, true);
                    return;
                }
                else
                {
                    //btnRequestAmount.Visible = true;
                    String msg1 = String.Format("alert('B.Total Approval amount is greater than Budget limit,Please request for increase Budget limit.');");
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg1, true);
                    String msgmodal = String.Format("showModal('divApprove');");
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodal", msgmodal, true);
                }
            }

            else
            {
                if (!isProvisionLimitsts)
                {
                    //check if only one approver is left then send him directly instead of prompting the current user to send and save the current approver's approval.
                    //  BLL_PURC_Purchase objTechService = new BLL_PURC_Purchase();
                    retval = "TRUE";
                    if (hdnBudgetCode.Value.ToString() == "1")
                    {
                        retval = objTechService.Check_Update_BudgetCode(Requisitioncode, Vessel_Code, ddlBudgetCode.SelectedValue, dtBudgetCode);
                    }

                    if (retval == "TRUE")
                    {
                        //btnRequestAmount.Visible = false;
                        int ApproverCount = BLL_PURC_Common.CheckHierarchy_SendForApproval(Requisitioncode, Document_Code, Convert.ToInt32(Vessel_Code), User, Supp_Total_Amount, dblPOAprLimitAmt, dtQuotationList_ForTopApprover);
                        if (ApproverCount == 1)
                        {
                            BLL_PURC_Common.INS_Remarks(Document_Code, Convert.ToInt32(User), txtComment.Text.Trim(), 303);
                            String msg = String.Format("alert('Approved successfully but  total Approval amount is greater than your approval limit ,this Requisition is now being sent to your supirior for his approval.'); RefreshPendingDetails();window.close();");
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg16", msg, true);
                        }
                        else if (ApproverCount > 1)
                        {
                            BLL_PURC_Common.INS_Remarks(Document_Code, Convert.ToInt32(User), txtComment.Text.Trim(), 303);
                            String msg1 = String.Format("alert('Approved successfully but  total Approval amount is greater than your approval limit ,this Requisition is now being sent to your supirior for his approval ');");
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg1, true);
                            ucApprovalUser1.ReqsnCode = Requisitioncode;


                            ucApprovalUser1.FillUser();
                            dvSendForApproval.Visible = true;
                        }
                        else if (ApproverCount == 0)
                        {
                            BLL_PURC_Common.INS_Remarks(Document_Code, Convert.ToInt32(User), txtComment.Text.Trim(), 303);
                            String msg1 = String.Format("alert('Total Approval amount is greater than your approval limit and no approver found for the amount " + Supp_Total_Amount + " . Please contact your manager.' );");
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgCt0", msg1, true);
                        }
                        String msgmoda12l = String.Format("hideModal('divApprove');");
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodalhide", msgmoda12l, true);
                    }
                    else
                    {
                        //btnRequestAmount.Visible = true;
                        String msg1 = String.Format("alert('C.Total Approval amount is greater than Budget limit,Please request for increase Budget limit.');");
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", msg1, true);
                        String msgmodal = String.Format("showModal('divApprove');");
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msgonFinalmodal", msgmodal, true);
                    }
                }
            }



            //divApprove.Visible = false;
            return;
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }