public void CalculateEvent_RepayTotallyDecliningBadLoan_42dayslate_NonRepaymentFeesBaseOnInitialAmount_KeepExpectedInstallment()
        {
            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},
                                                     KeepExpectedInstallment = true,
                                                     AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB,
                                                     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.NonRepaymentPenalties.InitialAmount = 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(1247.77m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
            RepaymentEvent bLRE = myContract.Repay(1, new DateTime(2006, 3, 15), 1247.77m, false, true);

            Assert.AreEqual(126m, bLRE.Fees.Value);
            Assert.AreEqual(121.77m, bLRE.Interests.Value);
            Assert.AreEqual(1000.00m, bLRE.Principal.Value);
        }
        public void TestTotalAnticipatedRepaymentFormerPrepaymentSameDayDecliningCash()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.DecliningFixedInstallments,
                                          ChargeInterestWithinGracePeriod = true,
                                          GracePeriod = 0,
                                          Currency = new Currency { Id = 1, UseCents = true}
                                      };
            package.KeepExpectedInstallment = true;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            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.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 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, 1, 1), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(1107.58m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));

            RepaymentEvent bLRE = myContract.Repay(1, new DateTime(2006, 1, 1), 194.60m, false, true);

            Assert.AreEqual(0, bLRE.Fees.Value);
            Assert.AreEqual(40m, bLRE.Interests.Value);
            Assert.AreEqual(154.60, bLRE.Principal.Value);

            cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 1, 1), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(912.98m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));

            bLRE = myContract.Repay(2, new DateTime(2006, 1, 1), 912.98m, true, true);

            Assert.AreEqual(0, bLRE.Fees.Value);
            Assert.AreEqual(67.58m, bLRE.Interests.Value);
            Assert.AreEqual(845.40m, bLRE.Principal.Value);
        }
        public void DecliningRate_OneMonthlate_FeesBasedOnOverdueAmountAndInterest_KeepNotExpectedInstallment()
        {
            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
                                      };
            package.KeepExpectedInstallment = false;
            Loan myContract = new Loan(package, 600, 0.03m, 6, 0, new DateTime(2006, 1, 4), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.OverDuePrincipal = 0.0016277;
            myContract.NonRepaymentPenalties.OverDueInterest = 0.0016277;

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

            Assert.AreEqual(227.78m, cCR.MaximumAmountToRegradingLoan.Value);
        }
        public void TestRepayFlatLoan2()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);

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

            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 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,Math.Round(cCR.MaximumAmountToRegradingLoan.Value,2));

            Assert.AreEqual(42, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 3, 15)));
            RepaymentEvent rPE = myContract.Repay(1,new DateTime(2006,3,15),386,false,false);
            Assert.AreEqual(126m,rPE.Fees.Value);
            Assert.AreEqual(60m,rPE.Interests.Value);
            Assert.AreEqual(200m,rPE.Principal.Value);
            Assert.IsFalse(myContract.BadLoan);

            Assert.AreEqual(0, myContract.CalculatePastDueSinceLastRepayment(new DateTime(2006, 3, 15)));
            CreditContractRepayment cCR2 = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 3, 15), 3, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));
            Assert.AreEqual(0, Math.Round(cCR2.MaximumAmountToRegradingLoan.Value,2));
            Assert.AreEqual(808, Math.Round(cCR2.MaximumAmountAuthorizeToRepay.Value,2));

            RepaymentEvent rPE2 = myContract.Repay(3,new DateTime(2006,3,15), 808m, false, false);
            Assert.AreEqual(8m, rPE2.Fees.Value);
            Assert.AreEqual(0m, rPE2.Interests.Value);
            Assert.AreEqual(800m, rPE2.Principal.Value);

            Assert.IsTrue(myContract.AllInstallmentsRepaid);
        }
        public void TestRepayFlatLoanWhenCalculateFeesWithDelta2()
        {
            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},
                                          KeepExpectedInstallment = false
                                      };

            Loan myContract = new Loan(package, 600, 0.03m, 6, 0, new DateTime(2006, 1, 4), new User(),
                                       ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""),
                                       ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()))
                                  {
                                      BadLoan = false,
                                      NonRepaymentPenalties = {OverDueInterest = 0.02, OverDuePrincipal = 0.02},
                                      AnticipatedTotalRepaymentPenalties = 0
                                  };

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

            RepaymentEvent rPE = myContract.Repay(1, new DateTime(2006, 3, 6), 50, false, false);

            Assert.AreEqual(50m, rPE.Fees.Value);
            Assert.AreEqual(0m, rPE.Interests.Value);
            Assert.AreEqual(0m, rPE.Principal.Value);

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType,
                                                                  package.KeepExpectedInstallment,
                                                                  false,
                                                                  0, 0,
                                                                  false,
                                                                  0,
                                                                  package.AnticipatedTotalRepaymentPenaltiesBase);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 4, 4), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(414m, cCR.MaximumAmountToRegradingLoan.Value);
        }
        public void TestCalculateMaximumAmountWithDecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnInitialAmountAndKeepNotExpectedInstallment()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);

            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.InitialAmount = 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.12m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
        }
        public void TestRounding()
        {
            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 = true;
            package.AnticipatedRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisioningTable.GetInstance(new User()));
            myContract.BadLoan = false;
            myContract.NonRepaymentPenalties.InitialAmount = 0.003;
            myContract.AnticipatedRepaymentPenalties = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, false, 0,
                                                                  package.AnticipatedRepaymentPenaltiesBase);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 2, 1), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));
            Assert.AreEqual(1180, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));

            myContract.Repay(1,new DateTime(2006,2,1),1179.97m,false,true);
            Assert.AreEqual(0,myContract.GetInstallment(0).PaidCapital.Value);
            Assert.AreEqual(200, myContract.GetInstallment(1).PaidCapital.Value);
            Assert.AreEqual(200, myContract.GetInstallment(2).PaidCapital.Value);
            Assert.AreEqual(200, myContract.GetInstallment(3).PaidCapital.Value);
            Assert.AreEqual(200, myContract.GetInstallment(4).PaidCapital.Value);
            Assert.AreEqual(199.97m, myContract.GetInstallment(5).PaidCapital.Value);
        }
Example #8
0
        public OCurrency CalculateAmountToRepaySpecifiedInstallment(int pNumber, DateTime pDate,
            bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount, 
            bool pDisableInterests, OCurrency pManualInterests, bool pKeepExpectedInstallment)
        {
            CreditContractOptions cCo =
                new CreditContractOptions(Product.LoanType, pKeepExpectedInstallment,
                    pCancelFees, pManualFeesAmount, pManualCommissionAmount,
                    pDisableInterests, pManualInterests, Product.AnticipatedTotalRepaymentPenaltiesBase);

            CreditContractRepayment cCr = new CreditContractRepayment(this, cCo, pDate, pNumber, _user, _generalSettings, _nwdS);

            return cCr.AmountToRepayInstallment;
        }
        public void TestCalculateMaximumAmountWithDecliningBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithoutInterestAndKeepExpectedInstallment()
        {
            LoanProduct package = new LoanProduct
                                      {
                                          InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                                          LoanType = OLoanTypes.DecliningFixedInstallments,
                                          ChargeInterestWithinGracePeriod = true,
                                          Currency = new Currency { Id = 1, UseCents = true},
                                          RoundingType = ORoundingType.Approximate
                                      };
            package.KeepExpectedInstallment = true;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.OverDuePrincipal = 0.003;
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, 0, false, 0,package.AnticipatedTotalRepaymentPenaltiesBase);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 3, 15), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(1129.68m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
        }
Example #10
0
        /// <summary>
        /// This method manages all the repayment cases implemented in the software
        /// </summary>
        /// <param name="pNumber">pNumber of the installment paid</param>
        /// <param name="pDate">pDate of the payment</param>
        /// <param name="pAmountPaid">amount paid by the client which can be lower, equal or greater than the expected amount for an installment</param>
        /// <param name="cancelFees">when true, cancel anticipated payment Commission</param>
        /// <param name="manualFeesAmount">manual amount of commission (when anticipated payment commission are cancelled)</param>
        /// <returns>A RepaymentEvent or null if : 
        /// - repayment amount lower than 0
        /// - repayment amount greater than olb + interestsToPay + commission
        /// - installment already repaid
        /// - bad loan and past due days greater than 180
        /// </returns>
        /// <param name="manualCommissionAmount"></param>
        /// <param name="disableInterests"></param>
        /// <param name="manualInterests"></param>
        /// <param name="keepExpectedInstallment"></param>
        /// <param name="payProportion"></param>
        /// <param name="paymentMethod"></param>
        /// <param name="comment"></param>
        /// <param name="pending"></param>
        public RepaymentEvent Repay(int pNumber, 
                                    DateTime pDate, 
                                    OCurrency pAmountPaid,
                                    bool cancelFees, 
                                    OCurrency manualFeesAmount, 
                                    OCurrency manualCommissionAmount,
                                    bool disableInterests, 
                                    OCurrency manualInterests, 
                                    bool keepExpectedInstallment,
                                    bool payProportion,
                                    PaymentMethod paymentMethod, 
                                    string comment, 
                                    bool pending)
        {
            OCurrency anticipatePayment =
                CalculateAnticipateInteresAmountForClosure(pDate, OPaymentType.PartialPayment, payProportion) +
                CalculateTotalNonRepaymentPenalties(pDate);

            if (anticipatePayment >= pAmountPaid
                || (anticipatePayment == 0 && GetInstallment(pNumber - 1).ExpectedDate <= pDate))
            {
                keepExpectedInstallment = true;
                payProportion = false;
            }

            var cCo = new CreditContractOptions(Product.LoanType,
                                                keepExpectedInstallment,
                                                cancelFees,
                                                manualFeesAmount,
                                                manualCommissionAmount,
                                                disableInterests,
                                                manualInterests,
                                                Product.AnticipatedTotalRepaymentPenaltiesBase,
                                                Product.IsExotic,
                                                payProportion);

            var cCr = new CreditContractRepayment(this, cCo, pDate, pNumber, _user, _generalSettings, _nwdS);

            if (AmountComparer.Compare(pAmountPaid, cCr.MaximumAmountAuthorizeToRepay, pNumber) > 0)
            {
                return null;
            }

            OCurrency principalEvent = 0;
            OCurrency interestEvent = 0;
            OCurrency interestPrepayment = 0;
            OCurrency penaltiesEvent = 0;
            OCurrency commissionsEvent = 0;
            OCurrency manualInterestEvent = cCo.ManualInterestsAmount;

            int pastDueDays = CalculatePastDueSinceLastRepayment(pDate);

            OPaymentType paymentType = OPaymentType.StandardPayment;

            foreach (Installment installment in InstallmentList)
            {
                if (!installment.IsRepaid && installment.Number == pNumber && !keepExpectedInstallment)
                {
                    paymentType = OPaymentType.PartialPayment;
                }
            }

            //we have total repayment for a person
            if(EscapedMember != null)
            {
                paymentType = OPaymentType.PartialPayment;
                keepExpectedInstallment = false;
                cCo.KeepExpectedInstallments = false;
            }

            if (AmountComparer.Compare(pAmountPaid, cCr.MaximumAmountAuthorizeToRepay, pNumber) == 0 && !keepExpectedInstallment)
            {
                paymentType = OPaymentType.TotalPayment;
            }

            if (payProportion && _product.LoanType == OLoanTypes.DecliningFixedPrincipal)
            {
                paymentType = OPaymentType.ProportionalPayment;
                keepExpectedInstallment = false;
                cCo.KeepExpectedInstallments = false;
            }

            if (_product.LoanType == OLoanTypes.DecliningFixedPrincipalWithRealInterest)
                paymentType = OPaymentType.StandardPayment;

            // We have to calculate penalties here because
            // once the repayment is done it is impossible to do
            // reliably afterward. These values are later used (see below)
            // during the event generation.

            cCr.Repay(pAmountPaid, ref penaltiesEvent, ref commissionsEvent, ref interestEvent,
                      ref interestPrepayment, ref principalEvent, ref manualInterestEvent, ref paymentType);

            //this part of code to correct calculation of principal
            OCurrency principalAmount = principalEvent;
            foreach (RepaymentEvent rPayment in Events.GetRepaymentEvents())
            {
                if (!rPayment.Deleted)
                    principalAmount += rPayment.Principal;

                if (principalAmount > Amount)
                {
                    principalEvent -= Math.Round(principalAmount.Value, 2) - Amount;
                }
            }

            // when we keep initial schedule and total payment
            if (AmountComparer.Compare(pAmountPaid, cCr.MaximumAmountAuthorizeToRepay, pNumber) == 0 && (pNumber != InstallmentList.Count) && AllInstallmentsRepaid)
            {
                paymentType = OPaymentType.TotalPayment;
            }

            //////////////////////////////////////////////////////////////
            RepaymentEvent rPe = CreateRepaymentEvent(pNumber,
                                                      pDate,
                                                      penaltiesEvent,
                                                      commissionsEvent,
                                                      interestEvent,
                                                      interestPrepayment,
                                                      principalEvent,
                                                      pastDueDays,
                                                      _clientType == OClientTypes.Group,
                                                      paymentType,
                                                      pending);

            if (AllInstallmentsRepaid && !pending)
            {
                if (ContractStatus != OContractStatus.WrittenOff)
                {
                    _closed = true;
                    ContractStatus = OContractStatus.Closed;
                    CloseDate = pDate;
                }

                // check if Client has other 'active' loans if so, mark him as active client
                if (Project != null)
                    foreach (var loan in Project.Credits)
                        Project.Client.Active = loan.ContractStatus == OContractStatus.Active;
            }

            //Event identification
            Events.Add(GenerateRepaymentEvents(cCr,
                                               pDate,
                                               penaltiesEvent, commissionsEvent, interestEvent,
                                                   interestPrepayment, principalEvent, pastDueDays, paymentType,
                                                   pending, pNumber, paymentMethod, cancelFees, manualFeesAmount,
                                                   manualInterestEvent,
                                               ref rPe));

            if (paymentType == OPaymentType.TotalPayment)
            {
                int installmentNumber = penaltiesEvent > 0 ? 0 : 1;
                Events.Add(GenerateCreditInsuranceEvent(installmentNumber));

                if (HasCompulsoryAmount())
                {
                    SavingBlockCompulsarySavingsEvent savingBlockEvent = CompulsorySavings.GetBlockCompulsorySavingEvent();
                    if (savingBlockEvent != null)
                        CompulsorySavings.GenerateUnblockCompulsoruSavingEvent(_user, true);
                }
            }

            //principal amount correction in case of shit which is taken place when we do big prepayment
            //please remove it when all shity contracts will be closed
            OCurrency paidPrincipal = 0;
            foreach (RepaymentEvent repaymentEvent in Events.GetLoanRepaymentEvents())
            {
                if(repaymentEvent.Deleted == false)
                {
                    paidPrincipal += repaymentEvent.Principal;
                }

                if(paidPrincipal >  Amount)
                {
                    repaymentEvent.Principal += Amount - paidPrincipal;
                }
            }
            //////////////////////////////////////////////////////////////////////////////////////////////

            _installmentList.Sort((x, y) => x.ExpectedDate.CompareTo(y.ExpectedDate));

            foreach (Installment installment in InstallmentList)
            {
                //setup paid date for installments
                if (installment.IsRepaid && installment.Number > pNumber)
                {
                    installment.PaidDate = pDate;
                    installment.Comment = comment;
                    installment.IsPending = pending;
                }
                else if (installment.Number == pNumber)
                {
                    installment.PaidDate = pDate;
                    installment.Comment = comment;
                    installment.IsPending = pending;
                }

                installment.OLB = CalculateExpectedOlb(installment.Number, keepExpectedInstallment);
            }
            EscapedMember = null;
            return rPe;
        }
Example #11
0
        private EventStock GenerateRepaymentEvents(CreditContractRepayment cCr, 
                                                   DateTime payDate, 
                                                   OCurrency penaltiesEvent,
                                                   OCurrency commissionsEvent, 
                                                   OCurrency interestEvent, 
                                                   OCurrency interestPrepayment, 
                                                   OCurrency principalEvent,
                                                   int pastDueDays, 
                                                   OPaymentType paymentType, 
                                                   bool isPending, 
                                                   int instNumber,
                                                   PaymentMethod paymentMethod,
                                                   bool overridePenalty,
                                                   OCurrency manualPenalty,
                                                   OCurrency manualInterestEvent,
                                                   ref RepaymentEvent totalEvent)
        {
            RepaymentEvent rpEvent;
            totalEvent.Penalties = 0;
            totalEvent.Commissions = 0;
            EventStock listOfLoanEvents = new EventStock();

            #region Event identification
            //////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (cCr.PaidIstallments.Count > 0)
            {
                List<Installment> lateInstallments = cCr.PaidIstallments.FindAll(i => i.CalculatedPenalty > 0);
                Installment lastLate = 0 == lateInstallments.Count ? null : lateInstallments.OrderBy(i => i.Number).Last();

                foreach (Installment paidInstallment in cCr.PaidIstallments)
                {
                    int number = paidInstallment.Number;
                    OCurrency rpeCapital = 0;
                    OCurrency rpeInterests = 0;
                    OCurrency rpeCommission = 0;
                    OCurrency rpePenalty = 0;
                    int overdueDays = (payDate.Date - paidInstallment.ExpectedDate).Days > 0
                                          ? (payDate.Date - paidInstallment.ExpectedDate).Days
                                          : 0;

                    foreach (RepaymentEvent rpe in Events.GetLoanRepaymentEvents())
                    {
                        if (rpe.InstallmentNumber == paidInstallment.Number && !rpe.Deleted)
                        {
                            if (rpe.RepaymentType != OPaymentType.PersonTotalPayment)
                            {
                                if ((rpe.RepaymentType != OPaymentType.PartialPayment)
                                    && (rpe.RepaymentType != OPaymentType.ProportionalPayment))
                                {
                                    rpeCapital += rpe.Principal;
                                    rpeInterests += rpe.Interests;
                                }

                                if (rpe.RepaymentType == OPaymentType.PartialPayment && paymentType == OPaymentType.TotalPayment)
                                {
                                    rpeCapital += rpe.Principal;
                                    rpeInterests += rpe.Interests;
                                }

                                rpePenalty += rpe.Penalties;
                            }

                            rpeCommission += rpe.Commissions;
                            if (rpe.RepaymentType == OPaymentType.PersonTotalPayment && cCr.LoanOptions.ManualCommissionAmount != 0)
                                rpeCommission -= rpe.Commissions;
                        }
                    }

                    if (rpeCapital > paidInstallment.PaidCapital)
                        rpeCapital = 0;

                    if (rpeInterests < 0)
                        rpeInterests = 0;

                    if (rpeInterests > paidInstallment.InterestsRepayment)
                    {
                        rpeInterests = 0;
                    }

                    OCurrency principalAmount = paidInstallment.CapitalRepayment -
                                                (paidInstallment.CapitalRepayment - (paidInstallment.PaidCapital - rpeCapital));

                    OCurrency interestAmount = paidInstallment.InterestsRepayment -
                                               (paidInstallment.InterestsRepayment - (paidInstallment.PaidInterests - rpeInterests));

                    if (interestAmount < 0)
                        interestAmount = 0;

                    principalEvent -= principalAmount;
                    interestEvent -= interestAmount;

                    if (principalAmount == 0
                        && interestAmount == 0
                        && paidInstallment.PaidCapital == 0 && manualInterestEvent == 0)
                    {
                        principalAmount = principalEvent;
                        interestAmount = interestEvent;
                    }

                    if (interestAmount < 0)
                        interestAmount = 0;

                    OCurrency commissionAmount = paidInstallment.CommissionsUnpaid -
                                               (paidInstallment.CommissionsUnpaid - (paidInstallment.PaidCommissions - rpeCommission));

                    OCurrency penaltyAmount;
                    if (overridePenalty)
                    {
                        if (lastLate != null && paidInstallment.CalculatedPenalty <= manualPenalty && paidInstallment.Number < lastLate.Number)
                        {
                            penaltyAmount = paidInstallment.CalculatedPenalty;
                            manualPenalty -= penaltyAmount;
                        }
                        else
                        {
                            penaltyAmount = manualPenalty;
                            manualPenalty = 0m;
                        }
                    }
                    else
                    {
                        penaltyAmount = paidInstallment.FeesUnpaid -
                                                  (paidInstallment.FeesUnpaid - (paidInstallment.PaidFees - rpePenalty));
                    }

                    //just to be sure that we do not have negative in the base
                    penaltyAmount = penaltyAmount < 0 ? 0 : penaltyAmount;
                    commissionAmount = commissionAmount < 0 ? 0 : commissionAmount;

                    if (overridePenalty && penaltyAmount > 0)
                    {
                        penaltyAmount = (-1.0) * penaltyAmount;
                    }

                    rpEvent = CreateRepaymentEvent(number,
                                                       payDate,
                                                       penaltyAmount,
                                                       commissionAmount,
                                                       interestAmount,
                                                       interestAmount,
                                                       principalAmount,
                                                       overdueDays,
                                                       _clientType == OClientTypes.Group,
                                                       paymentType,
                                                       isPending);

                    if (overridePenalty && penaltyAmount < 0)
                        penaltyAmount = (-1.0)*penaltyAmount;
                    rpEvent.PaymentMethod = paymentMethod;
                    rpEvent.CalculatedPenalties = paidInstallment.CalculatedPenalty;
                    if (rpEvent.CalculatedPenalties > penaltyAmount)
                    {
                        if (overridePenalty)
                        {
                            rpEvent.WrittenOffPenalties = rpEvent.CalculatedPenalties - penaltyAmount;
                        }
                        else
                        {
                            rpEvent.UnpaidPenalties = rpEvent.CalculatedPenalties - penaltyAmount;
                        }
                    }
                    totalEvent.Penalties += rpEvent.Penalties;
                    totalEvent.Commissions += rpEvent.Commissions;

                    if (rpEvent.InterestPrepayment != 0
                        || rpEvent.Principal != 0
                        || rpEvent.Penalties != 0
                        || rpEvent.Commissions != 0)
                        listOfLoanEvents.Add(rpEvent);
                }
            }
            else
            {
                rpEvent = CreateRepaymentEvent(instNumber,
                                               payDate,
                                               penaltiesEvent,
                                               commissionsEvent,
                                               interestEvent,
                                               interestPrepayment,
                                               principalEvent,
                                               pastDueDays,
                                               _clientType == OClientTypes.Group,
                                               paymentType,
                                               isPending);
                rpEvent.PaymentMethod = paymentMethod;
                // Calculate penalties
                Installment installment = GetInstallment(instNumber - 1);
                rpEvent.CalculatedPenalties = installment.CalculatedPenalty;
                if (rpEvent.CalculatedPenalties > penaltiesEvent)
                {
                    if (overridePenalty)
                    {
                        rpEvent.WrittenOffPenalties = rpEvent.CalculatedPenalties - penaltiesEvent;
                    }
                    else
                    {
                        rpEvent.UnpaidPenalties = rpEvent.CalculatedPenalties - penaltiesEvent;
                    }
                }
                totalEvent.Penalties += rpEvent.Penalties;
                totalEvent.Commissions += rpEvent.Commissions;
                listOfLoanEvents.Add(rpEvent);
            }
            #endregion

            return listOfLoanEvents;
        }
Example #12
0
        public OCurrency CalculateMaximumAmountForEscapedMember(int pNumber, DateTime pDate,
            bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount,
            bool pDisableInterests, OCurrency pManualInterests, bool pKeepExpectedInstallment, OCurrency pLoanShareAmount)
        {
            var cCo = new CreditContractOptions(Product.LoanType,
                                                pKeepExpectedInstallment,
                                                pCancelFees,
                                                pManualFeesAmount,
                                                pManualCommissionAmount,
                                                pDisableInterests,
                                                pManualInterests,
                                                Product.AnticipatedTotalRepaymentPenaltiesBase,
                                                Product.IsExotic,
                                                false);

            var cCr = new CreditContractRepayment(this, cCo, pDate, pNumber, _user, _generalSettings, _nwdS);

            return cCr.MaximumAmountForEscapedMember;
        }
Example #13
0
        public OCurrency CalculateMaximumAmountAuthorizedToRepay(int pNumber, DateTime pDate, 
            bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount, 
            bool pDisableInterests, OCurrency pManualInterests, bool pKeepExpectedInstallment, bool pIsForExoticProduct)
        {
            Loan fakeLoan = Copy();
            if (_generalSettings.AccountingProcesses == OAccountingProcesses.Accrual && !pKeepExpectedInstallment)
            {
                fakeLoan.CreateLoanInterestAccruingEvent(pDate);
            }

            CreditContractOptions cCo = new CreditContractOptions(Product.LoanType,
                                                                  pKeepExpectedInstallment,
                                                                  pCancelFees,
                                                                  pManualFeesAmount,
                                                                  pManualCommissionAmount,
                                                                  pDisableInterests,
                                                                  pManualInterests,
                                                                  Product.AnticipatedTotalRepaymentPenaltiesBase,
                                                                  pIsForExoticProduct,
                                                                  false);

            CreditContractRepayment cCr = new CreditContractRepayment(fakeLoan,
                                                                      cCo,
                                                                      pDate,
                                                                      pNumber,
                                                                      _user,
                                                                      _generalSettings,
                                                                      _nwdS);

            return cCr.MaximumAmountAuthorizeToRepay;
        }
        public void TestCalculateAmountToRegradingLoanWithFlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnInitialAmountAndKeepExpectedInstallmentAndCancelFeesSetToTrue()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);
            LoanProduct package = new LoanProduct
            {
                InstallmentType = new InstallmentType(1, "Monthly", 0, 1),
                LoanType = OLoanTypes.Flat,
                ChargeInterestWithinGracePeriod = true
            };
            package.KeepExpectedInstallment = true;
            package.AnticipatedRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisioningTable.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 0.003;
            myContract.AnticipatedRepaymentPenalties = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, true, 0, false, 0,
                                                                  package.AnticipatedRepaymentPenaltiesBase);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 3, 15), 1, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(260, Math.Round(cCR.MaximumAmountToRegradingLoan.Value, 2));
        }
        public void TestCalculateEventWhenRepayTotallyFlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnOverDueWithoutIntereestAndKeepNotExpectedInstallment()
        {
            Assert.Ignore();
            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.OverDuePrincipal = 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(1076.4m, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
            RepaymentEvent bLRE = myContract.Repay(1, new DateTime(2006, 3, 15), 1076.4m, false, false);

            Assert.AreEqual(16.40m, bLRE.Fees.Value);
            Assert.AreEqual(60, bLRE.Interests.Value);
            Assert.AreEqual(1000, bLRE.Principal.Value);
        }
        public void TestCalculateMaximumAmountWithFlateBadLoanWith42dayslateWhenNonRepaymentFeesBaseOnInitialAmountAndKeepNotExpectedInstallment()
        {
            Assert.Ignore();
            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;
            package.AnticipatedTotalRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;

            Loan myContract = new Loan(package, 1000, 0.03m, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisionTable.GetInstance(new User()), ChartOfAccounts.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 0.003;
            myContract.AnticipatedTotalRepaymentPenalties = 0.01;

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

            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.00m, false, false);
            Assert.AreEqual(0m, rPE.Fees.Value);
            Assert.AreEqual(30m, rPE.Interests.Value);
            Assert.AreEqual(356m, rPE.Principal.Value);

            CreditContractRepayment cCR2 = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 4, 3), 3, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));
            Assert.AreEqual(932.09, Math.Round(cCR2.MaximumAmountAuthorizeToRepay.Value, 2));

            RepaymentEvent rPE2 = myContract.Repay(1, new DateTime(2006, 4, 3), 836, false, false);
            Assert.AreEqual(4, rPE2.Fees.Value);
            Assert.AreEqual(90, rPE2.Interests.Value);
            Assert.AreEqual(742, rPE2.Principal.Value);

            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);
        }
        public void TestCalculateMaximumAmountWhenRepayFlatLoanWith1MonthLate()
        {
            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 = false;
            myContract.AnticipatedTotalRepaymentPenalties = 0.03;

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

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, 0, false, 0,
                                                                  package.AnticipatedTotalRepaymentPenaltiesBase);
            CreditContractRepayment cCR = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 4, 3), 2, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));

            Assert.AreEqual(1078, Math.Round(cCR.MaximumAmountAuthorizeToRepay.Value, 2));
        }
        public void TestRepayDecliningLoanWhenKeepExpectedInstallmentButEntirlyPaidButNoCancelFees()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.CALCULATIONLATEFEESDURINGPUBLICHOLIDAYS, true);

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

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

            Assert.AreEqual(1107.58m, cCR.MaximumAmountAuthorizeToRepay.Value);

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

            Assert.AreEqual(0m, repayEvent.Fees.Value);
            Assert.AreEqual(107.58m, repayEvent.Interests.Value);
            Assert.AreEqual(1000m, repayEvent.Principal.Value);

            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(154.60m, myContract.GetInstallment(1).CapitalRepayment.Value);
            Assert.AreEqual(1000m, myContract.GetInstallment(1).OLB.Value);
            Assert.AreEqual(154.60m, myContract.GetInstallment(1).PaidCapital.Value);
            Assert.AreEqual(30m, myContract.GetInstallment(1).PaidInterests.Value);

            Assert.AreEqual(25.36m, myContract.GetInstallment(2).InterestsRepayment.Value);
            Assert.AreEqual(159.24m, myContract.GetInstallment(2).CapitalRepayment.Value);
            Assert.AreEqual(845.40m, myContract.GetInstallment(2).OLB.Value);
            Assert.AreEqual(159.24m, myContract.GetInstallment(2).PaidCapital.Value);
            Assert.AreEqual(25.36m, myContract.GetInstallment(2).PaidInterests.Value);

            Assert.AreEqual(20.58m, myContract.GetInstallment(3).InterestsRepayment.Value);
            Assert.AreEqual(164.02m, myContract.GetInstallment(3).CapitalRepayment.Value);
            Assert.AreEqual(686.16m, myContract.GetInstallment(3).OLB.Value);
            Assert.AreEqual(164.02m, myContract.GetInstallment(3).PaidCapital.Value);
            Assert.AreEqual(20.58m, myContract.GetInstallment(3).PaidInterests.Value);

            Assert.AreEqual(15.66m, myContract.GetInstallment(4).InterestsRepayment.Value);
            Assert.AreEqual(168.93m, myContract.GetInstallment(4).CapitalRepayment.Value);
            Assert.AreEqual(522.14m, myContract.GetInstallment(4).OLB.Value);
            Assert.AreEqual(168.93m, myContract.GetInstallment(4).PaidCapital.Value);
            Assert.AreEqual(15.66m, myContract.GetInstallment(4).PaidInterests.Value);

            Assert.AreEqual(10.60m, myContract.GetInstallment(5).InterestsRepayment.Value);
            Assert.AreEqual(173.99m, myContract.GetInstallment(5).CapitalRepayment.Value);
            Assert.AreEqual(353.21m, myContract.GetInstallment(5).OLB.Value);
            Assert.AreEqual(173.99m, myContract.GetInstallment(5).PaidCapital.Value);
            Assert.AreEqual(10.60m, myContract.GetInstallment(5).PaidInterests.Value);

            Assert.AreEqual(5.38m, myContract.GetInstallment(6).InterestsRepayment.Value);
            Assert.AreEqual(179.22m, myContract.GetInstallment(6).CapitalRepayment.Value);
            Assert.AreEqual(179.22m, myContract.GetInstallment(6).OLB.Value);
            Assert.AreEqual(179.22m, myContract.GetInstallment(6).PaidCapital.Value);
            Assert.AreEqual(5.38m, myContract.GetInstallment(6).PaidInterests.Value);
        }
Example #19
0
        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 TestRepayFlatLoan()
        {
            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.AnticipatedRepaymentPenaltiesBase = OAnticipatedRepaymentPenaltiesBases.RemainingOLB;
            Loan myContract = new Loan(package, 1000, 0.03, 6, 1, new DateTime(2006, 1, 1), new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""), ProvisioningTable.GetInstance(new User()));
            myContract.BadLoan = true;
            myContract.NonRepaymentPenalties.InitialAmount = 0.003;
            myContract.AnticipatedRepaymentPenalties = 0.01;

            CreditContractOptions cCO = new CreditContractOptions(package.LoanType, package.KeepExpectedInstallment, false, 0, false, 0,
                                                                  package.AnticipatedRepaymentPenaltiesBase);
            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,Math.Round(cCR.MaximumAmountToRegradingLoan.Value,2));

            RepaymentEvent rPE = myContract.Repay(1,new DateTime(2006,3,15),386,false,false);
            Assert.AreEqual(126m,rPE.Fees.Value);
            Assert.AreEqual(60m,rPE.Interests.Value);
            Assert.AreEqual(200m,rPE.Principal.Value);

            CreditContractRepayment cCR2 = new CreditContractRepayment(myContract, cCO, new DateTime(2006, 4, 3), 3, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance(""));
            Assert.AreEqual(836,Math.Round(cCR2.MaximumAmountAuthorizeToRepay.Value,2));
        }