dolibarr  17.0.4
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2016-2021 Ferran Marcet <fmarcet@2byte.es>
6  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7  * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
8  * Copyright (C) 2023 Christophe Battarel <christophe@altairis.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array("sendings", "deliveries", 'companies', 'bills', 'products'));
42 
43 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search
44 
45 $socid = GETPOST('socid', 'int');
46 
47 $action = GETPOST('action', 'alpha');
48 $massaction = GETPOST('massaction', 'alpha');
49 $show_files = GETPOST('show_files', 'int');
50 $toselect = GETPOST('toselect', 'array');
51 
52 // Security check
53 $expeditionid = GETPOST('id', 'int');
54 if ($user->socid) {
55  $socid = $user->socid;
56 }
57 $result = restrictedArea($user, 'expedition', $expeditionid, '');
58 
59 $search_ref_exp = GETPOST("search_ref_exp", 'alpha');
60 $search_ref_liv = GETPOST('search_ref_liv', 'alpha');
61 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
62 $search_company = GETPOST("search_company", 'alpha');
63 $search_shipping_method_id = GETPOST('search_shipping_method_id');
64 $search_tracking = GETPOST("search_tracking", 'alpha');
65 $search_town = GETPOST('search_town', 'alpha');
66 $search_zip = GETPOST('search_zip', 'alpha');
67 $search_state = GETPOST("search_state");
68 $search_country = GETPOST("search_country", 'int');
69 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
70 $search_billed = GETPOST("search_billed", 'int');
71 $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOST('search_datedelivery_startmonth', 'int'), GETPOST('search_datedelivery_startday', 'int'), GETPOST('search_datedelivery_startyear', 'int'));
72 $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOST('search_datedelivery_endmonth', 'int'), GETPOST('search_datedelivery_endday', 'int'), GETPOST('search_datedelivery_endyear', 'int'));
73 $search_datereceipt_start = dol_mktime(0, 0, 0, GETPOST('search_datereceipt_startmonth', 'int'), GETPOST('search_datereceipt_startday', 'int'), GETPOST('search_datereceipt_startyear', 'int'));
74 $search_datereceipt_end = dol_mktime(23, 59, 59, GETPOST('search_datereceipt_endmonth', 'int'), GETPOST('search_datereceipt_endday', 'int'), GETPOST('search_datereceipt_endyear', 'int'));
75 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
76 $search_user = GETPOST('search_user', 'int');
77 $search_sale = GETPOST('search_sale', 'int');
78 $search_categ_cus = GETPOST("search_categ_cus", 'int');
79 $search_product_category = GETPOST('search_product_category', 'int');
80 $optioncss = GETPOST('optioncss', 'alpha');
81 
82 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
83 $sortfield = GETPOST('sortfield', 'aZ09comma');
84 $sortorder = GETPOST('sortorder', 'aZ09comma');
85 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
86 if (!$sortfield) {
87  $sortfield = "e.ref";
88 }
89 if (!$sortorder) {
90  $sortorder = "DESC";
91 }
92 if (empty($page) || $page == -1 || (empty($toselect) && $massaction === '0')) {
93  $page = 0;
94 } // If $page is not defined, or '' or -1
95 $offset = $limit * $page;
96 $pageprev = $page - 1;
97 $pagenext = $page + 1;
98 
99 $search_status = GETPOST('search_status', 'intcomma');
100 
101 $diroutputmassaction = $conf->expedition->dir_output.'/sending/temp/massgeneration/'.$user->id;
102 
103 $object = new Expedition($db);
104 $form = new Form($db);
105 
106 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
107 $hookmanager->initHooks(array('shipmentlist'));
108 $extrafields = new ExtraFields($db);
109 
110 // fetch optionals attributes and labels
111 $extrafields->fetch_name_optionals_label($object->table_element);
112 
113 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
114 
115 // List of fields to search into when doing a "search in all"
116 $fieldstosearchall = array(
117  'e.ref'=>"Ref",
118  's.nom'=>"ThirdParty",
119  'e.note_public'=>'NotePublic',
120  //'e.fk_shipping_method'=>'SendingMethod', // TODO fix this, does not work
121  'e.tracking_number'=>"TrackingNumber",
122 );
123 if (empty($user->socid)) {
124  $fieldstosearchall["e.note_private"] = "NotePrivate";
125 }
126 
127 $checkedtypetiers = 0;
128 $arrayfields = array(
129  'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>1),
130  'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>2),
131  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>3),
132  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1, 'position'=>4),
133  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>5),
134  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>6),
135  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>7),
136  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers, 'position'=>8),
137  'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'position'=>9),
138  'e.fk_shipping_method'=>array('label'=>$langs->trans('SendingMethod'), 'checked'=>1, 'position'=>10),
139  'e.tracking_number'=>array('label'=>$langs->trans("TrackingNumber"), 'checked'=>1, 'position'=>11),
140  'e.weight'=>array('label'=>$langs->trans("Weight"), 'checked'=>0, 'position'=>12),
141  'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
142  'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
143  'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
144  'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->delivery_note->enabled) ? 0 : 1)),
145  'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->delivery_note->enabled) ? 0 : 1)),
146  'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
147 );
148 
149 // Extra fields
150 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
151 
152 $object->fields = dol_sort_array($object->fields, 'position');
153 $arrayfields = dol_sort_array($arrayfields, 'position');
154 
155 
156 /*
157  * Actions
158  */
159 $error = 0;
160 
161 if (GETPOST('cancel', 'alpha')) {
162  $action = 'list'; $massaction = '';
163 }
164 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
165  $massaction = '';
166 }
167 
168 $parameters = array('socid'=>$socid);
169 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
170 if ($reshook < 0) {
171  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
172 }
173 
174 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
175 
176 // Purge search criteria
177 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
178  $search_categ = '';
179  $search_user = '';
180  $search_sale = '';
181  $search_product_category = '';
182  $search_ref_exp = '';
183  $search_ref_liv = '';
184  $search_ref_customer = '';
185  $search_company = '';
186  $search_town = '';
187  $search_zip = "";
188  $search_state = "";
189  $search_type = '';
190  $search_country = '';
191  $search_tracking = '';
192  $search_shipping_method_id = '';
193  $search_type_thirdparty = '';
194  $search_billed = '';
195  $search_datedelivery_start = '';
196  $search_datedelivery_end = '';
197  $search_datereceipt_start = '';
198  $search_datereceipt_end = '';
199  $search_status = '';
200  $toselect = array();
201  $search_array_options = array();
202  $search_categ_cus = 0;
203 }
204 
205 if (empty($reshook)) {
206  $objectclass = 'Expedition';
207  $objectlabel = 'Sendings';
208  $permissiontoread = $user->rights->expedition->lire;
209  $permissiontoadd = $user->rights->expedition->creer;
210  $permissiontodelete = $user->rights->expedition->supprimer;
211  $uploaddir = $conf->expedition->dir_output.'/sending';
212  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
213 }
214 
215 // If massaction is close
216 if ($massaction == 'classifyclose') {
217  $error=0;
218  $selectids = GETPOST('toselect', 'array');
219  foreach ($selectids as $selectid) {
220  // $object->fetch($selectid);
221  $object->fetch($selectid);
222  $result = $object->setClosed();
223  }
224 
225  $massaction = $action = 'classifyclose';
226 
227  if ($result < 0) {
228  $error++;
229  }
230 
231 
232  if (!$error) {
233  $db->commit();
234 
235  setEventMessage($langs->trans("Close Done"));
236  header('Location: '.$_SERVER["PHP_SELF"]);
237  exit;
238  } else {
239  $db->rollback();
240  exit;
241  }
242 }
243 
244 /*
245  * View
246  */
247 
248 $now = dol_now();
249 
250 $form = new Form($db);
251 $formother = new FormOther($db);
252 $formfile = new FormFile($db);
253 $companystatic = new Societe($db);
254 $formcompany = new FormCompany($db);
255 $shipment = new Expedition($db);
256 
257 $helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
258 llxHeader('', $langs->trans('ListOfSendings'), $helpurl);
259 
260 $sql = 'SELECT';
261 if ($sall || $search_user > 0) {
262  $sql = 'SELECT DISTINCT';
263 }
264 $sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number, e.fk_shipping_method,";
265 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
266  // Link for delivery fields ref and date. Does not duplicate the line because we should always have ony 1 link or 0 per shipment
267  $sql .= " l.date_delivery as date_reception,";
268 }
269 $sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ";
270 $sql .= " typent.code as typent_code,";
271 $sql .= " state.code_departement as state_code, state.nom as state_name,";
272 $sql .= " e.date_creation as date_creation, e.tms as date_update,";
273 $sql .= " u.login";
274 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
275  $sql .= ", cc.fk_categorie, cc.fk_soc";
276 }
277 // Add fields from extrafields
278 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
279  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
280  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
281  }
282 }
283 // Add fields from hooks
284 $parameters = array();
285 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
286 $sql .= $hookmanager->resPrint;
287 
288 $sqlfields = $sql; // $sql fields to remove for count total
289 
290 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
291 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
292  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
293 }
294 if ($sall) {
295  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition';
296  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_origin_line';
297 }
298 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
299 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
300  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
301 }
302 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
303 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
304 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
305 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
306  // Link for delivery fields ref and date. Does not duplicate the line because we should always have ony 1 link or 0 per shipment
307  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
308  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
309 }
310 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user_author = u.rowid';
311 if ($search_user > 0) { // Get link to order to get the order id in eesource.fk_source
312  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'";
313 }
314 // We'll need this table joined to the select in order to filter by sale
315 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
316  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
317 }
318 if ($search_user > 0) {
319  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
320  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
321 }
322 
323 // Add table from hooks
324 $parameters = array();
325 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
326 $sql .= $hookmanager->resPrint;
327 
328 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
329 
330 if ($socid > 0) {
331  $sql .= " AND s.rowid = ".((int) $socid);
332 }
333 if (empty($user->rights->societe->client->voir) && !$socid) { // Internal user with no permission to see all
334  $sql .= " AND e.fk_soc = sc.fk_soc";
335  $sql .= " AND sc.fk_user = ".((int) $user->id);
336 }
337 if ($socid) {
338  $sql .= " AND e.fk_soc = ".((int) $socid);
339 }
340 if ($search_status <> '' && $search_status >= 0) {
341  $sql .= " AND e.fk_statut = ".((int) $search_status);
342 }
343 if ($search_ref_customer != '') {
344  $sql .= natural_search('e.ref_customer', $search_ref_customer);
345 }
346 if ($search_billed != '' && $search_billed >= 0) {
347  $sql .= ' AND e.billed = '.((int) $search_billed);
348 }
349 if ($search_town) {
350  $sql .= natural_search('s.town', $search_town);
351 }
352 if ($search_zip) {
353  $sql .= natural_search("s.zip", $search_zip);
354 }
355 if ($search_state) {
356  $sql .= natural_search("state.nom", $search_state);
357 }
358 if ($search_country) {
359  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
360 }
361 if ($search_shipping_method_id > 0) {
362  $sql .= " AND e.fk_shipping_method = ".((int) $search_shipping_method_id);
363 }
364 if ($search_tracking) {
365  $sql .= natural_search("e.tracking_number", $search_tracking);
366 }
367 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
368  $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
369 }
370 if ($search_sale > 0) {
371  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
372 }
373 if ($search_user > 0) {
374  // The contact on a shipment is also the contact of the order.
375  $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = eesource.fk_source AND ec.fk_socpeople = ".((int) $search_user);
376 }
377 if ($search_company) {
378  $sql .= natural_search('s.nom', $search_company);
379 }
380 if ($search_ref_exp) {
381  $sql .= natural_search('e.ref', $search_ref_exp);
382 }
383 if ($search_datedelivery_start) {
384  $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'";
385 }
386 if ($search_datedelivery_end) {
387  $sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'";
388 }
389 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
390  if ($search_ref_liv) {
391  $sql .= natural_search('l.ref', $search_ref_liv);
392  }
393  if ($search_datereceipt_start) {
394  $sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'";
395  }
396  if ($search_datereceipt_end) {
397  $sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'";
398  }
399 }
400 if ($sall) {
401  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
402 }
403 if ($search_categ_cus > 0) {
404  $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
405 }
406 if ($search_categ_cus == -2) {
407  $sql .= " AND cc.fk_categorie IS NULL";
408 }
409 // Search for tag/category ($searchCategoryProductList is an array of ID)
410 $searchCategoryProductOperator = -1;
411 $searchCategoryProductList = array($search_product_category);
412 if (!empty($searchCategoryProductList)) {
413  $searchCategoryProductSqlList = array();
414  $listofcategoryid = '';
415  foreach ($searchCategoryProductList as $searchCategoryProduct) {
416  if (intval($searchCategoryProduct) == -2) {
417  $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product)";
418  } elseif (intval($searchCategoryProduct) > 0) {
419  if ($searchCategoryProductOperator == 0) {
420  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
421  } else {
422  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
423  }
424  }
425  }
426  if ($listofcategoryid) {
427  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
428  }
429  if ($searchCategoryProductOperator == 1) {
430  if (!empty($searchCategoryProductSqlList)) {
431  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
432  }
433  } else {
434  if (!empty($searchCategoryProductSqlList)) {
435  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
436  }
437  }
438 }
439 // Add where from extra fields
440 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
441 
442 // Add where from hooks
443 $parameters = array();
444 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
445 $sql .= $hookmanager->resPrint;
446 
447 // Add HAVING from hooks
448 $parameters = array();
449 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
450 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
451 
452 $nbtotalofrecords = '';
453 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
454  /* The fast and low memory method to get and count full list converts the sql into a sql count */
455  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
456  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
457  $resql = $db->query($sqlforcount);
458  if ($resql) {
459  $objforcount = $db->fetch_object($resql);
460  $nbtotalofrecords = $objforcount->nbtotalofrecords;
461  } else {
462  dol_print_error($db);
463  }
464 
465  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
466  $page = 0;
467  $offset = 0;
468  }
469  $db->free($resql);
470 }
471 
472 // Complete request and execute it with limit
473 $sql .= $db->order($sortfield, $sortorder);
474 if ($limit) {
475  $sql .= $db->plimit($limit + 1, $offset);
476 }
477 
478 //print $sql;
479 $resql = $db->query($sql);
480 if (!$resql) {
481  dol_print_error($db);
482  exit;
483 }
484 
485 $num = $db->num_rows($resql);
486 
487 $arrayofselected = is_array($toselect) ? $toselect : array();
488 
489 $expedition = new Expedition($db);
490 
491 $param = '';
492 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
493  $param .= '&contextpage='.urlencode($contextpage);
494 }
495 if ($limit > 0 && $limit != $conf->liste_limit) {
496  $param .= '&limit='.urlencode($limit);
497 }
498 if ($sall) {
499  $param .= "&sall=".urlencode($sall);
500 }
501 if ($search_ref_exp) {
502  $param .= "&search_ref_exp=".urlencode($search_ref_exp);
503 }
504 if ($search_ref_liv) {
505  $param .= "&search_ref_liv=".urlencode($search_ref_liv);
506 }
507 if ($search_ref_customer) {
508  $param .= "&search_ref_customer=".urlencode($search_ref_customer);
509 }
510 if ($search_user > 0) {
511  $param .= '&search_user='.urlencode($search_user);
512 }
513 if ($search_sale > 0) {
514  $param .= '&search_sale='.urlencode($search_sale);
515 }
516 if ($search_company) {
517  $param .= "&search_company=".urlencode($search_company);
518 }
519 if ($search_shipping_method_id) {
520  $param .= "&amp;search_shipping_method_id=".urlencode($search_shipping_method_id);
521 }
522 if ($search_tracking) {
523  $param .= "&search_tracking=".urlencode($search_tracking);
524 }
525 if ($search_town) {
526  $param .= '&search_town='.urlencode($search_town);
527 }
528 if ($search_zip) {
529  $param .= '&search_zip='.urlencode($search_zip);
530 }
531 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
532  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
533 }
534 if ($search_datedelivery_start) {
535  $param .= '&search_datedelivery_startday='.urlencode(dol_print_date($search_datedelivery_start, '%d')).'&search_datedelivery_startmonth='.urlencode(dol_print_date($search_datedelivery_start, '%m')).'&search_datedelivery_startyear='.urlencode(dol_print_date($search_datedelivery_start, '%Y'));
536 }
537 if ($search_datedelivery_end) {
538  $param .= '&search_datedelivery_endday='.urlencode(dol_print_date($search_datedelivery_end, '%d')).'&search_datedelivery_endmonth='.urlencode(dol_print_date($search_datedelivery_end, '%m')).'&search_datedelivery_endyear='.urlencode(dol_print_date($search_datedelivery_end, '%Y'));
539 }
540 if ($search_datereceipt_start) {
541  $param .= '&search_datereceipt_startday='.urlencode(dol_print_date($search_datereceipt_start, '%d')).'&search_datereceipt_startmonth='.urlencode(dol_print_date($search_datereceipt_start, '%m')).'&search_datereceipt_startyear='.urlencode(dol_print_date($search_datereceipt_start, '%Y'));
542 }
543 if ($search_datereceipt_end) {
544  $param .= '&search_datereceipt_endday='.urlencode(dol_print_date($search_datereceipt_end, '%d')).'&search_datereceipt_endmonth='.urlencode(dol_print_date($search_datereceipt_end, '%m')).'&search_datereceipt_endyear='.urlencode(dol_print_date($search_datereceipt_end, '%Y'));
545 }
546 if ($search_product_category != '') {
547  $param .= '&search_product_category='.urlencode($search_product_category);
548 }
549 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
550  $param .= '&search_categ_cus='.urlencode($search_categ_cus);
551 }
552 if ($search_status != '') {
553  $param .= '&search_status='.urlencode($search_status);
554 }
555 if ($optioncss != '') {
556  $param .= '&optioncss='.urlencode($optioncss);
557 }
558 // Add $param from extra fields
559 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
560 
561 // Add $param from hooks
562 $parameters = array();
563 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
564 $param .= $hookmanager->resPrint;
565 
566 $arrayofmassactions = array(
567  'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
568  'classifyclose' => img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("Close"),
569  'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
570 );
571 if (in_array($massaction, array('presend'))) {
572  $arrayofmassactions = array();
573 }
574 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
575 
576 // Currently: a sending can't create from sending list
577 // $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
578 // if (!empty($socid)) $url .= '&socid='.$socid;
579 // $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
580 $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2', '', $user->rights->expedition->creer);
581 
582 $i = 0;
583 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
584 if ($optioncss != '') {
585  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
586 }
587 print '<input type="hidden" name="token" value="'.newToken().'">';
588 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
589 print '<input type="hidden" name="action" value="list">';
590 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
591 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
592 
593 print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dolly', 0, $newcardbutton, '', $limit, 0, 0, 1);
594 
595 $topicmail = "SendShippingRef";
596 $modelmail = "shipping_send";
597 $objecttmp = new Expedition($db);
598 $trackid = 'shi'.$object->id;
599 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
600 
601 if ($sall) {
602  foreach ($fieldstosearchall as $key => $val) {
603  $fieldstosearchall[$key] = $langs->trans($val);
604  }
605  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
606 }
607 
608 $moreforfilter = '';
609 
610 // If the user can view prospects other than his'
611 if ($user->rights->user->user->lire) {
612  $langs->load("commercial");
613  $moreforfilter .= '<div class="divsearchfield">';
614  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
615  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
616  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
617  $moreforfilter .= '</div>';
618 }
619 // If the user can view other users
620 if ($user->rights->user->user->lire) {
621  $moreforfilter .= '<div class="divsearchfield">';
622  $tmptitle = $langs->trans('LinkedToSpecificUsers');
623  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
624  $moreforfilter .= $form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
625  $moreforfilter .= '</div>';
626 }
627 // If the user can view prospects other than his'
628 if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
629  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
630  $moreforfilter .= '<div class="divsearchfield">';
631  $tmptitle = $langs->trans('IncludingProductWithTag');
632  $moreforfilter .= img_picto($tmptitle, 'category');
633  //$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
634  //$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
635  $moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'search_product_category', 1, $tmptitle);
636 
637  $moreforfilter .= '</div>';
638 }
639 if (isModEnabled('categorie') && $user->rights->categorie->lire) {
640  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
641  $moreforfilter .= '<div class="divsearchfield">';
642  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
643  $moreforfilter .= img_picto($tmptitle, 'category');
644  $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
645  $moreforfilter .= '</div>';
646 }
647 $parameters = array();
648 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
649 if (empty($reshook)) {
650  $moreforfilter .= $hookmanager->resPrint;
651 } else {
652  $moreforfilter = $hookmanager->resPrint;
653 }
654 
655 if (!empty($moreforfilter)) {
656  print '<div class="liste_titre liste_titre_bydiv centpercent">';
657  print $moreforfilter;
658  print '</div>';
659 }
660 
661 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
662 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', ''));
663 if ($massactionbutton) {
664  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields
665 }
666 
667 print '<div class="div-table-responsive">';
668 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
669 
670 // Fields title search
671 print '<tr class="liste_titre_filter">';
672 // Action column
673 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
674  print '<td class="liste_titre middle">';
675  $searchpicto = $form->showFilterButtons('left');
676  print $searchpicto;
677  print '</td>';
678 }
679 // Ref
680 if (!empty($arrayfields['e.ref']['checked'])) {
681  print '<td class="liste_titre">';
682  print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
683  print '</td>';
684 }
685 // Ref customer
686 if (!empty($arrayfields['e.ref_customer']['checked'])) {
687  print '<td class="liste_titre">';
688  print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
689  print '</td>';
690 }
691 // Thirdparty
692 if (!empty($arrayfields['s.nom']['checked'])) {
693  print '<td class="liste_titre left">';
694  print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
695  print '</td>';
696 }
697 // Town
698 if (!empty($arrayfields['s.town']['checked'])) {
699  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
700 }
701 // Zip
702 if (!empty($arrayfields['s.zip']['checked'])) {
703  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
704 }
705 // State
706 if (!empty($arrayfields['state.nom']['checked'])) {
707  print '<td class="liste_titre">';
708  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
709  print '</td>';
710 }
711 // Country
712 if (!empty($arrayfields['country.code_iso']['checked'])) {
713  print '<td class="liste_titre center">';
714  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
715  print '</td>';
716 }
717 // Company type
718 if (!empty($arrayfields['typent.code']['checked'])) {
719  print '<td class="liste_titre maxwidthonsmartphone center">';
720  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
721  print '</td>';
722 }
723 // Weight
724 if (!empty($arrayfields['e.weight']['checked'])) {
725  print '<td class="liste_titre maxwidthonsmartphone center">';
726 
727  print '</td>';
728 }
729 // Date delivery planned
730 if (!empty($arrayfields['e.date_delivery']['checked'])) {
731  print '<td class="liste_titre center">';
732  print '<div class="nowrap">';
733  print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
734  print '</div>';
735  print '<div class="nowrap">';
736  print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
737  print '</div>';
738  print '</td>';
739 }
740 if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
741  // Delivery method
742  print '<td class="liste_titre center">';
743  $shipment->fetch_delivery_methods();
744  print $form->selectarray("search_shipping_method_id", $shipment->meths, $search_shipping_method_id, 1, 0, 0, "", 1, 0, 0, '', 'maxwidth150');
745  print "</td>\n";
746 }
747 // Tracking number
748 if (!empty($arrayfields['e.tracking_number']['checked'])) {
749  print '<td class="liste_titre center">';
750  print '<input class="flat" size="6" type="text" name="search_tracking" value="'.dol_escape_htmltag($search_tracking).'">';
751  print '</td>';
752 }
753 if (!empty($arrayfields['l.ref']['checked'])) {
754  // Delivery ref
755  print '<td class="liste_titre">';
756  print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
757  print '</td>';
758 }
759 if (!empty($arrayfields['l.date_delivery']['checked'])) {
760  // Date received
761  print '<td class="liste_titre center">';
762  print '<div class="nowrap">';
763  print $form->selectDate($search_datereceipt_start ? $search_datereceipt_start : -1, 'search_datereceipt_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
764  print '</div>';
765  print '<div class="nowrap">';
766  print $form->selectDate($search_datereceipt_end ? $search_datereceipt_end : -1, 'search_datereceipt_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
767  print '</div>';
768  print '</td>';
769 }
770 // Extra fields
771 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
772 
773 // Fields from hook
774 $parameters = array('arrayfields'=>$arrayfields);
775 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
776 print $hookmanager->resPrint;
777 // Date creation
778 if (!empty($arrayfields['e.datec']['checked'])) {
779  print '<td class="liste_titre">';
780  print '</td>';
781 }
782 // Date modification
783 if (!empty($arrayfields['e.tms']['checked'])) {
784  print '<td class="liste_titre">';
785  print '</td>';
786 }
787 // Status
788 if (!empty($arrayfields['e.fk_statut']['checked'])) {
789  print '<td class="liste_titre maxwidthonsmartphone right">';
790  print $form->selectarray('search_status', array('0'=>$langs->trans('StatusSendingDraftShort'), '1'=>$langs->trans('StatusSendingValidatedShort'), '2'=>$langs->trans('StatusSendingProcessedShort')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'onrightofpage');
791  print '</td>';
792 }
793 // Status billed
794 if (!empty($arrayfields['e.billed']['checked'])) {
795  print '<td class="liste_titre maxwidthonsmartphone center">';
796  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
797  print '</td>';
798 }
799 // Action column
800 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
801  print '<td class="liste_titre middle">';
802  $searchpicto = $form->showFilterAndCheckAddButtons(0);
803  print $searchpicto;
804  print '</td>';
805 }
806 print "</tr>\n";
807 
808 print '<tr class="liste_titre">';
809 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
810  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
811 }
812 if (!empty($arrayfields['e.ref']['checked'])) {
813  print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
814 }
815 if (!empty($arrayfields['e.ref_customer']['checked'])) {
816  print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);
817 }
818 if (!empty($arrayfields['s.nom']['checked'])) {
819  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
820 }
821 if (!empty($arrayfields['s.town']['checked'])) {
822  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
823 }
824 if (!empty($arrayfields['s.zip']['checked'])) {
825  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
826 }
827 if (!empty($arrayfields['state.nom']['checked'])) {
828  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
829 }
830 if (!empty($arrayfields['country.code_iso']['checked'])) {
831  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
832 }
833 if (!empty($arrayfields['typent.code']['checked'])) {
834  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
835 }
836 if (!empty($arrayfields['e.weight']['checked'])) {
837  print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center ');
838 }
839 if (!empty($arrayfields['e.date_delivery']['checked'])) {
840  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
841 }
842 if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
843  print_liste_field_titre($arrayfields['e.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "e.fk_shipping_method", "", $param, '', $sortfield, $sortorder, 'center ');
844 }
845 if (!empty($arrayfields['e.tracking_number']['checked'])) {
846  print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center ');
847 }
848 if (!empty($arrayfields['l.ref']['checked'])) {
849  print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
850 }
851 if (!empty($arrayfields['l.date_delivery']['checked'])) {
852  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
853 }
854 // Extra fields
855 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
856 // Hook fields
857 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
858 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
859 print $hookmanager->resPrint;
860 if (!empty($arrayfields['e.datec']['checked'])) {
861  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
862 }
863 if (!empty($arrayfields['e.tms']['checked'])) {
864  print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
865 }
866 if (!empty($arrayfields['e.fk_statut']['checked'])) {
867  print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
868 }
869 if (!empty($arrayfields['e.billed']['checked'])) {
870  print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
871 }
872 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
873  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
874 }
875 print "</tr>\n";
876 
877 $typenArray = $formcompany->typent_array(1);
878 $i = 0;
879 $totalarray = array();
880 $totalarray['nbfield'] = 0;
881 while ($i < min($num, $limit)) {
882  $obj = $db->fetch_object($resql);
883 
884  $shipment->id = $obj->rowid;
885  $shipment->ref = $obj->ref;
886  $shipment->shipping_method_id=$obj->fk_shipping_method;
887 
888  $companystatic->id = $obj->socid;
889  $companystatic->ref = $obj->name;
890  $companystatic->name = $obj->name;
891 
892  $object = new Expedition($db);
893  $object->fetch($obj->rowid);
894 
895  print '<tr class="oddeven">';
896 
897  // Action column
898  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
899  print '<td class="nowrap" align="center">';
900  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
901  $selected = 0;
902  if (in_array($obj->rowid, $arrayofselected)) {
903  $selected = 1;
904  }
905  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
906  }
907  print '</td>';
908  }
909  // Ref
910  if (!empty($arrayfields['e.ref']['checked'])) {
911  print '<td class="nowraponall">';
912  print $shipment->getNomUrl(1);
913  print "</td>\n";
914  if (!$i) {
915  $totalarray['nbfield']++;
916  }
917  }
918 
919  // Ref customer
920  if (!empty($arrayfields['e.ref_customer']['checked'])) {
921  print "<td>";
922  print $obj->ref_customer;
923  print "</td>\n";
924  if (!$i) {
925  $totalarray['nbfield']++;
926  }
927  }
928 
929  // Third party
930  if (!empty($arrayfields['s.nom']['checked'])) {
931  print '<td class="tdoverflowmax150">';
932  print $companystatic->getNomUrl(1);
933  print '</td>';
934  if (!$i) {
935  $totalarray['nbfield']++;
936  }
937  }
938  // Town
939  if (!empty($arrayfields['s.town']['checked'])) {
940  print '<td class="nocellnopadd">';
941  print $obj->town;
942  print '</td>';
943  if (!$i) {
944  $totalarray['nbfield']++;
945  }
946  }
947  // Zip
948  if (!empty($arrayfields['s.zip']['checked'])) {
949  print '<td class="nocellnopadd center">';
950  print $obj->zip;
951  print '</td>';
952  if (!$i) {
953  $totalarray['nbfield']++;
954  }
955  }
956  // State
957  if (!empty($arrayfields['state.nom']['checked'])) {
958  print '<td class="center">'.$obj->state_name."</td>\n";
959  if (!$i) {
960  $totalarray['nbfield']++;
961  }
962  }
963  // Country
964  if (!empty($arrayfields['country.code_iso']['checked'])) {
965  print '<td class="center">';
966  $tmparray = getCountry($obj->fk_pays, 'all');
967  print $tmparray['label'];
968  print '</td>';
969  if (!$i) {
970  $totalarray['nbfield']++;
971  }
972  }
973  // Type ent
974  if (!empty($arrayfields['typent.code']['checked'])) {
975  print '<td class="center">';
976  if (isset($typenArray[$obj->typent_code])) {
977  print $typenArray[$obj->typent_code];
978  }
979  print '</td>';
980  if (!$i) {
981  $totalarray['nbfield']++;
982  }
983  }
984  // Weight
985  if (!empty($arrayfields['e.weight']['checked'])) {
986  print '<td class="center">';
987  if (empty($object->trueWeight)) {
988  $tmparray = $object->getTotalWeightVolume();
989  print showDimensionInBestUnit($tmparray['weight'], 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no');
990  print $form->textwithpicto('', $langs->trans('EstimatedWeight'), 1);
991  } else {
992  print $object->trueWeight;
993  print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
994  }
995  print '</td>';
996  if (!$i) {
997  $totalarray['nbfield']++;
998  }
999  }
1000  // Date delivery planed
1001  if (!empty($arrayfields['e.date_delivery']['checked'])) {
1002  print '<td class="center">';
1003  print dol_print_date($db->jdate($obj->delivery_date), "dayhour");
1004  print "</td>\n";
1005  }
1006  if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1007  // Get code using getLabelFromKey
1008  $code=$langs->getLabelFromKey($db, $shipment->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
1009  print '<td class="center tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans("SendingMethod".strtoupper($code))).'">';
1010  if ($shipment->shipping_method_id > 0) print $langs->trans("SendingMethod".strtoupper($code));
1011  print '</td>';
1012  }
1013  // Tracking number
1014  if (!empty($arrayfields['e.tracking_number']['checked'])) {
1015  $shipment->getUrlTrackingStatus($obj->tracking_number);
1016  print '<td class="center">'.$shipment->tracking_url."</td>\n";
1017  //print $form->editfieldval("TrackingNumber", 'tracking_number', $obj->tracking_url, $obj, $user->rights->expedition->creer, 'string', $obj->tracking_number);
1018  if (!$i) {
1019  $totalarray['nbfield']++;
1020  }
1021  }
1022 
1023  if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1024  $shipment->fetchObjectLinked($shipment->id, $shipment->element);
1025  $receiving = '';
1026  if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) {
1027  $receiving = reset($shipment->linkedObjects['delivery']);
1028  }
1029 
1030  if (!empty($arrayfields['l.ref']['checked'])) {
1031  // Ref
1032  print '<td>';
1033  print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1034  print '</td>';
1035  }
1036 
1037  if (!empty($arrayfields['l.date_delivery']['checked'])) {
1038  // Date received
1039  print '<td class="center">';
1040  print dol_print_date($db->jdate($obj->date_reception), "day");
1041  print '</td>'."\n";
1042  }
1043  }
1044 
1045  // Extra fields
1046  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1047  // Fields from hook
1048  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1049  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1050  print $hookmanager->resPrint;
1051  // Date creation
1052  if (!empty($arrayfields['e.datec']['checked'])) {
1053  print '<td class="center nowrap">';
1054  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1055  print '</td>';
1056  if (!$i) {
1057  $totalarray['nbfield']++;
1058  }
1059  }
1060  // Date modification
1061  if (!empty($arrayfields['e.tms']['checked'])) {
1062  print '<td class="center nowrap">';
1063  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1064  print '</td>';
1065  if (!$i) {
1066  $totalarray['nbfield']++;
1067  }
1068  }
1069  // Status
1070  if (!empty($arrayfields['e.fk_statut']['checked'])) {
1071  print '<td class="right nowrap">'.$shipment->LibStatut($obj->fk_statut, 5).'</td>';
1072  if (!$i) {
1073  $totalarray['nbfield']++;
1074  }
1075  }
1076  // Billed
1077  if (!empty($arrayfields['e.billed']['checked'])) {
1078  print '<td class="center">'.yn($obj->billed).'</td>';
1079  if (!$i) {
1080  $totalarray['nbfield']++;
1081  }
1082  }
1083 
1084  // Action column
1085  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1086  print '<td class="nowrap" align="center">';
1087  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1088  $selected = 0;
1089  if (in_array($obj->rowid, $arrayofselected)) {
1090  $selected = 1;
1091  }
1092  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1093  }
1094  print '</td>';
1095  }
1096  if (!$i) {
1097  $totalarray['nbfield']++;
1098  }
1099 
1100  print "</tr>\n";
1101 
1102  $i++;
1103 }
1104 
1105 // If no record found
1106 if ($num == 0) {
1107  $colspan = 1;
1108  foreach ($arrayfields as $key => $val) {
1109  if (!empty($val['checked'])) {
1110  $colspan++;
1111  }
1112  }
1113  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1114 }
1115 
1116 $db->free($resql);
1117 
1118 $parameters = array('arrayfields'=>$arrayfields, 'totalarray' => $totalarray, 'sql'=>$sql);
1119 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1120 print $hookmanager->resPrint;
1121 
1122 print "</table>";
1123 print "</div>";
1124 print '</form>';
1125 
1126 $hidegeneratedfilelistifempty = 1;
1127 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1128  $hidegeneratedfilelistifempty = 0;
1129 }
1130 
1131 // Show list of available documents
1132 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1133 $urlsource .= str_replace('&amp;', '&', $param);
1134 
1135 $filedir = $diroutputmassaction;
1136 $genallowed = $user->rights->expedition->lire;
1137 $delallowed = $user->rights->expedition->creer;
1138 $title = '';
1139 
1140 print $formfile->showdocuments('massfilesarea_sendings', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1141 
1142 // End of page
1143 llxFooter();
1144 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage shipments.
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.