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 = $nb = 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";
106$sql .=
" GROUP BY tf.code, tf.label";
108$result = $db->query($sql);
110 $num = $db->num_rows($result);
113 $objp = $db->fetch_object($result);
115 $somme[$objp->code] = $objp->km;
116 $nb[$objp->code] = $objp->nb;
117 $label[$objp->code] = $objp->label;
118 $totalnb += $objp->nb;
119 $totalsum += $objp->km;
131print
'<div class="fichecenter"><div class="fichethirdleft">';
133print
'<div class="div-table-responsive-no-min">';
134print
'<table class="noborder nohover centpercent">';
135print
'<tr class="liste_titre">';
136print
'<th colspan="4">'.$langs->trans(
"Statistics").
'</th>';
139$listoftype = $tripandexpense_static->listOfTypes();
140$dataseries = array();
141foreach ($listoftype as $code => $label) {
142 $dataseries[] = array($label, (isset($somme[$code]) ? (
int) $somme[$code] : 0));
151if (count($dataseries) > ($KEEPNFIRST + 1)) {
152 foreach ($dataseries as $key => $val) {
153 if ($i < $KEEPNFIRST) {
158 $dataseries[$KEEPNFIRST][0] = $langs->trans(
"Others").
'...';
159 if ($key == $KEEPNFIRST) {
163 $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
164 unset($dataseries[$key]);
169if (
$conf->use_javascript_ajax) {
170 print
'<tr><td class="center" colspan="4">';
172 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
174 $dolgraph->SetData($dataseries);
175 $dolgraph->setHeight(350);
176 $dolgraph->combine = !
getDolGlobalString(
'MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT') ? 0.05 :
$conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
177 $dolgraph->setShowLegend(2);
178 $dolgraph->setShowPercent(1);
179 $dolgraph->SetType(array(
'pie'));
180 $dolgraph->setHeight(
'200');
181 $dolgraph->draw(
'idgraphstatus');
182 print $dolgraph->show($totalnb ? 0 : 1);
187print
'<tr class="liste_total">';
188print
'<td>'.$langs->trans(
"Total").
'</td>';
189print
'<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0,
$conf->currency).
'</td>';
198print
'</div><div class="fichetwothirdright">';
201$langs->load(
"boxes");
203$sql =
"SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
204$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";
205$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d, ".MAIN_DB_PREFIX.
"user as u";
206$sql .=
" WHERE u.rowid = d.fk_user_author";
208if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
209 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
210 $childids = $user->getAllChildIds();
211 $childids[] = $user->id;
212 $sql .=
" AND d.fk_user_author IN (".$db->sanitize(implode(
',', $childids)).
")\n";
214$sql .=
' AND d.entity IN ('.getEntity(
'expensereport').
')';
215$sql .= $db->order($sortfield, $sortorder);
216$sql .= $db->plimit($max, 0);
218$result = $db->query($sql);
221 $num = $db->num_rows($result);
225 print
'<div class="div-table-responsive-no-min">';
226 print
'<table class="noborder centpercent">';
227 print
'<tr class="liste_titre">';
228 print
'<th colspan="2">'.$langs->trans(
"BoxTitleLastModifiedExpenses", min($max, $num)).
'</th>';
229 print
'<th class="right">'.$langs->trans(
"AmountHT").
'</th>';
230 print
'<th class="right">'.$langs->trans(
"AmountTTC").
'</th>';
231 print
'<th class="right">'.$langs->trans(
"DateModificationShort").
'</th>';
233 print
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">';
234 print
img_picto($langs->trans(
"FullList"),
'expensereport');
239 $total_ttc = $totalam = $total = 0;
242 $userstatic =
new User($db);
243 while ($i < $num && $i < $max) {
244 $obj = $db->fetch_object($result);
246 $expensereportstatic->id = $obj->rowid;
247 $expensereportstatic->ref = $obj->ref;
248 $expensereportstatic->status = $obj->status;
250 $userstatic->id = $obj->uid;
251 $userstatic->admin = $obj->admin;
252 $userstatic->email = $obj->email;
253 $userstatic->lastname = $obj->lastname;
254 $userstatic->firstname = $obj->firstname;
255 $userstatic->login = $obj->login;
256 $userstatic->status = $obj->user_status;
257 $userstatic->photo = $obj->photo;
259 print
'<tr class="oddeven">';
260 print
'<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).
'</td>';
261 print
'<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).
'</td>';
262 print
'<td class="right amount">'.price($obj->total_ht).
'</td>';
263 print
'<td class="right amount">'.price($obj->total_ttc).
'</td>';
264 print
'<td class="right">'.dol_print_date($db->jdate($obj->dm),
'day').
'</td>';
265 print
'<td class="right">';
266 print $expensereportstatic->getLibStatut(3);
273 print
'<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
275 print
'</table></div><br>';
282$parameters = array(
'user' => $user);
283$reshook = $hookmanager->executeHooks(
'dashboardExpenseReport', $parameters, $object);
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.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.