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