* * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file bankimport/bankimportindex.php * \ingroup bankimport * \brief Dashboard page for BankImport module */ // 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 && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array("bankimport@bankimport", "banks")); $action = GETPOST('action', 'aZ09'); // Security check if (!$user->hasRight('bankimport', 'read')) { accessforbidden(); } $socid = GETPOSTINT('socid'); if (!empty($user->socid) && $user->socid > 0) { $action = ''; $socid = $user->socid; } /* * View */ $form = new Form($db); dol_include_once('/bankimport/class/bankstatement.class.php'); llxHeader("", $langs->trans("BankImportArea"), '', '', 0, 0, '', '', '', 'mod-bankimport page-index'); print load_fiche_titre($langs->trans("BankImportArea"), '', 'bank'); // Reminder: check if statements are outdated $reminderEnabled = getDolGlobalString('BANKIMPORT_REMINDER_ENABLED', '1'); if ($reminderEnabled) { $reminderMonths = getDolGlobalInt('BANKIMPORT_REMINDER_MONTHS') ?: 3; $stmtCheck = new BankImportStatement($db); $lastEndDate = $stmtCheck->getLatestStatementEndDate(); $thresholdDate = dol_time_plus_duree(dol_now(), -$reminderMonths, 'm'); if ($lastEndDate === null) { // No statements at all print '
'; print img_warning().' '.$langs->trans("ReminderNoStatements"); print ' '.$langs->trans("UploadPDFStatement").''; print '

'; } elseif ($lastEndDate < $thresholdDate) { $monthsAgo = (int) round((dol_now() - $lastEndDate) / (30 * 24 * 3600)); print '
'; print img_warning().' '.$langs->trans("ReminderOutdatedStatements", dol_print_date($lastEndDate, 'day'), $monthsAgo); print ' '.$langs->trans("UploadPDFStatement").''; print '

'; } } // Payment matching notification $bankAccountId = getDolGlobalInt('BANKIMPORT_BANK_ACCOUNT_ID'); if (!empty($bankAccountId)) { $sqlNewCount = "SELECT COUNT(*) as cnt FROM ".MAIN_DB_PREFIX."bankimport_transaction"; $sqlNewCount .= " WHERE entity IN (".getEntity('banktransaction').")"; $sqlNewCount .= " AND status = 0"; $resNewCount = $db->query($sqlNewCount); $newCount = 0; if ($resNewCount) { $objNewCount = $db->fetch_object($resNewCount); $newCount = (int) $objNewCount->cnt; } if ($newCount > 0) { print '
'; print img_picto('', 'payment', 'class="pictofixedwidth"'); print ''.$langs->trans("PendingPaymentMatches", $newCount).''; print '
'.$langs->trans("PendingPaymentMatchesDesc"); print ' '; print $langs->trans("ReviewAndConfirm"); print ''; print '
'; } } else { print '
'; print img_warning().' '.$langs->trans("NoBankAccountConfigured"); print ' '.$langs->trans("GoToSetup").''; print '
'; } print '
'; // ----------------------------------------------- // Widget: Letzte 10 importierte Buchungen // ----------------------------------------------- $max = 10; $sql = "SELECT t.rowid, t.ref, t.date_trans, t.name, t.description, t.amount, t.currency, t.status"; $sql .= " FROM ".MAIN_DB_PREFIX."bankimport_transaction as t"; $sql .= " WHERE t.entity IN (".getEntity('banktransaction').")"; $sql .= " ORDER BY t.date_trans DESC, t.rowid DESC"; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); print ''; print ''; print ''; print ''; if ($resql) { $num = $db->num_rows($resql); if ($num > 0) { $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); print ''; // Date print ''; // Name + Description print ''; // Amount print ''; // Status print ''; print ''; $i++; } } else { print ''; } $db->free($resql); } else { dol_print_error($db); } print '
'; print $langs->trans("LastImportedTransactions"); // Count total $sqlcount = "SELECT COUNT(*) as total FROM ".MAIN_DB_PREFIX."bankimport_transaction WHERE entity IN (".getEntity('banktransaction').")"; $rescount = $db->query($sqlcount); if ($rescount) { $objcount = $db->fetch_object($rescount); if ($objcount->total > 0) { print ''; print ''.$objcount->total.''; print ''; } } print '
'; print dol_print_date($db->jdate($obj->date_trans), 'day'); print ''; print ''; print dol_escape_htmltag(dol_trunc($obj->name, 30)); print ''; if ($obj->description) { print '
'.dol_escape_htmltag(dol_trunc($obj->description, 40)).''; } 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 ''; switch ($obj->status) { case 0: print ''.$langs->trans("New").''; break; case 1: print ''.$langs->trans("Matched").''; break; case 2: print ''.$langs->trans("Reconciled").''; break; case 9: print ''.$langs->trans("Ignored").''; break; } print '
'.$langs->trans("NoTransactionsInDatabase").'
'; // Link "Alle anzeigen" if (!empty($objcount) && $objcount->total > 0) { print ''; } print '
'; // ----------------------------------------------- // Widget: Letzte 5 PDF-Kontoauszüge // ----------------------------------------------- $maxpdf = 5; $sql2 = "SELECT s.rowid, s.statement_number, s.statement_year, s.iban, s.date_from, s.date_to,"; $sql2 .= " s.opening_balance, s.closing_balance, s.filename, s.filepath, s.filesize, s.datec"; $sql2 .= " FROM ".MAIN_DB_PREFIX."bankimport_statement as s"; $sql2 .= " WHERE s.entity IN (".getEntity('bankstatement').")"; $sql2 .= " ORDER BY s.datec DESC"; $sql2 .= $db->plimit($maxpdf, 0); $resql2 = $db->query($sql2); print ''; print ''; print ''; print ''; if ($resql2) { $num2 = $db->num_rows($resql2); if ($num2 > 0) { $i = 0; while ($i < $num2) { $obj2 = $db->fetch_object($resql2); print ''; // Statement number / Year print ''; // IBAN (shortened) print ''; // Period print ''; // Closing balance print ''; // Actions print ''; print ''; $i++; } } else { print ''; } $db->free($resql2); } else { dol_print_error($db); } print '
'; print $langs->trans("LastPDFStatements"); // Count total $sqlcount2 = "SELECT COUNT(*) as total FROM ".MAIN_DB_PREFIX."bankimport_statement WHERE entity IN (".getEntity('bankstatement').")"; $rescount2 = $db->query($sqlcount2); if ($rescount2) { $objcount2 = $db->fetch_object($rescount2); if ($objcount2->total > 0) { print ''; print ''.$objcount2->total.''; print ''; } } print '
'; print ''.dol_escape_htmltag($obj2->statement_number).'/'.$obj2->statement_year; print ''; if ($obj2->iban) { print dol_escape_htmltag(dol_trunc($obj2->iban, 20)); } else { print '-'; } print ''; if ($obj2->date_from && $obj2->date_to) { print dol_print_date($db->jdate($obj2->date_from), 'day').' - '.dol_print_date($db->jdate($obj2->date_to), 'day'); } elseif ($obj2->date_from) { print dol_print_date($db->jdate($obj2->date_from), 'day').' -'; } else { print '-'; } print ''; if ($obj2->closing_balance !== null && $obj2->closing_balance !== '') { $color = (float) $obj2->closing_balance >= 0 ? '' : 'color: red;'; print ''.price($obj2->closing_balance, 0, $langs, 1, -1, 2, 'EUR').''; } else { print '-'; } print ''; if ($obj2->filepath && file_exists($obj2->filepath)) { print ''; print img_picto($langs->trans("View"), 'eye'); print ''; print ''; print img_picto($langs->trans("Download"), 'download'); print ''; } print '
'.$langs->trans("NoPDFStatementsFound").'
'; // Links print '
'; if (!empty($objcount2) && $objcount2->total > 0) { print ''; print $langs->trans("ShowAll"); print ''; print ' | '; } print ''; print $langs->trans("UploadNew").' »'; print ''; print '
'; print '
'; // End of page llxFooter(); $db->close();