dolibarr 25.0.0-alpha
box_expensereports_to_approve.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Dolibarr contributors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
24
29{
30 public $boxcode = "expensereportstoapprove";
31 public $boximg = "object_trip";
32 public $boxlabel = "BoxExpenseReportsToApprove";
33 public $depends = array("expensereport");
34
41 public function __construct($db, $param) // @phpstan-ignore constructor.unusedParameter
42 {
43 global $user;
44
45 $this->db = $db;
46
47 $this->hidden = !($user->hasRight('expensereport', 'lire') && $user->hasRight('expensereport', 'approve'));
48 }
49
56 public function loadBox($max = 5)
57 {
58 global $user, $langs;
59 $langs->loadLangs(array("boxes", "trips"));
60
61 $this->max = $max;
62
63 include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
64 $expensereportstatic = new ExpenseReport($this->db);
65 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
66 $userstatic = new User($this->db);
67
68 $this->info_box_head = array('text' => $langs->trans("BoxTitleExpenseReportsToApprove", $max));
69
70 if ($user->hasRight('expensereport', 'lire') && $user->hasRight('expensereport', 'approve')) {
71 $childids = $user->getAllChildIds(1);
72
73 $sql = "SELECT d.rowid, d.ref, d.date_debut, d.date_fin, d.total_ttc, d.fk_statut as status";
74 $sql .= ", u.rowid as user_id, u.lastname, u.firstname, u.login, u.photo, u.statut as user_status, u.entity as user_entity";
75 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
76 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user_author = u.rowid";
77 $sql .= " WHERE d.fk_statut = ".ExpenseReport::STATUS_VALIDATED;
78 $sql .= " AND d.entity IN (".getEntity('expensereport').")";
79 if (!$user->hasRight('expensereport', 'readall')) {
80 $sql .= " AND (d.fk_user_author IN (".$this->db->sanitize(implode(',', $childids)).")";
81 $sql .= " OR d.fk_user_validator = ".((int) $user->id).")";
82 }
83 $sql .= " ORDER BY d.date_valid ASC";
84 $sql .= $this->db->plimit($max, 0);
85
86 $result = $this->db->query($sql);
87 if ($result) {
88 $num = $this->db->num_rows($result);
89
90 $line = 0;
91 while ($line < $num) {
92 $objp = $this->db->fetch_object($result);
93
94 $expensereportstatic->id = $objp->rowid;
95 $expensereportstatic->ref = $objp->ref;
96 $expensereportstatic->statut = $objp->status;
97 $expensereportstatic->status = $objp->status;
98
99 $userstatic->id = $objp->user_id;
100 $userstatic->lastname = $objp->lastname;
101 $userstatic->firstname = $objp->firstname;
102 $userstatic->login = $objp->login;
103 $userstatic->photo = $objp->photo;
104 $userstatic->statut = $objp->user_status;
105 $userstatic->status = $objp->user_status;
106 $userstatic->entity = $objp->user_entity;
107
108 $this->info_box_contents[$line][] = array(
109 'td' => 'class="nowraponall"',
110 'text' => $expensereportstatic->getNomUrl(1),
111 'asis' => 1
112 );
113
114 $this->info_box_contents[$line][] = array(
115 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
116 'text' => $userstatic->getNomUrl(-1),
117 'asis' => 1,
118 );
119
120 $this->info_box_contents[$line][] = array(
121 'td' => 'class="nowraponall right"',
122 'text' => dol_print_date($this->db->jdate($objp->date_debut), 'day').' - '.dol_print_date($this->db->jdate($objp->date_fin), 'day'),
123 );
124
125 $this->info_box_contents[$line][] = array(
126 'td' => 'class="nowraponall right amount"',
127 'text' => price($objp->total_ttc),
128 );
129
130 $line++;
131 }
132
133 if ($num == 0) {
134 $this->info_box_contents[$line][] = array(
135 'td' => 'class="center"',
136 'text' => '<span class="opacitymedium">'.$langs->trans("NoExpenseReportToApprove").'</span>',
137 );
138 }
139
140 $this->db->free($result);
141 } else {
142 $this->info_box_contents[0][] = array(
143 'td' => '',
144 'maxlength' => 500,
145 'text' => ($this->db->error().' sql='.$sql),
146 );
147 }
148 } else {
149 $this->info_box_contents[0][] = array(
150 'td' => 'class="nohover left"',
151 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
152 );
153 }
154 }
155
164 public function showBox($head = null, $contents = null, $nooutput = 0)
165 {
166 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
167 }
168}
Class to manage Trips and Expenses.
Class ModeleBoxes.
Class to manage Dolibarr users.
Class to manage the box to show expense reports waiting for approval.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).