dolibarr 21.0.0-alpha
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 Frederic 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
62 public function loadBox($max = 5)
63 {
64 global $user, $langs, $conf;
65 $langs->load('orders');
66
67 $this->max = $max;
68
69 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
70 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
71
72 $commandestatic = new Commande($this->db);
73 $societestatic = new Societe($this->db);
74 $userstatic = new User($this->db);
75
76 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."CustomerOrders", $max);
77 $this->info_box_head = array(
78 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
79 );
80
81 if ($user->hasRight('commande', 'lire')) {
82 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
84 $sql .= ", s.logo, s.email, s.entity";
85 $sql .= ", c.ref, c.tms";
86 $sql .= ", c.rowid";
87 $sql .= ", c.date_commande";
88 $sql .= ", c.ref_client";
89 $sql .= ", c.fk_statut";
90 $sql .= ", c.fk_user_valid";
91 $sql .= ", c.facture";
92 $sql .= ", c.total_ht";
93 $sql .= ", c.total_tva";
94 $sql .= ", c.total_ttc";
95 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
96 if (!$user->hasRight('societe', 'client', 'voir')) {
97 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98 }
99 $sql .= " WHERE c.fk_soc = s.rowid";
100 $sql .= " AND c.entity IN (".getEntity('commande').")";
101 if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY')) {
102 $sql .= " AND c.fk_statut = 1";
103 }
104 if (!$user->hasRight('societe', 'client', 'voir')) {
105 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
106 }
107 if ($user->socid) {
108 $sql .= " AND s.rowid = ".((int) $user->socid);
109 }
110 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
111 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
112 } else {
113 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
114 }
115 $sql .= $this->db->plimit($max, 0);
116
117 $result = $this->db->query($sql);
118 if ($result) {
119 $num = $this->db->num_rows($result);
120
121 $line = 0;
122
123 while ($line < $num) {
124 $objp = $this->db->fetch_object($result);
125 $date = $this->db->jdate($objp->date_commande);
126 $datem = $this->db->jdate($objp->tms);
127
128 $commandestatic->id = $objp->rowid;
129 $commandestatic->ref = $objp->ref;
130 $commandestatic->ref_client = $objp->ref_client;
131 $commandestatic->total_ht = $objp->total_ht;
132 $commandestatic->total_tva = $objp->total_tva;
133 $commandestatic->total_ttc = $objp->total_ttc;
134 $commandestatic->date = $date;
135 $commandestatic->date_modification = $datem;
136
137 $societestatic->id = $objp->socid;
138 $societestatic->name = $objp->name;
139 //$societestatic->name_alias = $objp->name_alias;
140 $societestatic->code_client = $objp->code_client;
141 $societestatic->code_compta = $objp->code_compta_client;
142 $societestatic->code_compta_client = $objp->code_compta_client;
143 $societestatic->client = $objp->client;
144 $societestatic->logo = $objp->logo;
145 $societestatic->email = $objp->email;
146 $societestatic->entity = $objp->entity;
147
148 $this->info_box_contents[$line][] = array(
149 'td' => 'class="nowraponall"',
150 'text' => $commandestatic->getNomUrl(1),
151 'asis' => 1,
152 );
153
154 $this->info_box_contents[$line][] = array(
155 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
156 'text' => $societestatic->getNomUrl(1),
157 'asis' => 1,
158 );
159
160 $this->info_box_contents[$line][] = array(
161 'td' => 'class="nowraponall right amount"',
162 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
163 );
164
165 if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER')) {
166 if ($objp->fk_user_valid > 0) {
167 $userstatic->fetch($objp->fk_user_valid);
168 }
169 $this->info_box_contents[$line][] = array(
170 'td' => 'class="right"',
171 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
172 'asis' => 1,
173 );
174 }
175
176 $this->info_box_contents[$line][] = array(
177 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
178 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
179 );
180
181 $this->info_box_contents[$line][] = array(
182 'td' => 'class="right" width="18"',
183 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
184 );
185
186 $line++;
187 }
188
189 if ($num == 0) {
190 $this->info_box_contents[$line][0] = array(
191 'td' => 'class="center"',
192 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
193 );
194 }
195
196 $this->db->free($result);
197 } else {
198 $this->info_box_contents[0][0] = array(
199 'td' => '',
200 'maxlength' => 500,
201 'text' => ($this->db->error().' sql='.$sql),
202 );
203 }
204 } else {
205 $this->info_box_contents[0][0] = array(
206 'td' => 'class="nohover left"',
207 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
208 );
209 }
210 }
211
212
213
222 public function showBox($head = null, $contents = null, $nooutput = 0)
223 {
224 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
225 }
226}
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)
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...