protected void Button_Create_Pmnt_Click(object sender, EventArgs e)
        {
            Dictionary <String, String> existingTranDict = (Dictionary <String, String>)Session[SessionFactory.ALL_INVOICE_PAYMENT_GRID_EXISTING_TRAN_NO];

            if (existingTranDict.ContainsKey(TextBox_Tran_No.Text.Trim()))
            {
                Label_Pmnt_Create_Stat.Visible   = true;
                Label_Pmnt_Create_Stat.Text      = "Transaction Number already exists.";
                Label_Pmnt_Create_Stat.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                BackEndObjects.Payment pmntObj = new BackEndObjects.Payment();

                String rfId  = Request.QueryString.GetValues("rfId")[0];
                String invId = Request.QueryString.GetValues("invId")[0];

                pmntObj.setPaymentId(new BackEndObjects.Id().getNewId(BackEndObjects.Id.ID_TYPE_PMNT_ID_STRING));
                pmntObj.setClearingStat(DropDownList_Clearing_Stat.SelectedValue);
                pmntObj.setPmntDate(TextBox_Pmnt_Date.Text);
                pmntObj.setEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                pmntObj.setInvoiceId(invId);
                pmntObj.setPaymentType(DropDownList_Pmnt_Type.SelectedValue);
                pmntObj.setRFQId(rfId);
                pmntObj.setTranNo(TextBox_Tran_No.Text);
                pmntObj.setUsrId(User.Identity.Name);
                pmntObj.setAmount(float.Parse(TextBox_Tran_Amnt.Text));
                pmntObj.setClearingStatNote(TextBox_Clearing_Stat_Note.Text);

                try
                {
                    BackEndObjects.Payment.insertPaymentDetailsDB(pmntObj);
                    Label_Pmnt_Create_Stat.Visible   = true;
                    Label_Pmnt_Create_Stat.ForeColor = System.Drawing.Color.Green;
                    Label_Pmnt_Create_Stat.Text      = "Payment Details Inserted Successfully";

                    DataTable dt = (DataTable)Session[SessionFactory.ALL_INVOICE_PAYMENT_GRID];
                    dt.Rows.Add();
                    int rowIndex = dt.Rows.Count - 1;
                    dt.Rows[rowIndex]["Pmnt_Id"]            = pmntObj.getPaymentId();
                    dt.Rows[rowIndex]["Tran_No"]            = pmntObj.getTranNo();
                    dt.Rows[rowIndex]["Pmnt_Type"]          = pmntObj.getPaymentType();
                    dt.Rows[rowIndex]["Amount"]             = pmntObj.getAmount();
                    dt.Rows[rowIndex]["Clearing_Stat"]      = pmntObj.getClearingStat();
                    dt.Rows[rowIndex]["Clearing_Stat_Note"] = pmntObj.getClearingStatNote();
                    dt.Rows[rowIndex]["Pmnt_Date"]          = pmntObj.getPmntDate();

                    GridView_Invoice_Pmnt.DataSource = dt;
                    GridView_Invoice_Pmnt.DataBind();
                    Session[SessionFactory.ALL_INVOICE_PAYMENT_GRID] = dt;

                    if (pmntObj.getClearingStat().Equals(BackEndObjects.Payment.PAYMENT_CLEARING_STAT_CLEAR))
                    {
                        Label_Total_Cleared.Text = (float.Parse(Label_Total_Cleared.Text) + pmntObj.getAmount()).ToString();
                    }
                    if (pmntObj.getClearingStat().Equals(BackEndObjects.Payment.PAYMENT_CLEARING_STAT_PENDING))
                    {
                        Label_Total_Uncleared.Text = (float.Parse(Label_Total_Uncleared.Text) + pmntObj.getAmount()).ToString();
                    }

                    Label_Total_Pmnt_Made.Text = (float.Parse(Label_Total_Pmnt_Made.Text) + pmntObj.getAmount()).ToString();
                    //fillPmntGrid();

                    existingTranDict.Add(pmntObj.getTranNo(), pmntObj.getTranNo());
                    Session[SessionFactory.ALL_INVOICE_PAYMENT_GRID_EXISTING_TRAN_NO] = existingTranDict;
                }
                catch (Exception ex)
                {
                    Label_Pmnt_Create_Stat.Visible   = true;
                    Label_Pmnt_Create_Stat.ForeColor = System.Drawing.Color.Red;
                    Label_Pmnt_Create_Stat.Text      = "Payment Details Creation Failed";
                }
            }
        }
        protected void fillOutoingInvGrid(ArrayList invList)
        {
            String[] contactEntId = Request.QueryString.GetValues("contactId");

            if (invList == null || invList.Count == 0)
            {
                invList = BackEndObjects.Invoice.getAllInvoicesbyRespEntId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
            }

            DataTable dt = new DataTable();

            dt.Columns.Add("rfqId");
            dt.Columns.Add("InvId");
            dt.Columns.Add("InvNo");
            dt.Columns.Add("totalAmnt");
            dt.Columns.Add("InvDate");
            dt.Columns.Add("pmntStat");
            dt.Columns.Add("totalPending");

            DateUtility dU = new DateUtility();

            int counter = 0;

            for (int i = 0; i < invList.Count; i++)
            {
                BackEndObjects.Invoice invObj = (BackEndObjects.Invoice)invList[i];

                //Filter out invoices whicha re meant for this contact only
                BackEndObjects.RFQDetails rfqObj = BackEndObjects.RFQDetails.getRFQDetailsbyIdDB(invObj.getRFQId());
                if (rfqObj != null && rfqObj.getEntityId() != null && rfqObj.getEntityId().Equals(contactEntId[0]))
                {
                    float totalPendingAmnt = 0;
                    float totalClearedAmnt = 0;

                    Dictionary <String, Payment> pmntDict = BackEndObjects.Payment.getPaymentDetailsforInvoiceDB(invObj.getInvoiceId());

                    foreach (KeyValuePair <String, Payment> kvp in pmntDict)
                    {
                        BackEndObjects.Payment pmntObj = kvp.Value;

                        totalClearedAmnt += pmntObj.getClearingStat().Equals(BackEndObjects.Payment.PAYMENT_CLEARING_STAT_CLEAR) ?
                                            pmntObj.getAmount() : 0;
                    }

                    totalPendingAmnt = invObj.getTotalAmount() - totalClearedAmnt;

                    dt.Rows.Add();
                    dt.Rows[counter]["rfqId"]        = invObj.getRFQId();
                    dt.Rows[counter]["InvId"]        = invObj.getInvoiceId();
                    dt.Rows[counter]["InvNo"]        = invObj.getInvoiceNo() != null && !invObj.getInvoiceNo().Equals("") ? invObj.getInvoiceNo() : invObj.getInvoiceId();
                    dt.Rows[counter]["totalAmnt"]    = invObj.getTotalAmount();
                    dt.Rows[counter]["InvDate"]      = dU.getConvertedDate(invObj.getInvoiceDate().Substring(0, invObj.getInvoiceDate().IndexOf(" ")));
                    dt.Rows[counter]["pmntStat"]     = invObj.getPaymentStatus();
                    dt.Rows[counter]["totalPending"] = totalPendingAmnt;

                    counter++;
                }
            }

            GridView_Outgoing_Invoices.Visible    = true;
            GridView_Outgoing_Invoices.DataSource = dt;
            GridView_Outgoing_Invoices.DataBind();
            GridView_Outgoing_Invoices.SelectedIndex = -1;
            Session[SessionFactory.ALL_CONTACT_ALL_DEAL_OUTGOING_INV_GRID]      = dt;
            Session[SessionFactory.ALL_CONTACT_ALL_DEAL_OUTGOING_INV_ARRAYLIST] = invList;
        }