public void DecliningRate_FixedInstallment_NewWayOfCalcul()
        {
            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, 800, 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), 24, 124, 800);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 20, 128, 676);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 16, 131, 548);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 13, 134, 417);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 8, 140, 283);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 4, 143, 143);
        }
Exemple #2
0
        public void Get_Set_Credits()
        {
            _project.AddCredit(new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())), OClientTypes.Group);
            Assert.AreEqual(1, _project.Credits.Count);

            Assert.AreEqual(OClientTypes.Group, _project.Credits[0].ClientType);
        }
        private static Loan _SetContract(OLoanTypes pLoansType, NonRepaymentPenalties pNonRepaymentPenalties, bool pKeepExpectedInstallment)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = pLoansType,
                ChargeInterestWithinGracePeriod        = true,
                KeepExpectedInstallment                = pKeepExpectedInstallment,
                AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB,
                Currency = new Currency {
                    Id = 1
                },
                RoundingType = ORoundingType.Approximate
            };
            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.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.NonRepaymentPenalties = pNonRepaymentPenalties;
            return(myContract);
        }
Exemple #4
0
 public NonWorkingDateSingleton GetNonWorkingDate()
 {
     return(NonWorkingDateSingleton.GetInstance(CurrentUser.Md5));
 }
        public void _Flate_BadLoan_42dayslate_BasedOnOverDueWithoutInterest_KeepExpectedInstallment()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                },
                KeepExpectedInstallment = true,
                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()))
            {
                BadLoan = true,
                NonRepaymentPenalties = { OverDuePrincipal = 0.003 },
                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 + 200 * 0.003 * 14
            Assert.AreEqual(268.4m, Math.Round(repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
            //NOT CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, false);

            //30 + 230 + 200 * 0.003 * 12
            Assert.AreEqual(266.60m, repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value);
        }
        public void DecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithInterestAndKeepNotExpectedInstallment()
        {
            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 = 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
            Assert.AreEqual(261.30m, Math.Round(repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value, 2));
        }
        public void SetUp()
        {
            Package package = new Package(new InstallmentType(1, "Monthly", 0, 1), OLoanTypes.Flat, true);

            package.KeepExpectedInstallment             = true;
            package.NonRepaymentPenalties.InitialAmount = 0.003;

            contractForAPerson = new Credit(package, 1000, 0.03, 6, 1, new DateTime(2006, 1, 1), User.CurrentUser, GeneralSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisioningTable.GetInstance(User.CurrentUser));
            contractForAPerson.NonRepaymentPenalties.InitialAmount = 0.003;

            _person           = new Person();
            _person.FirstName = "Nicolas";
            _person.LastName  = "MANGIN";
            _person.District  = new District(1, "Ile de France", new Province(1, "France"));
            _person.City      = "Paris";

            User user = User.CurrentUser;

            user.FirstName = "Nicolas";
            user.LastName  = "MANGIN";
            contractForAPerson.LoanOfficer = user;

            contractForAGroup           = new Credit(package, 1000, 0.03, 6, 1, new DateTime(2006, 1, 1), User.CurrentUser, GeneralSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisioningTable.GetInstance(User.CurrentUser));
            _group                      = new Group();
            _group.Name                 = "Groupe MANGIN";
            _group.District             = new District(1, "Lorraine", new Province(1, "France"));
            _group.City                 = "Nancy";
            contractForAGroup.EntryFees = 0.03;
        }
        public void TestIsWriteOffContractWhenItIsNot()
        {
            ClosureContractStock closureContractStock = new ClosureContractStock();
            Loan contract1 = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                Id = 1
            };

            closureContractStock.AddContract(contract1);
            Assert.IsFalse(closureContractStock.IsWriteOffContract(contract1));
        }
        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);
        }
        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("")));
        }
Exemple #11
0
        public void LateFeesCalculation_OverduePrincipalWithGracePeriodLatePenalties()
        {
            Loan myContract = _SetContractWithGracePeriodOfFees(OLoanTypes.Flat, new NonRepaymentPenalties(0.01, 0.01, 0.01, 0.01), 5, true);

            Assert.AreEqual(0m, CalculationBaseForLateFees.FeesBasedOnOverdueInterest(myContract, new DateTime(2006, 2, 6), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value);//0 (1st installment without interest) * 0.003 * 32 = 0
        }
Exemple #12
0
        public void LateFeesCalculation_OverdueInterest()
        {
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", true);
            Loan myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0, 0, 0.003), true);

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

            //NOT CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS
            ApplicationSettings.GetInstance("").UpdateParameter("CALCULATION_LATE_FEES_DURING_PUBLIC_HOLIDAYS", false);
            myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0, 0, 0.003), true);
            Assert.AreEqual(3m, CalculationBaseForLateFees.FeesBasedOnOverdueInterest(myContract, new DateTime(2006, 3, 5), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value); // 30 * 0.003 * 28 = 2.430 =>2
        }
Exemple #13
0
        public void LateFeesCalculation_OLB()
        {
            Loan myContract = _SetContract(OLoanTypes.Flat, new NonRepaymentPenalties(0, 0.0026, 0, 0), true);

            Assert.AreEqual(10m, CalculationBaseForLateFees.FeesBasedOnOlb(myContract, new DateTime(2006, 2, 5), 1, false, ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")).Value); // 1000 * 0.0026 * 4 = 10.4 => 10
        }
        public void TestDeleteContract()
        {
            ClosureContractStock closureContractStock = new ClosureContractStock();
            Loan contract1 = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                Id = 1
            };
            Loan contract2 = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                Id = 2
            };

            closureContractStock.AddContract(contract1);
            closureContractStock.AddContract(contract2);
            Assert.AreEqual(2, closureContractStock.Contracts.Count);
            closureContractStock.DeleteContract(contract1.Id);
            Assert.AreEqual(1, closureContractStock.Contracts.Count);
        }
Exemple #15
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 TestGetWriteOffContracts()
        {
            ClosureContractStock closureContractStock = new ClosureContractStock();
            Loan contract1 = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
            {
                Id = 1
            };
            Loan contract2 = new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            contract2.Events.Add(new WriteOffEvent());
            contract2.Id         = 2;
            contract2.WrittenOff = true;
            closureContractStock.AddContract(contract1);
            closureContractStock.AddContract(contract2);
            Assert.AreEqual(1, closureContractStock.WriteOffContracts.Count);
        }
Exemple #17
0
        public void TestCalculateMaximumAmountWithFlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithInterestAndKeepNotExpectedInstallment()
        {
            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.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);

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

            //30 + 230 + 30 * 0.003 * 42 + 230 * 0.003 *14 = 30 + 230 + 3.78 + 9.66 = 273.44=> 30 + 230 + 4 + 10 = 274
            Assert.AreEqual(273, Math.Round(this.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 }
            });
        }
        public void OLB_DecliningFixedInstallments_OneRepayment_OneMonthGracePeriod_Overdue_KeepNotExpectedInstallment()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);

            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };

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

            myContract.Repay(1, new DateTime(2006, 3, 1), 740, false, false);

            Assert.AreEqual(750, myContract.CalculateExpectedOlb(1, false).Value);
            Assert.AreEqual(32.5m, myContract.CalculateExpectedOlb(2, false).Value);
            Assert.AreEqual(28.85m, myContract.CalculateExpectedOlb(3, false).Value);
            Assert.AreEqual(25.09m, myContract.CalculateExpectedOlb(4, false).Value);
            Assert.AreEqual(21.21m, myContract.CalculateExpectedOlb(5, false).Value);
            Assert.AreEqual(17.22m, myContract.CalculateExpectedOlb(6, false).Value);
            Assert.AreEqual(13.11m, myContract.CalculateExpectedOlb(7, false).Value);
            Assert.AreEqual(8.87m, myContract.CalculateExpectedOlb(8, false).Value);
            Assert.AreEqual(4.51m, myContract.CalculateExpectedOlb(9, false).Value);
        }
        public void DecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOLBAndKeepExpectedInstallment()
        {
            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.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 + 218.35 + 1000 * 0.003 * 42
            Assert.AreEqual(374.35m, repayStrategy.CalculateMaximumAmountToRegradingLoan(new DateTime(2006, 3, 15)).Value);
        }
        public void CalculateExpectedOLB2()
        {
            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, 20000, 0.02m, 10, 0, new DateTime(2009, 1, 17), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = false;

            myContract.Repay(1, new DateTime(2009, 1, 17), 1000, true, false);

            Assert.AreEqual(19000, myContract.CalculateExpectedOlb(1, false).Value);
            Assert.AreEqual(17100, myContract.CalculateExpectedOlb(2, false).Value);
            Assert.AreEqual(15200, myContract.CalculateExpectedOlb(3, false).Value);
            Assert.AreEqual(13300, myContract.CalculateExpectedOlb(4, false).Value);
            Assert.AreEqual(11400, myContract.CalculateExpectedOlb(5, false).Value);
            Assert.AreEqual(9500, myContract.CalculateExpectedOlb(6, false).Value);
            Assert.AreEqual(7600, myContract.CalculateExpectedOlb(7, false).Value);
            Assert.AreEqual(5700, myContract.CalculateExpectedOlb(8, false).Value);
            Assert.AreEqual(3800, myContract.CalculateExpectedOlb(9, false).Value);
            Assert.AreEqual(1900, myContract.CalculateExpectedOlb(10, false).Value);
        }
        public void Flate_BadLoan_42DaysLate_BasedOnInitialAmount_KeepExpectedInstallment_Fees()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod        = true,
                KeepExpectedInstallment                = true,
                AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB,
                Currency = new Currency {
                    Id = 1
                }
            };
            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.003;
            myContract.AnticipatedTotalRepaymentPenalties  = 0.01;

            //42 days late
            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));
        }
        public void TestRepayFlat_GracePeriod_KeepNotExpectedInstallments()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);

            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, 50000, 0.01m, 8, 2, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.BadLoan = false;

            myContract.Repay(1, new DateTime(2006, 2, 1), 1050, true, true);
            myContract.Repay(2, new DateTime(2006, 6, 1), 40000, true, true);

            Assert.AreEqual(50000, myContract.CalculateExpectedOlb(1, false).Value);
            Assert.AreEqual(50000, myContract.CalculateExpectedOlb(2, false).Value);
            Assert.AreEqual(50000m, myContract.CalculateExpectedOlb(3, false).Value);
            Assert.AreEqual(41666.67m, myContract.CalculateExpectedOlb(4, false).Value);
            Assert.AreEqual(33333.34m, myContract.CalculateExpectedOlb(5, false).Value);
            //Assert.AreEqual(11428m, myContract.CalculateExpectedOLB(6, false).Value);
            //Assert.AreEqual(7618.67m, myContract.CalculateExpectedOLB(7, false).Value);
            //Assert.AreEqual(3809.34m, myContract.CalculateExpectedOLB(8, false).Value);
        }
        private static CalculateMaximumAmountToRepayStrategy _MaximumAmountToRepay(Loan pContract, bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount, bool pCancelInterest, OCurrency pManualInterestAmount)
        {
            CreditContractOptions cCO = new CreditContractOptions(pContract.Product.LoanType, pContract.Product.KeepExpectedInstallment, pCancelFees,
                                                                  pManualFeesAmount, pManualCommissionAmount,
                                                                  pCancelInterest, pManualInterestAmount, pContract.Product.AnticipatedTotalRepaymentPenaltiesBase);

            return(new CalculateMaximumAmountToRepayStrategy(cCO, pContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")));
        }
        private static Loan _GetLoan(DateTime pDisburseDate, int pNumberOfInstallments, int pGracePeriod, OLoanTypes pLoanTypes)
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = pLoanTypes,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1, UseCents = true
                }
            };

            return(new Loan(package, 1000, 0.03m, pNumberOfInstallments, pGracePeriod, pDisburseDate, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())));
        }
        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);
        }
        public void TestAddContract()
        {
            ClosureContractStock closureContractStock = new ClosureContractStock();

            closureContractStock.AddContract(new Loan(new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User())));
            Assert.AreEqual(1, closureContractStock.Contracts.Count);
        }
        public void DecliningRate_FixedPrincipal_GracePeriod()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType        = OLoanTypes.DecliningFixedPrincipal,
                ChargeInterestWithinGracePeriod = true,
                Currency = new Currency {
                    Id = 1
                }
            };
            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, 333, 1000);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 20, 334, 667);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 10, 333, 333);
        }
        private static Loan _SetContract(OAnticipatedRepaymentPenaltiesBases pAnticipatedRepaymentBase, double pAnticipated, bool pKeepExpectedInstallment, bool useCents)
        {
            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, UseCents = useCents
                }
            };

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