From 1c2ecda2872dabe808920a9fe69d1673bca5d368 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 7 Apr 2024 17:31:43 +0000 Subject: [PATCH] ui fixes --- Business/Finance/Loan.php | 50 +++++++++++++++++++ .../Database/Mapper/DataMapperAbstract.php | 2 +- Localization/Defaults/CityMapper.php | 2 +- Localization/Defaults/CountryMapper.php | 2 +- Localization/Defaults/CurrencyMapper.php | 2 +- Localization/Defaults/IbanMapper.php | 2 +- Localization/Defaults/LanguageMapper.php | 2 +- Router/WebRouter.php | 8 +++ .../Admin/Install/Application/Routes.php | 1 + 9 files changed, 65 insertions(+), 6 deletions(-) diff --git a/Business/Finance/Loan.php b/Business/Finance/Loan.php index f8fffc10d..647e02c96 100755 --- a/Business/Finance/Loan.php +++ b/Business/Finance/Loan.php @@ -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; + } } diff --git a/DataStorage/Database/Mapper/DataMapperAbstract.php b/DataStorage/Database/Mapper/DataMapperAbstract.php index d63ef9d34..d2bf67c43 100755 --- a/DataStorage/Database/Mapper/DataMapperAbstract.php +++ b/DataStorage/Database/Mapper/DataMapperAbstract.php @@ -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 */ diff --git a/Localization/Defaults/CityMapper.php b/Localization/Defaults/CityMapper.php index bb06f779a..8bbf91872 100755 --- a/Localization/Defaults/CityMapper.php +++ b/Localization/Defaults/CityMapper.php @@ -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 diff --git a/Localization/Defaults/CountryMapper.php b/Localization/Defaults/CountryMapper.php index 7f66ab9b6..588223d59 100755 --- a/Localization/Defaults/CountryMapper.php +++ b/Localization/Defaults/CountryMapper.php @@ -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 diff --git a/Localization/Defaults/CurrencyMapper.php b/Localization/Defaults/CurrencyMapper.php index 296de7233..c685dd766 100755 --- a/Localization/Defaults/CurrencyMapper.php +++ b/Localization/Defaults/CurrencyMapper.php @@ -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 diff --git a/Localization/Defaults/IbanMapper.php b/Localization/Defaults/IbanMapper.php index ae8af7bdf..2b58aca03 100755 --- a/Localization/Defaults/IbanMapper.php +++ b/Localization/Defaults/IbanMapper.php @@ -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 diff --git a/Localization/Defaults/LanguageMapper.php b/Localization/Defaults/LanguageMapper.php index 2e692a0be..16a1c24a0 100755 --- a/Localization/Defaults/LanguageMapper.php +++ b/Localization/Defaults/LanguageMapper.php @@ -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 diff --git a/Router/WebRouter.php b/Router/WebRouter.php index cc962d13a..68b158566 100755 --- a/Router/WebRouter.php +++ b/Router/WebRouter.php @@ -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 diff --git a/tests/Application/Testapp/Admin/Install/Application/Routes.php b/tests/Application/Testapp/Admin/Install/Application/Routes.php index a46bb7b9d..72e0d4f13 100755 --- a/tests/Application/Testapp/Admin/Install/Application/Routes.php +++ b/tests/Application/Testapp/Admin/Install/Application/Routes.php @@ -19,6 +19,7 @@ return [ [ 'dest' => '\phpOMS\tess\Application\Apps\Testapp\Controller\Controller:testEndpoint', 'verb' => RouteVerb::GET, + 'active' => true, 'permission' => [ 'type' => 1, 'state' => 2,