Пример #1
0
        private void RepaymentOpen_Click(object sender, RoutedEventArgs e)
        {
            IList <Request> request = _requestBusinessComponent.GetByStatus(RequestStatus.CreditProvided);

            foreach (var req in request)
            {
                ContractNoCreditType cnct = (ContractNoCreditType)RepaymentListView.SelectedItem;
                if ((req.Client.PassportNo == RepaymentPassportNo.Text) && (Convert.ToInt32(cnct.ContractNO) == req.Credit.CreditId)) // CreditId==ContrqctNo
                {
                    if (RepaymentListView.SelectedItem == null)
                    {
                        MessageBox.Show("Choose ContractNo, please.");
                    }
                    else
                    {
                        var debt = this.CountUpNewDebt();
                        RepaymentDebt.Text = debt.ToString("N2");                         //высчитываем долг
                        RepaymentName.Text = req.Client.Name + " " + req.Client.LastName; // + " " + req.Client.Patronymic;
                        //  RepaymentDebt.Text = // req.Credit.PaidForFine.ToString();
                        var monthLeft     = 0;
                        var creditEndDate = req.Credit.StartDate.AddDays(req.CreditType.TimeMonths * 30);
                        if (creditEndDate > DateTime.Now)
                        {
                            monthLeft = (req.Credit.StartDate.AddDays(req.CreditType.TimeMonths * 30) - DateTime.Now).Days / 30 + 1;
                        }

                        RepaymentToRepayTheLoan.Text = (monthLeft * req.Credit.AmountOfPaymentPerMonth + debt).ToString("N2"); /*req.Credit.AmountOfPaymentPerMonth * ( req.CreditType.TimeMonths  )*//*+ req.Credit.PaidForFine*/
                    }
                }
            }
        }
Пример #2
0
        private decimal CountUpNewDebt()
        {
            ContractNoCreditType cnct = (ContractNoCreditType)RepaymentListView.SelectedValue;
            Credit credit             =
                _creditBusinessComponent.GetAll()
                .FirstOrDefault(x => x.CreditId == Convert.ToInt32(cnct.ContractNO));

            decimal debt = 0;

            if (DateTime.Now > credit.CountFineFromThisDate)
            {
                var daysDiff = (DateTime.Now - credit.CountFineFromThisDate).Days;
                debt += credit.AmountToCountFineFromForFirstDelayedMonth + credit.AmountToCountFineFromForFirstDelayedMonth * daysDiff / 360 * credit.CreditType.FinePercent / 100;
                //int fullMonths = (DateTime.Now - credit.CountFineFromThisDate).Days / 30;
                daysDiff -= 30;
                while (daysDiff > 0)
                {
                    debt     += credit.AmountOfPaymentPerMonth + credit.AmountOfPaymentPerMonth * daysDiff / 360 * credit.CreditType.FinePercent / 100;
                    daysDiff -= 30;
                }
                debt -= credit.PaidForFine;
            }

            return(debt);
        }
Пример #3
0
        private decimal CountUpFine()
        {
            ContractNoCreditType cnct = (ContractNoCreditType)RepaymentListView.SelectedValue;
            Credit credit             =
                _creditBusinessComponent.GetAll()
                .FirstOrDefault(x => x.CreditId == Convert.ToInt32(cnct.ContractNO));

            return(CountUpFine(credit));
        }
Пример #4
0
        private void RepaymentSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (Validate(false, true, false, false))
            {
                if (decimal.Parse(RepaymentToPay.Text) > decimal.Parse(RepaymentToRepayTheLoan.Text))
                {
                    MessageBox.Show("Cannot pay more, than " + RepaymentToRepayTheLoan.Text);
                }
                else
                {
                    MessageBoxResult messageBoxResult = MessageBox.Show(
                        "Are you sure?",
                        "Accept Confirmation",
                        MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        ContractNoCreditType cnct = (ContractNoCreditType)RepaymentListView.SelectedValue;
                        Client client             =
                            _clientBusinessComponent.GetAll()
                            .Where(x => x.PassportNo == RepaymentPassportNo.Text)
                            .FirstOrDefault();
                        Credit credit =
                            _creditBusinessComponent.GetAll()
                            .Where(x => x.CreditId == Convert.ToInt32(cnct.ContractNO))
                            .FirstOrDefault();
                        var paymentAmount = Convert.ToDecimal(RepaymentToPay.Text);

                        var fine = this.CountUpFine();
                        if (paymentAmount < fine) // хватило только на проценты
                        {
                            credit.PaidForFine += paymentAmount;
                        }
                        else
                        {
                            if (Math.Abs(paymentAmount - decimal.Parse(RepaymentToRepayTheLoan.Text)) >= 0.01m)
                            {
                                var paymentLeft = paymentAmount - fine;
                                //уменьшаюощаяся сумма по которой будем смотреть насколько далеко можно отодвинуть дату/сумму нового долга
                                credit.PaidForFine = 0;

                                if (paymentLeft < credit.AmountToCountFineFromForFirstDelayedMonth)
                                //хватило только на умиеньшение суммы с которой идет процент запервый месяц просрочки
                                {
                                    credit.AmountToCountFineFromForFirstDelayedMonth -= paymentLeft;
                                }
                                else
                                {
                                    paymentLeft -= credit.AmountToCountFineFromForFirstDelayedMonth;
                                    credit.CountFineFromThisDate = credit.CountFineFromThisDate.AddDays(30);

                                    while (paymentLeft >= credit.AmountOfPaymentPerMonth)
                                    {
                                        paymentLeft -= credit.AmountOfPaymentPerMonth;
                                        credit.CountFineFromThisDate = credit.CountFineFromThisDate.AddDays(30);
                                    }
                                    credit.AmountToCountFineFromForFirstDelayedMonth = credit.AmountOfPaymentPerMonth
                                                                                       - paymentLeft;
                                }
                                credit.PaidForFine = this.CountUpFine(credit);
                            }
                            else
                            {
                                credit.IsRepaid = true;
                            }
                        }
                        credit.AllreadyPaid += paymentAmount;

                        _paymentBusinessComponent.Add(
                            _operatorId,
                            client.Requests.Where(
                                x =>
                                x.Status == RequestStatus.CreditProvided &&
                                x.Credit.CreditId == Convert.ToInt32(cnct.ContractNO))
                            .FirstOrDefault()
                            .Credit.CreditId,
                            paymentAmount,
                            DateTime.Now);


                        _creditBusinessComponent.Update(credit);
                        _creditBusinessComponent = _ninjectKernel.Get <ICreditBusinessComponent>();


                        // if not re-created will fail on 2nd update
                        TabRepaymentClear(true);
                    }
                }
            }
        }