From 0df412b6be718c2389a7ed87ff062b4aba86c030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sat, 23 Nov 2024 18:24:15 +0100 Subject: [PATCH] refactor loan schedule --- htdocs/core/lib/loan.lib.php | 16 ++++++---- htdocs/loan/schedule.php | 57 +++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index 3de9f42290b..88b5146eff9 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -1,8 +1,8 @@ - * Copyright (C) 2015-2020 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2020 Maxime DEMAREST - * Copyright (C) 2024 MDW + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -98,7 +98,7 @@ function loan_prepare_head($object) * @param float $rate Loan rate * @param int $numactualloadterm Actual loan term * @param int $nbterm Total number of term for this loan - * @return array Array with remaining capital, interest, and mensuality for each remaining terms + * @return array Array with remaining capital, interest, and mensuality for each remaining terms */ function loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm) { @@ -123,7 +123,13 @@ function loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbt $int = round($int, 2, PHP_ROUND_HALF_UP); $cap_rest = round((float) $capital - ((float) $mens - $int), 2, PHP_ROUND_HALF_UP); } - $output[$numactualloadterm] = array('cap_rest' => $cap_rest, 'cap_rest_str' => price($cap_rest, 0, '', 1, -1, -1, $conf->currency), 'interet' => $int, 'interet_str' => price($int, 0, '', 1, -1, -1, $conf->currency), 'mens' => $mens); + $output[$numactualloadterm] = array( + 'cap_rest' => $cap_rest, + 'cap_rest_str' => price($cap_rest, 0, '', 1, -1, -1, $conf->currency), + 'interet' => $int, + 'interet_str' => price($int, 0, '', 1, -1, -1, $conf->currency), + 'mens' => price($mens), + ); $numactualloadterm++; $capital = $cap_rest; @@ -139,7 +145,7 @@ function loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbt 'cap_rest_str' => price($cap_rest, 0, '', 1, -1, -1, $conf->currency), 'interet' => $int, 'interet_str' => price($int, 0, '', 1, -1, -1, $conf->currency), - 'mens' => $mens, + 'mens' => price($mens), ); $capital = $cap_rest; $numactualloadterm++; diff --git a/htdocs/loan/schedule.php b/htdocs/loan/schedule.php index e48ff1fe773..23e6c561dfd 100644 --- a/htdocs/loan/schedule.php +++ b/htdocs/loan/schedule.php @@ -214,34 +214,45 @@ dol_banner_tab($object, 'loanid', $linkback, 1, 'rowid', 'ref', $morehtmlref, '' ?> nbterm > 0 && count($echeances->lines) == 0) { print ''.dol_print_date(dol_time_plus_duree($object->datestart, $i - 1, 'm'), 'day').''; print ''.price($insu, 0, '', 1, -1, -1, $conf->currency).''; print ''.price($int, 0, '', 1, -1, -1, $conf->currency).''; - print ''; + print ''; print ''.price($cap_rest).''; print ''."\n"; $i++; @@ -327,7 +338,7 @@ if ($object->nbterm > 0 && count($echeances->lines) == 0) { print ''.price($insu, 0, '', 1, -1, -1, $conf->currency).''; print ''.price($int, 0, '', 1, -1, -1, $conf->currency).''; if (empty($line->fk_bank)) { - print ''; + print ''; } else { print ''.price($mens, 0, '', 1, -1, -1, $conf->currency).''; }