dolibarr 25.0.0-alpha
bankentries_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2024 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Vinícius Nogueira <viniciusvgn@gmail.com>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-cooncept.pro>
7 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2017-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
13 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
49
50require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
51require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
52require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
53require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
54require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
55require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
56require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
57require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
58require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
59require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
60require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
61require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
62require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
63require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
64require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
65require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
66require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
67require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
68require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
69
70// Load translation files required by the page
71$langs->loadLangs(array("banks", "bills", "categories", "companies", "margins", "salaries", "loan", "donations", "trips", "members", "compta", "accountancy"));
72
73$id = GETPOSTINT('id');
74$ref = GETPOST('ref', 'alpha');
75$action = GETPOST('action', 'aZ09');
76$cancel = GETPOST('cancel', 'alpha');
77$confirm = GETPOST('confirm', 'alpha');
78$contextpage = 'bankentrieslist';
79$massaction = GETPOST('massaction', 'alpha');
80$optioncss = GETPOST('optioncss', 'aZ09');
81$mode = GETPOST('mode', 'aZ');
82
83$dateop = dol_mktime(12, 0, 0, GETPOSTINT("opmonth"), GETPOSTINT("opday"), GETPOSTINT("opyear"));
84$search_debit = GETPOST("search_debit", 'alpha');
85$search_credit = GETPOST("search_credit", 'alpha');
86$search_type = GETPOST("search_type", 'alpha');
87$search_account = GETPOST("search_account", 'int') ? GETPOST("search_account", 'int') : GETPOST("account", 'int');
88$search_accountancy_code = GETPOST('search_accountancy_code', 'alpha') ? GETPOST('search_accountancy_code', 'alpha') : GETPOST('accountancy_code', 'alpha');
89$search_bid = GETPOST("search_bid", 'int') ? GETPOST("search_bid", 'int') : GETPOST("bid", 'int'); // Category id
90$search_ref = GETPOST('search_ref', 'alpha');
91$search_description = GETPOST("search_description", 'alpha');
92$search_dt_start = dol_mktime(0, 0, 0, GETPOSTINT('search_start_dtmonth'), GETPOSTINT('search_start_dtday'), GETPOSTINT('search_start_dtyear'));
93$search_dt_end = dol_mktime(0, 0, 0, GETPOSTINT('search_end_dtmonth'), GETPOSTINT('search_end_dtday'), GETPOSTINT('search_end_dtyear'));
94$search_dv_start = dol_mktime(0, 0, 0, GETPOSTINT('search_start_dvmonth'), GETPOSTINT('search_start_dvday'), GETPOSTINT('search_start_dvyear'));
95$search_dv_end = dol_mktime(0, 0, 0, GETPOSTINT('search_end_dvmonth'), GETPOSTINT('search_end_dvday'), GETPOSTINT('search_end_dvyear'));
96$search_thirdparty_user = GETPOST("search_thirdparty", 'alpha') ? GETPOST("search_thirdparty", 'alpha') : GETPOST("thirdparty", 'alpha');
97$search_req_nb = GETPOST("req_nb", 'alpha');
98$search_num_releve = GETPOST("search_num_releve", 'alpha');
99$search_conciliated = GETPOST("search_conciliated", 'int');
100$search_fk_bordereau = GETPOST("search_fk_bordereau", 'int');
101$optioncss = GETPOST('optioncss', 'alpha');
102$toselect = GETPOST('toselect', 'array:int');
103$num_releve = GETPOST("num_releve", "alpha");
104if (empty($dateop)) {
105 $dateop = -1;
106}
107
108$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
109$sortfield = GETPOST('sortfield', 'aZ09comma');
110$sortorder = GETPOST('sortorder', 'aZ09comma');
111$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
112if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
113 // If $page is not defined, or '' or -1 or if we click on clear filters
114 $page = 0;
115}
116$offset = $limit * $page;
117$pageprev = $page - 1;
118$pagenext = $page + 1;
119if (!$sortorder) {
120 $sortorder = 'desc,desc,desc';
121}
122if (!$sortfield) {
123 $sortfield = 'b.datev,b.dateo,b.rowid';
124}
125
126$object = new Account($db);
127if ($id > 0 || !empty($ref)) {
128 $result = $object->fetch($id, $ref);
129 $search_account = $object->id; // Force the search field on id of account
130
131 if (!($object->id > 0)) {
132 recordNotFound('', 0);
133 }
134}
135
136// redefine contextpage to depend on bank account
137$contextpage = 'banktransactionlist'.(empty($object->id) ? '' : '-'.$object->id);
138
139$mode_balance_ok = false;
140//if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) // TODO Manage balance when account not selected
141if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) {
142 $sortfield = 'b.datev,b.dateo,b.rowid';
143 if ($id > 0 || !empty($ref) || $search_account > 0) {
144 $mode_balance_ok = true;
145 }
146}
147
148// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
149$hookmanager->initHooks(array('banktransactionlist', $contextpage));
150
151$extrafieldsobjectkey = 'bank'; // Used by extrafields_..._tpl.php
152
153// fetch optionals attributes and labels
154$extrafields->fetch_name_optionals_label($extrafieldsobjectkey);
155$search_array_options = $extrafields->getOptionalsFromPost($extrafieldsobjectkey, '', 'search_');
156
157$arrayfields = array(
158 'b.rowid' => array('label' => $langs->trans("Ref"), 'checked' => '1','position' => 10),
159 'b.label' => array('label' => $langs->trans("Description"), 'checked' => '1','position' => 20),
160 'b.dateo' => array('label' => $langs->trans("DateOperationShort"), 'checked' => '-1','position' => 30),
161 'b.datev' => array('label' => $langs->trans("DateValueShort"), 'checked' => '1','position' => 40),
162 'type' => array('label' => $langs->trans("Type"), 'checked' => '1','position' => 50),
163 'b.num_chq' => array('label' => $langs->trans("Numero"), 'checked' => '0','position' => 60),
164 'b.fk_bordereau' => array('label' => $langs->trans("ChequeNumber"), 'checked' => '0', 'position' => 65),
165 'bu.label' => array('label' => $langs->trans("ThirdParty").'/'.$langs->trans("User"), 'checked' => '1', 'position' => 70),
166 'ba.ref' => array('label' => $langs->trans("BankAccount"), 'checked' => (($id > 0 || !empty($ref)) ? '0' : '1'), 'position' => 80),
167 'b.debit' => array('label' => $langs->trans("Debit"), 'checked' => '1', 'position' => 90),
168 'b.credit' => array('label' => $langs->trans("Credit"), 'checked' => '1', 'position' => 100),
169 'balancebefore' => array('label' => $langs->trans("BalanceBefore"), 'checked' => '0', 'position' => 110),
170 'balance' => array('label' => $langs->trans("Balance"), 'checked' => '1', 'position' => 120),
171 'b.num_releve' => array('label' => $langs->trans("AccountStatement"), 'checked' => '1', 'position' => 130),
172 'b.conciliated' => array('label' => $langs->trans("BankLineReconciled"), 'enabled' => (string) (int) $object->rappro, 'checked' => ($action == 'reconcile' ? '1' : '0'), 'position' => 140),
173);
174// Extra fields
175include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
176// Add hook to complete $arrayfield
177$parameters = array('arrayfields' => &$arrayfields);
178$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
179
180$object->fields = dol_sort_array($object->fields, 'position');
181$arrayfields = dol_sort_array($arrayfields, 'position');
182
183// Security check
184$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
185$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
186if ($fieldvalue) {
187 if ($user->socid) {
188 $socid = $user->socid;
189 }
190 $result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account&bank_account', '', '', $fieldtype);
191} else {
192 if ($user->socid) {
193 $socid = $user->socid;
194 }
195 $result = restrictedArea($user, 'banque');
196}
197
198
199/*
200 * Actions
201 */
202
203if (GETPOST('cancel', 'alpha')) {
204 $action = 'list';
205 $massaction = '';
206}
207if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
208 $massaction = '';
209}
210
211$parameters = array();
212$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
213if ($reshook < 0) {
214 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
215}
216
217include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
218
219if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
220 $search_dt_start = '';
221 $search_dt_end = '';
222 $search_dv_start = '';
223 $search_dv_end = '';
224 $search_type = "";
225 $search_debit = "";
226 $search_credit = "";
227 $search_bid = "";
228 $search_ref = "";
229 $search_req_nb = '';
230 $search_description = '';
231 $search_thirdparty_user = '';
232 $search_num_releve = '';
233 $search_conciliated = '';
234 $search_fk_bordereau = '';
235 $toselect = array();
236
237 $search_account = "";
238 if ($id > 0 || !empty($ref)) {
239 $search_account = $object->id;
240 }
241}
242
243if (empty($reshook)) {
244 $objectclass = 'Account';
245 $objectlabel = 'BankTransaction';
246 $permissiontoread = $user->hasRight('banque', 'lire');
247 $permissiontodelete = $user->hasRight('banque', 'modifier');
248 $uploaddir = $conf->bank->dir_output;
249 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
250}
251
252$rowids = GETPOST('rowid', 'array:int');
253
254// Conciliation
255if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', 'alpha'))
256 && (GETPOST("num_releve", "alpha") || !empty($rowids))
257 && $user->hasRight('banque', 'consolidate')
258 && (!GETPOSTISSET('pageplusone') || (GETPOST('pageplusone') == GETPOST('pageplusoneold')))) {
259 $error = 0;
260
261 // Definition, nettoyage parameters
262 $num_releve = GETPOST("num_releve", "alpha");
263
264 if ($num_releve) {
265 $bankline = new AccountLine($db);
266
267 $rowids = GETPOST('rowid', 'array:int');
268
269 if (!empty($rowids) && is_array($rowids)) {
270 foreach ($rowids as $row) {
271 if ($row > 0) {
272 $result = $bankline->fetch($row);
273 $bankline->num_releve = $num_releve; // GETPOST("num_releve");
274 $result = $bankline->update_conciliation($user, GETPOSTINT("cat"), GETPOST('confirm_reconcile', 'alpha') ? 1 : 0); // If we confirm_reconcile, we set flag 'rappro' to 1.
275 if ($result < 0) {
276 setEventMessages($bankline->error, $bankline->errors, 'errors');
277 $error++;
278 break;
279 }
280 }
281 }
282 if (!$error && count($rowids) > 0) {
283 setEventMessages($langs->trans("XNewLinesConciliated", count($rowids)), null);
284 }
285 } else {
286 $error++;
287 $langs->load("errors");
288 setEventMessages($langs->trans("NoRecordSelected"), null, 'errors');
289 }
290 } else {
291 $error++;
292 $langs->load("errors");
293 setEventMessages($langs->trans("ErrorPleaseTypeBankTransactionReportName"), null, 'errors');
294 }
295
296 if (!$error) {
297 $param = 'action=reconcile&contextpage=banktransactionlist&id='.((int) $object->id).'&search_account='.((int) $object->id);
298 if ($page) {
299 $param .= '&page='.urlencode((string) ($page));
300 }
301 if ($offset) {
302 $param .= '&offset='.urlencode((string) ($offset));
303 }
304 if ($limit) {
305 $param .= '&limit='.((int) $limit);
306 }
307 if ($search_conciliated != '' && $search_conciliated != '-1') {
308 $param .= '&search_conciliated='.urlencode((string) ($search_conciliated));
309 }
310 if ($search_thirdparty_user) {
311 $param .= '&search_thirdparty='.urlencode($search_thirdparty_user);
312 }
313 if ($search_num_releve) {
314 $param .= '&search_num_releve='.urlencode($search_num_releve);
315 }
316 if ($search_description) {
317 $param .= '&search_description='.urlencode($search_description);
318 }
319 if (dol_strlen($search_dt_start) > 0) {
320 $param .= '&search_start_dtmonth='.GETPOSTINT('search_start_dtmonth').'&search_start_dtday='.GETPOSTINT('search_start_dtday').'&search_start_dtyear='.GETPOSTINT('search_start_dtyear');
321 }
322 if (dol_strlen($search_dt_end) > 0) {
323 $param .= '&search_end_dtmonth='.GETPOSTINT('search_end_dtmonth').'&search_end_dtday='.GETPOSTINT('search_end_dtday').'&search_end_dtyear='.GETPOSTINT('search_end_dtyear');
324 }
325 if (dol_strlen($search_dv_start) > 0) {
326 $param .= '&search_start_dvmonth='.GETPOSTINT('search_start_dvmonth').'&search_start_dvday='.GETPOSTINT('search_start_dvday').'&search_start_dvyear='.GETPOSTINT('search_start_dvyear');
327 }
328 if (dol_strlen($search_dv_end) > 0) {
329 $param .= '&search_end_dvmonth='.GETPOSTINT('search_end_dvmonth').'&search_end_dvday='.GETPOSTINT('search_end_dvday').'&search_end_dvyear='.GETPOSTINT('search_end_dvyear');
330 }
331 if ($search_type) {
332 $param .= '&search_type='.urlencode($search_type);
333 }
334 if ($search_debit) {
335 $param .= '&search_debit='.urlencode($search_debit);
336 }
337 if ($search_credit) {
338 $param .= '&search_credit='.urlencode($search_credit);
339 }
340 $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
341 header('Location: '.$_SERVER["PHP_SELF"].'?'.$param); // To avoid to submit twice and allow the back button
342 exit;
343 }
344}
345
346
347if (GETPOST('save') && !$cancel && $user->hasRight('banque', 'modifier')) {
348 $error = 0;
349
350 if (price2num(GETPOST("addcredit")) > 0) {
351 $amount = price2num(GETPOST("addcredit"));
352 } else {
353 $amount = price2num(-1 * (float) price2num(GETPOST("adddebit")));
354 }
355
356 $operation = GETPOST("operation", 'alpha');
357 $num_chq = GETPOST("num_chq", 'alpha');
358 $label = GETPOST("label", 'alpha');
359 $cat1 = GETPOST("cat1", 'alpha');
360
361 $bankaccountid = $id;
362 if (GETPOSTINT('add_account') > 0) {
363 $bankaccountid = GETPOSTINT('add_account');
364 }
365 if (!$dateop) {
366 $error++;
367 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
368 }
369 if (!$operation) {
370 $error++;
371 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
372 }
373 if (!$label) {
374 $error++;
375 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
376 }
377 if (!$amount) {
378 $error++;
379 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
380 }
381 if (!($bankaccountid > 0)) {
382 $error++;
383 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
384 }
385 /*if (isModEnabled('accounting') && (empty($search_accountancy_code) || $search_accountancy_code == '-1'))
386 {
387 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
388 $error++;
389 }*/
390
391 if (!$error && getDolGlobalString('BANK_USE_OLD_VARIOUS_PAYMENT')) {
392 $objecttmp = new Account($db);
393 $objecttmp->fetch($bankaccountid);
394 $insertid = $objecttmp->addline((int) $dateop, $operation, $label, (float) $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code);
395 if ($insertid > 0) {
396 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
397 header("Location: ".$_SERVER['PHP_SELF'].($id ? "?id=".$id : ''));
398 exit;
399 } else {
400 setEventMessages($object->error, $object->errors, 'errors');
401 }
402 } else {
403 $action = 'addline';
404 }
405}
406
407if ($action == 'confirm_deleteonreconcile' && $confirm == 'yes' && $user->hasRight('banque', 'modifier')) {
408 $accline = new AccountLine($db);
409 $result = $accline->fetch(GETPOSTINT("rowid"));
410 $result = $accline->delete($user);
411 if ($result <= 0) {
412 setEventMessages($accline->error, $accline->errors, 'errors');
413 } else {
414 setEventMessages('RecordDeleted', null, 'mesgs');
415 }
416
417 $action = 'reconcile';
418}
419
420if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('banque', 'modifier')) {
421 $accline = new AccountLine($db);
422 $result = $accline->fetch(GETPOSTINT("rowid"));
423 $result = $accline->delete($user);
424 if ($result <= 0) {
425 setEventMessages($accline->error, $accline->errors, 'errors');
426 } else {
427 setEventMessages('RecordDeleted', null, 'mesgs');
428 }
429}
430
431
432/*
433 * View
434 */
435
436$form = new Form($db);
437$formother = new FormOther($db);
438$formaccounting = new FormAccounting($db);
439
440$companystatic = new Societe($db);
441$bankaccountstatic = new Account($db);
442$userstatic = new User($db);
443
444$banktransferstatic = new BonPrelevement($db);
445$societestatic = new Societe($db);
446$userstatic = new User($db);
447$chargestatic = new ChargeSociales($db);
448$loanstatic = new Loan($db);
449$memberstatic = new Adherent($db);
450$donstatic = new Don($db);
451$paymentstatic = new Paiement($db);
452$paymentsupplierstatic = new PaiementFourn($db);
453$paymentscstatic = new PaymentSocialContribution($db);
454$paymentvatstatic = new PaymentVAT($db);
455$paymentsalstatic = new PaymentSalary($db);
456$paymentdonationstatic = new PaymentDonation($db);
457$paymentvariousstatic = new PaymentVarious($db);
458$paymentexpensereportstatic = new PaymentExpenseReport($db);
459$bankstatic = new Account($db);
460$banklinestatic = new AccountLine($db);
461$bordereaustatic = new RemiseCheque($db);
462
463$now = dol_now();
464
465// Must be before button action
466$param = '';
467if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
468 $param .= '&contextpage='.urlencode($contextpage);
469}
470if ($limit > 0 && $limit != $conf->liste_limit) {
471 $param .= '&limit='.((int) $limit);
472}
473if ($id > 0) {
474 $param .= '&id='.urlencode((string) ($id));
475}
476if (!empty($ref)) {
477 $param .= '&ref='.urlencode($ref);
478}
479if (!empty($search_ref)) {
480 $param .= '&search_ref='.urlencode($search_ref);
481}
482if (!empty($search_description)) {
483 $param .= '&search_description='.urlencode($search_description);
484}
485if (!empty($search_type)) {
486 $param .= '&type='.urlencode($search_type);
487}
488if (!empty($search_thirdparty_user)) {
489 $param .= '&search_thirdparty='.urlencode($search_thirdparty_user);
490}
491if (!empty($search_debit)) {
492 $param .= '&search_debit='.urlencode($search_debit);
493}
494if (!empty($search_credit)) {
495 $param .= '&search_credit='.urlencode($search_credit);
496}
497if ($search_account > 0) {
498 $param .= '&search_account='.((int) $search_account);
499}
500if (!empty($search_num_releve)) {
501 $param .= '&search_num_releve='.urlencode($search_num_releve);
502}
503if ($search_conciliated != '' && $search_conciliated != '-1') {
504 $param .= '&search_conciliated='.urlencode((string) ($search_conciliated));
505}
506if ($search_fk_bordereau > 0) {
507 $param .= '$&search_fk_bordereau='.urlencode((string) ($search_fk_bordereau));
508}
509if ($search_bid > 0) { // Category id
510 $param .= '&search_bid='.((int) $search_bid);
511}
512if (dol_strlen($search_dt_start) > 0) {
513 $param .= '&search_start_dtmonth='.GETPOSTINT('search_start_dtmonth').'&search_start_dtday='.GETPOSTINT('search_start_dtday').'&search_start_dtyear='.GETPOSTINT('search_start_dtyear');
514}
515if (dol_strlen($search_dt_end) > 0) {
516 $param .= '&search_end_dtmonth='.GETPOSTINT('search_end_dtmonth').'&search_end_dtday='.GETPOSTINT('search_end_dtday').'&search_end_dtyear='.GETPOSTINT('search_end_dtyear');
517}
518if (dol_strlen($search_dv_start) > 0) {
519 $param .= '&search_start_dvmonth='.GETPOSTINT('search_start_dvmonth').'&search_start_dvday='.GETPOSTINT('search_start_dvday').'&search_start_dvyear='.GETPOSTINT('search_start_dvyear');
520}
521if (dol_strlen($search_dv_end) > 0) {
522 $param .= '&search_end_dvmonth='.GETPOSTINT('search_end_dvmonth').'&search_end_dvday='.GETPOSTINT('search_end_dvday').'&search_end_dvyear='.GETPOSTINT('search_end_dvyear');
523}
524if ($search_req_nb) {
525 $param .= '&req_nb='.urlencode($search_req_nb);
526}
527if (GETPOSTINT("search_thirdparty")) {
528 $param .= '&thirdparty='.urlencode((string) (GETPOSTINT("search_thirdparty")));
529}
530if ($optioncss != '') {
531 $param .= '&optioncss='.urlencode($optioncss);
532}
533if ($action == 'reconcile' || $action == 'confirm_deleteonreconcile') {
534 $param .= '&action=reconcile';
535}
536$totalarray = array(
537 'nbfield' => 0,
538 'totalcred' => 0,
539 'totaldeb' => 0,
540);
541// Add $param from extra fields
542include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
543
544$options = array();
545
546$buttonreconcile = '';
547$morehtmlref = '';
548
549if ($id > 0 || !empty($ref)) {
550 $title = $object->ref.' - '.$langs->trans("Transactions");
551} else {
552 $title = $langs->trans("BankTransactions");
553}
554$help_url = '';
555
556llxHeader('', $title, $help_url, '', 0, 0, array(), array(), $param);
557
558
559if ($id > 0 || !empty($ref)) {
560 // Load bank groups
561 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
562 $bankcateg = new BankCateg($db);
563
564 $arrayofbankcateg = $bankcateg->fetchAll();
565 foreach ($arrayofbankcateg as $bankcategory) {
566 $options[$bankcategory->id] = $bankcategory->label;
567 }
568
569 // Bank card
570 $head = bank_prepare_head($object);
571 $activetab = 'journal';
572 if ($action == 'reconcile' || $action == 'confirm_deleteonreconcile') {
573 $activetab = 'reconcile';
574 }
575 print dol_get_fiche_head($head, $activetab, $langs->trans("FinancialAccount"), 0, 'account');
576
577 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
578
579 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
580
581 print dol_get_fiche_end();
582}
583
584$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro as conciliated, b.num_releve, b.num_chq,";
585$sql .= " b.fk_account, b.fk_type, b.fk_bordereau,";
586$sql .= " ba.rowid as bankid, ba.ref as bankref";
587// Add fields from extrafields
588if (!empty($extrafields->attributes[$extrafieldsobjectkey]['label'])) {
589 foreach ($extrafields->attributes[$extrafieldsobjectkey]['label'] as $key => $val) {
590 $sql .= ($extrafields->attributes[$extrafieldsobjectkey]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
591 }
592}
593// Add fields from hooks
594$parameters = array();
595$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
596$sql .= $hookmanager->resPrint;
597$sql .= " FROM ";
598if ($search_bid > 0) {
599 $sql .= MAIN_DB_PREFIX."category_bankline as l,";
600}
601$sql .= " ".MAIN_DB_PREFIX."bank_account as ba,";
602$sql .= " ".MAIN_DB_PREFIX."bank as b";
603if (!empty($extrafields->attributes[$extrafieldsobjectkey]['label']) && is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) {
604 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$extrafieldsobjectkey."_extrafields as ef on (b.rowid = ef.fk_object)";
605}
606
607// Add fields from hooks
608$parameters = array();
609$reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
610$sql .= $hookmanager->resPrint;
611
612$sql .= " WHERE b.fk_account = ba.rowid";
613$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
614if ($search_account > 0) {
615 $sql .= " AND b.fk_account = ".((int) $search_account);
616}
617// Search period criteria
618if (dol_strlen($search_dt_start) > 0) {
619 $sql .= " AND b.dateo >= '".$db->idate($search_dt_start)."'";
620}
621if (dol_strlen($search_dt_end) > 0) {
622 $sql .= " AND b.dateo <= '".$db->idate($search_dt_end)."'";
623}
624// Search period criteria
625if (dol_strlen($search_dv_start) > 0) {
626 $sql .= " AND b.datev >= '".$db->idate($search_dv_start)."'";
627}
628if (dol_strlen($search_dv_end) > 0) {
629 $sql .= " AND b.datev <= '".$db->idate($search_dv_end)."'";
630}
631if ($search_ref) {
632 $sql .= natural_search("b.rowid", $search_ref, 1);
633}
634if ($search_req_nb) {
635 $sql .= natural_search("b.num_chq", $search_req_nb);
636}
637if ($search_num_releve) {
638 $sql .= natural_search("b.num_releve", $search_num_releve);
639}
640if ($search_conciliated != '' && $search_conciliated != '-1') {
641 $sql .= " AND b.rappro = ".((int) $search_conciliated);
642}
643if ($search_fk_bordereau > 0) {
644 $sql .= " AND b.fk_bordereau = " . ((int) $search_fk_bordereau);
645}
646if ($search_thirdparty_user) {
647 $sql .= " AND (b.rowid IN ";
648 $sql .= " ( SELECT bu.fk_bank FROM ".MAIN_DB_PREFIX."bank_url AS bu";
649 $sql .= " JOIN ".MAIN_DB_PREFIX."bank AS b2 ON b2.rowid = bu.fk_bank";
650 $sql .= " JOIN ".MAIN_DB_PREFIX."user AS subUser ON (bu.type = 'user' AND bu.url_id = subUser.rowid)";
651 $sql .= " WHERE ". natural_search(array("subUser.firstname", "subUser.lastname"), $search_thirdparty_user, 0, 1).")";
652
653 $sql .= " OR b.rowid IN ";
654 $sql .= " ( SELECT bu.fk_bank FROM ".MAIN_DB_PREFIX."bank_url AS bu";
655 $sql .= " JOIN ".MAIN_DB_PREFIX."bank AS b2 ON b2.rowid = bu.fk_bank";
656 $sql .= " JOIN ".MAIN_DB_PREFIX."societe AS subSoc ON (bu.type = 'company' AND bu.url_id = subSoc.rowid)";
657 $sql .= " WHERE ". natural_search(array("subSoc.nom"), $search_thirdparty_user, 0, 1);
658 $sql .= "))";
659}
660if ($search_description) {
661 $search_description_to_use = $search_description;
662 $arrayoffixedlabels = array(
663 'payment_salary',
664 'CustomerInvoicePayment',
665 'CustomerInvoicePaymentBack',
666 'SupplierInvoicePayment',
667 'SupplierInvoicePaymentBack',
668 'DonationPayment',
669 'ExpenseReportPayment',
670 'SocialContributionPayment',
671 'SubscriptionPayment',
672 'WithdrawalPayment'
673 );
674 foreach ($arrayoffixedlabels as $keyforlabel) {
675 $translatedlabel = $langs->transnoentitiesnoconv($keyforlabel);
676 if (preg_match('/'.$search_description.'/i', $translatedlabel)) {
677 $search_description_to_use .= "|".$keyforlabel;
678 }
679 }
680 $sql .= natural_search("b.label", $search_description_to_use); // Warning some text are just translation keys, not translated strings
681}
682
683if ($search_bid > 0) {
684 $sql .= " AND b.rowid = l.lineid AND l.fk_categ = ".((int) $search_bid);
685}
686if (!empty($search_type)) {
687 $sql .= " AND b.fk_type = '".$db->escape($search_type)."'";
688}
689// Search criteria amount
690if ($search_debit) {
691 $sql .= natural_search('-b.amount', $search_debit, 1);
692 $sql .= ' AND b.amount <= 0';
693}
694if ($search_credit) {
695 $sql .= natural_search('b.amount', $search_credit, 1);
696 $sql .= ' AND b.amount >= 0';
697}
698// Add where from extra fields
699include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
700
701// Add where from hooks
702$parameters = array();
703$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
704$sql .= $hookmanager->resPrint;
705
706$sql .= $db->order($sortfield, $sortorder);
707
708$nbtotalofrecords = '';
709$nbtotalofpages = 0;
710if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
711 $result = $db->query($sql);
712 $nbtotalofrecords = $db->num_rows($result);
713 $nbtotalofpages = ceil($nbtotalofrecords / $limit);
714}
715
716if ($page >= $nbtotalofpages) {
717 // If we made a search and result has low page than the page number we were on
718 $page = ($nbtotalofpages - 1);
719 $offset = $limit * $page;
720 if ($page < 0) {
721 $page = 0;
722 }
723}
724
725
726// If not account defined $mode_balance_ok=false
727if (empty($search_account)) {
728 $mode_balance_ok = false;
729}
730// If a search is done $mode_balance_ok=false
731if (!empty($search_ref)) {
732 $mode_balance_ok = false;
733}
734if (!empty($search_description)) {
735 $mode_balance_ok = false;
736}
737if (!empty($search_type)) {
738 $mode_balance_ok = false;
739}
740if (!empty($search_debit)) {
741 $mode_balance_ok = false;
742}
743if (!empty($search_credit)) {
744 $mode_balance_ok = false;
745}
746if (!empty($search_thirdparty_user)) {
747 $mode_balance_ok = false;
748}
749if ($search_conciliated != '' && $search_conciliated != '-1') {
750 $mode_balance_ok = false;
751}
752if (!empty($search_num_releve)) {
753 $mode_balance_ok = false;
754}
755if (!empty($search_fk_bordereau)) {
756 $mode_balance_ok = false;
757}
758
759$sql .= $db->plimit($limit + 1, $offset);
760//print $sql;
761dol_syslog('compta/bank/bankentries_list.php', LOG_DEBUG);
762$resql = $db->query($sql);
763if ($resql) {
764 $num = $db->num_rows($resql);
765
766 $arrayofselected = (!empty($toselect) && is_array($toselect)) ? $toselect : array();
767
768 // List of mass actions available
769 $arrayofmassactions = array(
770 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
771 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
772 );
773 if (in_array($massaction, array('presend', 'predelete'))) {
774 $arrayofmassactions = array();
775 }
776 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
777
778 // Confirmation delete
779 if ($action == 'delete') {
780 $text = $langs->trans('ConfirmDeleteTransaction');
781 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.GETPOSTINT("rowid"), $langs->trans('DeleteTransaction'), $text, 'confirm_delete', null, '', 1);
782 }
783
784 // Lines of title fields
785 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="search_form" spellcheck="false">'."\n";
786 if ($optioncss != '') {
787 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
788 }
789 print '<input type="hidden" name="token" value="'.newToken().'">';
790 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
791 print '<input type="hidden" name="action" value="'.($action != 'delete' ? $action : 'search').'">';
792 if (!empty($mode)) {
793 print '<input type="hidden" name="mode" value="'.dol_escape_htmltag($mode).'">';
794 }
795 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
796 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
797 print '<input type="hidden" name="page" value="'.$page.'">';
798 print '<input type="hidden" name="id" value="'.$id.'">';
799 print '<input type="hidden" name="ref" value="'.$ref.'">';
800 if (GETPOSTINT('bid')) {
801 print '<input type="hidden" name="bid" value="'.GETPOSTINT("bid").'">';
802 }
803
804 // Form to add a transaction with no invoice
805 if ($user->hasRight('banque', 'modifier') && $action == 'addline' && getDolGlobalString('BANK_USE_OLD_VARIOUS_PAYMENT')) {
806 print load_fiche_titre($langs->trans("AddBankRecordLong"), '', '');
807
808 print '<table class="noborder centpercent">';
809
810 print '<tr class="liste_titre">';
811 print '<td>'.$langs->trans("Description").'</td>';
812 print '<td>'.$langs->trans("Date").'</td>';
813 print '<td>&nbsp;</td>';
814 print '<td>'.$langs->trans("Type").'</td>';
815 print '<td>'.$langs->trans("Numero").'</td>';
816 print '<td class=right>'.$langs->trans("BankAccount").'</td>';
817 print '<td class=right>'.$langs->trans("Debit").'</td>';
818 print '<td class=right>'.$langs->trans("Credit").'</td>';
819 /*if (isModEnabled('accounting'))
820 {
821 print '<td class="center">';
822 print $langs->trans("AccountAccounting");
823 print '</td>';
824 }*/
825 print '<td class="center">&nbsp;</td>';
826 print '</tr>';
827
828 print '<tr>';
829 print '<td>';
830 print '<input name="label" class="flat minwidth200" type="text" value="'.GETPOST("label", "alpha").'">';
831 if (is_array($options) && count($options)) {
832 print '<br>'.$langs->trans("Rubrique").': ';
833 print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
834 }
835 print '</td>';
836 print '<td class="nowrap">';
837 print $form->selectDate(empty($dateop) ? -1 : $dateop, 'op', 0, 0, 0, 'transaction');
838 print '</td>';
839 print '<td>&nbsp;</td>';
840 print '<td class="nowrap">';
841 print $form->select_types_paiements((GETPOST('operation') ? GETPOST('operation') : ($object->type == Account::TYPE_CASH ? 'LIQ' : '')), 'operation', '1,2', 2, 1, 0, 0, 1, '', 1);
842 print '</td>';
843 print '<td>';
844 print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq", "alpha").'">';
845 print '</td>';
846 //if (! $search_account > 0)
847 //{
848 print '<td class=right>';
849 print $form->select_comptes(GETPOSTINT('add_account') ? GETPOSTINT('add_account') : $search_account, 'add_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, '', 1);
850 print '</td>';
851 //}
852 print '<td class="right"><input name="adddebit" class="flat" type="text" size="4" value="'.GETPOST("adddebit", "alpha").'"></td>';
853 print '<td class="right"><input name="addcredit" class="flat" type="text" size="4" value="'.GETPOST("addcredit", "alpha").'"></td>';
854 /*if (isModEnabled('accounting'))
855 {
856 print '<td class="center">';
857 print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, null, 1, 1, '');
858 print '</td>';
859 }*/
860 print '<td class="center">';
861 print '<input type="submit" name="save" class="button buttongen marginbottomonly button-add" value="'.$langs->trans("Add").'"><br>';
862 print '<input type="submit" name="cancel" class="button buttongen marginbottomonly button-cancel" value="'.$langs->trans("Cancel").'">';
863 print '</td></tr>';
864
865 print '</table>';
866 print '<br>';
867 }
868
869 // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page
870 $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?format=dayreduceformat&token='.currentToken();
871 print '
872 <script type="text/javascript">
873 $(function() {
874 $("a.ajaxforbankoperationchange").each(function(){
875 var current = $(this);
876 current.click(function()
877 {
878 var url = "'.$urlajax.'&"+current.attr("href").split("?")[1];
879 console.log("We click on ajaxforbankoperationchange url="+url);
880 $.get(url, function(data)
881 {
882 console.log(data);
883 current.parent().parent().find(".spanforajaxedit").replaceWith(data);
884 });
885 return false;
886 });
887 });
888 });
889 </script>
890 ';
891
892 $i = 0;
893
894 // Title
895 $bankcateg = new BankCateg($db);
896
897 $newcardbutton = '';
898 if ($action != 'addline') {
899 if (!getDolGlobalString('BANK_DISABLE_DIRECT_INPUT')) {
900 if ($object->status == $object::STATUS_CLOSED) {
901 $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), 'Bank account is closed', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', -2);
902 } else {
903 if (!getDolGlobalString('BANK_USE_OLD_VARIOUS_PAYMENT')) { // Default is to record miscellaneous direct entries using miscellaneous payments
904 $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.urlencode($search_account).'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.urlencode($search_account)), '', $user->hasRight('banque', 'modifier'));
905 } else { // If direct entries is not done using miscellaneous payments
906 $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', $user->hasRight('banque', 'modifier'));
907 }
908 }
909 } else {
910 $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), 'Direct input in bank lines has been disabled by option BANK_DISABLE_DIRECT_INPUT', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', -2);
911 }
912 }
913
914 $morehtml = '';
915
916 if ($action != 'addline' && $action != 'reconcile' && $action != 'confirm_deleteonreconcile') {
917 $morehtml .= $buttonreconcile;
918 }
919
920 $morehtmlright = '<!-- Add New button -->'.$newcardbutton;
921
922 $picto = 'bank_account';
923 if ($id > 0 || !empty($ref)) {
924 $picto = '';
925 }
926
927 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
928 print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton.$morehtml, $num, $nbtotalofrecords, $picto, 0, $morehtmlright, '', $limit, 0, 0, 1);
929
930 // Form to reconcile
931 if ($user->hasRight('banque', 'consolidate') && ($action == 'reconcile' || $action == 'confirm_deleteonreconcile')) {
932 // Show last bank statements
933 $nbmax = 12; // We show last 12 receipts (so we can have more than one year)
934 $listoflastreceipts = '';
935 $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank";
936 $sql .= " WHERE fk_account = ".((int) $object->id)." AND num_releve IS NOT NULL";
937 $sql .= $db->order("num_releve", "DESC");
938 $sql .= $db->plimit($nbmax + 1);
939
940 $last_receipts = array();
941 $last_releve = '';
942 $last_ok = 0;
943 $numr = 0;
944
945 $resqlr = $db->query($sql);
946 if ($resqlr) {
947 $i = 0;
948 $numr = $db->num_rows($resqlr);
949 while (($i < $numr) && ($i < $nbmax)) {
950 $objr = $db->fetch_object($resqlr);
951 if ($objr) {
952 $last_receipts[] = $objr->num_releve;
953 if (!$last_ok) {
954 $last_releve = $objr->num_releve;
955 $last_ok = 1;
956 }
957 }
958 $i++;
959 }
960 }
961
962 print '<!-- form with reconciliation input -->'."\n";
963 print '<div class="valignmiddle inline-block" style="padding-right: 20px;">';
964 if (getDolGlobalInt('NW_RECEIPTNUMBERFORMAT')) {
965 print '<strong>'.$langs->trans("InputReceiptNumber").'</strong>: ';
966 print '<input class="flat width100 center" id="num_releve" list="num_releve_list" name="num_releve" type="text" value="'.(GETPOST('num_releve') ? GETPOST('num_releve') : '').'">';
967 } else {
968 $texttoshow = $langs->trans("InputReceiptNumber").': ';
969 $yyyy = dol_substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1);
970 $mm = dol_substr($langs->transnoentitiesnoconv("Month"), 0, 1).substr($langs->transnoentitiesnoconv("Month"), 0, 1);
971 $dd = dol_substr($langs->transnoentitiesnoconv("Day"), 0, 1).substr($langs->transnoentitiesnoconv("Day"), 0, 1);
972 $placeholder = $yyyy.$mm;
973 $placeholder2 = $yyyy.$mm;
974 $placeholder2 .= ' '.$langs->trans("or").' ';
975 $placeholder2 .= $yyyy.$mm.$dd;
976 if (!$placeholder) {
977 $texttoshow .= $langs->trans("InputReceiptNumberBis");
978 }
979 print $texttoshow;
980 print '<input class="flat width100 center" pattern="[0-9]+" title="'.dol_escape_htmltag($texttoshow.': '.$placeholder2).'" id="num_releve" list="num_releve_list" name="num_releve" placeholder="'.dol_escape_htmltag($placeholder).'" type="text" value="'.(GETPOSTINT('num_releve') ? GETPOSTINT('num_releve') : '').'">'; // The only default value is value we just entered
981 }
982
983 // Output last values into combo list.
984 if (!empty($last_receipts)) {
985 print '<datalist id="num_releve_list">';
986 foreach ($last_receipts as $num_releve) {
987 print '<option value="'.$num_releve.'"></option>'; // TODO We can add some info into option
988 }
989 print '</datalist>';
990 }
991
992 print '</div>';
993 if (is_array($options) && count($options)) {
994 print $langs->trans("EventualyAddCategory").': ';
995 print Form::selectarray('cat', $options, GETPOST('cat'), 1);
996 }
997 print '<br><div style="margin-top: 5px;"><span class="opacitymedium">'.$langs->trans("ThenCheckLinesAndConciliate").'</span> ';
998 print '<input type="submit" class="button" name="confirm_reconcile" value="'.$langs->trans("Conciliate").'">';
999 print ' <span class="opacitymedium">'.$langs->trans("otherwise").'</span> ';
1000 print '<input type="submit" class="button small" name="confirm_savestatement" value="'.$langs->trans("SaveStatementOnly").'">';
1001 //print ' <span class="opacitymedium">'.$langs->trans("or").'</span> ';
1002 //print '<input type="submit" name="cancel" class="button button-cancel small" value="'.$langs->trans("Cancel").'">';
1003 print '</div>';
1004
1005 print '<br>';
1006 print '<!-- Last bank statements -->'."\n";
1007 print $langs->trans("LastAccountStatements").' : ';
1008
1009 $nbmaxlinks = (empty($conf->dol_optimize_smallscreen) ? 5 : 2); // Number of links of last statements to show
1010 $j = 0;
1011 foreach ($last_receipts as $num_releve) {
1012 if ($j >= $nbmaxlinks) {
1013 break;
1014 }
1015 $newentreyinlist = '<a target="_blank" href="'.DOL_URL_ROOT.'/compta/bank/releve.php?account='.((int) $id).'&num='.urlencode($num_releve).'">';
1016 $newentreyinlist .= img_picto($num_releve, 'generic', 'class="paddingright"');
1017 $newentreyinlist .= dol_escape_htmltag($num_releve).'</a> &nbsp; ';
1018 $listoflastreceipts = $newentreyinlist.$listoflastreceipts;
1019 $j++;
1020 }
1021 if ($numr > $nbmaxlinks) {
1022 $listoflastreceipts = "... &nbsp; ".$listoflastreceipts;
1023 }
1024 print $listoflastreceipts;
1025 if ($numr <= 0) {
1026 print '<b>'.$langs->trans("None").'</b>';
1027 }
1028
1029 // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not)
1030 if (getDolGlobalString('BANK_REPORT_LAST_NUM_RELEVE')) {
1031 print '
1032 <script type="text/javascript">
1033 $("#num_releve").val("' . $last_releve.'");
1034 </script>
1035 ';
1036 }
1037 print '<br><br>';
1038 }
1039
1040 // We can add page now to param
1041 if ($page != '') {
1042 $param .= '&page='.urlencode((string) ($page));
1043 }
1044
1045 $moreforfilter = '';
1046 $moreforfilter .= '<div class="divsearchfield">';
1047 $moreforfilter .= $langs->trans('DateOperationShort');
1048 $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
1049 $moreforfilter .= '<div class="nowrap inline-block">';
1050 $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1051 $moreforfilter .= '</div>';
1052 $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
1053 $moreforfilter .= '<div class="nowrap inline-block">';
1054 $moreforfilter .= $form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1055 $moreforfilter .= '</div>';
1056 $moreforfilter .= '</div>';
1057
1058 $moreforfilter .= '<div class="divsearchfield">';
1059 $moreforfilter .= $langs->trans('DateValueShort');
1060 $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
1061 $moreforfilter .= '<div class="nowrap inline-block">';
1062 $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1063 $moreforfilter .= '</div>';
1064 $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
1065 $moreforfilter .= '<div class="nowrap inline-block">';
1066 $moreforfilter .= $form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1067 $moreforfilter .= '</div>';
1068 $moreforfilter .= '</div>';
1069
1070 if (isModEnabled('category')) {
1071 // Categories
1072 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1073 $langs->load('categories');
1074
1075 // Bank line
1076 $moreforfilter .= '<div class="divsearchfield">';
1077 $tmptitle = $langs->trans('RubriquesTransactions');
1078 $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', 0, 0, 1);
1079 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_bid', $cate_arbo, $search_bid, $tmptitle, 0, 0, '', 0, 0, 0, '', '', 1);
1080 $moreforfilter .= '</div>';
1081 }
1082 }
1083
1084 $parameters = array();
1085 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1086 if (empty($reshook)) {
1087 $moreforfilter .= $hookmanager->resPrint;
1088 } else {
1089 $moreforfilter = $hookmanager->resPrint;
1090 }
1091
1092 if ($moreforfilter) {
1093 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1094 print $moreforfilter;
1095 print '</div>'."\n";
1096 }
1097
1098 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1099 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
1100 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1101 $selectedfields .= (($action == 'reconcile' || $action == 'confirm_deleteonreconcile') ? $form->showCheckAddButtons('checkforselect', 1) : '');
1102
1103 // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation).
1104 if ($action == 'reconcile' || $action == 'confirm_deleteonreconcile') {
1105 $arrayfields['b.num_releve']['checked'] = 1;
1106 }
1107
1108 print '<div class="div-table-responsive">';
1109 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1110
1111 // Fields title search
1112 // --------------------------------------------------------------------
1113 print '<tr class="liste_titre_filter">';
1114 // Actions and select
1115 if ($conf->main_checkbox_left_column) {
1116 print '<td class="liste_titre valignmiddle center">';
1117 $searchpicto = $form->showFilterButtons('left');
1118 print $searchpicto;
1119 //$searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1120 //print $searchpicto;
1121 print '</td>';
1122 }
1123 if (!empty($arrayfields['b.rowid']['checked'])) {
1124 print '<td class="liste_titre">';
1125 print '<input type="text" class="flat" name="search_ref" size="2" value="'.dol_escape_htmltag($search_ref).'">';
1126 print '</td>';
1127 }
1128 if (!empty($arrayfields['b.label']['checked'])) {
1129 print '<td class="liste_titre">';
1130 print '<input type="text" class="flat maxwidth100" name="search_description" value="'.dol_escape_htmltag($search_description).'">';
1131 print '</td>';
1132 }
1133 if (!empty($arrayfields['b.dateo']['checked'])) {
1134 print '<td class="liste_titre">&nbsp;</td>';
1135 }
1136 if (!empty($arrayfields['b.datev']['checked'])) {
1137 print '<td class="liste_titre">&nbsp;</td>';
1138 }
1139 // Type
1140 if (!empty($arrayfields['type']['checked'])) {
1141 print '<td class="liste_titre">';
1142 print $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100', 1);
1143 print '</td>';
1144 }
1145 // Numero
1146 if (!empty($arrayfields['b.num_chq']['checked'])) {
1147 print '<td class="liste_titre center"><input type="text" class="flat" name="req_nb" value="'.dol_escape_htmltag($search_req_nb).'" size="2"></td>';
1148 }
1149 // Bordereau
1150 if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
1151 print '<td class="liste_titre center"><input type="text" class="flat width50" name="search_fk_bordereau" value="'.dol_escape_htmltag($search_fk_bordereau).'"></td>';
1152 }
1153 // Thirdparty
1154 if (!empty($arrayfields['bu.label']['checked'])) {
1155 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_thirdparty" value="'.dol_escape_htmltag($search_thirdparty_user).'"></td>';
1156 }
1157 // Ref
1158 if (!empty($arrayfields['ba.ref']['checked'])) {
1159 print '<td class="liste_titre">';
1160 $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100');
1161 print '</td>';
1162 }
1163 // Debit
1164 if (!empty($arrayfields['b.debit']['checked'])) {
1165 print '<td class="liste_titre right">';
1166 print '<input type="text" class="flat width50" name="search_debit" value="'.dol_escape_htmltag($search_debit).'">';
1167 print '</td>';
1168 }
1169 // Credit
1170 if (!empty($arrayfields['b.credit']['checked'])) {
1171 print '<td class="liste_titre right">';
1172 print '<input type="text" class="flat width50" name="search_credit" value="'.dol_escape_htmltag($search_credit).'">';
1173 print '</td>';
1174 }
1175 // Balance before
1176 if (!empty($arrayfields['balancebefore']['checked'])) {
1177 print '<td class="liste_titre right">';
1178 $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
1179 print $form->textwithpicto('', $htmltext, 1);
1180 print '</td>';
1181 }
1182 // Balance
1183 if (!empty($arrayfields['balance']['checked'])) {
1184 print '<td class="liste_titre right">';
1185 $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
1186 print $form->textwithpicto('', $htmltext, 1);
1187 print '</td>';
1188 }
1189 // Numero statement
1190 if (!empty($arrayfields['b.num_releve']['checked'])) {
1191 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
1192 print '<td class="liste_titre center"><input type="text" class="flat width50" name="search_num_releve" value="'.dol_escape_htmltag($search_num_releve).'"></td>';
1193 }
1194 // Conciliated
1195 if (!empty($arrayfields['b.conciliated']['checked'])) {
1196 print '<td class="liste_titre center parentonrightofpage">';
1197 print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1, 'search_status onrightofpage width75');
1198 print '</td>';
1199 }
1200 // Extra fields
1201 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1202 // Action edit/delete and select
1203 print '<td class="nowraponall center"></td>';
1204
1205 // Actions and select
1206 if (!$conf->main_checkbox_left_column) {
1207 print '<td class="liste_titre valignmiddle center">';
1208 //$searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1209 //print $searchpicto;
1210 $searchpicto = $form->showFilterButtons();
1211 print $searchpicto;
1212 print '</td>';
1213 }
1214 print "</tr>\n";
1215
1216 $totalarray = array();
1217 $totalarray['nbfield'] = 0;
1218
1219 // Fields title
1220 print '<tr class="liste_titre">';
1221 // Actions and select
1222 if ($conf->main_checkbox_left_column) {
1223 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1224 $totalarray['nbfield']++;
1225 }
1226 if (!empty($arrayfields['b.rowid']['checked'])) {
1227 print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
1228 $totalarray['nbfield']++;
1229 }
1230 if (!empty($arrayfields['b.label']['checked'])) {
1231 print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER['PHP_SELF'], 'b.label', '', $param, '', $sortfield, $sortorder);
1232 $totalarray['nbfield']++;
1233 }
1234 if (!empty($arrayfields['b.dateo']['checked'])) {
1235 print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '', $sortfield, $sortorder, "center ");
1236 $totalarray['nbfield']++;
1237 }
1238 if (!empty($arrayfields['b.datev']['checked'])) {
1239 print_liste_field_titre($arrayfields['b.datev']['label'], $_SERVER['PHP_SELF'], 'b.datev,b.dateo,b.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1240 $totalarray['nbfield']++;
1241 }
1242 if (!empty($arrayfields['type']['checked'])) {
1243 print_liste_field_titre($arrayfields['type']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1244 $totalarray['nbfield']++;
1245 }
1246 if (!empty($arrayfields['b.num_chq']['checked'])) {
1247 print_liste_field_titre($arrayfields['b.num_chq']['label'], $_SERVER['PHP_SELF'], 'b.num_chq', '', $param, '', $sortfield, $sortorder, "center ");
1248 $totalarray['nbfield']++;
1249 }
1250 if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
1251 print_liste_field_titre($arrayfields['b.fk_bordereau']['label'], $_SERVER['PHP_SELF'], 'b.fk_bordereau', '', $param, '', $sortfield, $sortorder, "center ");
1252 $totalarray['nbfield']++;
1253 }
1254 if (!empty($arrayfields['bu.label']['checked'])) {
1255 print_liste_field_titre($arrayfields['bu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1256 $totalarray['nbfield']++;
1257 }
1258 if (!empty($arrayfields['ba.ref']['checked'])) {
1259 print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder);
1260 $totalarray['nbfield']++;
1261 }
1262 if (!empty($arrayfields['b.debit']['checked'])) {
1263 print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
1264 $totalarray['nbfield']++;
1265 }
1266 if (!empty($arrayfields['b.credit']['checked'])) {
1267 print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
1268 $totalarray['nbfield']++;
1269 }
1270 if (!empty($arrayfields['balancebefore']['checked'])) {
1271 print_liste_field_titre($arrayfields['balancebefore']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
1272 $totalarray['nbfield']++;
1273 }
1274 if (!empty($arrayfields['balance']['checked'])) {
1275 print_liste_field_titre($arrayfields['balance']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
1276 $totalarray['nbfield']++;
1277 }
1278 if (!empty($arrayfields['b.num_releve']['checked'])) {
1279 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1280 print_liste_field_titre($arrayfields['b.num_releve']['label'], $_SERVER['PHP_SELF'], 'b.num_releve', '', $param, '', $sortfield, $sortorder, "center ");
1281 $totalarray['nbfield']++;
1282 }
1283 if (!empty($arrayfields['b.conciliated']['checked'])) {
1284 print_liste_field_titre($arrayfields['b.conciliated']['label'], $_SERVER['PHP_SELF'], 'b.rappro', '', $param, '', $sortfield, $sortorder, "center ");
1285 $totalarray['nbfield']++;
1286 }
1287
1288 // Extra fields
1289 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1290 // Hook fields
1291 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1292 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1293 print $hookmanager->resPrint;
1294 // Action edit/delete and select
1295 print '<td class="nowraponall center"></td>';
1296 $totalarray['nbfield']++;
1297 // Actions and select
1298 if (!$conf->main_checkbox_left_column) {
1299 //print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1300 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
1301 $totalarray['nbfield']++;
1302 }
1303 print "</tr>\n";
1304
1305 $balance = 0; // For balance
1306 $balancebefore = 0; // For balance
1307 $balancecalculated = false;
1308 $posconciliatecol = 0;
1309 $cachebankaccount = array();
1310
1311 $sign = 1;
1312
1313 // Loop on each record
1314 $i = 0;
1315 $savnbfield = $totalarray['nbfield'];
1316 $totalarray = array();
1317 $totalarray['nbfield'] = 0;
1318 $totalarray['totaldeb'] = 0;
1319 $totalarray['totalcred'] = 0;
1320
1321 $imaxinloop = ($limit ? min($num, $limit) : $num);
1322 while ($i < $imaxinloop) {
1323 $objp = $db->fetch_object($resql);
1324 $links = $bankaccountstatic->get_url($objp->rowid);
1325 // If we are in a situation where we need/can show balance, we calculate the start of balance
1326 if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0')) {
1327 if (!$search_account) {
1328 dol_print_error(null, 'account is not defined but $mode_balance_ok is true');
1329 exit;
1330 }
1331
1332 // Loop on each record before
1333 $sign = 1;
1334 $i = 0;
1335 $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal';
1336 $sqlforbalance .= " FROM ";
1337 $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,";
1338 $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b";
1339 $sqlforbalance .= " WHERE b.fk_account = ba.rowid";
1340 $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")";
1341 $sqlforbalance .= " AND b.fk_account = ".((int) $search_account);
1342 // To limit record on the page
1343 $sqlforbalance .= " AND (b.datev < '".$db->idate($db->jdate($objp->dv))."' OR (b.datev = '".$db->idate($db->jdate($objp->dv))."' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".((int) $objp->rowid)."))))";
1344 $resqlforbalance = $db->query($sqlforbalance);
1345
1346 //print $sqlforbalance;
1347 if ($resqlforbalance) {
1348 $objforbalance = $db->fetch_object($resqlforbalance);
1349 if ($objforbalance) {
1350 // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show
1351 if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
1352 $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount);
1353 } else {
1354 // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show
1355 $balance = $objforbalance->previoustotal;
1356 }
1357 }
1358 } else {
1359 dol_print_error($db);
1360 }
1361
1362 $balancecalculated = true;
1363
1364 // Output a line with start balance
1365 if ($user->hasRight('banque', 'consolidate') && ($action == 'reconcile' || $action == 'confirm_deleteonreconcile')) {
1366 $tmpnbfieldbeforebalance = 0;
1367 $tmpnbfieldafterbalance = 0;
1368 $balancefieldfound = 0;
1369 foreach ($arrayfields as $key => $val) {
1370 if ($key == 'balancebefore' || $key == 'balance') {
1371 $balancefieldfound++;
1372 continue;
1373 }
1374 if (!empty($arrayfields[$key]['checked'])) {
1375 if (!$balancefieldfound) {
1376 $tmpnbfieldbeforebalance++;
1377 } else {
1378 $tmpnbfieldafterbalance++;
1379 }
1380 }
1381 }
1382 // Extra
1383 $element = $extrafieldsobjectkey;
1384 if (!empty($extrafields->attributes[$element]['label']) && is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) {
1385 foreach ($extrafields->attributes[$element]['label'] as $key => $val) {
1386 if (!empty($arrayfields["ef.".$key]['checked'])) {
1387 if (!empty($arrayfields[$key]['checked'])) {
1388 if (!$balancefieldfound) {
1389 $tmpnbfieldbeforebalance++;
1390 } else {
1391 $tmpnbfieldafterbalance++;
1392 }
1393 }
1394 }
1395 }
1396 }
1397
1398 print '<tr class="oddeven trforbreak">';
1399 // Action column
1400 if ($conf->main_checkbox_left_column) {
1401 print '<td></td>';
1402 }
1403 if ($tmpnbfieldbeforebalance) {
1404 print '<td colspan="'.$tmpnbfieldbeforebalance.'">';
1405 print '&nbsp;';
1406 print '</td>';
1407 }
1408
1409 if (!empty($arrayfields['balancebefore']['checked'])) {
1410 print '<td class="right">';
1411 if ($search_conciliated !== '0') {
1412 if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
1413 print price(price2num($balancebefore, 'MT'), 1, $langs);
1414 } else {
1415 print price(price2num($balance, 'MT'), 1, $langs);
1416 }
1417 }
1418 print '</td>';
1419 }
1420 if (!empty($arrayfields['balance']['checked'])) {
1421 print '<td class="right">';
1422 if ($search_conciliated !== '0') { // If not filter of filter on "conciliated"
1423 if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
1424 print price(price2num($balancebefore, 'MT'), 1, $langs);
1425 } else {
1426 print price(price2num($balance, 'MT'), 1, $langs);
1427 }
1428 }
1429 print '</td>';
1430 }
1431
1432 if (!empty($arrayfields['b.num_releve']['checked'])) {
1433 print '<td></td>';
1434 }
1435
1436 // conciliate
1437 print '<td colspan="'.($tmpnbfieldafterbalance).'">';
1438 print '&nbsp;';
1439 print '</td>';
1440
1441 // Action column
1442 if (!$conf->main_checkbox_left_column) {
1443 print '<td></td>';
1444 }
1445
1446 print '</tr>';
1447 }
1448 }
1449
1450 if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
1451 $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc)
1452 $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT');
1453 } else {
1454 $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc)
1455 $balance = price2num($balance + ($sign * $objp->amount), 'MT');
1456 }
1457
1458 if (empty($cachebankaccount[$objp->bankid])) {
1459 $bankaccounttmp = new Account($db);
1460 $bankaccounttmp->fetch($objp->bankid);
1461 $cachebankaccount[$objp->bankid] = $bankaccounttmp;
1462 $bankaccount = $bankaccounttmp;
1463 } else {
1464 $bankaccount = $cachebankaccount[$objp->bankid];
1465 }
1466
1467 if (!getDolGlobalString('BANK_COLORIZE_MOVEMENT')) {
1468 $backgroundcolor = "class='oddeven'";
1469 } else {
1470 if ($objp->amount < 0) {
1471 $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR1', 'fca955');
1472 $backgroundcolor = 'style="background: '.$color.';"';
1473 } else {
1474 $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR2', '7fdb86');
1475 $backgroundcolor = 'style="background: '.$color.';"';
1476 }
1477 }
1478
1479 $banklinestatic->id = $objp->rowid;
1480 $banklinestatic->ref = (string) $objp->rowid;
1481 $banklinestatic->amount = $objp->amount;
1482
1483 // Lines that can be reconciled use the intuitive row selection (Ctrl/Shift+click, and single click if MAIN_ROW_SINGLECLICK_TOSELECT)
1484 $lineselectable = (!$objp->conciliated && ($action == 'reconcile' || $action == 'confirm_deleteonreconcile'));
1485
1486 print '<tr class="oddeven'.($lineselectable ? ' row-with-select' : '').'" '.$backgroundcolor.'>';
1487
1488 // Action column
1489 if ($conf->main_checkbox_left_column) {
1490 print '<td class="center">';
1491 if ($lineselectable) {
1492 print '<input class="flat checkforselect" name="rowid['.$objp->rowid.']" type="checkbox" name="toselect[]" value="'.$objp->rowid.'" size="1"'.(in_array($objp->rowid, $rowids) ? ' checked' : '').'>';
1493 }
1494 print '</td>';
1495 if (!$i) {
1496 $totalarray['nbfield']++;
1497 }
1498 }
1499
1500 // Ref
1501 if (!empty($arrayfields['b.rowid']['checked'])) {
1502 print '<td class="nowrap left">';
1503 print $banklinestatic->getNomUrl(1);
1504 print '</td>';
1505 if (!$i) {
1506 $totalarray['nbfield']++;
1507 }
1508 }
1509
1510 // Description
1511 if (!empty($arrayfields['b.label']['checked'])) {
1512 $labeltoshow = '';
1513 $titletoshow = '';
1514 $reg = array();
1515 preg_match('/\‍((.+)\‍)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction
1516 if (!empty($reg[1]) && $langs->trans($reg[1]) != $reg[1]) {
1517 // Example: $reg[1] = 'CustomerInvoicePayment', 'SupplierInvoicePayment', ... (or on old version: 'WithdrawalPayment', 'BankTransferPayment')
1518 $labeltoshow = $langs->trans($reg[1]);
1519 } else {
1520 if ($objp->label == '(payment_salary)') {
1521 $labeltoshow = $langs->trans("SalaryPayment");
1522 } else {
1523 $labeltoshow = dol_escape_htmltag($objp->label);
1524 $titletoshow = $objp->label;
1525 }
1526 }
1527
1528
1529 print '<td class="tdoverflowmax250"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>';
1530
1531 // Add info about links after description
1532 $cachebankaccount = array();
1533 foreach ($links as $key => $val) {
1534 print '<!-- '.$links[$key]['type'].' -->';
1535 if ($links[$key]['type'] == 'withdraw') {
1536 $banktransferstatic->id = $links[$key]['url_id'];
1537 $banktransferstatic->ref = $links[$key]['label'];
1538 print $banktransferstatic->getNomUrl(0).($labeltoshow ? ' ' : '');
1539 } elseif ($links[$key]['type'] == 'payment') {
1540 $paymentstatic->id = $links[$key]['url_id'];
1541 $paymentstatic->ref = (string) $links[$key]['url_id']; // FIXME This is id, not ref of payment
1542 $paymentstatic->date = $db->jdate($objp->do);
1543 print $paymentstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1544 } elseif ($links[$key]['type'] == 'payment_supplier') {
1545 $paymentsupplierstatic->id = $links[$key]['url_id'];
1546 $paymentsupplierstatic->ref = (string) $links[$key]['url_id']; // FIXME This is id, not ref of payment
1547 print $paymentsupplierstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1548 } elseif ($links[$key]['type'] == 'payment_sc') {
1549 $paymentscstatic->id = $links[$key]['url_id'];
1550 $paymentscstatic->ref = (string) $links[$key]['url_id'];
1551 $paymentscstatic->label = $links[$key]['label'];
1552 print $paymentscstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1553 } elseif ($links[$key]['type'] == 'payment_vat') {
1554 $paymentvatstatic->id = $links[$key]['url_id'];
1555 $paymentvatstatic->ref = (string) $links[$key]['url_id'];
1556 print $paymentvatstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1557 } elseif ($links[$key]['type'] == 'payment_salary') {
1558 $paymentsalstatic->id = $links[$key]['url_id'];
1559 $paymentsalstatic->ref = (string) $links[$key]['url_id'];
1560 $paymentsalstatic->label = $links[$key]['label'];
1561 print $paymentsalstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1562 } elseif ($links[$key]['type'] == 'payment_loan') {
1563 print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
1564 print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
1565 print '</a>'.($labeltoshow ? ' ' : '');
1566 } elseif ($links[$key]['type'] == 'payment_donation') {
1567 $paymentdonationstatic->id = $links[$key]['url_id'];
1568 $paymentdonationstatic->ref = (string) $links[$key]['url_id'];
1569 print $paymentdonationstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1570 } elseif ($links[$key]['type'] == 'payment_expensereport') {
1571 $paymentexpensereportstatic->id = $links[$key]['url_id'];
1572 $paymentexpensereportstatic->ref = (string) $links[$key]['url_id'];
1573 print $paymentexpensereportstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1574 } elseif ($links[$key]['type'] == 'payment_various') {
1575 $paymentvariousstatic->id = $links[$key]['url_id'];
1576 $paymentvariousstatic->ref = (string) $links[$key]['url_id'];
1577 print $paymentvariousstatic->getNomUrl(2).($labeltoshow ? ' ' : '');
1578 } elseif ($links[$key]['type'] == 'banktransfert') {
1579 // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
1580 if ($objp->amount > 0) {
1581 $banklinestatic->fetch($links[$key]['url_id']);
1582 $bankstatic->id = $banklinestatic->fk_account;
1583 $bankstatic->label = $banklinestatic->bank_account_ref;
1584 print $langs->trans("TransferFrom").' ';
1585 print $bankstatic->getNomUrl(1, 'transactions');
1586 print ' '.$langs->trans("toward").' ';
1587 $bankstatic->id = $objp->bankid;
1588 $bankstatic->label = $objp->bankref;
1589 print $bankstatic->getNomUrl(1, '');
1590 print($labeltoshow ? ' - ' : '');
1591 } else {
1592 $bankstatic->id = $objp->bankid;
1593 $bankstatic->label = $objp->bankref;
1594 print $langs->trans("TransferFrom").' ';
1595 print $bankstatic->getNomUrl(1, '');
1596 print ' '.$langs->trans("toward").' ';
1597 $banklinestatic->fetch($links[$key]['url_id']);
1598 $bankstatic->id = $banklinestatic->fk_account;
1599 $bankstatic->label = $banklinestatic->bank_account_ref;
1600 print $bankstatic->getNomUrl(1, 'transactions');
1601 print($labeltoshow ? ' - ' : '');
1602 }
1603 //var_dump($links);
1604 } elseif ($links[$key]['type'] == 'company') {
1605 } elseif ($links[$key]['type'] == 'user') {
1606 } elseif ($links[$key]['type'] == 'member') {
1607 } elseif ($links[$key]['type'] == 'sc') {
1608 } elseif ($links[$key]['type'] == 'vat') {
1609 } elseif ($links[$key]['type'] == 'salary') {
1610 // Information is already shown using the payment_salary link. No need of this link.
1611 } else {
1612 // Show link with label $links[$key]['label']
1613 print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
1614 if (preg_match('/^\‍((.*)\‍)$/i', $links[$key]['label'], $reg)) {
1615 // Generic label because it is in parentheses. We display it translated.
1616 if ($reg[1] == 'paiement') {
1617 $reg[1] = 'Payment';
1618 }
1619 print $langs->trans($reg[1]);
1620 } else {
1621 print $links[$key]['label'];
1622 }
1623 print '</a>'.($labeltoshow ? ' - ' : '');
1624 }
1625 }
1626
1627 print $labeltoshow; // Already escaped
1628
1629 print '</td>';
1630 if (!$i) {
1631 $totalarray['nbfield']++;
1632 }
1633 }
1634
1635 // Date ope
1636 if (!empty($arrayfields['b.dateo']['checked'])) {
1637 print '<td class="nowraponall center">';
1638 print '<span class="spanforajaxedit" id="dateoperation_'.$objp->rowid.'" title="'.dol_print_date($db->jdate($objp->do), "day").'">';
1639 print dol_print_date($db->jdate($objp->do), "dayreduceformat");
1640 print "</span>";
1641 print '&nbsp;';
1642 print '<span class="inline-block">';
1643 print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1644 print img_edit_remove()."</a> ";
1645 print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=donext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1646 print img_edit_add()."</a>";
1647 print '</span>';
1648 print "</td>\n";
1649 if (!$i) {
1650 $totalarray['nbfield']++;
1651 }
1652 }
1653
1654 // Date value
1655 if (!empty($arrayfields['b.datev']['checked'])) {
1656 print '<td class="nowraponall center">';
1657 print '<span class="spanforajaxedit" id="datevalue_'.$objp->rowid.'" title="'.dol_print_date($db->jdate($objp->dv), "day").'">';
1658 print dol_print_date($db->jdate($objp->dv), "dayreduceformat");
1659 print "</span>";
1660 print '&nbsp;';
1661 print '<span class="inline-block">';
1662 print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1663 print img_edit_remove()."</a> ";
1664 print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
1665 print img_edit_add()."</a>";
1666 print '</span>';
1667 print "</td>\n";
1668 if (!$i) {
1669 $totalarray['nbfield']++;
1670 }
1671 }
1672
1673 // Payment type
1674 if (!empty($arrayfields['type']['checked'])) {
1675 $labeltype = ($langs->transnoentitiesnoconv("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->transnoentitiesnoconv("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1);
1676 if (empty($arrayfields['b.num_chq']['checked'])) {
1677 $labeltype .= ($objp->num_chq ? ' <span class="opacitymedium">- '.$objp->num_chq.'</span>' : '');
1678 }
1679 print '<td class="tdoverflowmax100" title="'.dolPrintLabel($labeltype).'">';
1680 if ($labeltype == 'SOLD') {
1681 print '&nbsp;'; //$langs->trans("InitialBankBalance");
1682 } else {
1683 print dolPrintHTML($labeltype);
1684 }
1685 print "</td>\n";
1686 if (!$i) {
1687 $totalarray['nbfield']++;
1688 }
1689 }
1690
1691 // Num cheque
1692 if (!empty($arrayfields['b.num_chq']['checked'])) {
1693 print '<td class="tdoverflowmax100 center" title="'.($objp->num_chq ? dolPrintLabel($objp->num_chq) : "").'">'.($objp->num_chq ? dolPrintLabel($objp->num_chq) : "")."</td>\n";
1694 if (!$i) {
1695 $totalarray['nbfield']++;
1696 }
1697 }
1698
1699 // Cheque
1700 if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
1701 print '<td class="nowraponall center">';
1702 if ($objp->fk_bordereau > 0) {
1703 $bordereaustatic->fetch($objp->fk_bordereau);
1704 print $bordereaustatic->getNomUrl();
1705 }
1706 print '</td>';
1707 if (!$i) {
1708 $totalarray['nbfield']++;
1709 }
1710 }
1711
1712 // Third party
1713 if (!empty($arrayfields['bu.label']['checked'])) {
1714 print '<td class="tdoverflowmax125">';
1715
1716 $companylinked_id = 0;
1717 $userlinked_id = 0;
1718 $type_link = "";
1719 $thirdstr = "";
1720
1721 //payment line type to define user display and user or company linked
1722 foreach ($links as $key => $value) {
1723 if ($links[$key]['type'] == 'payment_sc') {
1724 $type_link = 'payment_sc';
1725 }
1726 if ($links[$key]['type'] == 'payment_salary') {
1727 $type_link = 'payment_salary';
1728 }
1729 if ($links[$key]['type'] == 'payment_donation') {
1730 $paymentdonationstatic->fetch($links[$key]['url_id']);
1731 $donstatic->fetch($paymentdonationstatic->fk_donation);
1732 $companylinked_id = $donstatic->socid;
1733 if (!$companylinked_id) {
1734 $thirdstr = ($donstatic->societe !== "" ?
1735 $donstatic->societe :
1736 $donstatic->firstname." ".$donstatic->lastname);
1737 }
1738 }
1739 if ($links[$key]['type'] == 'payment_expensereport') {
1740 $type_link = 'payment_expensereport';
1741 }
1742
1743 if ($links[$key]['type'] == 'company') {
1744 $companylinked_id = $links[$key]['url_id'];
1745 }
1746 if ($links[$key]['type'] == 'user') {
1747 $userlinked_id = $links[$key]['url_id'];
1748 }
1749 }
1750
1751 // Show more information in the column thirdparty.
1752 if ($companylinked_id) {
1753 // TODO Add a cache of loaded companies here ?
1754 $companystatic->fetch($companylinked_id);
1755 print $companystatic->getNomUrl(1);
1756 } elseif ($userlinked_id &&
1757 (($type_link == 'payment_salary' && $user->hasRight('salaries', 'read'))
1758 || ($type_link == 'payment_sc' && $user->hasRight('tax', 'charges', 'lire'))
1759 || ($type_link == 'payment_expensereport' && $user->hasRight('expensereport', 'lire')))) {
1760 // Get object user from cache or load it
1761 if (!empty($conf->cache['user'][$userlinked_id])) {
1762 $tmpuser = $conf->cache['user'][$userlinked_id];
1763 } else {
1764 $tmpuser = new User($db);
1765 $tmpuser->fetch($userlinked_id);
1766 $conf->cache['user'][$userlinked_id] = $tmpuser;
1767 }
1768 print $tmpuser->getNomUrl(-1);
1769 } elseif ($thirdstr) {
1770 print $thirdstr;
1771 } else {
1772 print '&nbsp;';
1773 }
1774
1775 print '</td>';
1776 if (!$i) {
1777 $totalarray['nbfield']++;
1778 }
1779 }
1780
1781 // Bank account
1782 if (!empty($arrayfields['ba.ref']['checked'])) {
1783 print '<td class="nowrap">';
1784 print $bankaccount->getNomUrl(1);
1785 print "</td>\n";
1786 if (!$i) {
1787 $totalarray['nbfield']++;
1788 }
1789 }
1790
1791 $currencykey = $bankaccount->currency_code;
1792 if (!isset($totalarray['totalpercurrency'][$currencykey])) {
1793 $totalarray['totalpercurrency'][$currencykey] = array('deb' => 0, 'cred' => 0);
1794 }
1795 $amountmaincurrency = empty($objp->amount_main_currency) ? $objp->amount : $objp->amount_main_currency;
1796
1797 // Debit
1798 if (!empty($arrayfields['b.debit']['checked'])) {
1799 print '<td class="nowraponall right"><span class="amount">';
1800 if ($objp->amount < 0) {
1801 print price($objp->amount * -1);
1802 $totalarray['totaldeb'] += $amountmaincurrency;
1803 $totalarray['totalpercurrency'][$currencykey]['deb'] += $objp->amount;
1804 }
1805 print "</span></td>\n";
1806 if (!$i) {
1807 $totalarray['nbfield']++;
1808 }
1809 if (!$i) {
1810 $totalarray['totaldebfield'] = $totalarray['nbfield'];
1811 }
1812 }
1813
1814 // Credit
1815 if (!empty($arrayfields['b.credit']['checked'])) {
1816 print '<td class="nowraponall right"><span class="amount">';
1817 if ($objp->amount > 0) {
1818 print price($objp->amount);
1819 $totalarray['totalcred'] += $amountmaincurrency;
1820 $totalarray['totalpercurrency'][$currencykey]['cred'] += $objp->amount;
1821 }
1822 print "</span></td>\n";
1823 if (!$i) {
1824 $totalarray['nbfield']++;
1825 }
1826 if (!$i) {
1827 $totalarray['totalcredfield'] = $totalarray['nbfield'];
1828 }
1829 }
1830
1831 // Balance before
1832 if (!empty($arrayfields['balancebefore']['checked'])) {
1833 if ($mode_balance_ok) {
1834 if ($balancebefore >= 0) {
1835 print '<td class="nowrap right">&nbsp;'.price($balancebefore).'</td>';
1836 } else {
1837 print '<td class="error nowrap right">&nbsp;'.price($balancebefore).'</td>';
1838 }
1839 } else {
1840 print '<td class="right">-</td>';
1841 }
1842 if (!$i) {
1843 $totalarray['nbfield']++;
1844 }
1845 }
1846
1847 // Balance after
1848 if (!empty($arrayfields['balance']['checked'])) {
1849 if ($mode_balance_ok) {
1850 if ($balance >= 0) {
1851 print '<td class="nowrap right">&nbsp;'.price($balance).'</td>';
1852 } else {
1853 print '<td class="error nowrap right">&nbsp;'.price($balance).'</td>';
1854 }
1855 } else {
1856 print '<td class="right">-</td>';
1857 }
1858 if (!$i) {
1859 $totalarray['nbfield']++;
1860 }
1861 }
1862
1863 if (!empty($arrayfields['b.num_releve']['checked'])) {
1864 print '<td class="nowraponall center">';
1865 // Transaction reconciliated or edit link
1866 if ($bankaccount->canBeConciliated() > 0) {
1867 if ($objp->num_releve) {
1868 print '<a href="releve.php?num='.urlencode($objp->num_releve).'&account='.urlencode($objp->bankid).'&save_lastsearch_values=1">'.dol_escape_htmltag($objp->num_releve).'</a>';
1869 }
1870 }
1871 print '</td>';
1872 if (!$i) {
1873 $totalarray['nbfield']++;
1874 $posconciliatecol = $totalarray['nbfield'];
1875 }
1876 }
1877
1878 // Conciliated
1879 if (!empty($arrayfields['b.conciliated']['checked'])) {
1880 print '<td class="nowraponall center">';
1881 print yn($objp->conciliated);
1882 print '</td>';
1883 if (!$i) {
1884 $totalarray['nbfield']++;
1885 }
1886 }
1887
1888 // Extra fields
1889 $obj = $objp; // Because extrafield template use $obj and not $objp as object variable name
1890 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1891 // Fields from hook
1892 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $objp, 'i' => $i, 'totalarray' => &$totalarray);
1893 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $objecttmpect may have been modified by hook
1894 print $hookmanager->resPrint;
1895
1896 // Action edit/delete and select
1897 print '<td class="nowraponall center">';
1898 // Transaction reconciliated or edit link
1899 if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) { // If line not conciliated and account can be conciliated
1900 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
1901 print img_edit();
1902 print '</a>';
1903 } else {
1904 if ($user->hasRight('banque', 'modifier') || $user->hasRight('banque', 'consolidate')) {
1905 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
1906 print img_edit();
1907 print '</a>';
1908 } else {
1909 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
1910 print img_view();
1911 print '</a>';
1912 }
1913 if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) {
1914 if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) {
1915 print ' '.img_warning($langs->trans("ReconciliationLate"));
1916 }
1917 }
1918 if ($user->hasRight('banque', 'modifier')) {
1919 // Strip the surrounding & so the leading action= we put first stays the only action= in the URL.
1920 // Without this the URL ends up with two action= params; PHP picks the last one and the page silently switches to 'reconcile' instead of 'delete'.
1921 $parambis = preg_replace('/&?action=(reconcile|confirm_deleteonreconcile)(&|$)/', '\2', $param);
1922 print '<a href="'.$_SERVER["PHP_SELF"].'?action='.($action == 'reconcile' ? 'confirm_deleteonreconcile&confirm=yes' : 'delete').'&token='.newToken().'&rowid='.$objp->rowid.'&page='.$page.$parambis.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">';
1923 print img_delete('', 'class="marginleftonly"');
1924 print '</a>';
1925 }
1926 }
1927 print '</td>';
1928 if (!$i) {
1929 $totalarray['nbfield']++;
1930 }
1931
1932 // Action column
1933 if (!$conf->main_checkbox_left_column) {
1934 print '<td class="center">';
1935 if ($lineselectable) {
1936 print '<input class="flat checkforselect" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(in_array($objp->rowid, $rowids) ? ' checked' : '').'>';
1937 }
1938 print '</td>';
1939 if (!$i) {
1940 $totalarray['nbfield']++;
1941 }
1942 }
1943
1944 print "</tr>\n";
1945
1946 $i++;
1947 }
1948
1949 // Show total line
1950 if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield'])) {
1951 print '<tr class="liste_total">';
1952 $i = 0;
1953 while ($i < $totalarray['nbfield']) {
1954 $i++;
1955 if ($i == 1) {
1956 if ($num < $limit && empty($offset)) {
1957 print '<td class="left">'.$langs->trans("Total").'</td>';
1958 } else {
1959 print '<td class="left tdoverflowmax50" title="'.$langs->trans("Totalforthispage").'">'.$langs->trans("Totalforthispage").'</td>';
1960 }
1961 } elseif ($totalarray['totaldebfield'] == $i) {
1962 print '<td class="right"><span class="amount">'.price(-1 * $totalarray['totaldeb']).'</span></td>';
1963 } elseif ($totalarray['totalcredfield'] == $i) {
1964 print '<td class="right"><span class="amount">'.price($totalarray['totalcred']).'</span></td>';
1965 } elseif ($i == $posconciliatecol) {
1966 print '<td class="center">';
1967 print '</td>';
1968 } else {
1969 print '<td></td>';
1970 }
1971 }
1972 print '</tr>';
1973
1974 // Show one line per currency when the list holds accounts in several currencies
1975 if (count($totalarray['totalpercurrency']) > 1) {
1976 foreach ($totalarray['totalpercurrency'] as $currencycode => $totalpercurrency) {
1977 print '<tr class="liste_total">';
1978 $i = 0;
1979 while ($i < $totalarray['nbfield']) {
1980 $i++;
1981 if ($i == 1) {
1982 print '<td class="left">'.$langs->trans("Total").' '.dol_escape_htmltag($currencycode).'</td>';
1983 } elseif (isset($totalarray['totaldebfield']) && $totalarray['totaldebfield'] == $i) {
1984 print '<td class="right"><span class="amount">'.price(-1 * $totalpercurrency['deb']).'</span></td>';
1985 } elseif (isset($totalarray['totalcredfield']) && $totalarray['totalcredfield'] == $i) {
1986 print '<td class="right"><span class="amount">'.price($totalpercurrency['cred']).'</span></td>';
1987 } else {
1988 print '<td></td>';
1989 }
1990 }
1991 print '</tr>';
1992 }
1993 }
1994 }
1995
1996 // If no record found
1997 if ($num == 0) {
1998 $colspan = 1;
1999 foreach ($arrayfields as $key => $val) {
2000 if (!empty($val['checked'])) {
2001 $colspan++;
2002 }
2003 }
2004 print '<tr><td colspan="'.($colspan + 1).'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2005 }
2006
2007 print "</table>";
2008 print "</div>";
2009
2010 // Remember the lines ticked for reconciliation in the browser tab (per bank account), so that
2011 // adding or deleting a line, changing page or reloading the page does not lose them.
2012 if (($action == 'reconcile' || $action == 'confirm_deleteonreconcile') && !empty($conf->use_javascript_ajax)) {
2013 print '<script nonce="'.getNonce().'">
2014 $(document).ready(function() {
2015 var key = "dol_bankreconcile_checked_'.((int) $object->id).'";
2016 var checked = {};
2017 try { checked = JSON.parse(sessionStorage.getItem(key) || "{}") || {}; } catch (e) { checked = {}; }
2018 function saveChecked() { try { sessionStorage.setItem(key, JSON.stringify(checked)); } catch (e) {} }
2019 $("input.checkforselect").each(function() {
2020 if (this.checked) {
2021 checked[this.value] = 1; // Line already ticked by the server (kept after an error)
2022 } else if (checked[this.value]) {
2023 console.log("Restore tick of bank line "+this.value);
2024 $(this).prop("checked", true).trigger("change");
2025 }
2026 });
2027 saveChecked();
2028 $(document).on("change", "input.checkforselect", function() {
2029 if (this.checked) {
2030 checked[this.value] = 1;
2031 } else {
2032 delete checked[this.value];
2033 }
2034 saveChecked();
2035 });
2036 $("input[name=confirm_reconcile]").on("click", function() {
2037 // Lines being reconciled will no longer be listed, so forget them
2038 $("input.checkforselect:checked").each(function() { delete checked[this.value]; });
2039 saveChecked();
2040 });
2041 });
2042 </script>';
2043 }
2044
2045 print '</form>';
2046 $db->free($resql);
2047} else {
2048 dol_print_error($db);
2049}
2050
2051// End of page
2052llxFooter();
2053$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
$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
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition bank.lib.php:40
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 members of a foundation.
Class to manage bank categories.
Class to manage withdrawal receipts.
Class for managing the social charges.
Class to manage donations.
Definition don.class.php:42
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 help generate other html components Only common components are here.
Loan.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of donations.
Class to manage payments of expense report.
Class to manage payments of salaries.
Class to manage payments of social contributions.
Class to manage payments of social contributions.
Class to manage various payments.
Class to manage cheque delivery receipts.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
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...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
currentToken()
Return the value of token currently saved into session with name 'token'.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
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.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
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.