dolibarr 22.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2024 Alexandre Spangaro <aspangaro@easya.solutions>
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("compta", "banks", "bills", "users", "accountancy", "categories"));
53
54// Get parameters
55$id = GETPOSTINT('id');
56$action = GETPOST('action', 'alpha');
57$confirm = GETPOST('confirm');
58$cancel = GETPOST('cancel');
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 (empty($datep) || empty($datev)) {
160 $langs->load('errors');
161 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
162 $error++;
163 }
164 if (empty($object->amount)) {
165 $langs->load('errors');
166 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
167 $error++;
168 }
169 if (isModEnabled("bank") && !$object->accountid > 0) {
170 $langs->load('errors');
171 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
172 $error++;
173 }
174 if (empty($object->type_payment) || $object->type_payment < 0) {
175 $langs->load('errors');
176 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
177 $error++;
178 }
179 if (isModEnabled('accounting') && !$object->accountancy_code) {
180 $langs->load('errors');
181 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
182 $error++;
183 }
184 if ($object->sens < 0) {
185 $langs->load('errors');
186 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
187 $error++;
188 }
189
190 $bankaccount = new Account($db);
191 $bankaccount->fetch($object->fk_account);
192
193 // Check currency
194 $currencyofpayment = $conf->currency; // The currency of various payment is not yet asked, so we suppose it is the main company currency
195
196 //var_dump($currencyofpayment); var_dump($bankaccount->currency_code);
197
198 if (isModEnabled('multicurrency') && $currencyofpayment != $bankaccount->currency_code) {
199 // TODO Support this feature the same way we do it for invoice payment
200 // using the $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
201 setEventMessages($langs->trans("ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported"), null, 'errors');
202 $error++;
203 }
204
205 if (!$error) {
206 $db->begin();
207
208 $ret = $object->create($user);
209 if ($ret > 0) {
210 $db->commit();
211 $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
212 header("Location: ".$urltogo);
213 exit;
214 } else {
215 $db->rollback();
216 setEventMessages($object->error, $object->errors, 'errors');
217 $action = "create";
218 }
219 }
220
221 $action = 'create';
222 }
223
224 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
225 $result = $object->fetch($id);
226
227 if ($object->rappro == 0) {
228 $db->begin();
229
230 $ret = $object->delete($user);
231 if ($ret > 0) {
232 $accountline = null;
233 if ($object->fk_bank) {
234 $accountline = new AccountLine($db);
235 $result = $accountline->fetch($object->fk_bank);
236 if ($result > 0) {
237 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
238 }
239 }
240
241 if ($result >= 0) {
242 $db->commit();
243 header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
244 exit;
245 } else {
246 $object->error = $accountline ? $accountline->error : 'No AccountLine';
247 $db->rollback();
248 setEventMessages($object->error, $object->errors, 'errors');
249 }
250 } else {
251 $db->rollback();
252 setEventMessages($object->error, $object->errors, 'errors');
253 }
254 } else {
255 setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
256 }
257 }
258
259 if ($action == 'setaccountancy_code' && $permissiontodelete) {
260 $db->begin();
261
262 $result = $object->fetch($id);
263
264 $object->accountancy_code = GETPOST('accountancy_code', 'alphanohtml');
265
266 $res = $object->update($user);
267 if ($res > 0) {
268 $db->commit();
269 } else {
270 $db->rollback();
271 setEventMessages($object->error, $object->errors, 'errors');
272 }
273 }
274
275 if ($action == 'setsubledger_account' && $permissiontodelete) {
276 $db->begin();
277
278 $result = $object->fetch($id);
279
280 $object->subledger_account = $subledger_account;
281
282 $res = $object->update($user);
283 if ($res > 0) {
284 $db->commit();
285 } else {
286 $db->rollback();
287 setEventMessages($object->error, $object->errors, 'errors');
288 }
289 }
290}
291
292// Action clone object
293if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required
294 $action = '';
295}
296
297if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
298 $db->begin();
299
300 $originalId = $id;
301
302 $object->fetch($id);
303
304 if ($object->id > 0) {
305 unset($object->id);
306 unset($object->ref);
307
308 if (GETPOST('clone_label', 'alphanohtml')) {
309 $object->label = GETPOST('clone_label', 'alphanohtml');
310 } else {
311 $object->label = $langs->trans("CopyOf").' '.$object->label;
312 }
313
314 $newdatepayment = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_paymentmonth'), GETPOSTINT('clone_date_paymentday'), GETPOSTINT('clone_date_paymentyear'));
315 $newdatevalue = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_valuemonth'), GETPOSTINT('clone_date_valueday'), GETPOSTINT('clone_date_valueyear'));
316 if ($newdatepayment) {
317 $object->datep = $newdatepayment;
318 }
319 if (!empty($newdatevalue)) {
320 $object->datev = $newdatevalue;
321 } else {
322 $object->datev = $newdatepayment;
323 }
324
325 if (GETPOSTISSET("clone_sens")) {
326 $object->sens = GETPOSTINT("clone_sens");
327 } // else { $object->sens = $object->sens; }
328
329 if (GETPOSTISSET("clone_amount")) {
330 $object->amount = GETPOSTFLOAT("clone_amount");
331 } else {
332 $object->amount = (float) price2num($object->amount);
333 }
334
335 if ($object->check()) {
336 $id = $object->create($user);
337 if ($id > 0) {
338 $db->commit();
339 $db->close();
340
341 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
342 exit;
343 } else {
344 $id = $originalId;
345 $db->rollback();
346
347 setEventMessages($object->error, $object->errors, 'errors');
348 }
349 } else {
350 $id = $originalId;
351 $db->rollback();
352
353 setEventMessages($object->error, $object->errors, 'errors');
354 }
355 } else {
356 $db->rollback();
357 dol_print_error($db, $object->error);
358 }
359}
360
361
362/*
363 * View
364 */
365
366$form = new Form($db);
367if (isModEnabled('accounting')) {
368 $formaccounting = new FormAccounting($db);
369} else {
370 $formaccounting = null;
371}
372if (isModEnabled('project')) {
373 $formproject = new FormProjets($db);
374} else {
375 $formproject = null;
376}
377
378if ($id) {
379 $object = new PaymentVarious($db);
380 $result = $object->fetch($id);
381 if ($result <= 0) {
382 dol_print_error($db);
383 exit;
384 }
385}
386
387$title = $object->ref." - ".$langs->trans('Card');
388if ($action == 'create') {
389 $title = $langs->trans("NewVariousPayment");
390}
391$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
392llxHeader('', $title, $help_url);
393
394$options = array();
395
396// Load bank groups
397require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
398$bankcateg = new BankCateg($db);
399
400$arrayofbankcategs = $bankcateg->fetchAll();
401
402foreach ($arrayofbankcategs as $bankcategory) {
403 $options[$bankcategory->id] = $bankcategory->label;
404}
405
406// Create mode
407if ($action == 'create') {
408 // Update fields properties in realtime
409 if (!empty($conf->use_javascript_ajax)) {
410 print "\n".'<script type="text/javascript">';
411 print '$(document).ready(function () {
412 setPaymentType();
413 $("#selectpaymenttype").change(function() {
414 setPaymentType();
415 });
416 function setPaymentType()
417 {
418 console.log("setPaymentType");
419 var code = $("#selectpaymenttype option:selected").val();
420 if (code == \'CHQ\' || code == \'VIR\')
421 {
422 if (code == \'CHQ\')
423 {
424 $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
425 }
426 if ($(\'#fieldchqemetteur\').val() == \'\')
427 {
428 var emetteur = jQuery(\'#thirdpartylabel\').val();
429 $(\'#fieldchqemetteur\').val(emetteur);
430 }
431 }
432 else
433 {
434 $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
435 $(\'#fieldchqemetteur\').val(\'\');
436 }
437 }
438 ';
439
440 print ' });'."\n";
441
442 print ' </script>'."\n";
443 }
444
445 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
446 print '<input type="hidden" name="token" value="'.newToken().'">';
447 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
448 print '<input type="hidden" name="action" value="add">';
449
450 print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
451
452 print dol_get_fiche_head([], '');
453
454 print '<table class="border centpercent">';
455
456 // Date payment
457 print '<tr><td class="titlefieldcreate">';
458 print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
459 print $form->selectDate((empty($datep) ? -1 : $datep), "datep", 0, 0, 0, 'add', 1, 1);
460 print '</td></tr>';
461
462 // Date value for bank
463 print '<tr><td>';
464 print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
465 print $form->selectDate((empty($datev) ? -1 : $datev), "datev", 0, 0, 0, 'add', 1, 1);
466 print '</td></tr>';
467
468 // Label
469 print '<tr><td>';
470 print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
471 print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
472 print '</td></tr>';
473
474 // Amount
475 print '<tr><td>';
476 print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
477 print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
478 print '</td></tr>';
479
480 // Bank
481 if (isModEnabled("bank")) {
482 print '<tr><td>';
483 print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
484 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
485 print $form->select_comptes($accountid, "accountid", 0, '', 2, '', (isModEnabled('multicurrency') ? 1 : 0), '', 1); // Show list of main accounts (comptes courants)
486 print '</td></tr>';
487 }
488
489 // Type payment
490 print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
491 $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
492 print "</td>\n";
493 print '</tr>';
494
495 // Number
496 if (isModEnabled("bank")) {
497 print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
498 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
499 print '</label></td>';
500 print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
501
502 // Check transmitter
503 print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
504 print ' <em>('.$langs->trans("ChequeMaker").')</em>';
505 print '</label></td>';
506 print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
507
508 // Bank name
509 print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
510 print ' <em>('.$langs->trans("ChequeBank").')</em>';
511 print '</label></td>';
512 print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
513 }
514
515 // Project
516 if (isModEnabled('project')) {
517 $formproject = new FormProjets($db);
518
519 // Associated project
520 $langs->load("projects");
521
522 print '<tr><td>'.$langs->trans("Project").'</td><td>';
523 print img_picto('', 'project', 'class="pictofixedwidth"');
524 print $formproject->select_projects(-1, (string) $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
525 print '</td></tr>';
526 }
527
528 // Other attributes
529 $parameters = array();
530 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
531 print $hookmanager->resPrint;
532
533 // Category
534 if (is_array($options) && count($options) && $conf->categorie->enabled) {
535 print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
536 print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
537 print '</td></tr>';
538 }
539
540 print '<tr><td colspan="2"><hr></td></tr>';
541
542 // Accountancy account
543 if (isModEnabled('accounting')) {
545 // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
546 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
547 print '<td>';
548 print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, array(), 1, 1);
549 print '</td></tr>';
550 } else { // For external software
551 print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
552 print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
553 print '</td></tr>';
554 }
555
556 // Subledger account
557 if (isModEnabled('accounting')) {
559 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
560 print '<td>';
561 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
562 print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
563 } else {
564 print '<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
565 }
566 print '</td></tr>';
567 } else { // For external software
568 print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
569 print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
570 print '</td></tr>';
571 }
572
573 // Sens
574 print '<tr><td>';
575 $labelsens = $form->textwithpicto($langs->trans('Sens'), $langs->trans("AccountingDirectionHelp"));
576 print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
577 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
578 print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
579 print '</td></tr>';
580
581 print '</table>';
582
583 print dol_get_fiche_end();
584
585 print $form->buttonsSaveCancel();
586
587 print '</form>';
588}
589
590// View in read or edit mode
591if ($id) {
592 $alreadyaccounted = $object->getVentilExportCompta();
593
595
596 // Clone confirmation
597 if ($action === 'clone') {
598 $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
599 $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
600
601 $formquestion = array(
602 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
603 array('type' => 'date', 'tdclass' => 'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
604 array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
605 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)),
606 array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
607 array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => (string) $object->sens),
608 );
609
610 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
611 }
612
613 // Confirmation of the removal of the Various Payment
614 if ($action == 'delete') {
615 $text = $langs->trans('ConfirmDeleteVariousPayment');
616 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
617 }
618
619 print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
620
621 $morehtmlref = '<div class="refidno">';
622 // Project
623 if (isModEnabled('project') && $formproject !== null) {
624 $langs->load("projects");
625 //$morehtmlref .= '<br>';
626 if ($permissiontoadd) {
627 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
628 if ($action != 'classify') {
629 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
630 }
631 if ($action == 'classify') {
632 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
633 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
634 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
635 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
636 $morehtmlref .= $formproject->select_projects(-1, (string) $object->fk_project, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
637 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
638 $morehtmlref .= '</form>';
639 } else {
640 $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');
641 }
642 } else {
643 if (!empty($object->fk_project)) {
644 $proj = new Project($db);
645 $proj->fetch($object->fk_project);
646 $morehtmlref .= $proj->getNomUrl(1);
647 if ($proj->title) {
648 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
649 }
650 }
651 }
652 }
653
654 $morehtmlref .= '</div>';
655 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
656
657 $morehtmlstatus = '';
658
659 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
660
661 print '<div class="fichecenter">';
662 print '<div class="underbanner clearboth"></div>';
663
664 print '<table class="border centpercent tableforfield">';
665
666 // Label
667 print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
668
669 // Payment date
670 print "<tr>";
671 print '<td>'.$langs->trans("DatePayment").'</td><td>';
672 print dol_print_date($object->datep, 'day');
673 print '</td></tr>';
674
675 // Value date
676 print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
677 print dol_print_date($object->datev, 'day');
678 print '</td></tr>';
679
680 // Debit / Credit
681 if ($object->sens == '1') {
682 $sens = $langs->trans("Credit");
683 } else {
684 $sens = $langs->trans("Debit");
685 }
686 print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
687
688 print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
689
690 // Account of Chart of account
691 $editvalue = '';
692 if (isModEnabled('accounting')) {
694 print '<tr><td class="nowrap">';
695 print $form->editfieldkey('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
696 print '</td><td>';
697 if ($action == 'editaccountancy_code' && (!$alreadyaccounted && $permissiontoadd)) {
698 //print $form->editfieldval('AccountAccounting', 'accountancy_code', $object->accountancy_code, $object, (!$alreadyaccounted && $user->hasRight('banque', 'modifier')), 'string', '', 0);
699 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code, 'accountancy_code', 0, 1, '', 1);
700 } else {
701 $accountingaccount = new AccountingAccount($db);
702 $accountingaccount->fetch(0, $object->accountancy_code, 1);
703
704 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
705 }
706 print '</td></tr>';
707 } else {
708 print '<tr><td class="nowrap">';
709 print $langs->trans("AccountAccounting");
710 print '</td><td>';
711 print $object->accountancy_code;
712 print '</td></tr>';
713 }
714
715 // Subledger account
716 print '<tr><td class="nowrap">';
717 print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (int) (!$alreadyaccounted && $permissiontoadd), 'string', '', 0);
718 print '</td><td>';
719 if ($action == 'editsubledger_account' && (!$alreadyaccounted && $permissiontoadd)) {
720 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
722 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->subledger_account, 'subledger_account', 1, 1, '', 1);
723 } else {
724 print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $permissiontoadd), 'string', '', null, null, '', 1, 'lengthAccounta');
725 }
726 } else {
727 print length_accounta($object->subledger_account);
728 }
729 print '</td></tr>';
730
731 $bankaccountnotfound = 0;
732
733 if (isModEnabled('bank')) {
734 print '<tr>';
735 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
736 print '<td colspan="3">';
737 if ($object->fk_bank > 0) {
738 $bankline = new AccountLine($db);
739 $result = $bankline->fetch($object->fk_bank);
740
741 if ($result <= 0) {
742 $bankaccountnotfound = 1;
743 } else {
744 print $bankline->getNomUrl(1, 0, 'showall');
745 }
746 } else {
747 $bankaccountnotfound = 1;
748
749 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
750 }
751 print '</td>';
752 print '</tr>';
753 }
754
755 // Other attributes
756 $parameters = array('socid' => $object->id);
757 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
758
759 print '</table>';
760
761 print '</div>';
762
763 print '<div class="clearboth"></div>';
764
765 print dol_get_fiche_end();
766
767
768 /*
769 * Action bar
770 */
771 print '<div class="tabsAction">'."\n";
772
773 // TODO
774 // Add button modify
775
776 // Clone
777 if ($permissiontoadd) {
778 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>";
779 }
780
781 // Delete
782 if (empty($object->rappro) || $bankaccountnotfound) {
783 if ($permissiontoadd) {
784 if ($alreadyaccounted) {
785 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
786 } else {
787 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
788 }
789 } else {
790 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
791 }
792 } else {
793 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
794 }
795
796 print "</div>";
797}
798
799// End of page
800llxFooter();
801$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
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:294
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.