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