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