dolibarr  20.0.0-beta
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 
46  public function __construct($db, $param)
47  {
48  global $user;
49 
50  $this->db = $db;
51 
52  $this->hidden = !$user->hasRight('expedition', 'lire');
53  }
54 
61  public function loadBox($max = 5)
62  {
63  global $user, $langs, $conf;
64  $langs->loadLangs(array('orders', 'sendings'));
65 
66  $this->max = $max;
67 
68  include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
69  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
70  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
71 
72  $shipmentstatic = new Expedition($this->db);
73  $orderstatic = new Commande($this->db);
74  $societestatic = new Societe($this->db);
75 
76  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastCustomerShipments", $max));
77 
78  if ($user->hasRight('expedition', 'lire')) {
79  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
80  $sql .= ", s.code_client, s.code_compta, s.client";
81  $sql .= ", s.logo, s.email, s.entity";
82  $sql .= ", e.ref, e.tms";
83  $sql .= ", e.rowid";
84  $sql .= ", e.ref_customer";
85  $sql .= ", e.fk_statut";
86  $sql .= ", e.fk_user_valid";
87  $sql .= ", c.ref as commande_ref";
88  $sql .= ", c.rowid as commande_id";
89  $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
90  $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')";
91  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
92  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
93  if (!$user->hasRight('societe', 'client', 'voir')) {
94  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
95  }
96  $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
97  if (getDolGlobalString('ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY')) {
98  $sql .= " AND e.fk_statut = 1";
99  }
100  if ($user->socid > 0) {
101  $sql.= " AND s.rowid = ".((int) $user->socid);
102  }
103  if (!$user->hasRight('societe', 'client', 'voir')) {
104  $sql .= " AND sc.fk_user = ".((int) $user->id);
105  } else {
106  $sql .= " ORDER BY e.date_delivery, e.ref DESC";
107  }
108  $sql .= $this->db->plimit($max, 0);
109 
110  $result = $this->db->query($sql);
111  if ($result) {
112  $num = $this->db->num_rows($result);
113 
114  $line = 0;
115 
116  while ($line < $num) {
117  $objp = $this->db->fetch_object($result);
118 
119  $shipmentstatic->id = $objp->rowid;
120  $shipmentstatic->ref = $objp->ref;
121  $shipmentstatic->ref_customer = $objp->ref_customer;
122 
123  $orderstatic->id = $objp->commande_id;
124  $orderstatic->ref = $objp->commande_ref;
125 
126  $societestatic->id = $objp->socid;
127  $societestatic->name = $objp->name;
128  //$societestatic->name_alias = $objp->name_alias;
129  $societestatic->code_client = $objp->code_client;
130  $societestatic->code_compta = $objp->code_compta;
131  $societestatic->client = $objp->client;
132  $societestatic->logo = $objp->logo;
133  $societestatic->email = $objp->email;
134  $societestatic->entity = $objp->entity;
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="nowraponall"',
138  'text' => $shipmentstatic->getNomUrl(1),
139  'asis' => 1,
140  );
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
144  'text' => $societestatic->getNomUrl(1),
145  'asis' => 1,
146  );
147 
148  $this->info_box_contents[$line][] = array(
149  'td' => 'class="nowraponall"',
150  'text' => $orderstatic->getNomUrl(1),
151  'asis' => 1,
152  );
153 
154  $this->info_box_contents[$line][] = array(
155  'td' => 'class="right" width="18"',
156  'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
157  );
158 
159  $line++;
160  }
161 
162  if ($num == 0) {
163  $this->info_box_contents[$line][0] = array(
164  'td' => 'class="center"',
165  'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedShipments").'</span>'
166  );
167  }
168 
169  $this->db->free($result);
170  } else {
171  $this->info_box_contents[0][0] = array(
172  'td' => '',
173  'maxlength'=>500,
174  'text' => ($this->db->error().' sql='.$sql),
175  );
176  }
177  } else {
178  $this->info_box_contents[0][0] = array(
179  'td' => 'class="nohover left"',
180  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
181  );
182  }
183  }
184 
193  public function showBox($head = null, $contents = null, $nooutput = 0)
194  {
195  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
196  }
197 }
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.
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:745
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.