dolibarr  13.0.2
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 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) $socid = $user->socid;
46 $result = restrictedArea($user, 'expensereport', '', '');
47 
48 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST("sortfield", 'alpha');
50 $sortorder = GETPOST("sortorder", 'alpha');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if (!$sortorder) $sortorder = "DESC";
57 if (!$sortfield) $sortfield = "d.date_create";
58 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
59 
60 
61 /*
62  * View
63  */
64 
65 $tripandexpense_static = new ExpenseReport($db);
66 
67 $childids = $user->getAllChildIds();
68 $childids[] = $user->id;
69 
70 //$help_url='EN:Module_Donations|FR:Module_Dons|ES:M&oacute;dulo_Donaciones';
71 $help_url = '';
72 llxHeader('', $langs->trans("ListOfFees"), $help_url);
73 
74 
75 $label = $somme = $nb = array();
76 
77 $totalnb = $totalsum = 0;
78 $sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
79 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
80 $sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
81 // RESTRICT RIGHTS
82 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
83  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
84 {
85  $childids = $user->getAllChildIds();
86  $childids[] = $user->id;
87  $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
88 }
89 
90 $sql .= " GROUP BY tf.code, tf.label";
91 
92 $result = $db->query($sql);
93 if ($result)
94 {
95  $num = $db->num_rows($result);
96  $i = 0;
97  while ($i < $num)
98  {
99  $objp = $db->fetch_object($result);
100 
101  $somme[$objp->code] = $objp->km;
102  $nb[$objp->code] = $objp->nb;
103  $label[$objp->code] = $objp->label;
104  $totalnb += $objp->nb;
105  $totalsum += $objp->km;
106  $i++;
107  }
108  $db->free($result);
109 } else {
110  dol_print_error($db);
111 }
112 
113 
114 print load_fiche_titre($langs->trans("ExpensesArea"), '', 'trip');
115 
116 
117 print '<div class="fichecenter"><div class="fichethirdleft">';
118 
119 print '<div class="div-table-responsive-no-min">';
120 print '<table class="noborder nohover centpercent">';
121 print '<tr class="liste_titre">';
122 print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
123 print "</tr>\n";
124 
125 $listoftype = $tripandexpense_static->listOfTypes();
126 foreach ($listoftype as $code => $label)
127 {
128  $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0));
129 }
130 
131 if ($conf->use_javascript_ajax)
132 {
133  print '<tr><td class="center" colspan="4">';
134 
135  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
136  $dolgraph = new DolGraph();
137  $dolgraph->SetData($dataseries);
138  $dolgraph->setHeight(350);
139  $dolgraph->combine = empty($conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT) ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
140  $dolgraph->setShowLegend(2);
141  $dolgraph->setShowPercent(1);
142  $dolgraph->SetType(array('pie'));
143  $dolgraph->setHeight('200');
144  $dolgraph->draw('idgraphstatus');
145  print $dolgraph->show($totalnb ? 0 : 1);
146 
147  print '</td></tr>';
148 }
149 
150 print '<tr class="liste_total">';
151 print '<td>'.$langs->trans("Total").'</td>';
152 print '<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).'</td>';
153 print '</tr>';
154 
155 print '</table>';
156 print '</div>';
157 
158 
159 
160 // Right area
161 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
162 
163 
164 $max = 10;
165 
166 $langs->load("boxes");
167 
168 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
169 $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";
170 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
171 if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
172 $sql .= " WHERE u.rowid = d.fk_user_author";
173 // RESTRICT RIGHTS
174 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
175  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
176 {
177  $childids = $user->getAllChildIds();
178  $childids[] = $user->id;
179  $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
180 }
181 $sql .= ' AND d.entity IN ('.getEntity('expensereport').')';
182 if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
183 if ($socid) $sql .= " AND d.fk_user_author = ".$socid;
184 $sql .= $db->order($sortfield, $sortorder);
185 $sql .= $db->plimit($max, 0);
186 
187 $result = $db->query($sql);
188 if ($result)
189 {
190  $var = false;
191  $num = $db->num_rows($result);
192 
193  $i = 0;
194 
195  print '<div class="div-table-responsive-no-min">';
196  print '<table class="noborder centpercent">';
197  print '<tr class="liste_titre">';
198  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
199  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
200  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
201  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
202  print '<th>&nbsp;</th>';
203  print '</tr>';
204  if ($num)
205  {
206  $total_ttc = $totalam = $total = 0;
207 
208  $expensereportstatic = new ExpenseReport($db);
209  $userstatic = new User($db);
210  while ($i < $num && $i < $max)
211  {
212  $obj = $db->fetch_object($result);
213 
214  $expensereportstatic->id = $obj->rowid;
215  $expensereportstatic->ref = $obj->ref;
216  $expensereportstatic->status = $obj->status;
217 
218  $userstatic->id = $obj->uid;
219  $userstatic->admin = $obj->admin;
220  $userstatic->email = $obj->email;
221  $userstatic->lastname = $obj->lastname;
222  $userstatic->firstname = $obj->firstname;
223  $userstatic->login = $obj->login;
224  $userstatic->statut = $obj->user_status;
225  $userstatic->photo = $obj->photo;
226 
227  print '<tr class="oddeven">';
228  print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
229  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
230  print '<td class="right">'.price($obj->total_ht).'</td>';
231  print '<td class="right">'.price($obj->total_ttc).'</td>';
232  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
233  print '<td class="right">';
234  print $expensereportstatic->getLibStatut(3);
235  print '</td>';
236  print '</tr>';
237 
238  $i++;
239  }
240  } else {
241  print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
242  }
243  print '</table></div><br>';
244 } else dol_print_error($db);
245 
246 print '</div></div></div>';
247 
248 $parameters = array('user' => $user);
249 $reshook = $hookmanager->executeHooks('dashboardExpenseReport', $parameters, $object); // Note that $action and $object may have been modified by hook
250 
251 // End of page
252 llxFooter();
253 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage Trips and Expenses.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59