public void RepayAllExpectedInstallments(DateTime date) { var loanIdList = _loanManager.GetLoanIdForRepayment(date); foreach (var id in loanIdList) { var client = ServicesProvider.GetInstance() .GetClientServices() .FindTiersByContractId(id); if (!(from item in client.Savings where item.Product.Code == "default" select item).Any()) continue; var repaymentConfiguration = new RepaymentConfiguration { Loan = SelectLoan(id, true, true, false), Client = client, Saving = (from item in client.Savings where item.Product.Code == "default" select item).First(), KeepExpectedInstallment = !false, Date = date, DisableFees = false, ManualFeesAmount = 0, DisableInterests = false, ManualInterestsAmount = 0, ManualCommission = 0, ProportionPayment = false, IsPending = false }; RepayLoanFromTransitAccount(repaymentConfiguration); } }
public Loan RepayLoanFromTransitAccount(RepaymentConfiguration config) { var currentUser = User.CurrentUser ?? ServicesProvider.GetInstance().GetUserServices().Find(1); var balance = config.Saving.GetBalance().Value; var amount = config.Loan.CalculateOverduePrincipal(config.Date).Value + config.Loan.GetUnpaidInterest(config.Date).Value + config.Loan.GetUnpaidLatePenalties(config.Date); if (amount > balance || !config.KeepExpectedInstallment) amount = balance; if (amount <= 0) return config.Loan; ServicesProvider.GetInstance() .GetSavingServices() .Withdraw(config.Saving, config.Date, amount, "Withdraw for loan repayment " + config.Loan.Code, currentUser, new Teller()); var paymentMethod = ServicesProvider.GetInstance().GetPaymentMethodServices().GetPaymentMethodByName("Savings"); var installment = config.Loan.GetFirstUnpaidInstallment() ?? config.Loan.InstallmentList.First(); return Repay(config.Loan, config.Client, installment.Number, config.Date.Date, amount, config.DisableFees, config.ManualFeesAmount, config.ManualCommission, config.DisableInterests, config.ManualInterestsAmount, config.KeepExpectedInstallment, config.ProportionPayment, paymentMethod, config.Saving.Events.Last().Id.ToString(CultureInfo.InvariantCulture), config.IsPending); }
private void buttonSave_Click(object sender, EventArgs e) { Event lastEvent = _loan.Events.GetLastLoanNonDeletedEvent; var comment = textBoxComment.Text; var pending = checkBoxPending.Visible && checkBoxPending.Checked; if (lastEvent.Date.Date == dtpRepaymentDate.Value.Date) { string message = MultiLanguageStrings.GetString(Ressource.CreditContractRepayForm, "alreadyAnEventForThisDate.Text"); if (lastEvent is RescheduleLoanEvent) message = GetString("AlreadyAnRoleEventForThisDate.Text"); if (lastEvent is LoanDisbursmentEvent || lastEvent is LoanValidationEvent) message = GetString("AlreadyAnLodeEventForThisDate.Text"); DialogResult res = MessageBox.Show(message, "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.No) return; } _date = new DateTime(dtpRepaymentDate.Value.Year, dtpRepaymentDate.Value.Month, dtpRepaymentDate.Value.Day); try { bool isNotPaid = true; if (_date.Date < DateTime.Today.Date) ServicesProvider.GetInstance().GetContractServices().PerformBackDateOperations(); else if (_date.Date > DateTime.Today.Date) ServicesProvider.GetInstance().GetContractServices().PerformFutureDateOperations(); if (ApplicationSettings.GetInstance(User.CurrentUser.Md5).UseMandatorySavingAccount) { ISavingsContract saving; if (!(from item in _client.Savings where item.Product.Code == "default" select item).Any()) { saving = ServicesProvider.GetInstance() .GetSavingServices() .AddAndActivateDefaultSavingAccount(_client); _client.Savings.Add(saving); } else saving = (from item in _client.Savings where item.Product.Code == "default" select item).First(); var savingsMethod = (OSavingsMethods) Enum.Parse(typeof (OSavingsMethods), (cmbPaymentMethod.SelectedIndex == 0) ? "Cash" : "Cheque"); var savingEvent = ServicesProvider .GetInstance() .GetSavingServices() .Deposit(saving, _date, _amount, _loan.Id.ToString(CultureInfo.InvariantCulture), User.CurrentUser, false, savingsMethod, null, Teller.CurrentTeller).FirstOrDefault(); using (var sqlTransaction = DatabaseConnection.GetConnection().BeginTransaction()) { ServicesProvider.GetInstance() .GetContractServices() .CallInterceptor(new Dictionary<string, object> { {"Loan", _loan}, {"Event", savingEvent}, {"SqlTransaction", sqlTransaction} }); sqlTransaction.Commit(); } var repaymentConfiguration = new RepaymentConfiguration() { Client = _client, Date = _date, Saving = saving, DisableFees = _disableFees, DisableInterests = _disableInterests, ManualCommission = _manualCommission, ManualFeesAmount = _manualPenalties, ManualInterestsAmount = _manualInterests, Loan = _loan, KeepExpectedInstallment = _keepExpectedInstallment, ProportionPayment = _doProportionPayment, IsPending = pending }; _loan = ServicesProvider.GetInstance() .GetContractServices() .RepayLoanFromTransitAccount(repaymentConfiguration); } else { if (_disableInterests || _disableFees || !_keepExpectedInstallment) { if (_disableInterests) { _loan = ServicesProvider.GetInstance().GetContractServices().ManualInterestCalculation( _loan, _client, _instalmentNumber, _date, _amount, _disableFees, _manualPenalties, _manualCommission, _disableInterests, _manualInterests, _keepExpectedInstallment, _doProportionPayment, _paymentMethod, comment, pending); isNotPaid = false; } if (_disableFees && isNotPaid) { _loan = ServicesProvider.GetInstance().GetContractServices().ManualFeesCalculation(_loan, _client, _instalmentNumber, _date, _amount, _disableFees, _manualPenalties, _manualCommission, _disableInterests, _manualInterests, _keepExpectedInstallment, _doProportionPayment, _paymentMethod, comment, pending); isNotPaid = false; } if (!_keepExpectedInstallment && isNotPaid) { _loan = ServicesProvider.GetInstance().GetContractServices().ChangeRepaymentType(_loan, _client, _instalmentNumber, _date, _amount, _disableFees, _manualPenalties, _manualCommission, _disableInterests, _manualInterests, _keepExpectedInstallment, _doProportionPayment, _paymentMethod, comment, pending); } } else { _loan = ServicesProvider.GetInstance().GetContractServices().Repay(_loan, _client, _instalmentNumber, _date, _amount, _disableFees, _manualPenalties, _manualCommission, _disableInterests, _manualInterests, _keepExpectedInstallment, _doProportionPayment, _paymentMethod, comment, pending); } } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog(); throw; } }