示例#1
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();
    }
示例#2
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);
    }