dolibarr  20.0.0-beta
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
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
34 require_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 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
45 $sortfield = GETPOST('sortfield', 'aZ09comma');
46 $sortorder = GETPOST('sortorder', 'aZ09comma');
47 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
48 if (empty($page) || $page == -1) {
49  $page = 0;
50 } // If $page is not defined, or '' or -1
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if (!$sortorder) {
55  $sortorder = "DESC";
56 }
57 if (!$sortfield) {
58  $sortfield = "d.tms";
59 }
60 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61 
62 $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
63 
64 // Security check
65 $socid = GETPOSTINT('socid');
66 if ($user->socid) {
67  $socid = $user->socid;
68 }
69 $result = restrictedArea($user, 'expensereport', '', '');
70 
71 
72 /*
73  * View
74  */
75 
76 $tripandexpense_static = new ExpenseReport($db);
77 
78 $childids = $user->getAllChildIds();
79 $childids[] = $user->id;
80 
81 $help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
82 
83 llxHeader('', $langs->trans("TripsAndExpenses"), $help_url);
84 
85 
86 $label = $somme = $nb = array();
87 
88 $totalnb = $totalsum = 0;
89 $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
90 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
91 $sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
92 // RESTRICT RIGHTS
93 if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
94  && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
95  $childids = $user->getAllChildIds();
96  $childids[] = $user->id;
97  $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n";
98 }
99 
100 $sql .= " GROUP BY tf.code, tf.label";
101 
102 $result = $db->query($sql);
103 if ($result) {
104  $num = $db->num_rows($result);
105  $i = 0;
106  while ($i < $num) {
107  $objp = $db->fetch_object($result);
108 
109  $somme[$objp->code] = $objp->km;
110  $nb[$objp->code] = $objp->nb;
111  $label[$objp->code] = $objp->label;
112  $totalnb += $objp->nb;
113  $totalsum += $objp->km;
114  $i++;
115  }
116  $db->free($result);
117 } else {
118  dol_print_error($db);
119 }
120 
121 
122 print load_fiche_titre($langs->trans("ExpensesArea"), '', 'trip');
123 
124 
125 print '<div class="fichecenter"><div class="fichethirdleft">';
126 
127 print '<div class="div-table-responsive-no-min">';
128 print '<table class="noborder nohover centpercent">';
129 print '<tr class="liste_titre">';
130 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
131 print "</tr>\n";
132 
133 $listoftype = $tripandexpense_static->listOfTypes();
134 $dataseries = array();
135 foreach ($listoftype as $code => $label) {
136  $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0));
137 }
138 
139 // Sort array with most important first
140 $dataseries = dol_sort_array($dataseries, 1, 'desc');
141 
142 // Merge all entries after the $KEEPNFIRST one into one entry called "Other..." (to avoid to have too much entries in graphic).
143 $KEEPNFIRST = 7; // Keep first $KEEPNFIRST one + 1 with the remain
144 $i = 0;
145 if (count($dataseries) > ($KEEPNFIRST + 1)) {
146  foreach ($dataseries as $key => $val) {
147  if ($i < $KEEPNFIRST) {
148  $i++;
149  continue;
150  }
151  // Here $key = $KEEPNFIRST
152  $dataseries[$KEEPNFIRST][0] = $langs->trans("Others").'...';
153  if ($key == $KEEPNFIRST) {
154  $i++;
155  continue;
156  }
157  $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
158  unset($dataseries[$key]);
159  $i++;
160  }
161 }
162 
163 if ($conf->use_javascript_ajax) {
164  print '<tr><td class="center" colspan="4">';
165 
166  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
167  $dolgraph = new DolGraph();
168  $dolgraph->SetData($dataseries);
169  $dolgraph->setHeight(350);
170  $dolgraph->combine = !getDolGlobalString('MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT') ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
171  $dolgraph->setShowLegend(2);
172  $dolgraph->setShowPercent(1);
173  $dolgraph->SetType(array('pie'));
174  $dolgraph->setHeight('200');
175  $dolgraph->draw('idgraphstatus');
176  print $dolgraph->show($totalnb ? 0 : 1);
177 
178  print '</td></tr>';
179 }
180 
181 print '<tr class="liste_total">';
182 print '<td>'.$langs->trans("Total").'</td>';
183 print '<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).'</td>';
184 print '</tr>';
185 
186 print '</table>';
187 print '</div>';
188 
189 
190 
191 // Right area
192 print '</div><div class="fichetwothirdright">';
193 
194 
195 $langs->load("boxes");
196 
197 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
198 $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";
199 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
200 $sql .= " WHERE u.rowid = d.fk_user_author";
201 // RESTRICT RIGHTS
202 if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
203  && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
204  $childids = $user->getAllChildIds();
205  $childids[] = $user->id;
206  $sql .= " AND d.fk_user_author IN (".$db->sanitize(implode(',', $childids)).")\n";
207 }
208 $sql .= ' AND d.entity IN ('.getEntity('expensereport').')';
209 $sql .= $db->order($sortfield, $sortorder);
210 $sql .= $db->plimit($max, 0);
211 
212 $result = $db->query($sql);
213 if ($result) {
214  $var = false;
215  $num = $db->num_rows($result);
216 
217  $i = 0;
218 
219  print '<div class="div-table-responsive-no-min">';
220  print '<table class="noborder centpercent">';
221  print '<tr class="liste_titre">';
222  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
223  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
224  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
225  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
226  print '<th>';
227  print '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">';
228  print img_picto($langs->trans("FullList"), 'expensereport');
229  print '</a>';
230  print '</th>';
231  print '</tr>';
232  if ($num) {
233  $total_ttc = $totalam = $total = 0;
234 
235  $expensereportstatic = new ExpenseReport($db);
236  $userstatic = new User($db);
237  while ($i < $num && $i < $max) {
238  $obj = $db->fetch_object($result);
239 
240  $expensereportstatic->id = $obj->rowid;
241  $expensereportstatic->ref = $obj->ref;
242  $expensereportstatic->status = $obj->status;
243 
244  $userstatic->id = $obj->uid;
245  $userstatic->admin = $obj->admin;
246  $userstatic->email = $obj->email;
247  $userstatic->lastname = $obj->lastname;
248  $userstatic->firstname = $obj->firstname;
249  $userstatic->login = $obj->login;
250  $userstatic->status = $obj->user_status;
251  $userstatic->photo = $obj->photo;
252 
253  print '<tr class="oddeven">';
254  print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
255  print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
256  print '<td class="right amount">'.price($obj->total_ht).'</td>';
257  print '<td class="right amount">'.price($obj->total_ttc).'</td>';
258  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
259  print '<td class="right">';
260  print $expensereportstatic->getLibStatut(3);
261  print '</td>';
262  print '</tr>';
263 
264  $i++;
265  }
266  } else {
267  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
268  }
269  print '</table></div><br>';
270 } else {
271  dol_print_error($db);
272 }
273 
274 print '</div></div>';
275 
276 $parameters = array('user' => $user);
277 $reshook = $hookmanager->executeHooks('dashboardExpenseReport', $parameters, $object); // Note that $action and $object may have been modified by hook
278 
279 // End of page
280 llxFooter();
281 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
Class to build graphs.
Class to manage Trips and Expenses.
Class to manage hooks.
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
llxFooter()
Footer empty.
Definition: index.php:72
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:64
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.