dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2015-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
43
44if (isModEnabled('accounting')) {
45 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
47}
48
49if (isModEnabled('project')) {
50 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51}
52
53// Load translation files required by the page
54$langs->loadLangs(array("banks", "bills", "compta", "loan"));
55
56$id = GETPOSTINT('id');
57$action = GETPOST('action', 'aZ09');
58$confirm = GETPOST('confirm');
59$cancel = GETPOST('cancel', 'alpha');
60
61$projectid = GETPOSTINT('projectid');
62
63// Security check
64/*
65$socid = GETPOSTINT('socid');
66if ($user->socid) {
67 $socid = $user->socid;
68} */
69$hookmanager->initHooks(array('loancard', 'globalcard'));
70$result = restrictedArea($user, 'loan', $id, '', '');
71
72$object = new Loan($db);
73
74$permissiontoadd = $user->hasRight('loan', 'write');
75
76$error = 0;
77$staytopay = 0;
78
79
80/*
81 * Actions
82 */
83
84$parameters = array();
85$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
86if ($reshook < 0) {
87 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88}
89if (empty($reshook)) {
90 // Classify paid
91 if ($action == 'confirm_paid' && $confirm == 'yes' && $permissiontoadd) {
92 $object->fetch($id);
93 $result = $object->setPaid($user);
94 if ($result > 0) {
95 setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
96 } else {
97 setEventMessages($object->error, $object->errors, 'errors');
98 }
99 }
100
101 // Delete loan
102 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontoadd) {
103 $object->fetch($id);
104 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
105 $result = $object->delete($user);
106 if ($result > 0) {
107 setEventMessages($langs->trans('LoanDeleted'), null, 'mesgs');
108 header("Location: list.php");
109 exit;
110 } else {
111 setEventMessages($object->error, $object->errors, 'errors');
112 }
113 }
114
115 // Add loan
116 if ($action == 'add' && $permissiontoadd) {
117 if (!$cancel) {
118 $datestart = dol_mktime(12, 0, 0, GETPOSTINT('startmonth'), GETPOSTINT('startday'), GETPOSTINT('startyear'));
119 $dateend = dol_mktime(12, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear'));
120
121 $capital = GETPOSTFLOAT('capital');
122 $rate = GETPOSTFLOAT('rate');
123
124 if (!$capital) {
125 $error++;
126 $action = 'create';
127 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
128 }
129 if (!$datestart) {
130 $error++;
131 $action = 'create';
132 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateStart")), null, 'errors');
133 }
134 if (!$dateend) {
135 $error++;
136 $action = 'create';
137 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateEnd")), null, 'errors');
138 }
139 if ($rate == '') {
140 $error++;
141 $action = 'create';
142 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rate")), null, 'errors');
143 }
144
145 if (!$error) {
146 $object->label = GETPOST('label');
147 $object->fk_bank = GETPOSTINT('accountid');
148 $object->capital = $capital;
149 $object->datestart = $datestart;
150 $object->dateend = $dateend;
151 $object->nbterm = (float) price2num(GETPOST('nbterm'));
152 $object->rate = $rate;
153 $object->frequency = (GETPOSTINT('frequency') > 0 ? GETPOSTINT('frequency') : 12);
154 $object->interest_basis = GETPOSTINT('interest_basis') ? 1 : 0;
155 $object->balloon_amount = GETPOSTFLOAT('balloon_amount');
156 $object->note_private = GETPOST('note_private', 'restricthtml');
157 $object->note_public = GETPOST('note_public', 'restricthtml');
158 $object->fk_project = GETPOSTINT('projectid');
159 $object->insurance_amount = GETPOSTFLOAT('insurance_amount');
160
161 $accountancy_account_capital = GETPOST('accountancy_account_capital');
162 $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
163 $accountancy_account_interest = GETPOST('accountancy_account_interest');
164
165 if ($accountancy_account_capital <= 0) {
166 $object->account_capital = '';
167 } else {
168 $object->account_capital = $accountancy_account_capital;
169 }
170 if ($accountancy_account_insurance <= 0) {
171 $object->account_insurance = '';
172 } else {
173 $object->account_insurance = $accountancy_account_insurance;
174 }
175 if ($accountancy_account_interest <= 0) {
176 $object->account_interest = '';
177 } else {
178 $object->account_interest = $accountancy_account_interest;
179 }
180
181 $id = $object->create($user);
182 if ($id <= 0) {
183 $error++;
184 setEventMessages($object->error, $object->errors, 'errors');
185 $action = 'create';
186 }
187 }
188 } else {
189 header("Location: list.php");
190 exit();
191 }
192 } elseif ($action == 'update' && $permissiontoadd) {
193 // Update record
194 if (!$cancel) {
195 $result = $object->fetch($id);
196
197 $datestart = dol_mktime(12, 0, 0, GETPOSTINT('startmonth'), GETPOSTINT('startday'), GETPOSTINT('startyear'));
198 $dateend = dol_mktime(12, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear'));
199
200 $capital = GETPOSTFLOAT('capital');
201
202 if (!$capital) {
203 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
204 $action = 'edit';
205 } else {
206 $object->datestart = $datestart;
207 $object->dateend = $dateend;
208 $object->capital = $capital;
209
210 $object->nbterm = GETPOSTINT("nbterm");
211 $object->rate = GETPOSTFLOAT("rate");
212 $object->frequency = (GETPOSTINT('frequency') > 0 ? GETPOSTINT('frequency') : 12);
213 $object->interest_basis = GETPOSTINT('interest_basis') ? 1 : 0;
214 $object->balloon_amount = GETPOSTFLOAT('balloon_amount');
215 $object->insurance_amount = GETPOSTFLOAT('insurance_amount');
216 $object->charge_type = GETPOSTINT('charge_type');
217 $object->charge_per_payment = GETPOSTINT('charge_per_payment') ? 1 : 0;
218
219 $accountancy_account_capital = GETPOST('accountancy_account_capital');
220 $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
221 $accountancy_account_interest = GETPOST('accountancy_account_interest');
222
223 if ($accountancy_account_capital <= 0) {
224 $object->account_capital = '';
225 } else {
226 $object->account_capital = $accountancy_account_capital;
227 }
228 if ($accountancy_account_insurance <= 0) {
229 $object->account_insurance = '';
230 } else {
231 $object->account_insurance = $accountancy_account_insurance;
232 }
233 if ($accountancy_account_interest <= 0) {
234 $object->account_interest = '';
235 } else {
236 $object->account_interest = $accountancy_account_interest;
237 }
238 }
239
240 $result = $object->update($user);
241
242 if ($result > 0) {
243 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
244 exit;
245 } else {
246 $error++;
247 setEventMessages($object->error, $object->errors, 'errors');
248 }
249 } else {
250 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
251 exit;
252 }
253 }
254
255 // Link to a project
256 if ($action == 'classin' && $permissiontoadd) {
257 $object->fetch($id);
258 $result = $object->setProject($projectid);
259 if ($result < 0) {
260 setEventMessages($object->error, $object->errors, 'errors');
261 }
262 }
263
264 if ($action == 'setlabel' && $permissiontoadd) {
265 $object->fetch($id);
266 $result = $object->setValueFrom('label', GETPOST('label'), '', null, 'text', '', $user, 'LOAN_MODIFY');
267 if ($result < 0) {
268 setEventMessages($object->error, $object->errors, 'errors');
269 }
270 }
271
272 // Actions to build doc
273 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
274}
275
276
277/*
278 * View
279 */
280
281$form = new Form($db);
282$formproject = new FormProjets($db);
283$morehtmlstatus = '';
284$outputlangs = $langs;
285$formaccounting = null;
286if (isModEnabled('accounting')) {
287 $formaccounting = new FormAccounting($db);
288}
289$title = $langs->trans("Loan").' - '.$langs->trans("Card");
290$help_url = 'EN:Module_Loan|FR:Module_Emprunt';
291
292llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-loan page-card');
293
294
295// Create mode
296if ($action == 'create') {
297 //WYSIWYG Editor
298 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
299
300 print load_fiche_titre($langs->trans("NewLoan"), '', 'money-bill-alt');
301
302 print '<form name="loan" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
303 print '<input type="hidden" name="token" value="'.newToken().'">';
304 print '<input type="hidden" name="action" value="add">';
305
306 print dol_get_fiche_head();
307
308 print '<table class="border centpercent">';
309
310 // Label
311 print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'" autofocus="autofocus"></td></tr>';
312
313 // Bank account
314 if (isModEnabled("bank")) {
315 print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
316 $form->select_comptes(GETPOST("accountid"), "accountid", 0, "(courant:=:1)", 1); // Show list of bank account with courant
317 print '</td></tr>';
318 } else {
319 print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
320 print $langs->trans("NoBankAccountDefined");
321 print '</td></tr>';
322 }
323
324 // Capital
325 print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="'.dol_escape_htmltag(GETPOST("capital")).'"></td></tr>';
326
327 // Date Start
328 print "<tr>";
329 print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
330 print $form->selectDate(!empty($datestart) ? $datestart : -1, 'start', 0, 0, 0, 'add', 1, 1);
331 print '</td></tr>';
332
333 // Date End
334 print "<tr>";
335 print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
336 print $form->selectDate(!empty($dateend) ? $dateend : -1, 'end', 0, 0, 0, 'add', 1, 1);
337 print '</td></tr>';
338
339 // Number of terms
340 print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="'.dol_escape_htmltag(GETPOST('nbterm')).'"></td></tr>';
341
342 // Rate
343 print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="'.dol_escape_htmltag(GETPOST("rate")).'"> %</td></tr>';
344
345 // Payment frequency and interest basis
346 $frequencies = array();
347 foreach (loanFrequencies() as $key => $label) {
348 $frequencies[$key] = $langs->trans($label);
349 }
350 print '<tr><td>'.$langs->trans("LoanFrequency").'</td><td>'.$form->selectarray('frequency', $frequencies, (GETPOSTINT('frequency') > 0 ? GETPOSTINT('frequency') : 12)).'</td></tr>';
351 print '<tr><td>'.$form->textwithpicto($langs->trans("LoanInterestBasis"), $langs->trans("LoanInterestBasisHelp")).'</td><td>'.$form->selectarray('interest_basis', array(0 => $langs->trans('LoanInterestBasisPeriod'), 1 => $langs->trans('LoanInterestBasisDaily')), GETPOSTINT('interest_basis')).'</td></tr>';
352
353 // Balloon / residual
354 print '<tr><td>'.$form->textwithpicto($langs->trans("LoanBalloon"), $langs->trans("LoanBalloonHelp")).'</td><td><input name="balloon_amount" size="10" value="'.dol_escape_htmltag(GETPOST("balloon_amount")).'" placeholder="'.$langs->trans('Amount').'"></td></tr>';
355
356 // Insurance amount
357 $chargetypes = array();
358 foreach (loanChargeTypes() as $key => $label) {
359 $chargetypes[$key] = $langs->trans($label);
360 }
361 print '<tr><td>'.$form->textwithpicto($langs->trans("LoanCharge"), $langs->trans("LoanChargeHelp")).'</td><td>';
362 print $form->selectarray('charge_type', $chargetypes, GETPOSTINT('charge_type')).' ';
363 print '<input name="insurance_amount" size="10" value="'.dol_escape_htmltag(GETPOST("insurance_amount")).'" placeholder="'.$langs->trans('Amount').'"> ';
364 print $form->selectarray('charge_per_payment', array(0 => $langs->trans('LoanChargeTotal'), 1 => $langs->trans('LoanChargePerPayment')), GETPOSTINT('charge_per_payment'));
365 print '</td></tr>';
366
367 // Project
368 if (isModEnabled('project')) {
369 $formproject = new FormProjets($db);
370
371 // Linked Project
372 $langs->loadLangs(array("projects"));
373
374 print '<tr><td>'.$langs->trans("Project").'</td><td>';
375
376 $formproject->select_projects(-1, (string) $projectid, 'projectid', 16, 0, 1, 1);
377
378 print '</td></tr>';
379 }
380
381 // Note Private
382 print '<tr>';
383 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
384 print '<td>';
385
386 $doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_6, '90%');
387 print $doleditor->Create(1);
388
389 print '</td></tr>';
390
391 // Note Public
392 print '<tr>';
393 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
394 print '<td>';
395 $doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), '', 160, 'dolibarr_notes', 'In', false, true, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_6, '90%');
396 print $doleditor->Create(1);
397 print '</td></tr>';
398
399 // Accountancy
400 if (isModEnabled('accounting') && $formaccounting !== null) {
402 // Accountancy_account_capital
403 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
404 print '<td>';
405 print $formaccounting->select_account(GETPOST('accountancy_account_capital') ? GETPOST('accountancy_account_capital') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_CAPITAL'), 'accountancy_account_capital', 1, array(), 1, 1);
406 print '</td></tr>';
407
408 // Accountancy_account_insurance
409 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
410 print '<td>';
411 print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ? GETPOST('accountancy_account_insurance') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INSURANCE'), 'accountancy_account_insurance', 1, array(), 1, 1);
412 print '</td></tr>';
413
414 // Accountancy_account_interest
415 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
416 print '<td>';
417 print $formaccounting->select_account(GETPOST('accountancy_account_interest') ? GETPOST('accountancy_account_interest') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INTEREST'), 'accountancy_account_interest', 1, array(), 1, 1);
418 print '</td></tr>';
419 } else {
420 // For external software
421 // Accountancy_account_capital
422 print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
423 print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
424 print '</td></tr>';
425
426 // Accountancy_account_insurance
427 print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
428 print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
429 print '</td></tr>';
430
431 // Accountancy_account_interest
432 print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
433 print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
434 print '</td></tr>';
435 }
436 print '</table>';
437
438 print dol_get_fiche_end();
439
440 print $form->buttonsSaveCancel("Add");
441
442 print '</form>';
443}
444
445// View
446if ($id > 0) {
447 $object = new Loan($db);
448 $result = $object->fetch($id);
449
450 if ($result > 0) {
451 $head = loan_prepare_head($object);
452
453 $totalpaid = $object->getSumPayment();
454
455 // Confirm for loan
456 if ($action == 'paid') {
457 $text = $langs->trans('ConfirmPayLoan');
458 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2);
459 }
460
461 if ($action == 'delete') {
462 $text = $langs->trans('ConfirmDeleteLoan');
463 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2);
464 }
465
466 if ($action == 'edit') {
467 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
468 print '<input type="hidden" name="token" value="'.newToken().'">';
469 print '<input type="hidden" name="action" value="update">';
470 print '<input type="hidden" name="id" value="'.$id.'">';
471 }
472
473 print dol_get_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'money-bill-alt', 0, '', '', 0, '', ($action == 'edit' ? 0 : 1));
474
475 // Loan card
476 $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
477
478 $morehtmlref = '<div class="refidno">';
479 // Ref loan
480 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', 0, 1);
481 $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', null, null, '', 1);
482 // Project
483 if (isModEnabled('project')) {
484 $langs->loadLangs(array("projects"));
485 $morehtmlref .= '<br>'.$langs->trans('Project').' ';
486 if ($user->hasRight('loan', 'write')) {
487 if ($action != 'classify') {
488 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
489 }
490 if ($action == 'classify') {
491 $maxlength = 0;
492 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
493 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
494 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
495 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
496 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
497 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
498 $morehtmlref .= '</form>';
499 } else {
500 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, (string) $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
501 }
502 } else {
503 if (!empty($object->fk_project)) {
504 $proj = new Project($db);
505 $proj->fetch($object->fk_project);
506 $morehtmlref .= ' : '.$proj->getNomUrl(1);
507 if ($proj->title) {
508 $morehtmlref .= ' - '.$proj->title;
509 }
510 } else {
511 $morehtmlref .= '';
512 }
513 }
514 }
515 $morehtmlref .= '</div>';
516
517 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
518
519 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
520
521 print '<div class="fichecenter">';
522 print '<div class="fichehalfleft">';
523 print '<div class="underbanner clearboth"></div>';
524
525 print '<table class="border centpercent tableforfield">';
526
527 // Capital
528 if ($action == 'edit') {
529 print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>';
530 print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>';
531 print '</td></tr>';
532 } else {
533 print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td><span class="amount">'.price($object->capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</span></td></tr>';
534 }
535
536 // Insurance
537 if ($action == 'edit') {
538 $chargetypes = array();
539 foreach (loanChargeTypes() as $key => $label) {
540 $chargetypes[$key] = $langs->trans($label);
541 }
542 print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("LoanCharge"), $langs->trans("LoanChargeHelp")).'</td><td>';
543 print $form->selectarray('charge_type', $chargetypes, (int) $object->charge_type).' ';
544 print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"> ';
545 print $form->selectarray('charge_per_payment', array(0 => $langs->trans('LoanChargeTotal'), 1 => $langs->trans('LoanChargePerPayment')), (int) $object->charge_per_payment);
546 print '</td></tr>';
547 print '</td></tr>';
548 } else {
549 print '<tr><td class="titlefield">'.loanChargeLabel($object->charge_type, $langs).'</td><td><span class="amount">'.price($object->insurance_amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</span>'.((float) $object->insurance_amount ? ' <span class="opacitymedium">'.$langs->trans($object->charge_per_payment ? 'LoanChargePerPayment' : 'LoanChargeTotal').'</span>' : '').'</td></tr>';
550 }
551
552 // Date start
553 print '<tr><td>'.$langs->trans("DateStart")."</td>";
554 print "<td>";
555 if ($action == 'edit') {
556 print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0);
557 } else {
558 print dol_print_date($object->datestart, "day");
559 }
560 print "</td></tr>";
561
562 // Date end
563 print '<tr><td>'.$langs->trans("DateEnd")."</td>";
564 print "<td>";
565 if ($action == 'edit') {
566 print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0);
567 } else {
568 print dol_print_date($object->dateend, "day");
569 }
570 print "</td></tr>";
571
572 // Nbterms
573 print '<tr><td>'.$langs->trans("Nbterms").'</td>';
574 print '<td>';
575 if ($action == 'edit') {
576 print '<input name="nbterm" size="4" value="'.$object->nbterm.'">';
577 } else {
578 print $object->nbterm;
579 }
580 print '</td></tr>';
581
582 // Rate
583 print '<tr><td>'.$langs->trans("Rate").'</td>';
584 print '<td>';
585 if ($action == 'edit') {
586 print '<input name="rate" size="4" value="'.$object->rate.'">%';
587 } else {
588 print price($object->rate).'%';
589 }
590 print '</td></tr>';
591
592 // Payment frequency
593 $frequencies = array();
594 foreach (loanFrequencies() as $key => $label) {
595 $frequencies[$key] = $langs->trans($label);
596 }
597 print '<tr><td>'.$langs->trans("LoanFrequency").'</td>';
598 print '<td>';
599 if ($action == 'edit') {
600 print $form->selectarray('frequency', $frequencies, (int) $object->frequency);
601 } else {
602 print $frequencies[(int) $object->frequency] ?? (int) $object->frequency;
603 }
604 print '</td></tr>';
605
606 // Interest basis
607 $bases = array(0 => $langs->trans('LoanInterestBasisPeriod'), 1 => $langs->trans('LoanInterestBasisDaily'));
608 print '<tr><td>'.$form->textwithpicto($langs->trans("LoanInterestBasis"), $langs->trans("LoanInterestBasisHelp")).'</td>';
609 print '<td>';
610 if ($action == 'edit') {
611 print $form->selectarray('interest_basis', $bases, (int) $object->interest_basis);
612 } else {
613 print $bases[(int) $object->interest_basis];
614 }
615 print '</td></tr>';
616
617 // Balloon / residual
618 print '<tr><td>'.$form->textwithpicto($langs->trans("LoanBalloon"), $langs->trans("LoanBalloonHelp")).'</td>';
619 print '<td>';
620 if ($action == 'edit') {
621 print '<input name="balloon_amount" size="10" value="'.((float) $object->balloon_amount ? price2num($object->balloon_amount) : '').'">';
622 } else {
623 print ((float) $object->balloon_amount ? '<span class="amount">'.price($object->balloon_amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</span>' : '');
624 }
625 print '</td></tr>';
626
627 // Accountancy account capital
628 print '<tr>';
629 if ($action == 'edit') {
630 print '<td class="nowrap fieldrequired">';
631 print $langs->trans("LoanAccountancyCapitalCode");
632 print '</td><td>';
633
634 if (isModEnabled('accounting') && $formaccounting !== null) {
636 print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, array(), 1, 1);
637 } else {
638 print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">';
639 }
640 print '</td>';
641 } else {
642 print '<td class="nowrap">';
643 print $langs->trans("LoanAccountancyCapitalCode");
644 print '</td><td>';
645
646 if (isModEnabled('accounting')) {
647 $accountingaccount = new AccountingAccount($db);
648 $accountingaccount->fetch(0, $object->account_capital, 1);
649
650 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
651 } else {
652 print $object->account_capital;
653 }
654
655 print '</td>';
656 }
657 print '</tr>';
658
659 // Accountancy account insurance
660 print '<tr>';
661 if ($action == 'edit') {
662 print '<td class="nowrap fieldrequired">';
663 print $langs->trans("LoanAccountancyChargeCode", loanChargeLabel($object->charge_type, $langs));
664 print '</td><td>';
665
666 if (isModEnabled('accounting') && $formaccounting !== null) {
668 print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, array(), 1, 1);
669 } else {
670 print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">';
671 }
672 print '</td>';
673 } else {
674 print '<td class="nowrap">';
675 print $langs->trans("LoanAccountancyChargeCode", loanChargeLabel($object->charge_type, $langs));
676 print '</td><td>';
677
678 if (isModEnabled('accounting')) {
679 $accountingaccount = new AccountingAccount($db);
680 $accountingaccount->fetch(0, $object->account_insurance, 1);
681
682 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
683 } else {
684 print $object->account_insurance;
685 }
686
687 print '</td>';
688 }
689 print '</tr>';
690
691 // Accountancy account interest
692 print '<tr>';
693 if ($action == 'edit') {
694 print '<td class="nowrap fieldrequired">';
695 print $langs->trans("LoanAccountancyInterestCode");
696 print '</td><td>';
697
698 if (isModEnabled('accounting') && $formaccounting !== null) {
700 print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, array(), 1, 1);
701 } else {
702 print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">';
703 }
704 print '</td>';
705 } else {
706 print '<td class="nowrap">';
707 print $langs->trans("LoanAccountancyInterestCode");
708 print '</td><td>';
709
710 if (isModEnabled('accounting')) {
711 $accountingaccount = new AccountingAccount($db);
712 $accountingaccount->fetch(0, $object->account_interest, 1);
713
714 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
715 } else {
716 print $object->account_interest;
717 }
718
719 print '</td>';
720 }
721 print '</tr>';
722
723 // Other attributes
724 $parameters = array();
725 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
726 print $hookmanager->resPrint;
727
728 print '</table>';
729
730 print '</div>';
731 print '<div class="fichehalfright">';
732
733 /*
734 * Payments
735 */
736 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp,";
737 $sql .= " p.amount_capital, p.amount_insurance, p.amount_interest,";
738 $sql .= " b.fk_account,";
739 $sql .= " c.libelle as paiement_type";
740 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
741 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
742 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id,";
743 $sql .= " ".MAIN_DB_PREFIX."loan as l";
744 $sql .= " WHERE p.fk_loan = ".((int) $id);
745 $sql .= " AND p.fk_loan = l.rowid";
746 $sql .= " AND l.entity IN ( ".getEntity('loan').")";
747 $sql .= " ORDER BY dp DESC";
748
749 //print $sql;
750 $resql = $db->query($sql);
751 if ($resql) {
752 $num = $db->num_rows($resql);
753 $i = 0;
754 $total_capital = 0;
755
756 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
757 print '<table class="noborder paymenttable">';
758 print '<tr class="liste_titre">';
759 print '<td>'.$langs->trans("RefPayment").'</td>';
760 print '<td>'.$langs->trans("Date").'</td>';
761 print '<td>'.$langs->trans("Type").'</td>';
762 print '<td>'.$langs->trans("BankAccount").'</td>';
763 print '<td class="right">'.loanChargeLabel($object->charge_type, $langs).'</td>';
764 print '<td class="right">'.$langs->trans("Interest").'</td>';
765 print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
766 print '<td class="right">'.$langs->trans("Total").'</td>';
767 print '</tr>';
768
769 $conf->cache['bankaccount'] = array();
770
771 while ($i < $num) {
772 $objp = $db->fetch_object($resql);
773
774 print '<tr class="oddeven">';
775 print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
776 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
777 print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
778 print "<td>";
779 if (!empty($conf->cache['bankaccount'][$objp->fk_account])) {
780 $tmpbank = $conf->cache['bankaccount'][$objp->fk_account];
781 } else {
782 $tmpbank = new Account($db);
783 $tmpbank->fetch($objp->fk_account);
784 $conf->cache['bankaccount'][$objp->fk_account] = $tmpbank;
785 }
786 print $tmpbank->getNomUrl(1);
787 print "</td>\n";
788 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
789 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
790 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
791 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_insurance + $objp->amount_interest + $objp->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
792 print "</tr>";
793 $total_capital += $objp->amount_capital;
794 $i++;
795 }
796
797 $totalpaid = $total_capital;
798
799 if ($object->paid == 0 || $object->paid == 2) {
800 print '<tr><td colspan="6" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="nowrap right">'.price($totalpaid, 0, $langs, 0, -1, -1, $conf->currency).'</td><td>&nbsp;</td></tr>';
801 print '<tr><td colspan="6" class="right">'.$langs->trans("AmountExpected").' :</td><td class="nowrap right">'.price($object->capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td><td>&nbsp;</td></tr>';
802
803 $staytopay = $object->capital - $totalpaid;
804
805 print '<tr><td colspan="6" class="right">'.$langs->trans("RemainderToPay").' :</td>';
806 print '<td class="nowrap right'.($staytopay ? ' amountremaintopay' : ' amountpaymentcomplete').'">';
807 print price($staytopay, 0, $langs, 0, -1, -1, $conf->currency);
808 print '</td>';
809 print '<td>&nbsp;</td>';
810 print '</tr>';
811 }
812 print "</table>";
813 print '</div>';
814
815 $db->free($resql);
816 } else {
817 dol_print_error($db);
818 }
819
820 print '</div>';
821 print '</div>';
822
823 print '<div class="clearboth"></div>';
824
825 print dol_get_fiche_end();
826
827 if ($action == 'edit') {
828 print $form->buttonsSaveCancel();
829
830 print '</form>';
831 }
832
833 /*
834 * Buttons actions
835 */
836 if ($action != 'edit') {
837 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
838 if (empty($reshook)) {
839 print '<div class="tabsAction">';
840
841 // Edit
842 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'write')) {
843 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>';
844 }
845
846 // Emit payment
847 // TODO check if loan schedule is created ($echeances->lines > 0)
848 if (($object->paid == 0 || $object->paid == 2) && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->hasRight('loan', 'write')) {
849 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>';
850 }
851
852 // Classify 'paid'
853 if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->hasRight('loan', 'write')) {
854 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
855 }
856
857 // Delete
858 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'delete')) {
859 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=delete&token='.newToken(), '', true, array('attr' => array('class' => 'reposition'))).'</div>'."\n";
860 }
861
862 print "</div>";
863 }
864 }
865 } else {
866 // Loan not found
867 dol_print_error(null, $object->error);
868 }
869}
870
871// End of page
872llxFooter();
873$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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 bank accounts.
Class to manage accounting accounts.
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Loan.
Class to manage projects.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
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
loanFrequencies()
Payment frequencies of a loan.
Definition loan.lib.php:231
loanChargeTypes()
Kinds of charge the "insurance" amount of a loan can be.
Definition loan.lib.php:312
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.