public List<LoanEntryFee> GetInstalledLoanEntryFees(Loan loan) { _productServices = ServicesProvider.GetInstance().GetProductServices(); List<LoanEntryFee> loanEntryFees = _loanManager.SelectInstalledLoanEntryFees(loan.Id); foreach (LoanEntryFee loanEntryFee in loanEntryFees) { loanEntryFee.ProductEntryFee = _productServices.GetEntryFeeById(loanEntryFee.ProductEntryFeeId); } return loanEntryFees; }
public List<Loan> FindActiveContracts(int pClientId) { _productServices = ServicesProvider.GetInstance().GetProductServices(); List<Loan> loans = _loanManager.SelectActiveLoans(pClientId); // should be reviewed this part of code and moved to correct place, ?????????? foreach (var loan in loans) { if (loan.Id != 0) { loan.LoanEntryFeesList = _loanManager.SelectInstalledLoanEntryFees(loan.Id); foreach (LoanEntryFee fee in loan.LoanEntryFeesList) { fee.ProductEntryFee = _productServices.GetEntryFeeById(fee.ProductEntryFeeId); } } } ////////////////////////////////////////////////////////////////////////////////// return loans; }
public List<LoanEntryFee> GetDefaultLoanEntryFees(Loan loan, IClient client) { _productServices = ServicesProvider.GetInstance().GetProductServices(); List<EntryFee> entryFees = _productServices.GetProductEntryFees(loan.Product, client); var loanEntryFees = new List<LoanEntryFee>(); foreach (EntryFee fee in entryFees) { LoanEntryFee loanFee = new LoanEntryFee(); loanFee.ProductEntryFee = fee; if (fee.Min != null) loanFee.FeeValue = (decimal) fee.Min; else loanFee.FeeValue = (decimal) fee.Value; loanEntryFees.Add(loanFee); } return loanEntryFees; }
public void TestCreationOfIndividualLoanWithLoanCycle() { Person person = new Person(); person.Id = 23456; var loanAmountCycle = GetLoanAmountCycles(); var rateCycles = GetRateCycles(); var maturityCycles = GetMaturityCycles(); LoanProductManager productManager = new LoanProductManager(DataUtil.TESTDB); ProductServices productServices = new ProductServices(productManager); productServices.SaveAllCycleParams(loanAmountCycle, rateCycles, maturityCycles); var entryFees = new List<EntryFee>(); Currency currency = new Currency(); currency.Id = 1; var nrp = new NonRepaymentPenaltiesNullableValues(100, 200, 10, 0.2); LoanProduct product = CreatePackage( "NewPackage", //package name null, //anticipatedTotalRepaymentPenalties 3, //anticipatedTotalRepaymentPenaltiesMin 6, //anticipatedTotalRepaymentPenaltiesMax 4, //grace period null, //gracePeriodMin null, //gracePeriodMax 0.2m, //interestRate null, //interesrRateMin null, //interestRateMax 0, //NmbOfInstallments null, //NmbOfInstallmentsMin null, //NmbOfInstallmentsMax entryFees, //List<EntryFee> nrp, //NonRepaymentPenalties null, //NonRepaymentPenaltiesMin null, //NonRepaymentPenaltiesMax _monthly, //InstallmentType 2000, //amount null, //amountMin null, //AmountMax null, //ExoticInstallmentsTable 2, //cycleId loanAmountCycle, //List<LoanAmountCycle> rateCycles, //List<RateCycle> maturityCycles, //List<MaturityCycle> "CODE1", //ProductCode null, //List<ProductClientType> null, //amountUnderLoc null, //amountUnderLocMin null, //amountUnderLocMax 1, //anticipatedPartialRRepaymentPenalties null, //anticipatedPartialRRepaymentPenaltiesMin null, //anticipatedPartialRRepaymentPenaltiesMax null, //compulsoryAmount null, //compulsoryAmountMin null, //compulsoryAmountMax currency ); Loan credit = new Loan(); credit.Product = product; person.LoanCycle = 0; productServices.SetCyclesParamsForContract(product,credit,person,true); //Cheking loan amount values Assert.AreEqual(product.AmountMin, loanAmountCycle[0].Min.Value); Assert.AreEqual(product.AmountMax, loanAmountCycle[0].Max.Value); //Checking rate values Assert.AreEqual(product.InterestRateMin, rateCycles[0].Min.Value); Assert.AreEqual(product.InterestRateMax, rateCycles[0].Max.Value); //Checking maturity values Assert.AreEqual(product.NbOfInstallmentsMin, maturityCycles[0].Min.Value); Assert.AreEqual(product.NbOfInstallmentsMax, maturityCycles[0].Max.Value); person.LoanCycle = 2; productServices.SetCyclesParamsForContract(product, credit, person, true); //Cheking loan amount values Assert.AreEqual(product.AmountMin, loanAmountCycle[2].Min.Value); Assert.AreEqual(product.AmountMax, loanAmountCycle[2].Max.Value); //Checking rate values Assert.AreEqual(product.InterestRateMin, rateCycles[2].Min.Value); Assert.AreEqual(product.InterestRateMax, rateCycles[2].Max.Value); //Checking maturity values Assert.AreEqual(product.NbOfInstallmentsMin, maturityCycles[2].Min.Value); Assert.AreEqual(product.NbOfInstallmentsMax, maturityCycles[2].Max.Value); person.LoanCycle = 1; productServices.SetCyclesParamsForContract(product, credit, person, true); //Cheking loan amount values Assert.AreEqual(product.AmountMin, loanAmountCycle[1].Min.Value); Assert.AreEqual(product.AmountMax, loanAmountCycle[1].Max.Value); //Checking rate values Assert.AreEqual(product.InterestRateMin, rateCycles[1].Min.Value); Assert.AreEqual(product.InterestRateMax, rateCycles[1].Max.Value); //Checking maturity values Assert.AreEqual(product.NbOfInstallmentsMin, maturityCycles[1].Min.Value); Assert.AreEqual(product.NbOfInstallmentsMax, maturityCycles[1].Max.Value); }
public void TestCreationOfProductWithoutLoanCycles() { Currency currency = new Currency(); currency.Id = 1; var nrp = new NonRepaymentPenaltiesNullableValues(100, 200, 10, 0.2); var entryFees = new List<EntryFee>(); LoanProduct product = CreatePackage( "NewPackage", //package name null, //anticipatedTotalRepaymentPenalties 3, //anticipatedTotalRepaymentPenaltiesMin 6, //anticipatedTotalRepaymentPenaltiesMax 4, //grace period null, //gracePeriodMin null, //gracePeriodMax 0.2m, //interestRate null, //interesrRateMin null, //interestRateMax 0, //NmbOfInstallments null, //NmbOfInstallmentsMin null, //NmbOfInstallmentsMax entryFees, //List<EntryFee> nrp, //NonRepaymentPenalties null, //NonRepaymentPenaltiesMin null, //NonRepaymentPenaltiesMax _monthly, //InstallmentType 2000, //amount null, //amountMin null, //AmountMax null, //ExoticInstallmentsTable null, //cycleId null, //List<LoanAmountCycle> null, //List<RateCycle> null, //List<MaturityCycle> "CODE1", //ProductCode null, //List<ProductClientType> null, //amountUnderLoc null, //amountUnderLocMin null, //amountUnderLocMax 1, //anticipatedPartialRRepaymentPenalties null, //anticipatedPartialRRepaymentPenaltiesMin null, //anticipatedPartialRRepaymentPenaltiesMax null, //compulsoryAmount null, //compulsoryAmountMin null, //compulsoryAmountMax currency ); LoanProductManager productManager = new LoanProductManager(DataUtil.TESTDB); ProductServices productServices = new ProductServices(productManager); productServices.ParseFieldsAndCheckErrors(product, false); }
public void TestAddExoticInstallmentInExoticProductWhenInstallmentIsNull() { ExoticInstallmentsTable product = new ExoticInstallmentsTable(); ExoticInstallment exoticInstallment = new ExoticInstallment(); exoticInstallment.InterestCoeff = null; exoticInstallment.PrincipalCoeff = 0; LoanProductManager productManager = new LoanProductManager(DataUtil.TESTDB); ProductServices productServices = new ProductServices(productManager); productServices.AddExoticInstallmentInExoticProduct(product, exoticInstallment, 1, false); }
public void TestCreatingContractForNonSolidaryGroupWithLoanCycles() { LoanProductManager productManager = new LoanProductManager(DataUtil.TESTDB); ProductServices productServices = new ProductServices(productManager); ClientManager clientManager = new ClientManager(DataUtil.TESTDB); ClientServices clientServices = new ClientServices(clientManager); Village village = new Village(); Person person = clientServices.FindPersonById(2); person.LoanCycle = 0; VillageMember villageMember = new VillageMember(); villageMember.Tiers = person; village.Members.Add(villageMember); person = clientServices.FindPersonById(4); person.LoanCycle = 1; villageMember = new VillageMember(); villageMember.Tiers = person; village.Members.Add(villageMember); person = clientServices.FindPersonById(6); person.LoanCycle = 2; villageMember = new VillageMember(); villageMember.Tiers = person; village.Members.Add(villageMember); var loanAmountCycle = GetLoanAmountCycles(); var maturityCycles = GetMaturityCycles(); var rateCycles = GetRateCycles(); var entryFees = new List<EntryFee>(); Currency currency = new Currency(); currency.Id = 1; var nrp = new NonRepaymentPenaltiesNullableValues(100, 200, 10, 0.2); LoanProduct product = CreatePackage( "NewPackage68", //package name null, //anticipatedTotalRepaymentPenalties 3, //anticipatedTotalRepaymentPenaltiesMin 6, //anticipatedTotalRepaymentPenaltiesMax 4, //grace period null, //gracePeriodMin null, //gracePeriodMax 0.2m, //interestRate null, //interesrRateMin null, //interestRateMax 10, //NmbOfInstallments null, //NmbOfInstallmentsMin null, //NmbOfInstallmentsMax entryFees, //List<EntryFee> nrp, //NonRepaymentPenalties null, //NonRepaymentPenaltiesMin null, //NonRepaymentPenaltiesMax _monthly, //InstallmentType 2000, //amount null, //amountMin null, //AmountMax null, //ExoticInstallmentsTable 2, //cycleId loanAmountCycle, //List<LoanAmountCycle> rateCycles, //List<RateCycle> maturityCycles, //List<MaturityCycle> "CODE1", //ProductCode null, //List<ProductClientType> null, //amountUnderLoc null, //amountUnderLocMin null, //amountUnderLocMax 1, //anticipatedPartialRRepaymentPenalties null, //anticipatedPartialRRepaymentPenaltiesMin null, //anticipatedPartialRRepaymentPenaltiesMax null, //compulsoryAmount null, //compulsoryAmountMin null, //compulsoryAmountMax currency ); product.ClientType = '-'; product.ProductClientTypes = new List<ProductClientType>(); product.AddedEntryFees = entryFees; product.Id=productServices.AddPackage(product); productServices.SaveAllCycleParams(loanAmountCycle, rateCycles, maturityCycles); foreach (VillageMember member in village.Members) { productServices.SetVillageMemberCycleParams(member, product.Id, ((Person)member.Tiers).LoanCycle); } for (int i = 0; i < village.Members.Count; i++) { int j = i; //to avoid index out of range exception (it occurs in product.LoanAmountCycleParams) if (i == product.LoanAmountCycleParams.Count) j = product.LoanAmountCycleParams.Count - 1; Assert.AreEqual(village.Members[i].Product.AmountMin, product.LoanAmountCycleParams[j].Min); Assert.AreEqual(village.Members[i].Product.AmountMax, product.LoanAmountCycleParams[j].Max); Assert.AreEqual(village.Members[i].Product.InterestRateMin, product.RateCycleParams[j].Min.Value); Assert.AreEqual(village.Members[i].Product.InterestRateMax, product.RateCycleParams[j].Max.Value); Assert.AreEqual(village.Members[i].Product.NbOfInstallmentsMin, (int) product.MaturityCycleParams[j].Min.Value); Assert.AreEqual(village.Members[i].Product.NbOfInstallmentsMax, (int) product.MaturityCycleParams[j].Max.Value); } foreach (VillageMember member in village.Members) { Loan loan = new Loan(); loan.LoanPurpose = "Unit tests"; loan.Product = member.Product; loan.Amount = member.Product.AmountMin; loan.AmountMin = member.Product.AmountMin; loan.AmountMax = member.Product.AmountMax; loan.InterestRate = member.Product.InterestRateMin.Value; loan.InterestRateMin = member.Product.InterestRateMin.Value; loan.InterestRateMax = member.Product.InterestRateMax.Value; loan.NbOfInstallments = member.Product.NbOfInstallmentsMin.Value; loan.NmbOfInstallmentsMin = member.Product.NbOfInstallmentsMin.Value; loan.NmbOfInstallmentsMax = member.Product.NbOfInstallmentsMax; loan.StartDate = TimeProvider.Now; loan.FirstInstallmentDate = loan.FirstInstallmentDate = DateTime.Now + new TimeSpan(30, 0, 0, 0); loan.CloseDate = TimeProvider.Now + new TimeSpan(365, 0, 0, 0); loan.EconomicActivityId = 1; loan.NonRepaymentPenalties = new NonRepaymentPenalties { InitialAmount = member.Product.NonRepaymentPenalties.InitialAmount ?? 0, OLB = member.Product.NonRepaymentPenalties.OLB ?? 0, OverDuePrincipal = member.Product.NonRepaymentPenalties.OverDuePrincipal ?? 0, OverDueInterest = member.Product.NonRepaymentPenalties.OverDueInterest ?? 0 }; loan.LoanEntryFeesList = new List<LoanEntryFee>(); loan.InstallmentType = member.Product.InstallmentType; loan.AnticipatedTotalRepaymentPenalties = 0; loan.FundingLine = new FundingLine("New_Founding_line", false); loan.FundingLine.Currency = loan.Product.Currency; loan.FundingLine.Id = 1; loan.LoanOfficer = User.CurrentUser; loan.LoanOfficer.LastName = "Unit"; loan.LoanOfficer.FirstName = "Test"; loan.Synchronize = false; loan.ContractStatus = OContractStatus.Validated; loan.CreditCommitteeCode = "OK"; loan.GracePeriod = 0; loan.GracePeriodOfLateFees = member.Product.GracePeriodOfLateFees; loan.AnticipatedPartialRepaymentPenalties = 2; loan.AnticipatedTotalRepaymentPenalties = 3; loan.LoanCycle = ((Person)member.Tiers).LoanCycle; loan.InstallmentList = new List<Installment>(); loan.InstallmentList.Add(new Installment()); loan.InstallmentList[0].ExpectedDate = TimeProvider.Now + new TimeSpan(60, 0, 0, 0); loan.InstallmentList[0].InterestsRepayment = 10; loan.InstallmentList[0].Number = 1; loan.InstallmentList[0].CapitalRepayment = 10; loan.InstallmentList[0].PaidInterests = 10; loan.InstallmentList[0].PaidCapital = 10; loan.InstallmentList[0].PaidDate = TimeProvider.Now; loan.InstallmentList[0].FeesUnpaid = 10; loan.InstallmentList[0].PaidFees = 10; loan.InstallmentList[0].Comment = "Unit test"; loan.InstallmentList[0].IsPending = false; loan.InstallmentList[0].StartDate = TimeProvider.Now; loan.InstallmentList[0].OLB = 20; loan.InstallmentList.Add(new Installment()); loan.InstallmentList[1].ExpectedDate = TimeProvider.Now + new TimeSpan(120, 0, 0, 0); loan.InstallmentList[1].InterestsRepayment = 10; loan.InstallmentList[1].Number = 2; loan.InstallmentList[1].CapitalRepayment = 10; loan.InstallmentList[1].PaidInterests = 10; loan.InstallmentList[1].PaidCapital = 10; loan.InstallmentList[1].PaidDate = TimeProvider.Now + new TimeSpan(120, 0, 0, 0); loan.InstallmentList[1].FeesUnpaid = 10; loan.InstallmentList[1].PaidFees = 10; loan.InstallmentList[1].Comment = "Unit test2"; loan.InstallmentList[1].IsPending = false; loan.InstallmentList[1].StartDate = TimeProvider.Now.AddDays(60); loan.InstallmentList[1].OLB = 10; loan.Events = new EventStock(); loan.AlignDisbursementDate = TimeProvider.Now; loan.CreditCommiteeDate = TimeProvider.Now; loan.Guarantors = new List<Guarantor>(); loan.Collaterals = new List<ContractCollateral>(); Project project; IClient client = member.Tiers; if (0 == client.Projects.Count) { project = new Project("Village"); project.Name = "Village"; project.Code = "Village"; project.Aim = "Village"; project.BeginDate = TimeProvider.Now; project.Id = ServicesProvider.GetInstance().GetProjectServices().SaveProject(project, client); member.Tiers.AddProject(project); } project = client.Projects[0]; client.District = new District(1, "Unit Test"); client.Name = "Unit Test"; ApplicationSettings appSettings = ApplicationSettings.GetInstance(User.CurrentUser.Md5); appSettings.UpdateParameter("ALLOWS_MULTIPLE_LOANS", 1); appSettings.UpdateParameter("CONTRACT_CODE_TEMPLATE", "Contract"); ServicesProvider.GetInstance().GetContractServices().SaveLoan(ref loan, project.Id, ref client); } foreach (VillageMember member in village.Members) { member.ActiveLoans = ServicesProvider.GetInstance().GetContractServices().FindActiveContracts(member.Tiers.Id); } for (int i = 0; i < village.Members.Count; i++) { int j = i; //to avoid index out of range exception (it occurs in product.LoanAmountCycleParams) if (i == product.LoanAmountCycleParams.Count) j = product.LoanAmountCycleParams.Count - 1; for (int k = 0; k < village.Members[i].ActiveLoans.Count; k++) { Assert.AreEqual(village.Members[i].ActiveLoans[k].AmountMin, loanAmountCycle[j].Min); Assert.AreEqual(village.Members[i].ActiveLoans[k].AmountMax, loanAmountCycle[j].Max); Assert.AreEqual(village.Members[i].ActiveLoans[k].Amount, loanAmountCycle[j].Min); Assert.AreEqual(village.Members[i].ActiveLoans[k].InterestRateMin, (double?) rateCycles[j].Min.Value); Assert.AreEqual(village.Members[i].ActiveLoans[k].InterestRateMax, (double?) rateCycles[j].Max.Value); Assert.AreEqual(village.Members[i].ActiveLoans[k].InterestRate, (double?) rateCycles[j].Min.Value); Assert.AreEqual(village.Members[i].ActiveLoans[k].NmbOfInstallmentsMin, (int) maturityCycles[j].Min.Value); Assert.AreEqual(village.Members[i].ActiveLoans[k].NmbOfInstallmentsMax, (int) maturityCycles[j].Max.Value); Assert.AreEqual(village.Members[i].ActiveLoans[k].NbOfInstallments, (int) maturityCycles[j].Min.Value); } } }
public void TestAddExoticInstallmentInExoticProductWhenInstallmentIsNotNull() { ExoticInstallmentsTable product = new ExoticInstallmentsTable(); ExoticInstallment exoticInstallment = new ExoticInstallment(); exoticInstallment.InterestCoeff = 0; exoticInstallment.PrincipalCoeff = 0; int number = product.GetNumberOfInstallments; ProductServices productServices = new ProductServices(new User {Id = 1}); Assert.AreEqual(number + 1, productServices.AddExoticInstallmentInExoticProduct(product, exoticInstallment, 1, false).GetNumberOfInstallments); }
public void TestSavingOfLoanCycleWithWrongParams() { var loanAmountCycles = GetLoanAmountCycles(); var maturityCycles = GetMaturityCycles(); var rateCycles = GetRateCycles(); loanAmountCycles.Add(new LoanAmountCycle(1,2,20,10,2,1)); maturityCycles.Add(new MaturityCycle(1,2,20,10,2,1)); rateCycles.Add(new RateCycle(1,2, 20,10,2,1)); ProductServices productServices = new ProductServices(new User {Id = 1}); productServices.SaveAllCycleParams(loanAmountCycles,rateCycles, maturityCycles); }
public void TestProductWithoutRateCycle() { var loanAmountCycles = GetLoanAmountCycles(); var maturityCycles = GetMaturityCycles(); var rateCycles = new List<RateCycle>(); var entryFees = new List<EntryFee>(); var nrp = new NonRepaymentPenaltiesNullableValues(200,100,20,1); var currency = new Currency(); currency.Id = 1; LoanProduct product = CreatePackage( "NewPackage", //package name null, //anticipatedTotalRepaymentPenalties 3, //anticipatedTotalRepaymentPenaltiesMin 6, //anticipatedTotalRepaymentPenaltiesMax 4, //grace period null, //gracePeriodMin null, //gracePeriodMax null, //interestRate null, //interesrRateMin null, //interestRateMax null, //NmbOfInstallments null, //NmbOfInstallmentsMin null, //NmbOfInstallmentsMax entryFees, //List<EntryFee> nrp, //NonRepaymentPenalties null, //NonRepaymentPenaltiesMin null, //NonRepaymentPenaltiesMax _monthly, //InstallmentType null, //amount null, //amountMin null, //AmountMax null, //ExoticInstallmentsTable 1, //cycleId loanAmountCycles, //List<LoanAmountCycle> rateCycles, //List<RateCycle> maturityCycles, //List<MaturityCycle> "CODE1", //ProductCode null, //List<ProductClientType> null, //amountUnderLoc null, //amountUnderLocMin null, //amountUnderLocMax 10, //anticipatedPartialRRepaymentPenalties null, //anticipatedPartialRRepaymentPenaltiesMin null, //anticipatedPartialRRepaymentPenaltiesMax null, //compulsoryAmount null, //compulsoryAmountMin null, //compulsoryAmountMax currency //Currency ); ProductServices productServices = new ProductServices(new User() {Id = 1}); productServices.ParseFieldsAndCheckErrors(product, false); }
public void FindAllInstallmentTypes() { List<InstallmentType> list = new List<InstallmentType>(); list.Add(_monthly); list.Add(_biWeekly); mockInstallmentTypeManagement.SetReturnValue("SelectAllInstallmentTypes",list); installmentTypeManagement = (InstallmentTypeManager)mockInstallmentTypeManagement.MockInstance; ProductServices productServices = new ProductServices(installmentTypeManagement); Assert.AreEqual(2, productServices.FindAllInstallmentTypes().Count); }
public void FindAllInstallmentsTypesWhenNoResult() { List<InstallmentType> list = new List<InstallmentType>(); mockInstallmentTypeManagement.SetReturnValue("SelectAllInstallmentTypes", list); installmentTypeManagement = (InstallmentTypeManager)mockInstallmentTypeManagement.MockInstance; ProductServices productServices = new ProductServices(installmentTypeManagement); Assert.AreEqual(0, productServices.FindAllInstallmentTypes().Count); }