dolibarr  21.0.0-alpha
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 
46  public function __construct($db, $param)
47  {
48  global $user;
49 
50  $this->db = $db;
51 
52  $this->hidden = !$user->hasRight('commande', 'lire');
53  }
54 
61  public function loadBox($max = 5)
62  {
63  global $user, $langs, $conf;
64  $langs->load('orders');
65 
66  $this->max = $max;
67 
68  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
69  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
70 
71  $commandestatic = new Commande($this->db);
72  $societestatic = new Societe($this->db);
73  $userstatic = new User($this->db);
74 
75  $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."CustomerOrders", $max);
76  $this->info_box_head = array(
77  'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/commande/list.php?sortfield=c.tms&sortorder=DESC"><span class="badge">...</span></a>'
78  );
79 
80  if ($user->hasRight('commande', 'lire')) {
81  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
82  $sql .= ", s.code_client, s.code_compta, s.client";
83  $sql .= ", s.logo, s.email, s.entity";
84  $sql .= ", c.ref, c.tms";
85  $sql .= ", c.rowid";
86  $sql .= ", c.date_commande";
87  $sql .= ", c.ref_client";
88  $sql .= ", c.fk_statut";
89  $sql .= ", c.fk_user_valid";
90  $sql .= ", c.facture";
91  $sql .= ", c.total_ht";
92  $sql .= ", c.total_tva";
93  $sql .= ", c.total_ttc";
94  $sql .= " FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
95  if (!$user->hasRight('societe', 'client', 'voir')) {
96  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
97  }
98  $sql .= " WHERE c.fk_soc = s.rowid";
99  $sql .= " AND c.entity IN (".getEntity('commande').")";
100  if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY')) {
101  $sql .= " AND c.fk_statut = 1";
102  }
103  if (!$user->hasRight('societe', 'client', 'voir')) {
104  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105  }
106  if ($user->socid) {
107  $sql .= " AND s.rowid = ".((int) $user->socid);
108  }
109  if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
110  $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
111  } else {
112  $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
113  }
114  $sql .= $this->db->plimit($max, 0);
115 
116  $result = $this->db->query($sql);
117  if ($result) {
118  $num = $this->db->num_rows($result);
119 
120  $line = 0;
121 
122  while ($line < $num) {
123  $objp = $this->db->fetch_object($result);
124  $date = $this->db->jdate($objp->date_commande);
125  $datem = $this->db->jdate($objp->tms);
126 
127  $commandestatic->id = $objp->rowid;
128  $commandestatic->ref = $objp->ref;
129  $commandestatic->ref_client = $objp->ref_client;
130  $commandestatic->total_ht = $objp->total_ht;
131  $commandestatic->total_tva = $objp->total_tva;
132  $commandestatic->total_ttc = $objp->total_ttc;
133  $commandestatic->date = $date;
134  $commandestatic->date_modification = $datem;
135 
136  $societestatic->id = $objp->socid;
137  $societestatic->name = $objp->name;
138  //$societestatic->name_alias = $objp->name_alias;
139  $societestatic->code_client = $objp->code_client;
140  $societestatic->code_compta = $objp->code_compta;
141  $societestatic->client = $objp->client;
142  $societestatic->logo = $objp->logo;
143  $societestatic->email = $objp->email;
144  $societestatic->entity = $objp->entity;
145 
146  $this->info_box_contents[$line][] = array(
147  'td' => 'class="nowraponall"',
148  'text' => $commandestatic->getNomUrl(1),
149  'asis' => 1,
150  );
151 
152  $this->info_box_contents[$line][] = array(
153  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
154  'text' => $societestatic->getNomUrl(1),
155  'asis' => 1,
156  );
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => 'class="nowraponall right amount"',
160  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
161  );
162 
163  if (getDolGlobalString('ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER')) {
164  if ($objp->fk_user_valid > 0) {
165  $userstatic->fetch($objp->fk_user_valid);
166  }
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="right"',
169  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
170  'asis' => 1,
171  );
172  }
173 
174  $this->info_box_contents[$line][] = array(
175  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
176  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
177  );
178 
179  $this->info_box_contents[$line][] = array(
180  'td' => 'class="right" width="18"',
181  'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
182  );
183 
184  $line++;
185  }
186 
187  if ($num == 0) {
188  $this->info_box_contents[$line][0] = array(
189  'td' => 'class="center"',
190  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
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 
218  public function showBox($head = null, $contents = null, $nooutput = 0)
219  {
220  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
221  }
222 }
Class to manage customers orders.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:50
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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
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 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...