* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. */ /** * \file bankimport/list.php * \ingroup bankimport * \brief List page for imported bank transactions */ // Load Dolibarr environment $res = 0; if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; } $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } if (!$res && file_exists("../main.inc.php")) { $res = @include "../main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; dol_include_once('/bankimport/class/banktransaction.class.php'); dol_include_once('/bankimport/lib/bankimport.lib.php'); /** * @var Conf $conf * @var DoliDB $db * @var Translate $langs * @var User $user */ $langs->loadLangs(array("bankimport@bankimport", "banks", "bills")); $action = GETPOST('action', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bankimporttransactionlist'; // Security check if (!$user->hasRight('bankimport', 'read')) { accessforbidden(); } // Search parameters - restore from session if no explicit filter provided $sessionKey = 'bankimport_list_filters'; $hasSearchParams = GETPOSTISSET('search_ref') || GETPOSTISSET('search_status') || GETPOSTISSET('button_search') || GETPOSTISSET('button_removefilter') || GETPOSTISSET('button_removefilter_x') || GETPOSTISSET('button_removefilter.x') || GETPOSTISSET('search_iban') || GETPOSTISSET('search_name') || GETPOSTISSET('search_description') || GETPOSTISSET('search_amount_min') || GETPOSTISSET('search_amount_max') || GETPOSTISSET('search_date_fromday') || GETPOSTISSET('search_date_today') || GETPOSTISSET('sortfield') || GETPOSTISSET('page'); if ($hasSearchParams) { // User is actively filtering - read from GET/POST $search_ref = GETPOST('search_ref', 'alpha'); $search_iban = GETPOST('search_iban', 'alpha'); $search_name = GETPOST('search_name', 'alpha'); $search_description = GETPOST('search_description', 'alpha'); $search_amount_min = GETPOST('search_amount_min', 'alpha'); $search_amount_max = GETPOST('search_amount_max', 'alpha'); $search_status = GETPOST('search_status', 'intcomma'); $search_date_from = dol_mktime(0, 0, 0, GETPOSTINT('search_date_frommonth'), GETPOSTINT('search_date_fromday'), GETPOSTINT('search_date_fromyear')); $search_date_to = dol_mktime(23, 59, 59, GETPOSTINT('search_date_tomonth'), GETPOSTINT('search_date_today'), GETPOSTINT('search_date_toyear')); } elseif (!empty($_SESSION[$sessionKey])) { // Restore from session (coming back from card.php/confirm.php) $filters = $_SESSION[$sessionKey]; $search_ref = $filters['search_ref'] ?? ''; $search_iban = $filters['search_iban'] ?? ''; $search_name = $filters['search_name'] ?? ''; $search_description = $filters['search_description'] ?? ''; $search_amount_min = $filters['search_amount_min'] ?? ''; $search_amount_max = $filters['search_amount_max'] ?? ''; $search_status = $filters['search_status'] ?? ''; $search_date_from = $filters['search_date_from'] ?? ''; $search_date_to = $filters['search_date_to'] ?? ''; } else { // First visit - apply default status filter from admin settings $search_ref = ''; $search_iban = ''; $search_name = ''; $search_description = ''; $search_amount_min = ''; $search_amount_max = ''; $defaultStatus = getDolGlobalString('BANKIMPORT_LIST_DEFAULT_STATUS'); $search_status = ($defaultStatus !== '') ? $defaultStatus : ''; $search_date_from = ''; $search_date_to = ''; } // Sorting $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); if (!$sortfield) $sortfield = 'date_trans'; if (!$sortorder) $sortorder = 'DESC'; // Pagination $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page'); if (empty($page) || $page < 0) $page = 0; $offset = $limit * $page; /* * Actions */ // Reset search if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $search_ref = ''; $search_iban = ''; $search_name = ''; $search_description = ''; $search_amount_min = ''; $search_amount_max = ''; $search_status = ''; $search_date_from = ''; $search_date_to = ''; $toselect = array(); unset($_SESSION[$sessionKey]); } // Save current filters to session for persistence across page navigation $_SESSION[$sessionKey] = array( 'search_ref' => $search_ref, 'search_iban' => $search_iban, 'search_name' => $search_name, 'search_description' => $search_description, 'search_amount_min' => $search_amount_min, 'search_amount_max' => $search_amount_max, 'search_status' => $search_status, 'search_date_from' => $search_date_from, 'search_date_to' => $search_date_to, ); /* * View */ $form = new Form($db); $transaction = new BankImportTransaction($db); $title = $langs->trans("TransactionList"); llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-bankimport page-list'); print load_fiche_titre($title, '', 'bank'); // Build filter array $filter = array(); if (!empty($search_ref)) $filter['ref'] = $search_ref; if (!empty($search_iban)) $filter['iban'] = $search_iban; if (!empty($search_name)) $filter['name'] = $search_name; if (!empty($search_description)) $filter['description'] = $search_description; if (!empty($search_amount_min)) $filter['amount_min'] = price2num($search_amount_min); if (!empty($search_amount_max)) $filter['amount_max'] = price2num($search_amount_max); if ($search_status !== '' && $search_status >= 0) $filter['status'] = (int) $search_status; if (!empty($search_date_from)) $filter['date_from'] = $search_date_from; if (!empty($search_date_to)) $filter['date_to'] = $search_date_to; // Count total $totalRecords = $transaction->fetchAll('', '', 0, 0, $filter, 'count'); // Fetch records $records = $transaction->fetchAll($sortfield, $sortorder, $limit, $offset, $filter); // Form $param = ''; if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref); if (!empty($search_iban)) $param .= '&search_iban='.urlencode($search_iban); if (!empty($search_name)) $param .= '&search_name='.urlencode($search_name); if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); if (!empty($search_amount_min)) $param .= '&search_amount_min='.urlencode($search_amount_min); if (!empty($search_amount_max)) $param .= '&search_amount_max='.urlencode($search_amount_max); if ($search_status !== '' && $search_status >= 0) $param .= '&search_status='.urlencode($search_status); if (!empty($search_date_from)) { $param .= '&search_date_fromday='.dol_print_date($search_date_from, '%d'); $param .= '&search_date_frommonth='.dol_print_date($search_date_from, '%m'); $param .= '&search_date_fromyear='.dol_print_date($search_date_from, '%Y'); } if (!empty($search_date_to)) { $param .= '&search_date_today='.dol_print_date($search_date_to, '%d'); $param .= '&search_date_tomonth='.dol_print_date($search_date_to, '%m'); $param .= '&search_date_toyear='.dol_print_date($search_date_to, '%Y'); } print '
'; print ''; print ''; print ''; // Navigation print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', is_array($records) ? count($records) : 0, $totalRecords, '', 0, '', '', $limit); print '
'; print ''; // Header row with filters print ''; // Ref print ''; // IBAN print ''; // Date print ''; // Name print ''; // Description print ''; // Amount print ''; // Statement print ''; // Status print ''; // Action buttons print ''; print ''; // Header titles print ''; print_liste_field_titre($langs->trans("TransactionRef"), $_SERVER["PHP_SELF"], "ref", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("AccountIBAN"), $_SERVER["PHP_SELF"], "iban", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Date"), $_SERVER["PHP_SELF"], "date_trans", "", $param, 'class="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Counterparty"), $_SERVER["PHP_SELF"], "name", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "description", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "amount", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("PDFStatement"), $_SERVER["PHP_SELF"], "fk_statement", "", $param, 'class="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "status", "", $param, 'class="center"', $sortfield, $sortorder); print_liste_field_titre('', $_SERVER["PHP_SELF"], "", "", $param, 'class="center"', $sortfield, $sortorder); print ''; // Data rows if (is_array($records) && count($records) > 0) { foreach ($records as $obj) { print ''; // Ref print ''; // IBAN print ''; // Date print ''; // Name print ''; // Description print ''; // Amount print ''; // Statement link print ''; // Status print ''; // Actions print ''; print ''; } } else { print ''; } print '
'; print ''; print ''; print ''; print ''; print '
'; print $form->selectDate($search_date_from, 'search_date_from', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); print '
'; print '
'; print $form->selectDate($search_date_to, 'search_date_to', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("To")); print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ' - '; print ''; print ''; print ''; $statusArray = array( '' => $langs->trans("AllStatuses"), '0' => $langs->trans("StatusNew"), '1' => $langs->trans("StatusMatched"), '2' => $langs->trans("StatusReconciled"), '9' => $langs->trans("StatusIgnored") ); print $form->selectarray('search_status', $statusArray, $search_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100'); print ''; print ''; print ' '; print ''; print '
'; print ''.dol_escape_htmltag($obj->ref).''; print ''; print dol_escape_htmltag(dol_trunc($obj->iban, 20)); print ''; print dol_print_date($obj->date_trans, 'day'); print ''; print dol_escape_htmltag($obj->name); print ''; print dol_escape_htmltag(dol_trunc($obj->description, 60)); print ''; if ($obj->amount >= 0) { print '+'.price($obj->amount, 0, $langs, 1, -1, 2, $obj->currency).''; } else { print ''.price($obj->amount, 0, $langs, 1, -1, 2, $obj->currency).''; } print ''; if (!empty($obj->fk_statement)) { print ''; print img_picto($langs->trans("ViewPDFStatement"), 'pdf'); print ''; } print ''; print $obj->getLibStatut(5); print ''; print ''.img_edit().''; print '
'; print $langs->trans("NoTransactionsInDatabase"); print '
'; print '
'; print '
'; // Buttons print '
'; print ''.$langs->trans("FetchStatements").''; print '
'; llxFooter(); $db->close();