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';
50require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
51if (isModEnabled('project')) {
52 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
54}
55
56// Load translation files required by the page
57$langs->loadLangs(array("accountancy", "banks", "bills", "categories", "compta", "users"));
58
59// Get parameters
60$id = GETPOSTINT('id');
61$action = GETPOST('action', 'alpha');
62$confirm = GETPOST('confirm');
63$cancel = GETPOST('cancel', 'alpha');
64$backtopage = GETPOST('backtopage', 'alpha');
65
66$accountid = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
67$label = GETPOST("label", "alpha");
68$sens = GETPOSTINT("sens");
69$amount = GETPOST("amount");
70$paymenttype = GETPOST("paymenttype", "aZ09");
71$accountancy_code = GETPOST("accountancy_code", "alpha");
72$fk_soc = GETPOSTINT('fk_soc');
73$projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : GETPOSTINT('fk_project');
74if (isModEnabled('accounting') && getDolGlobalString('ACCOUNTANCY_AUXACCOUNT_USE_SEARCH_TO_SELECT') > 0) {
75 $subledger_account = GETPOST("subledger_account", "alpha") > 0 ? GETPOST("subledger_account", "alpha") : '';
76} else {
77 $subledger_account = GETPOST("subledger_account", "alpha");
78}
79
80// Security check
81$socid = GETPOSTINT("socid");
82if ($user->socid) {
83 $socid = $user->socid;
84}
85
86// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
87$hookmanager->initHooks(array('variouscard', 'globalcard'));
88
89$result = restrictedArea($user, 'banque', '', '', '');
90// PaymentVarious::fetch() returns a record regardless of entity (low-level primitive), so the entity
91// restriction is enforced here in the caller: the various payment must belong to the current entity.
92if ($id > 0) {
93 $resqlent = $db->query("SELECT rowid FROM ".MAIN_DB_PREFIX."payment_various WHERE rowid = ".((int) $id)." AND entity IN (".getEntity('payment_various').")");
94 if (!$resqlent || !$db->num_rows($resqlent)) {
96 }
97}
98
99$object = new PaymentVarious($db);
100
101// Load object
102include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
103
104$extrafields->fetch_name_optionals_label($object->table_element);
105
106$permissiontoadd = $user->hasRight('banque', 'modifier');
107$permissiontodelete = $user->hasRight('banque', 'modifier');
108
109
114$parameters = array();
115$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
116if ($reshook < 0) {
117 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120if (empty($reshook)) {
121 if ($cancel) {
122 if ($action != 'addlink' && $action != 'setaccountancy_code' && $action != 'setsubledger_account') {
123 $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
124 header("Location: ".$urltogo);
125 exit;
126 }
127 $action = '';
128 }
129
130 // Link to a project
131 if ($action == 'classin' && $permissiontoadd) {
132 $object->setProject(GETPOSTINT('projectid'));
133 }
134
135 if ($action == 'add' && $permissiontoadd) {
136 $error = 0;
137
138 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
139 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
140 if (empty($datev)) {
141 $datev = $datep;
142 }
143
144 $object->ref = ''; // TODO
145 $object->fk_account = GETPOSTINT("accountid") > 0 ? GETPOSTINT("accountid") : 0;
146 $object->accountid = $object->fk_account;
147 $object->datev = $datev;
148 $object->datep = $datep;
149 $object->amount = GETPOSTFLOAT("amount");
150 $object->label = GETPOST("label", 'restricthtml');
151 $object->note_private = GETPOST("note", 'restricthtml');
152 $object->note = $object->note_private;
153 $object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1);
154 $object->num_payment = GETPOST("num_payment", 'alpha');
155 $object->chqemetteur = GETPOST("chqemetteur", 'alpha');
156 $object->chqbank = GETPOST("chqbank", 'alpha');
157 $object->fk_user_author = $user->id;
158 $object->category_transaction = GETPOSTINT("category_transaction");
159
160 $object->accountancy_code = (GETPOST("accountancy_code") != '-1' ? GETPOST("accountancy_code", "alpha") : "");
161 $object->subledger_account = $subledger_account;
162
163 $object->sens = GETPOSTINT('sens');
164 $object->fk_project = GETPOSTINT('fk_project');
165
166 if (getDolGlobalString('BANK_VARIOUS_PAYMENT_USE_THIRDPARTY')) {
167 $object->fk_soc = ($fk_soc > 0 ? $fk_soc : 0);
168 $object->socid = $object->fk_soc;
169 }
170
171 // Fill array 'array_options' with data from add form
172 $ret = $extrafields->setOptionalsFromPost(null, $object);
173 if ($ret < 0) {
174 $error++;
175 }
176
177 if (!checkGeneralAccountAllowsAuxiliary($db, $object->accountancy_code, $object->subledger_account)) {
178 setEventMessages($langs->trans("ErrorAccountNotCentralized"). ". " . $langs->trans("RemoveSubsidiaryAccountOrAdjustTheGeneralAccount"), null, 'errors');
179 $error++;
180 }
181 if (empty($datep) || empty($datev)) {
182 $langs->load('errors');
183 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
184 $error++;
185 }
186 if (empty($object->amount)) {
187 $langs->load('errors');
188 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
189 $error++;
190 }
191 if (isModEnabled("bank") && !$object->accountid > 0) {
192 $langs->load('errors');
193 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
194 $error++;
195 }
196 if (empty($object->type_payment) || $object->type_payment < 0) {
197 $langs->load('errors');
198 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
199 $error++;
200 }
201 if (isModEnabled('accounting') && !$object->accountancy_code) {
202 $langs->load('errors');
203 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
204 $error++;
205 }
206 if ($object->sens < 0) {
207 $langs->load('errors');
208 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
209 $error++;
210 }
211
212 $bankaccount = new Account($db);
213 if ($object->fk_account > 0) {
214 $bankaccount->fetch((int) $object->fk_account);
215 }
216
217 // Check currency
218 $currencyofpayment = $conf->currency; // The currency of various payment is not yet asked, so we suppose it is the main company currency
219
220 if (isModEnabled('multicurrency') && $currencyofpayment != $bankaccount->currency_code) {
221 // TODO Support this feature the same way we do it for invoice payment
222 // using the $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
223 setEventMessages($langs->trans("ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported"), null, 'errors');
224 $error++;
225 }
226
227 if (!$error) {
228 $db->begin();
229
230 $ret = $object->create($user);
231 if ($ret > 0) {
232 $db->commit();
233 $urltogo = ($backtopage ? $backtopage : dolBuildUrl(DOL_URL_ROOT.'/compta/bank/various_payment/list.php'));
234 header("Location: ".$urltogo);
235 exit;
236 } else {
237 $db->rollback();
238 setEventMessages($object->error, $object->errors, 'errors');
239 $action = "create";
240 }
241 }
242
243 $action = 'create';
244 }
245
246 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
247 if ($object->rappro == 0) {
248 $db->begin();
249
250 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
251 $ret = $object->delete($user);
252 if ($ret > 0) {
253 $accountline = null;
254 if ($object->fk_bank) {
255 $accountline = new AccountLine($db);
256 $result = $accountline->fetch($object->fk_bank);
257 if ($result > 0) {
258 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
259 }
260 }
261
262 if ($result >= 0) {
263 $db->commit();
264 header("Location: ".dolBuildUrl(DOL_URL_ROOT.'/compta/bank/various_payment/list.php'));
265 exit;
266 } else {
267 $object->error = $accountline ? $accountline->error : 'No AccountLine';
268 $db->rollback();
269 setEventMessages($object->error, $object->errors, 'errors');
270 }
271 } else {
272 $db->rollback();
273 setEventMessages($object->error, $object->errors, 'errors');
274 }
275 } else {
276 setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
277 }
278 }
279
280 if ($action == 'setaccountancy_code' && $permissiontodelete) {
281 $db->begin();
282
283 $object->accountancy_code = GETPOST('accountancy_code', 'alphanohtml');
284
285 $res = $object->update($user);
286 if ($res > 0) {
287 $db->commit();
288 } else {
289 $db->rollback();
290 setEventMessages($object->error, $object->errors, 'errors');
291 }
292 }
293
294 if ($action == 'setsubledger_account' && $permissiontodelete) {
295 $db->begin();
296
297 $object->subledger_account = $subledger_account;
298
299 $res = $object->update($user);
300 if ($res > 0) {
301 $db->commit();
302 } else {
303 $db->rollback();
304 setEventMessages($object->error, $object->errors, 'errors');
305 }
306 }
307}
308
309// Action clone object
310if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required
311 $action = '';
312}
313
314if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
315 $db->begin();
316
317 $originalId = $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 ($action != 'create' && ! $object->id) {
400}
401
402$title = $object->ref." - ".$langs->trans('Card');
403if ($action == 'create') {
404 $title = $langs->trans("NewVariousPayment");
405}
406$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
407llxHeader('', $title, $help_url);
408
409$options = array();
410
411// Load bank groups
412require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
413$bankcateg = new BankCateg($db);
414
415$arrayofbankcategs = $bankcateg->fetchAll();
416
417foreach ($arrayofbankcategs as $bankcategory) {
418 $options[$bankcategory->id] = $bankcategory->label;
419}
420
421// Create mode
422if ($action == 'create') {
423 // Update fields properties in realtime
424 if (!empty($conf->use_javascript_ajax)) {
425 ?>
426 <script type="text/javascript">
427 $(document).ready(function() {
428 setPaymentType();
429 $("#selectpaymenttype").change(function() {
430 setPaymentType();
431 });
432
433 function setPaymentType() {
434 console.log("setPaymentType");
435 var code = $("#selectpaymenttype option:selected").val();
436 if (code == "CHQ" || code == "VIR") {
437 if (code == 'CHQ') {
438 $('.fieldrequireddyn').addClass('fieldrequired');
439 }
440 if ($('#fieldchqemetteur').val() == '') {
441 var emetteur = jQuery('#thirdpartylabel').val();
442 $('#fieldchqemetteur').val(emetteur);
443 }
444 } else {
445 $(".fieldrequireddyn").removeClass("fieldrequired");
446 $("#fieldchqemetteur").val("");
447 }
448 }
449
450 function toggleSubledger() {
451 var isCentral = $("#accountancy_code option:selected").data("centralized");
452 console.log("the selected general ledger account is centralised?", isCentral);
453 if (isCentral) {
454 $("#subledger_account").prop("disabled", false);
455 } else {
456 $("#subledger_account").prop("disabled", true);
457 }
458 }
459 toggleSubledger();
460
461 $("#accountancy_code").on("change", toggleSubledger);
462 $("#accountancy_code").on("select2:select", toggleSubledger);
463 });
464 </script>
465 <?php
466 }
467
468 print '<form action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'" method="POST">';
469 print '<input type="hidden" name="token" value="'.newToken().'">';
470 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
471 print '<input type="hidden" name="action" value="add">';
472
473 print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
474
475 print dol_get_fiche_head([], '');
476
477 print '<table class="border centpercent">';
478
479 // Date payment
480 print '<tr><td class="titlefieldcreate">';
481 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
482 print $form->selectDate((empty($datep) ? -1 : $datep), "datep", 0, 0, 0, 'add', 1, 1);
483 print '</td></tr>';
484
485 // Date value for bank
486 print '<tr><td>';
487 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
488 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
489 print '</td></tr>';
490
491 // Label
492 print '<tr><td>';
493 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
494 print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
495 print '</td></tr>';
496
497 // Amount
498 print '<tr><td>';
499 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
500 print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
501 print ' '.$langs->getCurrencySymbol();
502 print '</td></tr>';
503
504 // Bank
505 if (isModEnabled("bank")) {
506 print '<tr><td>';
507 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
508 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
509 print $form->select_comptes($accountid, "accountid", 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), '', 1); // Show list of main accounts (comptes courants)
510 print '</td></tr>';
511 }
512
513 // Type payment
514 print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
515 $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
516 print "</td>\n";
517 print '</tr>';
518
519 // Number
520 if (isModEnabled("bank")) {
521 print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
522 print ' <em class="opacitymedium">('.$langs->trans("ChequeOrTransferNumber").')</em>';
523 print '</label></td>';
524 print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
525
526 // Check transmitter
527 print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
528 print ' <em class="opacitymedium">('.$langs->trans("ChequeMaker").')</em>';
529 print '</label></td>';
530 print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
531
532 // Bank name
533 print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
534 print ' <em class="opacitymedium">('.$langs->trans("ChequeBank").')</em>';
535 print '</label></td>';
536 print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
537 }
538
539 // Third party
540 if (getDolGlobalString('BANK_VARIOUS_PAYMENT_USE_THIRDPARTY')) {
541 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
542 print img_picto('', 'company', 'class="pictofixedwidth"');
543 print $form->select_company($fk_soc, 'fk_soc', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300 widthcentpercentminusx maxwidth500');
544 print '</td></tr>';
545 }
546
547 // Project
548 if (isModEnabled('project')) {
549 $formproject = new FormProjets($db);
550
551 // Associated project
552 $langs->load("projects");
553
554 print '<tr><td>'.$langs->trans("Project").'</td><td>';
555 print img_picto('', 'project', 'class="pictofixedwidth"');
556 print $formproject->select_projects(-1, (string) $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
557 print '</td></tr>';
558 }
559
560 // Other attributes
561 print $object->showOptionals($extrafields, 'create');
562
563 $parameters = array();
564 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
565 print $hookmanager->resPrint;
566
567 // Category
568 if (is_array($options) && count($options) && isModEnabled('category')) {
569 print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
570 print img_picto('', 'category', 'class="pictofixedwidth"') . Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
571 print '</td></tr>';
572 }
573
574 print '<tr><td colspan="2"><hr></td></tr>';
575
576 // Accountancy account
577 if (isModEnabled('accounting')) {
579 // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
580 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
581 print '<td>';
582 print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, array(), 1, 1);
583 print '</td></tr>';
584 } else { // For external software
585 print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
586 print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
587 print '</td></tr>';
588 }
589
590 // Subledger account
591 if (isModEnabled('accounting')) {
593 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
594 print '<td>';
595 print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
596 print '</td></tr>';
597 } else { // For external software
598 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
599 print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
600 print '</td></tr>';
601 }
602
603 // Sens
604 print '<tr><td>';
605 $labelsens = $form->textwithpicto($langs->trans('Sens'), $langs->trans("AccountingDirectionHelp"));
606 print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
607 $sensarray = array(
608 '0' => array('label' => $langs->trans("Debit")),
609 '1' => array('label' => $langs->trans("Credit"))
610 );
611 // We can't use this module to enter customer payments
612 include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
613 if (isALNERunningVersion()) {
614 $sensarray['1']['disabled'] = 1;
615 }
616
617 print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
618 print '</td></tr>';
619
620 print '</table>';
621
622 print dol_get_fiche_end();
623
624 print $form->buttonsSaveCancel();
625
626 print '</form>';
627}
628
629// View in read or edit mode
630if ($object->id > 0) {
631 $alreadyaccounted = $object->getVentilExportCompta();
632
633 $head = various_payment_prepare_head($object);
634
635 // Clone confirmation
636 if ($action === 'clone') {
637 $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
638 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
639
640 $formquestion = array(
641 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
642 array('type' => 'date', 'tdclass' => 'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
643 array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
644 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)),
645 array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
646 array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' ' . $set_value_help, 'values' => $sensarray, 'default' => (string) $object->sens),
647 );
648
649 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
650 }
651
652 // Confirmation of the removal of the Various Payment
653 if ($action == 'delete') {
654 $text = $langs->trans('ConfirmDeleteVariousPayment');
655 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
656 }
657
658 print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto, 0, '', '', 0, '', 1);
659
660 $morehtmlref = '<div class="refidno">';
661 // Project
662 if (isModEnabled('project') && $formproject !== null) {
663 $langs->load("projects");
664 //$morehtmlref .= '<br>';
665 if ($permissiontoadd) {
666 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
667 if ($action != 'classify') {
668 $morehtmlref .= '<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">' . img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
669 }
670 if ($action == 'classify') {
671 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
672 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
673 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
674 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
675 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
676 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
677 $morehtmlref .= '</form>';
678 } else {
679 $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');
680 }
681 } else {
682 if (!empty($object->fk_project)) {
683 $proj = new Project($db);
684 $proj->fetch($object->fk_project);
685 $morehtmlref .= $proj->getNomUrl(1);
686 if ($proj->title) {
687 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
688 }
689 }
690 }
691 }
692
693 $morehtmlref .= '</div>';
694 $linkback = '<a href="' . DOL_URL_ROOT . '/compta/bank/various_payment/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '').'">'.$langs->trans("BackToList").'</a>';
695
696 $morehtmlstatus = '';
697
698 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
699
700 print '<div class="fichecenter">';
701 print '<div class="underbanner clearboth"></div>';
702
703 print '<table class="border centpercent tableforfield">';
704
705 // Label
706 print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
707
708 // Thirdparty - optional
709 if (getDolGlobalString('BANK_VARIOUS_PAYMENT_USE_THIRDPARTY')) {
710 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
711 if ($object->fk_soc > 0) {
712 $thirdparty = new Societe($db);
713 if ($thirdparty->fetch($object->fk_soc) > 0) {
714 print $thirdparty->getNomUrl(1);
715 }
716 }
717 print '</td></tr>';
718 }
719
720 // Payment date
721 print "<tr>";
722 print '<td>'.$langs->trans("DatePayment").'</td><td>';
723 print dol_print_date($object->datep, 'day');
724 print '</td></tr>';
725
726 // Value date
727 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
728 print dol_print_date($object->datev, 'day');
729 print '</td></tr>';
730
731 // Debit / Credit
732 if ($object->sens == '1') {
733 $sens = $langs->trans("Credit");
734 } else {
735 $sens = $langs->trans("Debit");
736 }
737 print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
738
739 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
740
741 // Account of Chart of account
742 $editvalue = '';
743 if (isModEnabled('accounting')) {
745 print '<tr><td class="nowrap">';
746 print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
747 print '</td><td>';
748 if ($action == 'editaccountancy_code' && (!$alreadyaccounted && $permissiontoadd)) {
749 //print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->hasRight('banque', 'modifier')), 'string', '', 0);
750 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->accountancy_code, 'accountancy_code', 0, 1, '', 1);
751 } else {
752 $accountingaccount = new AccountingAccount($db);
753 $accountingaccount->fetch(0, $object->accountancy_code, 1);
754
755 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
756 }
757 print '</td></tr>';
758 } else {
759 print '<tr><td class="nowrap">';
760 print $langs->trans("AccountAccounting");
761 print '</td><td>';
762 print $object->accountancy_code;
763 print '</td></tr>';
764 }
765
766 // Subledger account
767 print '<tr><td class="nowrap">';
768 print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
769 print '</td><td>';
770 if ($action == 'editsubledger_account' && (!$alreadyaccounted && $permissiontoadd)) {
771 if (getDolGlobalString('ACCOUNTANCY_AUXACCOUNT_USE_SEARCH_TO_SELECT') > 0) {
773 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->subledger_account, 'subledger_account', 1, 1, '', 1);
774 } else {
775 print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', null, null, '', 1, 'lengthAccounta');
776 }
777 } else {
778 print length_accounta($object->subledger_account);
779 }
780 print '</td></tr>';
781
782 $bankaccountnotfound = 0;
783
784 if (isModEnabled('bank')) {
785 print '<tr>';
786 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
787 print '<td colspan="3">';
788 if ($object->fk_bank > 0) {
789 $bankline = new AccountLine($db);
790 $result = $bankline->fetch($object->fk_bank);
791
792 if ($result <= 0) {
793 $bankaccountnotfound = 1;
794 } else {
795 print $bankline->getNomUrl(1, 0, 'showall');
796 }
797 } else {
798 $bankaccountnotfound = 1;
799
800 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
801 }
802 print '</td>';
803 print '</tr>';
804 }
805
806 // Other attributes
807 $parameters = array('socid' => $object->id);
808 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
809
810 print '</table>';
811
812 print '</div>';
813
814 print '<div class="clearboth"></div>';
815
816 print dol_get_fiche_end();
817
818
819 /*
820 * Action bar
821 */
822 print '<div class="tabsAction">' . "\n";
823
824 // TODO
825 // Add button modify
826
827 // Clone
828 if ($permissiontoadd) {
829 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>';
830 }
831
832 // Delete
833 if (empty($object->rappro) || $bankaccountnotfound) {
834 if ($permissiontoadd) {
835 if ($alreadyaccounted) {
836 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
837 } else {
838 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";
839 }
840 } else {
841 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
842 }
843 } else {
844 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
845 }
846
847 print "</div>";
848}
849
850// End of page
851llxFooter();
852$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:281
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
Class to manage third parties objects (customers, suppliers, prospects...)
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, $currencycode='')
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:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
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.