dolibarr 23.0.3
box_commandes.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "lastcustomerorders";
37 public $boximg = "object_order";
38 public $boxlabel = "BoxLastCustomerOrders";
39 public $depends = array("commande");
40
47 public function __construct($db, $param)
48 {
49 global $user;
50
51 $this->db = $db;
52
53 $this->hidden = !$user->hasRight('commande', 'lire');
54
55 $this->urltoaddentry = DOL_URL_ROOT.'/commande/card.php?action=create';
56
57 $this->msgNoRecords = 'NoRecordedOrders';
58 }
59
66 public function loadBox($max = 5)
67 {
68 global $user, $langs, $conf, $hookmanager;
69 $langs->load('orders');
70
71 $this->max = $max;
72
73 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
74 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
75
76 $commandestatic = new Commande($this->db);
77 $societestatic = new Societe($this->db);
78 $userstatic = new User($this->db);
79
80 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."CustomerOrders", $max);
81 $this->info_box_head = array(
82 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
83 );
84
85 if ($user->hasRight('commande', 'lire')) {
86 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
87 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
88 $sql .= ", s.logo, s.email, s.entity";
89 $sql .= ", c.ref, c.tms";
90 $sql .= ", c.rowid";
91 $sql .= ", c.date_commande";
92 $sql .= ", c.ref_client";
93 $sql .= ", c.fk_statut";
94 $sql .= ", c.fk_user_valid";
95 $sql .= ", c.facture";
96 $sql .= ", c.total_ht";
97 $sql .= ", c.total_tva";
98 $sql .= ", c.total_ttc";
99 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
100 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
101 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
102 }
103 $sql .= " WHERE c.fk_soc = s.rowid";
104 $sql .= " AND c.entity IN (".getEntity('commande').")";
105 if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY')) {
106 $sql .= " AND c.fk_statut = 1";
107 }
108 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
109 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
110 }
111 // Add where from hooks
112 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
113 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $commandestatic); // Note that $action and $object may have been modified by hook
114 if (empty($reshook)) {
115 if ($user->socid) {
116 $sql .= " AND s.rowid = " . ((int) $user->socid);
117 }
118 }
119 $sql .= $hookmanager->resPrint;
120 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
121 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
122 } else {
123 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
124 }
125 $sql .= $this->db->plimit($max, 0);
126
127 $result = $this->db->query($sql);
128 if ($result) {
129 $num = $this->db->num_rows($result);
130
131 $line = 0;
132 while ($line < $num) {
133 $objp = $this->db->fetch_object($result);
134 $date = $this->db->jdate($objp->date_commande);
135 $datem = $this->db->jdate($objp->tms);
136
137 $commandestatic->id = $objp->rowid;
138 $commandestatic->ref = $objp->ref;
139 $commandestatic->ref_client = $objp->ref_client;
140 $commandestatic->total_ht = $objp->total_ht;
141 $commandestatic->total_tva = $objp->total_tva;
142 $commandestatic->total_ttc = $objp->total_ttc;
143 $commandestatic->date = $date;
144 $commandestatic->date_modification = $datem;
145
146 $societestatic->id = $objp->socid;
147 $societestatic->name = $objp->name;
148 //$societestatic->name_alias = $objp->name_alias;
149 $societestatic->code_client = $objp->code_client;
150 $societestatic->code_compta = $objp->code_compta_client;
151 $societestatic->code_compta_client = $objp->code_compta_client;
152 $societestatic->client = $objp->client;
153 $societestatic->logo = $objp->logo;
154 $societestatic->email = $objp->email;
155 $societestatic->entity = $objp->entity;
156
157 $this->info_box_contents[$line][] = array(
158 'td' => 'class="nowraponall"',
159 'text' => $commandestatic->getNomUrl(1),
160 'asis' => 1,
161 );
162
163 $this->info_box_contents[$line][] = array(
164 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
165 'text' => $societestatic->getNomUrl(1),
166 'asis' => 1,
167 );
168
169 $this->info_box_contents[$line][] = array(
170 'td' => 'class="nowraponall right amount"',
171 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
172 );
173
174 if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER')) {
175 if ($objp->fk_user_valid > 0) {
176 $userstatic->fetch($objp->fk_user_valid);
177 }
178 $this->info_box_contents[$line][] = array(
179 'td' => 'class="right"',
180 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
181 'asis' => 1,
182 );
183 }
184
185 $this->info_box_contents[$line][] = array(
186 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
187 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
188 );
189
190 $this->info_box_contents[$line][] = array(
191 'td' => 'class="right" width="18"',
192 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
193 );
194
195 $line++;
196 }
197
198
199 $this->db->free($result);
200 } else {
201 $this->info_box_contents[0][0] = array(
202 'td' => '',
203 'maxlength' => 500,
204 'text' => ($this->db->error().' sql='.$sql),
205 );
206 }
207 } else {
208 $this->info_box_contents[0][0] = array(
209 'td' => 'class="nohover left"',
210 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
211 );
212 }
213 }
214
215
216
225 public function showBox($head = null, $contents = null, $nooutput = 0)
226 {
227 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
228 }
229}
Class to manage customers orders.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Class to manage the box to show last customer orders.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...