public CalculateAmountToRepaySpecifiedInstallmentStrategy(CreditContractOptions pCCo,Loan pContract, User pUser, 
     ApplicationSettings pGeneralSettings,NonWorkingDateSingleton pNonWorkingDate)
 {
     _user = pUser;
     _generalSettings = pGeneralSettings;
     _nWds = pNonWorkingDate;
     _contract = pContract;
     _cCo = pCCo;
 }
        public CalculateMaximumAmountToRegradingLoanStrategy(CreditContractOptions pCCo,Loan pContract, User pUser, 
            ApplicationSettings pGeneralSettings,NonWorkingDateSingleton pNonWorkingDate)
        {
            _user = pUser;
            _generalSettings = pGeneralSettings;
            _nWDS = pNonWorkingDate;

            _contract = pContract;
            _cCo = pCCo;
        }
Пример #3
0
 public CalculateInstallments(CreditContractOptions pCCO, Loan pContract, User pUser, ApplicationSettings pGeneralSettings,NonWorkingDateSingleton pNonWorkingDate)
 {
     _generalSettings = pGeneralSettings;
     _nWds = pNonWorkingDate;
     _contract = pContract;
     _cCo = pCCO;
     _methodToRepayFees = new RepayFeesStrategy(pCCO);
     _methodToRepayInterest = new RepayInterestStrategy(pCCO);
     _methodToRepayCommission = new RepayCommisionStrategy(pCCO);
     PaidIstallments = new List<Installment>();
 }
Пример #4
0
        public RescheduleLoanEvent Reschedule(ReschedulingOptions ro, Loan contract, NonWorkingDateSingleton nwdS, ApplicationSettings applicationSettings)
        {
            _contract = contract;
            _nwdS = nwdS;
            _generalSettings = applicationSettings;

            switch (contract.Product.LoanType)
            {
                case OLoanTypes.Flat:
                    _Reschedule_Flat(ro);
                    break;

                case OLoanTypes.DecliningFixedPrincipal:
                    _Reschedule_FixedPrincipal(ro);
                    break;

                case OLoanTypes.DecliningFixedInstallments:
                    _Reschedule_DecliningFixedInstallments(ro);
                    break;
            }

            _Reschedule_AdjustOverpaid();

            RescheduleLoanEvent rSe = new RescheduleLoanEvent
            {
                Date = ro.ReschedulingDate,
                Amount = contract.CalculateActualOlb(),
                Interest = contract.GetTotalInterestDue(),
                ClientType = contract.ClientType,
                BadLoan = contract.BadLoan,
                NbOfMaturity = ro.NewInstallments,
                DateOffset = ro.RepaymentDateOffset,
                GracePeriod = ro.GracePeriod,
                ChargeInterestDuringShift = ro.ChargeInterestDuringShift,
                ChargeInterestDuringGracePeriod = ro.ChargeInterestDuringGracePeriod
            };

            return rSe;
        }
Пример #5
0
        public CreditContractRepayment(Loan pContract, CreditContractOptions pCCo, DateTime pDate,int pInstallmentNumber, User pUser, ApplicationSettings pGeneralSettings,NonWorkingDateSingleton pNonWorkingDate)
        {
            _generalSettings = pGeneralSettings;
            _nWds = pNonWorkingDate;

            _date = pDate;
            _installmentNumber = pInstallmentNumber;

            PaidIstallments = new List<Installment>();

            _amountToRepayTottalyLoan = new CalculateMaximumAmountToRepayStrategy(pCCo, pContract.Copy(), pUser, _generalSettings,_nWds);
            _amountToRegradingLoan = new CalculateMaximumAmountToRegradingLoanStrategy(pCCo, pContract.Copy(), pUser, _generalSettings, _nWds);
            _amountToRepayInstallment = new CalculateAmountToRepaySpecifiedInstallmentStrategy(pCCo, pContract.Copy(), pUser, _generalSettings, _nWds);

            _calculateInstallments = new Repayment.RepayLateInstallments.CalculateInstallments(pCCo, pContract, pUser, _generalSettings, _nWds);
            _feesForAnticipatedRepayment = new CalculateAnticipatedFeesStrategy(pCCo, pContract, _generalSettings);
            _repayNextInstallments = new RepayNextInstallmentsStrategy(pContract, pCCo, pUser, _generalSettings);
            _repaymentMethod = new RepaymentMethod(pContract,pCCo);

            CalculateMaximumAmountAuthorizedToRepay();
            CalculateAmountToRegradingLoan();
            CalculateMaximumAmountForEscapedMember();
            LoanOptions = pCCo;
        }
        public void FlatRate_MonthlyInstallmentType_ExoticInstallments_GracePeriod_RoundingInterest_RoundingCapital()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0.1, 0.1),
                    new ExoticInstallment(2, 0.1, 0.1),
                    new ExoticInstallment(3, 0.1, 0.5),
                    new ExoticInstallment(4, 0.1, 0.1),
                    new ExoticInstallment(5, 0.1, 0.1),
                    new ExoticInstallment(6, 0.5, 0.1)
                },
                Currency = new Currency {
                    Id = 1
                }
            };

            Loan myContract = new Loan(package, 987, 0.03m, 8, 2, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30, 0, 987);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 29, 0, 987);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 18, 99, 987);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 18, 98, 888);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 89, 99, 790);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 18, 99, 691);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 18, 98, 592);
            _AssertSpecifiedInstallment(myContract.GetInstallment(7), 8, new DateTime(2006, 9, 1), 17, 494, 494);
        }
        private static Loan _SetContract(OLoanTypes pLoansType, NonRepaymentPenalties pNonRepaymentFees, bool pKeepExpectedInstallment, bool useCents)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = pLoansType,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = useCents
                }
            };

            package.KeepExpectedInstallment = pKeepExpectedInstallment;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = false;
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.NonRepaymentPenalties = pNonRepaymentFees;
            return(myContract);
        }
        public void LateFeesCalculation_OverdueInterest()
        {
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", false);
            Loan myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0, 0, 0.003), true, true);

            Assert.AreEqual(2.52m, CalculationBaseForLateFees.FeesBasedOnOverdueInterest(myContract, new DateTime(2006, 3, 5), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value); // 30 * 0.003 * 28 = 2.88m

            //CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", true);
            myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0, 0, 0.003), true, true);
            Assert.AreEqual(2.88m, CalculationBaseForLateFees.FeesBasedOnOverdueInterest(myContract, new DateTime(2006, 3, 5), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value); // 30 * 0.003 * 32 = 2.88m
        }
        public void DecliningRate_ExoticInstallments_NoGracePeriod_RoundingCapital_RoundingInterest()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0.1, null),
                    new ExoticInstallment(2, 0.1, null),
                    new ExoticInstallment(3, 0.1, null),
                    new ExoticInstallment(4, 0.1, null),
                    new ExoticInstallment(5, 0.1, null),
                    new ExoticInstallment(6, 0.5, null)
                },
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };

            Loan myContract = new Loan(package, 954, 0.03m, 6, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 28.62m, 95.40m, 954);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 25.76m, 95.40m, 858.6m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 22.90m, 95.40m, 763.2m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 20.03m, 95.40m, 667.8m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 17.17m, 95.40m, 572.4m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 14.31m, 477, 477);
        }
        public void DecliningRate_FixedInstallment_NoGracePeriod_RoundingProblem()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                },
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 100, 0.01m, 10, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 1, 9.56m, 100, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 0.9m, 9.66m, 90.44m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 0.81m, 9.75m, 80.78m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 0.71m, 9.85m, 71.03m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 0.61m, 9.95m, 61.18m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 0.51m, 10.05m, 51.23m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 0.41m, 10.14m, 41.18m, 10.55m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(7), 8, new DateTime(2006, 9, 1), 0.31m, 10.24m, 31.04m, 10.55m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(8), 9, new DateTime(2006, 10, 2), 0.21m, 10.35m, 20.8m, 10.56m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(9), 10, new DateTime(2006, 11, 1), 0.1m, 10.45m, 10.45m, 10.55m);
        }
Пример #11
0
        public CreditContractRepayment(Loan contract, CreditContractOptions creditOptions, DateTime pDate, int pInstallmentNumber, User user, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate)
        {
            _generalSettings = pGeneralSettings;
            _nWds            = pNonWorkingDate;

            _date = pDate.Date;
            _installmentNumber = pInstallmentNumber;

            PaidIstallments = new List <Installment>();

            _amountToRepayTotalyLoan  = new CalculateMaximumAmountToRepayStrategy(creditOptions, contract.Copy(), user, _generalSettings, _nWds);
            _amountToRegradingLoan    = new CalculateMaximumAmountToRegradingLoanStrategy(creditOptions, contract.Copy(), user, _generalSettings, _nWds);
            _amountToRepayInstallment = new CalculateAmountToRepaySpecifiedInstallmentStrategy(creditOptions, contract.Copy(), user, _generalSettings, _nWds);

            _calculateInstallments             = new Repayment.RepayLateInstallments.CalculateInstallments(creditOptions, contract, user, _generalSettings, _nWds);
            _calculateRealInterestInstallments = new CalculateRealInterestInstallments(creditOptions, _amountToRepayTotalyLoan, contract, _generalSettings, _nWds);

            _feesForAnticipatedRepayment = new CalculateAnticipatedFeesStrategy(creditOptions, contract, _generalSettings);
            _repayNextInstallments       = new RepayNextInstallmentsStrategy(contract, creditOptions, user, _generalSettings);
            _repaymentMethod             = new RepaymentMethod(contract, creditOptions);

            _loan = contract;

            CalculateMaximumAmountAuthorizedToRepay();
            CalculateAmountToRegradingLoan();
            CalculateMaximumAmountForEscapedMember();
            LoanOptions = creditOptions;
        }
Пример #12
0
 public NonWorkingDateSingleton GetNonWorkingDate()
 {
     return(NonWorkingDateSingleton.GetInstance(CurrentUser.Md5));
 }
        public static OCurrency FeesBasedOnInitialAmount(Loan pContract, DateTime pDate, int pInstallmentNumber, bool pForClosure,
            ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate)
        {
            if (pContract.NonRepaymentPenalties.InitialAmount != 0)
            {

                int pastDueDays = pForClosure ? pContract.CalculatePastDueForClosure(pDate) : pContract.CalculatePastDueSinceLastRepayment(pDate);
                pastDueDays = _CalculatePastDueWithGeneralParameterForRepayment(pastDueDays, pGeneralSettings);
                if (pContract.GracePeriodOfLateFees >= pastDueDays)
                {
                    pastDueDays = 0;
                }
                OCurrency fees = pContract.Amount * Convert.ToDecimal(pContract.NonRepaymentPenalties.InitialAmount) * (double)pastDueDays;

                return pContract.UseCents ? Math.Round(fees.Value, 2) : Math.Round(fees.Value, 0);
            }
            return 0;
        }
        private static OCurrency _CalculateNonRepaymentPenaltiesForClosure(Loan pContract, DateTime pDate, int pInstallmentNumber,
            OLateRepaymentTypes repaymentType, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate)
        {
            Installment installment = pContract.GetInstallment(pInstallmentNumber - 1);
            if (pDate <= installment.ExpectedDate) return 0;

            DateTime baseDate = DateTime.MinValue;

            DateTime dateForInstallment = installment.PaidDate.HasValue ? installment.PaidDate.Value : installment.ExpectedDate;

            if (baseDate == DateTime.MinValue)
            {
                baseDate = dateForInstallment;
            }
            else
            {
                if (baseDate < dateForInstallment)
                    baseDate = dateForInstallment;
            }

            int pstDueDays = (pDate - baseDate).Days < 0 ? 0 : (pDate - baseDate).Days;
            pstDueDays = pstDueDays - CountDaysOff(baseDate, pDate, pGeneralSettings, pNonWorkingDate);

            if(pContract.GracePeriodOfLateFees >= pstDueDays)
            {
                pstDueDays = 0;
            }

            double penalties;
            OCurrency amountHasToPay;

            if (repaymentType == OLateRepaymentTypes.Principal)
            {
                amountHasToPay = installment.PrincipalHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDuePrincipal;
            }
            else if (repaymentType == OLateRepaymentTypes.Interest)
            {
                amountHasToPay = installment.InterestHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDueInterest;
            }
            else if (repaymentType == OLateRepaymentTypes.Olb)
            {
                amountHasToPay = installment.OLB;
                penalties = pContract.NonRepaymentPenalties.OLB;
            }
            else if (repaymentType == OLateRepaymentTypes.Amount)
            {
                amountHasToPay = installment.Amount;
                penalties = pContract.NonRepaymentPenalties.InitialAmount;
            }
            else // Fixed method of late repayments for future implementation; Principal is set for now
            {
                amountHasToPay = installment.PrincipalHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDuePrincipal;
            }

            return amountHasToPay * penalties * pstDueDays;
        }
        private static OCurrency _CalculateNonRepaymentPenalties(Loan pContract, DateTime pDate, int installmentNumber,
            OLateRepaymentTypes repaymentType, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate)
        {
            Installment installment = pContract.GetInstallment(installmentNumber - 1);

            DateTime date = installment.ExpectedDate;

            foreach (RepaymentEvent rPayment in pContract.Events.GetRepaymentEvents())
            {
                if (rPayment.Date == pDate && rPayment.Deleted == false && installmentNumber == rPayment.InstallmentNumber)
                {
                    date = pDate;
                }

                if (rPayment.InstallmentNumber <= installment.Number && rPayment.Deleted == false && rPayment.Date != pDate && pDate > installment.ExpectedDate && installment.PaidFees != 0)
                {
                    date = rPayment.Date <= installment.ExpectedDate ? installment.ExpectedDate : rPayment.Date;
                }
            }

            int nbOfDays = (pDate - date).Days < 0 ? 0 : (pDate - date).Days;
            nbOfDays = nbOfDays - CountDaysOff(date, pDate, pGeneralSettings, pNonWorkingDate);
            nbOfDays = _CalculatePastDueWithGeneralParameterForRepayment(nbOfDays, pGeneralSettings);

            if (pContract.GracePeriodOfLateFees >= nbOfDays)
            {
                nbOfDays = 0;
            }

            double penalties;
            OCurrency amountHasToPay;

            if (repaymentType == OLateRepaymentTypes.Principal)
            {
                amountHasToPay = installment.PrincipalHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDuePrincipal;
            }
            else if (repaymentType == OLateRepaymentTypes.Interest)
            {
                amountHasToPay = installment.InterestHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDueInterest;
            }
            else if (repaymentType == OLateRepaymentTypes.Olb)
            {
                amountHasToPay = installment.OLB;
                penalties = pContract.NonRepaymentPenalties.OLB;
            }
            else if (repaymentType == OLateRepaymentTypes.Amount)
            {
                amountHasToPay = installment.Amount;
                penalties = pContract.NonRepaymentPenalties.InitialAmount;
            }
            else // Fixed method of late repayments for future implementation; Principal is set for now
            {
                amountHasToPay = installment.PrincipalHasToPay;
                penalties = pContract.NonRepaymentPenalties.OverDuePrincipal;
            }

            return amountHasToPay * penalties * nbOfDays;
        }
        public static OCurrency CalculateAnticipateRepayment(Loan pContract, DateTime pDate, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate, OPaymentType pPaymentType)
        {
            Installment pInstallment = null;
            OCurrency interests = 0;
            Installment priorInstallment;
            OCurrency olb = 0;
            OCurrency fees = 0;
            OCurrency ammountHasToPay = 0;

            for (int i = 0; i < pContract.NbOfInstallments; i++)
            {
                Installment installment = pContract.GetInstallment(i);

                if (!installment.IsRepaid && installment.ExpectedDate > pDate)
                {
                    if (pInstallment == null)
                    {
                        pInstallment = installment;

                        if (olb == 0)
                        {
                            olb = pContract.CalculateExpectedOlb(pInstallment.Number, false);
                        }

                        //is case APR on the first installment
                        DateTime expectedDate;

                        if (i == 0)
                        {
                            expectedDate = pContract.StartDate;
                        }
                        else
                        {
                            priorInstallment = pContract.GetInstallment(i - 1);
                            expectedDate = priorInstallment.ExpectedDate;
                        }

                        int daySpan = (pDate - expectedDate).Days < 0 ? 0 : (pDate - expectedDate).Days;
                        int daysInMonth = DateTime.DaysInMonth(pDate.Year, pDate.Month);

                        if (pGeneralSettings.AccountingProcesses == OAccountingProcesses.Accrual)
                        {
                            interests = pInstallment.InterestsRepayment * daySpan / daysInMonth;
                        }
                        else
                        {
                            interests = pInstallment.ExpectedDate > pDate ? 0 : pInstallment.InterestsRepayment;
                        }
                    }

                    fees += CalculateCommision(pContract, pDate, installment.Number, pPaymentType, pGeneralSettings);
                }

                if (!installment.IsRepaid && installment.ExpectedDate <= pDate)
                {
                    ammountHasToPay += installment.InterestsRepayment + installment.PrincipalHasToPay;
                }
            }

            if (interests != 0)
                interests = pContract.UseCents ? Math.Round(interests.Value, 2) : Math.Round(interests.Value, 0);

            OCurrency amount = interests + fees + ammountHasToPay;

            return amount;
        }
        private static int CountDaysOff(DateTime beginDate, DateTime endDate, ApplicationSettings pGeneralSettings, 
            NonWorkingDateSingleton pNonWorkingDate)
        {
            var dt = new DateTime();
            int countDayOff = 0;

            if (!pGeneralSettings.IsCalculationLateFeesDuringHolidays)
            {
                //count day off
                for (int day = 1; day <= (endDate - beginDate).Days; day++)
                {
                    //week end
                    if (!pGeneralSettings.DoNotSkipNonWorkingDays)
                    if (((int)(dt.DayOfWeek) == pGeneralSettings.WeekEndDay1) || ((int)(dt.DayOfWeek) == pGeneralSettings.WeekEndDay2))
                        countDayOff++;

                    //holidays
                    countDayOff += pNonWorkingDate.PublicHolidays.Keys.Count(publicHoliday => dt == publicHoliday);
                    dt = beginDate.AddDays(day);
                }
            }

            return countDayOff;
        }
        public static OCurrency AnticipateFeesBasedOnOverdueInterest(Loan pContract, DateTime pDate, int pInstallmentNumber, bool pForClosure, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate, OPaymentType pPaymentType)
        {
            OCurrency fees = _AnticipateCalculateNonRepaymentPenalties(pContract, pDate, pInstallmentNumber, pPaymentType, pGeneralSettings);

            return fees.Value;
        }
        private static Loan _SetContract(OAnticipatedRepaymentPenaltiesBases pAnticipatedRepaymentBase, double pAnticipated, bool pKeepExpectedInstallment)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,

                KeepExpectedInstallment = pKeepExpectedInstallment,
                AnticipatedTotalRepaymentPenaltiesBase = pAnticipatedRepaymentBase,
                Currency = new Currency {
                    Id = 1
                }
            };

            return(new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                BadLoan = false,
                AnticipatedTotalRepaymentPenalties = pAnticipated,
                NonRepaymentPenalties = { InitialAmount = 0.003 }
            });
        }
 public NonWorkingDateManagement(string testDB) : base(testDB)
 {
     dbParam = ApplicationSettings.GetInstance("");
     nonWorkingDateHelper = NonWorkingDateSingleton.GetInstance("");
 }
Пример #21
0
        public void RepayInstallments_DontCancelFees_InitialAmount_RepaymentTwicelyADay()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "10-days", 10, 0),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };

            package.KeepExpectedInstallment = true;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;

            Loan myContract = new Loan(package, 8000, 0.03333m, 5, 0, new DateTime(2010, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = false;
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.NonRepaymentPenalties = new NonRepaymentPenalties(0, 0, 0.0667, 0.01);

            myContract.CalculateInstallments(true);

            myContract.Disburse(new DateTime(2010, 1, 1), false, true);
            myContract.Repay(1, new DateTime(2010, 1, 8), 30, false, true);

            RepaymentEvent rPE = myContract.Repay(1, new DateTime(2010, 1, 11), 0, false, true);

            Assert.AreEqual(rPE.Penalties, 0);
        }
        public static OCurrency FeesBasedOnOverduePrincipal(Loan pContract, DateTime pDate, int pInstallmentNumber, bool pForClosure, 
            ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate)
        {
            if (pContract.NonRepaymentPenalties.OverDuePrincipal != 0)
            {
                OCurrency fees = pForClosure
                    ? _CalculateNonRepaymentPenaltiesForClosure(pContract, pDate, pInstallmentNumber, OLateRepaymentTypes.Principal,
                    pGeneralSettings, pNonWorkingDate)
                    : _CalculateNonRepaymentPenalties(pContract, pDate, pInstallmentNumber, OLateRepaymentTypes.Principal,
                    pGeneralSettings, pNonWorkingDate);

                return pContract.UseCents ? Math.Round(fees.Value, 2) : Math.Round(fees.Value, 0);
            }
            return 0;
        }
        public void DecliningRate_FixedInstallment_NoGracePeriod_RoundingTypeEnd()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                },
                RoundingType = ORoundingType.End
            };

            Loan myContract = new Loan(package, 10000, 0.05m, 6, 0, new DateTime(2010, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2010, 2, 1), 500, 1470, 10000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2010, 3, 1), 427, 1543, 8530);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2010, 4, 1), 349, 1621, 6987);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2010, 5, 3), 268, 1702, 5366);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2010, 6, 1), 183, 1787, 3664);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2010, 7, 1), 94, 1877, 1877);
        }
Пример #24
0
        public void FlatRate_MonthlyInstallmentType_NoGracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                },
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            Assert.AreEqual(6, myContract.InstallmentList.Count);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30.00m, 166.67m, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30.00m, 166.67m, 833.33m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 30.00m, 166.67m, 666.66m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 30.00m, 166.66m, 499.99m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 30.00m, 166.67m, 333.33m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 30.00m, 166.66m, 166.66m);
        }
        public void DecliningRate_FixedInstallment_NoGracePeriodCheckRounding()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                },
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 1000, 0.02m, 6, 0, new DateTime(2010, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2010, 2, 1), 20, 159, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2010, 3, 1), 17, 161, 841);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2010, 4, 1), 14, 165, 680);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2010, 5, 3), 10, 169, 515);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2010, 6, 1), 7, 171, 346);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2010, 7, 1), 4, 175, 175);
        }
        public void DecliningRate_FixedInstallments_GracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Bi-Weekly", 14, 0),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                },
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            Assert.AreEqual(1000, _CheckInstalmentsTotalPrincipal(myContract).Value);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 1, 16), 32.14m, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 1, 30), 30.00m, 154.60m, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 2, 13), 25.36m, 159.24m, 845.40m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 2, 27), 20.58m, 164.02m, 686.16m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 3, 13), 15.66m, 168.93m, 522.14m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 3, 27), 10.60m, 173.99m, 353.21m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 4, 10), 5.38m, 179.22m, 179.22m);
        }
        public void DecliningRate_FixedPrincipal_NoGracePeriod_BiWeekly()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Bi-Weekly", 14, 0),
                LoanType        = OLoanTypes.DecliningFixedPrincipal,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 5, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 1, 16), 32, 200, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 1, 30), 24, 200, 800);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 2, 13), 18, 200, 600);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 2, 27), 12, 200, 400);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 3, 13), 6, 200, 200);
        }
        public void DecliningRate_ExoticInstallments_GracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0.1, null),
                    new ExoticInstallment(2, 0.1, null),
                    new ExoticInstallment(3, 0.1, null),
                    new ExoticInstallment(4, 0.1, null),
                    new ExoticInstallment(5, 0.1, null),
                    new ExoticInstallment(6, 0.5, null)
                },
                Currency = new Currency {
                    Id = 1
                }
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30.00m, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30.00m, 100.00m, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 27.00m, 100.00m, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 24.00m, 100.00m, 800);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 21.00m, 100.00m, 700);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 18.00m, 100.00m, 600);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 15.00m, 500.00m, 500);
        }
        public void DecliningRate_ExoticInstallments_NoGracePeriod_RoundingValue()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0.1, null),
                    new ExoticInstallment(2, 0.1, null),
                    new ExoticInstallment(3, 0.1, null),
                    new ExoticInstallment(4, 0.1, null),
                    new ExoticInstallment(5, 0.1, null),
                    new ExoticInstallment(6, 0.5, null)
                },
                Currency = new Currency {
                    Id = 1
                }
            };
            Loan myContract = new Loan(package, 950, 0.03m, 6, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 28, 95, 950);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 26, 95, 855);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 23, 95, 760);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 20, 95, 665);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 17, 95, 570);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 14, 475, 475);
        }
        public void LateFeesCalculation_OverduePrincipal()
        {
            Loan myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0, 0.003, 0), true, false);

            Assert.AreEqual(0m, CalculationBaseForLateFees.FeesBasedOnOverdueInterest(myContract, new DateTime(2006, 3, 5), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value);//0 (1st installment without interest) * 0.003 * 32 = 0
        }
        public void TestCalculateInstallmentDateWhenWeekEndDay2IsSunday()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 0, new DateTime(2006, 6, 30), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            Assert.AreEqual(new DateTime(2006, 7, 31), myContract.CalculateInstallmentDate(myContract.StartDate, 1));
        }
        public void LateFeesCalculation_OLB()
        {
            Loan myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0.003, 0, 0), true, false);

            Assert.AreEqual(12m, CalculationBaseForLateFees.FeesBasedOnOlb(myContract, new DateTime(2006, 2, 5), 1, false,
                                                                           ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value); // 1000 * 0.003 * 4 = 12
        }
        public void DecliningRate_FixedInstallment_GracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                },
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 3, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 30, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 30, 324, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 20, 333, 676);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 10, 343, 343);
        }
        private static Loan GetContract(OCurrency pAmount, int pNumberOfInstallments, decimal pRate, int pGracePeriod, bool pChargeInterestDuringGracePeriod)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = pChargeInterestDuringGracePeriod,
                Currency = new Currency {
                    Id = 1
                }
            };

            return(new Loan(package, pAmount, pRate, pNumberOfInstallments, pGracePeriod, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())));
        }
        public void FlatRate_BiWeeklyInstallmentType_GracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Bi-Weekly", 14, 0),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 2, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 1, 16), 32.14m, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 1, 30), 30.00m, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 2, 13), 30.00m, 250, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 2, 27), 30.00m, 250, 750);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 3, 13), 30.00m, 250, 500);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 3, 27), 30.00m, 250, 250);
        }
 public NonWorkingDateManagement(User pUser) : base(pUser)
 {
     _user   = pUser;
     dbParam = ApplicationSettings.GetInstance(pUser.Md5);
     nonWorkingDateHelper = NonWorkingDateSingleton.GetInstance(_user.Md5);
 }
        public void FlatRate_ExoticInstallments_GracePeriod_50PercentMiddle_50PercentEnd()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,

                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0, 0),
                    new ExoticInstallment(2, 0, 0),
                    new ExoticInstallment(3, 0.5, 0.5),
                    new ExoticInstallment(4, 0, 0),
                    new ExoticInstallment(5, 0, 0),
                    new ExoticInstallment(6, 0.5, 0.5)
                },
                Currency = new Currency {
                    Id = 1
                }
            };

            Loan myContract = new Loan(package, 1000, 0.02m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 20.00m, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 0, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 0, 0, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 60, 500, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 0, 0, 500);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 0, 0, 500);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 60, 500, 500);
        }
Пример #38
0
        private static OpenCBS.CoreDomain.Contracts.Loans.LoanRepayment.Repayment.RepayLateInstallments.CalculateInstallments _SetRepaymentOptions(Loan pContract, bool pCancelFees)
        {
            CreditContractOptions cCO = new CreditContractOptions(pContract.Product.LoanType, pContract.Product.KeepExpectedInstallment, pCancelFees, 0, 0, false, 0,
                                                                  pContract.Product.AnticipatedTotalRepaymentPenaltiesBase);

            return(new OpenCBS.CoreDomain.Contracts.Loans.LoanRepayment.Repayment.RepayLateInstallments.CalculateInstallments(cCO, pContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")));
        }
Пример #39
0
        public Loan(LoanProduct pAckage, OCurrency pAmount, double pInterestRate, int pNbOfInstallments, int pGracePeriod,
                      DateTime pStartDate, DayOfWeek? meetingDay, User pUser, ApplicationSettings pGeneralSettings,
                        NonWorkingDateSingleton pNwds, ProvisionTable pPt, ChartOfAccounts pChartOfAccounts)
        {
            _user = pUser;
            _generalSettings = pGeneralSettings;
            _nwdS = pNwds;
            Product = pAckage;

            NonRepaymentPenalties = new NonRepaymentPenalties();
            _events = new EventStock();
            _guarantors = new List<Guarantor>();
            _collaterals = new List<ContractCollateral>();
            _installmentType = pAckage.InstallmentType;
            _amount = pAmount;
            _interestRate = pInterestRate;
            _nbOfInstallments = pNbOfInstallments;
            GracePeriod = pGracePeriod;
            CreationDate = pStartDate;
            _startDate = pStartDate;

            _firstInstallmentDate = CalculateInstallmentDate(pStartDate, 1);
            if (meetingDay.HasValue)
                _firstInstallmentDate = GetMeetingDate(_firstInstallmentDate, meetingDay);

            _alignAlignDisbursementDate = CalculateAlignDisbursementDate(_firstInstallmentDate);

            //with this constructor, installment are directly calculated when a new CreditContract is instanciated
            _installmentList = CalculateInstallments(true);
            EntryFeesPercentage = pAckage.EntryFeesPercentage;
        }
        public void TestCalculateMaximumAmountWithFlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithoutInterestAndKeepExpectedInstallment()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };

            package.KeepExpectedInstallment = true;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.OverDuePrincipal = 0.003;
            myContract.AnticipatedTotalRepaymentPenalties     = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, 0, false, 0, package.AnticipatedTotalRepaymentPenaltiesBase);

            this.repayStrategy = new CalculateMaximumAmountToRegradingLoanStrategy(cCO, myContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, false);
            //30 + 230 + 200 * 0.003 * 12 = 268.4 => 267
            // Assert.AreEqual(267, Math.Round(this.repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
            Assert.AreEqual(267, Math.Round(this.repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 0));

            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            //30 + 230 + 200 * 0.003 * 14 = 268.4 => 268
            Assert.AreEqual(268, Math.Round(this.repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
        }
        public static OCurrency AnticipateFeesBasedOnOlb(Loan pContract, DateTime pDate, int pInstallmentNumber, bool pForClosure, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNonWorkingDate, OPaymentType pPaymentType)
        {
            OCurrency fees = AnticipateCalculateFeesBasedOnOlb(pContract, pDate, pInstallmentNumber, pPaymentType);

            return pContract.UseCents ? Math.Round(fees.Value, 2) : Math.Round(fees.Value, 0);
        }
        public void FlatRate_ExoticInstallments_GracePeriod_RoundingInterest()
        {
            LoanProduct package = new LoanProduct {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,

                ExoticProduct = new ExoticInstallmentsTable
                {
                    new ExoticInstallment(1, 0.1, 0.1),
                    new ExoticInstallment(2, 0.1, 0.1),
                    new ExoticInstallment(3, 0.1, 0.1),
                    new ExoticInstallment(4, 0.1, 0.1),
                    new ExoticInstallment(5, 0.1, 0.1),
                    new ExoticInstallment(6, 0.5, 0.5)
                },
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };

            Loan myContract = new Loan(package, 900, 0.026m, 9, 3, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 23.4m, 0, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 23.4m, 0, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 23.4m, 0, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 14.04m, 90.00m, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 14.04m, 90.00m, 810);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 14.04m, 90.00m, 720);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 14.04m, 90.00m, 630);
            _AssertSpecifiedInstallment(myContract.GetInstallment(7), 8, new DateTime(2006, 9, 1), 14.04m, 90.00m, 540);
            _AssertSpecifiedInstallment(myContract.GetInstallment(8), 9, new DateTime(2006, 10, 2), 70.20m, 450.00m, 450);
        }
        public void TestCalculateMaximumAmountWithDecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithInterestAndKeepNotExpectedInstallment()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                },
                RoundingType = ORoundingType.Approximate
            };

            package.KeepExpectedInstallment = false;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.OverDueInterest  = 0.003;
            myContract.NonRepaymentPenalties.OverDuePrincipal = 0.003;
            myContract.AnticipatedTotalRepaymentPenalties     = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, 0, false, 0, package.AnticipatedTotalRepaymentPenaltiesBase);

            repayStrategy = new CalculateMaximumAmountToRegradingLoanStrategy(cCO, myContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            //30 + 218.35 + 30 * 0.003 * 42 + 218.35 * 0.003 * 14 = 30 + 218 + 4 + 9 = 261
            Assert.AreEqual(261, Math.Round(repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
        }
        public void TestCalculateMaximumAmountWithFlateBadLoanWith42DaysLateWhenNonRepaymentFeesBaseOnInitialAmountAndKeepExpectedInstallmentAndCancelFeesSetToFalse()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };

            package.KeepExpectedInstallment = true;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 0.0123;
            myContract.AnticipatedTotalRepaymentPenalties  = 0.01;

            //42 days late
            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, 0, false, 0, package.AnticipatedTotalRepaymentPenaltiesBase);

            this.repayStrategy = new CalculateMaximumAmountToRegradingLoanStrategy(cCO, myContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            //30 + 230 + 1000 * 0.0123 * 42 = 776.6 => 777
            //  Assert.AreEqual(777, Math.Round(this.repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
            Assert.AreEqual(777, Math.Round(this.repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 0));
        }
Пример #45
0
        /// <summary>
        /// Instancy a new CreditContract. Use it if installments need'nt calculate 
        /// </summary>
        /// <param name="pUser"></param>
        /// <param name="pGeneralSettings"></param>
        /// <param name="pNwds"></param>
        /// <param name="pPt"></param>
        /// <param name="pChartOfAccounts"></param>
        public Loan(User pUser, ApplicationSettings pGeneralSettings, NonWorkingDateSingleton pNwds, ProvisionTable pPt, ChartOfAccounts pChartOfAccounts)
        {
            _user = pUser;
            _generalSettings = pGeneralSettings;
            _nwdS = pNwds;

            NonRepaymentPenalties = new NonRepaymentPenalties();
            _installmentList = new List<Installment>();
            _guarantors = new List<Guarantor>();
            _collaterals = new List<ContractCollateral>();
            _events = new EventStock();
            EntryFeesPercentage = true;
        }