This commit is contained in:
Dennis Eichhorn 2024-04-07 17:31:43 +00:00
parent ab3e8e0939
commit 1c2ecda287
9 changed files with 65 additions and 6 deletions

View File

@ -133,4 +133,54 @@ final class Loan
{
return $loan / $collateral;
}
public static function getAmortizationLoanPayment(float $loan, float $r, int $duration, int $interval)
{
return $loan * (($r / $interval * (1.0 + $r / $interval) / $duration) / ((1.0 + $r / $interval) / $duration) - 1);
}
public static function getAmortizationLoanInterest(float $loan, float $r, int $interval) : float
{
return $loan * $r / $interval;
}
public static function getAmortizationPrincipalPayment(float $payment, float $interest)
{
return $payment - $interest;
}
/**
* @param float $loan Loan amount
* @param float $r Borrowing rate (annual)
* @param int $duration Loan duration in months
* @param int $interval Payment interval (usually 12 = every month)
*/
public static function getAmortizationSchedule(float $loan, float $r, int $duration, int $interval) : array
{
$schedule = [0 => ['loan' => $loan, 'total' => 0.0, 'interest' => 0.0, 'principal' => 0.0]];
$previous = \reset($schedule);
while ($previous['loan'] > 0.0) {
$new = [
'loan' => 0.0,
'total' => 0.0,
'interest' => 0.0,
'principal' => 0.0,
];
$new['total'] = \round(self::getAmortizationLoanPayment($previous['loan'], $r, $duration, $interval), 2);
$new['interest'] = \round(self::getAmortizationLoanInterest($previous['loan'], $r, $interval), 2);
$new['principal'] = \round($new['total'] - $new['interest'], 2);
$new['loan'] = \max(0, \round($previous['loan'] - $new['principal'], 2));
if ($new['loan'] < 0.01) {
$new['loan'] = 0.0;
}
$schedule[] = $new;
$previous = $new;
}
return $schedule;
}
}

View File

@ -400,7 +400,7 @@ abstract class DataMapperAbstract
* @param string $logic Comparison logic (e.g. =, in, ...)
* @param string $connector Filter connector (e.g. AND, OR, ...)
*
* @return self
* @return static
*
* @since 1.0.0
*/

View File

@ -17,7 +17,7 @@ namespace phpOMS\Localization\Defaults;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
* City mapper class.
*
* @package phpOMS\Localization\Defaults
* @license OMS License 2.0

View File

@ -17,7 +17,7 @@ namespace phpOMS\Localization\Defaults;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
* Country mapper class.
*
* @package phpOMS\Localization\Defaults
* @license OMS License 2.0

View File

@ -17,7 +17,7 @@ namespace phpOMS\Localization\Defaults;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
* Currency mapper class.
*
* @package phpOMS\Localization\Defaults
* @license OMS License 2.0

View File

@ -17,7 +17,7 @@ namespace phpOMS\Localization\Defaults;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
* Iban mapper class.
*
* @package phpOMS\Localization\Defaults
* @license OMS License 2.0

View File

@ -17,7 +17,7 @@ namespace phpOMS\Localization\Defaults;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
* Language mapper class.
*
* @package phpOMS\Localization\Defaults
* @license OMS License 2.0

View File

@ -30,6 +30,10 @@ use phpOMS\Account\Account;
*
* @todo Instead of doing only regex matching, combine it with a tree search, this should be faster
* https://github.com/Karaka-Management/phpOMS/issues/276
*
* @question Consider to build Routes.php files from class Attributes.
* This way we would have the advantage of both worlds.
* Of course the update and install function would be a bit more complicated
*/
final class WebRouter implements RouterInterface
{
@ -134,6 +138,10 @@ final class WebRouter implements RouterInterface
}
foreach ($destination as $d) {
if (!$d['active']) {
continue;
}
if ($d['verb'] === RouteVerb::ANY
|| $verb === RouteVerb::ANY
|| ($verb & $d['verb']) === $verb

View File

@ -19,6 +19,7 @@ return [
[
'dest' => '\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testEndpoint',
'verb' => RouteVerb::GET,
'active' => true,
'permission' => [
'type' => 1,
'state' => 2,