dolibarr  17.0.4
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 == 'setaccountancy_code') {
218  $db->begin();
219 
220  $result = $object->fetch($id);
221 
222  $object->accountancy_code = GETPOST('accountancy_code', 'alphanohtml');
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  if ($action == 'setsubledger_account') {
234  $db->begin();
235 
236  $result = $object->fetch($id);
237 
238  $object->subledger_account = $subledger_account;
239 
240  $res = $object->update($user);
241  if ($res > 0) {
242  $db->commit();
243  } else {
244  $db->rollback();
245  setEventMessages($object->error, $object->errors, 'errors');
246  }
247  }
248 }
249 
250 // Action clone object
251 if ($action == 'confirm_clone' && $confirm != 'yes') {
252  $action = '';
253 }
254 
255 if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier)) {
256  $db->begin();
257 
258  $originalId = $id;
259 
260  $object->fetch($id);
261 
262  if ($object->id > 0) {
263  $object->id = $object->ref = null;
264 
265  if (GETPOST('clone_label', 'alphanohtml')) {
266  $object->label = GETPOST('clone_label', 'alphanohtml');
267  } else {
268  $object->label = $langs->trans("CopyOf").' '.$object->label;
269  }
270 
271  $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int'));
272  $newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int'));
273  if ($newdatepayment) {
274  $object->datep = $newdatepayment;
275  }
276  if (!empty($newdatevalue)) {
277  $object->datev = $newdatevalue;
278  } else {
279  $object->datev = $newdatepayment;
280  }
281 
282  if (GETPOSTISSET("clone_sens")) {
283  $object->sens = GETPOST("clone_sens", 'int');
284  } else {
285  $object->sens = $object->sens;
286  }
287 
288  if (GETPOST("clone_amount", "alpha")) {
289  $object->amount = price2num(GETPOST("clone_amount", "alpha"));
290  } else {
291  $object->amount = price2num($object->amount);
292  }
293 
294  if ($object->check()) {
295  $id = $object->create($user);
296  if ($id > 0) {
297  $db->commit();
298  $db->close();
299 
300  header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
301  exit;
302  } else {
303  $id = $originalId;
304  $db->rollback();
305 
306  setEventMessages($object->error, $object->errors, 'errors');
307  }
308  } else {
309  $id = $originalId;
310  $db->rollback();
311 
312  setEventMessages($object->error, $object->errors, 'errors');
313  }
314  } else {
315  $db->rollback();
316  dol_print_error($db, $object->error);
317  }
318 }
319 
320 
321 /*
322  * View
323  */
324 $form = new Form($db);
325 if (isModEnabled('accounting')) {
326  $formaccounting = new FormAccounting($db);
327 }
328 if (isModEnabled('project')) {
329  $formproject = new FormProjets($db);
330 }
331 
332 if ($id) {
333  $object = new PaymentVarious($db);
334  $result = $object->fetch($id);
335  if ($result <= 0) {
336  dol_print_error($db);
337  exit;
338  }
339 }
340 
341 $title = $object->ref." - ".$langs->trans('Card');
342 if ($action == 'create') {
343  $title = $langs->trans("NewVariousPayment");
344 }
345 $help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
346 llxHeader('', $title, $help_url);
347 
348 $options = array();
349 
350 // Load bank groups
351 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
352 $bankcateg = new BankCateg($db);
353 
354 foreach ($bankcateg->fetchAll() as $bankcategory) {
355  $options[$bankcategory->id] = $bankcategory->label;
356 }
357 
358 // Create mode
359 if ($action == 'create') {
360  // Update fields properties in realtime
361  if (!empty($conf->use_javascript_ajax)) {
362  print "\n".'<script type="text/javascript">';
363  print '$(document).ready(function () {
364  setPaymentType();
365  $("#selectpaymenttype").change(function() {
366  setPaymentType();
367  });
368  function setPaymentType()
369  {
370  console.log("setPaymentType");
371  var code = $("#selectpaymenttype option:selected").val();
372  if (code == \'CHQ\' || code == \'VIR\')
373  {
374  if (code == \'CHQ\')
375  {
376  $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
377  }
378  if ($(\'#fieldchqemetteur\').val() == \'\')
379  {
380  var emetteur = jQuery(\'#thirdpartylabel\').val();
381  $(\'#fieldchqemetteur\').val(emetteur);
382  }
383  }
384  else
385  {
386  $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
387  $(\'#fieldchqemetteur\').val(\'\');
388  }
389  }
390  ';
391 
392  print ' });'."\n";
393 
394  print ' </script>'."\n";
395  }
396 
397  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
398  print '<input type="hidden" name="token" value="'.newToken().'">';
399  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
400  print '<input type="hidden" name="action" value="add">';
401 
402  print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
403 
404  print dol_get_fiche_head('', '');
405 
406  print '<table class="border centpercent">';
407 
408  // Date payment
409  print '<tr><td class="titlefieldcreate">';
410  print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
411  print $form->selectDate((empty($datep) ?-1 : $datep), "datep", '', '', '', 'add', 1, 1);
412  print '</td></tr>';
413 
414  // Date value for bank
415  print '<tr><td>';
416  print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
417  print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
418  print '</td></tr>';
419 
420  // Label
421  print '<tr><td>';
422  print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
423  print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
424  print '</td></tr>';
425 
426  // Amount
427  print '<tr><td>';
428  print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
429  print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
430  print '</td></tr>';
431 
432  // Bank
433  if (isModEnabled("banque")) {
434  print '<tr><td>';
435  print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
436  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
437  print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants)
438  print '</td></tr>';
439  }
440 
441  // Type payment
442  print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
443  $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
444  print "</td>\n";
445  print '</tr>';
446 
447  // Number
448  if (isModEnabled("banque")) {
449  print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
450  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
451  print '</label></td>';
452  print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
453 
454  // Check transmitter
455  print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
456  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
457  print '</label></td>';
458  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
459 
460  // Bank name
461  print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
462  print ' <em>('.$langs->trans("ChequeBank").')</em>';
463  print '</label></td>';
464  print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
465  }
466 
467  // Accountancy account
468  if (isModEnabled('accounting')) {
469  // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
470  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
471  print '<td>';
472  print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1);
473  print '</td></tr>';
474  } else { // For external software
475  print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
476  print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
477  print '</td></tr>';
478  }
479 
480  // Subledger account
481  if (isModEnabled('accounting')) {
482  print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
483  print '<td>';
484  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
485  print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
486  } else {
487  print '<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
488  }
489  print '</td></tr>';
490  } else { // For external software
491  print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
492  print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
493  print '</td></tr>';
494  }
495 
496  // Sens
497  print '<tr><td>';
498  $labelsens = $form->textwithpicto('Sens', $langs->trans("AccountingDirectionHelp"));
499  print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
500  $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
501  print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
502  print '</td></tr>';
503 
504  // Project
505  if (isModEnabled('project')) {
506  $formproject = new FormProjets($db);
507 
508  // Associated project
509  $langs->load("projects");
510 
511  print '<tr><td>'.$langs->trans("Project").'</td><td>';
512  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
513  print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
514  print '</td></tr>';
515  }
516 
517  // Other attributes
518  $parameters = array();
519  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
520  print $hookmanager->resPrint;
521 
522  // Category
523  if (is_array($options) && count($options) && $conf->categorie->enabled) {
524  print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
525  print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
526  print '</td></tr>';
527  }
528 
529  print '</table>';
530 
531  print dol_get_fiche_end();
532 
533  print $form->buttonsSaveCancel();
534 
535  print '</form>';
536 }
537 
538 
539 /* ************************************************************************** */
540 /* */
541 /* View mode */
542 /* */
543 /* ************************************************************************** */
544 
545 if ($id) {
546  $alreadyaccounted = $object->getVentilExportCompta();
547 
548  $head = various_payment_prepare_head($object);
549 
550  // Clone confirmation
551  if ($action === 'clone') {
552  $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
553  $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
554 
555  $formquestion = array(
556  array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
557  array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
558  array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
559  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)),
560  array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
561  array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => $object->sens),
562  );
563 
564  print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
565  }
566 
567  // Confirmation of the removal of the Various Payment
568  if ($action == 'delete') {
569  $text = $langs->trans('ConfirmDeleteVariousPayment');
570  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
571  }
572 
573  print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
574 
575  $morehtmlref = '<div class="refidno">';
576  // Project
577  if (isModEnabled('project')) {
578  $langs->load("projects");
579  $morehtmlref .= $langs->trans('Project').' ';
580  if ($user->rights->banque->modifier) {
581  if ($action != 'classify') {
582  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
583  }
584  if ($action == 'classify') {
585  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
586  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
587  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
588  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
589  $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
590  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
591  $morehtmlref .= '</form>';
592  } else {
593  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (property_exists($object, 'socid') ? $object->socid : 0), $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
594  }
595  } else {
596  if (!empty($object->fk_project)) {
597  $proj = new Project($db);
598  $proj->fetch($object->fk_project);
599  $morehtmlref .= $proj->getNomUrl(1);
600  } else {
601  $morehtmlref .= '';
602  }
603  }
604  }
605  $morehtmlref .= '</div>';
606  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
607 
608  $morehtmlright = '';
609 
610  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
611 
612  print '<div class="fichecenter">';
613  print '<div class="underbanner clearboth"></div>';
614 
615  print '<table class="border centpercent tableforfield">';
616 
617  // Label
618  print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
619 
620  // Payment date
621  print "<tr>";
622  print '<td>'.$langs->trans("DatePayment").'</td><td>';
623  print dol_print_date($object->datep, 'day');
624  print '</td></tr>';
625 
626  // Value date
627  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
628  print dol_print_date($object->datev, 'day');
629  print '</td></tr>';
630 
631  // Debit / Credit
632  if ($object->sens == '1') {
633  $sens = $langs->trans("Credit");
634  } else {
635  $sens = $langs->trans("Debit");
636  }
637  print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
638 
639  print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
640 
641  // Accountancy code
642  if (isModEnabled('accounting')) {
643  print '<tr><td class="nowrap">';
644  print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
645  print '</td><td>';
646  if ($action == 'editaccountancy_code') {
647  print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
648  } else {
649  $accountingaccount = new AccountingAccount($db);
650  $accountingaccount->fetch('', $object->accountancy_code, 1);
651 
652  print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
653  }
654  print '</td></tr>';
655  } else {
656  print '<tr><td class="nowrap">';
657  print $langs->trans("AccountAccounting");
658  print '</td><td>';
659  print $object->accountancy_code;
660  print '</td></tr>';
661  }
662 
663  // Subledger account
664  print '<tr><td class="nowrap">';
665  print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
666  print '</td><td>';
667  print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
668  print '</td></tr>';
669 
670  $bankaccountnotfound = 0;
671 
672  if (isModEnabled('banque')) {
673  print '<tr>';
674  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
675  print '<td colspan="3">';
676  if ($object->fk_bank > 0) {
677  $bankline = new AccountLine($db);
678  $result = $bankline->fetch($object->fk_bank);
679 
680  if ($result <= 0) {
681  $bankaccountnotfound = 1;
682  } else {
683  print $bankline->getNomUrl(1, 0, 'showall');
684  }
685  } else {
686  $bankaccountnotfound = 1;
687 
688  print '<span class="opacitymedium">'.$langs->trans("NoRecordfound").'</span>';
689  }
690  print '</td>';
691  print '</tr>';
692  }
693 
694  // Other attributes
695  $parameters = array('socid'=>$object->id);
696  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
697 
698  print '</table>';
699 
700  print '</div>';
701 
702  print '<div class="clearboth"></div>';
703 
704  print dol_get_fiche_end();
705 
706 
707  /*
708  * Action bar
709  */
710  print '<div class="tabsAction">'."\n";
711 
712  // TODO
713  // Add button modify
714 
715  // Clone
716  if ($user->rights->banque->modifier) {
717  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>";
718  }
719 
720  // Delete
721  if (empty($object->rappro) || $bankaccountnotfound) {
722  if (!empty($user->rights->banque->modifier)) {
723  if ($alreadyaccounted) {
724  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
725  } else {
726  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
727  }
728  } else {
729  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
730  }
731  } else {
732  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
733  }
734 
735  print "</div>";
736 }
737 
738 // End of page
739 llxFooter();
740 $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.