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