/// <summary>
        /// Method to add a TrancheEvent into database. We use the NullableTypes to make the correspondance between
        /// nullable int, decimal and double types in database and our own objects
        /// </summary>
        /// <param name="trancheEvent">TrancheEvent Object</param>
        /// <returns>The id of the Tranche Event which has been added</returns>
        public int Add(TrancheEvent trancheEvent)
        {
            const string sqlText = @"
                INSERT INTO [TrancheEvents]
                           ( [id]
                            ,[interest_rate]
                            ,[amount]
                            ,[maturity]
                            ,[start_date]
                            ,[applied_new_interest])
                            VALUES
                            (@Id,
                             @InterestRate,
                             @Amount,
                             @Maturity,
                             @StartDate, 
                             @applied_new_interest) 
                SELECT SCOPE_IDENTITY()";

            using (SqlConnection conn = GetConnection())
                using (var cmd = new OpenCbsCommand(sqlText, conn))
                {
                    SetTrancheEvent(cmd, trancheEvent);
                    return(int.Parse(cmd.ExecuteScalar().ToString()));
                }
        }
        private void DisplayEvent()
        {
            listViewEvents.Items.Clear();

            ListViewItem listViewItem = new ListViewItem(_event.Date.ToShortDateString());

            listViewItem.SubItems.Add(_event.Code);
            listViewItem.Tag = _event;

            if (_event is LoanDisbursmentEvent)
            {
                LoanDisbursmentEvent evt = _event as LoanDisbursmentEvent;
                listViewItem.SubItems.Add(evt.Amount.GetFormatedValue(true));
                listViewItem.SubItems.Add("-");
                listViewItem.SubItems.Add("-");
            }
            else if (_event is RepaymentEvent)
            {
                RepaymentEvent evt = _event as RepaymentEvent;
                listViewItem.SubItems.Add(evt.Principal.GetFormatedValue(true));
                listViewItem.SubItems.Add(evt.Interests.GetFormatedValue(true));
                listViewItem.SubItems.Add(evt.Fees.GetFormatedValue(true));
            }
            else if (_event is BadLoanRepaymentEvent)
            {
                BadLoanRepaymentEvent evt = _event as BadLoanRepaymentEvent;
                listViewItem.SubItems.Add(evt.Principal.GetFormatedValue(true));
                listViewItem.SubItems.Add(evt.Interests.GetFormatedValue(true));
                listViewItem.SubItems.Add(evt.Fees.GetFormatedValue(true));
            }
            else if (_event is TrancheEvent)
            {
                TrancheEvent evt = _event as TrancheEvent;
                listViewItem.SubItems.Add(evt.Amount.GetFormatedValue(true));
                listViewItem.SubItems.Add(evt.InterestRate.GetFormatedValue(true));
                listViewItem.SubItems.Add("-");
            }
            else if (_event is RegEvent || _event is WriteOffEvent || _event is LoanValidationEvent)
            {
                listViewItem.SubItems.Add("-");
                listViewItem.SubItems.Add("-");
                listViewItem.SubItems.Add("-");
            }
            else if (_event is RescheduleLoanEvent)
            {
                RescheduleLoanEvent evt = _event as RescheduleLoanEvent;
                listViewItem.SubItems.Add(evt.Amount.GetFormatedValue(true));
                listViewItem.SubItems.Add("-");
                listViewItem.SubItems.Add("-");
            }
            listViewItem.SubItems.Add(_event.Cancelable.ToString());

            if (_event.Deleted)
            {
                listViewItem.BackColor = Color.FromArgb(188, 209, 199);
                listViewItem.ForeColor = Color.White;
            }
            listViewEvents.Items.Add(listViewItem);
        }
 private static void SetTrancheEvent(OpenCbsCommand cmd, TrancheEvent trancheEvent)
 {
     cmd.AddParam("@Id", trancheEvent.Id);
     cmd.AddParam("@InterestRate", trancheEvent.InterestRate);
     cmd.AddParam("@Amount", trancheEvent.Amount);
     cmd.AddParam("@Maturity", trancheEvent.Maturity);
     cmd.AddParam("@StartDate", trancheEvent.StartDate);
     cmd.AddParam("@applied_new_interest", trancheEvent.StartDate);
 }
Esempio n. 4
0
        private static OCurrency GetValue(TrancheEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }

            return(amount);
        }
        public void Update(TrancheEvent trancheEvent)
        {
            string sqlText = @"
                            UPDATE [TrancheEvents] SET 
                            [interest_rate] = @InterestRate,
                            [amount] = @Amount,
                            [maturity] = @Maturity,
                            [start_date] = @StartDate,
                            [applied_new_interest] = @applied_new_interest
                            WHERE id = @Id";

            using (SqlConnection conn = GetConnection())
                using (var cmd = new OpenCbsCommand(sqlText, conn))
                {
                    SetTrancheEvent(cmd, trancheEvent);
                    cmd.ExecuteNonQuery();
                }
        }
Esempio n. 6
0
        public TrancheEvent AddTranche(TrancheOptions trancheOptions)
        {
            _trancheEvent = new TrancheEvent
            {
                Date         = trancheOptions.TrancheDate,
                InterestRate = trancheOptions.InterestRate,
                Amount       = trancheOptions.TrancheAmount,
                Maturity     = trancheOptions.CountOfNewInstallments,
                StartDate    = trancheOptions.TrancheDate,
                Number       = _currentLoan.GivenTranches.Count
            };

            trancheOptions.Number = _trancheEvent.Number;

            switch (_currentLoan.Product.LoanType)
            {
            case OLoanTypes.Flat:
            {
                AddFlatTranche(trancheOptions);
            }
            break;

            case OLoanTypes.DecliningFixedPrincipal:
            {
                AddFixedPrincipalTranche(trancheOptions);
            }
            break;

            case OLoanTypes.DecliningFixedInstallments:
            {
                AddFixedInstallmentTranche(trancheOptions);
            }
            break;
            }

            _currentLoan.CalculateStartDates();
            return(_trancheEvent);
        }
Esempio n. 7
0
        public TrancheEvent AddTranche(TrancheOptions pTO)
        {
            _trancheEvent = new TrancheEvent
                                {
                                    Date = DateTime.Now,
                                    InterestRate = pTO.InterestRate,
                                    Amount = pTO.TrancheAmount,
                                    Maturity = pTO.CountOfNewInstallments,
                                    StartDate = pTO.TrancheDate,
                                    Number = _currentLoan.GivenTranches.Count
                                };

            pTO.Number = _trancheEvent.Number;

            switch (_currentLoan.Product.LoanType)
            {
                case OLoanTypes.Flat:
                    {
                        AddFlatTranche(pTO);
                    }
                    break;

                case OLoanTypes.DecliningFixedPrincipal:
                    {
                        AddFixedPrincipalTranche(pTO);
                    }
                    break;

                case OLoanTypes.DecliningFixedInstallments:
                    {
                        AddFixedInstallmentTranche(pTO);
                    }
                    break;
            }

            return _trancheEvent;
        }
Esempio n. 8
0
 private void TrancheEventOrigination(TrancheEvent trancheEvent, Loan pContract, SqlTransaction sqlTransac)
 {
     _eventManagement.AddLoanEvent(trancheEvent, pContract.Id, sqlTransac);
 }
Esempio n. 9
0
 public TrancheEvent AddTranche(TrancheEvent pTe)
 {
     GivenTranches.Add(pTe);
     return pTe;
 }
Esempio n. 10
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();
                        loanEntryFeeEvent.Fee = Product.Currency.UseCents ? Math.Round(entryFees[i].Value, 2) : Math.Round(entryFees[i].Value, MidpointRounding.AwayFromZero);
                        loanEntryFeeEvent.Code = "LEE" + LoanEntryFeesList[i].ProductEntryFee.Index;
                        loanEntryFeeEvent.DisbursementEventId = e.Id;
                        loanEntryFeeEvent.Cancelable = true;
                        loanEntryFeeEvent.User = User.CurrentUser;
                        e.Commissions.Add(loanEntryFeeEvent);
                        if (loanEntryFeeEvent.Fee > 0)
                        {
                            Events.Add(loanEntryFeeEvent);
                        }
                    }
                }
            }

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

            GivenTranches.Add(trancheEvent);

            return e;
        }