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