dolibarr  18.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
4  * Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
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.'/core/lib/bank.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
36 if (isModEnabled('project')) {
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 
41 // Load translation files required by the page
42 $langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy", "categories"));
43 
44 // Get parameters
45 $id = GETPOST('id', 'int');
46 $action = GETPOST('action', 'alpha');
47 $confirm = GETPOST('confirm');
48 $cancel = GETPOST('cancel', 'aZ09');
49 $backtopage = GETPOST('backtopage', 'alpha');
50 
51 $accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0;
52 $label = GETPOST("label", "alpha");
53 $sens = GETPOST("sens", "int");
54 $amount = price2num(GETPOST("amount", "alpha"));
55 $paymenttype = GETPOST("paymenttype", "aZ09");
56 $accountancy_code = GETPOST("accountancy_code", "alpha");
57 $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
58 if (isModEnabled('accounting') && !empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
59  $subledger_account = GETPOST("subledger_account", "alpha") > 0 ? GETPOST("subledger_account", "alpha") : '';
60 } else {
61  $subledger_account = GETPOST("subledger_account", "alpha");
62 }
63 
64 // Security check
65 $socid = GETPOST("socid", "int");
66 if ($user->socid) {
67  $socid = $user->socid;
68 }
69 $result = restrictedArea($user, 'banque', '', '', '');
70 
71 $object = new PaymentVarious($db);
72 
73 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
74 $hookmanager->initHooks(array('variouscard', 'globalcard'));
75 
76 $permissiontoadd = $user->hasRight('banque', 'modifier');
77 
78 
83 $parameters = array();
84 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
85 if ($reshook < 0) {
86  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87 }
88 
89 if (empty($reshook)) {
90  if ($cancel) {
91  if ($action != 'addlink' && $action != 'setaccountancy_code' && $action != 'setsubledger_account') {
92  $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
93  header("Location: ".$urltogo);
94  exit;
95  }
96  if ($id > 0 || !empty($ref)) {
97  $ret = $object->fetch($id, $ref);
98  }
99  $action = '';
100  }
101 
102  // Link to a project
103  if ($action == 'classin' && $permissiontoadd) {
104  $object->fetch($id);
105  $object->setProject(GETPOST('projectid', 'int'));
106  }
107 
108  if ($action == 'add') {
109  $error = 0;
110 
111  $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
112  $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
113  if (empty($datev)) {
114  $datev = $datep;
115  }
116 
117  $object->ref = ''; // TODO
118  $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
119  $object->datev = $datev;
120  $object->datep = $datep;
121  $object->amount = price2num(GETPOST("amount", 'alpha'));
122  $object->label = GETPOST("label", 'restricthtml');
123  $object->note = GETPOST("note", 'restricthtml');
124  $object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1);
125  $object->num_payment = GETPOST("num_payment", 'alpha');
126  $object->chqemetteur = GETPOST("chqemetteur", 'alpha');
127  $object->chqbank = GETPOST("chqbank", 'alpha');
128  $object->fk_user_author = $user->id;
129  $object->category_transaction = GETPOST("category_transaction", 'alpha');
130 
131  $object->accountancy_code = GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code", "alpha") : "";
132  $object->subledger_account = $subledger_account;
133 
134  $object->sens = GETPOSTINT('sens');
135  $object->fk_project = GETPOSTINT('fk_project');
136 
137  if (empty($datep) || empty($datev)) {
138  $langs->load('errors');
139  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
140  $error++;
141  }
142  if (empty($object->amount)) {
143  $langs->load('errors');
144  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
145  $error++;
146  }
147  if (isModEnabled("banque") && !$object->accountid > 0) {
148  $langs->load('errors');
149  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
150  $error++;
151  }
152  if (empty($object->type_payment) || $object->type_payment < 0) {
153  $langs->load('errors');
154  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
155  $error++;
156  }
157  if (isModEnabled('accounting') && !$object->accountancy_code) {
158  $langs->load('errors');
159  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
160  $error++;
161  }
162  if ($object->sens < 0) {
163  $langs->load('errors');
164  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
165  $error++;
166  }
167 
168  if (!$error) {
169  $db->begin();
170 
171  $ret = $object->create($user);
172  if ($ret > 0) {
173  $db->commit();
174  $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
175  header("Location: ".$urltogo);
176  exit;
177  } else {
178  $db->rollback();
179  setEventMessages($object->error, $object->errors, 'errors');
180  $action = "create";
181  }
182  }
183 
184  $action = 'create';
185  }
186 
187  if ($action == 'confirm_delete' && $confirm == 'yes') {
188  $result = $object->fetch($id);
189 
190  if ($object->rappro == 0) {
191  $db->begin();
192 
193  $ret = $object->delete($user);
194  if ($ret > 0) {
195  if ($object->fk_bank) {
196  $accountline = new AccountLine($db);
197  $result = $accountline->fetch($object->fk_bank);
198  if ($result > 0) {
199  $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
200  }
201  }
202 
203  if ($result >= 0) {
204  $db->commit();
205  header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
206  exit;
207  } else {
208  $object->error = $accountline->error;
209  $db->rollback();
210  setEventMessages($object->error, $object->errors, 'errors');
211  }
212  } else {
213  $db->rollback();
214  setEventMessages($object->error, $object->errors, 'errors');
215  }
216  } else {
217  setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
218  }
219  }
220 
221  if ($action == 'setaccountancy_code') {
222  $db->begin();
223 
224  $result = $object->fetch($id);
225 
226  $object->accountancy_code = GETPOST('accountancy_code', 'alpha');
227 
228  $res = $object->update($user);
229  if ($res > 0) {
230  $db->commit();
231  } else {
232  $db->rollback();
233  setEventMessages($object->error, $object->errors, 'errors');
234  }
235  }
236 
237  if ($action == 'setsubledger_account') {
238  $db->begin();
239 
240  $result = $object->fetch($id);
241 
242  $object->subledger_account = $subledger_account;
243 
244  $res = $object->update($user);
245  if ($res > 0) {
246  $db->commit();
247  } else {
248  $db->rollback();
249  setEventMessages($object->error, $object->errors, 'errors');
250  }
251  }
252 }
253 
254 // Action clone object
255 if ($action == 'confirm_clone' && $confirm != 'yes') {
256  $action = '';
257 }
258 
259 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
260  $db->begin();
261 
262  $originalId = $id;
263 
264  $object->fetch($id);
265 
266  if ($object->id > 0) {
267  $object->id = $object->ref = null;
268 
269  if (GETPOST('clone_label', 'alphanohtml')) {
270  $object->label = GETPOST('clone_label', 'alphanohtml');
271  } else {
272  $object->label = $langs->trans("CopyOf").' '.$object->label;
273  }
274 
275  $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int'));
276  $newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int'));
277  if ($newdatepayment) {
278  $object->datep = $newdatepayment;
279  }
280  if (!empty($newdatevalue)) {
281  $object->datev = $newdatevalue;
282  } else {
283  $object->datev = $newdatepayment;
284  }
285 
286  if (GETPOSTISSET("clone_sens")) {
287  $object->sens = GETPOST("clone_sens", 'int');
288  } else {
289  $object->sens = $object->sens;
290  }
291 
292  if (GETPOST("clone_amount", "alpha")) {
293  $object->amount = price2num(GETPOST("clone_amount", "alpha"));
294  } else {
295  $object->amount = price2num($object->amount);
296  }
297 
298  if ($object->check()) {
299  $id = $object->create($user);
300  if ($id > 0) {
301  $db->commit();
302  $db->close();
303 
304  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
305  exit;
306  } else {
307  $id = $originalId;
308  $db->rollback();
309 
310  setEventMessages($object->error, $object->errors, 'errors');
311  }
312  } else {
313  $id = $originalId;
314  $db->rollback();
315 
316  setEventMessages($object->error, $object->errors, 'errors');
317  }
318  } else {
319  $db->rollback();
320  dol_print_error($db, $object->error);
321  }
322 }
323 
324 
325 /*
326  * View
327  */
328 $form = new Form($db);
329 if (isModEnabled('accounting')) {
330  $formaccounting = new FormAccounting($db);
331 }
332 if (isModEnabled('project')) {
333  $formproject = new FormProjets($db);
334 }
335 
336 if ($id) {
337  $object = new PaymentVarious($db);
338  $result = $object->fetch($id);
339  if ($result <= 0) {
340  dol_print_error($db);
341  exit;
342  }
343 }
344 
345 $title = $object->ref." - ".$langs->trans('Card');
346 if ($action == 'create') {
347  $title = $langs->trans("NewVariousPayment");
348 }
349 $help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
350 llxHeader('', $title, $help_url);
351 
352 $options = array();
353 
354 // Load bank groups
355 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
356 $bankcateg = new BankCateg($db);
357 
358 foreach ($bankcateg->fetchAll() as $bankcategory) {
359  $options[$bankcategory->id] = $bankcategory->label;
360 }
361 
362 // Create mode
363 if ($action == 'create') {
364  // Update fields properties in realtime
365  if (!empty($conf->use_javascript_ajax)) {
366  print "\n".'<script type="text/javascript">';
367  print '$(document).ready(function () {
368  setPaymentType();
369  $("#selectpaymenttype").change(function() {
370  setPaymentType();
371  });
372  function setPaymentType()
373  {
374  console.log("setPaymentType");
375  var code = $("#selectpaymenttype option:selected").val();
376  if (code == \'CHQ\' || code == \'VIR\')
377  {
378  if (code == \'CHQ\')
379  {
380  $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
381  }
382  if ($(\'#fieldchqemetteur\').val() == \'\')
383  {
384  var emetteur = jQuery(\'#thirdpartylabel\').val();
385  $(\'#fieldchqemetteur\').val(emetteur);
386  }
387  }
388  else
389  {
390  $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
391  $(\'#fieldchqemetteur\').val(\'\');
392  }
393  }
394  ';
395 
396  print ' });'."\n";
397 
398  print ' </script>'."\n";
399  }
400 
401  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
402  print '<input type="hidden" name="token" value="'.newToken().'">';
403  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
404  print '<input type="hidden" name="action" value="add">';
405 
406  print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
407 
408  print dol_get_fiche_head('', '');
409 
410  print '<table class="border centpercent">';
411 
412  // Date payment
413  print '<tr><td class="titlefieldcreate">';
414  print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
415  print $form->selectDate((empty($datep) ?-1 : $datep), "datep", '', '', '', 'add', 1, 1);
416  print '</td></tr>';
417 
418  // Date value for bank
419  print '<tr><td>';
420  print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
421  print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
422  print '</td></tr>';
423 
424  // Label
425  print '<tr><td>';
426  print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
427  print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
428  print '</td></tr>';
429 
430  // Amount
431  print '<tr><td>';
432  print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
433  print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
434  print '</td></tr>';
435 
436  // Bank
437  if (isModEnabled("banque")) {
438  print '<tr><td>';
439  print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
440  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
441  print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants)
442  print '</td></tr>';
443  }
444 
445  // Type payment
446  print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
447  $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
448  print "</td>\n";
449  print '</tr>';
450 
451  // Number
452  if (isModEnabled("banque")) {
453  print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
454  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
455  print '</label></td>';
456  print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
457 
458  // Check transmitter
459  print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
460  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
461  print '</label></td>';
462  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
463 
464  // Bank name
465  print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
466  print ' <em>('.$langs->trans("ChequeBank").')</em>';
467  print '</label></td>';
468  print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
469  }
470 
471  // Accountancy account
472  if (isModEnabled('accounting')) {
473  // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
474  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
475  print '<td>';
476  print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1);
477  print '</td></tr>';
478  } else { // For external software
479  print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
480  print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
481  print '</td></tr>';
482  }
483 
484  // Subledger account
485  if (isModEnabled('accounting')) {
486  print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
487  print '<td>';
488  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
489  print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
490  } else {
491  print '<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
492  }
493  print '</td></tr>';
494  } else { // For external software
495  print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
496  print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
497  print '</td></tr>';
498  }
499 
500  // Sens
501  print '<tr><td>';
502  $labelsens = $form->textwithpicto($langs->trans('Sens'), $langs->trans("AccountingDirectionHelp"));
503  print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
504  $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
505  print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
506  print '</td></tr>';
507 
508  // Project
509  if (isModEnabled('project')) {
510  $formproject = new FormProjets($db);
511 
512  // Associated project
513  $langs->load("projects");
514 
515  print '<tr><td>'.$langs->trans("Project").'</td><td>';
516  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
517  print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
518  print '</td></tr>';
519  }
520 
521  // Other attributes
522  $parameters = array();
523  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
524  print $hookmanager->resPrint;
525 
526  // Category
527  if (is_array($options) && count($options) && $conf->categorie->enabled) {
528  print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
529  print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
530  print '</td></tr>';
531  }
532 
533  print '</table>';
534 
535  print dol_get_fiche_end();
536 
537  print $form->buttonsSaveCancel();
538 
539  print '</form>';
540 }
541 
542 
543 /* ************************************************************************** */
544 /* */
545 /* View mode */
546 /* */
547 /* ************************************************************************** */
548 
549 if ($id) {
550  $alreadyaccounted = $object->getVentilExportCompta();
551 
552  $head = various_payment_prepare_head($object);
553 
554  // Clone confirmation
555  if ($action === 'clone') {
556  $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
557  $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
558 
559  $formquestion = array(
560  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
561  array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
562  array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
563  array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'clone_accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($object->fk_account, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)),
564  array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
565  array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => $object->sens),
566  );
567 
568  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
569  }
570 
571  // Confirmation of the removal of the Various Payment
572  if ($action == 'delete') {
573  $text = $langs->trans('ConfirmDeleteVariousPayment');
574  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
575  }
576 
577  print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
578 
579  $morehtmlref = '<div class="refidno">';
580  // Project
581  if (isModEnabled('project')) {
582  $langs->load("projects");
583  //$morehtmlref .= '<br>';
584  if ($permissiontoadd) {
585  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
586  if ($action != 'classify') {
587  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
588  }
589  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
590  } else {
591  if (!empty($object->fk_project)) {
592  $proj = new Project($db);
593  $proj->fetch($object->fk_project);
594  $morehtmlref .= $proj->getNomUrl(1);
595  if ($proj->title) {
596  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
597  }
598  }
599  }
600  }
601 
602  $morehtmlref .= '</div>';
603  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
604 
605  $morehtmlright = '';
606 
607  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
608 
609  print '<div class="fichecenter">';
610  print '<div class="underbanner clearboth"></div>';
611 
612  print '<table class="border centpercent tableforfield">';
613 
614  // Label
615  print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
616 
617  // Payment date
618  print "<tr>";
619  print '<td>'.$langs->trans("DatePayment").'</td><td>';
620  print dol_print_date($object->datep, 'day');
621  print '</td></tr>';
622 
623  // Value date
624  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
625  print dol_print_date($object->datev, 'day');
626  print '</td></tr>';
627 
628  // Debit / Credit
629  if ($object->sens == '1') {
630  $sens = $langs->trans("Credit");
631  } else {
632  $sens = $langs->trans("Debit");
633  }
634  print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
635 
636  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
637 
638  // Account of Chart of account
639  $editvalue = '';
640  if (isModEnabled('accounting')) {
641  $editvalue = $formaccounting->select_account($object->accountancy_code, 'accountancy_code', 1, null, 1, 1);
642  }
643 
644  print '</td></tr>';
645  print '<tr><td class="nowrap">';
646  print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
647  print '</td><td>';
648  print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $permissiontoadd), 'asis', $editvalue, 0, null, '', 1, 'lengthAccountg');
649  print '</td></tr>';
650 
651  // Subledger account
652  print '<tr><td class="nowrap">';
653  print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
654  print '</td><td>';
655  print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', 0, null, '', 1, 'lengthAccounta');
656  print '</td></tr>';
657 
658  $bankaccountnotfound = 0;
659 
660  if (isModEnabled('banque')) {
661  print '<tr>';
662  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
663  print '<td colspan="3">';
664  if ($object->fk_bank > 0) {
665  $bankline = new AccountLine($db);
666  $result = $bankline->fetch($object->fk_bank);
667 
668  if ($result <= 0) {
669  $bankaccountnotfound = 1;
670  } else {
671  print $bankline->getNomUrl(1, 0, 'showall');
672  }
673  } else {
674  $bankaccountnotfound = 1;
675 
676  print '<span class="opacitymedium">'.$langs->trans("NoRecordfound").'</span>';
677  }
678  print '</td>';
679  print '</tr>';
680  }
681 
682  // Other attributes
683  $parameters = array('socid'=>$object->id);
684  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
685 
686  print '</table>';
687 
688  print '</div>';
689 
690  print '<div class="clearboth"></div>';
691 
692  print dol_get_fiche_end();
693 
694 
695  /*
696  * Action bar
697  */
698  print '<div class="tabsAction">'."\n";
699 
700  // TODO
701  // Add button modify
702 
703  // Clone
704  if ($permissiontoadd) {
705  print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/bank/various_payment/card.php", 1).'?id='.$object->id.'&amp;action=clone">'.$langs->trans("ToClone")."</a></div>";
706  }
707 
708  // Delete
709  if (empty($object->rappro) || $bankaccountnotfound) {
710  if ($permissiontoadd) {
711  if ($alreadyaccounted) {
712  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
713  } else {
714  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
715  }
716  } else {
717  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
718  }
719  } else {
720  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
721  }
722 
723  print "</div>";
724 }
725 
726 // End of page
727 llxFooter();
728 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:36
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
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:609
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:5107
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1158
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:143
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
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:2205
$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:118
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5955
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:2675
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
PaymentVarious
Class to manage various payments.
Definition: paymentvarious.class.php:32
llxHeader
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
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:9091
BankCateg
Class to manage bank categories.
Definition: bankcateg.class.php:29
GETPOSTINT
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:926
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
restrictedArea
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.
Definition: security.lib.php:353
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
Definition: functions.lib.php:1979
various_payment_prepare_head
various_payment_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:232
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
$parameters
$parameters
Actions.
Definition: card.php:83
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1880
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:5829
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:2968