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