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