dolibarr  13.0.2
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 = !($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".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ? "" : "Modified")."CustomerOrders", $max));
87 
88  if ($user->rights->commande->lire)
89  {
90  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
91  $sql .= ", s.code_client, s.code_compta, s.client";
92  $sql .= ", s.logo, s.email, s.entity";
93  $sql .= ", c.ref, c.tms";
94  $sql .= ", c.rowid";
95  $sql .= ", c.date_commande";
96  $sql .= ", c.ref_client";
97  $sql .= ", c.fk_statut";
98  $sql .= ", c.fk_user_valid";
99  $sql .= ", c.facture";
100  $sql .= ", c.total_ht";
101  $sql .= ", c.tva as total_tva";
102  $sql .= ", c.total_ttc";
103  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
104  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
105  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
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)) $sql .= " AND c.fk_statut = 1";
109  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
110  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
111  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
112  else $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
113  $sql .= $this->db->plimit($max, 0);
114 
115  $result = $this->db->query($sql);
116  if ($result) {
117  $num = $this->db->num_rows($result);
118 
119  $line = 0;
120 
121  while ($line < $num) {
122  $objp = $this->db->fetch_object($result);
123  $date = $this->db->jdate($objp->date_commande);
124  $datem = $this->db->jdate($objp->tms);
125 
126  $commandestatic->id = $objp->rowid;
127  $commandestatic->ref = $objp->ref;
128  $commandestatic->ref_client = $objp->ref_client;
129  $commandestatic->total_ht = $objp->total_ht;
130  $commandestatic->total_tva = $objp->total_tva;
131  $commandestatic->total_ttc = $objp->total_ttc;
132 
133  $societestatic->id = $objp->socid;
134  $societestatic->name = $objp->name;
135  //$societestatic->name_alias = $objp->name_alias;
136  $societestatic->code_client = $objp->code_client;
137  $societestatic->code_compta = $objp->code_compta;
138  $societestatic->client = $objp->client;
139  $societestatic->logo = $objp->logo;
140  $societestatic->email = $objp->email;
141  $societestatic->entity = $objp->entity;
142 
143  $this->info_box_contents[$line][] = array(
144  'td' => 'class="nowraponall"',
145  'text' => $commandestatic->getNomUrl(1),
146  'asis' => 1,
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
151  'text' => $societestatic->getNomUrl(1),
152  'asis' => 1,
153  );
154 
155  $this->info_box_contents[$line][] = array(
156  'td' => 'class="nowraponall right"',
157  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
158  );
159 
160  if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
161  if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="right"',
164  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
165  'asis' => 1,
166  );
167  }
168 
169  $this->info_box_contents[$line][] = array(
170  'td' => 'class="right"',
171  'text' => dol_print_date($date, 'day'),
172  );
173 
174  $this->info_box_contents[$line][] = array(
175  'td' => 'class="right" width="18"',
176  'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
177  );
178 
179  $line++;
180  }
181 
182  if ($num == 0) $this->info_box_contents[$line][0] = array(
183  'td' => 'class="center opacitymedium"',
184  'text'=>$langs->trans("NoRecordedOrders")
185  );
186 
187  $this->db->free($result);
188  } else {
189  $this->info_box_contents[0][0] = array(
190  'td' => '',
191  'maxlength'=>500,
192  'text' => ($this->db->error().' sql='.$sql),
193  );
194  }
195  } else {
196  $this->info_box_contents[0][0] = array(
197  'td' => 'class="nohover opacitymedium left"',
198  'text' => $langs->trans("ReadPermissionNotAllowed")
199  );
200  }
201  }
202 
211  public function showBox($head = null, $contents = null, $nooutput = 0)
212  {
213  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
214  }
215 }
Class to manage the box to show last orders.
loadBox($max=5)
Load data for box to show them later.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
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).