dolibarr 24.0.2
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// PaymentVarious::fetch() returns a record regardless of entity (low-level primitive), so the entity
88// restriction is enforced here in the caller: the various payment must belong to the current entity.
89if ($id > 0) {
90 $resqlent = $db->query("SELECT rowid FROM ".MAIN_DB_PREFIX."payment_various WHERE rowid = ".((int) $id)." AND entity IN (".getEntity('payment_various').")");
91 if (!$resqlent || !$db->num_rows($resqlent)) {
93 }
94}
95
97
98$extrafields->fetch_name_optionals_label($object->table_element);
99
100$permissiontoadd = $user->hasRight('banque', 'modifier');
101$permissiontodelete = $user->hasRight('banque', 'modifier');
102
103
108$parameters = array();
109$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110if ($reshook < 0) {
111 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112}
113
114if (empty($reshook)) {
115 if ($cancel) {
116 if ($action != 'addlink' && $action != 'setaccountancy_code' && $action != 'setsubledger_account') {
117 $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
118 header("Location: ".$urltogo);
119 exit;
120 }
121 if ($id > 0) {
122 $ret = $object->fetch($id);
123 }
124 $action = '';
125 }
126
127 // Link to a project
128 if ($action == 'classin' && $permissiontoadd) {
129 $object->fetch($id);
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 $result = $object->fetch($id);
241
242 if ($object->rappro == 0) {
243 $db->begin();
244
245 $ret = $object->delete($user);
246 if ($ret > 0) {
247 $accountline = null;
248 if ($object->fk_bank) {
249 $accountline = new AccountLine($db);
250 $result = $accountline->fetch($object->fk_bank);
251 if ($result > 0) {
252 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
253 }
254 }
255
256 if ($result >= 0) {
257 $db->commit();
258 header("Location: ".dolBuildUrl(DOL_URL_ROOT.'/compta/bank/various_payment/list.php'));
259 exit;
260 } else {
261 $object->error = $accountline ? $accountline->error : 'No AccountLine';
262 $db->rollback();
263 setEventMessages($object->error, $object->errors, 'errors');
264 }
265 } else {
266 $db->rollback();
267 setEventMessages($object->error, $object->errors, 'errors');
268 }
269 } else {
270 setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
271 }
272 }
273
274 if ($action == 'setaccountancy_code' && $permissiontodelete) {
275 $db->begin();
276
277 $result = $object->fetch($id);
278
279 $object->accountancy_code = GETPOST('accountancy_code', 'alphanohtml');
280
281 $res = $object->update($user);
282 if ($res > 0) {
283 $db->commit();
284 } else {
285 $db->rollback();
286 setEventMessages($object->error, $object->errors, 'errors');
287 }
288 }
289
290 if ($action == 'setsubledger_account' && $permissiontodelete) {
291 $db->begin();
292
293 $result = $object->fetch($id);
294
295 $object->subledger_account = $subledger_account;
296
297 $res = $object->update($user);
298 if ($res > 0) {
299 $db->commit();
300 } else {
301 $db->rollback();
302 setEventMessages($object->error, $object->errors, 'errors');
303 }
304 }
305}
306
307// Action clone object
308if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required
309 $action = '';
310}
311
312if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
313 $db->begin();
314
315 $originalId = $id;
316
317 $object->fetch($id);
318
319 if ($object->id > 0) {
320 unset($object->id);
321 unset($object->ref);
322
323 if (GETPOST('clone_label', 'alphanohtml')) {
324 $object->label = GETPOST('clone_label', 'alphanohtml');
325 } else {
326 $object->label = $langs->trans("CopyOf").' '.$object->label;
327 }
328
329 $newdatepayment = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_paymentmonth'), GETPOSTINT('clone_date_paymentday'), GETPOSTINT('clone_date_paymentyear'));
330 $newdatevalue = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_valuemonth'), GETPOSTINT('clone_date_valueday'), GETPOSTINT('clone_date_valueyear'));
331 if ($newdatepayment) {
332 $object->datep = $newdatepayment;
333 }
334 if (!empty($newdatevalue)) {
335 $object->datev = $newdatevalue;
336 } else {
337 $object->datev = $newdatepayment;
338 }
339
340 if (GETPOSTINT('selectclone_accountid') > 0) {
341 $object->fk_account = GETPOSTINT('selectclone_accountid');
342 $object->accountid = $object->fk_account;
343 }
344
345 if (GETPOSTISSET("clone_sens")) {
346 $object->sens = GETPOSTINT("clone_sens");
347 } // else { $object->sens = $object->sens; }
348
349 if (GETPOSTISSET("clone_amount")) {
350 $object->amount = GETPOSTFLOAT("clone_amount");
351 } else {
352 $object->amount = (float) price2num($object->amount);
353 }
354
355 if ($object->check()) {
356 $id = $object->create($user);
357 if ($id > 0) {
358 $db->commit();
359 $db->close();
360
361 header("Location: ".dolBuildUrl($_SERVER["PHP_SELF"], ["id" => $id]));
362 exit;
363 } else {
364 $id = $originalId;
365 $db->rollback();
366
367 setEventMessages($object->error, $object->errors, 'errors');
368 }
369 } else {
370 $id = $originalId;
371 $db->rollback();
372
373 setEventMessages($object->error, $object->errors, 'errors');
374 }
375 } else {
376 $db->rollback();
377 dol_print_error($db, $object->error);
378 }
379}
380
381
382/*
383 * View
384 */
385
386$form = new Form($db);
387if (isModEnabled('accounting')) {
388 $formaccounting = new FormAccounting($db);
389} else {
390 $formaccounting = null;
391}
392if (isModEnabled('project')) {
393 $formproject = new FormProjets($db);
394} else {
395 $formproject = null;
396}
397
398if ($id) {
400 $result = $object->fetch($id);
401 if ($result <= 0) {
403 exit;
404 }
405}
406
407$title = $object->ref." - ".$langs->trans('Card');
408if ($action == 'create') {
409 $title = $langs->trans("NewVariousPayment");
410}
411$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
412llxHeader('', $title, $help_url);
413
414$options = array();
415
416// Load bank groups
417require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
418$bankcateg = new BankCateg($db);
419
420$arrayofbankcategs = $bankcateg->fetchAll();
421
422foreach ($arrayofbankcategs as $bankcategory) {
423 $options[$bankcategory->id] = $bankcategory->label;
424}
425
426// Create mode
427if ($action == 'create') {
428 // Update fields properties in realtime
429 if (!empty($conf->use_javascript_ajax)) {
430 ?>
431 <script type="text/javascript">
432 $(document).ready(function() {
433 setPaymentType();
434 $("#selectpaymenttype").change(function() {
435 setPaymentType();
436 });
437
438 function setPaymentType() {
439 console.log("setPaymentType");
440 var code = $("#selectpaymenttype option:selected").val();
441 if (code == "CHQ" || code == "VIR") {
442 if (code == 'CHQ') {
443 $('.fieldrequireddyn').addClass('fieldrequired');
444 }
445 if ($('#fieldchqemetteur').val() == '') {
446 var emetteur = jQuery('#thirdpartylabel').val();
447 $('#fieldchqemetteur').val(emetteur);
448 }
449 } else {
450 $(".fieldrequireddyn").removeClass("fieldrequired");
451 $("#fieldchqemetteur").val("");
452 }
453 }
454
455 function toggleSubledger() {
456 var isCentral = $("#accountancy_code option:selected").data("centralized");
457 console.log("the selected general ledger account is centralised?", isCentral);
458 if (isCentral) {
459 $("#subledger_account").prop("disabled", false);
460 } else {
461 $("#subledger_account").prop("disabled", true);
462 }
463 }
464 toggleSubledger();
465
466 $("#accountancy_code").on("change", toggleSubledger);
467 $("#accountancy_code").on("select2:select", toggleSubledger);
468 });
469 </script>
470 <?php
471 }
472
473 print '<form action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'" method="POST">';
474 print '<input type="hidden" name="token" value="'.newToken().'">';
475 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
476 print '<input type="hidden" name="action" value="add">';
477
478 print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
479
480 print dol_get_fiche_head([], '');
481
482 print '<table class="border centpercent">';
483
484 // Date payment
485 print '<tr><td class="titlefieldcreate">';
486 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
487 print $form->selectDate((empty($datep) ? -1 : $datep), "datep", 0, 0, 0, 'add', 1, 1);
488 print '</td></tr>';
489
490 // Date value for bank
491 print '<tr><td>';
492 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
493 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
494 print '</td></tr>';
495
496 // Label
497 print '<tr><td>';
498 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
499 print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
500 print '</td></tr>';
501
502 // Amount
503 print '<tr><td>';
504 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
505 print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
506 print ' '.$langs->getCurrencySymbol();
507 print '</td></tr>';
508
509 // Bank
510 if (isModEnabled("bank")) {
511 print '<tr><td>';
512 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
513 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
514 print $form->select_comptes($accountid, "accountid", 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), '', 1); // Show list of main accounts (comptes courants)
515 print '</td></tr>';
516 }
517
518 // Type payment
519 print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
520 $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
521 print "</td>\n";
522 print '</tr>';
523
524 // Number
525 if (isModEnabled("bank")) {
526 print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
527 print ' <em class="opacitymedium">('.$langs->trans("ChequeOrTransferNumber").')</em>';
528 print '</label></td>';
529 print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
530
531 // Check transmitter
532 print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
533 print ' <em class="opacitymedium">('.$langs->trans("ChequeMaker").')</em>';
534 print '</label></td>';
535 print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
536
537 // Bank name
538 print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
539 print ' <em class="opacitymedium">('.$langs->trans("ChequeBank").')</em>';
540 print '</label></td>';
541 print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
542 }
543
544 // Project
545 if (isModEnabled('project')) {
546 $formproject = new FormProjets($db);
547
548 // Associated project
549 $langs->load("projects");
550
551 print '<tr><td>'.$langs->trans("Project").'</td><td>';
552 print img_picto('', 'project', 'class="pictofixedwidth"');
553 print $formproject->select_projects(-1, (string) $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
554 print '</td></tr>';
555 }
556
557 // Other attributes
558 print $object->showOptionals($extrafields, 'create');
559
560 $parameters = array();
561 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
562 print $hookmanager->resPrint;
563
564 // Category
565 if (is_array($options) && count($options) && isModEnabled('category')) {
566 print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
567 print img_picto('', 'category', 'class="pictofixedwidth"') . Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
568 print '</td></tr>';
569 }
570
571 print '<tr><td colspan="2"><hr></td></tr>';
572
573 // Accountancy account
574 if (isModEnabled('accounting')) {
576 // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
577 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
578 print '<td>';
579 print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, array(), 1, 1);
580 print '</td></tr>';
581 } else { // For external software
582 print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
583 print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
584 print '</td></tr>';
585 }
586
587 // Subledger account
588 if (isModEnabled('accounting')) {
590 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
591 print '<td>';
592 print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
593 print '</td></tr>';
594 } else { // For external software
595 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
596 print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
597 print '</td></tr>';
598 }
599
600 // Sens
601 print '<tr><td>';
602 $labelsens = $form->textwithpicto($langs->trans('Sens'), $langs->trans("AccountingDirectionHelp"));
603 print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
604 $sensarray = array(
605 '0' => array('label' => $langs->trans("Debit")),
606 '1' => array('label' => $langs->trans("Credit"))
607 );
608 // We can't use this module to enter customer payments
609 include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
610 if (isALNERunningVersion()) {
611 $sensarray['1']['disabled'] = 1;
612 }
613
614 print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
615 print '</td></tr>';
616
617 print '</table>';
618
619 print dol_get_fiche_end();
620
621 print $form->buttonsSaveCancel();
622
623 print '</form>';
624}
625
626// View in read or edit mode
627if ($id) {
628 $alreadyaccounted = $object->getVentilExportCompta();
629
630 $head = various_payment_prepare_head($object);
631
632 // Clone confirmation
633 if ($action === 'clone') {
634 $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
635 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
636
637 $formquestion = array(
638 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
639 array('type' => 'date', 'tdclass' => 'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
640 array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
641 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)),
642 array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
643 array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' ' . $set_value_help, 'values' => $sensarray, 'default' => (string) $object->sens),
644 );
645
646 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
647 }
648
649 // Confirmation of the removal of the Various Payment
650 if ($action == 'delete') {
651 $text = $langs->trans('ConfirmDeleteVariousPayment');
652 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
653 }
654
655 print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
656
657 $morehtmlref = '<div class="refidno">';
658 // Project
659 if (isModEnabled('project') && $formproject !== null) {
660 $langs->load("projects");
661 //$morehtmlref .= '<br>';
662 if ($permissiontoadd) {
663 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
664 if ($action != 'classify') {
665 $morehtmlref .= '<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">' . img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
666 }
667 if ($action == 'classify') {
668 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
669 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
670 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
671 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
672 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
673 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
674 $morehtmlref .= '</form>';
675 } else {
676 $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');
677 }
678 } else {
679 if (!empty($object->fk_project)) {
680 $proj = new Project($db);
681 $proj->fetch($object->fk_project);
682 $morehtmlref .= $proj->getNomUrl(1);
683 if ($proj->title) {
684 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
685 }
686 }
687 }
688 }
689
690 $morehtmlref .= '</div>';
691 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/bank/various_payment/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '').'">'.$langs->trans("BackToList").'</a>';
692
693 $morehtmlstatus = '';
694
695 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
696
697 print '<div class="fichecenter">';
698 print '<div class="underbanner clearboth"></div>';
699
700 print '<table class="border centpercent tableforfield">';
701
702 // Label
703 print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
704
705 // Payment date
706 print "<tr>";
707 print '<td>'.$langs->trans("DatePayment").'</td><td>';
708 print dol_print_date($object->datep, 'day');
709 print '</td></tr>';
710
711 // Value date
712 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
713 print dol_print_date($object->datev, 'day');
714 print '</td></tr>';
715
716 // Debit / Credit
717 if ($object->sens == '1') {
718 $sens = $langs->trans("Credit");
719 } else {
720 $sens = $langs->trans("Debit");
721 }
722 print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
723
724 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
725
726 // Account of Chart of account
727 $editvalue = '';
728 if (isModEnabled('accounting')) {
730 print '<tr><td class="nowrap">';
731 print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
732 print '</td><td>';
733 if ($action == 'editaccountancy_code' && (!$alreadyaccounted && $permissiontoadd)) {
734 //print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->hasRight('banque', 'modifier')), 'string', '', 0);
735 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->accountancy_code, 'accountancy_code', 0, 1, '', 1);
736 } else {
737 $accountingaccount = new AccountingAccount($db);
738 $accountingaccount->fetch(0, $object->accountancy_code, 1);
739
740 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
741 }
742 print '</td></tr>';
743 } else {
744 print '<tr><td class="nowrap">';
745 print $langs->trans("AccountAccounting");
746 print '</td><td>';
747 print $object->accountancy_code;
748 print '</td></tr>';
749 }
750
751 // Subledger account
752 print '<tr><td class="nowrap">';
753 print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
754 print '</td><td>';
755 if ($action == 'editsubledger_account' && (!$alreadyaccounted && $permissiontoadd)) {
756 if (getDolGlobalString('ACCOUNTANCY_AUXACCOUNT_USE_SEARCH_TO_SELECT') > 0) {
758 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->subledger_account, 'subledger_account', 1, 1, '', 1);
759 } else {
760 print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', null, null, '', 1, 'lengthAccounta');
761 }
762 } else {
763 print length_accounta($object->subledger_account);
764 }
765 print '</td></tr>';
766
767 $bankaccountnotfound = 0;
768
769 if (isModEnabled('bank')) {
770 print '<tr>';
771 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
772 print '<td colspan="3">';
773 if ($object->fk_bank > 0) {
774 $bankline = new AccountLine($db);
775 $result = $bankline->fetch($object->fk_bank);
776
777 if ($result <= 0) {
778 $bankaccountnotfound = 1;
779 } else {
780 print $bankline->getNomUrl(1, 0, 'showall');
781 }
782 } else {
783 $bankaccountnotfound = 1;
784
785 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
786 }
787 print '</td>';
788 print '</tr>';
789 }
790
791 // Other attributes
792 $parameters = array('socid' => $object->id);
793 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
794
795 print '</table>';
796
797 print '</div>';
798
799 print '<div class="clearboth"></div>';
800
801 print dol_get_fiche_end();
802
803
804 /*
805 * Action bar
806 */
807 print '<div class="tabsAction">' . "\n";
808
809 // TODO
810 // Add button modify
811
812 // Clone
813 if ($permissiontoadd) {
814 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>";
815 }
816
817 // Delete
818 if (empty($object->rappro) || $bankaccountnotfound) {
819 if ($permissiontoadd) {
820 if ($alreadyaccounted) {
821 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
822 } else {
823 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token=' . newToken().'">'.$langs->trans("Delete").'</a></div>';
824 }
825 } else {
826 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
827 }
828 } else {
829 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
830 }
831
832 print "</div>";
833}
834
835// End of page
836llxFooter();
837$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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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:137
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.