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->note_private = GETPOST('note_private', 'restricthtml');
154 $object->note_public = GETPOST('note_public', 'restricthtml');
155 $object->fk_project = GETPOSTINT('projectid');
156 $object->insurance_amount = GETPOSTFLOAT('insurance_amount');
157
158 $accountancy_account_capital = GETPOST('accountancy_account_capital');
159 $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
160 $accountancy_account_interest = GETPOST('accountancy_account_interest');
161
162 if ($accountancy_account_capital <= 0) {
163 $object->account_capital = '';
164 } else {
165 $object->account_capital = $accountancy_account_capital;
166 }
167 if ($accountancy_account_insurance <= 0) {
168 $object->account_insurance = '';
169 } else {
170 $object->account_insurance = $accountancy_account_insurance;
171 }
172 if ($accountancy_account_interest <= 0) {
173 $object->account_interest = '';
174 } else {
175 $object->account_interest = $accountancy_account_interest;
176 }
177
178 $id = $object->create($user);
179 if ($id <= 0) {
180 $error++;
181 setEventMessages($object->error, $object->errors, 'errors');
182 $action = 'create';
183 }
184 }
185 } else {
186 header("Location: list.php");
187 exit();
188 }
189 } elseif ($action == 'update' && $permissiontoadd) {
190 // Update record
191 if (!$cancel) {
192 $result = $object->fetch($id);
193
194 $datestart = dol_mktime(12, 0, 0, GETPOSTINT('startmonth'), GETPOSTINT('startday'), GETPOSTINT('startyear'));
195 $dateend = dol_mktime(12, 0, 0, GETPOSTINT('endmonth'), GETPOSTINT('endday'), GETPOSTINT('endyear'));
196
197 $capital = GETPOSTFLOAT('capital');
198
199 if (!$capital) {
200 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("LoanCapital")), null, 'errors');
201 $action = 'edit';
202 } else {
203 $object->datestart = $datestart;
204 $object->dateend = $dateend;
205 $object->capital = $capital;
206
207 $object->nbterm = GETPOSTINT("nbterm");
208 $object->rate = GETPOSTFLOAT("rate");
209 $object->insurance_amount = GETPOSTFLOAT('insurance_amount');
210
211 $accountancy_account_capital = GETPOST('accountancy_account_capital');
212 $accountancy_account_insurance = GETPOST('accountancy_account_insurance');
213 $accountancy_account_interest = GETPOST('accountancy_account_interest');
214
215 if ($accountancy_account_capital <= 0) {
216 $object->account_capital = '';
217 } else {
218 $object->account_capital = $accountancy_account_capital;
219 }
220 if ($accountancy_account_insurance <= 0) {
221 $object->account_insurance = '';
222 } else {
223 $object->account_insurance = $accountancy_account_insurance;
224 }
225 if ($accountancy_account_interest <= 0) {
226 $object->account_interest = '';
227 } else {
228 $object->account_interest = $accountancy_account_interest;
229 }
230 }
231
232 $result = $object->update($user);
233
234 if ($result > 0) {
235 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
236 exit;
237 } else {
238 $error++;
239 setEventMessages($object->error, $object->errors, 'errors');
240 }
241 } else {
242 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
243 exit;
244 }
245 }
246
247 // Link to a project
248 if ($action == 'classin' && $permissiontoadd) {
249 $object->fetch($id);
250 $result = $object->setProject($projectid);
251 if ($result < 0) {
252 setEventMessages($object->error, $object->errors, 'errors');
253 }
254 }
255
256 if ($action == 'setlabel' && $permissiontoadd) {
257 $object->fetch($id);
258 $result = $object->setValueFrom('label', GETPOST('label'), '', null, 'text', '', $user, 'LOAN_MODIFY');
259 if ($result < 0) {
260 setEventMessages($object->error, $object->errors, 'errors');
261 }
262 }
263
264 // Actions to build doc
265 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
266}
267
268
269/*
270 * View
271 */
272
273$form = new Form($db);
274$formproject = new FormProjets($db);
275$morehtmlstatus = '';
276$outputlangs = $langs;
277$formaccounting = null;
278if (isModEnabled('accounting')) {
279 $formaccounting = new FormAccounting($db);
280}
281$title = $langs->trans("Loan").' - '.$langs->trans("Card");
282$help_url = 'EN:Module_Loan|FR:Module_Emprunt';
283
284llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-loan page-card');
285
286
287// Create mode
288if ($action == 'create') {
289 //WYSIWYG Editor
290 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
291
292 print load_fiche_titre($langs->trans("NewLoan"), '', 'money-bill-alt');
293
294 print '<form name="loan" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
295 print '<input type="hidden" name="token" value="'.newToken().'">';
296 print '<input type="hidden" name="action" value="add">';
297
298 print dol_get_fiche_head();
299
300 print '<table class="border centpercent">';
301
302 // Label
303 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>';
304
305 // Bank account
306 if (isModEnabled("bank")) {
307 print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
308 $form->select_comptes(GETPOST("accountid"), "accountid", 0, "(courant:=:1)", 1); // Show list of bank account with courant
309 print '</td></tr>';
310 } else {
311 print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
312 print $langs->trans("NoBankAccountDefined");
313 print '</td></tr>';
314 }
315
316 // Capital
317 print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="'.dol_escape_htmltag(GETPOST("capital")).'"></td></tr>';
318
319 // Date Start
320 print "<tr>";
321 print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
322 print $form->selectDate(!empty($datestart) ? $datestart : -1, 'start', 0, 0, 0, 'add', 1, 1);
323 print '</td></tr>';
324
325 // Date End
326 print "<tr>";
327 print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
328 print $form->selectDate(!empty($dateend) ? $dateend : -1, 'end', 0, 0, 0, 'add', 1, 1);
329 print '</td></tr>';
330
331 // Number of terms
332 print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="'.dol_escape_htmltag(GETPOST('nbterm')).'"></td></tr>';
333
334 // Rate
335 print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="'.dol_escape_htmltag(GETPOST("rate")).'"> %</td></tr>';
336
337 // Insurance amount
338 print '<tr><td>'.$langs->trans("Insurance").'</td><td><input name="insurance_amount" size="10" value="'.dol_escape_htmltag(GETPOST("insurance_amount")).'" placeholder="'.$langs->trans('Amount').'"></td></tr>';
339
340 // Project
341 if (isModEnabled('project')) {
342 $formproject = new FormProjets($db);
343
344 // Linked Project
345 $langs->loadLangs(array("projects"));
346
347 print '<tr><td>'.$langs->trans("Project").'</td><td>';
348
349 $formproject->select_projects(-1, (string) $projectid, 'projectid', 16, 0, 1, 1);
350
351 print '</td></tr>';
352 }
353
354 // Note Private
355 print '<tr>';
356 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
357 print '<td>';
358
359 $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%');
360 print $doleditor->Create(1);
361
362 print '</td></tr>';
363
364 // Note Public
365 print '<tr>';
366 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
367 print '<td>';
368 $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%');
369 print $doleditor->Create(1);
370 print '</td></tr>';
371
372 // Accountancy
373 if (isModEnabled('accounting') && $formaccounting !== null) {
375 // Accountancy_account_capital
376 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
377 print '<td>';
378 print $formaccounting->select_account(GETPOST('accountancy_account_capital') ? GETPOST('accountancy_account_capital') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_CAPITAL'), 'accountancy_account_capital', 1, array(), 1, 1);
379 print '</td></tr>';
380
381 // Accountancy_account_insurance
382 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
383 print '<td>';
384 print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ? GETPOST('accountancy_account_insurance') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INSURANCE'), 'accountancy_account_insurance', 1, array(), 1, 1);
385 print '</td></tr>';
386
387 // Accountancy_account_interest
388 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
389 print '<td>';
390 print $formaccounting->select_account(GETPOST('accountancy_account_interest') ? GETPOST('accountancy_account_interest') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INTEREST'), 'accountancy_account_interest', 1, array(), 1, 1);
391 print '</td></tr>';
392 } else {
393 // For external software
394 // Accountancy_account_capital
395 print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
396 print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
397 print '</td></tr>';
398
399 // Accountancy_account_insurance
400 print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
401 print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
402 print '</td></tr>';
403
404 // Accountancy_account_interest
405 print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
406 print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
407 print '</td></tr>';
408 }
409 print '</table>';
410
411 print dol_get_fiche_end();
412
413 print $form->buttonsSaveCancel("Add");
414
415 print '</form>';
416}
417
418// View
419if ($id > 0) {
420 $object = new Loan($db);
421 $result = $object->fetch($id);
422
423 if ($result > 0) {
424 $head = loan_prepare_head($object);
425
426 $totalpaid = $object->getSumPayment();
427
428 // Confirm for loan
429 if ($action == 'paid') {
430 $text = $langs->trans('ConfirmPayLoan');
431 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2);
432 }
433
434 if ($action == 'delete') {
435 $text = $langs->trans('ConfirmDeleteLoan');
436 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2);
437 }
438
439 if ($action == 'edit') {
440 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
441 print '<input type="hidden" name="token" value="'.newToken().'">';
442 print '<input type="hidden" name="action" value="update">';
443 print '<input type="hidden" name="id" value="'.$id.'">';
444 }
445
446 print dol_get_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'money-bill-alt', 0, '', '', 0, '', ($action == 'edit' ? 0 : 1));
447
448 // Loan card
449 $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
450
451 $morehtmlref = '<div class="refidno">';
452 // Ref loan
453 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', 0, 1);
454 $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', null, null, '', 1);
455 // Project
456 if (isModEnabled('project')) {
457 $langs->loadLangs(array("projects"));
458 $morehtmlref .= '<br>'.$langs->trans('Project').' ';
459 if ($user->hasRight('loan', 'write')) {
460 if ($action != 'classify') {
461 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
462 }
463 if ($action == 'classify') {
464 $maxlength = 0;
465 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
466 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
467 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
468 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
469 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
470 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
471 $morehtmlref .= '</form>';
472 } else {
473 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, (string) $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
474 }
475 } else {
476 if (!empty($object->fk_project)) {
477 $proj = new Project($db);
478 $proj->fetch($object->fk_project);
479 $morehtmlref .= ' : '.$proj->getNomUrl(1);
480 if ($proj->title) {
481 $morehtmlref .= ' - '.$proj->title;
482 }
483 } else {
484 $morehtmlref .= '';
485 }
486 }
487 }
488 $morehtmlref .= '</div>';
489
490 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
491
492 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
493
494 print '<div class="fichecenter">';
495 print '<div class="fichehalfleft">';
496 print '<div class="underbanner clearboth"></div>';
497
498 print '<table class="border centpercent tableforfield">';
499
500 // Capital
501 if ($action == 'edit') {
502 print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>';
503 print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>';
504 print '</td></tr>';
505 } else {
506 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>';
507 }
508
509 // Insurance
510 if ($action == 'edit') {
511 print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>';
512 print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"></td></tr>';
513 print '</td></tr>';
514 } else {
515 print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td><span class="amount">'.price($object->insurance_amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</span></td></tr>';
516 }
517
518 // Date start
519 print '<tr><td>'.$langs->trans("DateStart")."</td>";
520 print "<td>";
521 if ($action == 'edit') {
522 print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0);
523 } else {
524 print dol_print_date($object->datestart, "day");
525 }
526 print "</td></tr>";
527
528 // Date end
529 print '<tr><td>'.$langs->trans("DateEnd")."</td>";
530 print "<td>";
531 if ($action == 'edit') {
532 print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0);
533 } else {
534 print dol_print_date($object->dateend, "day");
535 }
536 print "</td></tr>";
537
538 // Nbterms
539 print '<tr><td>'.$langs->trans("Nbterms").'</td>';
540 print '<td>';
541 if ($action == 'edit') {
542 print '<input name="nbterm" size="4" value="'.$object->nbterm.'">';
543 } else {
544 print $object->nbterm;
545 }
546 print '</td></tr>';
547
548 // Rate
549 print '<tr><td>'.$langs->trans("Rate").'</td>';
550 print '<td>';
551 if ($action == 'edit') {
552 print '<input name="rate" size="4" value="'.$object->rate.'">%';
553 } else {
554 print price($object->rate).'%';
555 }
556 print '</td></tr>';
557
558 // Accountancy account capital
559 print '<tr>';
560 if ($action == 'edit') {
561 print '<td class="nowrap fieldrequired">';
562 print $langs->trans("LoanAccountancyCapitalCode");
563 print '</td><td>';
564
565 if (isModEnabled('accounting') && $formaccounting !== null) {
567 print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, array(), 1, 1);
568 } else {
569 print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">';
570 }
571 print '</td>';
572 } else {
573 print '<td class="nowrap">';
574 print $langs->trans("LoanAccountancyCapitalCode");
575 print '</td><td>';
576
577 if (isModEnabled('accounting')) {
578 $accountingaccount = new AccountingAccount($db);
579 $accountingaccount->fetch(0, $object->account_capital, 1);
580
581 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
582 } else {
583 print $object->account_capital;
584 }
585
586 print '</td>';
587 }
588 print '</tr>';
589
590 // Accountancy account insurance
591 print '<tr>';
592 if ($action == 'edit') {
593 print '<td class="nowrap fieldrequired">';
594 print $langs->trans("LoanAccountancyInsuranceCode");
595 print '</td><td>';
596
597 if (isModEnabled('accounting') && $formaccounting !== null) {
599 print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, array(), 1, 1);
600 } else {
601 print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">';
602 }
603 print '</td>';
604 } else {
605 print '<td class="nowrap">';
606 print $langs->trans("LoanAccountancyInsuranceCode");
607 print '</td><td>';
608
609 if (isModEnabled('accounting')) {
610 $accountingaccount = new AccountingAccount($db);
611 $accountingaccount->fetch(0, $object->account_insurance, 1);
612
613 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
614 } else {
615 print $object->account_insurance;
616 }
617
618 print '</td>';
619 }
620 print '</tr>';
621
622 // Accountancy account interest
623 print '<tr>';
624 if ($action == 'edit') {
625 print '<td class="nowrap fieldrequired">';
626 print $langs->trans("LoanAccountancyInterestCode");
627 print '</td><td>';
628
629 if (isModEnabled('accounting') && $formaccounting !== null) {
631 print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, array(), 1, 1);
632 } else {
633 print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">';
634 }
635 print '</td>';
636 } else {
637 print '<td class="nowrap">';
638 print $langs->trans("LoanAccountancyInterestCode");
639 print '</td><td>';
640
641 if (isModEnabled('accounting')) {
642 $accountingaccount = new AccountingAccount($db);
643 $accountingaccount->fetch(0, $object->account_interest, 1);
644
645 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
646 } else {
647 print $object->account_interest;
648 }
649
650 print '</td>';
651 }
652 print '</tr>';
653
654 // Other attributes
655 $parameters = array();
656 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
657 print $hookmanager->resPrint;
658
659 print '</table>';
660
661 print '</div>';
662 print '<div class="fichehalfright">';
663
664 /*
665 * Payments
666 */
667 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp,";
668 $sql .= " p.amount_capital, p.amount_insurance, p.amount_interest,";
669 $sql .= " b.fk_account,";
670 $sql .= " c.libelle as paiement_type";
671 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
672 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
673 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id,";
674 $sql .= " ".MAIN_DB_PREFIX."loan as l";
675 $sql .= " WHERE p.fk_loan = ".((int) $id);
676 $sql .= " AND p.fk_loan = l.rowid";
677 $sql .= " AND l.entity IN ( ".getEntity('loan').")";
678 $sql .= " ORDER BY dp DESC";
679
680 //print $sql;
681 $resql = $db->query($sql);
682 if ($resql) {
683 $num = $db->num_rows($resql);
684 $i = 0;
685 $total_capital = 0;
686
687 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
688 print '<table class="noborder paymenttable">';
689 print '<tr class="liste_titre">';
690 print '<td>'.$langs->trans("RefPayment").'</td>';
691 print '<td>'.$langs->trans("Date").'</td>';
692 print '<td>'.$langs->trans("Type").'</td>';
693 print '<td>'.$langs->trans("BankAccount").'</td>';
694 print '<td class="right">'.$langs->trans("Insurance").'</td>';
695 print '<td class="right">'.$langs->trans("Interest").'</td>';
696 print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
697 print '<td class="right">'.$langs->trans("Total").'</td>';
698 print '</tr>';
699
700 $conf->cache['bankaccount'] = array();
701
702 while ($i < $num) {
703 $objp = $db->fetch_object($resql);
704
705 print '<tr class="oddeven">';
706 print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
707 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
708 print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
709 print "<td>";
710 if (!empty($conf->cache['bankaccount'][$objp->fk_account])) {
711 $tmpbank = $conf->cache['bankaccount'][$objp->fk_account];
712 } else {
713 $tmpbank = new Account($db);
714 $tmpbank->fetch($objp->fk_account);
715 $conf->cache['bankaccount'][$objp->fk_account] = $tmpbank;
716 }
717 print $tmpbank->getNomUrl(1);
718 print "</td>\n";
719 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
720 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
721 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
722 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";
723 print "</tr>";
724 $total_capital += $objp->amount_capital;
725 $i++;
726 }
727
728 $totalpaid = $total_capital;
729
730 if ($object->paid == 0 || $object->paid == 2) {
731 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>';
732 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>';
733
734 $staytopay = $object->capital - $totalpaid;
735
736 print '<tr><td colspan="6" class="right">'.$langs->trans("RemainderToPay").' :</td>';
737 print '<td class="nowrap right'.($staytopay ? ' amountremaintopay' : ' amountpaymentcomplete').'">';
738 print price($staytopay, 0, $langs, 0, -1, -1, $conf->currency);
739 print '</td>';
740 print '<td>&nbsp;</td>';
741 print '</tr>';
742 }
743 print "</table>";
744 print '</div>';
745
746 $db->free($resql);
747 } else {
748 dol_print_error($db);
749 }
750
751 print '</div>';
752 print '</div>';
753
754 print '<div class="clearboth"></div>';
755
756 print dol_get_fiche_end();
757
758 if ($action == 'edit') {
759 print $form->buttonsSaveCancel();
760
761 print '</form>';
762 }
763
764 /*
765 * Buttons actions
766 */
767 if ($action != 'edit') {
768 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
769 if (empty($reshook)) {
770 print '<div class="tabsAction">';
771
772 // Edit
773 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'write')) {
774 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>';
775 }
776
777 // Emit payment
778 // TODO check if loan schedule is created ($echeances->lines > 0)
779 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')) {
780 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>';
781 }
782
783 // Classify 'paid'
784 if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->hasRight('loan', 'write')) {
785 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>';
786 }
787
788 // Delete
789 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'delete')) {
790 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";
791 }
792
793 print "</div>";
794 }
795 }
796 } else {
797 // Loan not found
798 dol_print_error(null, $object->error);
799 }
800}
801
802// End of page
803llxFooter();
804$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
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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)
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:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
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:181
loan_prepare_head($object)
Prepare array with list of tabs.
Definition loan.lib.php:34
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.