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