Пример #1
0
 public void TestCompareWhenAmount2MinusAmount1GreaterThan002()
 {
     Assert.IsTrue(AmountComparer.Compare(154.011m, 154.033m) < 0);
 }
Пример #2
0
 public void TestCompareWhenAmount2MinusAmount1LowerThan002()
 {
     Assert.IsTrue(AmountComparer.Compare(154.014m, 154.033m) == 0);
 }
        public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid <= 0)
            {
                return;
            }
            OCurrency totalInterest  = 0;
            OCurrency totalPrincipal = 0;
            double    nbInterest     = 0;
            double    nbPrincipal    = 0;

            foreach (Installment installment in _contract.InstallmentList)
            {
                if (installment.InterestsRepayment - installment.PaidInterests > 0)
                {
                    totalInterest += (installment.InterestsRepayment - installment.PaidInterests);
                    if (!_contract.GracePeriod.HasValue)
                    {
                        nbInterest += _contract.Product.ExoticProduct.GetExoticInstallment(installment.Number - 1).InterestCoeff.Value;
                    }
                    else if (installment.Number > _contract.GracePeriod.Value)
                    {
                        nbInterest += _contract.Product.ExoticProduct.GetExoticInstallment(installment.Number - 1 - _contract.GracePeriod.Value).InterestCoeff.Value;
                    }
                }

                if (installment.CapitalRepayment - installment.PaidCapital > 0)
                {
                    totalPrincipal += (installment.CapitalRepayment - installment.PaidCapital);
                    if (!_contract.GracePeriod.HasValue)
                    {
                        nbPrincipal += _contract.Product.ExoticProduct.GetExoticInstallment(installment.Number - 1).PrincipalCoeff;
                    }
                    else if (installment.Number > _contract.GracePeriod.Value)
                    {
                        nbPrincipal += _contract.Product.ExoticProduct.GetExoticInstallment(installment.Number - 1 - _contract.GracePeriod.Value).PrincipalCoeff;
                    }
                }
            }

            if (AmountComparer.Compare(amountPaid, totalInterest) > 0)
            {
                amountPaid         -= totalInterest;
                interestEvent      += totalInterest;
                interestPrepayment += totalInterest;
                totalInterest       = 0;
            }
            else
            {
                totalInterest      -= amountPaid;
                interestEvent      += amountPaid;
                interestPrepayment += amountPaid;
                amountPaid          = 0;
            }

            if (AmountComparer.Compare(amountPaid, totalPrincipal) > 0)
            {
                amountPaid     -= totalPrincipal;
                principalEvent += totalPrincipal;
                totalPrincipal  = 0;
            }
            else
            {
                totalPrincipal -= amountPaid;
                principalEvent += amountPaid;
                amountPaid      = 0;
            }

            if (totalInterest != 0)
            {
                totalInterest = totalInterest / (Convert.ToDecimal(nbInterest) * 10);
            }

            if (totalPrincipal != 0)
            {
                totalPrincipal = totalPrincipal / (Convert.ToDecimal(nbPrincipal) * 10);
            }

            OCurrency interestForLastInstallment = 0;
            OCurrency capitalForLastInstallment  = 0;

            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                Installment installment = _contract.GetInstallment(i);
                if (!installment.IsRepaid)
                {
                    ExoticInstallment exoticInstallment;

                    if (!_contract.GracePeriod.HasValue)
                    {
                        exoticInstallment = _contract.Product.ExoticProduct.GetExoticInstallment(i);

                        OCurrency tempInterest = Convert.ToDecimal(exoticInstallment.InterestCoeff) * totalInterest * (double)10;
                        OCurrency tempCapital  = Convert.ToDecimal(exoticInstallment.PrincipalCoeff) * totalPrincipal * (double)10;

                        installment.InterestsRepayment = Math.Truncate(tempInterest.Value);
                        installment.CapitalRepayment   = Math.Truncate(tempCapital.Value);

                        interestForLastInstallment += tempInterest - installment.InterestsRepayment;
                        capitalForLastInstallment  += tempCapital - installment.CapitalRepayment;
                    }
                    else if (installment.Number > _contract.GracePeriod.Value)
                    {
                        exoticInstallment = _contract.Product.ExoticProduct.GetExoticInstallment(i - _contract.GracePeriod.Value);

                        OCurrency tempInterest = Convert.ToDecimal(exoticInstallment.InterestCoeff) * totalInterest * (double)10;
                        OCurrency tempCapital  = Convert.ToDecimal(exoticInstallment.PrincipalCoeff) * totalPrincipal * (double)10;

                        installment.InterestsRepayment = Math.Truncate(tempInterest.Value);
                        installment.CapitalRepayment   = Math.Truncate(tempCapital.Value);

                        interestForLastInstallment += tempInterest - installment.InterestsRepayment;
                        capitalForLastInstallment  += tempCapital - installment.CapitalRepayment;
                    }
                    else
                    {
                        OCurrency tempInterest = 0;
                        if (totalInterest != 0)
                        {
                            tempInterest = totalPrincipal * Convert.ToDecimal(_contract.InterestRate);
                        }

                        installment.InterestsRepayment = Math.Truncate(tempInterest.Value);
                        installment.CapitalRepayment   = 0;

                        interestForLastInstallment += tempInterest - installment.InterestsRepayment;
                    }
                }

                _paidInstallments.Add(installment);
            }

            Installment lastInstallment = _contract.GetInstallment(_contract.NbOfInstallments - 1);

            lastInstallment.InterestsRepayment += interestForLastInstallment;
            lastInstallment.CapitalRepayment   += capitalForLastInstallment;
            lastInstallment.InterestsRepayment  = lastInstallment.InterestsRepayment;
            lastInstallment.CapitalRepayment    = lastInstallment.CapitalRepayment;

            lastInstallment.InterestsRepayment = Math.Round(lastInstallment.InterestsRepayment.Value, 0);
            lastInstallment.CapitalRepayment   = Math.Round(lastInstallment.CapitalRepayment.Value, 0);
        }
Пример #4
0
 public void TestCompareWhenAmount1MinusAmount2GreaterThan002()
 {
     Assert.IsTrue(AmountComparer.Compare(154.033m, 154.001m) > 0);
 }
        public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid == 0)
            {
                return;
            }
            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                Installment installment = _contract.GetInstallment(i);
                if (!installment.IsRepaid && amountPaid > 0)
                {
                    //commission
                    _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);
                    if (amountPaid == 0)
                    {
                        break;
                    }

                    //penalty
                    _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);
                    if (amountPaid == 0)
                    {
                        break;
                    }

                    //Interests
                    if (amountPaid == 0)
                    {
                        return;
                    }
                    _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent, ref interestPrepayment);

                    //principal
                    if (amountPaid == 0)
                    {
                        _paidInstallments.Add(installment);
                        return;
                    }

                    OCurrency principalHasToPay = installment.CapitalRepayment - installment.PaidCapital;

                    if (AmountComparer.Compare(amountPaid, principalHasToPay) < 0)
                    {
                        installment.PaidCapital += amountPaid;
                        installment.PaidCapital  = Math.Round(installment.PaidCapital.Value, 2);
                        principalEvent          += amountPaid;
                        amountPaid = 0;
                    }
                    else if (AmountComparer.Compare(amountPaid, principalHasToPay) > 0)
                    {
                        installment.PaidCapital = installment.CapitalRepayment;
                        amountPaid     -= principalHasToPay;
                        principalEvent += principalHasToPay;
                    }
                    else
                    {
                        installment.PaidCapital += amountPaid;
                        installment.PaidCapital  = Math.Round(installment.PaidCapital.Value, 2);
                        principalEvent          += amountPaid;
                        amountPaid = 0;
                    }

                    _paidInstallments.Add(installment);
                }
            }
        }