Example #1
0
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string policyNumber       = tbPolicyNumber.Text;
        int    insuranceCompanyID = int.Parse(ddlInsuranceCompany.SelectedValue);

        try {
            PolicyItem pi = PolicyItem.GetByNumberAndInsuranceCompany(policyNumber, insuranceCompanyID);

            if (pi != null)
            {
                UpdateTextBoxes(pi);
                lblFeedback.Text = string.Empty;
                GridViewRates.DataBind();
                btnGenerate.Enabled = true;
            }
            else
            {
                lblFeedback.Text = "Не е пронајдена полиса!";
            }
            odsPaidPayments.SelectParameters.Clear();
            odsPaidPayments.SelectParameters.Add("policyItemID", pi.ID.ToString());
            GridViewPayments.DataBind();
        } catch (Exception ex) {
            pnlInsurancecSubType.Visible = true;
            ddlInsuranceSubTypes.DataBind();
            lblFeedback.Text    = "Изберете полиса!";
            btnGenerate.Enabled = false;
            btnInsert.Enabled   = false;
            // GridViewRates.DataBind();
            // GridViewPayments.DataBind();
        }
    }
Example #2
0
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string factureNumber = tbFactureNumber.Text;

        try {
            Broker.DataAccess.Facture f = Broker.DataAccess.Facture.GetByNumber(factureNumber);

            if (f != null)
            {
                UpdateTextBoxes(f);
                lblFeedback.Text = string.Empty;
                gvFactureItemsPreview.DataBind();
                btnGenerate.Enabled     = true;
                tbInsuranceCompany.Text = f.InsuranceCompany.ShortName;
            }
            else
            {
                lblFeedback.Text = "Не е пронајдена фактура!";
            }
            GridViewPayments.DataBind();
        } catch (Exception ex) {
            lblFeedback.Text    = "Изберете фактура!";
            btnGenerate.Enabled = false;
            btnInsert.Enabled   = false;
        }
    }
Example #3
0
    protected void ddlInsuranceSubTypes_SelectedIndexChanged(object sender, EventArgs e)
    {
        odsRates.SelectParameters.Clear();
        odsRates.TypeName           = "Broker.DataAccess.Rate";
        odsRates.DataObjectTypeName = "Broker.DataAccess.Rate";
        odsRates.SelectMethod       = "GetByPolicyNumberAndInsuranceSubTypeIDAndInsuranceCompanyID";
        odsRates.SelectParameters.Add("policyNumber", tbPolicyNumber.Text);
        odsRates.SelectParameters.Add("insuranceSubTypeID", Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue).ToString());
        odsRates.SelectParameters.Add("insuranceCompanyID", Convert.ToInt32(ddlInsuranceCompany.SelectedValue).ToString());
        GridViewRates.DataBind();
        PolicyItem pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), int.Parse(ddlInsuranceCompany.SelectedValue));

        odsPaidPayments.SelectParameters.Clear();
        odsPaidPayments.SelectParameters.Add("policyItemID", pi.ID.ToString());
        GridViewPayments.DataBind();
        UpdateTextBoxes(pi);
    }
 protected void GridViewPaidBills_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Select_Bill")
     {
         long Bill_ID = Convert.ToInt64(((LinkButton)e.CommandSource).Text);
         // select bill info
         Bill bill = new Bill();
         bill.Bill_ID = Bill_ID;
         double Cost, Paid_amount;
         bill               = bill.Get_Bill_Info(out Cost, out Paid_amount);
         lblBill_ID.Text    = Bill_ID.ToString();
         lblBillDate.Text   = bill.Bill_Date.ToShortDateString();
         lblClientName.Text = bill.Client_Name;
         lblBillCost.Text   = Cost.ToString();
         if (bill.Discount == 0)
         {
             lblDiscountValue.Visible = false;
             lblDiscount.Visible      = false;
         }
         else
         {
             lblDiscountValue.Text = bill.Discount.ToString();
         }
         lblPaid_Value.Text          = Paid_amount.ToString();
         lblAdditionalCostValue.Text = bill.AdditionalCost.ToString();
         lblAdditionalcostNotes.Text = bill.AdditionalCostNotes;
         lblRest.Text = (Cost + bill.AdditionalCost - Paid_amount - bill.Discount) >= 0 ? (Cost + bill.AdditionalCost - Paid_amount - bill.Discount).ToString() :
                        (-(Cost + bill.AdditionalCost - Paid_amount - bill.Discount)).ToString() + " " + "فرق تكلفه للعميل";
         // select bill items
         ViewState["Bill_ID"] = Bill_ID;
         BindBill(Bill_ID);
         GridViewPayments.DataSource = Bill_Payments.Get_Bill_Payments(Bill_ID);
         GridViewPayments.DataBind();
         PanelBill.Visible  = true;
         PanelBills.Visible = false;
     }
 }
 protected void ImageButtonSearch_Click(object sender, ImageClickEventArgs e)
 {
     PanelBill.Visible = false;
     if (TextBoxSearch.Visible)
     {
         Bill bill = new Bill();
         bill.Client_Name = TextBoxSearch.Text;
         if (string.IsNullOrEmpty(TextBoxSearch.Text) || !bill.IsExistsBill())
         {
             PanelBills.Visible        = false;
             PanelErrorMessage.Visible = true;
         }
         else
         {
             PanelBills.Visible          = true;
             PanelErrorMessage.Visible   = false;
             PanelPaidBills.Visible      = true;
             PanelUnPaidBills.Visible    = false;
             lnkBtnPaidBills.ForeColor   = System.Drawing.Color.White;
             lnkBtnUnpaidBills.ForeColor = System.Drawing.Color.Black;
             GridViewPaidBills.PageIndex = 0;
         }
     }
     else // search by Bill_ID
     {
         Bill bill = new Bill();
         bill.Bill_ID = txtBill_ID.Text != "" ? Convert.ToInt64(txtBill_ID.Text) : 0;
         if (string.IsNullOrEmpty(txtBill_ID.Text) || !bill.IsExistsBillWithID())
         {
             PanelBills.Visible        = false;
             PanelErrorMessage.Visible = true;
         }
         else
         {
             PanelErrorMessage.Visible = false;
             PanelBill.Visible         = true;
             double Cost, Paid_amount;
             bill               = bill.Get_Bill_Info(out Cost, out Paid_amount);
             lblBill_ID.Text    = txtBill_ID.Text;
             lblBillDate.Text   = bill.Bill_Date.ToShortDateString();
             lblClientName.Text = bill.Client_Name;
             lblBillCost.Text   = Cost.ToString();
             if (bill.Discount == 0)
             {
                 lblDiscountValue.Visible = false;
                 lblDiscount.Visible      = false;
             }
             else
             {
                 lblDiscountValue.Text = bill.Discount.ToString();
             }
             lblPaid_Value.Text          = Paid_amount.ToString();
             lblAdditionalCostValue.Text = bill.AdditionalCost.ToString();
             lblAdditionalcostNotes.Text = bill.AdditionalCostNotes;
             lblRest.Text = (Cost + bill.AdditionalCost - Paid_amount - bill.Discount) >= 0 ? (Cost + bill.AdditionalCost - Paid_amount - bill.Discount).ToString() :
                            (-(Cost + bill.AdditionalCost - Paid_amount - bill.Discount)).ToString() + " " + "فرق تكلفه للعميل";
             // select bill items
             ViewState["Bill_ID"] = txtBill_ID.Text;
             BindBill(Convert.ToInt64(txtBill_ID.Text));
             GridViewPayments.DataSource = Bill_Payments.Get_Bill_Payments(Convert.ToInt64(txtBill_ID.Text));
             GridViewPayments.DataBind();
         }
     }
 }
Example #6
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        DateTime       inputDate = Convert.ToDateTime(tbDateOfPayment.Text);
        PolicyItem     pi;
        List <Payment> newPayments = new List <Payment>();

        if (ddlInsuranceSubTypes.Items.Count > 0)
        {
            pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), int.Parse(ddlInsuranceCompany.SelectedValue));
        }
        else
        {
            pi = PolicyItem.GetByNumber(tbPolicyNumber.Text, int.Parse(ddlInsuranceCompany.SelectedValue));
        }
        if (inputDate.Date > DateTime.Today)
        {
            lblFeedback.Text = "Не е можно внесување на датуми поголеми од денешниот";
        }
        else
        {
            lblFeedback.Text = string.Empty;
            List <Payment> listPayments = Payment.GetByPolicyItemID(pi.ID);
            newPayments.AddRange(listPayments);
            decimal paymentTotalValue = 0;
            foreach (Payment payment in listPayments)
            {
                paymentTotalValue += payment.Value;
            }
            if (Convert.ToDecimal(tbValueOfPayment.Text) > (pi.PremiumValue - paymentTotalValue))
            {
                lblFeedback.Text = "Поголем износ од преостанатиот износ за плаќање";
            }
            else
            {
                lblFeedback.Text = string.Empty;
                decimal valueFromClient          = Convert.ToDecimal(tbValueOfPayment.Text);
                Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue));
                Rate currentRate = Rate.GetCurrentRateForPayment(pi.ID);
                while (valueFromClient > 0)
                {
                    Payment newPayment = new Payment();
                    newPayment.Date           = Convert.ToDateTime(tbDateOfPayment.Text);
                    newPayment.RateID         = currentRate.ID;
                    newPayment.Rate           = currentRate;
                    newPayment.IsCashReported = false;
                    newPayment.PaymentTypeID  = pt.ID;
                    if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD)
                    {
                        newPayment.BankCreditCardID = BankCreditCard.GetByBankAndCard(Convert.ToInt32(ddlBank.SelectedValue), Convert.ToInt32(ddlCardTypes.SelectedValue)).ID;
                    }
                    newPayment.UserID   = this.PageUser.ID;
                    newPayment.BranchID = this.PageUser.BranchID;
                    if (tbBankslipNumber.Text.Trim() != string.Empty)
                    {
                        newPayment.BankslipNumber = tbBankslipNumber.Text;
                        newPayment.BankslipBankID = Convert.ToInt32(ddlBankslipBanks.SelectedValue);
                    }
                    if (valueFromClient >= currentRate.Value)
                    {
                        newPayment.Value       = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID);
                        valueFromClient       -= newPayment.Value;
                        currentRate.PaidValue += newPayment.Value;
                        newPayments.Add(newPayment);
                        int currentRateNumber = currentRate.Number;
                        int nextNumber;
                        int maxNumber = Rate.Table.Where(r => r.PolicyItemID == pi.ID).OrderBy(r => r.Number).Select(r => r.Number).ToList().Last();
                        if (currentRateNumber < maxNumber)
                        {
                            nextNumber = ++currentRateNumber;
                        }
                        else
                        {
                            nextNumber = currentRateNumber;
                        }
                        currentRate = Rate.Table.Where(r => r.PolicyItemID == pi.ID && r.Number == nextNumber).SingleOrDefault();
                    }
                    else
                    {
                        if (valueFromClient <= (currentRate.Value - currentRate.PaidValue))
                        {
                            newPayment.Value      = valueFromClient;
                            currentRate.PaidValue = valueFromClient;
                            newPayments.Add(newPayment);
                            break;
                        }
                        else
                        {
                            newPayment.Value      = (currentRate.Value - currentRate.PaidValue);
                            currentRate.PaidValue = currentRate.PaidValue;
                            newPayments.Add(newPayment);
                            valueFromClient -= newPayment.Value;
                            int currentRateNumber = currentRate.Number;
                            int nextNumber;
                            int maxNumber = Rate.Table.Where(r => r.PolicyItemID == pi.ID).OrderBy(r => r.Number).Select(r => r.Number).ToList().Last();
                            if (currentRateNumber < maxNumber)
                            {
                                nextNumber = ++currentRateNumber;
                            }
                            else
                            {
                                nextNumber = currentRateNumber;
                            }
                            currentRate = Rate.Table.Where(r => r.PolicyItemID == pi.ID && r.Number == nextNumber).SingleOrDefault();
                        }
                    }
                }
                btnInsert.Enabled = true;
            }
        }
        odsPaidPayments.SelectParameters.Clear();
        GridViewPayments.DataSourceID = null;
        GridViewPayments.DataSource   = newPayments;
        GridViewPayments.DataBind();
    }
Example #7
0
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        DateTime   inputDate          = Convert.ToDateTime(tbDateOfPayment.Text);
        int        insuranceCompanyID = int.Parse(ddlInsuranceCompany.SelectedValue);
        PolicyItem pi;

        if (ddlInsuranceSubTypes.Items.Count > 0)
        {
            pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), insuranceCompanyID);
        }
        else
        {
            pi = PolicyItem.GetByNumber(tbPolicyNumber.Text, insuranceCompanyID);
        }
        if (inputDate.Date > DateTime.Today)
        {
            lblFeedback.Text = "Не е можно внесување на датуми поголеми од денешниот";
        }
        else
        {
            List <Payment> listPayments      = Payment.GetByPolicyItemID(pi.ID);
            decimal        paymentTotalValue = 0;
            foreach (Payment payment in listPayments)
            {
                paymentTotalValue += payment.Value;
            }
            if (Convert.ToDecimal(tbValueOfPayment.Text) > (pi.PremiumValue - paymentTotalValue))
            {
                lblFeedback.Text = "Поголем износ од преостанатиот износ за плаќање";
            }
            else
            {
                decimal valueFromClient = Convert.ToDecimal(tbValueOfPayment.Text);
                while (valueFromClient > 0)
                {
                    Rate    currentRate = Rate.GetCurrentRateForPayment(pi.ID);
                    Payment newPayment  = new Payment();
                    newPayment.Date           = Convert.ToDateTime(tbDateOfPayment.Text);
                    newPayment.RateID         = currentRate.ID;
                    newPayment.IsCashReported = false;
                    Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue));
                    newPayment.PaymentTypeID = pt.ID;
                    if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD)
                    {
                        newPayment.BankCreditCardID = BankCreditCard.GetByBankAndCard(Convert.ToInt32(ddlBank.SelectedValue), Convert.ToInt32(ddlCardTypes.SelectedValue)).ID;
                    }
                    newPayment.UserID   = this.PageUser.ID;
                    newPayment.BranchID = this.PageUser.BranchID;
                    if (tbBankslipNumber.Text.Trim() != string.Empty)
                    {
                        newPayment.BankslipNumber = tbBankslipNumber.Text;
                        newPayment.BankslipBankID = Convert.ToInt32(ddlBankslipBanks.SelectedValue);
                    }
                    if (valueFromClient >= currentRate.Value)
                    {
                        newPayment.Value = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID);
                        newPayment.Insert();
                        decimal basicValue = newPayment.Value;
                        decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                        List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                        foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                        {
                            PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                            if (pei != null)
                            {
                                decimal peiValue = 0;
                                decimal.TryParse(pei.Value, out peiValue);
                                basicValue -= k * peiValue;
                                if (peiValue > 0)
                                {
                                    PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                    ppist.PaymentID          = newPayment.ID;
                                    ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                    ppist.PaidValue          = k * peiValue;
                                    ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                    ppist.Insert();
                                }
                            }
                        }
                        if (basicValue > 0)
                        {
                            PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                            ppist.PaymentID          = newPayment.ID;
                            ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                            ppist.PaidValue          = basicValue;
                            ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                            ppist.Insert();
                        }
                        valueFromClient       -= newPayment.Value;
                        currentRate.PaidValue += newPayment.Value;
                        Rate.Table.Context.SubmitChanges();
                    }
                    else
                    {
                        if (valueFromClient <= (currentRate.Value - currentRate.PaidValue))
                        {
                            newPayment.Value = valueFromClient;
                            newPayment.Insert();
                            decimal basicValue = newPayment.Value;
                            decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                            List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                            foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                            {
                                PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                                if (pei != null)
                                {
                                    decimal peiValue = 0;
                                    decimal.TryParse(pei.Value, out peiValue);
                                    basicValue -= k * peiValue;
                                    if (peiValue > 0)
                                    {
                                        PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                        ppist.PaymentID          = newPayment.ID;
                                        ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                        ppist.PaidValue          = k * peiValue;
                                        ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                        ppist.Insert();
                                    }
                                }
                            }
                            if (basicValue > 0)
                            {
                                PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                ppist.PaymentID          = newPayment.ID;
                                ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                                ppist.PaidValue          = basicValue;
                                ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                ppist.Insert();
                            }
                            currentRate.PaidValue += valueFromClient;
                            Rate.Table.Context.SubmitChanges();
                            break;
                        }
                        else
                        {
                            newPayment.Value = (currentRate.Value - currentRate.PaidValue);
                            newPayment.Insert();
                            decimal basicValue = newPayment.Value;
                            decimal k          = basicValue / newPayment.Rate.PolicyItem.PremiumValue;
                            List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList();
                            foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST)
                            {
                                PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID);
                                if (pei != null)
                                {
                                    decimal peiValue = 0;
                                    decimal.TryParse(pei.Value, out peiValue);
                                    basicValue -= k * peiValue;
                                    if (peiValue > 0)
                                    {
                                        PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                        ppist.PaymentID          = newPayment.ID;
                                        ppist.InsuranceSubTypeID = c.InsuranceSubTypeID;
                                        ppist.PaidValue          = k * peiValue;
                                        ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                        ppist.Insert();
                                    }
                                }
                            }

                            if (basicValue > 0)
                            {
                                PaymentsPerInsSubType ppist = new PaymentsPerInsSubType();
                                ppist.PaymentID          = newPayment.ID;
                                ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID;
                                ppist.PaidValue          = basicValue;
                                ppist.BrokerageValue     = ppist.PaidValue * pi.BrokeragePercentage / 100;
                                ppist.Insert();
                            }
                            //currentRate.PaidValue += valueFromClient;
                            //Rate.Table.Context.SubmitChanges();
                            currentRate.PaidValue += newPayment.Value;
                            Rate.Table.Context.SubmitChanges();
                            valueFromClient -= newPayment.Value;
                        }
                    }
                }
                Broker.DataAccess.Facture.UpdatePaidStatusForFacture(pi.ID);
            }
        }
        GridViewPayments.DataSource   = null;
        GridViewPayments.DataSourceID = odsPaidPayments.ID;
        odsPaidPayments.SelectParameters.Clear();
        odsPaidPayments.SelectParameters.Add("policyItemID", pi.ID.ToString());
        GridViewPayments.DataBind();

        GridViewRates.DataSource   = null;
        GridViewRates.DataSourceID = odsRates.ID;

        odsRates.SelectParameters.Clear();
        odsRates.TypeName           = "Broker.DataAccess.Rate";
        odsRates.DataObjectTypeName = "Broker.DataAccess.Rate";
        odsRates.SelectMethod       = "GetByPolicyNumberAndInsuranceSubTypeIDAndInsuranceCompanyID";
        odsRates.SelectParameters.Add("policyNumber", tbPolicyNumber.Text);
        odsRates.SelectParameters.Add("insuranceSubTypeID", pi.InsuranceSubType.ID.ToString());
        odsRates.SelectParameters.Add("insuranceCompanyID", ddlInsuranceCompany.SelectedValue);
        //odsRates.SelectMethod = "Broker.DataAccess.PolicyItem.GetByNumberAndInsuranceSubType";
        GridViewRates.DataBind();
        UpdateTextBoxes(pi);
    }
Example #8
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        string   factureNumber = tbFactureNumber.Text;
        DateTime paidDate      = DateTime.Now;

        DateTime.TryParse(tbDateOfPayment.Text, out paidDate);

        try {
            Broker.DataAccess.Facture f = Broker.DataAccess.Facture.GetByNumber(factureNumber);
            if (f != null)
            {
                decimal newPaymentValue = 0;
                decimal.TryParse(tbValueOfPayment.Text, out newPaymentValue);
                if (newPaymentValue > Convert.ToDecimal(tbFactureForPaidValue.Text))
                {
                    RegisterStartupScript("myAlert", "<script>alert('ИЗНОСОТ КОЈ ГО ВНЕСОВТЕ ЗА ПЛАЌАЊЕ Е ПОГОЛЕМ ОД ПРЕОСТАНАТИОТ ДОЛГ!')</script>");
                    return;
                }
                decimal proValue = RateController.Scale5(newPaymentValue / (decimal)f.FactureItems.Count);
                List <FactureCollectedPaidValue> list = FactureCollectedPaidValue.GetGroupedByFactureID(f.ID);
                if (list.Count > 0)
                {
                    int restColumn = f.FactureItems.Count;
                    foreach (FactureCollectedPaidValue fcpv in list)
                    {
                        if (FactureCollectedPaidValue.GetPaidValueForFactureItem(fcpv.FactureItemID) == fcpv.FactureItem.BrokerageValue)
                        {
                            restColumn--;
                        }
                        proValue      = RateController.Scale5(newPaymentValue / (decimal)restColumn);
                        fcpv.PaidDate = paidDate;
                        if ((fcpv.PaidValue + proValue) > fcpv.FactureItem.BrokerageValue)
                        {
                            fcpv.PaidValue = fcpv.FactureItem.BrokerageValue;
                        }
                        else
                        {
                            fcpv.PaidValue += proValue;
                        }
                    }
                }
                else
                {
                    decimal rest = newPaymentValue;
                    int     i    = 0;
                    foreach (FactureItem fi in f.FactureItems)
                    {
                        proValue = RateController.Scale5(rest / (decimal)(f.FactureItems.Count - i));
                        FactureCollectedPaidValue fcpv = new FactureCollectedPaidValue();
                        fcpv.FactureItemID = fi.ID;
                        fcpv.FactureItem   = fi;
                        fcpv.PaidDate      = paidDate;
                        if (fi.BrokerageValue > (proValue + FactureCollectedPaidValue.GetPaidValueForFactureItem(fi.ID)))
                        {
                            fcpv.PaidValue += proValue;
                        }
                        else
                        {
                            fcpv.PaidValue = fi.BrokerageValue;
                        }
                        rest -= fcpv.PaidValue;
                        list.Add(fcpv);
                        i++;
                    }
                }
                GridViewPayments.DataSourceID = null;
                GridViewPayments.DataSource   = list;
                GridViewPayments.DataBind();
                btnInsert.Enabled = true;
            }
            else
            {
                lblFeedback.Text = "Не е пронајдена фактура!";
            }
        } catch (Exception ex) {
            lblFeedback.Text = "Грешка!";
        }
    }