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