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';
45$langs->loadLangs(array(
'companies',
'users',
'trips'));
48$hookmanager->initHooks(array(
'expensereportindex'));
51$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
52$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
54if (empty($page) || $page == -1) {
57$offset = $limit * $page;
73 $socid = $user->socid;
84$childids = $user->getAllChildIds();
85$childids[] = $user->id;
87$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
89llxHeader(
'', $langs->trans(
"TripsAndExpenses"), $help_url);
92$label = $somme = array();
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";
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";
105$sql .=
" GROUP BY tf.code, tf.label";
107$result = $db->query($sql);
109 $num = $db->num_rows($result);
112 $objp = $db->fetch_object($result);
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;
130print
'<div class="fichecenter"><div class="fichethirdleft">';
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>';
138$listoftype = $tripandexpense_static->listOfTypes();
139$dataseries = array();
140foreach ($listoftype as $code => $label) {
141 $dataseries[] = array($label, (isset($somme[$code]) ? (
int) $somme[$code] : 0));
150if (count($dataseries) > ($KEEPNFIRST + 1)) {
151 foreach ($dataseries as $key => $val) {
152 if ($i < $KEEPNFIRST) {
157 $dataseries[$KEEPNFIRST][0] = $langs->trans(
"Others").
'...';
158 if ($key == $KEEPNFIRST) {
162 $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
163 unset($dataseries[$key]);
168if ($conf->use_javascript_ajax) {
169 print
'<tr><td class="center" colspan="4">';
171 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
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);
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>';
197print
'</div><div class="fichetwothirdright">';
200$langs->load(
"boxes");
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";
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";
213$sql .=
' AND d.entity IN ('.getEntity(
'expensereport').
')';
214$sql .= $db->order($sortfield, $sortorder);
215$sql .= $db->plimit($max, 0);
217$result = $db->query($sql);
220 $num = $db->num_rows($result);
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>';
232 print
'<a class="badge" title="'.$langs->trans(
"FullList").
'" href="'.DOL_URL_ROOT.
'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">';
238 $total_ttc = $totalam = $total = 0;
241 $userstatic =
new User($db);
242 while ($i < $num && $i < $max) {
243 $obj = $db->fetch_object($result);
245 $expensereportstatic->id = $obj->rowid;
246 $expensereportstatic->ref = $obj->ref;
247 $expensereportstatic->status = $obj->status;
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;
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);
272 print
'<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
274 print
'</table></div><br>';
281$parameters = array(
'user' => $user);
282$reshook = $hookmanager->executeHooks(
'dashboardExpenseReport', $parameters, $object);
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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.