* Copyright (C) 2004-2021 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2019 Nicolas ZABOURI * Copyright (C) 2019-2024 Frédéric France * * 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 . * or see https://www.gnu.org/ */ /** * \file htdocs/expensereport/index.php * \ingroup expensereport * \brief Page list of expenses */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; $hookmanager = new HookManager($db); // Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('expensereportindex')); // Load translation files required by the page $langs->loadLangs(array('companies', 'users', 'trips')); $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "d.tms"; } $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5); // Security check $socid = GETPOSTINT('socid'); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'expensereport', '', ''); /* * View */ $tripandexpense_static = new ExpenseReport($db); $childids = $user->getAllChildIds(); $childids[] = $user->id; $help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais"; llxHeader('', $langs->trans("TripsAndExpenses"), $help_url); $label = $somme = $nb = array(); $totalnb = $totalsum = 0; $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf"; $sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id"; // RESTRICT RIGHTS if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous') && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) { $childids = $user->getAllChildIds(); $childids[] = $user->id; $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n"; } $sql .= " GROUP BY tf.code, tf.label"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $somme[$objp->code] = $objp->km; $nb[$objp->code] = $objp->nb; $label[$objp->code] = $objp->label; $totalnb += $objp->nb; $totalsum += $objp->km; $i++; } $db->free($result); } else { dol_print_error($db); } print load_fiche_titre($langs->trans("ExpensesArea"), '', 'trip'); print '
'; print '
'; print ''; print ''; print ''; print "\n"; $listoftype = $tripandexpense_static->listOfTypes(); $dataseries = array(); foreach ($listoftype as $code => $label) { $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); } // Sort array with most important first $dataseries = dol_sort_array($dataseries, '1', 'desc'); // Merge all entries after the $KEEPNFIRST one into one entry called "Other..." (to avoid to have too much entries in graphic). $KEEPNFIRST = 7; // Keep first $KEEPNFIRST one + 1 with the remain $i = 0; if (count($dataseries) > ($KEEPNFIRST + 1)) { foreach ($dataseries as $key => $val) { if ($i < $KEEPNFIRST) { $i++; continue; } // Here $key = $KEEPNFIRST $dataseries[$KEEPNFIRST][0] = $langs->trans("Others").'...'; if ($key == $KEEPNFIRST) { $i++; continue; } $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1]; unset($dataseries[$key]); $i++; } } if ($conf->use_javascript_ajax) { print ''; } print ''; print ''; print ''; print ''; print '
'.$langs->trans("Statistics").'
'; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $dolgraph = new DolGraph(); $dolgraph->SetData($dataseries); $dolgraph->setHeight(350); $dolgraph->combine = !getDolGlobalString('MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT') ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT; $dolgraph->setShowLegend(2); $dolgraph->setShowPercent(1); $dolgraph->SetType(array('pie')); $dolgraph->setHeight('200'); $dolgraph->draw('idgraphstatus'); print $dolgraph->show($totalnb ? 0 : 1); print '
'.$langs->trans("Total").''.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).'
'; print '
'; // Right area print '
'; $langs->load("boxes"); $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,"; $sql .= " d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.rowid = d.fk_user_author"; // RESTRICT RIGHTS if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous') && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) { $childids = $user->getAllChildIds(); $childids[] = $user->id; $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n"; } $sql .= ' AND d.entity IN ('.getEntity('expensereport').')'; $sql .= $db->order($sortfield, $sortorder); $sql .= $db->plimit($max, 0); $result = $db->query($sql); if ($result) { $var = false; $num = $db->num_rows($result); $i = 0; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($num) { $total_ttc = $totalam = $total = 0; $expensereportstatic = new ExpenseReport($db); $userstatic = new User($db); while ($i < $num && $i < $max) { $obj = $db->fetch_object($result); $expensereportstatic->id = $obj->rowid; $expensereportstatic->ref = $obj->ref; $expensereportstatic->status = $obj->status; $userstatic->id = $obj->uid; $userstatic->admin = $obj->admin; $userstatic->email = $obj->email; $userstatic->lastname = $obj->lastname; $userstatic->firstname = $obj->firstname; $userstatic->login = $obj->login; $userstatic->status = $obj->user_status; $userstatic->photo = $obj->photo; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $i++; } } else { print ''; } print '
'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").''; print ''; print img_picto($langs->trans("FullList"), 'expensereport'); print ''; print '
'.$expensereportstatic->getNomUrl(1).''.$userstatic->getNomUrl(-1).''.price($obj->total_ht).''.price($obj->total_ttc).''.dol_print_date($db->jdate($obj->dm), 'day').''; print $expensereportstatic->getLibStatut(3); print '
'.$langs->trans("None").'

'; } else { dol_print_error($db); } print '
'; $parameters = array('user' => $user); $reshook = $hookmanager->executeHooks('dashboardExpenseReport', $parameters, $object); // Note that $action and $object may have been modified by hook // End of page llxFooter(); $db->close();