dolibarr  16.0.1
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."societe as s";
103  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
104  if (empty($user->rights->societe->client->voir) && !$user->socid) {
105  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
106  }
107  $sql .= " WHERE c.fk_soc = s.rowid";
108  $sql .= " AND c.entity IN (".getEntity('commande').")";
109  if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) {
110  $sql .= " AND c.fk_statut = 1";
111  }
112  if (empty($user->rights->societe->client->voir) && !$user->socid) {
113  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
114  }
115  if ($user->socid) {
116  $sql .= " AND s.rowid = ".((int) $user->socid);
117  }
118  if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
119  $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
120  } else {
121  $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
122  }
123  $sql .= $this->db->plimit($max, 0);
124 
125  $result = $this->db->query($sql);
126  if ($result) {
127  $num = $this->db->num_rows($result);
128 
129  $line = 0;
130 
131  while ($line < $num) {
132  $objp = $this->db->fetch_object($result);
133  $date = $this->db->jdate($objp->date_commande);
134  $datem = $this->db->jdate($objp->tms);
135 
136  $commandestatic->id = $objp->rowid;
137  $commandestatic->ref = $objp->ref;
138  $commandestatic->ref_client = $objp->ref_client;
139  $commandestatic->total_ht = $objp->total_ht;
140  $commandestatic->total_tva = $objp->total_tva;
141  $commandestatic->total_ttc = $objp->total_ttc;
142  $commandestatic->date = $date;
143  $commandestatic->date_modification = $datem;
144 
145  $societestatic->id = $objp->socid;
146  $societestatic->name = $objp->name;
147  //$societestatic->name_alias = $objp->name_alias;
148  $societestatic->code_client = $objp->code_client;
149  $societestatic->code_compta = $objp->code_compta;
150  $societestatic->client = $objp->client;
151  $societestatic->logo = $objp->logo;
152  $societestatic->email = $objp->email;
153  $societestatic->entity = $objp->entity;
154 
155  $this->info_box_contents[$line][] = array(
156  'td' => 'class="nowraponall"',
157  'text' => $commandestatic->getNomUrl(1),
158  'asis' => 1,
159  );
160 
161  $this->info_box_contents[$line][] = array(
162  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
163  'text' => $societestatic->getNomUrl(1),
164  'asis' => 1,
165  );
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="nowraponall right amount"',
169  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
170  );
171 
172  if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
173  if ($objp->fk_user_valid > 0) {
174  $userstatic->fetch($objp->fk_user_valid);
175  }
176  $this->info_box_contents[$line][] = array(
177  'td' => 'class="right"',
178  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
179  'asis' => 1,
180  );
181  }
182 
183  $this->info_box_contents[$line][] = array(
184  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
185  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
186  );
187 
188  $this->info_box_contents[$line][] = array(
189  'td' => 'class="right" width="18"',
190  'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
191  );
192 
193  $line++;
194  }
195 
196  if ($num == 0) {
197  $this->info_box_contents[$line][0] = array(
198  'td' => 'class="center opacitymedium"',
199  'text'=>$langs->trans("NoRecordedOrders")
200  );
201  }
202 
203  $this->db->free($result);
204  } else {
205  $this->info_box_contents[0][0] = array(
206  'td' => '',
207  'maxlength'=>500,
208  'text' => ($this->db->error().' sql='.$sql),
209  );
210  }
211  } else {
212  $this->info_box_contents[0][0] = array(
213  'td' => 'class="nohover opacitymedium left"',
214  'text' => $langs->trans("ReadPermissionNotAllowed")
215  );
216  }
217  }
218 
227  public function showBox($head = null, $contents = null, $nooutput = 0)
228  {
229  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
230  }
231 }
Class to manage the box to show last orders.
loadBox($max=5)
Load data for box to show them later.
$conf db
API class for accounts.
Definition: inc.php:41
Class to manage Dolibarr users.
Definition: user.class.php:44
Class ModeleBoxes.
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...
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...
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage third parties objects (customers, suppliers, prospects...)
__construct($db, $param)
Constructor.
Class to manage customers orders.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).