ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Cumulative.php
Go to the documentation of this file.
1<?php
2
4
9
11{
32 public static function interest(
33 $rate,
34 $periods,
35 $presentValue,
36 $start,
37 $end,
38 $type = FinancialConstants::PAYMENT_END_OF_PERIOD
39 ) {
40 $rate = Functions::flattenSingleValue($rate);
41 $periods = Functions::flattenSingleValue($periods);
42 $presentValue = Functions::flattenSingleValue($presentValue);
45 $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
46
47 try {
49 $periods = CashFlowValidations::validateInt($periods);
50 $presentValue = CashFlowValidations::validatePresentValue($presentValue);
54 } catch (Exception $e) {
55 return $e->getMessage();
56 }
57
58 // Validate parameters
59 if ($start < 1 || $start > $end) {
60 return Functions::NAN();
61 }
62
63 // Calculate
64 $interest = 0;
65 for ($per = $start; $per <= $end; ++$per) {
66 $ipmt = Interest::payment($rate, $per, $periods, $presentValue, 0, $type);
67 if (is_string($ipmt)) {
68 return $ipmt;
69 }
70
71 $interest += $ipmt;
72 }
73
74 return $interest;
75 }
76
97 public static function principal(
98 $rate,
99 $periods,
100 $presentValue,
101 $start,
102 $end,
103 $type = FinancialConstants::PAYMENT_END_OF_PERIOD
104 ) {
105 $rate = Functions::flattenSingleValue($rate);
106 $periods = Functions::flattenSingleValue($periods);
107 $presentValue = Functions::flattenSingleValue($presentValue);
110 $type = ($type === null) ? FinancialConstants::PAYMENT_END_OF_PERIOD : Functions::flattenSingleValue($type);
111
112 try {
114 $periods = CashFlowValidations::validateInt($periods);
115 $presentValue = CashFlowValidations::validatePresentValue($presentValue);
119 } catch (Exception $e) {
120 return $e->getMessage();
121 }
122
123 // Validate parameters
124 if ($start < 1 || $start > $end) {
125 return Functions::VALUE();
126 }
127
128 // Calculate
129 $principal = 0;
130 for ($per = $start; $per <= $end; ++$per) {
131 $ppmt = Payments::interestPayment($rate, $per, $periods, $presentValue, 0, $type);
132 if (is_string($ppmt)) {
133 return $ppmt;
134 }
135
136 $principal += $ppmt;
137 }
138
139 return $principal;
140 }
141}
An exception for terminatinating execution or to throw for unit testing.
static interest( $rate, $periods, $presentValue, $start, $end, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
CUMIPMT.
Definition: Cumulative.php:32
static principal( $rate, $periods, $presentValue, $start, $end, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
CUMPRINC.
Definition: Cumulative.php:97
static payment( $interestRate, $period, $numberOfPeriods, $presentValue, $futureValue=0, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
IPMT.
Definition: Interest.php:34
static interestPayment( $interestRate, $period, $numberOfPeriods, $presentValue, $futureValue=0, $type=FinancialConstants::PAYMENT_END_OF_PERIOD)
PPMT.
Definition: Payments.php:72
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
$type
$start
Definition: bench.php:8