dolibarr 21.0.0-beta
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 $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;
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 (!$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 (!$user->hasRight('societe', 'client', 'voir')) {
109 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
110 }
111 if ($user->socid) {
112 $sql .= " AND s.rowid = ".((int) $user->socid);
113 }
114 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
115 $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
116 } else {
117 $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
118 }
119 $sql .= $this->db->plimit($max, 0);
120
121 $result = $this->db->query($sql);
122 if ($result) {
123 $num = $this->db->num_rows($result);
124 $num=0;
125 $line = 0;
126
127 while ($line < $num) {
128 $objp = $this->db->fetch_object($result);
129 $date = $this->db->jdate($objp->date_commande);
130 $datem = $this->db->jdate($objp->tms);
131
132 $commandestatic->id = $objp->rowid;
133 $commandestatic->ref = $objp->ref;
134 $commandestatic->ref_client = $objp->ref_client;
135 $commandestatic->total_ht = $objp->total_ht;
136 $commandestatic->total_tva = $objp->total_tva;
137 $commandestatic->total_ttc = $objp->total_ttc;
138 $commandestatic->date = $date;
139 $commandestatic->date_modification = $datem;
140
141 $societestatic->id = $objp->socid;
142 $societestatic->name = $objp->name;
143 //$societestatic->name_alias = $objp->name_alias;
144 $societestatic->code_client = $objp->code_client;
145 $societestatic->code_compta = $objp->code_compta_client;
146 $societestatic->code_compta_client = $objp->code_compta_client;
147 $societestatic->client = $objp->client;
148 $societestatic->logo = $objp->logo;
149 $societestatic->email = $objp->email;
150 $societestatic->entity = $objp->entity;
151
152 $this->info_box_contents[$line][] = array(
153 'td' => 'class="nowraponall"',
154 'text' => $commandestatic->getNomUrl(1),
155 'asis' => 1,
156 );
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
160 'text' => $societestatic->getNomUrl(1),
161 'asis' => 1,
162 );
163
164 $this->info_box_contents[$line][] = array(
165 'td' => 'class="nowraponall right amount"',
166 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
167 );
168
169 if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER')) {
170 if ($objp->fk_user_valid > 0) {
171 $userstatic->fetch($objp->fk_user_valid);
172 }
173 $this->info_box_contents[$line][] = array(
174 'td' => 'class="right"',
175 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
176 'asis' => 1,
177 );
178 }
179
180 $this->info_box_contents[$line][] = array(
181 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
182 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
183 );
184
185 $this->info_box_contents[$line][] = array(
186 'td' => 'class="right" width="18"',
187 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
188 );
189
190 $line++;
191 }
192
193
194 $this->db->free($result);
195 } else {
196 $this->info_box_contents[0][0] = array(
197 'td' => '',
198 'maxlength' => 500,
199 'text' => ($this->db->error().' sql='.$sql),
200 );
201 }
202 } else {
203 $this->info_box_contents[0][0] = array(
204 'td' => 'class="nohover left"',
205 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
206 );
207 }
208 }
209
210
211
220 public function showBox($head = null, $contents = null, $nooutput = 0)
221 {
222 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
223 }
224}
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79