dolibarr 25.0.0-alpha
loan.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
35{
36 global $db, $langs, $conf;
37
38 $tab = 0;
39 $head = array();
40
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';
44 $tab++;
45
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';
49 $tab++;
50
51 // Show more tabs from modules
52 // Entries must be declared in modules descriptor with line
53 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
54 // $this->tabs = array('entity:-tabname); to remove a tab
55 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'loan', 'add', 'core');
56
57 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
58 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
59 $upload_dir = $conf->loan->dir_output."/".dol_sanitizeFileName($object->ref);
60 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
61 $nbLinks = Link::count($db, $object->element, $object->id);
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>';
66 }
67 $head[$tab][2] = 'documents';
68 $tab++;
69
70 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
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");
74 if ($nbNote > 0) {
75 $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
76 }
77 $head[$tab][2] = 'note';
78 $tab++;
79 }
80
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';
84 $tab++;
85
86 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'loan', 'add', 'external');
87
88 complete_head_from_modules($conf, $langs, $object, $head, $tab, 'loan', 'remove');
89
90 return $head;
91}
92
111function loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm, $amort = null, $source = 'mens', $grace_period = 0, $int = null, $frequency = 12, $interest_basis = 0, $datestart = 0, $balloon = 0)
112{
113 global $conf, $db;
114 require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
115 $object = new LoanSchedule($db);
116 $output = array();
117
118 // Sanitize data in case of
119 $mens = (float) price2num($mens);
120 $capital = (float) price2num($capital);
121 $rate = (float) price2num($rate);
122 $numactualloadterm = ((int) $numactualloadterm);
123 $nbterm = ((int) $nbterm);
124 $grace_period = ((int) $grace_period);
125 $amort = ($amort !== null && $amort !== '') ? (float) price2num($amort) : null;
126 $int = ($int !== null && $int !== '') ? (float) price2num($int) : null;
127 $frequency = ((int) $frequency > 0 ? (int) $frequency : 12);
128 $interest_basis = (int) $interest_basis;
129 $datestart = (int) $datestart;
130 // Rate of the period that ends with a given term (rate / 12 for a monthly loan with interest per period)
131 $periodrate = function (int $term) use ($rate, $frequency, $interest_basis, $datestart): float {
132 return loanPeriodRate((float) $rate, $frequency, $interest_basis, ($interest_basis && $datestart ? loanPeriodDays($datestart, $term, $frequency) : 0));
133 };
134
135 if ($grace_period > 0 && $numactualloadterm <= $grace_period) {
136 $amort = 0.0;
137 $int = ($int !== null && $int > 0) ? $int : round((float) $capital * $periodrate($numactualloadterm), 2, PHP_ROUND_HALF_UP);
138 $mens = $int;
139 $cap_rest = $capital;
140 } elseif ($source === 'amort') {
141 $amort = ($amort !== null) ? $amort : 0.0;
142 $int = ($int !== null && $int > 0) ? $int : round((float) $capital * $periodrate($numactualloadterm), 2, PHP_ROUND_HALF_UP);
143 $mens = round((float) $amort + (float) $int, 2, PHP_ROUND_HALF_UP);
144 $cap_rest = round((float) $capital - (float) $amort, 2, PHP_ROUND_HALF_UP);
145 } elseif ($source === 'interet') {
146 $int = ($int !== null) ? $int : round((float) $capital * $periodrate($numactualloadterm), 2, PHP_ROUND_HALF_UP);
147 $amort = ($amort !== null) ? $amort : 0.0;
148 $mens = round((float) $amort + (float) $int, 2, PHP_ROUND_HALF_UP);
149 $cap_rest = round((float) $capital - (float) $amort, 2, PHP_ROUND_HALF_UP);
150 } else {
151 // source === 'mens'
152 if ($amort !== null && $amort == 0) {
153 // Zero capital amortization: payment is interest/fees and capital stays intact
154 $amort = 0.0;
155 $int = $mens;
156 $cap_rest = $capital;
157 } else {
158 $int = ($int !== null && $int > 0) ? $int : round((float) $capital * $periodrate($numactualloadterm), 2, PHP_ROUND_HALF_UP);
159 $amort = round((float) $mens - (float) $int, 2, PHP_ROUND_HALF_UP);
160 if ($amort < 0) {
161 $amort = 0.0;
162 $int = $mens;
163 $cap_rest = $capital;
164 } else {
165 $cap_rest = round((float) $capital - (float) $amort, 2, PHP_ROUND_HALF_UP);
166 }
167 }
168 }
169
170 $output[$numactualloadterm] = array(
171 'cap_rest' => $cap_rest,
172 'cap_rest_str' => price($cap_rest, 0, '', 1, -1, -1, $conf->currency),
173 'interet' => $int,
174 'interet_str' => price($int, 0, '', 1, -1, -1, $conf->currency),
175 'amort' => price($amort),
176 'amort_num' => (float) $amort,
177 'mens' => price($mens),
178 'mens_num' => (float) $mens,
179 );
180
181 $numactualloadterm++;
182 $capital = $cap_rest;
183 while ($numactualloadterm <= $nbterm) {
184 if ($grace_period > 0 && $numactualloadterm <= $grace_period) {
185 $amort = 0.0;
186 $int = ((float) $capital * $periodrate($numactualloadterm));
187 $int = round($int, 2, PHP_ROUND_HALF_UP);
188 $mens = $int;
189 $cap_rest = $capital;
190 } else {
191 $mens = round($object->calcMonthlyPayments($capital, (float) $rate, $nbterm - $numactualloadterm + 1, $frequency, $interest_basis, (float) $balloon), 2, PHP_ROUND_HALF_UP);
192
193 $int = ($capital * $periodrate($numactualloadterm));
194 $int = round($int, 2, PHP_ROUND_HALF_UP);
195 $amort = round($mens - $int, 2, PHP_ROUND_HALF_UP);
196 $cap_rest = round($capital - $amort, 2, PHP_ROUND_HALF_UP);
197
198 // Adjust rounding difference on the last installment if small remainder (with daily interest,
199 // periods are not all the same length, so the last installment always settles what is left)
200 // A balloon is paid with the last installment, which then repays all the capital left.
201 if ($numactualloadterm == $nbterm && ($interest_basis || (float) $balloon > 0 || abs($cap_rest) <= 0.05) && $capital > 0) {
202 $amort = $capital;
203 $cap_rest = 0.0;
204 $mens = round($amort + $int, 2, PHP_ROUND_HALF_UP);
205 }
206 }
207
208 $output[$numactualloadterm] = array(
209 'cap_rest' => $cap_rest,
210 'cap_rest_str' => price($cap_rest, 0, '', 1, -1, -1, $conf->currency),
211 'interet' => $int,
212 'interet_str' => price($int, 0, '', 1, -1, -1, $conf->currency),
213 'amort' => price($amort),
214 'amort_num' => (float) $amort,
215 'mens' => price($mens),
216 'mens_num' => (float) $mens,
217 );
218 $capital = $cap_rest;
219 $numactualloadterm++;
220 }
221
222 return $output;
223}
224
225
232{
233 return array(
234 52 => 'LoanFrequencyWeekly',
235 26 => 'LoanFrequencyFortnightly',
236 12 => 'LoanFrequencyMonthly',
237 4 => 'LoanFrequencyQuarterly',
238 2 => 'LoanFrequencyHalfYearly',
239 1 => 'LoanFrequencyYearly',
240 );
241}
242
251function loanTermDate($datestart, $index, $frequency = 12)
252{
253 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
254
255 $frequency = (int) $frequency;
256 if ($frequency == 52) {
257 return dol_time_plus_duree($datestart, 7 * $index, 'd');
258 }
259 if ($frequency == 26) {
260 return dol_time_plus_duree($datestart, 14 * $index, 'd');
261 }
262 $months = (($frequency == 4 || $frequency == 2 || $frequency == 1) ? (int) (12 / $frequency) : 1) * $index;
263 $date = dol_time_plus_duree($datestart, $months, 'm');
264 // A start on the 29th to 31st must not run into the next month (31 January + 1 month = 28 February)
265 $day = (int) dol_print_date($datestart, '%d');
266 if ((int) dol_print_date($date, '%d') != $day) {
267 $date = dol_time_plus_duree($date, -(int) dol_print_date($date, '%d'), 'd');
268 }
269 return $date;
270}
271
280function loanPeriodDays($datestart, $term, $frequency = 12)
281{
282 return (int) round((loanTermDate($datestart, $term - 1, $frequency) - loanTermDate($datestart, $term - 2, $frequency)) / 86400);
283}
284
294function loanPeriodRate($rate, $frequency = 12, $interest_basis = 0, $days = 0)
295{
296 $frequency = ((int) $frequency > 0 ? (int) $frequency : 12);
297 if ($interest_basis) {
298 if ($days <= 0) {
299 $days = ($frequency == 52 ? 7 : ($frequency == 26 ? 14 : 365 / $frequency));
300 }
301 return $rate * $days / 365;
302 }
303 return $rate / $frequency;
304}
305
306
313{
314 return array(
315 0 => 'Insurance',
316 1 => 'LoanChargeAccountFee',
317 2 => 'LoanChargeOtherFee',
318 );
319}
320
328function loanChargeLabel($charge_type, $outputlangs)
329{
330 $types = loanChargeTypes();
331 return $outputlangs->trans($types[(int) $charge_type] ?? $types[0]);
332}
333
342function loanChargePerPayment($amount, $per_payment, $nbterm)
343{
344 if ($per_payment) {
345 return array((float) price2num($amount, 'MT'), 0.0);
346 }
347 if ((float) $nbterm <= 0) {
348 return array(0.0, 0.0);
349 }
350 $each = (float) price2num((float) $amount / $nbterm, 'MT');
351 return array($each, (float) price2num((float) $amount - ($each * $nbterm)));
352}
353
370function loanRecalculateSchedule($db, $user, $loan, $lines, $from, $capital, $rate, $keep, $payment = 0.0)
371{
372 $from = (int) $from;
373 require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
374
375 $lines = array_values($lines);
376 $total = count($lines);
377 $res = array('error' => '', 'payment_old' => 0.0, 'payment_new' => 0.0, 'nbterm_old' => $total, 'nbterm_new' => $total);
378 if ($from < 0 || $from >= $total) {
379 $res['error'] = 'LoanRecalcNothingToRecalculate';
380 return $res;
381 }
382 for ($i = $from; $i < $total; $i++) {
383 if (!empty($lines[$i]->fk_bank)) {
384 $res['error'] = 'LoanRecalcLaterPaymentPaid';
385 return $res;
386 }
387 }
388
389 $frequency = ((int) $loan->frequency > 0 ? (int) $loan->frequency : 12);
390 $interest_basis = (int) $loan->interest_basis;
391 $balloon = (float) $loan->balloon_amount;
392 $datestart = (int) $loan->datestart;
393 $lastdate = (int) $lines[$total - 1]->datep;
394 // Annual rate of a payment: the given one, or the one in force on the date of the payment
395 $history = ($rate === null ? loanFetchChanges($db, $loan->id) : array());
396 $rateof = function (int $index) use ($rate, $history, $loan, $lines, $total, $lastdate, $frequency): float {
397 if ($rate !== null) {
398 return (float) $rate;
399 }
400 $date = ($index < $total ? (int) $lines[$index]->datep : loanTermDate($lastdate, $index - ($total - 1), $frequency));
401 return loanRateAt($history, (float) $loan->rate, $date);
402 };
403 // Rate of the period that ends with the payment of a given index (0 = first payment of the loan)
404 $periodrate = function (int $index) use ($rateof, $frequency, $interest_basis, $datestart): float {
405 return loanPeriodRate($rateof($index), $frequency, $interest_basis, ($interest_basis ? loanPeriodDays($datestart, $index + 1, $frequency) : 0)) / 100;
406 };
407
408 $res['payment_old'] = (float) price2num((float) $lines[$from]->amount_capital + (float) $lines[$from]->amount_interest, 'MT');
409 $calc = new LoanSchedule($db);
410 $new = array(); // index of the line => array(capital, interest)
411 $cap = (float) $capital;
412
413 if ($keep === 'payment') {
414 // Repayment of each payment: the given one, else its current one; payments added after the last one get the
415 // last regular repayment (the last payment itself is only what was left, or includes the balloon)
416 $regular = (float) price2num((float) $lines[max(0, $total - 2)]->amount_capital + (float) $lines[max(0, $total - 2)]->amount_interest, 'MT');
417 $i = $from;
418 while ($cap > 0.005) {
419 if ($payment > 0) {
420 $pmt = (float) price2num($payment, 'MT');
421 } elseif ($i < $total - 1) {
422 $pmt = (float) price2num((float) $lines[$i]->amount_capital + (float) $lines[$i]->amount_interest, 'MT');
423 } else {
424 $pmt = $regular;
425 }
426 if ($i == $from) {
427 $res['payment_new'] = $pmt;
428 }
429 if ($i - $from >= 1200) {
430 $res['error'] = 'LoanRecalcPaymentTooSmall';
431 return $res;
432 }
433 $int = (float) price2num($cap * $periodrate($i), 'MT');
434 if ($pmt - $int <= 0) {
435 $res['error'] = 'LoanRecalcPaymentTooSmall';
436 return $res;
437 }
438 $amort = (float) price2num($pmt - $int, 'MT');
439 if ($cap - $amort <= $balloon + 0.005) {
440 $amort = $cap; // last payment: all that is left (with the balloon if any)
441 }
442 $new[$i] = array($amort, $int);
443 $cap = (float) price2num($cap - $amort, 'MT');
444 $i++;
445 }
446 } else {
447 $n = $total - $from;
448 for ($k = 0; $k < $n; $k++) {
449 $i = $from + $k;
450 $mens = (float) price2num($calc->calcMonthlyPayments($cap, $rateof($i) / 100, $n - $k, $frequency, $interest_basis, $balloon), 'MT');
451 $int = (float) price2num($cap * $periodrate($i), 'MT');
452 $amort = (float) price2num($mens - $int, 'MT');
453 if ($k == $n - 1) {
454 $amort = $cap; // last payment: all that is left (with the balloon if any)
455 }
456 $new[$i] = array($amort, $int);
457 $cap = (float) price2num($cap - $amort, 'MT');
458 if ($k == 0) {
459 $res['payment_new'] = $mens;
460 }
461 }
462 }
463
464 // Write the lines: update existing ones, add the missing ones, delete the ones no longer needed
465 list($charge, $chargeregul) = loanChargePerPayment($loan->insurance_amount, $loan->charge_per_payment, $loan->nbterm);
466 $enddate = $lastdate;
467 foreach ($new as $i => $amounts) {
468 if ($i < $total) {
469 $line = $lines[$i];
470 } else {
471 $line = new LoanSchedule($db);
472 $line->fk_loan = $loan->id;
473 $line->datec = dol_now();
474 $line->datep = loanTermDate($lastdate, $i - ($total - 1), $frequency);
475 $line->amount_insurance = $charge;
476 $line->fk_typepayment = (int) $lines[$total - 1]->fk_typepayment;
477 $line->fk_bank = 0;
478 $line->fk_user_creat = $user->id;
479 }
480 $line->amount_capital = $amounts[0];
481 $line->amount_interest = $amounts[1];
482 $line->tms = dol_now();
483 $line->fk_user_modif = $user->id;
484 $result = ($i < $total ? $line->update($user, 0) : $line->create($user));
485 if ($result < 0) {
486 $res['error'] = ($line->error ? $line->error : 'Error');
487 return $res;
488 }
489 $enddate = (int) $line->datep;
490 }
491 $nbnew = $from + count($new);
492 for ($i = $nbnew; $i < $total; $i++) {
493 if ($lines[$i]->delete($user) < 0) {
494 $res['error'] = ($lines[$i]->error ? $lines[$i]->error : 'Error');
495 return $res;
496 }
497 }
498
499 if ($rate !== null) {
500 $loan->rate = (float) $rate;
501 }
502 $loan->nbterm = $nbnew;
503 $loan->dateend = $enddate;
504 if ($loan->update($user) < 0) {
505 $res['error'] = ($loan->error ? $loan->error : 'Error');
506 return $res;
507 }
508 $res['nbterm_new'] = $nbnew;
509
510 return $res;
511}
512
531function loanRecordChange($db, $user, $loanid, $reason, $datechange, $rate_old, $rate_new, $keep, $payment_old, $payment_new, $nbterm_old, $nbterm_new, $fk_payment = 0)
532{
533 global $conf;
534
535 $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan_change (entity, fk_loan, datec, date_change, reason, rate_old, rate_new, keep_mode, payment_old, payment_new, nbterm_old, nbterm_new, fk_payment_loan, fk_user_author)";
536 $sql .= " VALUES (".((int) $conf->entity).", ".((int) $loanid).", '".$db->idate(dol_now())."', '".$db->idate($datechange)."',";
537 $sql .= " '".$db->escape($reason)."', ".((float) $rate_old).", ".((float) $rate_new).", '".$db->escape($keep)."',";
538 $sql .= " ".((float) price2num($payment_old, 'MT')).", ".((float) price2num($payment_new, 'MT')).", ".((float) $nbterm_old).", ".((float) $nbterm_new).",";
539 $sql .= " ".($fk_payment > 0 ? ((int) $fk_payment) : "NULL").", ".((int) $user->id).")";
540 if (!$db->query($sql)) {
541 return -1;
542 }
543 return $db->last_insert_id(MAIN_DB_PREFIX."loan_change");
544}
545
553function loanFetchChanges($db, $loanid)
554{
555 $out = array();
556 $sql = "SELECT rowid, datec, date_change, reason, rate_old, rate_new, keep_mode, payment_old, payment_new, nbterm_old, nbterm_new, fk_payment_loan, fk_user_author";
557 $sql .= " FROM ".MAIN_DB_PREFIX."loan_change WHERE fk_loan = ".((int) $loanid)." ORDER BY datec DESC, rowid DESC";
558 $resql = $db->query($sql);
559 while ($resql && ($obj = $db->fetch_object($resql))) {
560 $obj->datec = $db->jdate($obj->datec);
561 $obj->date_change = $db->jdate($obj->date_change);
562 $out[] = $obj;
563 }
564 return $out;
565}
566
577function loanRateAt($history, $current, $date)
578{
579 $found = null;
580 $first = null;
581 foreach ($history as $c) { // most recent first
582 if ($c->reason != 'rate') {
583 continue;
584 }
585 $first = $c;
586 if ($found === null && (int) $c->date_change <= (int) $date) {
587 $found = $c;
588 }
589 }
590 if ($found !== null) {
591 return (float) $found->rate_new;
592 }
593 return ($first !== null ? (float) $first->rate_old : (float) $current);
594}
595
606function loanNextPayment($db, $loan)
607{
608 require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
609
610 $frequency = ((int) $loan->frequency > 0 ? (int) $loan->frequency : 12);
611 $datestart = (int) $loan->datestart;
612 $nbterm = (int) $loan->nbterm;
613
614 // Payments already made
615 $paidcapital = 0.0;
616 $lastdate = 0;
617 $sql = "SELECT amount_capital, datep FROM ".MAIN_DB_PREFIX."payment_loan WHERE fk_loan = ".((int) $loan->id);
618 $resql = $db->query($sql);
619 while ($resql && ($obj = $db->fetch_object($resql))) {
620 $paidcapital += (float) $obj->amount_capital;
621 $lastdate = max($lastdate, (int) $db->jdate($obj->datep));
622 }
623 $capital = (float) price2num((float) $loan->capital - $paidcapital, 'MT');
624 if ($capital <= 0 || empty($datestart) || $nbterm <= 0) {
625 return null;
626 }
627
628 // First payment date after the last payment (index 0 = first payment of the loan)
629 $index = 0;
630 if ($lastdate) {
631 while ($index < $nbterm - 1 && loanTermDate($datestart, $index, $frequency) <= $lastdate) {
632 $index++;
633 }
634 }
635 $date = loanTermDate($datestart, $index, $frequency);
636
637 $rate = loanRateAt(loanFetchChanges($db, $loan->id), (float) $loan->rate, $date);
638 $days = ((int) $loan->interest_basis ? loanPeriodDays($datestart, $index + 1, $frequency) : 0);
639 $interest = (float) price2num($capital * loanPeriodRate($rate, $frequency, (int) $loan->interest_basis, $days) / 100, 'MT');
640
641 $left = $nbterm - $index;
642 if ($left <= 1) {
643 $amort = $capital; // last payment: all that is left (with the balloon if any)
644 } else {
645 $calc = new LoanSchedule($db);
646 $mens = (float) price2num($calc->calcMonthlyPayments($capital, $rate / 100, $left, $frequency, (int) $loan->interest_basis, (float) $loan->balloon_amount), 'MT');
647 $amort = (float) price2num($mens - $interest, 'MT');
648 }
649
650 list($charge, $chargeregul) = loanChargePerPayment($loan->insurance_amount, $loan->charge_per_payment, $nbterm);
651 if ($index == 0) {
652 $charge = (float) price2num($charge + $chargeregul, 'MT');
653 }
654
655 return array('date' => $date, 'term' => $index + 1, 'capital' => $amort, 'interest' => $interest, 'charge' => $charge);
656}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$c
Definition line.php:353
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage Schedule of loans.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
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.
Definition files.lib.php:66
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
loanFetchChanges($db, $loanid)
History of the changes of a loan, most recent first.
Definition loan.lib.php:553
loanNextPayment($db, $loan)
Next payment of a loan that has no schedule, worked out from the loan and the payments already made: ...
Definition loan.lib.php:606
loan_prepare_head($object)
Prepare array with list of tabs.
Definition loan.lib.php:34
loanChargeLabel($charge_type, $outputlangs)
Label of the charge of a loan (Insurance, Account-keeping fee, Other fee).
Definition loan.lib.php:328
loanChargePerPayment($amount, $per_payment, $nbterm)
Charge of each payment of a loan.
Definition loan.lib.php:342
loanRecordChange($db, $user, $loanid, $reason, $datechange, $rate_old, $rate_new, $keep, $payment_old, $payment_new, $nbterm_old, $nbterm_new, $fk_payment=0)
Record a change of a loan (rate change, or a payment that differs from the schedule) in its history.
Definition loan.lib.php:531
loanRecalculateSchedule($db, $user, $loan, $lines, $from, $capital, $rate, $keep, $payment=0.0)
Recalculate the unpaid payments of a loan schedule, from one payment to the end, after a rate change ...
Definition loan.lib.php:370
loanPeriodRate($rate, $frequency=12, $interest_basis=0, $days=0)
Interest rate of one period of a loan.
Definition loan.lib.php:294
loanFrequencies()
Payment frequencies of a loan.
Definition loan.lib.php:231
loanTermDate($datestart, $index, $frequency=12)
Date of a payment of a loan.
Definition loan.lib.php:251
loanChargeTypes()
Kinds of charge the "insurance" amount of a loan can be.
Definition loan.lib.php:312
loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm, $amort=null, $source='mens', $grace_period=0, $int=null, $frequency=12, $interest_basis=0, $datestart=0, $balloon=0)
Calculate remaining loan mensuality and interests.
Definition loan.lib.php:111
loanPeriodDays($datestart, $term, $frequency=12)
Number of days of the period that ends with a payment (used by the daily interest basis).
Definition loan.lib.php:280
loanRateAt($history, $current, $date)
Annual rate of a loan in force on a date, from the history of its rate changes: the rate of the most ...
Definition loan.lib.php:577