dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6  * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.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 
28 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
32 
33 $hookmanager = new HookManager($db);
34 $socid = GETPOST('socid', 'int');
35 
36 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
37 $hookmanager->initHooks(array('sendingindex'));
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('orders', 'sendings'));
41 
42 /*
43  * View
44  */
45 
46 $orderstatic = new Commande($db);
47 $companystatic = new Societe($db);
48 $shipment = new Expedition($db);
49 
50 $helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
51 llxHeader('', $langs->trans("Shipment"), $helpurl);
52 
53 print load_fiche_titre($langs->trans("SendingsArea"), '', 'dolly');
54 
55 
56 print '<div class="fichecenter"><div class="fichethirdleft">';
57 
58 /*
59  * Shipments to validate
60  */
61 
62 $clause = " WHERE ";
63 
64 $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
65 $sql .= " s.nom as name, s.rowid as socid,";
66 $sql .= " c.ref as commande_ref, c.rowid as commande_id";
67 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
68 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
69 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
70 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
71 if (empty($user->rights->societe->client->voir) && !$socid) {
72  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
73  $sql .= $clause." sc.fk_user = ".((int) $user->id);
74  $clause = " AND ";
75 }
76 $sql .= $clause." e.fk_statut = ".Expedition::STATUS_DRAFT;
77 $sql .= " AND e.entity IN (".getEntity('expedition').")";
78 if ($socid) {
79  $sql .= " AND c.fk_soc = ".((int) $socid);
80 }
81 
82 $resql = $db->query($sql);
83 if ($resql) {
84  $num = $db->num_rows($resql);
85 
86  print '<div class="div-table-responsive-no-min">';
87  print '<table class="noborder centpercent">';
88  print '<tr class="liste_titre">';
89  print '<th colspan="3">';
90  print $langs->trans("SendingsToValidate").' ';
91  print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_DRAFT.'">';
92  print '<span class="badge">'.$num.'</span>';
93  print '</a>';
94  print '</th>';
95  print '</tr>';
96 
97  if ($num) {
98  $i = 0;
99  while ($i < $num) {
100  $obj = $db->fetch_object($resql);
101 
102  $shipment->id = $obj->rowid;
103  $shipment->ref = $obj->ref;
104  $shipment->ref_customer = $obj->ref_customer;
105 
106  print '<tr class="oddeven"><td class="nowrap">';
107  print $shipment->getNomUrl(1);
108  print "</td>";
109  print '<td>';
110  print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
111  print '</td>';
112  print '<td>';
113  if ($obj->commande_id) {
114  print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
115  }
116  print '</td></tr>';
117  $i++;
118  }
119  } else {
120  print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td></tr>';
121  }
122 
123  print "</table></div><br>";
124 }
125 
126 
127 
128 //print '</td><td valign="top" width="70%">';
129 print '</div><div class="fichetwothirdright">';
130 
131 $max = 5;
132 
133 /*
134  * Latest shipments
135  */
136 $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
137 $sql .= " s.nom as name, s.rowid as socid,";
138 $sql .= " c.ref as commande_ref, c.rowid as commande_id";
139 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
140 $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')";
141 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
142 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
143 if (empty($user->rights->societe->client->voir) && !$socid) {
144  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
145 }
146 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
147 if (empty($user->rights->societe->client->voir) && !$socid) {
148  $sql .= " AND sc.fk_user = ".((int) $user->id);
149 }
150 $sql .= " AND e.fk_statut = ".Expedition::STATUS_VALIDATED;
151 if ($socid) {
152  $sql .= " AND c.fk_soc = ".((int) $socid);
153 }
154 $sql .= " ORDER BY e.date_delivery DESC";
155 $sql .= $db->plimit($max, 0);
156 
157 $resql = $db->query($sql);
158 if ($resql) {
159  $num = $db->num_rows($resql);
160 
161  print '<div class="div-table-responsive-no-min">';
162  print '<table class="noborder centpercent">';
163  print '<tr class="liste_titre">';
164  print '<th colspan="4">';
165  print $langs->trans("LastSendings").' ';
166  print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_VALIDATED.'">';
167  print '<span class="badge">'.$num.'</span>';
168  print '</a>';
169  print '</th>';
170  print '</tr>';
171 
172  if ($num) {
173  $i = 0;
174  while ($i < $num) {
175  $obj = $db->fetch_object($resql);
176 
177  $shipment->id = $obj->rowid;
178  $shipment->ref = $obj->ref;
179  $shipment->ref_customer = $obj->ref_customer;
180 
181  print '<tr class="oddeven"><td>';
182  print $shipment->getNomUrl(1);
183  print '</td>';
184  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
185  print '<td>';
186  if ($obj->commande_id > 0) {
187  $orderstatic->id = $obj->commande_id;
188  $orderstatic->ref = $obj->commande_ref;
189  print $orderstatic->getNomUrl(1);
190  }
191  print '</td>';
192  print '<td class="">';
193 
194  print '</td>';
195  print '</tr>';
196  $i++;
197  }
198  } else {
199  print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td><td></td></tr>';
200  }
201  print "</table></div><br>";
202  $db->free($resql);
203 } else {
204  dol_print_error($db);
205 }
206 
207 /*
208  * Open orders
209  */
210 $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
211 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
212 $sql .= " ".MAIN_DB_PREFIX."societe as s";
213 if (empty($user->rights->societe->client->voir) && !$socid) {
214  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
215 }
216 $sql .= " WHERE c.fk_soc = s.rowid";
217 $sql .= " AND c.entity IN (".getEntity('order').")";
218 $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_ACCEPTED.")";
219 if ($socid > 0) {
220  $sql .= " AND c.fk_soc = ".((int) $socid);
221 }
222 if (empty($user->rights->societe->client->voir) && !$socid) {
223  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
224 }
225 $sql .= " ORDER BY c.rowid ASC";
226 
227 $resql = $db->query($sql);
228 if ($resql) {
229  $langs->load("orders");
230 
231  $num = $db->num_rows($resql);
232 
233  print '<div class="div-table-responsive-no-min">';
234  print '<table class="noborder centpercent">';
235 
236  print '<tr class="liste_titre">';
237  print '<th colspan="3">'.$langs->trans("OrdersToProcess").' ';
238  print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.','.Commande::STATUS_ACCEPTED.'">';
239  print '<span class="badge">'.$num.'</span>';
240  print '</a>';
241  print '</th>';
242  print '</tr>';
243 
244  if ($num) {
245  $i = 0;
246  while ($i < $num && $i < 10) {
247  $obj = $db->fetch_object($resql);
248 
249  $orderstatic->id = $obj->rowid;
250  $orderstatic->ref = $obj->ref;
251  $orderstatic->ref_customer = $obj->ref_customer;
252  $orderstatic->statut = $obj->status;
253  $orderstatic->billed = $obj->billed;
254 
255  $companystatic->name = $obj->name;
256  $companystatic->id = $obj->socid;
257 
258  print '<tr class="oddeven"><td>';
259  print $orderstatic->getNomUrl(1);
260  print '</td>';
261  print '<td>';
262  print $companystatic->getNomUrl(1, 'customer', 32);
263  print '</td>';
264  print '<td class="right">';
265  print $orderstatic->getLibStatut(3);
266  print '</td>';
267  print '</tr>';
268  $i++;
269  }
270 
271  if ($i < $num) {
272  print '<tr class="opacitymedium">';
273  print '<td>'.$langs->trans("More").'...</td>';
274  print '<td></td>';
275  print '<td></td>';
276  print '</tr>';
277  }
278  } else {
279  print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td></tr>';
280  }
281 
282  print "</table></div><br>";
283 } else {
284  dol_print_error($db);
285 }
286 
287 
288 print '</div></div>';
289 
290 $parameters = array('user' => $user);
291 $reshook = $hookmanager->executeHooks('dashboardWarehouseSendings', $parameters, $object); // Note that $action and $object may have been modified by hook
292 
293 // End of page
294 llxFooter();
295 $db->close();
Class to manage customers orders.
const STATUS_VALIDATED
Validated status.
Class to manage shipments.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage hooks.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63