Ejemplo n.º 1
0
        public void AddLoanDisbursmentEvent()
        {
            EventManager eventManager = (EventManager)container["EventManager"];

            LoanDisbursmentEvent loanDisbursmentEvent = new LoanDisbursmentEvent
                                            {
                                                Id = 10,
                                                User = new User { Id = 1 },
                                                Date = new DateTime(2006, 7, 21),
                                                Amount = 100,
                                            };
            loanDisbursmentEvent.Commissions = new List<LoanEntryFeeEvent>();
            LoanEntryFeeEvent commission = new LoanEntryFeeEvent();
            commission.Fee = 10;
            loanDisbursmentEvent.Commissions.Add(commission);

            PaymentMethod method = new PaymentMethod(1, "Savings", "Savings method", false);
            loanDisbursmentEvent.PaymentMethod = method;

            eventManager.AddLoanEvent(loanDisbursmentEvent, 1);
            Assert.AreNotEqual(0, loanDisbursmentEvent.Id);
        }
Ejemplo n.º 2
0
 private void AddEntryFeeEvent(LoanEntryFeeEvent entryFeeEvent, Loan loan, SqlTransaction transaction)
 {
     var id = _eventManagement.AddLoanEventHead(entryFeeEvent, loan.Id, transaction);
     entryFeeEvent.Id = id;
     _eventManagement.AddLoanEntryFeesEvent(entryFeeEvent, transaction);
 }
Ejemplo n.º 3
0
        public Loan AddTranche(Loan loan, IClient client, ITrancheConfiguration trancheConfiguration, IList<LoanEntryFee> entryFees, PaymentMethod paymentMethod)
        {
            using (var connection = _loanManager.GetConnection())
            using (var transaction = connection.BeginTransaction())
            {
                try
                {
                    CheckTranche(trancheConfiguration.StartDate, loan, trancheConfiguration.Amount);

                    var copyOfLoan = SimulateTranche(loan, trancheConfiguration);
                    var startInstallment =
                        copyOfLoan.InstallmentList
                                  .FindAll(i => i.ExpectedDate <= trancheConfiguration.StartDate)
                                  .LastOrDefault();
                    var trancheEvent = new TrancheEvent
                        {
                            Amount = trancheConfiguration.Amount,
                            ApplyNewInterest = trancheConfiguration.ApplyNewInterestRateToOlb,
                            Maturity = trancheConfiguration.NumberOfInstallments,
                            StartDate = trancheConfiguration.StartDate,
                            Date = trancheConfiguration.StartDate,
                            InterestRate = trancheConfiguration.InterestRate/100,
                            Number = copyOfLoan.GivenTranches.Count,
                            FirstRepaymentDate = trancheConfiguration.PreferredFirstInstallmentDate,
                            GracePeriod = trancheConfiguration.GracePeriod,
                            StartedFromInstallment = startInstallment == null ? 0 : startInstallment.Number,
                            User = _user,
                            PaymentMethod = paymentMethod
                        };

                    trancheEvent.User = _user;

                    //insert into table TrancheEvent
                    _ePs.FireEvent(trancheEvent, copyOfLoan, transaction);
                    copyOfLoan.Events.Add(trancheEvent);

                    CallInterceptor(new Dictionary<string, object>
                    {
                        {"Loan", copyOfLoan},
                        {"Event", trancheEvent},
                        {"SqlTransaction", transaction}
                    });

                    // Add entry fee events
                    foreach (var entryFee in entryFees)
                    {
                        if (entryFee.FeeValue == 0) continue;
                        var entryFeeEvent = new LoanEntryFeeEvent
                        {
                            Fee = entryFee.FeeValue,
                            Code = "LEE" + entryFee.ProductEntryFee.Index,
                            DisbursementEventId = trancheEvent.Id,
                            Cancelable = true,
                            User = User.CurrentUser,
                            Date = trancheEvent.Date
                        };
                        _ePs.FireEvent(entryFeeEvent, copyOfLoan, transaction);
                        copyOfLoan.Events.Add(entryFeeEvent);
                    }

                    var trancheEntryFeeEvent =
                        copyOfLoan.Events.OfType<LoanEntryFeeEvent>()
                                  .First(i => i.DisbursementEventId == trancheEvent.Id);
                    if (trancheEntryFeeEvent != null)
                        CallInterceptor(new Dictionary<string, object>
                        {
                            {"Loan", copyOfLoan},
                            {
                                "Event", new LoanEntryFeeEvent
                                    {
                                        Id = trancheEntryFeeEvent.Id,
                                        Fee = entryFees.Sum(i => i.FeeValue),
                                        Code = "LEE0"
                                    }
                            },
                            {"SqlTransaction", transaction}
                        });

                    ArchiveInstallments(loan, trancheEvent, transaction);

                    //delete all the old installments of the table Installments
                    _instalmentManager.DeleteInstallments(loan.Id, transaction);

                    //insert all the new installments in the table Installments
                    _instalmentManager.AddInstallments(copyOfLoan.InstallmentList, copyOfLoan.Id, transaction);

                    //Activate the contract if it's closed because of new tranch
                    if (copyOfLoan.Closed)
                    {
                        copyOfLoan.ContractStatus = OContractStatus.Active;
                        copyOfLoan.Closed = false;
                        _loanManager.UpdateLoan(copyOfLoan, transaction);
                    }
                    //in the feature might be combine UpdateLoan + UpdateLoanWithinTranche
                    _loanManager.UpdateLoanWithinTranche(
                        trancheConfiguration.InterestRate/100,
                        copyOfLoan.NbOfInstallments,
                        copyOfLoan,
                        transaction);
                    copyOfLoan.GivenTranches.Add(trancheEvent);
                    transaction.Commit();

                    SetClientStatus(copyOfLoan, client);
                    return copyOfLoan;
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 4
0
        public void Select_Added_loanDisbursmentEvent()
        {
            EventManager eventManager = (EventManager)container["EventManager"];

            LoanDisbursmentEvent loanDisbursmentEvent = new LoanDisbursmentEvent
            {
                Id = 100,
                User = new User { Id = 1 },
                Date = new DateTime(2006, 7, 21),
                Amount = 100,
            };
            var commission = new LoanEntryFeeEvent();
            commission.Fee = 10;
            loanDisbursmentEvent.Commissions = new List<LoanEntryFeeEvent>();
            loanDisbursmentEvent.Commissions.Add(commission);

            PaymentMethod method = new PaymentMethod(1, "Savings", "Savings method", false);
            loanDisbursmentEvent.PaymentMethod = method;

            eventManager.AddLoanEvent(loanDisbursmentEvent, 2);
            EventStock eventStock = eventManager.SelectEvents(2);

            foreach (Event e in eventStock.GetEvents())
            {
                if (e is LoanDisbursmentEvent)
                    _AssertLoanDisbursmentEvent(e as LoanDisbursmentEvent, new DateTime(2006, 7, 21), 100, 10);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method to Disburse money for the contract
        /// </summary>
        /// <param name="pDisburseDate">Date of disbursment</param>
        /// <param name="pDisableFees">when true, entry commission paid for this contract are set to 0</param>
        /// <param name="pAlignInstallmentsDatesOnRealDisbursmentDate"></param>
        /// <returns>A LoanDisburment event if correct date of disbursment. /!\Becarful, loan must be non debursed </returns>
        public LoanDisbursmentEvent Disburse(DateTime pDisburseDate, bool pAlignInstallmentsDatesOnRealDisbursmentDate, bool pDisableFees)
        {
            LoanDisbursmentEvent e = _generalSettings.AccountingProcesses == OAccountingProcesses.Cash
                                         ? GenerateEvents.Cash.GenerateLoanDisbursmentEvent(this, _generalSettings,
                                                                                            pDisburseDate,
                                                                                            pAlignInstallmentsDatesOnRealDisbursmentDate,
                                                                                            pDisableFees, _user)
                                         : GenerateEvents.Accrual.GenerateLoanDisbursmentEvent(this, _generalSettings,
                                                                                               pDisburseDate,
                                                                                               pAlignInstallmentsDatesOnRealDisbursmentDate,
                                                                                               pDisableFees, _user);
            e.Interest = GetTotalInterestDue();
            if (!pDisableFees)
            {
                List<OCurrency> entryFees = GetEntryFees();
                if (entryFees != null)
                {
                    e.Commissions = new List<LoanEntryFeeEvent>();
                    for (int i=0; i<entryFees.Count; i++)
                    {
                        LoanEntryFeeEvent loanEntryFeeEvent = new LoanEntryFeeEvent
                                                                  {
                                                                      Fee =
                                                                          Product.Currency.UseCents
                                                                              ? Math.Round(entryFees[i].Value, 2)
                                                                              : Math.Round(entryFees[i].Value,
                                                                                           MidpointRounding.AwayFromZero),
                                                                      Code = "LEE" + LoanEntryFeesList[i].ProductEntryFee.Index,
                                                                      DisbursementEventId = e.Id,
                                                                      Cancelable = true,
                                                                      User = User.CurrentUser,
                                                                      Date = e.Date
                                                                  };
                        e.Commissions.Add(loanEntryFeeEvent);

                        if (Teller.CurrentTeller != null && Teller.CurrentTeller.Id != 0)
                            loanEntryFeeEvent.TellerId = Teller.CurrentTeller.Id;

                        if (loanEntryFeeEvent.Fee > 0)
                        {
                            Events.Add(loanEntryFeeEvent);
                        }
                    }
                }
            }

            if (HasCompulsoryAmount())
            {
                SavingBlockCompulsarySavingsEvent savingBlockEvent = new SavingBlockCompulsarySavingsEvent();
                Debug.Assert(CompulsorySavingsPercentage != null,
                             string.Format(
                                 "Loan with code {0}, should be cheked for compulsory existance, before adding saving block event",
                                 Code)
                    );
                OCurrency csAmount = (Amount.Value * CompulsorySavingsPercentage.Value) / 100m;
                int contracId = CompulsorySavings.Id;
                savingBlockEvent.ContracId = contracId;
                savingBlockEvent.User = _user;
                savingBlockEvent.Amount = csAmount;
                savingBlockEvent.Date = StartDate;
                savingBlockEvent.EntryDate = TimeProvider.Now;
                savingBlockEvent.Cancelable = true;
                CompulsorySavings.Events.Add(savingBlockEvent);
            }

            CreditInsuranceEvent cie = GetCreditInsuranceEvent(e);
            if (cie.Commission > 0)
                Events.Add(cie);

            GivenTranches.Clear();
            TrancheEvent trancheEvent = new TrancheEvent
            {
                StartDate = pDisburseDate,
                Maturity = NbOfInstallments,
                Amount = Amount,
                InterestRate = (decimal)InterestRate,
                ApplyNewInterest = false,
                Number = 0
            };

            GivenTranches.Add(trancheEvent);
            return e;
        }
Ejemplo n.º 6
0
 public void AddLoanEntryFeesEvent(LoanEntryFeeEvent pEvent, SqlTransaction pSqlTransac)
 {
     const string q = @"INSERT INTO [LoanEntryFeeEvents]
                             (
                                  [id]
                                 ,[fee]
                                 ,[disbursement_event_id]
                             )
                             VALUES
                             (
                                 @id
                                 ,@fee
                                 ,@disbursement_event_id
                             )";
     using (OpenCbsCommand c = new OpenCbsCommand(q, pSqlTransac.Connection, pSqlTransac))
     {
         SetEntryFeesEvent(pEvent, c);
         c.ExecuteNonQuery();
     }
 }
Ejemplo n.º 7
0
 public List<LoanEntryFeeEvent> GetEntryFeeEvents(int disbursementEventId)
 {
     List<LoanEntryFeeEvent> entryFeeEvents = new List<LoanEntryFeeEvent>();
     const string q = @"SELECT DISTINCT  entry_date
                                     ,event_type
                                     ,LoanEntryFeeEvents.fee
                                     ,[user_id]
                                     ,ContractEvents.id
                                     ,ContractEvents.is_deleted
                                     ,LoanEntryFeeEvents.disbursement_event_id
                         FROM ContractEvents
                         INNER JOIN LoanEntryFeeEvents ON ContractEvents.id = LoanEntryFeeEvents.id
                         WHERE ContractEvents.event_type LIKE 'LEE%' AND
                         LoanEntryFeeEvents.[disbursement_event_id]=@disbursement_event_id";
     using (SqlConnection conn = GetConnection())
     using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
     {
         c.AddParam("@disbursement_event_id", disbursementEventId);
         using (OpenCbsReader r = c.ExecuteReader())
         {
             while (r.Read())
             {
                 var loanEntryFeeEvent = new LoanEntryFeeEvent
                                             {
                                                 Code = r.GetString("event_type"),
                                                 Fee = r.GetDecimal("fee"),
                                                 Cancelable = true,
                                                 Deleted = r.GetBool("is_deleted"),
                                                 User = new User { Id = r.GetInt("user_id") },
                                                 EntryDate = r.GetDateTime("entry_date"),
                                                 Id = r.GetInt("id"),
                                                 DisbursementEventId = r.GetInt("disbursement_event_id")
                                             };
                 entryFeeEvents.Add(loanEntryFeeEvent);
             }
         }
     }
     return entryFeeEvents;
 }
Ejemplo n.º 8
0
 private static void SetEntryFeesEvent(LoanEntryFeeEvent pEvent, OpenCbsCommand c)
 {
     c.AddParam("@id", pEvent.Id);
     c.AddParam("@fee", pEvent.Fee);
     c.AddParam("@disbursement_event_id", pEvent.DisbursementEventId);
 }
Ejemplo n.º 9
0
        private static OCurrency GetValue(LoanEntryFeeEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "fee")
            {
                amount = eventItem.Fee;
            }
            return amount;
        }