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';
38 $hookmanager->initHooks(array(
'expensereportindex'));
41 $langs->loadLangs(array(
'companies',
'users',
'trips'));
44 $socid =
GETPOST(
'socid',
'int');
45 if ($user->socid) $socid = $user->socid;
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
"sortfield",
'alpha');
50 $sortorder =
GETPOST(
"sortorder",
'alpha');
52 if (empty($page) || $page == -1) { $page = 0; }
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;
67 $childids = $user->getAllChildIds();
68 $childids[] = $user->id;
72 llxHeader(
'', $langs->trans(
"ListOfFees"), $help_url);
75 $label = $somme = $nb = array();
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";
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)))
85 $childids = $user->getAllChildIds();
86 $childids[] = $user->id;
87 $sql .=
" AND d.fk_user_author IN (".join(
',', $childids).
")\n";
90 $sql .=
" GROUP BY tf.code, tf.label";
92 $result = $db->query($sql);
95 $num = $db->num_rows($result);
99 $objp = $db->fetch_object($result);
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;
117 print '<div class="fichecenter"><div class="fichethirdleft">';
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>';
125 $listoftype = $tripandexpense_static->listOfTypes();
126 foreach ($listoftype as $code => $label)
128 $dataseries[] = array($label, (isset($somme[$code]) ? (
int) $somme[$code] : 0));
131 if ($conf->use_javascript_ajax)
133 print
'<tr><td class="center" colspan="4">';
135 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
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);
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>';
161 print
'</div><div class="fichetwothirdright"><div class="ficheaddleft">';
166 $langs->load(
"boxes");
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";
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)))
177 $childids = $user->getAllChildIds();
178 $childids[] = $user->id;
179 $sql .=
" AND d.fk_user_author IN (".join(
',', $childids).
")\n";
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);
187 $result = $db->query($sql);
191 $num = $db->num_rows($result);
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> </th>';
206 $total_ttc = $totalam = $total = 0;
209 $userstatic =
new User($db);
210 while ($i < $num && $i < $max)
212 $obj = $db->fetch_object($result);
214 $expensereportstatic->id = $obj->rowid;
215 $expensereportstatic->ref = $obj->ref;
216 $expensereportstatic->status = $obj->status;
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;
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);
241 print
'<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
243 print
'</table></div><br>';
246 print
'</div></div></div>';
248 $parameters = array(
'user' => $user);
249 $reshook = $hookmanager->executeHooks(
'dashboardExpenseReport', $parameters, $object);
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.
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.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...