dolibarr 25.0.0-alpha
loan.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 * Copyright (C) 2015-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
26
27
31class Loan extends CommonObject
32{
36 public $element = 'loan';
37
43 public $table = 'loan';
44
48 public $table_element = 'loan';
49
53 public $picto = 'money-bill-alt';
54
58 public $rowid;
59
63 public $datestart;
64
68 public $dateend;
69
73 public $label;
74
78 public $capital;
79
83 public $nbterm;
84
88 public $rate;
89
93 public $paid;
94
98 public $account_capital;
99
103 public $account_insurance;
104
108 public $account_interest;
109
113 public $accountancy_account_capital;
114
118 public $accountancy_account_insurance;
119
123 public $accountancy_account_interest;
124
128 public $insurance_amount;
129
133 public $fk_bank;
134
138 public $fk_user_creat;
139
143 public $fk_user_modif;
144
148 public $totalpaid;
149
153 const STATUS_UNPAID = 0;
154
158 const STATUS_PAID = 1;
159
163 const STATUS_STARTED = 2;
164
165
171 public function __construct($db)
172 {
173 $this->db = $db;
174 }
175
182 public function fetch($id)
183 {
184 $sql = "SELECT l.rowid, l.entity, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public, l.insurance_amount,";
185 $sql .= " l.paid, l.fk_bank, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
186 $sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
187 $sql .= " WHERE l.rowid = ".((int) $id);
188
189 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
190 $resql = $this->db->query($sql);
191 if ($resql) {
192 if ($this->db->num_rows($resql)) {
193 $obj = $this->db->fetch_object($resql);
194
195 $this->id = $obj->rowid;
196 $this->entity = $obj->entity;
197 $this->ref = $obj->rowid;
198 $this->datestart = $this->db->jdate($obj->datestart);
199 $this->dateend = $this->db->jdate($obj->dateend);
200 $this->label = $obj->label;
201 $this->capital = $obj->capital;
202 $this->nbterm = $obj->nbterm;
203 $this->rate = $obj->rate;
204 $this->note_private = $obj->note_private;
205 $this->note_public = $obj->note_public;
206 $this->insurance_amount = $obj->insurance_amount;
207 $this->paid = $obj->paid;
208 $this->fk_bank = $obj->fk_bank;
209
210 $this->account_capital = $obj->accountancy_account_capital;
211 $this->account_insurance = $obj->accountancy_account_insurance;
212 $this->account_interest = $obj->accountancy_account_interest;
213 $this->fk_project = $obj->fk_project;
214
215 $this->db->free($resql);
216 return 1;
217 } else {
218 $this->db->free($resql);
219 return 0;
220 }
221 } else {
222 $this->error = $this->db->lasterror();
223 return -1;
224 }
225 }
226
227
235 public function create($user, $notrigger = 0)
236 {
237 global $conf, $langs;
238
239 $error = 0;
240
241 $now = dol_now();
242
243 // clean parameters
244 $newcapital = price2num($this->capital, 'MT');
245 if (empty($this->insurance_amount)) {
246 $this->insurance_amount = 0;
247 }
248 $newinsuranceamount = price2num($this->insurance_amount, 'MT');
249 if (isset($this->note_private)) {
250 $this->note_private = trim($this->note_private);
251 }
252 if (isset($this->note_public)) {
253 $this->note_public = trim($this->note_public);
254 }
255 if (isset($this->account_capital)) {
256 $this->account_capital = trim($this->account_capital);
257 }
258 if (isset($this->account_insurance)) {
259 $this->account_insurance = trim($this->account_insurance);
260 }
261 if (isset($this->account_interest)) {
262 $this->account_interest = trim($this->account_interest);
263 }
264 if (isset($this->fk_bank)) {
265 $this->fk_bank = (int) $this->fk_bank;
266 }
267 if (isset($this->fk_user_creat)) {
268 $this->fk_user_creat = (int) $this->fk_user_creat;
269 }
270 if (isset($this->fk_user_modif)) {
271 $this->fk_user_modif = (int) $this->fk_user_modif;
272 }
273 if (isset($this->fk_project)) {
274 $this->fk_project = (int) $this->fk_project;
275 }
276
277 // Check parameters
278 if (!($newcapital > 0) || empty($this->datestart) || empty($this->dateend)) {
279 $this->error = "ErrorBadParameter";
280 return -2;
281 }
282 if (isModEnabled('accounting') && empty($this->account_capital)) {
283 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode"));
284 return -2;
285 }
286 if (isModEnabled('accounting') && empty($this->account_insurance)) {
287 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode"));
288 return -2;
289 }
290 if (isModEnabled('accounting') && empty($this->account_interest)) {
291 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode"));
292 return -2;
293 }
294
295 $this->db->begin();
296
297 $sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
298 $sql .= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
299 $sql .= " datec, fk_projet, fk_user_author, insurance_amount)";
300 $sql .= " VALUES ('".$this->db->escape($this->label)."',";
301 $sql .= " '".$this->db->escape((string) $this->fk_bank)."',";
302 $sql .= " '".price2num($newcapital)."',";
303 $sql .= " '".$this->db->idate($this->datestart)."',";
304 $sql .= " '".$this->db->idate($this->dateend)."',";
305 $sql .= " '".$this->db->escape((string) $this->nbterm)."',";
306 $sql .= " '".$this->db->escape((string) $this->rate)."',";
307 $sql .= " '".$this->db->escape($this->note_private)."',";
308 $sql .= " '".$this->db->escape($this->note_public)."',";
309 $sql .= " '".$this->db->escape($this->account_capital)."',";
310 $sql .= " '".$this->db->escape($this->account_insurance)."',";
311 $sql .= " '".$this->db->escape($this->account_interest)."',";
312 $sql .= " ".((int) $conf->entity).",";
313 $sql .= " '".$this->db->idate($now)."',";
314 $sql .= " ".(empty($this->fk_project) ? 'NULL' : ((int) $this->fk_project)).",";
315 $sql .= " ".((int) $user->id).",";
316 $sql .= " '".price2num($newinsuranceamount)."'";
317 $sql .= ")";
318
319 dol_syslog(get_class($this)."::create", LOG_DEBUG);
320 $resql = $this->db->query($sql);
321 if ($resql) {
322 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."loan");
323
324 if (!$notrigger) {
325 // Call trigger
326 $result = $this->call_trigger('LOAN_CREATE', $user);
327 if ($result < 0) {
328 $error++;
329 }
330 // End call triggers
331 }
332
333 if ($error) {
334 $this->db->rollback();
335 return -1;
336 }
337
338 //dol_syslog("Loans::create this->id=".$this->id);
339 $this->db->commit();
340 return $this->id;
341 } else {
342 $this->error = $this->db->error();
343 $this->db->rollback();
344 return -1;
345 }
346 }
347
348
356 public function delete($user, $notrigger = 0)
357 {
358 $error = 0;
359
360 $this->db->begin();
361
362 // Get bank transaction lines for this loan
363 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
364 $account = new Account($this->db);
365 $lines_url = $account->get_url(0, $this->id, 'loan');
366
367 // Delete bank urls
368 foreach ($lines_url as $line_url) {
369 if (!$error) {
370 $accountline = new AccountLine($this->db);
371 $accountline->fetch($line_url['fk_bank']);
372 $result = $accountline->delete_urls($user);
373 if ($result < 0) {
374 $this->errors = array_merge($this->errors, [$accountline->error], $accountline->errors);
375 $error++;
376 }
377 }
378 }
379
380 // Delete payments
381 if (!$error) {
382 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".((int) $this->id);
383 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
384 $resql = $this->db->query($sql);
385 if (!$resql) {
386 $error++;
387 $this->error = $this->db->lasterror();
388 }
389 }
390
391 if (!$error) {
392 $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".((int) $this->id);
393 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
394 $resql = $this->db->query($sql);
395 if (!$resql) {
396 $error++;
397 $this->error = $this->db->lasterror();
398 }
399 }
400
401 if (!$error && !$notrigger) {
402 // Call trigger
403 $result = $this->call_trigger('LOAN_DELETE', $user);
404 if ($result < 0) {
405 $error++;
406 }
407 // End call triggers
408 }
409
410 if (!$error) {
411 $this->db->commit();
412 return 1;
413 } else {
414 $this->db->rollback();
415 return -1;
416 }
417 }
418
419
427 public function update($user, $notrigger = 0)
428 {
429 $this->db->begin();
430
431 if (!is_numeric($this->nbterm)) {
432 $this->error = 'BadValueForParameterForNbTerm';
433 return -1;
434 }
435
436 $sql = "UPDATE ".MAIN_DB_PREFIX."loan";
437 $sql .= " SET label='".$this->db->escape($this->label)."',";
438 $sql .= " capital='".$this->db->escape(price2num($this->capital))."',";
439 $sql .= " datestart='".$this->db->idate($this->datestart)."',";
440 $sql .= " dateend='".$this->db->idate($this->dateend)."',";
441 $sql .= " nbterm=".((float) $this->nbterm).",";
442 $sql .= " rate=".((float) $this->rate).",";
443 $sql .= " accountancy_account_capital = '".$this->db->escape($this->account_capital)."',";
444 $sql .= " accountancy_account_insurance = '".$this->db->escape($this->account_insurance)."',";
445 $sql .= " accountancy_account_interest = '".$this->db->escape($this->account_interest)."',";
446 $sql .= " fk_projet=".(empty($this->fk_project) ? 'NULL' : ((int) $this->fk_project)).",";
447 $sql .= " fk_user_modif = ".((int) $user->id).",";
448 $sql .= " insurance_amount = '".price2num($this->db->escape((string) $this->insurance_amount))."'";
449 $sql .= " WHERE rowid=".((int) $this->id);
450
451 dol_syslog(get_class($this)."::update", LOG_DEBUG);
452 $resql = $this->db->query($sql);
453 if ($resql) {
454 if (!$notrigger) {
455 // Call trigger
456 $result = $this->call_trigger('LOAN_MODIFY', $user);
457 if ($result < 0) {
458 $this->db->rollback();
459 return -1;
460 }
461 // End call triggers
462 }
463
464 $this->db->commit();
465 return 1;
466 } else {
467 $this->error = $this->db->error();
468 $this->db->rollback();
469 return -1;
470 }
471 }
472
479 public function setPaid($user)
480 {
481 $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
482 $sql .= " paid = ".((int) $this::STATUS_PAID);
483 $sql .= " WHERE rowid = ".((int) $this->id);
484
485 $return = $this->db->query($sql);
486
487 if ($return) {
488 $this->paid = $this::STATUS_PAID;
489 return 1;
490 } else {
491 $this->error = $this->db->lasterror();
492 return -1;
493 }
494 }
495
496 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
505 public function set_started($user)
506 {
507 // phpcs:enable
508 dol_syslog(get_class($this)."::set_started is deprecated, use setStarted instead", LOG_NOTICE);
509 return $this->setStarted($user);
510 }
511
518 public function setStarted($user)
519 {
520 $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
521 $sql .= " paid = ".((int) $this::STATUS_STARTED);
522 $sql .= " WHERE rowid = ".((int) $this->id);
523
524 $return = $this->db->query($sql);
525
526 if ($return) {
527 $this->paid = $this::STATUS_STARTED;
528 return 1;
529 } else {
530 $this->error = $this->db->lasterror();
531 return -1;
532 }
533 }
534
541 public function setUnpaid($user)
542 {
543 $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
544 $sql .= " paid = ".((int) $this::STATUS_UNPAID);
545 $sql .= " WHERE rowid = ".((int) $this->id);
546
547 $return = $this->db->query($sql);
548
549 if ($return) {
550 $this->paid = $this::STATUS_UNPAID;
551 return 1;
552 } else {
553 $this->error = $this->db->lasterror();
554 return -1;
555 }
556 }
557
565 public function getLibStatut($mode = 0, $alreadypaid = -1)
566 {
567 return $this->LibStatut($this->paid, $mode, $alreadypaid);
568 }
569
570 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
579 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
580 {
581 // phpcs:enable
582 global $langs;
583
584 // Load translation files required by the page
585 $langs->loadLangs(array("customers", "bills"));
586
587 unset($this->labelStatus); // Force to reset the array of status label, because label can change depending on parameters
588 // Always true because of 'unset':
589 // if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
590 global $langs;
591 $this->labelStatus = array();
592 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid');
593 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid');
594 $this->labelStatus[self::STATUS_STARTED] = $langs->transnoentitiesnoconv("BillStatusStarted");
595 if ($status == 0 && $alreadypaid > 0) {
596 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
597 }
598 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid');
599 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid');
600 $this->labelStatusShort[self::STATUS_STARTED] = $langs->transnoentitiesnoconv("BillStatusStarted");
601 if ($status == 0 && $alreadypaid > 0) {
602 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
603 }
604 // } // End of empty(labelStatus,labelStatusShort)
605
606 $statusType = 'status1';
607 if (($status == 0 && $alreadypaid > 0) || $status == self::STATUS_STARTED) {
608 $statusType = 'status3';
609 }
610 if ($status == 1) {
611 $statusType = 'status6';
612 }
613
614 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
615 }
616
617
629 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
630 {
631 global $conf, $langs, $hookmanager;
632
633 $result = '';
634
635 $label = '<u>'.$langs->trans("ShowLoan").'</u>';
636 if (!empty($this->ref)) {
637 $label .= '<br><strong>'.$langs->trans('Ref').':</strong> '.$this->ref;
638 }
639 if (!empty($this->label)) {
640 $label .= '<br><strong>'.$langs->trans('Label').':</strong> '.$this->label;
641 }
642 if (isDolTms($this->datestart)) {
643 $label .= '<br><strong>'.$langs->trans("DateStart").':</strong> '.dol_print_date($this->datestart, 'day');
644 }
645 if (isDolTms($this->dateend)) {
646 $label .= '<br><strong>'.$langs->trans("DateEnd").':</strong> '.dol_print_date($this->dateend, 'day');
647 }
648
649 $baseurl = DOL_URL_ROOT.'/loan/card.php';
650 $query = ['id' => $this->id];
651 if ($option != 'nolink') {
652 // Add param to save lastsearch_values or not
653 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
654 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
655 $add_save_lastsearch_values = 1;
656 }
657 if ($add_save_lastsearch_values) {
658 $query += ['save_lastsearch_values' => 1];
659 }
660 }
661 $url = dolBuildUrl($baseurl, $query);
662
663 $linkclose = '';
664 if (empty($notooltip)) {
665 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
666 $label = $langs->trans("ShowLoan");
667 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
668 }
669 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
670 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
671 } else {
672 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
673 }
674
675 $linkstart = '<a href="'.$url.'"';
676 $linkstart .= $linkclose.'>';
677 $linkend = '</a>';
678
679 $result .= $linkstart;
680 if ($withpicto) {
681 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
682 }
683 if ($withpicto != 2) {
684 $result .= ($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref);
685 }
686 $result .= $linkend;
687
688 global $action;
689 $hookmanager->initHooks(array($this->element . 'dao'));
690 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
691 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
692 if ($reshook > 0) {
693 $result = $hookmanager->resPrint;
694 } else {
695 $result .= $hookmanager->resPrint;
696 }
697 return $result;
698 }
699
707 public function initAsSpecimen()
708 {
709 $now = dol_now();
710
711 // Initialise parameters
712 $this->id = 0;
713 $this->fk_bank = 1;
714 $this->label = 'SPECIMEN';
715 $this->specimen = 1;
716 $this->account_capital = '16';
717 $this->account_insurance = '616';
718 $this->account_interest = '518';
719 $this->datestart = $now;
720 $this->dateend = $now + (3600 * 24 * 365);
721 $this->note_public = 'SPECIMEN';
722 $this->capital = 20000.80;
723 $this->nbterm = 48;
724 $this->rate = 4.3;
725
726 return 1;
727 }
728
734 public function getSumPayment()
735 {
736 $sql = "SELECT sum(amount_capital) as amount";
737 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan";
738 $sql .= " WHERE fk_loan = ".((int) $this->id);
739
740 dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG);
741
742 $resql = $this->db->query($sql);
743 if ($resql) {
744 $amount = 0;
745
746 $obj = $this->db->fetch_object($resql);
747 if ($obj) {
748 $amount = $obj->amount ? $obj->amount : 0;
749 }
750
751 $this->db->free($resql);
752 return $amount;
753 } else {
754 $this->error = $this->db->lasterror();
755 return -1;
756 }
757 }
758
765 public function info($id)
766 {
767 $sql = 'SELECT l.rowid, l.datec, l.fk_user_author, l.fk_user_modif,';
768 $sql .= ' l.tms as datem';
769 $sql .= ' WHERE l.rowid = '.((int) $id);
770
771 dol_syslog(get_class($this).'::info', LOG_DEBUG);
772 $result = $this->db->query($sql);
773
774 if ($result) {
775 if ($this->db->num_rows($result)) {
776 $obj = $this->db->fetch_object($result);
777
778 $this->id = $obj->rowid;
779
780 $this->user_creation_id = $obj->fk_user_author;
781 $this->user_modification_id = $obj->fk_user_modif;
782 $this->date_creation = $this->db->jdate($obj->datec);
783 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
784
785 $this->db->free($result);
786 return 1;
787 } else {
788 $this->db->free($result);
789 return 0;
790 }
791 } else {
792 $this->error = $this->db->lasterror();
793 return -1;
794 }
795 }
796
804 public function getKanbanView($option = '', $arraydata = null)
805 {
806 global $langs;
807
808 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
809
810 $return = '<div class="box-flex-item box-flex-grow-zero">';
811 $return .= '<div class="info-box info-box-sm">';
812 $return .= '<span class="info-box-icon bg-infobox-action">';
813 $return .= img_picto('', $this->picto);
814 $return .= '</span>';
815 $return .= '<div class="info-box-content">';
816 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl(1).'</span>';
817 if ($selected >= 0) {
818 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
819 }
820 if (!empty($this->capital)) {
821 $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->capital).'</span>';
822 }
823 if (isDolTms($this->datestart)) {
824 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateStart").'</span> : <span class="info-box-label">'.dol_print_date($this->datestart, 'day').'</span>';
825 }
826 if (isDolTms($this->dateend)) {
827 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label">'.dol_print_date($this->dateend, 'day').'</span>';
828 }
829
830 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, (float) $this->totalpaid).'</div>';
831 $return .= '</div>';
832 $return .= '</div>';
833 $return .= '</div>';
834
835 return $return;
836 }
837}
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage bank transaction lines.
Loan.
fetch($id)
Load object in memory from database.
setUnpaid($user)
Tag loan as payment as unpaid.
initAsSpecimen()
Initialise an instance with random values.
setPaid($user)
Tag loan as paid completely.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
setStarted($user)
Tag loan as payment started.
info($id)
Information on record.
LibStatut($status, $mode=0, $alreadypaid=-1)
Return label for given status.
__construct($db)
Constructor.
getNomUrl($withpicto=0, $maxlen=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable name (with eventually the picto)
getSumPayment()
Return amount of payments already done.
update($user, $notrigger=0)
Update loan.
set_started($user)
Tag loan as payment started.
create($user, $notrigger=0)
Create a loan into database.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of loan status (unpaid, paid)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
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).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.