You are here

public static function PHPExcel_Calculation_Financial::CUMPRINC in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::CUMPRINC()

* CUMPRINC * * Returns the cumulative principal paid on a loan between the start and end periods. * * Excel Function: * CUMPRINC(rate,nper,pv,start,end[,type]) * * @access public * @category Financial Functions *

Parameters

float $rate The Interest rate: * @param integer $nper The total number of payment periods * @param float $pv Present Value * @param integer $start The first period in the calculation. * Payment periods are numbered beginning with 1. * @param integer $end The last period in the calculation. * @param integer $type A number 0 or 1 and indicates when payments are due: * 0 or omitted At the end of the period. * 1 At the beginning of the period. * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php, line 856

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0) {
  $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
  $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper);
  $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv);
  $start = (int) PHPExcel_Calculation_Functions::flattenSingleValue($start);
  $end = (int) PHPExcel_Calculation_Functions::flattenSingleValue($end);
  $type = (int) PHPExcel_Calculation_Functions::flattenSingleValue($type);

  // Validate parameters
  if ($type != 0 && $type != 1) {
    return PHPExcel_Calculation_Functions::NaN();
  }
  if ($start < 1 || $start > $end) {
    return PHPExcel_Calculation_Functions::VALUE();
  }

  // Calculate
  $principal = 0;
  for ($per = $start; $per <= $end; ++$per) {
    $principal += self::PPMT($rate, $per, $nper, $pv, 0, $type);
  }
  return $principal;
}