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