Example #1
0
 private static OCurrency _ExpensesLoanLossBalance(Loan pCredit,ProvisionTable pProvisionningTable)
 {
     if (pCredit.Disbursed && !pCredit.AllInstallmentsRepaid && !pCredit.WrittenOff)
         return pCredit.Amount * Convert.ToDecimal(pProvisionningTable.GetProvisiningRateByNbOfDays(0).Rate);
     else
         return 0;
 }
Example #2
0
        private static OCurrency _IncomeLoanLossBalance(Loan pCredit, ProvisionTable pProvisionningTable)
        {
            OCurrency olb = pCredit.GetOlb();
            OCurrency rate = Convert.ToDecimal(pProvisionningTable.GetProvisiningRateByNbOfDays(0).Rate);
            if (pCredit.GetPastDueDays(TimeProvider.Today) != 0) olb = 0;
            if (pCredit.WrittenOff) return 0;

            if (!pCredit.Disbursed) return 0;

            if (pCredit.AllInstallmentsRepaid) return 0;

            if (!pCredit.BadLoan) return (pCredit.Amount - olb) * rate;

            else return (pCredit.Amount) * rate;
        }
Example #3
0
        public static bool CheckDegradeToBadLoan(Loan pLoan, ApplicationSettings settings, ProvisionTable pProvisionTable, DateTime pDate, bool authorizeSeveralPastDueEventByPeriod, int? pPstDueDays,User pUser)
        {
            DateTime date;
            int pastDueDays;
            if (pPstDueDays.HasValue)
            {
                pastDueDays = pPstDueDays.Value;
                date = pDate.AddDays(pastDueDays - pLoan.GetPastDueDays(pDate));
            }
            else
            {
                date = pDate;
                pastDueDays = pLoan.GetPastDueDays(date);
            }

            //In this case, the loan is not considered as bad loan
            if (pastDueDays < PAST_DUE_MIN_DAYS)
            {
                return false;
            }

               //A loan is only degraded from cash credit to bad loan one time
            OCurrency cashBalance = 0; //pLoan.ChartOfAccounts.GetAccountByNumber(OAccounts.CASH_CREDIT, pLoan.Product.Currency.Id, pLoan, OBookingDirections.Both).Balance;
            if (cashBalance != 0)
            {
                pLoan.BadLoan = true;
            }
            else
            {
                //Downgrading the loan to unrecoverable bad loans is done once for loan with past due days greater than 180
                if (pastDueDays > settings.BadLoanDays)
                {
                    pLoan.BadLoan = true;
                }
            }
            return true;
        }
        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())));
        }
Example #5
0
        public Settings GetCurrentSettings(bool pIncludePackages)
        {
            Settings settings = new Settings();
            // General parameters
            SettingGroup generalParameters = new SettingGroup(GENERAL_PARAMETERS);

            settings.Add(generalParameters);
            ApplicationSettings gp = ApplicationSettings.GetInstance(_user.Md5);


            generalParameters.Add(new Setting(OGeneralSettings.ACCOUNTINGPROCESS, ((int)gp.AccountingProcesses).ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.ALLOWSMULTIPLELOANS, gp.IsAllowMultipleLoans.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.ALLOWSMULTIPLEGROUPS, gp.IsAllowMultipleGroups.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.BAD_LOAN_DAYS, gp.BadLoanDays.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, gp.IsCalculationLateFeesDuringHolidays.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.CEASE_LAIE_DAYS, gp.CeaseLateDays.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.CONTRACT_CODE_TEMPLATE, gp.ContractCodeTemplate));
            generalParameters.Add(new Setting(OGeneralSettings.COUNTRY, gp.Country));
            generalParameters.Add(new Setting(OGeneralSettings.AUTOMATIC_ID, gp.IsAutomaticID.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.DONOTSKIPWEEKENDSININSTALLMENTSDATE, gp.DoNotSkipNonWorkingDays.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.ENFORCE_ID_PATTERN, gp.EnforceIDPattern.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.GROUPMINMEMBERS, gp.GroupMinMembers.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.GROUPMAXMEMBERS, gp.GroupMaxMembers.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.VILLAGEMINMEMBERS, gp.VillageMinMembers.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.VILLAGEMAXMEMBERS, gp.VillageMaxMembers.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.CLIENT_AGE_MIN, gp.ClientAgeMin.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.CLIENT_AGE_MAX, gp.ClientAgeMax.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.MAX_LOANS_COVERED, gp.MaxLoansCovered.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.MAX_GUARANTOR_AMOUNT, gp.MaxGuarantorAmount.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.ID_PATTERN, gp.IDPattern));
            generalParameters.Add(new Setting(OGeneralSettings.INTERESTS_ALSO_CREDITED_IN_FL, gp.InterestsCreditedInFL.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.INCREMENTALDURINGDAYOFF, gp.IsIncrementalDuringDayOff.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.LATEDAYSAFTERACCRUALCEASES, gp.LateDaysAfterAccrualCeases.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.MAX_NUMBER_INSTALLMENT, gp.MaxNumberInstallment.ToString()));;
            generalParameters.Add(new Setting(OGeneralSettings.MFI_NAME, gp.MfiName));

            generalParameters.Add(new Setting(OGeneralSettings.OLBBEFOREREPAYMENT, gp.IsOlbBeforeRepayment.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.PAYFIRSTINSTALLMENTREALVALUE, gp.PayFirstInterestRealValue.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.PENDING_SAVINGS_MODE, gp.PendingSavingsMode));

            generalParameters.Add(new Setting(OGeneralSettings.SAVINGS_CODE_TEMPLATE, gp.SavingsCodeTemplate));

            generalParameters.Add(new Setting(OGeneralSettings.VAT_RATE, gp.VatRate.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.WEEKENDDAY1, gp.WeekEndDay1.ToString()));
            generalParameters.Add(new Setting(OGeneralSettings.WEEKENDDAY2, gp.WeekEndDay2.ToString()));

            generalParameters.Add(new Setting(OGeneralSettings.INTEREST_RATE_DECIMAL_PLACES, Convert.ToString(gp.InterestRateDecimalPlaces)));
            generalParameters.Add(new Setting(OGeneralSettings.STOP_WRITEOFF_PENALTY, Convert.ToString(gp.IsStopWriteOffPenalty.ToString())));
            generalParameters.Add(new Setting(OGeneralSettings.MODIFY_ENTRY_FEE, Convert.ToString(gp.ModifyEntryFee.ToString())));

            // Provisioning Rules
            SettingGroup provisioningRules = new SettingGroup(PROVISIONING_RULES);

            settings.Add(provisioningRules);
            foreach (ProvisioningRate prate in ProvisionTable.GetInstance(_user).ProvisioningRates)
            {
                provisioningRules.Add(new Setting(prate.Number.ToString(), String.Format("{0}/{1}/{2}/{3}/{4}",
                                                                                         prate.NbOfDaysMin,
                                                                                         prate.NbOfDaysMax,
                                                                                         prate.ProvisioningValue,
                                                                                         prate.ProvisioningInterest,
                                                                                         prate.ProvisioningPenalty)));
            }

            // Public Holidays
            SettingGroup publicHolidays = new SettingGroup(PUBLIC_HOLIDAYS);

            settings.Add(publicHolidays);
            foreach (DateTime entry in ServicesProvider.GetInstance().GetNonWorkingDate().PublicHolidays.Keys)
            {
                publicHolidays.Add(new Setting(ServicesProvider.GetInstance().GetNonWorkingDate().PublicHolidays[entry], (entry).ToString("dd/MM/yyyy")));
            }
            //if (pIncludePackages)
            //{
            //    // Packages
            //    SettingGroup packages = new SettingGroup(PACKAGES);
            //    settings.Add(packages);
            //    List<LoanProduct> allPackages = new ProductServices(_user).FindAllPackages(false, OClientTypes.Both);
            //    foreach (LoanProduct package in allPackages)
            //    {
            //        Setting p = new Setting(package.Name, null);
            //        //p.Package = package;
            //        packages.Add(p);
            //    }
            //}
            return(settings);
        }
Example #6
0
        private static OCurrency _LoanLossReserveBalance(Loan pCredit, ProvisionTable pProvisionningTable, int writeOffDays)
        {
            OCurrency theoricBalance = 0;
            if (!pCredit.Disbursed) return theoricBalance;

            if (pCredit.GetPastDueDays(TimeProvider.Today) == 0) return theoricBalance;
            if (pCredit.GetPastDueDays(TimeProvider.Today) > writeOffDays) return theoricBalance;

            foreach (Installment installment in pCredit.InstallmentList)
            {
                if (installment.ExpectedDate >= TimeProvider.Today)
                    break;
                theoricBalance += (installment.InterestsRepayment - installment.PaidInterests);
            }

            theoricBalance += pCredit.GetUnpaidLatePenalties(TimeProvider.Today);

            int pastDueDays = pCredit.GetPastDueDays(TimeProvider.Today);
            theoricBalance += pCredit.GetOlb() * Convert.ToDecimal(pProvisionningTable.GetProvisiningRateByNbOfDays(pastDueDays).Rate);

            OCurrency realBalance = 0;
            return theoricBalance > realBalance ? theoricBalance : realBalance;
        }
Example #7
0
        public static OCurrency GetStockBalance(Loan pCredit, ApplicationSettings settings, ProvisionTable pProvisionningTable, string pAccountNumber)
        {
            OCurrency balance = 0;

            return balance;
        }
        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);
        }
Example #9
0
        public ProvisionEvent GetProvisionEvent(DateTime dateTime, ProvisionTable provisionTable)
        {
            int lateDays = CalculatePastDueSinceLastRepayment(dateTime);
            OCurrency rate = 0;

            foreach (ProvisioningRate provisioningRate in provisionTable.ProvisioningRates)
            {
                if(lateDays >= provisioningRate.NbOfDaysMin && lateDays <= provisioningRate.NbOfDaysMax)
                {
                    rate = (decimal)provisioningRate.Rate;
                }

                if(Rescheduled && provisioningRate.NbOfDaysMin  < 0 && provisioningRate.NbOfDaysMax < 0)
                {
                    rate = (decimal)provisioningRate.Rate;
                }
            }

            ProvisionEvent provisionEvent = new ProvisionEvent
            {
                Id = 0,
                Code = "LLPE",
                Amount = GetOlb() * rate,
                OverdueDays = lateDays,
                Rate = rate,
                Date = TimeProvider.Now,
                User = User.CurrentUser
            };
            if (provisionEvent.Amount > 0)
            {
                Events.Add(provisionEvent);
                return provisionEvent;
            }
            return null;
        }
        public void FlatRate_ExoticInstallments_NoGracePeriod()
        {
            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
                }
            };

            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()));

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 18.00m, 100.00m, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 18.00m, 100.00m, 900);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 18.00m, 100.00m, 800);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 18.00m, 100.00m, 700);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 18.00m, 100.00m, 600);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 90.00m, 500.00m, 500);
        }
        public void Flate_BadLoan_42dayslate_OnOLB_KeepNotExpectedInstallment()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };

            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.OLB          = 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 + 230 + 1000 * 0.003 * 42 = 386
            Assert.AreEqual(386, Math.Round(repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
        }
        private static Loan _SetContract(OLoanTypes pLoansType, bool pKeepExpectedInstallment, int pGracePeriod, int pMaturity, ExoticInstallmentsTable pExoticProduct)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = pLoansType,
                ChargeInterestWithinGracePeriod = true,
                KeepExpectedInstallment         = pKeepExpectedInstallment,
                ExoticProduct = pExoticProduct,
                AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB,
                Currency = new Currency {
                    Id = 1, UseCents = true
                },
                RoundingType = ORoundingType.Approximate
            };

            return(new Loan(package, 1000, 0.03m, pMaturity, pGracePeriod, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                BadLoan = false,
                AnticipatedTotalRepaymentPenalties = 0.01,
                NonRepaymentPenalties = { InitialAmount = 0.003 }
            });
        }
Example #13
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;
        }
Example #14
0
        public static OCurrency GetStockBalance(Loan pCredit, ApplicationSettings settings, ProvisionTable pProvisionningTable, string pAccountNumber)
        {
            OCurrency balance = 0;

            return(balance);
        }
        public void FlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithInterestAndKeepNotExpectedInstallment()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };

            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;

            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", true);

            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 + 230 + 30 * 0.003 * 42 + 230 * 0.003 *14

            Assert.AreEqual(273.44m, Math.Round(repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
            //NOT CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", false);



            //30 + 230 + 30 * 0.003 * 36 + 230 * 0.003 *12
            Assert.AreEqual(270.74m, repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value);
        }
        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 void DecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithoutInterestAndKeepExpectedInstallment2()
        {
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", true);

            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
            };

            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);

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

            Assert.AreEqual(256.26m, repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value);
            //30 + 218.35 + 188.35 * 1.003 * 14
            //30+218.3546

            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", false);

            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(""));

            Assert.AreEqual(254.57m, repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value);
        }
Example #18
0
        public void DecliningRate_FixedInstallment_BiWeeklyInstallmentType_NoGracePeriod()
        {
            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, 6, 0, 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, 154.60m, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 1, 30), 25.36m, 159.24m, 845.40m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 2, 13), 20.58m, 164.02m, 686.16m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 2, 27), 15.66m, 168.93m, 522.14m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 3, 13), 10.60m, 173.99m, 353.21m);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 3, 27), 5.38m, 179.22m, 179.22m);
        }
Example #19
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);
        }
Example #20
0
        private static Loan _GetContract_6Month_Flat()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };
            Loan retval = new Loan(package, 1000, 0.02m, 6, 1, new DateTime(2006, 1, 3), new User()
                                   , ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            return(retval);
        }
        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);
        }
Example #22
0
 protected override void SetUp()
 {
     base.SetUp();
     _loanManager = (LoanManager)container["LoanManager"];
     _loan        = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
     {
         ClientType  = OClientTypes.Person,
         LoanOfficer = new User {
             Id = 1
         },
         BranchCode            = "DU",
         CreationDate          = DateTime.Today.AddDays(-1),
         StartDate             = DateTime.Today,
         FirstInstallmentDate  = DateTime.Today.AddDays(1),
         AlignDisbursementDate = DateTime.Today,
         CloseDate             = DateTime.Today.AddDays(1),
         Product = new LoanProduct {
             Id = 1, Currency = new Currency {
                 Id = 1
             }
         },
         Amount          = 1000m,
         InterestRate    = 3,
         InstallmentType = new InstallmentType {
             Id = 1
         },
         NbOfInstallments = 2,
         FundingLine      = new FundingLine {
             Id = 1
         },
         InstallmentList = new List <Installment> {
             _installment1, _installment2
         },
         EconomicActivityId = 1,
         EconomicActivity   = new EconomicActivity {
             Id = 1
         },
         GracePeriodOfLateFees = 0
     };
 }
        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);
        }
Example #24
0
 private static OCurrency _LiabilitiesLoanLossBalance(Loan pCredit, ProvisionTable pProvisionningTable)
 {
     if (pCredit.Disbursed && !pCredit.BadLoan)
         return pCredit.GetPastDueDays(TimeProvider.Today) == 0
                    ? pCredit.GetOlb()* Convert.ToDecimal(pProvisionningTable.GetProvisiningRateByNbOfDays(0).Rate)
                    : 0;
     return 0;
 }
        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);
        }
        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 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 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);
        }
        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));
        }
        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 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);
        }
Example #32
0
 private static OCurrency _ExpensesLoanLossBalance(Loan pCredit, ProvisionTable pProvisionningTable)
 {
     return(pCredit.Disbursed && !pCredit.AllInstallmentsRepaid && !pCredit.WrittenOff
                ? pCredit.Amount * Convert.ToDecimal(pProvisionningTable.GetProvisiningRateByNbOfDays(0).Rate)
                : 0);
 }
        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 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 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 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));
        }
Example #38
0
        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);
        }
Example #39
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;
        }