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