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';
39 $hookmanager->initHooks(array(
'expensereportindex'));
42 $langs->loadLangs(array(
'companies',
'users',
'trips'));
45 $socid =
GETPOST(
'socid',
'int');
47 $socid = $user->socid;
51 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
52 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
53 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55 if (empty($page) || $page == -1) {
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
65 $sortfield =
"d.date_create";
67 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
76 $childids = $user->getAllChildIds();
77 $childids[] = $user->id;
79 $help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
84 $label = $somme = $nb = array();
86 $totalnb = $totalsum = 0;
87 $sql =
"SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
88 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d, ".MAIN_DB_PREFIX.
"expensereport_det as de, ".MAIN_DB_PREFIX.
"c_type_fees as tf";
89 $sql .=
" WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity(
'expensereport').
") AND de.fk_c_type_fees = tf.id";
91 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
92 && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
93 $childids = $user->getAllChildIds();
94 $childids[] = $user->id;
95 $sql .=
" AND d.fk_user_author IN (".$db->sanitize(join(
',', $childids)).
")\n";
98 $sql .=
" GROUP BY tf.code, tf.label";
100 $result = $db->query($sql);
102 $num = $db->num_rows($result);
105 $objp = $db->fetch_object($result);
107 $somme[$objp->code] = $objp->km;
108 $nb[$objp->code] = $objp->nb;
109 $label[$objp->code] = $objp->label;
110 $totalnb += $objp->nb;
111 $totalsum += $objp->km;
123 print
'<div class="fichecenter"><div class="fichethirdleft">';
125 print
'<div class="div-table-responsive-no-min">';
126 print
'<table class="noborder nohover centpercent">';
127 print
'<tr class="liste_titre">';
128 print
'<th colspan="4">'.$langs->trans(
"Statistics").
'</th>';
131 $listoftype = $tripandexpense_static->listOfTypes();
132 foreach ($listoftype as $code => $label) {
133 $dataseries[] = array($label, (isset($somme[$code]) ? (
int) $somme[$code] : 0));
142 if (count($dataseries) > ($KEEPNFIRST + 1)) {
143 foreach ($dataseries as $key => $val) {
144 if ($i < $KEEPNFIRST) {
149 $dataseries[$KEEPNFIRST][0] = $langs->trans(
"Others").
'...';
150 if ($key == $KEEPNFIRST) {
154 $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1];
155 unset($dataseries[$key]);
160 if ($conf->use_javascript_ajax) {
161 print
'<tr><td class="center" colspan="4">';
163 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
165 $dolgraph->SetData($dataseries);
166 $dolgraph->setHeight(350);
167 $dolgraph->combine = empty($conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT) ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT;
168 $dolgraph->setShowLegend(2);
169 $dolgraph->setShowPercent(1);
170 $dolgraph->SetType(array(
'pie'));
171 $dolgraph->setHeight(
'200');
172 $dolgraph->draw(
'idgraphstatus');
173 print $dolgraph->show($totalnb ? 0 : 1);
178 print
'<tr class="liste_total">';
179 print
'<td>'.$langs->trans(
"Total").
'</td>';
180 print
'<td class="right" colspan="3">'.price($totalsum, 1, $langs, 0, 0, 0, $conf->currency).
'</td>';
189 print
'</div><div class="fichetwothirdright">';
194 $langs->load(
"boxes");
196 $sql =
"SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
197 $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";
198 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d, ".MAIN_DB_PREFIX.
"user as u";
199 $sql .=
" WHERE u.rowid = d.fk_user_author";
201 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
202 && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
203 $childids = $user->getAllChildIds();
204 $childids[] = $user->id;
205 $sql .=
" AND d.fk_user_author IN (".$db->sanitize(join(
',', $childids)).
")\n";
207 $sql .=
' AND d.entity IN ('.getEntity(
'expensereport').
')';
208 $sql .= $db->order($sortfield, $sortorder);
209 $sql .= $db->plimit($max, 0);
211 $result = $db->query($sql);
214 $num = $db->num_rows($result);
218 print
'<div class="div-table-responsive-no-min">';
219 print
'<table class="noborder centpercent">';
220 print
'<tr class="liste_titre">';
221 print
'<th colspan="2">'.$langs->trans(
"BoxTitleLastModifiedExpenses", min($max, $num)).
'</th>';
222 print
'<th class="right">'.$langs->trans(
"AmountHT").
'</th>';
223 print
'<th class="right">'.$langs->trans(
"AmountTTC").
'</th>';
224 print
'<th class="right">'.$langs->trans(
"DateModificationShort").
'</th>';
225 print
'<th> </th>';
228 $total_ttc = $totalam = $total = 0;
231 $userstatic =
new User($db);
232 while ($i < $num && $i < $max) {
233 $obj = $db->fetch_object($result);
235 $expensereportstatic->id = $obj->rowid;
236 $expensereportstatic->ref = $obj->ref;
237 $expensereportstatic->status = $obj->status;
239 $userstatic->id = $obj->uid;
240 $userstatic->admin = $obj->admin;
241 $userstatic->email = $obj->email;
242 $userstatic->lastname = $obj->lastname;
243 $userstatic->firstname = $obj->firstname;
244 $userstatic->login = $obj->login;
245 $userstatic->statut = $obj->user_status;
246 $userstatic->photo = $obj->photo;
248 print
'<tr class="oddeven">';
249 print
'<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).
'</td>';
250 print
'<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).
'</td>';
251 print
'<td class="right amount">'.price($obj->total_ht).
'</td>';
252 print
'<td class="right amount">'.price($obj->total_ttc).
'</td>';
253 print
'<td class="right">'.dol_print_date($db->jdate($obj->dm),
'day').
'</td>';
254 print
'<td class="right">';
255 print $expensereportstatic->getLibStatut(3);
262 print
'<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
264 print
'</table></div><br>';
269 print
'</div></div>';
271 $parameters = array(
'user' => $user);
272 $reshook = $hookmanager->executeHooks(
'dashboardExpenseReport', $parameters, $object);
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.
Class to manage Trips and Expenses.
Class to manage Dolibarr users.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
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.