dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "lastcustomershipments";
37 public $boximg = "dolly";
38 public $boxlabel = "BoxLastCustomerShipments";
39 public $depends = array("expedition");
40
47 public function __construct($db, $param)
48 {
49 global $user;
50
51 $this->db = $db;
52
53 $this->hidden = !$user->hasRight('expedition', 'lire');
54
55 $this->urltoaddentry = DOL_URL_ROOT.'/expedition/card.php?action=create2';
56 $this->msgNoRecords = 'NoRecordedShipments';
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $user, $langs;
68 $langs->loadLangs(array('orders', 'sendings'));
69
70 $this->max = $max;
71
72 include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
73 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
74 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
75
76 $shipmentstatic = new Expedition($this->db);
77 $orderstatic = new Commande($this->db);
78 $societestatic = new Societe($this->db);
79
80 $this->info_box_head = array(
81 '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>'
82 );
83
84 if ($user->hasRight('expedition', 'lire')) {
85 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
86 $sql .= ", s.code_client, s.code_compta, s.client";
87 $sql .= ", s.logo, s.email, s.entity";
88 $sql .= ", e.ref, e.tms";
89 $sql .= ", e.rowid";
90 $sql .= ", e.ref_customer";
91 $sql .= ", e.fk_statut";
92 $sql .= ", e.fk_user_valid";
93 $sql .= ", c.ref as commande_ref";
94 $sql .= ", c.rowid as commande_id";
95 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
96 $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')";
97 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
98 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
99 if (!$user->hasRight('societe', 'client', 'voir')) {
100 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
101 }
102 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
103 if (getDolGlobalString('ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY')) {
104 $sql .= " AND e.fk_statut = 1";
105 }
106 if ($user->socid > 0) {
107 $sql .= " AND s.rowid = ".((int) $user->socid);
108 }
109 if (!$user->hasRight('societe', 'client', 'voir')) {
110 $sql .= " AND sc.fk_user = ".((int) $user->id);
111 } else {
112 $sql .= " ORDER BY e.tms DESC, e.date_delivery DESC, e.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
125 $shipmentstatic->id = $objp->rowid;
126 $shipmentstatic->ref = $objp->ref;
127 $shipmentstatic->ref_customer = $objp->ref_customer;
128
129 $orderstatic->id = $objp->commande_id;
130 $orderstatic->ref = $objp->commande_ref;
131
132 $societestatic->id = $objp->socid;
133 $societestatic->name = $objp->name;
134 //$societestatic->name_alias = $objp->name_alias;
135 $societestatic->code_client = $objp->code_client;
136 $societestatic->code_compta = $objp->code_compta;
137 $societestatic->code_compta_client = $objp->code_compta;
138 $societestatic->client = $objp->client;
139 $societestatic->logo = $objp->logo;
140 $societestatic->email = $objp->email;
141 $societestatic->entity = $objp->entity;
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="nowraponall"',
145 'text' => $shipmentstatic->getNomUrl(1),
146 'asis' => 1,
147 );
148
149 $this->info_box_contents[$line][] = array(
150 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
151 'text' => $societestatic->getNomUrl(1),
152 'asis' => 1,
153 );
154
155 $this->info_box_contents[$line][] = array(
156 'td' => 'class="nowraponall"',
157 'text' => ($orderstatic->id > 0 ? $orderstatic->getNomUrl(1) : ''),
158 'asis' => 1,
159 );
160
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="right" width="18"',
163 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
164 );
165
166 $line++;
167 }
168
169 // if ($num == 0) {
170 // $this->info_box_contents[$line][0] = array(
171 // 'td' => 'class="center"',
172 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedShipments").'</span>'
173 // );
174 // }
175
176 $this->db->free($result);
177 } else {
178 $this->info_box_contents[0][0] = array(
179 'td' => '',
180 'maxlength' => 500,
181 'text' => ($this->db->error().' sql='.$sql),
182 );
183 }
184 } else {
185 $this->info_box_contents[0][0] = array(
186 'td' => 'class="nohover left"',
187 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
188 );
189 }
190 }
191
192
193
202 public function showBox($head = null, $contents = null, $nooutput = 0)
203 {
204 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 }
206}
Class to manage customers orders.
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 a Dolibarr global constant string value.