dolibarr 21.0.3
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-2024 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 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';
30require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
36
37if (isModEnabled('accounting')) {
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
40}
41
42if (isModEnabled('project')) {
43 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
44}
45
46
55// Load translation files required by the page
56$langs->loadLangs(array("banks", "bills", "compta", "loan"));
57
58$id = GETPOSTINT('id');
59$action = GETPOST('action', 'aZ09');
60$confirm = GETPOST('confirm');
61$cancel = GETPOST('cancel', 'alpha');
62
63$projectid = GETPOSTINT('projectid');
64
65// Security check
66$socid = GETPOSTINT('socid');
67if ($user->socid) {
68 $socid = $user->socid;
69}
70$hookmanager->initHooks(array('loancard', 'globalcard'));
71$result = restrictedArea($user, 'loan', $id, '', '');
72
73$object = new Loan($db);
74
75$permissiontoadd = $user->hasRight('loan', 'write');
76
77$error = 0;
78$staytopay = 0;
79
80
81/*
82 * Actions
83 */
84
85$parameters = array();
86$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
87if ($reshook < 0) {
88 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
89}
90if (empty($reshook)) {
91 // Classify paid
92 if ($action == 'confirm_paid' && $confirm == 'yes' && $permissiontoadd) {
93 $object->fetch($id);
94 $result = $object->setPaid($user);
95 if ($result > 0) {
96 setEventMessages($langs->trans('LoanPaid'), null, 'mesgs');
97 } else {
98 setEventMessages($object->error, $object->errors, 'errors');
99 }
100 }
101
102 // Delete loan
103 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontoadd) {
104 $object->fetch($id);
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;
277if (isModEnabled('accounting')) {
278 $formaccounting = new FormAccounting($db);
279}
280$title = $langs->trans("Loan").' - '.$langs->trans("Card");
281$help_url = 'EN:Module_Loan|FR:Module_Emprunt';
282
283llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-loan page-card');
284
285
286// Create mode
287if ($action == 'create') {
288 //WYSIWYG Editor
289 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
290
291 print load_fiche_titre($langs->trans("NewLoan"), '', 'money-bill-alt');
292
293 $datec = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
294
295 print '<form name="loan" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
296 print '<input type="hidden" name="token" value="'.newToken().'">';
297 print '<input type="hidden" name="action" value="add">';
298
299 print dol_get_fiche_head();
300
301 print '<table class="border centpercent">';
302
303 // Label
304 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>';
305
306 // Bank account
307 if (isModEnabled("bank")) {
308 print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
309 $form->select_comptes(GETPOST("accountid"), "accountid", 0, "courant=1", 1); // Show list of bank account with courant
310 print '</td></tr>';
311 } else {
312 print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
313 print $langs->trans("NoBankAccountDefined");
314 print '</td></tr>';
315 }
316
317 // Capital
318 print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="'.dol_escape_htmltag(GETPOST("capital")).'"></td></tr>';
319
320 // Date Start
321 print "<tr>";
322 print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
323 print $form->selectDate(!empty($datestart) ? $datestart : -1, 'start', 0, 0, 0, 'add', 1, 1);
324 print '</td></tr>';
325
326 // Date End
327 print "<tr>";
328 print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
329 print $form->selectDate(!empty($dateend) ? $dateend : -1, 'end', 0, 0, 0, 'add', 1, 1);
330 print '</td></tr>';
331
332 // Number of terms
333 print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="'.dol_escape_htmltag(GETPOST('nbterm')).'"></td></tr>';
334
335 // Rate
336 print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="'.dol_escape_htmltag(GETPOST("rate")).'"> %</td></tr>';
337
338 // Insurance amount
339 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>';
340
341 // Project
342 if (isModEnabled('project')) {
343 $formproject = new FormProjets($db);
344
345 // Linked Project
346 $langs->loadLangs(array("projects"));
347
348 print '<tr><td>'.$langs->trans("Project").'</td><td>';
349
350 $numproject = $formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1);
351
352 print '</td></tr>';
353 }
354
355 // Note Private
356 print '<tr>';
357 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
358 print '<td>';
359
360 $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%');
361 print $doleditor->Create(1);
362
363 print '</td></tr>';
364
365 // Note Public
366 print '<tr>';
367 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
368 print '<td>';
369 $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%');
370 print $doleditor->Create(1);
371 print '</td></tr>';
372
373 // Accountancy
374 if (isModEnabled('accounting')) {
376 // Accountancy_account_capital
377 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
378 print '<td>';
379 print $formaccounting->select_account(GETPOST('accountancy_account_capital') ? GETPOST('accountancy_account_capital') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_CAPITAL'), 'accountancy_account_capital', 1, '', 1, 1);
380 print '</td></tr>';
381
382 // Accountancy_account_insurance
383 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
384 print '<td>';
385 print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ? GETPOST('accountancy_account_insurance') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INSURANCE'), 'accountancy_account_insurance', 1, '', 1, 1);
386 print '</td></tr>';
387
388 // Accountancy_account_interest
389 print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
390 print '<td>';
391 print $formaccounting->select_account(GETPOST('accountancy_account_interest') ? GETPOST('accountancy_account_interest') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INTEREST'), 'accountancy_account_interest', 1, '', 1, 1);
392 print '</td></tr>';
393 } else {
394 // For external software
395 // Accountancy_account_capital
396 print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
397 print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
398 print '</td></tr>';
399
400 // Accountancy_account_insurance
401 print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
402 print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
403 print '</td></tr>';
404
405 // Accountancy_account_interest
406 print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
407 print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
408 print '</td></tr>';
409 }
410 print '</table>';
411
412 print dol_get_fiche_end();
413
414 print $form->buttonsSaveCancel("Add");
415
416 print '</form>';
417}
418
419// View
420if ($id > 0) {
421 $object = new Loan($db);
422 $result = $object->fetch($id);
423
424 if ($result > 0) {
425 $head = loan_prepare_head($object);
426
427 $totalpaid = $object->getSumPayment();
428
429 // Confirm for loan
430 if ($action == 'paid') {
431 $text = $langs->trans('ConfirmPayLoan');
432 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2);
433 }
434
435 if ($action == 'delete') {
436 $text = $langs->trans('ConfirmDeleteLoan');
437 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2);
438 }
439
440 if ($action == 'edit') {
441 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
442 print '<input type="hidden" name="token" value="'.newToken().'">';
443 print '<input type="hidden" name="action" value="update">';
444 print '<input type="hidden" name="id" value="'.$id.'">';
445 }
446
447 print dol_get_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'money-bill-alt', 0, '', '', 0, '', 1);
448
449 // Loan card
450 $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
451
452 $morehtmlref = '<div class="refidno">';
453 // Ref loan
454 $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', 0, 1);
455 $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', null, null, '', 1);
456 // Project
457 if (isModEnabled('project')) {
458 $langs->loadLangs(array("projects"));
459 $morehtmlref .= '<br>'.$langs->trans('Project').' ';
460 if ($user->hasRight('loan', 'write')) {
461 if ($action != 'classify') {
462 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
463 }
464 if ($action == 'classify') {
465 $maxlength = 0;
466 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
467 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
468 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
469 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
470 $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
471 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
472 $morehtmlref .= '</form>';
473 } else {
474 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
475 }
476 } else {
477 if (!empty($object->fk_project)) {
478 $proj = new Project($db);
479 $proj->fetch($object->fk_project);
480 $morehtmlref .= ' : '.$proj->getNomUrl(1);
481 if ($proj->title) {
482 $morehtmlref .= ' - '.$proj->title;
483 }
484 } else {
485 $morehtmlref .= '';
486 }
487 }
488 }
489 $morehtmlref .= '</div>';
490
491 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
492
493 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
494
495 print '<div class="fichecenter">';
496 print '<div class="fichehalfleft">';
497 print '<div class="underbanner clearboth"></div>';
498
499 print '<table class="border centpercent tableforfield">';
500
501 // Capital
502 if ($action == 'edit') {
503 print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>';
504 print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>';
505 print '</td></tr>';
506 } else {
507 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>';
508 }
509
510 // Insurance
511 if ($action == 'edit') {
512 print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>';
513 print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"></td></tr>';
514 print '</td></tr>';
515 } else {
516 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>';
517 }
518
519 // Date start
520 print '<tr><td>'.$langs->trans("DateStart")."</td>";
521 print "<td>";
522 if ($action == 'edit') {
523 print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0);
524 } else {
525 print dol_print_date($object->datestart, "day");
526 }
527 print "</td></tr>";
528
529 // Date end
530 print '<tr><td>'.$langs->trans("DateEnd")."</td>";
531 print "<td>";
532 if ($action == 'edit') {
533 print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0);
534 } else {
535 print dol_print_date($object->dateend, "day");
536 }
537 print "</td></tr>";
538
539 // Nbterms
540 print '<tr><td>'.$langs->trans("Nbterms").'</td>';
541 print '<td>';
542 if ($action == 'edit') {
543 print '<input name="nbterm" size="4" value="'.$object->nbterm.'">';
544 } else {
545 print $object->nbterm;
546 }
547 print '</td></tr>';
548
549 // Rate
550 print '<tr><td>'.$langs->trans("Rate").'</td>';
551 print '<td>';
552 if ($action == 'edit') {
553 print '<input name="rate" size="4" value="'.$object->rate.'">%';
554 } else {
555 print price($object->rate).'%';
556 }
557 print '</td></tr>';
558
559 // Accountancy account capital
560 print '<tr>';
561 if ($action == 'edit') {
562 print '<td class="nowrap fieldrequired">';
563 print $langs->trans("LoanAccountancyCapitalCode");
564 print '</td><td>';
565
566 if (isModEnabled('accounting')) {
568 print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1);
569 } else {
570 print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">';
571 }
572 print '</td>';
573 } else {
574 print '<td class="nowrap">';
575 print $langs->trans("LoanAccountancyCapitalCode");
576 print '</td><td>';
577
578 if (isModEnabled('accounting')) {
579 $accountingaccount = new AccountingAccount($db);
580 $accountingaccount->fetch('', $object->account_capital, 1);
581
582 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
583 } else {
584 print $object->account_capital;
585 }
586
587 print '</td>';
588 }
589 print '</tr>';
590
591 // Accountancy account insurance
592 print '<tr>';
593 if ($action == 'edit') {
594 print '<td class="nowrap fieldrequired">';
595 print $langs->trans("LoanAccountancyInsuranceCode");
596 print '</td><td>';
597
598 if (isModEnabled('accounting')) {
600 print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1);
601 } else {
602 print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">';
603 }
604 print '</td>';
605 } else {
606 print '<td class="nowrap">';
607 print $langs->trans("LoanAccountancyInsuranceCode");
608 print '</td><td>';
609
610 if (isModEnabled('accounting')) {
611 $accountingaccount = new AccountingAccount($db);
612 $accountingaccount->fetch('', $object->account_insurance, 1);
613
614 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
615 } else {
616 print $object->account_insurance;
617 }
618
619 print '</td>';
620 }
621 print '</tr>';
622
623 // Accountancy account interest
624 print '<tr>';
625 if ($action == 'edit') {
626 print '<td class="nowrap fieldrequired">';
627 print $langs->trans("LoanAccountancyInterestCode");
628 print '</td><td>';
629
630 if (isModEnabled('accounting')) {
632 print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1);
633 } else {
634 print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">';
635 }
636 print '</td>';
637 } else {
638 print '<td class="nowrap">';
639 print $langs->trans("LoanAccountancyInterestCode");
640 print '</td><td>';
641
642 if (isModEnabled('accounting')) {
643 $accountingaccount = new AccountingAccount($db);
644 $accountingaccount->fetch('', $object->account_interest, 1);
645
646 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
647 } else {
648 print $object->account_interest;
649 }
650
651 print '</td>';
652 }
653 print '</tr>';
654
655 // Other attributes
656 $parameters = array();
657 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
658 print $hookmanager->resPrint;
659
660 print '</table>';
661
662 print '</div>';
663 print '<div class="fichehalfright">';
664
665 /*
666 * Payments
667 */
668 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp,";
669 $sql .= " p.amount_capital, p.amount_insurance, p.amount_interest,";
670 $sql .= " b.fk_account,";
671 $sql .= " c.libelle as paiement_type";
672 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
673 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
674 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id,";
675 $sql .= " ".MAIN_DB_PREFIX."loan as l";
676 $sql .= " WHERE p.fk_loan = ".((int) $id);
677 $sql .= " AND p.fk_loan = l.rowid";
678 $sql .= " AND l.entity IN ( ".getEntity('loan').")";
679 $sql .= " ORDER BY dp DESC";
680
681 //print $sql;
682 $resql = $db->query($sql);
683 if ($resql) {
684 $num = $db->num_rows($resql);
685 $i = 0;
686 $total_insurance = 0;
687 $total_interest = 0;
688 $total_capital = 0;
689
690 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
691 print '<table class="noborder paymenttable">';
692 print '<tr class="liste_titre">';
693 print '<td>'.$langs->trans("RefPayment").'</td>';
694 print '<td>'.$langs->trans("Date").'</td>';
695 print '<td>'.$langs->trans("Type").'</td>';
696 print '<td>'.$langs->trans("BankAccount").'</td>';
697 print '<td class="right">'.$langs->trans("Insurance").'</td>';
698 print '<td class="right">'.$langs->trans("Interest").'</td>';
699 print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
700 print '</tr>';
701
702 $conf->cache['bankaccount'] = array();
703
704 while ($i < $num) {
705 $objp = $db->fetch_object($resql);
706
707 print '<tr class="oddeven">';
708 print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
709 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
710 print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
711 print "<td>";
712 if (!empty($conf->cache['bankaccount'][$objp->fk_account])) {
713 $tmpbank = $conf->cache['bankaccount'][$objp->fk_account];
714 } else {
715 $tmpbank = new Account($db);
716 $tmpbank->fetch($objp->fk_account);
717 $conf->cache['bankaccount'][$objp->fk_account] = $tmpbank;
718 }
719 print $tmpbank->getNomUrl(1);
720 print "</td>\n";
721 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
722 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
723 print '<td class="nowrap right"><span class="amount">'.price($objp->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
724 print "</tr>";
725 $total_capital += $objp->amount_capital;
726 $i++;
727 }
728
729 $totalpaid = $total_capital;
730
731 if ($object->paid == 0 || $object->paid == 2) {
732 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></tr>';
733 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></tr>';
734
735 $staytopay = $object->capital - $totalpaid;
736
737 print '<tr><td colspan="6" class="right">'.$langs->trans("RemainderToPay").' :</td>';
738 print '<td class="nowrap right'.($staytopay ? ' amountremaintopay' : ' amountpaymentcomplete').'">';
739 print price($staytopay, 0, $langs, 0, -1, -1, $conf->currency);
740 print '</td></tr>';
741 }
742 print "</table>";
743 print '</div>';
744
745 $db->free($resql);
746 } else {
747 dol_print_error($db);
748 }
749
750 print '</div>';
751 print '</div>';
752
753 print '<div class="clearboth"></div>';
754
755 print dol_get_fiche_end();
756
757 if ($action == 'edit') {
758 print $form->buttonsSaveCancel();
759
760 print '</form>';
761 }
762
763 /*
764 * Buttons actions
765 */
766 if ($action != 'edit') {
767 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
768 if (empty($reshook)) {
769 print '<div class="tabsAction">';
770
771 // Edit
772 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'write')) {
773 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>';
774 }
775
776 // Emit payment
777 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')) {
778 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>';
779 }
780
781 // Classify 'paid'
782 if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->hasRight('loan', 'write')) {
783 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>';
784 }
785
786 // Delete
787 if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'delete')) {
788 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
789 }
790
791 print "</div>";
792 }
793 }
794 } else {
795 // Loan not found
796 dol_print_error(null, $object->error);
797 }
798}
799
800// End of page
801llxFooter();
802$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
loan_prepare_head($object)
Prepare array with list of tabs.
Definition loan.lib.php:34
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.