dolibarr  7.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@capnetworks.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 <http://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  var $boxcode="lastcustomerorders";
36  var $boximg="object_order";
37  var $boxlabel="BoxLastCustomerOrders";
38  var $depends = array("commande");
39 
40  var $db;
41  var $param;
42 
43  var $info_box_head = array();
44  var $info_box_contents = array();
45 
46 
53  function __construct($db,$param)
54  {
55  global $user;
56 
57  $this->db=$db;
58 
59  $this->hidden=! ($user->rights->commande->lire);
60  }
61 
68  function loadBox($max=5)
69  {
70  global $user, $langs, $db, $conf;
71 
72  $this->max = $max;
73 
74  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
75  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
76 
77  $commandestatic = new Commande($db);
78  $societestatic = new Societe($db);
79  $userstatic = new User($db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."CustomerOrders",$max));
82 
83  if ($user->rights->commande->lire)
84  {
85  $sql = "SELECT s.nom as name";
86  $sql.= ", s.rowid as socid";
87  $sql.= ", s.code_client";
88  $sql.= ", s.logo";
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.tva as total_tva";
98  $sql.= ", c.total_ttc";
99  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
100  $sql.= ", ".MAIN_DB_PREFIX."commande as c";
101  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
102  $sql.= " WHERE c.fk_soc = s.rowid";
103  $sql.= " AND c.entity = ".$conf->entity;
104  if (! empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) $sql.=" AND c.fk_statut = 1";
105  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
106  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
107  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_commande DESC, c.ref DESC ";
108  else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
109  $sql.= $db->plimit($max, 0);
110 
111  $result = $db->query($sql);
112  if ($result) {
113  $num = $db->num_rows($result);
114 
115  $line = 0;
116 
117  while ($line < $num) {
118  $objp = $db->fetch_object($result);
119  $date=$db->jdate($objp->date_commande);
120  $datem=$db->jdate($objp->tms);
121  $commandestatic->id = $objp->rowid;
122  $commandestatic->ref = $objp->ref;
123  $commandestatic->ref_client = $objp->ref_client;
124  $commandestatic->total_ht = $objp->total_ht;
125  $commandestatic->total_tva = $objp->total_tva;
126  $commandestatic->total_ttc = $objp->total_ttc;
127  $societestatic->id = $objp->socid;
128  $societestatic->name = $objp->name;
129  $societestatic->code_client = $objp->code_client;
130  $societestatic->logo = $objp->logo;
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => '',
134  'text' => $commandestatic->getNomUrl(1),
135  'asis' => 1,
136  );
137 
138  $this->info_box_contents[$line][] = array(
139  'td' => 'class="tdoverflowmax100"',
140  'text' => $societestatic->getNomUrl(1),
141  'asis' => 1,
142  );
143 
144  $this->info_box_contents[$line][] = array(
145  'td' => 'class="right"',
146  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
147  );
148 
149  if (! empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
150  if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
151  $this->info_box_contents[$line][] = array(
152  'td' => 'class="right"',
153  'text' => (($objp->fk_user_valid > 0)?$userstatic->getNomUrl(1):''),
154  'asis' => 1,
155  );
156  }
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => 'class="right"',
160  'text' => dol_print_date($date,'day'),
161  );
162 
163  $this->info_box_contents[$line][] = array(
164  'td' => 'align="right" width="18"',
165  'text' => $commandestatic->LibStatut($objp->fk_statut,$objp->facture,3),
166  );
167 
168  $line++;
169  }
170 
171  if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedOrders"));
172 
173  $db->free($result);
174  } else {
175  $this->info_box_contents[0][0] = array(
176  'td' => '',
177  'maxlength'=>500,
178  'text' => ($db->error().' sql='.$sql),
179  );
180  }
181  } else {
182  $this->info_box_contents[0][0] = array(
183  'td' => 'align="left" class="nohover opacitymedium"',
184  'text' => $langs->trans("ReadPermissionNotAllowed")
185  );
186  }
187  }
188 
197  function showBox($head = null, $contents = null, $nooutput=0)
198  {
199  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
200  }
201 
202 }
203 
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:39
Class ModeleBoxes.
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.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).