Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\Financial\CashFlow\Constant\Periodic;
   4  
   5  use PhpOffice\PhpSpreadsheet\Calculation\Financial\Constants as FinancialConstants;
   6  
   7  class InterestAndPrincipal
   8  {
   9      protected $interest;
  10  
  11      protected $principal;
  12  
  13      public function __construct(
  14          float $rate = 0.0,
  15          int $period = 0,
  16          int $numberOfPeriods = 0,
  17          float $presentValue = 0,
  18          float $futureValue = 0,
  19          int $type = FinancialConstants::PAYMENT_END_OF_PERIOD
  20      ) {
  21          $payment = Payments::annuity($rate, $numberOfPeriods, $presentValue, $futureValue, $type);
  22          $capital = $presentValue;
  23          $interest = 0.0;
  24          $principal = 0.0;
  25          for ($i = 1; $i <= $period; ++$i) {
  26              $interest = ($type === FinancialConstants::PAYMENT_BEGINNING_OF_PERIOD && $i == 1) ? 0 : -$capital * $rate;
  27              $principal = $payment - $interest;
  28              $capital += $principal;
  29          }
  30  
  31          $this->interest = $interest;
  32          $this->principal = $principal;
  33      }
  34  
  35      public function interest(): float
  36      {
  37          return $this->interest;
  38      }
  39  
  40      public function principal(): float
  41      {
  42          return $this->principal;
  43      }
  44  }