dolibarr  17.0.4
box_shipments.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) 2019 Alexandre Spangaro <aspangaro@open-dsi.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 = "lastcustomershipments";
36  public $boximg = "dolly";
37  public $boxlabel = "BoxLastCustomerShipments";
38  public $depends = array("expedition");
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->expedition->lire);
64  }
65 
72  public function loadBox($max = 5)
73  {
74  global $user, $langs, $conf;
75  $langs->loadLangs(array('orders', 'sendings'));
76 
77  $this->max = $max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
80  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
81  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
82 
83  $shipmentstatic = new Expedition($this->db);
84  $orderstatic = new Commande($this->db);
85  $societestatic = new Societe($this->db);
86 
87  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastCustomerShipments", $max));
88 
89  if ($user->rights->expedition->lire) {
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 .= ", e.ref, e.tms";
94  $sql .= ", e.rowid";
95  $sql .= ", e.ref_customer";
96  $sql .= ", e.fk_statut";
97  $sql .= ", e.fk_user_valid";
98  $sql .= ", c.ref as commande_ref";
99  $sql .= ", c.rowid as commande_id";
100  $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
101  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
102  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
103  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
104  if (empty($user->rights->societe->client->voir) && !$user->socid) {
105  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
106  }
107  $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
108  if (!empty($conf->global->ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY)) {
109  $sql .= " AND e.fk_statut = 1";
110  }
111  if ($user->socid > 0) {
112  $sql.= " AND s.rowid = ".((int) $user->socid);
113  }
114  if (empty($user->rights->societe->client->voir) && !$user->socid) {
115  $sql .= " AND sc.fk_user = ".((int) $user->id);
116  } else {
117  $sql .= " ORDER BY e.date_delivery, e.ref DESC ";
118  }
119  $sql .= $this->db->plimit($max, 0);
120 
121  $result = $this->db->query($sql);
122  if ($result) {
123  $num = $this->db->num_rows($result);
124 
125  $line = 0;
126 
127  while ($line < $num) {
128  $objp = $this->db->fetch_object($result);
129 
130  $shipmentstatic->id = $objp->rowid;
131  $shipmentstatic->ref = $objp->ref;
132  $shipmentstatic->ref_customer = $objp->ref_customer;
133 
134  $orderstatic->id = $objp->commande_id;
135  $orderstatic->ref = $objp->commande_ref;
136 
137  $societestatic->id = $objp->socid;
138  $societestatic->name = $objp->name;
139  //$societestatic->name_alias = $objp->name_alias;
140  $societestatic->code_client = $objp->code_client;
141  $societestatic->code_compta = $objp->code_compta;
142  $societestatic->client = $objp->client;
143  $societestatic->logo = $objp->logo;
144  $societestatic->email = $objp->email;
145  $societestatic->entity = $objp->entity;
146 
147  $this->info_box_contents[$line][] = array(
148  'td' => 'class="nowraponall"',
149  'text' => $shipmentstatic->getNomUrl(1),
150  'asis' => 1,
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
155  'text' => $societestatic->getNomUrl(1),
156  'asis' => 1,
157  );
158 
159  $this->info_box_contents[$line][] = array(
160  'td' => 'class="nowraponall"',
161  'text' => $orderstatic->getNomUrl(1),
162  'asis' => 1,
163  );
164 
165  $this->info_box_contents[$line][] = array(
166  'td' => 'class="right" width="18"',
167  'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
168  );
169 
170  $line++;
171  }
172 
173  if ($num == 0) {
174  $this->info_box_contents[$line][0] = array(
175  'td' => 'class="center opacitymedium"',
176  'text'=>$langs->trans("NoRecordedShipments")
177  );
178  }
179 
180  $this->db->free($result);
181  } else {
182  $this->info_box_contents[0][0] = array(
183  'td' => '',
184  'maxlength'=>500,
185  'text' => ($this->db->error().' sql='.$sql),
186  );
187  }
188  } else {
189  $this->info_box_contents[0][0] = array(
190  'td' => 'class="nohover opacitymedium left"',
191  'text' => $langs->trans("ReadPermissionNotAllowed")
192  );
193  }
194  }
195 
204  public function showBox($head = null, $contents = null, $nooutput = 0)
205  {
206  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
207  }
208 }
Class to manage customers orders.
Class to manage shipments.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last shipments.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
$conf db
API class for accounts.
Definition: inc.php:41