dolibarr 20.0.0
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
27include_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;
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(
77 'text' => $langs->trans("BoxTitleLastCustomerShipments", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/expedition/list.php?sortfield=e.tms&sortorder=DESC"><span class="badge">...</span></a>'
78 );
79
80 if ($user->hasRight('expedition', '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 .= ", e.ref, e.tms";
85 $sql .= ", e.rowid";
86 $sql .= ", e.ref_customer";
87 $sql .= ", e.fk_statut";
88 $sql .= ", e.fk_user_valid";
89 $sql .= ", c.ref as commande_ref";
90 $sql .= ", c.rowid as commande_id";
91 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
92 $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')";
93 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
94 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
95 if (!$user->hasRight('societe', 'client', 'voir')) {
96 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
97 }
98 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
99 if (getDolGlobalString('ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY')) {
100 $sql .= " AND e.fk_statut = 1";
101 }
102 if ($user->socid > 0) {
103 $sql.= " AND s.rowid = ".((int) $user->socid);
104 }
105 if (!$user->hasRight('societe', 'client', 'voir')) {
106 $sql .= " AND sc.fk_user = ".((int) $user->id);
107 } else {
108 $sql .= " ORDER BY e.tms DESC, e.date_delivery DESC, e.ref DESC";
109 }
110 $sql .= $this->db->plimit($max, 0);
111
112 $result = $this->db->query($sql);
113 if ($result) {
114 $num = $this->db->num_rows($result);
115
116 $line = 0;
117
118 while ($line < $num) {
119 $objp = $this->db->fetch_object($result);
120
121 $shipmentstatic->id = $objp->rowid;
122 $shipmentstatic->ref = $objp->ref;
123 $shipmentstatic->ref_customer = $objp->ref_customer;
124
125 $orderstatic->id = $objp->commande_id;
126 $orderstatic->ref = $objp->commande_ref;
127
128 $societestatic->id = $objp->socid;
129 $societestatic->name = $objp->name;
130 //$societestatic->name_alias = $objp->name_alias;
131 $societestatic->code_client = $objp->code_client;
132 $societestatic->code_compta = $objp->code_compta;
133 $societestatic->client = $objp->client;
134 $societestatic->logo = $objp->logo;
135 $societestatic->email = $objp->email;
136 $societestatic->entity = $objp->entity;
137
138 $this->info_box_contents[$line][] = array(
139 'td' => 'class="nowraponall"',
140 'text' => $shipmentstatic->getNomUrl(1),
141 'asis' => 1,
142 );
143
144 $this->info_box_contents[$line][] = array(
145 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
146 'text' => $societestatic->getNomUrl(1),
147 'asis' => 1,
148 );
149
150 $this->info_box_contents[$line][] = array(
151 'td' => 'class="nowraponall"',
152 'text' => ($orderstatic->id > 0 ? $orderstatic->getNomUrl(1) : ''),
153 'asis' => 1,
154 );
155
156 $this->info_box_contents[$line][] = array(
157 'td' => 'class="right" width="18"',
158 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
159 );
160
161 $line++;
162 }
163
164 if ($num == 0) {
165 $this->info_box_contents[$line][0] = array(
166 'td' => 'class="center"',
167 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedShipments").'</span>'
168 );
169 }
170
171 $this->db->free($result);
172 } else {
173 $this->info_box_contents[0][0] = array(
174 'td' => '',
175 'maxlength'=>500,
176 'text' => ($this->db->error().' sql='.$sql),
177 );
178 }
179 } else {
180 $this->info_box_contents[0][0] = array(
181 'td' => 'class="nohover left"',
182 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
183 );
184 }
185 }
186
195 public function showBox($head = null, $contents = null, $nooutput = 0)
196 {
197 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
198 }
199}
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.