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