36 global $db, $langs,
$conf;
41 $head[$tab][0] = DOL_URL_ROOT.
'/loan/card.php?id='.
$object->id;
42 $head[$tab][1] = $langs->trans(
'Card');
43 $head[$tab][2] =
'card';
46 $head[$tab][0] = DOL_URL_ROOT.
'/loan/schedule.php?loanid='.
$object->id;
47 $head[$tab][1] = $langs->trans(
'FinancialCommitment');
48 $head[$tab][2] =
'FinancialCommitment';
57 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
60 $nbFiles = count(
dol_dir_list($upload_dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$'));
62 $head[$tab][0] = DOL_URL_ROOT.
'/loan/document.php?id='.
$object->id;
63 $head[$tab][1] = $langs->trans(
"Documents");
64 if (($nbFiles + $nbLinks) > 0) {
65 $head[$tab][1] .=
'<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).
'</span>';
67 $head[$tab][2] =
'documents';
71 $nbNote = (empty(
$object->note_private) ? 0 : 1) + (empty(
$object->note_public) ? 0 : 1);
72 $head[$tab][0] = DOL_URL_ROOT.
"/loan/note.php?id=".
$object->id;
73 $head[$tab][1] = $langs->trans(
"Notes");
75 $head[$tab][1] .=
'<span class="badge marginleftonlyshort">'.$nbNote.
'</span>';
77 $head[$tab][2] =
'note';
81 $head[$tab][0] = DOL_URL_ROOT.
'/loan/info.php?id='.
$object->id;
82 $head[$tab][1] = $langs->trans(
"Info");
83 $head[$tab][2] =
'info';
107function loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm, $amort =
null, $source =
'mens', $grace_period = 0, $int =
null)
110 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
118 $numactualloadterm = ((int) $numactualloadterm);
119 $nbterm = ((int) $nbterm);
120 $grace_period = ((int) $grace_period);
121 $amort = ($amort !==
null && $amort !==
'') ? (
float)
price2num($amort) :
null;
122 $int = ($int !==
null && $int !==
'') ? (
float)
price2num($int) :
null;
124 if ($grace_period > 0 && $numactualloadterm <= $grace_period) {
126 $int = ($int !==
null && $int > 0) ? $int : round((
float) $capital * ((
float) $rate / 12), 2, PHP_ROUND_HALF_UP);
128 $cap_rest = $capital;
129 } elseif ($source ===
'amort') {
130 $amort = ($amort !==
null) ? $amort : 0.0;
131 $int = ($int !==
null && $int > 0) ? $int : round((
float) $capital * ((
float) $rate / 12), 2, PHP_ROUND_HALF_UP);
132 $mens = round((
float) $amort + (
float) $int, 2, PHP_ROUND_HALF_UP);
133 $cap_rest = round((
float) $capital - (
float) $amort, 2, PHP_ROUND_HALF_UP);
134 } elseif ($source ===
'interet') {
135 $int = ($int !==
null) ? $int : round((
float) $capital * ((
float) $rate / 12), 2, PHP_ROUND_HALF_UP);
136 $amort = ($amort !==
null) ? $amort : 0.0;
137 $mens = round((
float) $amort + (
float) $int, 2, PHP_ROUND_HALF_UP);
138 $cap_rest = round((
float) $capital - (
float) $amort, 2, PHP_ROUND_HALF_UP);
141 if ($amort !==
null && $amort == 0) {
145 $cap_rest = $capital;
147 $int = ($int !==
null && $int > 0) ? $int : round((
float) $capital * ((
float) $rate / 12), 2, PHP_ROUND_HALF_UP);
148 $amort = round((
float) $mens - (
float) $int, 2, PHP_ROUND_HALF_UP);
152 $cap_rest = $capital;
154 $cap_rest = round((
float) $capital - (
float) $amort, 2, PHP_ROUND_HALF_UP);
159 $output[$numactualloadterm] = array(
160 'cap_rest' => $cap_rest,
161 'cap_rest_str' =>
price($cap_rest, 0,
'', 1, -1, -1,
$conf->currency),
163 'interet_str' =>
price($int, 0,
'', 1, -1, -1,
$conf->currency),
164 'amort' =>
price($amort),
165 'amort_num' => (
float) $amort,
166 'mens' =>
price($mens),
167 'mens_num' => (
float) $mens,
170 $numactualloadterm++;
171 $capital = $cap_rest;
172 while ($numactualloadterm <= $nbterm) {
173 if ($grace_period > 0 && $numactualloadterm <= $grace_period) {
175 $int = ((float) $capital * ((
float) $rate / 12));
176 $int = round($int, 2, PHP_ROUND_HALF_UP);
178 $cap_rest = $capital;
180 $mens = round(
$object->calcMonthlyPayments($capital, (
float) $rate, $nbterm - $numactualloadterm + 1), 2, PHP_ROUND_HALF_UP);
182 $int = ($capital * ((float) $rate / 12));
183 $int = round($int, 2, PHP_ROUND_HALF_UP);
184 $amort = round($mens - $int, 2, PHP_ROUND_HALF_UP);
185 $cap_rest = round($capital - $amort, 2, PHP_ROUND_HALF_UP);
188 if ($numactualloadterm == $nbterm && abs($cap_rest) <= 0.05 && $capital > 0) {
191 $mens = round($amort + $int, 2, PHP_ROUND_HALF_UP);
195 $output[$numactualloadterm] = array(
196 'cap_rest' => $cap_rest,
197 'cap_rest_str' =>
price($cap_rest, 0,
'', 1, -1, -1,
$conf->currency),
199 'interet_str' =>
price($int, 0,
'', 1, -1, -1,
$conf->currency),
200 'amort' =>
price($amort),
201 'amort_num' => (
float) $amort,
202 'mens' =>
price($mens),
203 'mens_num' => (
float) $mens,
205 $capital = $cap_rest;
206 $numactualloadterm++;
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm, $amort=null, $source='mens', $grace_period=0, $int=null)
Calculate remaining loan mensuality and interests.