dolibarr 23.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
8 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
34require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array('companies', 'users', 'trips'));
46
47// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
48$hookmanager->initHooks(array('expensereportindex'));
49
50$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
51$sortfield = GETPOST('sortfield', 'aZ09comma');
52$sortorder = GETPOST('sortorder', 'aZ09comma');
53$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
54if (empty($page) || $page == -1) {
55 $page = 0;
56} // If $page is not defined, or '' or -1
57$offset = $limit * $page;
58$pageprev = $page - 1;
59$pagenext = $page + 1;
60if (!$sortorder) {
61 $sortorder = "DESC";
62}
63if (!$sortfield) {
64 $sortfield = "d.tms";
65}
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67
68$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
69
70// Security check
71$socid = GETPOSTINT('socid');
72if ($user->socid) {
73 $socid = $user->socid;
74}
75$result = restrictedArea($user, 'expensereport', '', '');
76
77
78/*
79 * View
80 */
81
82$tripandexpense_static = new ExpenseReport($db);
83
84$childids = $user->getAllChildIds();
85$childids[] = $user->id;
86
87$help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
88
89llxHeader('', $langs->trans("TripsAndExpenses"), $help_url);
90
91
92$label = $somme = array();
93
94$totalnb = $totalsum = 0;
95$sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
96$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
97$sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
98// RESTRICT RIGHTS
99if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
100 && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
101 $childids = $user->getAllChildIds();
102 $childids[] = $user->id;
103 $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n";
104}
105$sql .= " GROUP BY tf.code, tf.label";
106
107$result = $db->query($sql);
108if ($result) {
109 $num = $db->num_rows($result);
110 $i = 0;
111 while ($i < $num) {
112 $objp = $db->fetch_object($result);
113
114 $somme[$objp->code] = $objp->km;
115 $nb[$objp->code] = $objp->nb;
116 $label[$objp->code] = $objp->label;
117 $totalnb += $objp->nb;
118 $totalsum += $objp->km;
119 $i++;
120 }
121 $db->free($result);
122} else {
123 dol_print_error($db);
124}
125
126
127print load_fiche_titre($langs->trans("ExpensesArea"), '', 'trip');
128
129
130print '<div class="fichecenter"><div class="fichethirdleft">';
131
132print '<div class="div-table-responsive-no-min">';
133print '<table class="noborder nohover centpercent">';
134print '<tr class="liste_titre">';
135print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
136print "</tr>\n";
137
138$listoftype = $tripandexpense_static->listOfTypes();
139$dataseries = array();
140foreach ($listoftype as $code => $label) {
141 $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0));
142}
143
144// Sort array with most important first
145$dataseries = dol_sort_array($dataseries, '1', 'desc');
146
147// Merge all entries after the $KEEPNFIRST one into one entry called "Other..." (to avoid to have too much entries in graphic).
148$KEEPNFIRST = 7; // Keep first $KEEPNFIRST one + 1 with the remain
149$i = 0;
150if (count($dataseries) > ($KEEPNFIRST + 1)) {
151 foreach ($dataseries as $key => $val) {
152 if ($i < $KEEPNFIRST) {
153 $i++;
154 continue;
155 }
156 // Here $key = $KEEPNFIRST
157 $dataseries[$KEEPNFIRST][0] = $langs->trans("Others").'...';
158 if ($key == $KEEPNFIRST) {
159 $i++;
160 continue;
161 }
162 $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
163 unset($dataseries[$key]);
164 $i++;
165 }
166}
167
168if ($conf->use_javascript_ajax) {
169 print '<tr><td class="center" colspan="4">';
170
171 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
172 $dolgraph = new DolGraph();
173 $dolgraph->SetData($dataseries);
174 $dolgraph->setHeight(350);
175 $dolgraph->combine = !getDolGlobalString('MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT') ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
176 $dolgraph->setShowLegend(2);
177 $dolgraph->setShowPercent(1);
178 $dolgraph->SetType(array('pie'));
179 $dolgraph->setHeight('200');
180 $dolgraph->draw('idgraphstatus');
181 print $dolgraph->show($totalnb ? 0 : 1);
182
183 print '</td></tr>';
184}
185
186print '<tr class="liste_total">';
187print '<td>'.$langs->trans("Total").'</td>';
188print '<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).'</td>';
189print '</tr>';
190
191print '</table>';
192print '</div>';
193
194
195
196// Right area
197print '</div><div class="fichetwothirdright">';
198
199
200$langs->load("boxes");
201
202$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
203$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";
204$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
205$sql .= " WHERE u.rowid = d.fk_user_author";
206// RESTRICT RIGHTS
207if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
208 && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
209 $childids = $user->getAllChildIds();
210 $childids[] = $user->id;
211 $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n";
212}
213$sql .= ' AND d.entity IN ('.getEntity('expensereport').')';
214$sql .= $db->order($sortfield, $sortorder);
215$sql .= $db->plimit($max, 0);
216
217$result = $db->query($sql);
218if ($result) {
219 $var = false;
220 $num = $db->num_rows($result);
221
222 $i = 0;
223
224 print '<div class="div-table-responsive-no-min">';
225 print '<table class="noborder centpercent">';
226 print '<tr class="liste_titre">';
227 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
228 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
229 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
230 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
231 print '<th>';
232 print '<a class="badge" title="'.$langs->trans("FullList").'" href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">';
233 print '...';
234 print '</a>';
235 print '</th>';
236 print '</tr>';
237 if ($num) {
238 $total_ttc = $totalam = $total = 0;
239
240 $expensereportstatic = new ExpenseReport($db);
241 $userstatic = new User($db);
242 while ($i < $num && $i < $max) {
243 $obj = $db->fetch_object($result);
244
245 $expensereportstatic->id = $obj->rowid;
246 $expensereportstatic->ref = $obj->ref;
247 $expensereportstatic->status = $obj->status;
248
249 $userstatic->id = $obj->uid;
250 $userstatic->admin = $obj->admin;
251 $userstatic->email = $obj->email;
252 $userstatic->lastname = $obj->lastname;
253 $userstatic->firstname = $obj->firstname;
254 $userstatic->login = $obj->login;
255 $userstatic->status = $obj->user_status;
256 $userstatic->photo = $obj->photo;
257
258 print '<tr class="oddeven">';
259 print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
260 print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
261 print '<td class="right amount">'.price($obj->total_ht).'</td>';
262 print '<td class="right amount">'.price($obj->total_ttc).'</td>';
263 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
264 print '<td class="right">';
265 print $expensereportstatic->getLibStatut(3);
266 print '</td>';
267 print '</tr>';
268
269 $i++;
270 }
271 } else {
272 print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
273 }
274 print '</table></div><br>';
275} else {
276 dol_print_error($db);
277}
278
279print '</div></div>';
280
281$parameters = array('user' => $user);
282$reshook = $hookmanager->executeHooks('dashboardExpenseReport', $parameters, $object); // Note that $action and $object may have been modified by hook
283
284// End of page
285llxFooter();
286$db->close();
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
Class to build graphs.
Class to manage Trips and Expenses.
Class to manage Dolibarr users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.