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 CalculateRemainingInterest_AccrualAccounting()
        {
            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}
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 0, new DateTime(2009, 12, 25), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            myContract.Repay(1, new DateTime(2010, 1, 25), 196.67m, false, true);

            Assert.AreEqual(17.42m, Math.Round(myContract.CalculateRemainingInterests(new DateTime(2010, 2, 12)).Value, 2));

            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);
        }
        public void Repay_DecliningLoan_KeepNotExpectedInstallment_SecondInstallmentNotEntirlyPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                KeepExpectedInstallment = false,
                Currency = new Currency { Id = 1, UseCents = true},
                RoundingType = ORoundingType.Approximate
            };
            Loan myContract = new Loan(package, 1000, 0.03m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

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

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 100, true, false);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30, 0, 1000, 0, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30, 154.60m, 1000, 70, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 25.36m, 159.24m, 845.40m, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 20.58m, 164.02m, 686.16m, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 15.66m, 168.93m, 522.14m, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 10.60m, 173.99m, 353.21m, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(6), 7, new DateTime(2006, 8, 1), 5.38m, 179.22m, 179.22m, 0, 0);
        }
        public void TestIfPastDueIsEqualToZeroWhenAllInstallmentsAreRepaid()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 }
                                      };
            package.KeepExpectedInstallment = false;
            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()));

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 30, true, false);
            myContract.Repay(3, new DateTime(2006, 4, 1), 280, true, false);
            myContract.Repay(4, new DateTime(2006, 5, 1), 280, true, false);
            myContract.Repay(5, new DateTime(2006, 6, 1), 280, true, false);
            myContract.Repay(6, new DateTime(2006, 7, 1), 280, true, false);

            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2005, 8, 7)));
        }
        public void Repay_DecliningLoan_KeepNotExpectedInstallment_EntirlyPaid_NoCancelFees()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);

            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType = OLoanTypes.DecliningFixedInstallments,
                ChargeInterestWithinGracePeriod = true,
                KeepExpectedInstallment = false,
                Currency = new Currency { Id = 1, UseCents = true},
                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()))
                                  {
                                      NonRepaymentPenalties = { InitialAmount = 0.003 },
                                      AnticipatedTotalRepaymentPenalties = 0.003
                                  };
            //VPM => 218,3546
            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            RepaymentEvent repayEvent = myContract.Repay(2, new DateTime(2006, 3, 1), 1032.44m, false, false);

            _AssertSpecifiedEvent(repayEvent, 2.44m, 30.00m, 1000.00m);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30.00m, 0, 1000, 0, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30.00m, 188.35m, 1000, 188.35m, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 0, 811.65m, 811.65m, 811.65m, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 0, 0, 0, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 0, 0, 0, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 0, 0, 0, 0, 0);
        }
        public void TestRepayButRepaymentEventIsNull()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

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

            RepaymentEvent rE = myContract.Repay(1, new DateTime(2006, 2, 1), 1032, true, false);
            Assert.IsNull(rE);

            RepaymentEvent rE2 = myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            Assert.IsNotNull(rE2);
        }
        public void TestContract9InstallmentsDecliningRateWhenLittleOverPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.DecliningFixedInstallments,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 }
                                      };
            package.KeepExpectedInstallment = false;
            Loan myContract = new Loan(package,1500,0.03m,9,1,new DateTime(2006,1,1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.AnticipatedTotalRepaymentPenalties = 0.02;

            Assert.AreEqual(45m,myContract.GetInstallment(0).InterestsRepayment.Value);
            Assert.AreEqual(0,myContract.GetInstallment(0).CapitalRepayment.Value);
            Assert.AreEqual(new DateTime(2006,2,1),myContract.GetInstallment(0).ExpectedDate);

            RepaymentEvent rPE = myContract.Repay(1,new DateTime(2006,2,1),45m,false,false);
            Assert.AreEqual(45,myContract.GetInstallment(0).PaidInterests.Value);
            Assert.AreEqual(0,myContract.GetInstallment(0).PaidCapital.Value);
            Assert.AreEqual(0m,rPE.Fees.Value);
            Assert.AreEqual(45m,rPE.Interests.Value);
            Assert.AreEqual(0m,rPE.Principal.Value);
        }
        public void TestCalculateMaximumAmountForExoticProductTypeForInstallment3()
        {
            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.NonRepaymentPenalties.OLB = 0.01;
            Loan myContract = new Loan(package, 1000, 0.01m, 3, 0, new DateTime(2008, 12, 17), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.Repay(1, new DateTime(2008, 12, 19), 103, true, true);
            myContract.Repay(2, new DateTime(2008, 12, 19), 618, true, true);

            OCurrency amountToRetreived = Math.Round(myContract.CalculateMaximumAmountAuthorizedToRepay(3, new DateTime(2007, 3, 28), false, 0, 0, false, 0, true, true).Value);

            Assert.AreEqual(310m, amountToRetreived.Value);
        }
        public void TestCalculatePastDueSinceLastRepayment()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          KeepExpectedInstallment = false,
                                          Currency = new Currency { Id = 1 }
                                      };
            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()));

            //before repayment
            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 1)));
            Assert.AreEqual(14, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 15)));
            Assert.AreEqual(59, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 4, 1)));
            Assert.AreEqual(152, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 7, 3)));

            //partially repayment
            PaymentMethod paymentMethod = new PaymentMethod(1, "Cash", "", false);
            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, 0, 0, false, 0, false, false, false, paymentMethod);
            myContract.Repay(2, new DateTime(2006, 3, 6), 10, true, 0, 0, false, 0, false, false, false, paymentMethod);

            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 1)));
            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 15)));
            Assert.AreEqual(28, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 4, 3)));
            Assert.AreEqual(119, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 7, 3)));

            //totally repayment
            myContract.Repay(2, new DateTime(2006, 3, 6), 20, true, 0, 0, false, 0, false, false, false, paymentMethod);
            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 1)));
            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 2, 15)));
            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 4, 3)));
            Assert.AreEqual(91, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 7, 3)));
        }
        public void TestRepayFlateLoanWhenKeepNotExpectedInstallmentButEntirlyPaidButNoCancelFees()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.INTEREST_RATE_DECIMAL_PLACES, 2);

            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency {Id = 1, UseCents = true},
                                          KeepExpectedInstallment = false
                                      };
            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()))
                                  {
                                      NonRepaymentPenalties = {InitialAmount = 0.003},
                                      AnticipatedTotalRepaymentPenalties = 0.003
                                  };

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            RepaymentEvent repayEvent = myContract.Repay(2, new DateTime(2006, 3, 1), 1032.4m, false, false);

            Assert.AreEqual(2.4m, repayEvent.Fees.Value);
            Assert.AreEqual(30, repayEvent.Interests.Value);
            Assert.AreEqual(1000, repayEvent.Principal.Value);

            Assert.AreEqual(30, myContract.GetInstallment(0).InterestsRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(0).CapitalRepayment.Value);
            Assert.AreEqual(1000, myContract.GetInstallment(0).OLB.Value);
            Assert.AreEqual(0, myContract.GetInstallment(0).PaidCapital.Value);
            Assert.AreEqual(30, myContract.GetInstallment(0).PaidInterests.Value);

            Assert.AreEqual(30, myContract.GetInstallment(1).InterestsRepayment.Value);
            Assert.AreEqual(200, myContract.GetInstallment(1).CapitalRepayment.Value);
            Assert.AreEqual(1000, myContract.GetInstallment(1).OLB.Value);
            Assert.AreEqual(200, myContract.GetInstallment(1).PaidCapital.Value);
            Assert.AreEqual(30, myContract.GetInstallment(1).PaidInterests.Value);

            Assert.AreEqual(0, myContract.GetInstallment(2).InterestsRepayment.Value);
            Assert.AreEqual(800, myContract.GetInstallment(2).CapitalRepayment.Value);
            Assert.AreEqual(800, myContract.GetInstallment(2).OLB.Value);
            Assert.AreEqual(800, myContract.GetInstallment(2).PaidCapital.Value);
            Assert.AreEqual(0, myContract.GetInstallment(2).PaidInterests.Value);

            Assert.AreEqual(0, myContract.GetInstallment(3).InterestsRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(3).CapitalRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(3).OLB.Value);
            Assert.AreEqual(0, myContract.GetInstallment(3).PaidCapital.Value);
            Assert.AreEqual(0, myContract.GetInstallment(3).PaidInterests.Value);

            Assert.AreEqual(0, myContract.GetInstallment(4).InterestsRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(4).CapitalRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(4).OLB.Value);
            Assert.AreEqual(0, myContract.GetInstallment(4).PaidCapital.Value);
            Assert.AreEqual(0, myContract.GetInstallment(4).PaidInterests.Value);

            Assert.AreEqual(0, myContract.GetInstallment(5).InterestsRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(5).CapitalRepayment.Value);
            Assert.AreEqual(0, myContract.GetInstallment(5).OLB.Value);
            Assert.AreEqual(0, myContract.GetInstallment(5).PaidCapital.Value);
            Assert.AreEqual(0, myContract.GetInstallment(5).PaidInterests.Value);
        }
        public void TestRepayFlateLoanWhenKeepNotExpectedInstallmentButSecondInstallmentNotEntirlyPaidTheSecondInstallment()
        {
            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 }
                                      };
            package.KeepExpectedInstallment = false;
            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.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 200, true, false);

            Assert.AreEqual(30m, myContract.GetInstallment(0).InterestsRepayment.Value);
            Assert.AreEqual(0m, myContract.GetInstallment(0).CapitalRepayment.Value);
            Assert.AreEqual(1000m, myContract.GetInstallment(0).OLB.Value);
            Assert.AreEqual(0m, myContract.GetInstallment(0).PaidCapital.Value);
            Assert.AreEqual(30m, myContract.GetInstallment(0).PaidInterests.Value);

            Assert.AreEqual(30m, myContract.GetInstallment(1).InterestsRepayment.Value);
            Assert.AreEqual(200m, myContract.GetInstallment(1).CapitalRepayment.Value);
            Assert.AreEqual(1000m, myContract.GetInstallment(1).OLB.Value);
            Assert.AreEqual(170m, myContract.GetInstallment(1).PaidCapital.Value);
            Assert.AreEqual(30m, myContract.GetInstallment(1).PaidInterests.Value);

            Assert.AreEqual(30m, myContract.GetInstallment(2).InterestsRepayment.Value);
            Assert.AreEqual(200m, myContract.GetInstallment(2).CapitalRepayment.Value);
            Assert.AreEqual(800m, myContract.GetInstallment(2).OLB.Value);
            Assert.AreEqual(0m, myContract.GetInstallment(2).PaidCapital.Value);
            Assert.AreEqual(0m, myContract.GetInstallment(2).PaidInterests.Value);
        }
        public void TestRepayFlateLoanWhenKeepExpectedInstallmentButSecondInstallmentNotEntirlyPaidTheSecondInstallment()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 }
                                      };
            package.KeepExpectedInstallment = true;
            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.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 200, true, false);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 1, new DateTime(2006, 2, 1), 30, 0, 1000, 0, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 2, new DateTime(2006, 3, 1), 30, 200, 1000, 170, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 3, new DateTime(2006, 4, 3), 30, 200, 800, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 4, new DateTime(2006, 5, 1), 30, 200, 600, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 5, new DateTime(2006, 6, 1), 30, 200, 400, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 6, new DateTime(2006, 7, 3), 30, 200, 200, 0, 0);
        }
        public void TestRepayFlateLoanWhenKeepNotExpectedInstallmentAndOverPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            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 }
                                      };
            package.KeepExpectedInstallment = false;
            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.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            RepaymentEvent rE = myContract.Repay(2, new DateTime(2006, 3, 1), 430, true, false);

            Assert.AreEqual(0, rE.Fees.Value);
            Assert.AreEqual(30, rE.Interests.Value);
            Assert.AreEqual(400, rE.Principal.Value);

            _AssertSpecifiedInstallment(myContract.GetInstallment(0), 30, 0, 1000, 0, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(1), 30, 200, 1000, 200, 30);
            _AssertSpecifiedInstallment(myContract.GetInstallment(2), 18, 150, 600, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(3), 18, 150, 450, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(4), 18, 150, 300, 0, 0);
            _AssertSpecifiedInstallment(myContract.GetInstallment(5), 18, 150, 150, 0, 0);
        }
        public void TestRepayEventCorrectlyGenerateWhenTenDaysLateAndPayFees()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.STOP_WRITEOFF_PENALTY, true);

            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          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.NonRepaymentPenalties.OLB = 0.003;

            Assert.AreEqual(new DateTime(2006, 2, 1), myContract.GetInstallment(0).ExpectedDate);
            Assert.AreEqual(new DateTime(2006, 3, 1), myContract.GetInstallment(1).ExpectedDate);

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);

            RepaymentEvent rPE = myContract.Repay(2, new DateTime(2006, 3, 11), 230.41m, false, false);

            Assert.AreEqual(30m, rPE.Fees.Value);
            Assert.AreEqual(30m, rPE.Interests.Value);
            Assert.AreEqual(170.41m, rPE.Principal.Value);
        }
        public void TestRepayEventCorrectlyGeneratedWithThirdInstallmentFlatRateWithOverPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            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 }
                                      };
            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.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.AnticipatedPartialRepaymentPenalties = 0.01;

            myContract.Repay(1, new DateTime(2006, 2, 1), 30m, false, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 230m, false, false);
            RepaymentEvent rPE = myContract.Repay(3, new DateTime(2006, 4, 3), 530m, false, false);

            Assert.AreEqual(6, rPE.Fees.Value);
            Assert.AreEqual(30, rPE.Interests.Value);
            Assert.AreEqual(494, rPE.Principal.Value);
        }
        public void TestRepayEventCorrectlyGeneratedWithThirdInstallmentDecliningWithOverPaid()
        {
            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 }
                                      };
            Loan myContract = new Loan(package, 600, 0.025m, 6, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            RepaymentEvent rPE = myContract.Repay(1, new DateTime(2006, 2, 1), 115m, false, false);

            Assert.AreEqual(15m, rPE.Interests.Value);
            Assert.AreEqual(100m, rPE.Principal.Value);
        }
        public void TestBadLoanAndGoBackToNormal()
        {
            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 }
                                      };
            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);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 3, 15), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));
            Assert.AreEqual(1194, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
            Assert.AreEqual(386.00m, Math.Round(cCR.MaximumAmountToRegradingLoan.Value, 2));

            RepaymentEvent rPE = myContract.Repay(1,new DateTime(2006,3,15),386,false,true);
            Assert.AreEqual(126,rPE.Fees.Value);
            Assert.AreEqual(60,rPE.Interests.Value);
            Assert.AreEqual(200,rPE.Principal.Value);
        }
        public void TestRepaySecondInstallmentDecliningRateNoOverPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, 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
                                      };
            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()));
            myContract.Repay(1, new DateTime(2006, 2, 1), 184.60m, false, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 184.60m, false, false);

            Assert.AreEqual(159.24m, myContract.GetInstallment(1).PaidCapital.Value);
            Assert.AreEqual(25.36m, myContract.GetInstallment(1).PaidInterests.Value);
            Assert.IsTrue(myContract.GetInstallment(1).IsRepaid);
        }
        public void TestCalculateInstallmentWhenChangeDateSetToFalse()
        {
            ApplicationSettings pDataParam = ApplicationSettings.GetInstance("");
            pDataParam.DeleteAllParameters();
            pDataParam.AddParameter("ALIGN_INSTALLMENTS_ON_REAL_DISBURSEMENT_DATE", false);
            pDataParam.AddParameter("PAY_FIRST_INSTALLMENT_REAL_VALUE", true);
            pDataParam.AddParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            pDataParam.AddParameter(OGeneralSettings.DONOTSKIPWEEKENDSININSTALLMENTSDATE, false);
            pDataParam.AddParameter(OGeneralSettings.INCREMENTALDURINGDAYOFF, true);

            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 }
                                      };
            Loan myContract = new Loan(package,1000,0.02m,6,1,new DateTime(2006,1,2), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));

            Assert.AreEqual(new DateTime(2006,2,2),myContract.GetInstallment(0).ExpectedDate);
            Assert.AreEqual(new DateTime(2006,3,2),myContract.GetInstallment(1).ExpectedDate);

            myContract.Disburse(new DateTime(2006,1,6),false,false);

            Assert.AreEqual(new DateTime(2006,1,2),myContract.StartDate);
            Assert.AreEqual(new DateTime(2006,2,2),myContract.GetInstallment(0).ExpectedDate);
            Assert.AreEqual(new DateTime(2006,3,2),myContract.GetInstallment(1).ExpectedDate);

            myContract.Repay(1,new DateTime(2006,2,2),100,true,false);
            Assert.AreEqual(new DateTime(2006,2,2),myContract.GetInstallment(0).ExpectedDate);
            Assert.AreEqual(new DateTime(2006,3,2),myContract.GetInstallment(1).ExpectedDate);
        }
        public void TestCalculatePastDueSinceLastRepayment2()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          KeepExpectedInstallment = false,
                                          Currency = new Currency { Id = 1 }
                                      };
            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()));
            PaymentMethod paymentMethod = new PaymentMethod(1, "Cash", "", false);
            myContract.Repay(1, new DateTime(2006, 6, 1), 30, true, 0, 0, false, 0, true, false, false, paymentMethod);

            Assert.IsTrue(myContract.GetInstallment(0).IsRepaid);

            Assert.AreEqual(122, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 7, 1)));
        }
        public void TestCalculateOverDueAmountWithoutInterest()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          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()));

            Assert.AreEqual(30m, myContract.GetInstallment(0).InterestsRepayment.Value);
            Assert.AreEqual(0m, myContract.GetInstallment(0).CapitalRepayment.Value);
            Assert.AreEqual(new DateTime(2006, 2, 1), myContract.GetInstallment(0).ExpectedDate);

            Assert.AreEqual(30m, myContract.GetInstallment(1).InterestsRepayment.Value);
            Assert.AreEqual(200m, myContract.GetInstallment(1).CapitalRepayment.Value);
            Assert.AreEqual(new DateTime(2006, 3, 1), myContract.GetInstallment(1).ExpectedDate);
            Assert.AreEqual(new DateTime(2006, 4, 3), myContract.GetInstallment(2).ExpectedDate);

            Assert.AreEqual(0m, myContract.CalculateOverduePrincipal(new DateTime(2006, 1, 9)).Value);

            Assert.AreEqual(400m, myContract.CalculateOverduePrincipal(new DateTime(2006, 4, 9)).Value);

            Assert.AreEqual(400m, myContract.CalculateOverduePrincipal(new DateTime(2006, 4, 9)).Value);

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            Assert.AreEqual(400m, myContract.CalculateOverduePrincipal(new DateTime(2006, 4, 9)).Value);

            myContract.Repay(2, new DateTime(2006, 3, 1), 230, true, false);
            Assert.AreEqual(200m, myContract.CalculateOverduePrincipal(new DateTime(2006, 4, 9)).Value);

            myContract.Repay(3, new DateTime(2006, 4, 3), 130, true, false);
            Assert.AreEqual(100m, myContract.CalculateOverduePrincipal(new DateTime(2006, 4, 9)).Value);
        }
        public void TestCalculatePendingRepayment()
        {
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true,
                KeepExpectedInstallment = false,
                Currency = new Currency { Id = 1 }
            };
            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()));

            PaymentMethod paymentMethod = new PaymentMethod(2, "Voucher", "", true);
            RepaymentEvent pEvent = myContract.Repay(1, new DateTime(2006, 6, 1), 30, true, 0, 0, false, 0, true, false, true,
                                                     paymentMethod);

            Assert.IsTrue(myContract.GetInstallment(0).IsRepaid);
            Assert.AreEqual(pEvent.Code, "PBLR");
            Assert.IsTrue(myContract.GetInstallment(0).IsPending);
            myContract.ConfirmPendingRepayment();
            Assert.IsFalse(myContract.GetInstallment(0).IsPending);
        }
 public void NonRepaidInstallments()
 {
     LoanProduct package = new LoanProduct
                               {
                                   InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                   LoanType = OLoanTypes.Flat,
                                   Currency = new Currency {Id = 1}
                               };
     Loan loan = new Loan(package, 1000, 0.02m, 5, 0, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
     loan.Repay(1, new DateTime(2006, 2, 1), 220, true, true);
     Assert.AreEqual(loan.GetInstallment(0).IsRepaid, true);
     int num = 2;
     foreach (Installment i in loan.NonRepaidInstallments)
     {
         Assert.AreEqual(i.Number, num);
         num++;
     }
 }
        public void TestOLBCorrectlyCalculated()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency {Id = 1},
                                          KeepExpectedInstallment = false
                                      };
            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()));

            Assert.AreEqual(1000m,myContract.CalculateActualOlb().Value);
            myContract.Repay(1,new DateTime(2006,2,1),30,true,false);
            Assert.AreEqual(1000m,myContract.CalculateActualOlb().Value);
            myContract.Repay(2,new DateTime(2006,3,1),30,true,false);
            Assert.AreEqual(1000m,myContract.CalculateActualOlb().Value);
            myContract.Repay(3,new DateTime(2006,4,3),280,true,false);
            Assert.AreEqual(750m,myContract.CalculateActualOlb().Value);
        }
        public void TestCalculatePastDueSinceLastRepaymentWhenSameYearAndLimitBypassed()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 },
                                          KeepExpectedInstallment = false
                                      };
            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()));

            myContract.Repay(1, new DateTime(2006, 2, 1), 30, true, false);
            DateTime limit = new DateTime(2006, 5, 1);

            Assert.AreEqual(61, myContract.CalculatePastDueSinceLastRepayment(limit));
        }
        public void TestRepayThirdInstallmentDecliningRateWithOverPaid()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            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, 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);

            myContract.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.AnticipatedPartialRepaymentPenalties = 0.01;

            myContract.Repay(1, new DateTime(2006, 2, 1), 184.60m, true, false);
            myContract.Repay(2, new DateTime(2006, 3, 1), 184.60m, true, false);

            RepaymentEvent rPE = myContract.Repay(3, new DateTime(2006, 4, 3), 250m, false, false);

            Assert.AreEqual(5.22m, rPE.Fees.Value);
            Assert.AreEqual(20.58m, rPE.Interests.Value);
            Assert.AreEqual(224.2m, rPE.Principal.Value);

            Assert.AreEqual(164.02m, myContract.GetInstallment(2).PaidCapital.Value);
            Assert.AreEqual(20.58m, myContract.GetInstallment(2).PaidInterests.Value);
            Assert.IsTrue(myContract.GetInstallment(2).IsRepaid);
            Assert.AreEqual(149.46m, myContract.GetInstallment(3).CapitalRepayment.Value);
            Assert.AreEqual(13.86m, myContract.GetInstallment(3).InterestsRepayment.Value);
            Assert.AreEqual(461.96m, myContract.GetInstallment(3).OLB.Value);
        }
        public void TestCalculateRemainingInterests()
        {
            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 }
                                      };

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

            myContract.Repay(1, new DateTime(2006, 2, 2), 20, false, false);

            Assert.AreEqual(100m, myContract.CalculateRemainingInterests().Value);
        }
        public void TestRepayWhenOverPaidGreaterThanMaximumAmountAuthorized()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.Flat,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1 }
                                      };

            ExoticInstallmentsTable exoticProduct = new ExoticInstallmentsTable();
            exoticProduct.Add(new ExoticInstallment(1,0,1));
            exoticProduct.Add(new ExoticInstallment(2,0,1));
            exoticProduct.Add(new ExoticInstallment(3,0.5,1));
            exoticProduct.Add(new ExoticInstallment(4,0,1));
            exoticProduct.Add(new ExoticInstallment(5,0,1));
            exoticProduct.Add(new ExoticInstallment(6,0.5,1));
            package.ExoticProduct = exoticProduct;

            Loan myContract = new Loan(package, 1000, 0.02m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.Repay(1,new DateTime(2006,2,1),20,false,false);
            myContract.Repay(2,new DateTime(2006,3,1),20,false,false);
            myContract.Repay(3,new DateTime(2006,4,1),20,false,false);
            RepaymentEvent rPE = myContract.Repay(4,new DateTime(2006,1,1),2000,false,false);

            Assert.IsNull(rPE);
        }
        public void TestCountFeesWithSmallPrepayment()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.STOP_WRITEOFF_PENALTY, true);

            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, 1000, 0.03m, 6, 1, new DateTime(2010, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.NonRepaymentPenalties.OverDuePrincipal = 0.01;

            Assert.AreEqual(new DateTime(2010, 2, 1), myContract.GetInstallment(0).ExpectedDate);
            Assert.AreEqual(new DateTime(2010, 3, 1), myContract.GetInstallment(1).ExpectedDate);

            myContract.Repay(1, new DateTime(2010, 2, 1), 30, true, false);
            myContract.Repay(2, new DateTime(2010, 2, 26), 30, true, false);

            RepaymentEvent rPE = myContract.Repay(2, new DateTime(2010, 3, 4), 196.58m, false, false);
            Assert.AreEqual(5.63m, rPE.Fees.Value);
            Assert.AreEqual(3.2m, rPE.Interests.Value);
            Assert.AreEqual(187.75m, rPE.Principal.Value);

            Assert.AreEqual(myContract.GetInstallment(1).IsRepaid, true);
        }
        public void TestRepayWhenOverPaidGreaterThanMaximumAmountAuthorizedWhenBadLoan()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.STOP_WRITEOFF_PENALTY, true);

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

            ExoticInstallmentsTable exoticProduct = new ExoticInstallmentsTable();
            exoticProduct.Add(new ExoticInstallment(1,0,0.1));
            exoticProduct.Add(new ExoticInstallment(2,0,0.1));
            exoticProduct.Add(new ExoticInstallment(3,0.5,0.1));
            exoticProduct.Add(new ExoticInstallment(4,0,0.1));
            exoticProduct.Add(new ExoticInstallment(5,0,0.1));
            exoticProduct.Add(new ExoticInstallment(6,0.5,0.1));
            exoticProduct.Add(new ExoticInstallment(7,0,0));
            package.ExoticProduct = exoticProduct;

            Loan myContract = new Loan(package, 1000, 0.02m, 7, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;
            myContract.NonRepaymentPenalties.OLB = 0.02;
            myContract.Repay(1,new DateTime(2006,2,1),20,false,false);
            myContract.Repay(2,new DateTime(2006,3,1),20,false,false);
            myContract.Repay(3,new DateTime(2006,4,1),20,false,false);
            RepaymentEvent rPE = myContract.Repay(4,new DateTime(2006,1,1),2000,false,false);

            Assert.IsNull(rPE);
        }