dolibarr  20.0.0-alpha
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2014-2023 Alexandre Spangaro <aspangaro@easya.solutions>
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
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
35 
36 if (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 
41 if (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');
58 if ($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
76 if ($reshook < 0) {
77  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78 }
79 if (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;
263 if (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 llxHeader("", $title, $help_url);
270 
271 
272 // Create mode
273 if ($action == 'create') {
274  //WYSIWYG Editor
275  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
276 
277  print load_fiche_titre($langs->trans("NewLoan"), '', 'money-bill-alt');
278 
279  $datec = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
280 
281  print '<form name="loan" method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
282  print '<input type="hidden" name="token" value="'.newToken().'">';
283  print '<input type="hidden" name="action" value="add">';
284 
285  print dol_get_fiche_head();
286 
287  print '<table class="border centpercent">';
288 
289  // Label
290  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>';
291 
292  // Bank account
293  if (isModEnabled("bank")) {
294  print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
295  $form->select_comptes(GETPOST("accountid"), "accountid", 0, "courant=1", 1); // Show list of bank account with courant
296  print '</td></tr>';
297  } else {
298  print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
299  print $langs->trans("NoBankAccountDefined");
300  print '</td></tr>';
301  }
302 
303  // Capital
304  print '<tr><td class="fieldrequired">'.$langs->trans("LoanCapital").'</td><td><input name="capital" size="10" value="'.dol_escape_htmltag(GETPOST("capital")).'"></td></tr>';
305 
306  // Date Start
307  print "<tr>";
308  print '<td class="fieldrequired">'.$langs->trans("DateStart").'</td><td>';
309  print $form->selectDate(!empty($datestart) ? $datestart : -1, 'start', 0, 0, 0, 'add', 1, 1);
310  print '</td></tr>';
311 
312  // Date End
313  print "<tr>";
314  print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td><td>';
315  print $form->selectDate(!empty($dateend) ? $dateend : -1, 'end', 0, 0, 0, 'add', 1, 1);
316  print '</td></tr>';
317 
318  // Number of terms
319  print '<tr><td class="fieldrequired">'.$langs->trans("Nbterms").'</td><td><input name="nbterm" size="5" value="'.dol_escape_htmltag(GETPOST('nbterm')).'"></td></tr>';
320 
321  // Rate
322  print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="'.dol_escape_htmltag(GETPOST("rate")).'"> %</td></tr>';
323 
324  // Insurance amount
325  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>';
326 
327  // Project
328  if (isModEnabled('project')) {
329  $formproject = new FormProjets($db);
330 
331  // Projet associe
332  $langs->loadLangs(array("projects"));
333 
334  print '<tr><td>'.$langs->trans("Project").'</td><td>';
335 
336  $numproject = $formproject->select_projects(-1, $projectid, 'projectid', 16, 0, 1, 1);
337 
338  print '</td></tr>';
339  }
340 
341  // Note Private
342  print '<tr>';
343  print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
344  print '<td>';
345 
346  $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%');
347  print $doleditor->Create(1);
348 
349  print '</td></tr>';
350 
351  // Note Public
352  print '<tr>';
353  print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
354  print '<td>';
355  $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%');
356  print $doleditor->Create(1);
357  print '</td></tr>';
358 
359  // Accountancy
360  if (isModEnabled('accounting')) {
361  // Accountancy_account_capital
362  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
363  print '<td>';
364  print $formaccounting->select_account(GETPOST('accountancy_account_capital') ? GETPOST('accountancy_account_capital') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_CAPITAL'), 'accountancy_account_capital', 1, '', 1, 1);
365  print '</td></tr>';
366 
367  // Accountancy_account_insurance
368  print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
369  print '<td>';
370  print $formaccounting->select_account(GETPOST('accountancy_account_insurance') ? GETPOST('accountancy_account_insurance') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INSURANCE'), 'accountancy_account_insurance', 1, '', 1, 1);
371  print '</td></tr>';
372 
373  // Accountancy_account_interest
374  print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
375  print '<td>';
376  print $formaccounting->select_account(GETPOST('accountancy_account_interest') ? GETPOST('accountancy_account_interest') : getDolGlobalString('LOAN_ACCOUNTING_ACCOUNT_INTEREST'), 'accountancy_account_interest', 1, '', 1, 1);
377  print '</td></tr>';
378  } else {
379  // For external software
380  // Accountancy_account_capital
381  print '<tr><td class="titlefieldcreate">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
382  print '<td><input name="accountancy_account_capital" size="16" value="'.$object->accountancy_account_capital.'">';
383  print '</td></tr>';
384 
385  // Accountancy_account_insurance
386  print '<tr><td>'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
387  print '<td><input name="accountancy_account_insurance" size="16" value="'.$object->accountancy_account_insurance.'">';
388  print '</td></tr>';
389 
390  // Accountancy_account_interest
391  print '<tr><td>'.$langs->trans("LoanAccountancyInterestCode").'</td>';
392  print '<td><input name="accountancy_account_interest" size="16" value="'.$object->accountancy_account_interest.'">';
393  print '</td></tr>';
394  }
395  print '</table>';
396 
397  print dol_get_fiche_end();
398 
399  print $form->buttonsSaveCancel("Add");
400 
401  print '</form>';
402 }
403 
404 // View
405 if ($id > 0) {
406  $object = new Loan($db);
407  $result = $object->fetch($id);
408 
409  if ($result > 0) {
410  $head = loan_prepare_head($object);
411 
412  $totalpaid = $object->getSumPayment();
413 
414  // Confirm for loan
415  if ($action == 'paid') {
416  $text = $langs->trans('ConfirmPayLoan');
417  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayLoan'), $text, "confirm_paid", '', '', 2);
418  }
419 
420  if ($action == 'delete') {
421  $text = $langs->trans('ConfirmDeleteLoan');
422  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteLoan'), $text, 'confirm_delete', '', '', 2);
423  }
424 
425  if ($action == 'edit') {
426  print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
427  print '<input type="hidden" name="token" value="'.newToken().'">';
428  print '<input type="hidden" name="action" value="update">';
429  print '<input type="hidden" name="id" value="'.$id.'">';
430  }
431 
432  print dol_get_fiche_head($head, 'card', $langs->trans("Loan"), -1, 'money-bill-alt', 0, '', '', 0, '', 1);
433 
434  // Loan card
435  $linkback = '<a href="'.DOL_URL_ROOT.'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
436 
437  $morehtmlref = '<div class="refidno">';
438  // Ref loan
439  $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', 0, 1);
440  $morehtmlref .= $form->editfieldval("Label", 'label', $object->label, $object, $user->hasRight('loan', 'write'), 'string', '', null, null, '', 1);
441  // Project
442  if (isModEnabled('project')) {
443  $langs->loadLangs(array("projects"));
444  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
445  if ($user->hasRight('loan', 'write')) {
446  if ($action != 'classify') {
447  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
448  }
449  if ($action == 'classify') {
450  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
451  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
452  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
453  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
454  $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
455  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
456  $morehtmlref .= '</form>';
457  } else {
458  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
459  }
460  } else {
461  if (!empty($object->fk_project)) {
462  $proj = new Project($db);
463  $proj->fetch($object->fk_project);
464  $morehtmlref .= ' : '.$proj->getNomUrl(1);
465  if ($proj->title) {
466  $morehtmlref .= ' - '.$proj->title;
467  }
468  } else {
469  $morehtmlref .= '';
470  }
471  }
472  }
473  $morehtmlref .= '</div>';
474 
475  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
476 
477  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
478 
479  print '<div class="fichecenter">';
480  print '<div class="fichehalfleft">';
481  print '<div class="underbanner clearboth"></div>';
482 
483  print '<table class="border centpercent tableforfield">';
484 
485  // Capital
486  if ($action == 'edit') {
487  print '<tr><td class="fieldrequired titlefield">'.$langs->trans("LoanCapital").'</td><td>';
488  print '<input name="capital" size="10" value="'.$object->capital.'"></td></tr>';
489  print '</td></tr>';
490  } else {
491  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>';
492  }
493 
494  // Insurance
495  if ($action == 'edit') {
496  print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>';
497  print '<input name="insurance_amount" size="10" value="'.$object->insurance_amount.'"></td></tr>';
498  print '</td></tr>';
499  } else {
500  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>';
501  }
502 
503  // Date start
504  print '<tr><td>'.$langs->trans("DateStart")."</td>";
505  print "<td>";
506  if ($action == 'edit') {
507  print $form->selectDate($object->datestart, 'start', 0, 0, 0, 'update', 1, 0);
508  } else {
509  print dol_print_date($object->datestart, "day");
510  }
511  print "</td></tr>";
512 
513  // Date end
514  print '<tr><td>'.$langs->trans("DateEnd")."</td>";
515  print "<td>";
516  if ($action == 'edit') {
517  print $form->selectDate($object->dateend, 'end', 0, 0, 0, 'update', 1, 0);
518  } else {
519  print dol_print_date($object->dateend, "day");
520  }
521  print "</td></tr>";
522 
523  // Nbterms
524  print '<tr><td>'.$langs->trans("Nbterms").'</td>';
525  print '<td>';
526  if ($action == 'edit') {
527  print '<input name="nbterm" size="4" value="'.$object->nbterm.'">';
528  } else {
529  print $object->nbterm;
530  }
531  print '</td></tr>';
532 
533  // Rate
534  print '<tr><td>'.$langs->trans("Rate").'</td>';
535  print '<td>';
536  if ($action == 'edit') {
537  print '<input name="rate" size="4" value="'.$object->rate.'">%';
538  } else {
539  print price($object->rate).'%';
540  }
541  print '</td></tr>';
542 
543  // Accountancy account capital
544  print '<tr>';
545  if ($action == 'edit') {
546  print '<td class="nowrap fieldrequired">';
547  print $langs->trans("LoanAccountancyCapitalCode");
548  print '</td><td>';
549 
550  if (isModEnabled('accounting')) {
551  print $formaccounting->select_account($object->account_capital, 'accountancy_account_capital', 1, '', 1, 1);
552  } else {
553  print '<input name="accountancy_account_capital" size="16" value="'.$object->account_capital.'">';
554  }
555  print '</td>';
556  } else {
557  print '<td class="nowrap">';
558  print $langs->trans("LoanAccountancyCapitalCode");
559  print '</td><td>';
560 
561  if (isModEnabled('accounting')) {
562  $accountingaccount = new AccountingAccount($db);
563  $accountingaccount->fetch('', $object->account_capital, 1);
564 
565  print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
566  } else {
567  print $object->account_capital;
568  }
569 
570  print '</td>';
571  }
572  print '</tr>';
573 
574  // Accountancy account insurance
575  print '<tr>';
576  if ($action == 'edit') {
577  print '<td class="nowrap fieldrequired">';
578  print $langs->trans("LoanAccountancyInsuranceCode");
579  print '</td><td>';
580 
581  if (isModEnabled('accounting')) {
582  print $formaccounting->select_account($object->account_insurance, 'accountancy_account_insurance', 1, '', 1, 1);
583  } else {
584  print '<input name="accountancy_account_insurance" size="16" value="'.$object->account_insurance.'">';
585  }
586  print '</td>';
587  } else {
588  print '<td class="nowrap">';
589  print $langs->trans("LoanAccountancyInsuranceCode");
590  print '</td><td>';
591 
592  if (isModEnabled('accounting')) {
593  $accountingaccount = new AccountingAccount($db);
594  $accountingaccount->fetch('', $object->account_insurance, 1);
595 
596  print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
597  } else {
598  print $object->account_insurance;
599  }
600 
601  print '</td>';
602  }
603  print '</tr>';
604 
605  // Accountancy account interest
606  print '<tr>';
607  if ($action == 'edit') {
608  print '<td class="nowrap fieldrequired">';
609  print $langs->trans("LoanAccountancyInterestCode");
610  print '</td><td>';
611 
612  if (isModEnabled('accounting')) {
613  print $formaccounting->select_account($object->account_interest, 'accountancy_account_interest', 1, '', 1, 1);
614  } else {
615  print '<input name="accountancy_account_interest" size="16" value="'.$object->account_interest.'">';
616  }
617  print '</td>';
618  } else {
619  print '<td class="nowrap">';
620  print $langs->trans("LoanAccountancyInterestCode");
621  print '</td><td>';
622 
623  if (isModEnabled('accounting')) {
624  $accountingaccount = new AccountingAccount($db);
625  $accountingaccount->fetch('', $object->account_interest, 1);
626 
627  print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
628  } else {
629  print $object->account_interest;
630  }
631 
632  print '</td>';
633  }
634  print '</tr>';
635 
636  // Other attributes
637  $parameters = array();
638  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
639  print $hookmanager->resPrint;
640 
641  print '</table>';
642 
643  print '</div>';
644  print '<div class="fichehalfright">';
645 
646  /*
647  * Payments
648  */
649  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp,";
650  $sql .= " p.amount_capital, p.amount_insurance, p.amount_interest,";
651  $sql .= " b.fk_account,";
652  $sql .= " c.libelle as paiement_type";
653  $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as p";
654  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
655  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id,";
656  $sql .= " ".MAIN_DB_PREFIX."loan as l";
657  $sql .= " WHERE p.fk_loan = ".((int) $id);
658  $sql .= " AND p.fk_loan = l.rowid";
659  $sql .= " AND l.entity IN ( ".getEntity('loan').")";
660  $sql .= " ORDER BY dp DESC";
661 
662  //print $sql;
663  $resql = $db->query($sql);
664  if ($resql) {
665  $num = $db->num_rows($resql);
666  $i = 0;
667  $total_insurance = 0;
668  $total_interest = 0;
669  $total_capital = 0;
670 
671  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
672  print '<table class="noborder paymenttable">';
673  print '<tr class="liste_titre">';
674  print '<td>'.$langs->trans("RefPayment").'</td>';
675  print '<td>'.$langs->trans("Date").'</td>';
676  print '<td>'.$langs->trans("Type").'</td>';
677  print '<td>'.$langs->trans("BankAccount").'</td>';
678  print '<td class="right">'.$langs->trans("Insurance").'</td>';
679  print '<td class="right">'.$langs->trans("Interest").'</td>';
680  print '<td class="right">'.$langs->trans("LoanCapital").'</td>';
681  print '</tr>';
682 
683  $conf->cache['bankaccount'] = array();
684 
685  while ($i < $num) {
686  $objp = $db->fetch_object($resql);
687 
688  print '<tr class="oddeven">';
689  print '<td><a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
690  print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
691  print "<td>".$objp->paiement_type.' '.$objp->num_payment."</td>\n";
692  print "<td>";
693  if (!empty($conf->cache['bankaccount'][$objp->fk_account])) {
694  $tmpbank = $conf->cache['bankaccount'][$objp->fk_account];
695  } else {
696  $tmpbank = new Account($db);
697  $tmpbank->fetch($objp->fk_account);
698  $conf->cache['bankaccount'][$objp->fk_account] = $tmpbank;
699  }
700  print $tmpbank->getNomUrl(1);
701  print "</td>\n";
702  print '<td class="nowrap right"><span class="amount">'.price($objp->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
703  print '<td class="nowrap right"><span class="amount">'.price($objp->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
704  print '<td class="nowrap right"><span class="amount">'.price($objp->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency)."</span></td>\n";
705  print "</tr>";
706  $total_capital += $objp->amount_capital;
707  $i++;
708  }
709 
710  $totalpaid = $total_capital;
711 
712  if ($object->paid == 0 || $object->paid == 2) {
713  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>';
714  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>';
715 
716  $staytopay = $object->capital - $totalpaid;
717 
718  print '<tr><td colspan="6" class="right">'.$langs->trans("RemainderToPay").' :</td>';
719  print '<td class="nowrap right'.($staytopay ? ' amountremaintopay' : ' amountpaymentcomplete').'">';
720  print price($staytopay, 0, $langs, 0, -1, -1, $conf->currency);
721  print '</td></tr>';
722  }
723  print "</table>";
724  print '</div>';
725 
726  $db->free($resql);
727  } else {
728  dol_print_error($db);
729  }
730 
731  print '</div>';
732  print '</div>';
733 
734  print '<div class="clearboth"></div>';
735 
736  print dol_get_fiche_end();
737 
738  if ($action == 'edit') {
739  print $form->buttonsSaveCancel();
740 
741  print '</form>';
742  }
743 
744  /*
745  * Buttons actions
746  */
747  if ($action != 'edit') {
748  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
749  if (empty($reshook)) {
750  print '<div class="tabsAction">';
751 
752  // Edit
753  if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'write')) {
754  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>';
755  }
756 
757  // Emit payment
758  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')) {
759  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>';
760  }
761 
762  // Classify 'paid'
763  if (($object->paid == 0 || $object->paid == 2) && round($staytopay) <= 0 && $user->hasRight('loan', 'write')) {
764  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>';
765  }
766 
767  // Delete
768  if (($object->paid == 0 || $object->paid == 2) && $user->hasRight('loan', 'delete')) {
769  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>';
770  }
771 
772  print "</div>";
773  }
774  }
775  } else {
776  // Loan not found
777  dol_print_error(null, $object->error);
778  }
779 }
780 
781 // End of page
782 llxFooter();
783 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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.
Definition: loan.class.php:31
Class to manage projects.
$parameters
Actions.
Definition: card.php:84
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.