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