dolibarr  17.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 Frederic France <frederic.france@free.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  public $boxcode = "lastcustomerorders";
36  public $boximg = "object_order";
37  public $boxlabel = "BoxLastCustomerOrders";
38  public $depends = array("commande");
39 
43  public $db;
44 
45  public $param;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param)
58  {
59  global $user;
60 
61  $this->db = $db;
62 
63  $this->hidden = empty($user->rights->commande->lire);
64  }
65 
72  public function loadBox($max = 5)
73  {
74  global $user, $langs, $conf;
75  $langs->load('orders');
76 
77  $this->max = $max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
80  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
81 
82  $commandestatic = new Commande($this->db);
83  $societestatic = new Societe($this->db);
84  $userstatic = new User($this->db);
85 
86  $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."CustomerOrders", $max));
87 
88  if ($user->rights->commande->lire) {
89  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
90  $sql .= ", s.code_client, s.code_compta, s.client";
91  $sql .= ", s.logo, s.email, s.entity";
92  $sql .= ", c.ref, c.tms";
93  $sql .= ", c.rowid";
94  $sql .= ", c.date_commande";
95  $sql .= ", c.ref_client";
96  $sql .= ", c.fk_statut";
97  $sql .= ", c.fk_user_valid";
98  $sql .= ", c.facture";
99  $sql .= ", c.total_ht";
100  $sql .= ", c.total_tva";
101  $sql .= ", c.total_ttc";
102  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
103  if (empty($user->rights->societe->client->voir) && !$user->socid) {
104  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
105  }
106  $sql .= " WHERE c.fk_soc = s.rowid";
107  $sql .= " AND c.entity IN (".getEntity('commande').")";
108  if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) {
109  $sql .= " AND c.fk_statut = 1";
110  }
111  if (empty($user->rights->societe->client->voir) && !$user->socid) {
112  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
113  }
114  if ($user->socid) {
115  $sql .= " AND s.rowid = ".((int) $user->socid);
116  }
117  if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
118  $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
119  } else {
120  $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
121  }
122  $sql .= $this->db->plimit($max, 0);
123 
124  $result = $this->db->query($sql);
125  if ($result) {
126  $num = $this->db->num_rows($result);
127 
128  $line = 0;
129 
130  while ($line < $num) {
131  $objp = $this->db->fetch_object($result);
132  $date = $this->db->jdate($objp->date_commande);
133  $datem = $this->db->jdate($objp->tms);
134 
135  $commandestatic->id = $objp->rowid;
136  $commandestatic->ref = $objp->ref;
137  $commandestatic->ref_client = $objp->ref_client;
138  $commandestatic->total_ht = $objp->total_ht;
139  $commandestatic->total_tva = $objp->total_tva;
140  $commandestatic->total_ttc = $objp->total_ttc;
141  $commandestatic->date = $date;
142  $commandestatic->date_modification = $datem;
143 
144  $societestatic->id = $objp->socid;
145  $societestatic->name = $objp->name;
146  //$societestatic->name_alias = $objp->name_alias;
147  $societestatic->code_client = $objp->code_client;
148  $societestatic->code_compta = $objp->code_compta;
149  $societestatic->client = $objp->client;
150  $societestatic->logo = $objp->logo;
151  $societestatic->email = $objp->email;
152  $societestatic->entity = $objp->entity;
153 
154  $this->info_box_contents[$line][] = array(
155  'td' => 'class="nowraponall"',
156  'text' => $commandestatic->getNomUrl(1),
157  'asis' => 1,
158  );
159 
160  $this->info_box_contents[$line][] = array(
161  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
162  'text' => $societestatic->getNomUrl(1),
163  'asis' => 1,
164  );
165 
166  $this->info_box_contents[$line][] = array(
167  'td' => 'class="nowraponall right amount"',
168  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
169  );
170 
171  if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
172  if ($objp->fk_user_valid > 0) {
173  $userstatic->fetch($objp->fk_user_valid);
174  }
175  $this->info_box_contents[$line][] = array(
176  'td' => 'class="right"',
177  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
178  'asis' => 1,
179  );
180  }
181 
182  $this->info_box_contents[$line][] = array(
183  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
184  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
185  );
186 
187  $this->info_box_contents[$line][] = array(
188  'td' => 'class="right" width="18"',
189  'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
190  );
191 
192  $line++;
193  }
194 
195  if ($num == 0) {
196  $this->info_box_contents[$line][0] = array(
197  'td' => 'class="center opacitymedium"',
198  'text'=>$langs->trans("NoRecordedOrders")
199  );
200  }
201 
202  $this->db->free($result);
203  } else {
204  $this->info_box_contents[0][0] = array(
205  'td' => '',
206  'maxlength'=>500,
207  'text' => ($this->db->error().' sql='.$sql),
208  );
209  }
210  } else {
211  $this->info_box_contents[0][0] = array(
212  'td' => 'class="nohover opacitymedium left"',
213  'text' => $langs->trans("ReadPermissionNotAllowed")
214  );
215  }
216  }
217 
226  public function showBox($head = null, $contents = null, $nooutput = 0)
227  {
228  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
229  }
230 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1493
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
Commande
Class to manage customers orders.
Definition: commande.class.php:46
box_commandes\__construct
__construct($db, $param)
Constructor.
Definition: box_commandes.php:57
box_commandes\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_commandes.php:226
box_commandes
Class to manage the box to show last orders.
Definition: box_commandes.php:33
User
Class to manage Dolibarr users.
Definition: user.class.php:46
price
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.
Definition: functions.lib.php:5697
box_commandes\loadBox
loadBox($max=5)
Load data for box to show them later.
Definition: box_commandes.php:72
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34