dolibarr 19.0.4
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 Frédéric FRANCE <frederic.france@netlogic.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
36$hookmanager = new HookManager($db);
37
38// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
39$hookmanager->initHooks(array('expensereportindex'));
40
41// Load translation files required by the page
42$langs->loadLangs(array('companies', 'users', 'trips'));
43
44// Security check
45$socid = GETPOST('socid', 'int');
46if ($user->socid) {
47 $socid = $user->socid;
48}
49$result = restrictedArea($user, 'expensereport', '', '');
50
51$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
52$sortfield = GETPOST('sortfield', 'aZ09comma');
53$sortorder = GETPOST('sortorder', 'aZ09comma');
54$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
55if (empty($page) || $page == -1) {
56 $page = 0;
57} // If $page is not defined, or '' or -1
58$offset = $limit * $page;
59$pageprev = $page - 1;
60$pagenext = $page + 1;
61if (!$sortorder) {
62 $sortorder = "DESC";
63}
64if (!$sortfield) {
65 $sortfield = "d.date_create";
66}
67$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
68
69
70/*
71 * View
72 */
73
74$tripandexpense_static = new ExpenseReport($db);
75
76$childids = $user->getAllChildIds();
77$childids[] = $user->id;
78
79$help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
80
81llxHeader('', $langs->trans("TripsAndExpenses"), $help_url);
82
83
84$label = $somme = $nb = array();
85
86$totalnb = $totalsum = 0;
87$sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
88$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
89$sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
90// RESTRICT RIGHTS
91if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
92 && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
93 $childids = $user->getAllChildIds();
94 $childids[] = $user->id;
95 $sql .= " AND d.fk_user_author IN (".$db->sanitize(join(',', $childids)).")\n";
96}
97
98$sql .= " GROUP BY tf.code, tf.label";
99
100$result = $db->query($sql);
101if ($result) {
102 $num = $db->num_rows($result);
103 $i = 0;
104 while ($i < $num) {
105 $objp = $db->fetch_object($result);
106
107 $somme[$objp->code] = $objp->km;
108 $nb[$objp->code] = $objp->nb;
109 $label[$objp->code] = $objp->label;
110 $totalnb += $objp->nb;
111 $totalsum += $objp->km;
112 $i++;
113 }
114 $db->free($result);
115} else {
116 dol_print_error($db);
117}
118
119
120print load_fiche_titre($langs->trans("ExpensesArea"), '', 'trip');
121
122
123print '<div class="fichecenter"><div class="fichethirdleft">';
124
125print '<div class="div-table-responsive-no-min">';
126print '<table class="noborder nohover centpercent">';
127print '<tr class="liste_titre">';
128print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
129print "</tr>\n";
130
131$listoftype = $tripandexpense_static->listOfTypes();
132foreach ($listoftype as $code => $label) {
133 $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0));
134}
135
136// Sort array with most important first
137$dataseries = dol_sort_array($dataseries, 1, 'desc');
138
139// Merge all entrie after the $KEEPNFIRST one into one entry called "Other..." (to avoid to have too much entries in graphic).
140$KEEPNFIRST = 7; // Keep first $KEEPNFIRST one + 1 with the remain
141$i = 0;
142if (count($dataseries) > ($KEEPNFIRST + 1)) {
143 foreach ($dataseries as $key => $val) {
144 if ($i < $KEEPNFIRST) {
145 $i++;
146 continue;
147 }
148 // Here $key = $KEEPNFIRST
149 $dataseries[$KEEPNFIRST][0] = $langs->trans("Others").'...';
150 if ($key == $KEEPNFIRST) {
151 $i++;
152 continue;
153 }
154 $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
155 unset($dataseries[$key]);
156 $i++;
157 }
158}
159
160if ($conf->use_javascript_ajax) {
161 print '<tr><td class="center" colspan="4">';
162
163 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
164 $dolgraph = new DolGraph();
165 $dolgraph->SetData($dataseries);
166 $dolgraph->setHeight(350);
167 $dolgraph->combine = !getDolGlobalString('MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT') ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
168 $dolgraph->setShowLegend(2);
169 $dolgraph->setShowPercent(1);
170 $dolgraph->SetType(array('pie'));
171 $dolgraph->setHeight('200');
172 $dolgraph->draw('idgraphstatus');
173 print $dolgraph->show($totalnb ? 0 : 1);
174
175 print '</td></tr>';
176}
177
178print '<tr class="liste_total">';
179print '<td>'.$langs->trans("Total").'</td>';
180print '<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).'</td>';
181print '</tr>';
182
183print '</table>';
184print '</div>';
185
186
187
188// Right area
189print '</div><div class="fichetwothirdright">';
190
191
192$max = 10;
193
194$langs->load("boxes");
195
196$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
197$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";
198$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
199$sql .= " WHERE u.rowid = d.fk_user_author";
200// RESTRICT RIGHTS
201if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
202 && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
203 $childids = $user->getAllChildIds();
204 $childids[] = $user->id;
205 $sql .= " AND d.fk_user_author IN (".$db->sanitize(join(',', $childids)).")\n";
206}
207$sql .= ' AND d.entity IN ('.getEntity('expensereport').')';
208$sql .= $db->order($sortfield, $sortorder);
209$sql .= $db->plimit($max, 0);
210
211$result = $db->query($sql);
212if ($result) {
213 $var = false;
214 $num = $db->num_rows($result);
215
216 $i = 0;
217
218 print '<div class="div-table-responsive-no-min">';
219 print '<table class="noborder centpercent">';
220 print '<tr class="liste_titre">';
221 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
222 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
223 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
224 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
225 print '<th>&nbsp;</th>';
226 print '</tr>';
227 if ($num) {
228 $total_ttc = $totalam = $total = 0;
229
230 $expensereportstatic = new ExpenseReport($db);
231 $userstatic = new User($db);
232 while ($i < $num && $i < $max) {
233 $obj = $db->fetch_object($result);
234
235 $expensereportstatic->id = $obj->rowid;
236 $expensereportstatic->ref = $obj->ref;
237 $expensereportstatic->status = $obj->status;
238
239 $userstatic->id = $obj->uid;
240 $userstatic->admin = $obj->admin;
241 $userstatic->email = $obj->email;
242 $userstatic->lastname = $obj->lastname;
243 $userstatic->firstname = $obj->firstname;
244 $userstatic->login = $obj->login;
245 $userstatic->statut = $obj->user_status;
246 $userstatic->photo = $obj->photo;
247
248 print '<tr class="oddeven">';
249 print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
250 print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
251 print '<td class="right amount">'.price($obj->total_ht).'</td>';
252 print '<td class="right amount">'.price($obj->total_ttc).'</td>';
253 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
254 print '<td class="right">';
255 print $expensereportstatic->getLibStatut(3);
256 print '</td>';
257 print '</tr>';
258
259 $i++;
260 }
261 } else {
262 print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
263 }
264 print '</table></div><br>';
265} else {
266 dol_print_error($db);
267}
268
269print '</div></div>';
270
271$parameters = array('user' => $user);
272$reshook = $hookmanager->executeHooks('dashboardExpenseReport', $parameters, $object); // Note that $action and $object may have been modified by hook
273
274// End of page
275llxFooter();
276$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to build graphs.
Class to manage Trips and Expenses.
Class to manage hooks.
Class to manage Dolibarr users.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return 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.