dolibarr 23.0.3
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
36require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
37require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
38if (isModEnabled('project')) {
39 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
41}
42
51// Load translation files required by the page
52$langs->loadLangs(array("accountancy", "banks", "bills", "categories", "compta", "users"));
53
54// Get parameters
55$id = GETPOSTINT('id');
56$action = GETPOST('action', 'alpha');
57$confirm = GETPOST('confirm');
58$cancel = GETPOST('cancel', 'alpha');
59$backtopage = GETPOST('backtopage', 'alpha');
60
61$accountid = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
62$label = GETPOST("label", "alpha");
63$sens = GETPOSTINT("sens");
64$amount = GETPOST("amount");
65$paymenttype = GETPOST("paymenttype", "aZ09");
66$accountancy_code = GETPOST("accountancy_code", "alpha");
67$projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project');
68if (isModEnabled('accounting') && getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
69 $subledger_account = GETPOST("subledger_account", "alpha") > 0 ? GETPOST("subledger_account", "alpha") : '';
70} else {
71 $subledger_account = GETPOST("subledger_account", "alpha");
72}
73
74// Security check
75$socid = GETPOSTINT("socid");
76if ($user->socid) {
77 $socid = $user->socid;
78}
79
80// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
81$hookmanager->initHooks(array('variouscard', 'globalcard'));
82
83$result = restrictedArea($user, 'banque', '', '', '');
84
85$object = new PaymentVarious($db);
86
87$permissiontoadd = $user->hasRight('banque', 'modifier');
88$permissiontodelete = $user->hasRight('banque', 'modifier');
89
90
95$parameters = array();
96$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
97if ($reshook < 0) {
98 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
99}
100
101if (empty($reshook)) {
102 if ($cancel) {
103 if ($action != 'addlink' && $action != 'setaccountancy_code' && $action != 'setsubledger_account') {
104 $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
105 header("Location: ".$urltogo);
106 exit;
107 }
108 if ($id > 0) {
109 $ret = $object->fetch($id);
110 }
111 $action = '';
112 }
113
114 // Link to a project
115 if ($action == 'classin' && $permissiontoadd) {
116 $object->fetch($id);
117 $object->setProject(GETPOSTINT('projectid'));
118 }
119
120 if ($action == 'add' && $permissiontoadd) {
121 $error = 0;
122
123 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
124 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
125 if (empty($datev)) {
126 $datev = $datep;
127 }
128
129 $object->ref = ''; // TODO
130 $object->fk_account = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
131 $object->accountid = $object->fk_account;
132 $object->datev = $datev;
133 $object->datep = $datep;
134 $object->amount = GETPOSTFLOAT("amount");
135 $object->label = GETPOST("label", 'restricthtml');
136 $object->note_private = GETPOST("note", 'restricthtml');
137 $object->note = $object->note_private;
138 $object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1);
139 $object->num_payment = GETPOST("num_payment", 'alpha');
140 $object->chqemetteur = GETPOST("chqemetteur", 'alpha');
141 $object->chqbank = GETPOST("chqbank", 'alpha');
142 $object->fk_user_author = $user->id;
143 $object->category_transaction = GETPOSTINT("category_transaction");
144
145 $object->accountancy_code = (GETPOST("accountancy_code") != '-1' ? GETPOST("accountancy_code", "alpha") : "");
146 $object->subledger_account = $subledger_account;
147
148 $object->sens = GETPOSTINT('sens');
149 $object->fk_project = GETPOSTINT('fk_project');
150
151 if (!checkGeneralAccountAllowsAuxiliary($db, $object->accountancy_code, $object->subledger_account)) {
152 setEventMessages($langs->trans("ErrorAccountNotCentralized"). ". " . $langs->trans("RemoveSubsidiaryAccountOrAdjustTheGeneralAccount"), null, 'errors');
153 $error++;
154 }
155 if (empty($datep) || empty($datev)) {
156 $langs->load('errors');
157 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
158 $error++;
159 }
160 if (empty($object->amount)) {
161 $langs->load('errors');
162 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
163 $error++;
164 }
165 if (isModEnabled("bank") && !$object->accountid > 0) {
166 $langs->load('errors');
167 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
168 $error++;
169 }
170 if (empty($object->type_payment) || $object->type_payment < 0) {
171 $langs->load('errors');
172 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
173 $error++;
174 }
175 if (isModEnabled('accounting') && !$object->accountancy_code) {
176 $langs->load('errors');
177 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
178 $error++;
179 }
180 if ($object->sens < 0) {
181 $langs->load('errors');
182 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
183 $error++;
184 }
185
186 $bankaccount = new Account($db);
187 $bankaccount->fetch($object->fk_account);
188
189 // Check currency
190 $currencyofpayment = $conf->currency; // The currency of various payment is not yet asked, so we suppose it is the main company currency
191
192 //var_dump($currencyofpayment); var_dump($bankaccount->currency_code);
193
194 if (isModEnabled('multicurrency') && $currencyofpayment != $bankaccount->currency_code) {
195 // TODO Support this feature the same way we do it for invoice payment
196 // using the $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
197 setEventMessages($langs->trans("ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported"), null, 'errors');
198 $error++;
199 }
200
201 if (!$error) {
202 $db->begin();
203
204 $ret = $object->create($user);
205 if ($ret > 0) {
206 $db->commit();
207 $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
208 header("Location: ".$urltogo);
209 exit;
210 } else {
211 $db->rollback();
212 setEventMessages($object->error, $object->errors, 'errors');
213 $action = "create";
214 }
215 }
216
217 $action = 'create';
218 }
219
220 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
221 $result = $object->fetch($id);
222
223 if ($object->rappro == 0) {
224 $db->begin();
225
226 $ret = $object->delete($user);
227 if ($ret > 0) {
228 $accountline = null;
229 if ($object->fk_bank) {
230 $accountline = new AccountLine($db);
231 $result = $accountline->fetch($object->fk_bank);
232 if ($result > 0) {
233 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
234 }
235 }
236
237 if ($result >= 0) {
238 $db->commit();
239 header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
240 exit;
241 } else {
242 $object->error = $accountline ? $accountline->error : 'No AccountLine';
243 $db->rollback();
244 setEventMessages($object->error, $object->errors, 'errors');
245 }
246 } else {
247 $db->rollback();
248 setEventMessages($object->error, $object->errors, 'errors');
249 }
250 } else {
251 setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
252 }
253 }
254
255 if ($action == 'setaccountancy_code' && $permissiontodelete) {
256 $db->begin();
257
258 $result = $object->fetch($id);
259
260 $object->accountancy_code = GETPOST('accountancy_code', 'alphanohtml');
261
262 $res = $object->update($user);
263 if ($res > 0) {
264 $db->commit();
265 } else {
266 $db->rollback();
267 setEventMessages($object->error, $object->errors, 'errors');
268 }
269 }
270
271 if ($action == 'setsubledger_account' && $permissiontodelete) {
272 $db->begin();
273
274 $result = $object->fetch($id);
275
276 $object->subledger_account = $subledger_account;
277
278 $res = $object->update($user);
279 if ($res > 0) {
280 $db->commit();
281 } else {
282 $db->rollback();
283 setEventMessages($object->error, $object->errors, 'errors');
284 }
285 }
286}
287
288// Action clone object
289if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required
290 $action = '';
291}
292
293if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
294 $db->begin();
295
296 $originalId = $id;
297
298 $object->fetch($id);
299
300 if ($object->id > 0) {
301 unset($object->id);
302 unset($object->ref);
303
304 if (GETPOST('clone_label', 'alphanohtml')) {
305 $object->label = GETPOST('clone_label', 'alphanohtml');
306 } else {
307 $object->label = $langs->trans("CopyOf").' '.$object->label;
308 }
309
310 $newdatepayment = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_paymentmonth'), GETPOSTINT('clone_date_paymentday'), GETPOSTINT('clone_date_paymentyear'));
311 $newdatevalue = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_valuemonth'), GETPOSTINT('clone_date_valueday'), GETPOSTINT('clone_date_valueyear'));
312 if ($newdatepayment) {
313 $object->datep = $newdatepayment;
314 }
315 if (!empty($newdatevalue)) {
316 $object->datev = $newdatevalue;
317 } else {
318 $object->datev = $newdatepayment;
319 }
320
321 if (GETPOSTISSET("clone_sens")) {
322 $object->sens = GETPOSTINT("clone_sens");
323 } // else { $object->sens = $object->sens; }
324
325 if (GETPOSTISSET("clone_amount")) {
326 $object->amount = GETPOSTFLOAT("clone_amount");
327 } else {
328 $object->amount = (float) price2num($object->amount);
329 }
330
331 if ($object->check()) {
332 $id = $object->create($user);
333 if ($id > 0) {
334 $db->commit();
335 $db->close();
336
337 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
338 exit;
339 } else {
340 $id = $originalId;
341 $db->rollback();
342
343 setEventMessages($object->error, $object->errors, 'errors');
344 }
345 } else {
346 $id = $originalId;
347 $db->rollback();
348
349 setEventMessages($object->error, $object->errors, 'errors');
350 }
351 } else {
352 $db->rollback();
353 dol_print_error($db, $object->error);
354 }
355}
356
357
358/*
359 * View
360 */
361
362$form = new Form($db);
363if (isModEnabled('accounting')) {
364 $formaccounting = new FormAccounting($db);
365} else {
366 $formaccounting = null;
367}
368if (isModEnabled('project')) {
369 $formproject = new FormProjets($db);
370} else {
371 $formproject = null;
372}
373
374if ($id) {
375 $object = new PaymentVarious($db);
376 $result = $object->fetch($id);
377 if ($result <= 0) {
378 dol_print_error($db);
379 exit;
380 }
381}
382
383$title = $object->ref." - ".$langs->trans('Card');
384if ($action == 'create') {
385 $title = $langs->trans("NewVariousPayment");
386}
387$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
388llxHeader('', $title, $help_url);
389
390$options = array();
391
392// Load bank groups
393require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
394$bankcateg = new BankCateg($db);
395
396$arrayofbankcategs = $bankcateg->fetchAll();
397
398foreach ($arrayofbankcategs as $bankcategory) {
399 $options[$bankcategory->id] = $bankcategory->label;
400}
401
402// Create mode
403if ($action == 'create') {
404 // Update fields properties in realtime
405 if (!empty($conf->use_javascript_ajax)) {
406 print "\n".'<script type="text/javascript">';
407 print '$(document).ready(function () {
408 setPaymentType();
409 $("#selectpaymenttype").change(function() {
410 setPaymentType();
411 });
412 function setPaymentType()
413 {
414 console.log("setPaymentType");
415 var code = $("#selectpaymenttype option:selected").val();
416 if (code == \'CHQ\' || code == \'VIR\')
417 {
418 if (code == \'CHQ\')
419 {
420 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
421 }
422 if ($(\'#fieldchqemetteur\').val() == \'\')
423 {
424 var emetteur = jQuery(\'#thirdpartylabel\').val();
425 $(\'#fieldchqemetteur\').val(emetteur);
426 }
427 }
428 else
429 {
430 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
431 $(\'#fieldchqemetteur\').val(\'\');
432 }
433 }
434 function toggleSubledger() {
435 var isCentral = $("#accountancy_code option:selected").data("centralized");
436 console.log("the selected general ledger account is centralised?", isCentral);
437 if (isCentral) {
438 $("#subledger_account").prop("disabled", false);
439 } else {
440 $("#subledger_account").prop("disabled", true);
441 }
442 }
443 toggleSubledger();
444
445 $("#accountancy_code").on("change", toggleSubledger);
446 $("#accountancy_code").on("select2:select", toggleSubledger);
447 ';
448
449 print ' });'."\n";
450
451 print ' </script>'."\n";
452 }
453
454 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
455 print '<input type="hidden" name="token" value="'.newToken().'">';
456 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
457 print '<input type="hidden" name="action" value="add">';
458
459 print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
460
461 print dol_get_fiche_head([], '');
462
463 print '<table class="border centpercent">';
464
465 // Date payment
466 print '<tr><td class="titlefieldcreate">';
467 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
468 print $form->selectDate((empty($datep) ? -1 : $datep), "datep", 0, 0, 0, 'add', 1, 1);
469 print '</td></tr>';
470
471 // Date value for bank
472 print '<tr><td>';
473 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
474 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
475 print '</td></tr>';
476
477 // Label
478 print '<tr><td>';
479 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
480 print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
481 print '</td></tr>';
482
483 // Amount
484 print '<tr><td>';
485 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
486 print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
487 print '</td></tr>';
488
489 // Bank
490 if (isModEnabled("bank")) {
491 print '<tr><td>';
492 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
493 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
494 print $form->select_comptes($accountid, "accountid", 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), '', 1); // Show list of main accounts (comptes courants)
495 print '</td></tr>';
496 }
497
498 // Type payment
499 print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
500 $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
501 print "</td>\n";
502 print '</tr>';
503
504 // Number
505 if (isModEnabled("bank")) {
506 print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
507 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
508 print '</label></td>';
509 print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
510
511 // Check transmitter
512 print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
513 print ' <em>('.$langs->trans("ChequeMaker").')</em>';
514 print '</label></td>';
515 print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
516
517 // Bank name
518 print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
519 print ' <em>('.$langs->trans("ChequeBank").')</em>';
520 print '</label></td>';
521 print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
522 }
523
524 // Project
525 if (isModEnabled('project')) {
526 $formproject = new FormProjets($db);
527
528 // Associated project
529 $langs->load("projects");
530
531 print '<tr><td>'.$langs->trans("Project").'</td><td>';
532 print img_picto('', 'project', 'class="pictofixedwidth"');
533 print $formproject->select_projects(-1, (string) $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
534 print '</td></tr>';
535 }
536
537 // Other attributes
538 $parameters = array();
539 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
540 print $hookmanager->resPrint;
541
542 // Category
543 if (is_array($options) && count($options) && isModEnabled('category')) {
544 print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
545 print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
546 print '</td></tr>';
547 }
548
549 print '<tr><td colspan="2"><hr></td></tr>';
550
551 // Accountancy account
552 if (isModEnabled('accounting')) {
554 // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
555 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
556 print '<td>';
557 print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, array(), 1, 1);
558 print '</td></tr>';
559 } else { // For external software
560 print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
561 print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
562 print '</td></tr>';
563 }
564
565 // Subledger account
566 if (isModEnabled('accounting')) {
568 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
569 print '<td>';
570 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
571 print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
572 } else {
573 print '<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
574 }
575 print '</td></tr>';
576 } else { // For external software
577 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
578 print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
579 print '</td></tr>';
580 }
581
582 // Sens
583 print '<tr><td>';
584 $labelsens = $form->textwithpicto($langs->trans('Sens'), $langs->trans("AccountingDirectionHelp"));
585 print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
586 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
587 print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
588 print '</td></tr>';
589
590 print '</table>';
591
592 print dol_get_fiche_end();
593
594 print $form->buttonsSaveCancel();
595
596 print '</form>';
597}
598
599// View in read or edit mode
600if ($id) {
601 $alreadyaccounted = $object->getVentilExportCompta();
602
603 $head = various_payment_prepare_head($object);
604
605 // Clone confirmation
606 if ($action === 'clone') {
607 $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
608 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
609
610 $formquestion = array(
611 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
612 array('type' => 'date', 'tdclass' => 'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
613 array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
614 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)),
615 array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
616 array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => (string) $object->sens),
617 );
618
619 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
620 }
621
622 // Confirmation of the removal of the Various Payment
623 if ($action == 'delete') {
624 $text = $langs->trans('ConfirmDeleteVariousPayment');
625 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
626 }
627
628 print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
629
630 $morehtmlref = '<div class="refidno">';
631 // Project
632 if (isModEnabled('project') && $formproject !== null) {
633 $langs->load("projects");
634 //$morehtmlref .= '<br>';
635 if ($permissiontoadd) {
636 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
637 if ($action != 'classify') {
638 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
639 }
640 if ($action == 'classify') {
641 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
642 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
643 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
644 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
645 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
646 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
647 $morehtmlref .= '</form>';
648 } else {
649 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (property_exists($object, 'socid') ? $object->socid : 0), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
650 }
651 } else {
652 if (!empty($object->fk_project)) {
653 $proj = new Project($db);
654 $proj->fetch($object->fk_project);
655 $morehtmlref .= $proj->getNomUrl(1);
656 if ($proj->title) {
657 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
658 }
659 }
660 }
661 }
662
663 $morehtmlref .= '</div>';
664 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
665
666 $morehtmlstatus = '';
667
668 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
669
670 print '<div class="fichecenter">';
671 print '<div class="underbanner clearboth"></div>';
672
673 print '<table class="border centpercent tableforfield">';
674
675 // Label
676 print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
677
678 // Payment date
679 print "<tr>";
680 print '<td>'.$langs->trans("DatePayment").'</td><td>';
681 print dol_print_date($object->datep, 'day');
682 print '</td></tr>';
683
684 // Value date
685 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
686 print dol_print_date($object->datev, 'day');
687 print '</td></tr>';
688
689 // Debit / Credit
690 if ($object->sens == '1') {
691 $sens = $langs->trans("Credit");
692 } else {
693 $sens = $langs->trans("Debit");
694 }
695 print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
696
697 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
698
699 // Account of Chart of account
700 $editvalue = '';
701 if (isModEnabled('accounting')) {
703 print '<tr><td class="nowrap">';
704 print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
705 print '</td><td>';
706 if ($action == 'editaccountancy_code' && (!$alreadyaccounted && $permissiontoadd)) {
707 //print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->hasRight('banque', 'modifier')), 'string', '', 0);
708 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code, 'accountancy_code', 0, 1, '', 1);
709 } else {
710 $accountingaccount = new AccountingAccount($db);
711 $accountingaccount->fetch(0, $object->accountancy_code, 1);
712
713 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
714 }
715 print '</td></tr>';
716 } else {
717 print '<tr><td class="nowrap">';
718 print $langs->trans("AccountAccounting");
719 print '</td><td>';
720 print $object->accountancy_code;
721 print '</td></tr>';
722 }
723
724 // Subledger account
725 print '<tr><td class="nowrap">';
726 print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
727 print '</td><td>';
728 if ($action == 'editsubledger_account' && (!$alreadyaccounted && $permissiontoadd)) {
729 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
731 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->subledger_account, 'subledger_account', 1, 1, '', 1);
732 } else {
733 print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', null, null, '', 1, 'lengthAccounta');
734 }
735 } else {
736 print length_accounta($object->subledger_account);
737 }
738 print '</td></tr>';
739
740 $bankaccountnotfound = 0;
741
742 if (isModEnabled('bank')) {
743 print '<tr>';
744 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
745 print '<td colspan="3">';
746 if ($object->fk_bank > 0) {
747 $bankline = new AccountLine($db);
748 $result = $bankline->fetch($object->fk_bank);
749
750 if ($result <= 0) {
751 $bankaccountnotfound = 1;
752 } else {
753 print $bankline->getNomUrl(1, 0, 'showall');
754 }
755 } else {
756 $bankaccountnotfound = 1;
757
758 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
759 }
760 print '</td>';
761 print '</tr>';
762 }
763
764 // Other attributes
765 $parameters = array('socid' => $object->id);
766 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
767
768 print '</table>';
769
770 print '</div>';
771
772 print '<div class="clearboth"></div>';
773
774 print dol_get_fiche_end();
775
776
777 /*
778 * Action bar
779 */
780 print '<div class="tabsAction">'."\n";
781
782 // TODO
783 // Add button modify
784
785 // Clone
786 if ($permissiontoadd) {
787 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>";
788 }
789
790 // Delete
791 if (empty($object->rappro) || $bankaccountnotfound) {
792 if ($permissiontoadd) {
793 if ($alreadyaccounted) {
794 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
795 } else {
796 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
797 }
798 } else {
799 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
800 }
801 } else {
802 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
803 }
804
805 print "</div>";
806}
807
808// End of page
809llxFooter();
810$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
checkGeneralAccountAllowsAuxiliary($db, $general_account, $auxiliary_account, $general_account_id=0)
Check if a general accounting account allows the use of an auxiliary account.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
various_payment_prepare_head($object)
Prepare array with list of tabs.
Definition bank.lib.php:311
Class to manage bank accounts.
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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.