*
* 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 importzugferdindex.php
* \ingroup importzugferd
* \brief Home page of the ZUGFeRD Import 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) {
die("Include of main fails");
}
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
dol_include_once('/importzugferd/class/zugferdimport.class.php');
dol_include_once('/importzugferd/lib/importzugferd.lib.php');
// Load translation files
$langs->loadLangs(array("importzugferd@importzugferd"));
// Security check
if (!isModEnabled('importzugferd')) {
accessforbidden('Module not enabled');
}
/*
* View
*/
$form = new Form($db);
$title = $langs->trans('ModuleImportZugferdName');
llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-importzugferd page-index');
print load_fiche_titre($title, '', 'fa-file-import');
print '
';
// Statistics box
print '
';
print '
';
print '
';
print '';
print '| '.$langs->trans('Statistics').' | ';
print '
';
// Count imports by status
$sql = "SELECT status, COUNT(*) as nb FROM ".MAIN_DB_PREFIX."importzugferd_import";
$sql .= " WHERE entity = ".(int)$conf->entity;
$sql .= " GROUP BY status";
$stats = array(0 => 0, 1 => 0, 2 => 0);
$resql = $db->query($sql);
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$stats[$obj->status] = $obj->nb;
}
}
$import = new ZugferdImport($db);
print '';
print '| '.$langs->trans('TotalImported').' | ';
print ''.array_sum($stats).' | ';
print '
';
print '';
print '| '.$import->LibStatut(0, 1).' | ';
print ''.$stats[0].' | ';
print '
';
print '';
print '| '.$import->LibStatut(1, 1).' | ';
print ''.$stats[1].' | ';
print '
';
print '';
print '| '.$import->LibStatut(2, 1).' | ';
print ''.$stats[2].' | ';
print '
';
print '
';
print '
';
print '
'; // fichethirdleft
// Quick actions and recent imports
print '
';
print '
';
// Recent imports
print '
';
print '
';
print '
';
print '';
print '| '.$langs->trans('RecentImports').' | ';
print '
';
$sql = "SELECT i.rowid, i.ref, i.invoice_number, i.invoice_date, i.seller_name, i.total_ttc, i.status";
$sql .= " FROM ".MAIN_DB_PREFIX."importzugferd_import as i";
$sql .= " WHERE i.entity = ".(int)$conf->entity;
$sql .= " ORDER BY i.date_creation DESC";
$sql .= " LIMIT 10";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0) {
while ($obj = $db->fetch_object($resql)) {
print '';
print '| '.$obj->ref.' | ';
print ''.dol_escape_htmltag($obj->invoice_number).' | ';
print ''.dol_print_date($db->jdate($obj->invoice_date), 'day').' | ';
print ''.dol_escape_htmltag($obj->seller_name).' | ';
print ''.price($obj->total_ttc).' EUR | ';
print ''.$import->LibStatut($obj->status, 0).' | ';
print '
';
}
} else {
print '| '.$langs->trans('NoRecordFound').' |
';
}
}
print '
';
print '
';
print '
'; // fichetwothirdright
print '
'; // fichecenter
print '';
llxFooter();
$db->close();