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