Exemple #1
0
 private void SendRequest_Click(object sender, RoutedEventArgs e)
 {
     if (Validate())
     {
         CreditType ct          = _creditTypeBusinessComponent.GetAllActiveCreditTypes().Where(x => x.Name == CreditCTypeBox.SelectedValue.ToString()).FirstOrDefault();
         bool       MoreThanMAX = ct.MaxAmount < Convert.ToInt32(CreditAmount.Text);
         bool       LessThanMIN = ct.MinAmount > Convert.ToInt32(CreditAmount.Text);
         if (Validate() && !MoreThanMAX && !LessThanMIN)
         {
             MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure?", "Accept Confirmation", MessageBoxButton.YesNo);
             if (messageBoxResult == MessageBoxResult.Yes)
             {
                 int        _clientId = _clientBusinessComponent.GetAll().Where(x => x.UserId == _userId).FirstOrDefault().ClientId;
                 CreditType ctype     = _creditTypeBusinessComponent.GetAllActiveCreditTypes().Where(x => x.Name == CreditCTypeBox.SelectedValue.ToString()).FirstOrDefault();
                 _requestBusinessComponent.Add(_clientId, null, null, ctype.CreditTypeId, Entities.Enums.RequestStatus.Created,
                                               Convert.ToDecimal(CreditAmount.Text), Convert.ToDecimal(CreditSalary.Text), "");
             }
             ClearRequestListView();
             FillRequestListView();
         }
         string error = "";
         if (LessThanMIN)
         {
             error += "Amount shold be more than " + ct.MinAmount + Environment.NewLine;
         }
         if (MoreThanMAX)
         {
             error += "Amount shold be less than " + ct.MaxAmount + Environment.NewLine;
         }
         if (error != "")
         {
             MessageBox.Show(error);
         }
     }
 }
Exemple #2
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);
                    }
                }
            }
        }