Exemplo n.º 1
0
 public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
 {
     //Nothing to modify
     pInstallment.PaidFees += pFeesEvent;
     pAmountPaid -= pFeesEvent;
     pFeesEvent = 0;
 }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            Installment compareTo = obj as Installment;

            if (null == compareTo)
            {
                return(false);
            }
            if (Number != compareTo.Number)
            {
                return(false);
            }
            if (CapitalRepayment != compareTo.CapitalRepayment)
            {
                return(false);
            }
            if (InterestsRepayment != compareTo.InterestsRepayment)
            {
                return(false);
            }
            if (!ExpectedDate.Equals(compareTo.ExpectedDate))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
 public void RepayCommission(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     if (!_pCCO.CancelFees)
         AutomaticRepayMethod(pInstallment, ref pAmountPaid, ref pCommisionEvent);
     else
         ManualRepayMethod(pInstallment, ref pAmountPaid, ref pCommisionEvent);
 }
        public void Calculate(Installment installment, IScheduleConfiguration configuration)
        {
            var annuity = configuration.RoundingPolicy.Round(FindAnnuity(configuration));

            installment.InterestsRepayment = CalculateInterest(installment, configuration, installment.OLB.Value);
            installment.CapitalRepayment = annuity - installment.InterestsRepayment;
        }
Exemplo n.º 5
0
 private static void ManualRepayMethod(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     pInstallment.PaidCommissions = pCommisionEvent;
     pInstallment.CommissionsUnpaid = 0;
     pAmountPaid -= pCommisionEvent;
     pCommisionEvent = 0;
     //Nothing to modify
 }
Exemplo n.º 6
0
        public List<Installment> CalculateInstallments(bool changeDate)
        {
            List<Installment> schedule = new List<Installment>();
            OCurrency olb = _contract.Amount;
            OCurrency totalInterestsRepayment = _contract.Amount * Convert.ToDecimal(_contract.InterestRate) * (_contract.NbOfInstallments - _contract.GracePeriod.Value);
            decimal decCr = 0;
            decimal decIr = 0;

            for (int number = 1; number <= _contract.NbOfInstallments; number++)
            {
                Installment installment = new Installment { Number = number, FeesUnpaid = 0, OLB = olb };

                if (changeDate)
                {
                    installment.ExpectedDate = _contract.CalculateInstallmentDate(_contract.AlignDisbursementDate, installment.Number);
                }
                else
                {
                    installment = _contract.GetInstallment(number - 1);
                }

                if (number <= _contract.GracePeriod)
                {
                    if (!_contract.Product.ChargeInterestWithinGracePeriod)
                        installment.InterestsRepayment = 0;

                    installment.CapitalRepayment = 0;
                    installment.InterestsRepayment = Math.Round(installment.OLB.Value * Convert.ToDecimal(_contract.InterestRate) + decIr, _roundingPoint);
                    decIr = _contract.Amount.Value * Convert.ToDecimal(_contract.InterestRate) - installment.InterestsRepayment.Value;
                }
                else
                {
                    ExoticInstallment exoInstallment = _contract.Product.ExoticProduct.GetExoticInstallment(number - _contract.GracePeriod.Value - 1);

                    OCurrency cr = Convert.ToDecimal(exoInstallment.PrincipalCoeff) * _contract.Amount.Value + decCr;
                    installment.CapitalRepayment = Math.Round(cr.Value, _roundingPoint);
                    decCr = cr.Value - installment.CapitalRepayment.Value;

                    OCurrency ir = totalInterestsRepayment.Value * Convert.ToDecimal(exoInstallment.InterestCoeff) + decIr;

                    installment.InterestsRepayment = Math.Round(ir.Value, _roundingPoint);
                    decIr = ir.Value - installment.InterestsRepayment.Value;
                }
                olb -= installment.CapitalRepayment.Value;

                if (installment.Number == 1 && _generalSettings.PayFirstInterestRealValue)
                {
                    installment.InterestsRepayment = Math.Round(installment.InterestsRepayment.Value / _contract.NbOfDaysInTheInstallment * (_contract.FirstInstallmentDate - _contract.StartDate).Days, _roundingPoint);
                }

                schedule.Add(installment);
            }

            return schedule;
        }
        public List<Installment> CalculateInstallments(bool changeDate)
		{
            List<Installment> schedule = new List<Installment>();
            OCurrency olb = _contract.Amount;

            DateTime date = _contract.AlignDisbursementDate;
            int daysInTheYear = GetDaysInAYear(_contract.AlignDisbursementDate.Date.Year);

            for (int number = 1; number <= _contract.NbOfInstallments; number++)
            {
                Installment installment = new Installment { Number = number, FeesUnpaid = 0 };

                if (changeDate)
                {
                    installment.ExpectedDate = _contract.CalculateInstallmentDate(_contract.AlignDisbursementDate, installment.Number);
                }

                installment.OLB = Math.Round(olb.Value, _roundingPoint);

                int days = (installment.ExpectedDate - date).Days;

                if (installment.Number == 1 && _generalSettings.PayFirstInterestRealValue)
                {
                    installment.InterestsRepayment =
                        Math.Round(olb.Value * Convert.ToDecimal(_contract.InterestRate) / daysInTheYear *
                            (installment.ExpectedDate - _contract.StartDate).Days, _roundingPoint);
                }
                else
                {
                    installment.InterestsRepayment =
                    Math.Round((olb * _contract.InterestRate / daysInTheYear * days).Value,
                        _roundingPoint, MidpointRounding.AwayFromZero);
                }

                if (number <= _contract.GracePeriod)
                {
                    if (!_contract.Product.ChargeInterestWithinGracePeriod)
                        installment.InterestsRepayment = 0;

                    installment.CapitalRepayment = 0;
                }
                else
                {
                    OCurrency principal = olb / (double)(_contract.NbOfInstallments - number + 1);
                    installment.CapitalRepayment = Math.Round(principal.Value, _roundingPoint);
                }

                olb -= installment.CapitalRepayment;
                date = installment.ExpectedDate;
                schedule.Add(installment);
            }
            return schedule;
		}
        /// <summary>
        /// Finding total for all Annuity policy (30/360, Fact/360, Fact/Fact)
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns>total annuity</returns>
        private decimal FindAnnuity(IScheduleConfiguration configuration)
        {
            var number = configuration.NumberOfInstallments - configuration.GracePeriod;
            var numberOfPeriods = configuration.PeriodPolicy.GetNumberOfPeriodsInYear(configuration.PreferredFirstInstallmentDate, configuration.YearPolicy);
            var interestRate = (double)configuration.InterestRate / 100 / numberOfPeriods;

            // at first we are trying to calculate standard annuity for 30/360 using standard formula.
            var numerator = (decimal)interestRate * configuration.Amount;
            var denominator = 1 - 1 / Math.Pow(1 + interestRate, number);

            var annuity = 0.0M;
            if (configuration.InterestRate == 0)
                annuity = configuration.Amount / number;
            else
                annuity = numerator / (decimal)denominator;

            // In order to define the annuity amount for the other types Period and Year policy
            // we need to increase the standard annuity, build schedule according defined amount
            // and if scheduled is not balanced, repeat the procedure again
            // remainder it is surplus amount, which is left after building schedule using calculated annuity
            // remainder = remainder/numberOfInstallemnts * interestRate/100
            // left remainder // should be divided by number of installments in order to proportionally spread between installments
            // but because we need to count interest also that amount should be multiplied by interest rate / 100
            var remainder = 0m;
            var counter = 0;
            var installment = new Installment {OLB = configuration.Amount};
            var endDate = configuration.PreferredFirstInstallmentDate;
            do
            {
                // loop is only for building schedule and determining the remainder
                for (var i = 1; i <= configuration.NumberOfInstallments; ++i)
                {
                    installment.Number = i;
                    installment.StartDate = i != 1 ? installment.ExpectedDate : configuration.StartDate;
                    endDate = i == 1
                        ? configuration.PreferredFirstInstallmentDate
                        : configuration.PeriodPolicy.GetNextDate(endDate);
                    installment.ExpectedDate = configuration.DateShiftPolicy.ShiftDate(endDate);
                    if (i <= configuration.GracePeriod) continue;
                    installment.InterestsRepayment = CalculateInterest(installment, configuration, installment.OLB.Value);
                    installment.CapitalRepayment = annuity - installment.InterestsRepayment;
                    installment.OLB -= installment.CapitalRepayment;
                }
                remainder = installment.OLB.Value;
                installment.OLB = configuration.Amount;
                ++counter;
                annuity += (remainder * configuration.InterestRate / (decimal)numberOfPeriods / 100 / number);
            } while (Math.Abs(remainder) > 0.01m && counter < 1000);
            return annuity;
        }
 protected decimal CalculateInterest(Installment installment, IScheduleConfiguration configuration, decimal amount)
 {
     var daysInPeriod = configuration.PeriodPolicy.GetNumberOfDays(installment.ExpectedDate);//, configuration.DateShiftPolicy);
     var daysInYear = configuration.YearPolicy.GetNumberOfDays(installment.ExpectedDate);
     var interest = installment.OLB * configuration.InterestRate / 100 * daysInPeriod / daysInYear;
     //if schedule is flat
     if (configuration.CalculationPolicy.GetType() == typeof(FlatInstallmentCalculationPolicy))
     {
         var numberOfPeriods =
             (decimal)
                 (configuration.PeriodPolicy.GetNumberOfPeriodsInYear(
                     configuration.PreferredFirstInstallmentDate, configuration.YearPolicy));
         interest = configuration.Amount*configuration.InterestRate/numberOfPeriods/100;
     }
     return configuration.RoundingPolicy.Round(interest.Value);
 }
Exemplo n.º 10
0
 private static void AutomaticRepayMethod(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     if (AmountComparer.Compare(pAmountPaid, pInstallment.CommissionsUnpaid) > 0)
     {
         pCommisionEvent += pInstallment.CommissionsUnpaid;
         pAmountPaid -= pInstallment.CommissionsUnpaid;
         pInstallment.PaidCommissions += pInstallment.CommissionsUnpaid;
         pInstallment.CommissionsUnpaid = 0;
     }
     else
     {
         pCommisionEvent += pAmountPaid;
         pInstallment.PaidCommissions += pAmountPaid;
         pInstallment.CommissionsUnpaid -= pAmountPaid;
         pAmountPaid = 0;
     }
 }
Exemplo n.º 11
0
        public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
        {
            if (AmountComparer.Compare(pAmountPaid, pInstallment.FeesUnpaid) > 0)
            {
                pFeesEvent += pInstallment.FeesUnpaid;
                pAmountPaid -= pInstallment.FeesUnpaid;
                pInstallment.PaidFees += pInstallment.FeesUnpaid;
                pInstallment.FeesUnpaid = 0;

            }
            else
            {
                pFeesEvent += pAmountPaid;
                pInstallment.PaidFees += pAmountPaid;
                pInstallment.FeesUnpaid -= pAmountPaid;
                pAmountPaid = 0;
            }
        }
Exemplo n.º 12
0
        public List<Installment> CalculateInstallments(bool changeDate)
		{
            List<Installment> schedule = new List<Installment>();
            OCurrency olb = _contract.Amount;

            for (int number = 1; number <= _contract.NbOfInstallments; number++)
            {
                Installment installment = new Installment { Number = number, FeesUnpaid = 0 };

                if (changeDate)
                {
                    installment.ExpectedDate = _contract.CalculateInstallmentDate(_contract.AlignDisbursementDate, installment.Number);
                }

                decimal olbValue = olb.Value;
                installment.OLB = Math.Round(olbValue, _roundingPoint);
                decimal interestRepayment = (olbValue * _contract.InterestRate);
                installment.InterestsRepayment = Math.Round(interestRepayment, _roundingPoint);

                if (installment.Number == 1 && _generalSettings.PayFirstInterestRealValue)
                {
                    installment.InterestsRepayment = Math.Round(installment.InterestsRepayment.Value / _contract.NbOfDaysInTheInstallment * (_contract.FirstInstallmentDate - _contract.StartDate).Days, _roundingPoint);
                }

                if (number <= _contract.GracePeriod)
                {
                    if (!_contract.Product.ChargeInterestWithinGracePeriod)
                        installment.InterestsRepayment = 0;

                    installment.CapitalRepayment = 0;
                }
                else
                {
                    OCurrency principal = olb / (double)(_contract.NbOfInstallments - number + 1);
                    installment.CapitalRepayment = Math.Round(principal.Value, _roundingPoint);
                }

                olb -= installment.CapitalRepayment;

                schedule.Add(installment);
            }
            return schedule;
		}
Exemplo n.º 13
0
        public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pInterestEvent, ref OCurrency pInterestPrepayment)
        {
            if (AmountComparer.Compare(pAmountPaid, pInstallment.InterestsRepayment - pInstallment.PaidInterests) > 0)
            {
                OCurrency interestHasToPay = pInstallment.InterestsRepayment - pInstallment.PaidInterests;

                pAmountPaid -= interestHasToPay;
                pInterestEvent += interestHasToPay;
                pInterestPrepayment += interestHasToPay;
                pInstallment.PaidInterests += interestHasToPay;
            }
            else
            {
                pInstallment.PaidInterests += pAmountPaid;
                pInterestEvent += pAmountPaid;
                pInterestPrepayment += pAmountPaid;
                pAmountPaid = 0;
            }
        }
Exemplo n.º 14
0
 public void TestPaidCapitalDefaultValue()
 {
     Installment i = new Installment();
     Assert.AreEqual(0m,i.PaidCapital.Value);
 }
Exemplo n.º 15
0
 private void InitTotal()
 {
     decimal totalInterest = 0, totalPrincipal = 0, totalPaidInterests = 0, totalPaidCapital = 0;
     foreach (var installment in Loan.InstallmentList)
     {
         totalInterest += installment.InterestsRepayment.Value;
         totalPrincipal += installment.CapitalRepayment.Value;
         totalPaidCapital += installment.PaidCapital.Value;
         totalPaidInterests += installment.PaidInterests.Value;
     }
     var empty = new OCurrency();
     var date = new DateTime();
     _total = new Installment(
         date,
         totalInterest,
         totalPrincipal,
         totalPaidCapital,
         totalPaidInterests,
         empty,
         null,
         -1);
 }
 private static void AssertSpecifiedInstallment(Installment pInstallment, OCurrency pInterestRepayment, OCurrency pCapitalRepayment, 
     OCurrency pPaidCapital, OCurrency pPaidInterest, OCurrency pFeesUnpaid)
 {
     Assert.AreEqual(pInterestRepayment.Value, pInstallment.InterestsRepayment.Value);
     Assert.AreEqual(pCapitalRepayment.Value, pInstallment.CapitalRepayment.Value);
     Assert.AreEqual(pPaidCapital.Value, pInstallment.PaidCapital.Value);
     Assert.AreEqual(pPaidInterest.Value, pInstallment.PaidInterests.Value);
     Assert.AreEqual(pFeesUnpaid.Value, pInstallment.FeesUnpaid.Value);
 }
Exemplo n.º 17
0
        public void TestFixtureSetUp()
        {
            ProvisioningTable.GetInstance(new User()).Add(new ProvisioningRate { Number = 1, NbOfDaysMin = 0, NbOfDaysMax = 1000, Rate = 0 });
            ApplicationSettings.GetInstance("").DeleteAllParameters();
            ApplicationSettings.GetInstance("").AddParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);
            ApplicationSettings.GetInstance("").AddParameter(OGeneralSettings.USECENTS, true);

            ApplicationSettings.GetInstance("").AddParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").AddParameter(OGeneralSettings.DONOTSKIPWEEKENDSININSTALLMENTSDATE, false);
            ApplicationSettings.GetInstance("").AddParameter(OGeneralSettings.INCREMENTALDURINGDAYOFF, true);

            TechnicalSettings.UseOnlineMode = false;

            projectManager = new ProjectManager(DataUtil.TESTDB);
            creditManagement = new CreditContractManagement(DataUtil.TESTDB);
            installmentManagement = new InstallmentManager(DataUtil.TESTDB);
            clientManagement = new ClientManager(DataUtil.TESTDB);
            connectionManager = ConnectionManager.GetInstance(DataUtil.TESTDB);
            fundingLineManager = new FundingLineManager(DataUtil.TESTDB);
            userManager = new UserManager(DataUtil.TESTDB);
            _packageManager = new LoanProductManager(DataUtil.TESTDB);

            installment1 = new Installment();
            installment1.Number = 1;
            installment1.CapitalRepayment = 200;
            installment1.InterestsRepayment = 100;
            installment1.PaidCapital = 200;
            installment1.PaidInterests = 100;
            //to initialize Installment.FeesUnpaid, ocurrency is an object, must be initialized
            installment1.FeesUnpaid = 0;
            installment1.ExpectedDate = DateTime.Today.AddDays(-1);

            installment2 = new Installment();
            installment2.Number = 2;
            installment2.CapitalRepayment = 200;
            installment2.InterestsRepayment = 100;
            installment2.PaidCapital = 0;
            installment2.PaidInterests = 100;
            //to initialize Installment.FeesUnpaid, ocurrency is an object, must be initialized
            installment2.FeesUnpaid = 0;
            installment2.ExpectedDate = DateTime.Today.AddMonths(1);
        }
Exemplo n.º 18
0
        public void TestSelectAllAlertsRepaymentAlertWhen2NonRepaidInstallmentsAndLoanOfficerFilterNotActive()
        {
            ApplicationSettings dataParam = ApplicationSettings.GetInstance("");
            dataParam.DeleteAllParameters();
            dataParam.AddParameter(OGeneralSettings.LOANOFFICERPORTFOLIOFILTER, false);
            dataParam.AddParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);
            dataParam.AddParameter(OGeneralSettings.USECENTS, true);
            dataParam.AddParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            //NonWorkingDateSingleton nonWorkingDateHelper = NonWorkingDateSingleton.GetInstance("");
            //nonWorkingDateHelper.WeekEndDay1 = 6;
            //nonWorkingDateHelper.WeekEndDay2 = 0;
            //nonWorkingDateHelper.PublicHolidays = new Hashtable();
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 1, 1), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 3, 8), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 3, 21), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 3, 22), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 5, 1), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 5, 9), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 6, 27), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 9, 9), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 11, 6), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 11, 26), "New Year Eve");
            //nonWorkingDateHelper.PublicHolidays.Add(new DateTime(2006, 1, 6), "Christmas");

            //dataParam.AddParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            credit.InstallmentList = new List<Installment>();

            Installment installment1 = new Installment();
            installment1.Number = 1;
            installment1.CapitalRepayment = 200;
            installment1.InterestsRepayment = 100;
            installment1.PaidCapital = 0;
            installment1.PaidInterests = 100;
            installment1.FeesUnpaid = 0;
            installment1.ExpectedDate = DateTime.Today.AddDays(-2);

            Installment installment2 = new Installment();
            installment2.Number = 2;
            installment2.CapitalRepayment = 200;
            installment2.InterestsRepayment = 100;
            installment2.PaidCapital = 0;
            installment2.PaidInterests = 65;
            installment2.FeesUnpaid = 0;
            installment2.ExpectedDate = DateTime.Today.AddDays(-1);

            credit.Disbursed = true;
            credit.AddInstallment(installment1);
            credit.AddInstallment(installment2);
            FundingLine fund = new FundingLine();
            fund.Purpose = "Microsoft financement";
            fund.Name = "AFD130";
            fund.Deleted = false;
            fund.StartDate = DateTime.Now;
            fund.EndDate = DateTime.Now;
            fund.Currency = new Currency { Id = 1 };
            fundingLineManager.AddFundingLine(fund, null);
            credit.FundingLine = fund;
            creditManagement.AddCredit(credit, _project.Id, null);

            AlertStock alertStock = creditManagement.SelectAllAlerts("");
            Assert.AreEqual(1, alertStock.GetNumberOfAlerts);
        }
Exemplo n.º 19
0
 public void RepayFees(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
 {
     _methodToCalculateFees.Repay(pInstallment,ref pAmountPaid, ref pFeesEvent);
 }
Exemplo n.º 20
0
 public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pInterestEvent, ref OCurrency pInterestPrepayment)
 {
     //Nothing to modify
 }
Exemplo n.º 21
0
 public int GetNumberOfDays(Installment installment, IDateShiftPolicy shiftPolicy)
 {
     return (shiftPolicy.ShiftDate(installment.ExpectedDate) - shiftPolicy.ShiftDate(installment.StartDate)).Days;
 }
Exemplo n.º 22
0
        public void UpdateAllInstalmentsDate()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.DONOTSKIPWEEKENDSININSTALLMENTSDATE, false);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.INCREMENTALDURINGDAYOFF, true);
            NonWorkingDateSingleton.GetInstance("").PublicHolidays = new Dictionary<DateTime, string>
                                                                         {{DateTime.Today.AddDays(-1), "dfsdf"}};
            Installment installment = new Installment
                                          {
                                              Number = 1,
                                              CapitalRepayment = 200,
                                              InterestsRepayment = 100,
                                              FeesUnpaid = 0,
                                              ExpectedDate = DateTime.Today.AddDays(-1)
                                          };

            DynamicMock mockInstalmentManager = new DynamicMock(typeof(InstallmentManager));
            mockInstalmentManager.Expect("UpdateInstallment",installment, 1, null, true);

            List<KeyValuePair<int, Installment>> list = new List<KeyValuePair<int, Installment>>
                                                            {
                                                                new KeyValuePair<int, Installment>(1, installment)
                                                            };

            LoanServices loanServices = new LoanServices((InstallmentManager)mockInstalmentManager.MockInstance, null, null);
            Assert.AreEqual(1, loanServices.UpdateAllInstallmentsDate(list));
        }
Exemplo n.º 23
0
 public void TestAddInstallmentAndGetInstallment()
 {
     Loan newContract = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())); new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
     Installment i = new Installment {PaidCapital = 100};
     newContract.AddInstallment(i);
     Assert.AreEqual(100m,newContract.GetInstallment(0).PaidCapital.Value);
 }
Exemplo n.º 24
0
 private static void _AssertSpecifiedInstallment(Installment pInstallment,int pNumber, DateTime pExpectedDate,OCurrency pInterestRepayment, OCurrency pCapitalRepayment,OCurrency pOLB, OCurrency pPaidCapital, OCurrency pPaidInterest)
 {
     Assert.AreEqual(pNumber, pInstallment.Number);
     Assert.AreEqual(pExpectedDate, pInstallment.ExpectedDate);
     Assert.AreEqual(pInterestRepayment.Value, pInstallment.InterestsRepayment.Value);
     Assert.AreEqual(pCapitalRepayment.Value, pInstallment.CapitalRepayment.Value);
     Assert.AreEqual(pOLB.Value, pInstallment.OLB.Value);
     Assert.AreEqual(pPaidCapital.Value, pInstallment.PaidCapital.Value);
     Assert.AreEqual(pPaidInterest.Value, pInstallment.PaidInterests.Value);
 }
 private static void _AssertSpecifiedInstallment(Installment pInstallment, int pNumber, DateTime pExpectedDate, OCurrency pInterestRepayment, OCurrency pCapitalRepayment, OCurrency pOLB, OCurrency pInstallmentTotalAmount)
 {
     Assert.AreEqual(pNumber, pInstallment.Number);
     Assert.AreEqual(pExpectedDate, pInstallment.ExpectedDate);
     Assert.AreEqual(pInterestRepayment.Value, pInstallment.InterestsRepayment.Value);
     Assert.AreEqual(pCapitalRepayment.Value, pInstallment.CapitalRepayment.Value);
     Assert.AreEqual(pOLB.Value, pInstallment.OLB.Value);
     Assert.AreEqual(pInstallmentTotalAmount.Value, pInstallment.AmountHasToPayWithInterest.Value);
 }
Exemplo n.º 26
0
        public void TestSortInstallments()
        {
            LoanProduct package = new LoanProduct {Currency = new Currency {Id = 1},KeepExpectedInstallment = true};
            Loan myContract = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())); new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.Amount = 1000;
            myContract.Product = package;

            Installment installment1 = new Installment
                                           {
                                               ExpectedDate = new DateTime(2005, 9, 5),
                                               Number = 1,
                                               InterestsRepayment = 0,
                                               CapitalRepayment = 100
                                           };

            Installment installment2 = new Installment
                                           {
                                               ExpectedDate = new DateTime(2005, 8, 5),
                                               Number = 1,
                                               InterestsRepayment = 0,
                                               CapitalRepayment = 100
                                           };

            Installment installment3 = new Installment
                                           {
                                               ExpectedDate = new DateTime(2005, 12, 5),
                                               Number = 1,
                                               InterestsRepayment = 0,
                                               CapitalRepayment = 100
                                           };

            Installment installment4 = new Installment
                                           {
                                               ExpectedDate = new DateTime(2005, 10, 5),
                                               Number = 1,
                                               InterestsRepayment = 0,
                                               CapitalRepayment = 100
                                           };

            myContract.InstallmentList = new List<Installment> {installment1,installment2,installment3,installment4};

            myContract.InstallmentList.Sort((x, y) => x.ExpectedDate.CompareTo(y.ExpectedDate));

            Assert.AreEqual(new DateTime(2005,8,5),myContract.InstallmentList[0].ExpectedDate);
            Assert.AreEqual(new DateTime(2005,9,5),myContract.InstallmentList[1].ExpectedDate);
            Assert.AreEqual(new DateTime(2005,10,5),myContract.InstallmentList[2].ExpectedDate);
            Assert.AreEqual(new DateTime(2005,12,5),myContract.InstallmentList[3].ExpectedDate);
        }
Exemplo n.º 27
0
 public void TestPaidInterestsDefaultValue()
 {
     Installment i = new Installment();
     Assert.AreEqual(0m,i.PaidInterests.Value);
 }
Exemplo n.º 28
0
 private static void _AssertSpecifiedInstallment(Installment pInstallment, OCurrency pInterestRepayment, OCurrency pCapitalRepayment, OCurrency pOLB, OCurrency pPaidCapital, OCurrency pPaidInterest)
 {
     Assert.AreEqual(pInterestRepayment.Value, pInstallment.InterestsRepayment.Value);
     Assert.AreEqual(pCapitalRepayment.Value, pInstallment.CapitalRepayment.Value);
     Assert.AreEqual(pOLB.Value, pInstallment.OLB.Value);
     Assert.AreEqual(pPaidCapital.Value, pInstallment.PaidCapital.Value);
     Assert.AreEqual(pPaidInterest.Value, pInstallment.PaidInterests.Value);
 }
Exemplo n.º 29
0
 public void Test_Setup()
 {
     _installment = new Installment(new DateTime(2009, 7, 6), 100, 1000, 0, 0, 0, null, 1);
 }
Exemplo n.º 30
0
        public List<Installment> CalculateInstallments(bool changeDate)
        {
            List<Installment> schedule = new List<Installment>();
            OCurrency olb = _contract.Amount;
            OCurrency totalAmount = _contract.Amount;

            OCurrency totalInterest = _contract.GracePeriod.HasValue &&
                                      !_contract.Product.ChargeInterestWithinGracePeriod
                                          ? Math.Round(
                                                _contract.Amount.Value * Convert.ToDecimal(_contract.InterestRate) *
                                                (_contract.NbOfInstallments - _contract.GracePeriod.Value),
                                                _roundingPoint, MidpointRounding.AwayFromZero)
                                          : Math.Round(
                                                _contract.Amount.Value * Convert.ToDecimal(_contract.InterestRate) *
                                                _contract.NbOfInstallments, _roundingPoint,
                                                MidpointRounding.AwayFromZero);

            int nbOfInstallmentWithoutGracePeriod = _contract.GracePeriod.HasValue
                                                        ? _contract.NbOfInstallments - _contract.GracePeriod.Value
                                                        : _contract.NbOfInstallments;

            OCurrency sumOfPrincipal = 0;
            OCurrency sumOfInterest = 0;

            OCurrency interestBase = _contract.Product.ChargeInterestWithinGracePeriod
                                         ? Math.Round(
                                               (totalInterest.Value - sumOfInterest.Value)/
                                               (nbOfInstallmentWithoutGracePeriod + _contract.GracePeriod.Value),
                                               _roundingPoint, MidpointRounding.AwayFromZero)
                                         : Math.Round(
                                               (totalInterest.Value - sumOfInterest.Value)/
                                               (nbOfInstallmentWithoutGracePeriod),
                                               _roundingPoint, MidpointRounding.AwayFromZero);

            OCurrency principalBase = Math.Round(
                                (totalAmount.Value - sumOfPrincipal.Value) /
                                (nbOfInstallmentWithoutGracePeriod),
                                _roundingPoint, MidpointRounding.AwayFromZero);

            int installmentNumberWithoutGracePeriodForCapital = 0;
            int installmentNumberWithoutGracePeriodForInterest = 0;

            if (!_contract.Rescheduled)
            {
                for (int number = 1; number <= _contract.NbOfInstallments; number++)
                {
                    Installment installment = new Installment { Number = number, FeesUnpaid = 0 };

                    if (changeDate)
                    {
                        installment.ExpectedDate = _contract.CalculateInstallmentDate(_contract.AlignDisbursementDate, installment.Number);
                    }

                    installment.OLB = olb;

                    OCurrency interest = Math.Round(
                                (totalInterest.Value - sumOfInterest.Value) /
                                (_contract.NbOfInstallments - installmentNumberWithoutGracePeriodForInterest),
                                _roundingPoint, MidpointRounding.AwayFromZero);

                    OCurrency principal = Math.Round(
                                (totalAmount.Value - sumOfPrincipal.Value) /
                                (nbOfInstallmentWithoutGracePeriod - installmentNumberWithoutGracePeriodForCapital),
                                _roundingPoint, MidpointRounding.AwayFromZero);

                    if (_contract.Product.RoundingType == ORoundingType.End ||
                             _contract.Product.RoundingType == ORoundingType.Begin)
                    {
                        interest = interestBase;
                        principal = principalBase;
                    }

                    if (_contract.GracePeriod.HasValue && number <= _contract.GracePeriod)
                    {
                        installment.CapitalRepayment = 0;

                        if (_contract.Product.ChargeInterestWithinGracePeriod)
                        {
                            installment.InterestsRepayment = interest;

                            sumOfInterest += installment.InterestsRepayment;
                            installmentNumberWithoutGracePeriodForInterest++;
                        }
                        else
                        {
                            installment.InterestsRepayment = 0;
                            installmentNumberWithoutGracePeriodForInterest++;
                        }
                    }
                    else
                    {
                        installment.CapitalRepayment = principal;

                        sumOfPrincipal += installment.CapitalRepayment;
                        installmentNumberWithoutGracePeriodForCapital++;

                        installment.InterestsRepayment = interest;

                        sumOfInterest += installment.InterestsRepayment;
                        installmentNumberWithoutGracePeriodForInterest++;
                    }

                    if (installment.Number == 1 && _generalSettings.PayFirstInterestRealValue)
                    {
                        installment.InterestsRepayment =
                            Math.Round(
                                installment.InterestsRepayment.Value/_contract.NbOfDaysInTheInstallment*
                                (_contract.FirstInstallmentDate - _contract.StartDate).Days, _roundingPoint,
                                MidpointRounding.AwayFromZero);
                    }

                    olb -= installment.CapitalRepayment.Value;

                    schedule.Add(installment);
                }
            }

            if (_contract.Product.RoundingType == ORoundingType.End)
            {
                schedule[_contract.NbOfInstallments - 1].InterestsRepayment += totalInterest - sumOfInterest;
                schedule[_contract.NbOfInstallments - 1].CapitalRepayment += totalAmount - sumOfPrincipal;
            }

            if (_contract.Product.RoundingType == ORoundingType.Begin)
            {
                schedule[0].CapitalRepayment += totalInterest - sumOfInterest;
                schedule[0].CapitalRepayment += totalAmount - sumOfPrincipal;
            }

            return schedule;
        }
Exemplo n.º 31
0
        public void TestInstallmentCopy()
        {
            Installment installment = new Installment(new DateTime(2006, 2, 1), 100, 102, 234, 32, 0, null, 1);
            Installment installmentCopyFake = installment;
            Installment installmentCopy = installment.Copy();

            installment.PaidCapital = 2345678;
            Assert.AreEqual(2345678,installmentCopyFake.PaidCapital.Value);
            Assert.AreEqual(234,installmentCopy.PaidCapital.Value);
        }