dolibarr  20.0.0-beta
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  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10  * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
11  * Copyright (C) 2024 Vincent Maury <vmaury@timgroup.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 // Load Dolibarr environment
34 require '../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array("sendings", "deliveries", 'companies', 'bills', 'products'));
46 
47 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search
48 
49 $socid = GETPOSTINT('socid');
50 
51 $action = GETPOST('action', 'alpha');
52 $massaction = GETPOST('massaction', 'alpha');
53 $show_files = GETPOSTINT('show_files');
54 $toselect = GETPOST('toselect', 'array');
55 $optioncss = GETPOST('optioncss', 'alpha');
56 $mode = GETPOST('mode', 'alpha');
57 
58 $search_ref_exp = GETPOST("search_ref_exp", 'alpha');
59 $search_ref_liv = GETPOST('search_ref_liv', 'alpha');
60 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
61 $search_company = GETPOST("search_company", 'alpha');
62 $search_shipping_method_ids = GETPOST('search_shipping_method_ids', 'array:int');
63 $search_tracking = GETPOST("search_tracking", 'alpha');
64 $search_town = GETPOST('search_town', 'alpha');
65 $search_zip = GETPOST('search_zip', 'alpha');
66 $search_state = GETPOST("search_state", 'alpha');
67 $search_country = GETPOST("search_country", 'aZ09');
68 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
69 $search_billed = GETPOST("search_billed", 'intcomma');
70 $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datedelivery_startmonth'), GETPOSTINT('search_datedelivery_startday'), GETPOSTINT('search_datedelivery_startyear'));
71 $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datedelivery_endmonth'), GETPOSTINT('search_datedelivery_endday'), GETPOSTINT('search_datedelivery_endyear'));
72 $search_datereceipt_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datereceipt_startmonth'), GETPOSTINT('search_datereceipt_startday'), GETPOSTINT('search_datereceipt_startyear'));
73 $search_datereceipt_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datereceipt_endmonth'), GETPOSTINT('search_datereceipt_endday'), GETPOSTINT('search_datereceipt_endyear'));
74 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
75 $search_user = GETPOST('search_user', 'intcomma');
76 $search_sale = GETPOST('search_sale', 'intcomma');
77 $search_categ_cus = GETPOST("search_categ_cus", 'intcomma');
78 $search_product_category = GETPOST('search_product_category', 'intcomma');
79 
80 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
81 $sortfield = GETPOST('sortfield', 'aZ09comma');
82 $sortorder = GETPOST('sortorder', 'aZ09comma');
83 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
84 if (!$sortfield) {
85  $sortfield = "e.ref";
86 }
87 if (!$sortorder) {
88  $sortorder = "DESC";
89 }
90 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
91  // If $page is not defined, or '' or -1 or if we click on clear filters
92  $page = 0;
93 }
94 $offset = $limit * $page;
95 $pageprev = $page - 1;
96 $pagenext = $page + 1;
97 
98 $search_status = GETPOST('search_status', 'intcomma');
99 
100 $diroutputmassaction = $conf->expedition->dir_output.'/sending/temp/massgeneration/'.$user->id;
101 
102 $object = new Expedition($db);
103 
104 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
105 $hookmanager->initHooks(array('shipmentlist'));
106 $extrafields = new ExtraFields($db);
107 
108 // Fetch optionals attributes and labels
109 $extrafields->fetch_name_optionals_label($object->table_element);
110 
111 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
112 
113 // List of fields to search into when doing a "search in all"
114 $fieldstosearchall = array(
115  'e.ref' => "Ref",
116  's.nom' => "ThirdParty",
117  'e.note_public' => 'NotePublic',
118  //'e.fk_shipping_method'=>'SendingMethod', // TODO fix this, does not work
119  'e.tracking_number' => "TrackingNumber",
120 );
121 if (empty($user->socid)) {
122  $fieldstosearchall["e.note_private"] = "NotePrivate";
123 }
124 
125 $checkedtypetiers = 0;
126 $arrayfields = array(
127  'e.ref' => array('label' => $langs->trans("Ref"), 'checked' => 1, 'position' => 1),
128  'e.ref_customer' => array('label' => $langs->trans("RefCustomer"), 'checked' => 1, 'position' => 2),
129  's.nom' => array('label' => $langs->trans("ThirdParty"), 'checked' => 1, 'position' => 3),
130  's.town' => array('label' => $langs->trans("Town"), 'checked' => 1, 'position' => 4),
131  's.zip' => array('label' => $langs->trans("Zip"), 'checked' => 1, 'position' => 5),
132  'state.nom' => array('label' => $langs->trans("StateShort"), 'checked' => 0, 'position' => 6),
133  'country.code_iso' => array('label' => $langs->trans("Country"), 'checked' => 0, 'position' => 7),
134  'typent.code' => array('label' => $langs->trans("ThirdPartyType"), 'checked' => $checkedtypetiers, 'position' => 8),
135  'e.date_delivery' => array('label' => $langs->trans("DateDeliveryPlanned"), 'checked' => 1, 'position' => 9),
136  'e.fk_shipping_method' => array('label' => $langs->trans('SendingMethod'), 'checked' => 1, 'position' => 10),
137  'e.tracking_number' => array('label' => $langs->trans("TrackingNumber"), 'checked' => 1, 'position' => 11),
138  'e.weight' => array('label' => $langs->trans("Weight"), 'checked' => 0, 'position' => 12),
139  'e.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500),
140  'e.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 500),
141  'e.fk_statut' => array('label' => $langs->trans("Status"), 'checked' => 1, 'position' => 1000),
142  'l.ref' => array('label' => $langs->trans("DeliveryRef"), 'checked' => 1, 'position' => 1010, 'enabled' => (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') ? 1 : 0)),
143  'l.date_delivery' => array('label' => $langs->trans("DateReceived"), 'position' => 1020, 'checked' => 1, 'enabled' => (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') ? 1 : 0)),
144  'e.billed' => array('label' => $langs->trans("Billed"), 'checked' => 1, 'position' => 1100, 'enabled' => 'getDolGlobalString("WORKFLOW_BILL_ON_SHIPMENT") !== "0"'),
145  'e.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES)), 'position'=>135),
146  'e.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES)), 'position'=>140),
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 '@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
155 
156 // Security check
157 $expeditionid = GETPOSTINT('id');
158 if ($user->socid) {
159  $socid = $user->socid;
160 }
161 $result = restrictedArea($user, 'expedition', $expeditionid, '');
162 
163 
164 
165 /*
166  * Actions
167  */
168 $error = 0;
169 
170 if (GETPOST('cancel', 'alpha')) {
171  $action = 'list';
172  $massaction = '';
173 }
174 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
175  $massaction = '';
176 }
177 
178 $parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
179 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
180 if ($reshook < 0) {
181  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
182 }
183 
184 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
185 
186 // Purge search criteria
187 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
188  $search_user = '';
189  $search_sale = '';
190  $search_product_category = '';
191  $search_ref_exp = '';
192  $search_ref_liv = '';
193  $search_ref_customer = '';
194  $search_company = '';
195  $search_town = '';
196  $search_zip = "";
197  $search_state = "";
198  $search_type = '';
199  $search_country = '';
200  $search_tracking = '';
201  $search_shipping_method_ids = [];
202  $search_type_thirdparty = '';
203  $search_billed = '';
204  $search_datedelivery_start = '';
205  $search_datedelivery_end = '';
206  $search_datereceipt_start = '';
207  $search_datereceipt_end = '';
208  $search_status = '';
209  $toselect = array();
210  $search_array_options = array();
211  $search_categ_cus = 0;
212  $search_all = '';
213 }
214 
215 if (empty($reshook)) {
216  $objectclass = 'Expedition';
217  $objectlabel = 'Sendings';
218  $permissiontoread = $user->hasRight('expedition', 'lire');
219  $permissiontoadd = $user->hasRight('expedition', 'creer');
220  $permissiontodelete = $user->hasRight('expedition', 'supprimer');
221  $uploaddir = $conf->expedition->dir_output.'/sending';
222  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
223 
224  if ($massaction == 'confirm_createbills') { // Create bills from sendings.
225  $sendings = GETPOST('toselect', 'array');
226  $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
227  $validate_invoices = GETPOST('validate_invoices', 'int');
228 
229  $errors = array();
230 
231  $TFact = array();
232  $TFactThird = array();
233  $TFactThirdNbLines = array();
234 
235  $nb_bills_created = 0;
236  $lastid= 0;
237  $lastref = '';
238 
239  $db->begin();
240 
241  $nbSendings = is_array($sendings) ? count($sendings) : 1;
242 
243  foreach ($sendings as $id_sending) {
244  $expd = new Expedition($db);
245  if ($expd->fetch($id_sending) <= 0) {
246  continue;
247  }
248  $expd->fetch_thirdparty();
249 
250  $objecttmp = new Facture($db);
251 
252  dol_include_once('/commande/class/commande.class.php');
253  $expdCmdSrc = new Commande($db);
254  $expdCmdSrc->fetch($expd->origin_id);
255 
256  if (!empty($createbills_onebythird) && !empty($TFactThird[$expd->socid])) {
257  // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we reuse it.
258  $objecttmp = $TFactThird[$expd->socid];
259  } else {
260  // If we want one invoice per sending or if there is no first invoice yet for this thirdparty.
261  $objecttmp->socid = $expd->socid;
262  $objecttmp->thirdparty = $expd->thirdparty;
263 
264  $objecttmp->type = $objecttmp::TYPE_STANDARD;
265  $objecttmp->cond_reglement_id = !empty($expdCmdSrc->cond_reglement_id) ? $expdCmdSrc->cond_reglement_id : (!empty($objecttmp->thirdparty->cond_reglement_id) ? $objecttmp->thirdparty->cond_reglement_id : 1);
266  $objecttmp->mode_reglement_id = !empty($expdCmdSrc->mode_reglement_id) ? $expdCmdSrc->mode_reglement_id : (!empty($objecttmp->thirdparty->mode_reglement_id) ? $objecttmp->thirdparty->mode_reglement_id : 0);
267 
268  $objecttmp->fk_project = $expd->fk_project;
269  $objecttmp->multicurrency_code = !empty($expdCmdSrc->multicurrency_code) ? $expdCmdSrc->multicurrency_code : (!empty($objecttmp->thirdparty->multicurrency_code) ? $objecttmp->thirdparty->multicurrency_code : $expd->multicurrency_code);
270  if (empty($createbills_onebythird)) {
271  $objecttmp->ref_client = $expd->ref_client;
272  }
273 
274  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
275  if (empty($datefacture)) {
276  $datefacture = dol_now();
277  }
278 
279  $objecttmp->date = $datefacture;
280  $objecttmp->origin = 'shipping';
281  $objecttmp->origin_id = $id_sending;
282 
283  $objecttmp->array_options = $expd->array_options; // Copy extrafields
284 
285  $res = $objecttmp->create($user);
286 
287  if ($res > 0) {
288  $nb_bills_created++;
289  $lastref = $objecttmp->ref;
290  $lastid = $objecttmp->id;
291 
292  $TFactThird[$expd->socid] = $objecttmp;
293  $TFactThirdNbLines[$expd->socid] = 0; //init nblines to have lines ordered by expedition and rang
294  } else {
295  $langs->load("errors");
296  $errors[] = $expd->ref.' : '.$langs->trans($objecttmp->errors[0]);
297  $error++;
298  }
299  }
300 
301  if ($objecttmp->id > 0) {
302  $res = $objecttmp->add_object_linked($objecttmp->origin, $id_sending);
303 
304  if ($res == 0) {
305  $errors[] = $expd->ref.' : '.$langs->trans($objecttmp->errors[0]);
306  $error++;
307  }
308 
309  $expd->fetchObjectLinked();
310  foreach ($expd->linkedObjectsIds as $sourcetype => $TIds) {
311  if ($sourcetype == 'facture') {
312  continue;
313  }
314  if (!empty($createbills_onebythird) && !empty($TFactThird[$expd->socid])) {
315  $objecttmp->fetchObjectLinked($object->id, 'commande');
316  foreach ($objecttmp->linkedObjectsIds as $tmpSourcetype => $tmpTIds) {
317  if ($tmpSourcetype == $sourcetype) {
318  if (!empty(array_intersect($TIds, $tmpTIds))) {
319  continue 2;
320  }
321  }
322  }
323  }
324 
325  $res = $objecttmp->add_object_linked($sourcetype, current($TIds));
326 
327  if ($res == 0) {
328  $errors[] = $expd->ref.' : '.$langs->trans($objecttmp->errors[0]);
329  $error++;
330  }
331  }
332 
333  if (!$error) {
334  $lines = $expd->lines;
335  if (empty($lines) && method_exists($expd, 'fetch_lines')) {
336  $expd->fetch_lines();
337  $lines = $expd->lines;
338  }
339 
340  $fk_parent_line = 0;
341  $num = count($lines);
342 
343  for ($i = 0; $i < $num; $i++) {
344  $desc = ($lines[$i]->desc ? $lines[$i]->desc : '');
345  // If we build one invoice for several sendings, we must put the ref of sending on the invoice line
346  if (!empty($createbills_onebythird)) {
347  $desc = dol_concatdesc($desc, $langs->trans("Order").' '.$expd->ref.' - '.dol_print_date($expd->date, 'day'));
348  }
349 
350  if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) {
351  // Negative line, we create a discount line
352  $discount = new DiscountAbsolute($db);
353  $discount->fk_soc = $objecttmp->socid;
354  $discount->amount_ht = abs($lines[$i]->total_ht);
355  $discount->amount_tva = abs($lines[$i]->total_tva);
356  $discount->amount_ttc = abs($lines[$i]->total_ttc);
357  $discount->tva_tx = $lines[$i]->tva_tx;
358  $discount->fk_user = $user->id;
359  $discount->description = $desc;
360  $discountid = $discount->create($user);
361  if ($discountid > 0) {
362  $result = $objecttmp->insert_discount($discountid);
363  //$result=$discount->link_to_invoice($lineid,$id);
364  } else {
365  setEventMessages($discount->error, $discount->errors, 'errors');
366  $error++;
367  break;
368  }
369  } else {
370  // Positive line
371  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
372  // Date start
373  $date_start = false;
374  if ($lines[$i]->date_debut_prevue) {
375  $date_start = $lines[$i]->date_debut_prevue;
376  }
377  if ($lines[$i]->date_debut_reel) {
378  $date_start = $lines[$i]->date_debut_reel;
379  }
380  if ($lines[$i]->date_start) {
381  $date_start = $lines[$i]->date_start;
382  }
383  //Date end
384  $date_end = false;
385  if ($lines[$i]->date_fin_prevue) {
386  $date_end = $lines[$i]->date_fin_prevue;
387  }
388  if ($lines[$i]->date_fin_reel) {
389  $date_end = $lines[$i]->date_fin_reel;
390  }
391  if ($lines[$i]->date_end) {
392  $date_end = $lines[$i]->date_end;
393  }
394  // Reset fk_parent_line for no child products and special product
395  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
396  $fk_parent_line = 0;
397  }
398 
399  // Extrafields
400  if (method_exists($lines[$i], 'fetch_optionals')) {
401  $lines[$i]->fetch_optionals();
402  $array_options = $lines[$i]->array_options;
403  }
404 
405  $objecttmp->context['createfromclone'] = 'createfromclone';
406 
407  $rang = ($nbSendings > 1) ? -1 : $lines[$i]->rang;
408  //there may already be rows from previous sendings
409  if (!empty($createbills_onebythird)) {
410  $rang = $TFactThirdNbLines[$expd->socid];
411  }
412 
413  $result = $objecttmp->addline(
414  $desc,
415  $lines[$i]->subprice,
416  $lines[$i]->qty,
417  $lines[$i]->tva_tx,
418  $lines[$i]->localtax1_tx,
419  $lines[$i]->localtax2_tx,
420  $lines[$i]->fk_product,
421  $lines[$i]->remise_percent,
422  $date_start,
423  $date_end,
424  0,
425  $lines[$i]->info_bits,
426  $lines[$i]->fk_remise_except,
427  'HT',
428  0,
429  $product_type,
430  $rang,
431  $lines[$i]->special_code,
432  $objecttmp->origin,
433  $lines[$i]->rowid,
434  $fk_parent_line,
435  $lines[$i]->fk_fournprice,
436  $lines[$i]->pa_ht,
437  $lines[$i]->label,
438  !empty($array_options) ? $array_options : '',
439  100,
440  0,
441  $lines[$i]->fk_unit
442  );
443  if ($result > 0) {
444  $lineid = $result;
445  if (!empty($createbills_onebythird)) //increment rang to keep sending
446  $TFactThirdNbLines[$expd->socid]++;
447  } else {
448  $lineid = 0;
449  $error++;
450  $errors[] = $objecttmp->error;
451  break;
452  }
453  // Defined the new fk_parent_line
454  if ($result > 0 && $lines[$i]->product_type == 9) {
455  $fk_parent_line = $result;
456  }
457  }
458  }
459  }
460  }
461 
462  if (!empty($createbills_onebythird) && empty($TFactThird[$expd->socid])) {
463  $TFactThird[$expd->socid] = $objecttmp;
464  } else {
465  $TFact[$objecttmp->id] = $objecttmp;
466  }
467  }
468 
469  // Build doc with all invoices
470  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
471  $toselect = array();
472 
473  if (!$error && $validate_invoices) {
474  $massaction = $action = 'builddoc';
475 
476  foreach ($TAllFact as &$objecttmp) {
477  $result = $objecttmp->validate($user);
478  if ($result <= 0) {
479  $error++;
480  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
481  break;
482  }
483 
484  $id = $objecttmp->id; // For builddoc action
485 
486  // Builddoc
487  $donotredirect = 1;
488  $upload_dir = $conf->facture->dir_output;
489  $permissiontoadd = $user->hasRight('facture', 'creer');
490 
491  // Call action to build doc
492  $savobject = $object;
493  $object = $objecttmp;
494  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
495  $object = $savobject;
496  }
497 
498  $massaction = $action = 'confirm_createbills';
499  }
500 
501  if (!$error) {
502  $db->commit();
503 
504  if ($nb_bills_created == 1) {
505  $texttoshow = $langs->trans('BillXCreated', '{s1}');
506  $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode(strval($lastid)).'">'.$lastref.'</a>', $texttoshow);
507  setEventMessages($texttoshow, null, 'mesgs');
508  } else {
509  setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
510  }
511 
512  // Make a redirect to avoid to bill twice if we make a refresh or back
513  $param = '';
514  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
515  $param .= '&contextpage='.urlencode($contextpage);
516  }
517  if ($limit > 0 && $limit != $conf->liste_limit) {
518  $param .= '&limit='.urlencode(strval($limit));
519  }
520  if ($sall) {
521  $param .= "&sall=".urlencode($sall);
522  }
523  if ($search_ref_exp) {
524  $param .= "&search_ref_exp=".urlencode($search_ref_exp);
525  }
526  if ($search_ref_liv) {
527  $param .= "&search_ref_liv=".urlencode($search_ref_liv);
528  }
529  if ($search_ref_customer) {
530  $param .= "&search_ref_customer=".urlencode($search_ref_customer);
531  }
532  if ($search_user > 0) {
533  $param .= '&search_user='.urlencode($search_user);
534  }
535  if ($search_sale > 0) {
536  $param .= '&search_sale='.urlencode($search_sale);
537  }
538  if ($search_company) {
539  $param .= "&search_company=".urlencode($search_company);
540  }
541  if ($search_shipping_method_id) {
542  $param .= "&amp;search_shipping_method_id=".urlencode($search_shipping_method_id);
543  }
544  if ($search_tracking) {
545  $param .= "&search_tracking=".urlencode($search_tracking);
546  }
547  if ($search_town) {
548  $param .= '&search_town='.urlencode($search_town);
549  }
550  if ($search_zip) {
551  $param .= '&search_zip='.urlencode($search_zip);
552  }
553  if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
554  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
555  }
556  if ($search_datedelivery_start) {
557  $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'));
558  }
559  if ($search_datedelivery_end) {
560  $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'));
561  }
562  if ($search_datereceipt_start) {
563  $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'));
564  }
565  if ($search_datereceipt_end) {
566  $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'));
567  }
568  if ($search_product_category != '') {
569  $param .= '&search_product_category='.urlencode($search_product_category);
570  }
571  if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
572  $param .= '&search_categ_cus='.urlencode($search_categ_cus);
573  }
574  if ($search_status != '') {
575  $param .= '&search_status='.urlencode($search_status);
576  }
577  if ($optioncss != '') {
578  $param .= '&optioncss='.urlencode($optioncss);
579  }
580  if ($search_billed != '') {
581  $param .= '&billed='.urlencode($search_billed);
582  }
583 
584  header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
585  exit;
586  } else {
587  $db->rollback();
588 
589  $action = 'create';
590  $_GET["origin"] = $_POST["origin"];
591  $_GET["originid"] = $_POST["originid"];
592  if (!empty($errors)) {
593  setEventMessages(null, $errors, 'errors');
594  } else {
595  setEventMessages("Error", null, 'errors');
596  }
597  $error++;
598  }
599  }
600 
601  // If massaction is close
602  if ($massaction == 'classifyclose') {
603  $error = 0;
604  $selectids = GETPOST('toselect', 'array');
605  foreach ($selectids as $selectid) {
606  // $object->fetch($selectid);
607  $object->fetch($selectid);
608  $result = $object->setClosed();
609  }
610 
611  $massaction = $action = 'classifyclose';
612 
613  if ($result < 0) {
614  $error++;
615  }
616 
617 
618  if (!$error) {
619  $db->commit();
620 
621  setEventMessage($langs->trans("Close Done"));
622  header('Location: '.$_SERVER["PHP_SELF"]);
623  exit;
624  } else {
625  $db->rollback();
626  exit;
627  }
628  }
629 }
630 
631 /*
632  * View
633  */
634 
635 $now = dol_now();
636 
637 $form = new Form($db);
638 $formother = new FormOther($db);
639 $formfile = new FormFile($db);
640 $companystatic = new Societe($db);
641 $formcompany = new FormCompany($db);
642 $shipment = new Expedition($db);
643 
644 $helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
645 llxHeader('', $langs->trans('ListOfSendings'), $helpurl);
646 
647 $sql = 'SELECT';
648 if ($search_all || $search_user > 0) {
649  $sql = 'SELECT DISTINCT';
650 }
651 $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,";
652 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
653  // Link for delivery fields ref and date. Does not duplicate the line because we should always have only 1 link or 0 per shipment
654  $sql .= " l.date_delivery as date_reception,";
655 }
656 $sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ";
657 $sql .= " typent.code as typent_code,";
658 $sql .= " state.code_departement as state_code, state.nom as state_name,";
659 $sql .= " e.date_creation as date_creation, e.tms as date_modification,e.note_public, e.note_private,";
660 $sql .= " u.login";
661 // Add fields from extrafields
662 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
663  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
664  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
665  }
666 }
667 // Add fields from hooks
668 $parameters = array();
669 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
670 $sql .= $hookmanager->resPrint;
671 
672 $sqlfields = $sql; // $sql fields to remove for count total
673 
674 $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
675 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
676  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
677 }
678 if ($search_all) {
679  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition';
680  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_elementdet';
681 }
682 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
683 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
684 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
685 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
686 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
687  // Link for delivery fields ref and date. Does not duplicate the line because we should always have only 1 link or 0 per shipment
688  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
689  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
690 }
691 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user_author = u.rowid';
692 if ($search_user > 0) { // Get link to order to get the order id in eesource.fk_source
693  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'";
694 }
695 if ($search_user > 0) {
696  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
697  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
698 }
699 
700 // Add table from hooks
701 $parameters = array();
702 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
703 $sql .= $hookmanager->resPrint;
704 
705 $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
706 
707 if ($socid > 0) {
708  $sql .= " AND s.rowid = ".((int) $socid);
709 }
710 if ($socid) {
711  $sql .= " AND e.fk_soc = ".((int) $socid);
712 }
713 if ($search_status != '' && $search_status >= 0) {
714  $sql .= " AND e.fk_statut = ".((int) $search_status);
715 }
716 if ($search_ref_customer != '') {
717  $sql .= natural_search('e.ref_customer', $search_ref_customer);
718 }
719 if ($search_billed != '' && $search_billed >= 0) {
720  $sql .= ' AND e.billed = '.((int) $search_billed);
721 }
722 if ($search_town) {
723  $sql .= natural_search('s.town', $search_town);
724 }
725 if ($search_zip) {
726  $sql .= natural_search("s.zip", $search_zip);
727 }
728 if ($search_state) {
729  $sql .= natural_search("state.nom", $search_state);
730 }
731 if ($search_country) {
732  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
733 }
734 if (!empty($search_shipping_method_ids)) {
735  $sql .= " AND e.fk_shipping_method IN (".$db->sanitize(implode(',', $search_shipping_method_ids)).')';
736 }
737 if ($search_tracking) {
738  $sql .= natural_search("e.tracking_number", $search_tracking);
739 }
740 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
741  $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
742 }
743 if ($search_user > 0) {
744  // The contact on a shipment is also the contact of the order.
745  $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);
746 }
747 if ($search_company) {
748  $sql .= natural_search('s.nom', $search_company);
749 }
750 if ($search_ref_exp) {
751  $sql .= natural_search('e.ref', $search_ref_exp);
752 }
753 if ($search_datedelivery_start) {
754  $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'";
755 }
756 if ($search_datedelivery_end) {
757  $sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'";
758 }
759 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
760  if ($search_ref_liv) {
761  $sql .= natural_search('l.ref', $search_ref_liv);
762  }
763  if ($search_datereceipt_start) {
764  $sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'";
765  }
766  if ($search_datereceipt_end) {
767  $sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'";
768  }
769 }
770 if ($search_all) {
771  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
772 }
773 // Search on sale representative
774 if ($search_sale && $search_sale != '-1') {
775  if ($search_sale == -2) {
776  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc)";
777  } elseif ($search_sale > 0) {
778  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
779  }
780 }
781 // Search for tag/category ($searchCategoryCustomerList is an array of ID)
782 $searchCategoryCustomerOperator = -1;
783 $searchCategoryCustomerList = array($search_categ_cus);
784 if (!empty($searchCategoryCustomerList)) {
785  $searchCategoryCustomerSqlList = array();
786  $listofcategoryid = '';
787  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
788  if (intval($searchCategoryCustomer) == -2) {
789  $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";
790  } elseif (intval($searchCategoryCustomer) > 0) {
791  if ($searchCategoryCustomerOperator == 0) {
792  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategoryCustomer).")";
793  } else {
794  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
795  }
796  }
797  }
798  if ($listofcategoryid) {
799  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
800  }
801  if ($searchCategoryCustomerOperator == 1) {
802  if (!empty($searchCategoryCustomerSqlList)) {
803  $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
804  }
805  } else {
806  if (!empty($searchCategoryCustomerSqlList)) {
807  $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
808  }
809  }
810 }
811 // Search for tag/category ($searchCategoryProductList is an array of ID)
812 $searchCategoryProductOperator = -1;
813 $searchCategoryProductList = array($search_product_category);
814 if (!empty($searchCategoryProductList)) {
815  $searchCategoryProductSqlList = array();
816  $listofcategoryid = '';
817  foreach ($searchCategoryProductList as $searchCategoryProduct) {
818  if (intval($searchCategoryProduct) == -2) {
819  $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_elementdet = cd.rowid AND cd.fk_product = ck.fk_product)";
820  } elseif (intval($searchCategoryProduct) > 0) {
821  if ($searchCategoryProductOperator == 0) {
822  $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_elementdet = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
823  } else {
824  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
825  }
826  }
827  }
828  if ($listofcategoryid) {
829  $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_elementdet = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
830  }
831  if ($searchCategoryProductOperator == 1) {
832  if (!empty($searchCategoryProductSqlList)) {
833  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
834  }
835  } else {
836  if (!empty($searchCategoryProductSqlList)) {
837  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
838  }
839  }
840 }
841 // Add where from extra fields
842 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
843 
844 // Add where from hooks
845 $parameters = array();
846 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
847 $sql .= $hookmanager->resPrint;
848 
849 // Add HAVING from hooks
850 $parameters = array();
851 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
852 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
853 
854 $nbtotalofrecords = '';
855 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
856  /* The fast and low memory method to get and count full list converts the sql into a sql count */
857  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
858  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
859  $resql = $db->query($sqlforcount);
860  if ($resql) {
861  $objforcount = $db->fetch_object($resql);
862  $nbtotalofrecords = $objforcount->nbtotalofrecords;
863  } else {
864  dol_print_error($db);
865  }
866 
867  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
868  $page = 0;
869  $offset = 0;
870  }
871  $db->free($resql);
872 }
873 
874 // Complete request and execute it with limit
875 $sql .= $db->order($sortfield, $sortorder);
876 if ($limit) {
877  $sql .= $db->plimit($limit + 1, $offset);
878 }
879 
880 //print $sql;
881 $resql = $db->query($sql);
882 if (!$resql) {
883  dol_print_error($db);
884  exit;
885 }
886 
887 $num = $db->num_rows($resql);
888 
889 $arrayofselected = is_array($toselect) ? $toselect : array();
890 
891 $expedition = new Expedition($db);
892 
893 if ($socid > 0) {
894  $soc = new Societe($db);
895  $soc->fetch($socid);
896  if (empty($search_company)) {
897  $search_company = $soc->name;
898  }
899 }
900 
901 $param = '';
902 if ($socid > 0) {
903  $param .= '&socid='.urlencode((string) ($socid));
904 }
905 if (!empty($mode)) {
906  $param .= '&mode='.urlencode($mode);
907 }
908 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
909  $param .= '&contextpage='.urlencode($contextpage);
910 }
911 if ($limit > 0 && $limit != $conf->liste_limit) {
912  $param .= '&limit='.((int) $limit);
913 }
914 if ($search_all) {
915  $param .= "&search_all=".urlencode($search_all);
916 }
917 if ($search_ref_exp) {
918  $param .= "&search_ref_exp=".urlencode($search_ref_exp);
919 }
920 if ($search_ref_liv) {
921  $param .= "&search_ref_liv=".urlencode($search_ref_liv);
922 }
923 if ($search_ref_customer) {
924  $param .= "&search_ref_customer=".urlencode($search_ref_customer);
925 }
926 if ($search_user > 0) {
927  $param .= '&search_user='.urlencode((string) ($search_user));
928 }
929 if ($search_sale > 0) {
930  $param .= '&search_sale='.urlencode((string) ($search_sale));
931 }
932 if ($search_company) {
933  $param .= "&search_company=".urlencode($search_company);
934 }
935 if ($search_shipping_method_ids) {
936  foreach ($search_shipping_method_ids as $value) {
937  $param .= "&amp;search_shipping_method_ids[]=".urlencode($value);
938  }
939 }
940 if ($search_tracking) {
941  $param .= "&search_tracking=".urlencode($search_tracking);
942 }
943 if ($search_town) {
944  $param .= '&search_town='.urlencode($search_town);
945 }
946 if ($search_zip) {
947  $param .= '&search_zip='.urlencode($search_zip);
948 }
949 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
950  $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
951 }
952 if ($search_datedelivery_start) {
953  $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'));
954 }
955 if ($search_datedelivery_end) {
956  $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'));
957 }
958 if ($search_datereceipt_start) {
959  $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'));
960 }
961 if ($search_datereceipt_end) {
962  $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'));
963 }
964 if ($search_product_category != '') {
965  $param .= '&search_product_category='.urlencode((string) ($search_product_category));
966 }
967 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
968  $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
969 }
970 if ($search_status != '') {
971  $param .= '&search_status='.urlencode($search_status);
972 }
973 if ($optioncss != '') {
974  $param .= '&optioncss='.urlencode($optioncss);
975 }
976 // Add $param from extra fields
977 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
978 
979 // Add $param from hooks
980 $parameters = array('param' => &$param);
981 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
982 $param .= $hookmanager->resPrint;
983 
984 $arrayofmassactions = array(
985  'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
986  'classifyclose' => img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("Close"),
987  'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
988 );
989 if ($user->hasRight('facture', 'creer')) {
990  $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomerFromSendings");
991 }
992 if (in_array($massaction, array('presend', 'createbills'))) {
993  $arrayofmassactions = array();
994 }
995 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
996 
997 // Currently: a sending can't create from sending list
998 // $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
999 // if (!empty($socid)) $url .= '&socid='.$socid;
1000 // $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
1001 $newcardbutton = '';
1002 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
1003 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
1004 $newcardbutton .= dolGetButtonTitleSeparator();
1005 $newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2', '', $user->hasRight('expedition', 'creer'));
1006 
1007 $i = 0;
1008 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1009 if ($optioncss != '') {
1010  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1011 }
1012 print '<input type="hidden" name="token" value="'.newToken().'">';
1013 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1014 print '<input type="hidden" name="action" value="list">';
1015 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1016 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1017 print '<input type="hidden" name="socid" value="'.$socid.'">';
1018 print '<input type="hidden" name="mode" value="'.$mode.'">';
1019 
1020 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1021 print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dolly', 0, $newcardbutton, '', $limit, 0, 0, 1);
1022 
1023 $topicmail = "SendShippingRef";
1024 $modelmail = "shipping_send";
1025 $objecttmp = new Expedition($db);
1026 $trackid = 'shi'.$object->id;
1027 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1028 
1029 if ($massaction == 'createbills') {
1030  print '<input type="hidden" name="massaction" value="confirm_createbills">';
1031 
1032  print '<table class="noborder" width="100%" >';
1033  print '<tr>';
1034  print '<td class="titlefield">';
1035  print $langs->trans('DateInvoice');
1036  print '</td>';
1037  print '<td>';
1038  print $form->selectDate('', '', '', '', '', '', 1, 1);
1039  print '</td>';
1040  print '</tr>';
1041  print '<tr>';
1042  print '<td>';
1043  print $langs->trans('CreateOneBillByThird');
1044  print '</td>';
1045  print '<td>';
1046  print $form->selectyesno('createbills_onebythird', '', 1);
1047  print '</td>';
1048  print '</tr>';
1049  print '<tr>';
1050  print '<td>';
1051  print $langs->trans('ValidateInvoices');
1052  print '</td>';
1053  print '<td>';
1054  if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
1055  print $form->selectyesno('validate_invoices', 0, 1, 1);
1056  $langs->load("errors");
1057  print ' ('.$langs->trans("WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal").')';
1058  } else {
1059  print $form->selectyesno('validate_invoices', 0, 1);
1060  }
1061  if (!empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) {
1062  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoSendingStayUnbilled").'</span>';
1063  } else {
1064  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetSendingBilledNotEnabled").'</span>';
1065  }
1066  print '</td>';
1067  print '</tr>';
1068  print '</table>';
1069 
1070  print '<br>';
1071  print '<div class="center">';
1072  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomerFromSendings').'"> ';
1073  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1074  print '</div>';
1075  print '<br>';
1076 }
1077 
1078 if ($search_all) {
1079  foreach ($fieldstosearchall as $key => $val) {
1080  $fieldstosearchall[$key] = $langs->trans($val);
1081  }
1082  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1083 }
1084 
1085 $moreforfilter = '';
1086 
1087 // If the user can view prospects other than his'
1088 if ($user->hasRight('user', 'user', 'lire')) {
1089  $langs->load("commercial");
1090  $moreforfilter .= '<div class="divsearchfield">';
1091  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1092  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
1093  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1094  $moreforfilter .= '</div>';
1095 }
1096 // If the user can view other users
1097 if ($user->hasRight('user', 'user', 'lire')) {
1098  $moreforfilter .= '<div class="divsearchfield">';
1099  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1100  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
1101  $moreforfilter .= $form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
1102  $moreforfilter .= '</div>';
1103 }
1104 // If the user can view prospects other than his'
1105 if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1106  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1107  $moreforfilter .= '<div class="divsearchfield">';
1108  $tmptitle = $langs->trans('IncludingProductWithTag');
1109  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1110  //$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1111  //$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
1112  $moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'search_product_category', 1, $tmptitle);
1113 
1114  $moreforfilter .= '</div>';
1115 }
1116 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1117  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1118  $moreforfilter .= '<div class="divsearchfield">';
1119  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1120  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1121  $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
1122  $moreforfilter .= '</div>';
1123 }
1124 $parameters = array();
1125 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1126 if (empty($reshook)) {
1127  $moreforfilter .= $hookmanager->resPrint;
1128 } else {
1129  $moreforfilter = $hookmanager->resPrint;
1130 }
1131 
1132 if (!empty($moreforfilter)) {
1133  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1134  print $moreforfilter;
1135  print '</div>';
1136 }
1137 
1138 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1139 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
1140 if ($massactionbutton) {
1141  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields
1142 }
1143 
1144 print '<div class="div-table-responsive">';
1145 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1146 
1147 // Fields title search
1148 // --------------------------------------------------------------------
1149 print '<tr class="liste_titre_filter">';
1150 // Action column
1151 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1152  print '<td class="liste_titre center maxwidthsearch">';
1153  $searchpicto = $form->showFilterButtons('left');
1154  print $searchpicto;
1155  print '</td>';
1156 }
1157 // Ref
1158 if (!empty($arrayfields['e.ref']['checked'])) {
1159  print '<td class="liste_titre">';
1160  print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
1161  print '</td>';
1162 }
1163 // Ref customer
1164 if (!empty($arrayfields['e.ref_customer']['checked'])) {
1165  print '<td class="liste_titre">';
1166  print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
1167  print '</td>';
1168 }
1169 // Thirdparty
1170 if (!empty($arrayfields['s.nom']['checked'])) {
1171  print '<td class="liste_titre left">';
1172  print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
1173  print '</td>';
1174 }
1175 // Town
1176 if (!empty($arrayfields['s.town']['checked'])) {
1177  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
1178 }
1179 // Zip
1180 if (!empty($arrayfields['s.zip']['checked'])) {
1181  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
1182 }
1183 // State
1184 if (!empty($arrayfields['state.nom']['checked'])) {
1185  print '<td class="liste_titre">';
1186  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1187  print '</td>';
1188 }
1189 // Country
1190 if (!empty($arrayfields['country.code_iso']['checked'])) {
1191  print '<td class="liste_titre center">';
1192  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1193  print '</td>';
1194 }
1195 // Company type
1196 if (!empty($arrayfields['typent.code']['checked'])) {
1197  print '<td class="liste_titre maxwidthonsmartphone center">';
1198  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC'), 'maxwidth75', 1);
1199  print '</td>';
1200 }
1201 // Weight
1202 if (!empty($arrayfields['e.weight']['checked'])) {
1203  print '<td class="liste_titre maxwidthonsmartphone center">';
1204 
1205  print '</td>';
1206 }
1207 // Date delivery planned
1208 if (!empty($arrayfields['e.date_delivery']['checked'])) {
1209  print '<td class="liste_titre center">';
1210  print '<div class="nowrapfordate">';
1211  print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1212  print '</div>';
1213  print '<div class="nowrapfordate">';
1214  print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1215  print '</div>';
1216  print '</td>';
1217 }
1218 if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1219  // Delivery method
1220  print '<td class="liste_titre center">';
1221  $shipment->fetch_delivery_methods();
1222  print $form->selectarray("search_shipping_method_ids[]", $shipment->meths, $search_shipping_method_ids, 1, 0, 0, 'multiple', 1, 0, 0, '', 'maxwidth150');
1223  print "</td>\n";
1224 }
1225 // Tracking number
1226 if (!empty($arrayfields['e.tracking_number']['checked'])) {
1227  print '<td class="liste_titre center">';
1228  print '<input class="flat" size="6" type="text" name="search_tracking" value="'.dol_escape_htmltag($search_tracking).'">';
1229  print '</td>';
1230 }
1231 if (!empty($arrayfields['l.ref']['checked'])) {
1232  // Delivery ref
1233  print '<td class="liste_titre">';
1234  print '<input class="flat width75" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
1235  print '</td>';
1236 }
1237 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1238  // Date received
1239  print '<td class="liste_titre center">';
1240  print '<div class="nowrapfordate">';
1241  print $form->selectDate($search_datereceipt_start ? $search_datereceipt_start : -1, 'search_datereceipt_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1242  print '</div>';
1243  print '<div class="nowrapfordate">';
1244  print $form->selectDate($search_datereceipt_end ? $search_datereceipt_end : -1, 'search_datereceipt_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1245  print '</div>';
1246  print '</td>';
1247 }
1248 // Note public
1249 if (!empty($arrayfields['e.note_public']['checked'])) {
1250  print '<td class="liste_titre">';
1251  print '</td>';
1252 }
1253 // Note private
1254 if (!empty($arrayfields['e.note_private']['checked'])) {
1255  print '<td class="liste_titre">';
1256  print '</td>';
1257 }
1258 // Extra fields
1259 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1260 
1261 // Fields from hook
1262 $parameters = array('arrayfields' => $arrayfields);
1263 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1264 print $hookmanager->resPrint;
1265 // Date creation
1266 if (!empty($arrayfields['e.datec']['checked'])) {
1267  print '<td class="liste_titre">';
1268  print '</td>';
1269 }
1270 // Date modification
1271 if (!empty($arrayfields['e.tms']['checked'])) {
1272  print '<td class="liste_titre">';
1273  print '</td>';
1274 }
1275 // Status
1276 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1277  print '<td class="liste_titre right parentonrightofpage">';
1278  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, '', 'search_status width100 onrightofpage');
1279  print '</td>';
1280 }
1281 // Status billed
1282 if (!empty($arrayfields['e.billed']['checked'])) {
1283  print '<td class="liste_titre maxwidthonsmartphone center">';
1284  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
1285  print '</td>';
1286 }
1287 // Action column
1288 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1289  print '<td class="liste_titre center maxwidthsearch">';
1290  $searchpicto = $form->showFilterButtons();
1291  print $searchpicto;
1292  print '</td>';
1293 }
1294 print '</tr>'."\n";
1295 
1296 $totalarray = array();
1297 $totalarray['nbfield'] = 0;
1298 
1299 // Fields title label
1300 // --------------------------------------------------------------------
1301 print '<tr class="liste_titre">';
1302 // Action column
1303 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1304  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1305  $totalarray['nbfield']++;
1306 }
1307 if (!empty($arrayfields['e.ref']['checked'])) {
1308  print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
1309  $totalarray['nbfield']++;
1310 }
1311 if (!empty($arrayfields['e.ref_customer']['checked'])) {
1312  print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);
1313  $totalarray['nbfield']++;
1314 }
1315 if (!empty($arrayfields['s.nom']['checked'])) {
1316  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
1317  $totalarray['nbfield']++;
1318 }
1319 if (!empty($arrayfields['s.town']['checked'])) {
1320  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1321  $totalarray['nbfield']++;
1322 }
1323 if (!empty($arrayfields['s.zip']['checked'])) {
1324  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1325  $totalarray['nbfield']++;
1326 }
1327 if (!empty($arrayfields['state.nom']['checked'])) {
1328  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1329  $totalarray['nbfield']++;
1330 }
1331 if (!empty($arrayfields['country.code_iso']['checked'])) {
1332  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1333  $totalarray['nbfield']++;
1334 }
1335 if (!empty($arrayfields['typent.code']['checked'])) {
1336  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1337  $totalarray['nbfield']++;
1338 }
1339 if (!empty($arrayfields['e.weight']['checked'])) {
1340  print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center ');
1341  $totalarray['nbfield']++;
1342 }
1343 if (!empty($arrayfields['e.date_delivery']['checked'])) {
1344  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1345  $totalarray['nbfield']++;
1346 }
1347 if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1348  print_liste_field_titre($arrayfields['e.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "e.fk_shipping_method", "", $param, '', $sortfield, $sortorder, 'center ');
1349  $totalarray['nbfield']++;
1350 }
1351 if (!empty($arrayfields['e.tracking_number']['checked'])) {
1352  print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center ');
1353  $totalarray['nbfield']++;
1354 }
1355 if (!empty($arrayfields['l.ref']['checked'])) {
1356  print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
1357  $totalarray['nbfield']++;
1358 }
1359 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1360  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1361  $totalarray['nbfield']++;
1362 }
1363 if (!empty($arrayfields['e.note_public']['checked'])) {
1364  print_liste_field_titre($arrayfields['e.note_public']['label'], $_SERVER["PHP_SELF"], "e.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
1365 }
1366 if (!empty($arrayfields['e.note_private']['checked'])) {
1367  print_liste_field_titre($arrayfields['e.note_private']['label'], $_SERVER["PHP_SELF"], "e.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
1368 }
1369 
1370 // Extra fields
1371 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1372 // Hook fields
1373 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, '$totalarray' => &$totalarray);
1374 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1375 print $hookmanager->resPrint;
1376 if (!empty($arrayfields['e.datec']['checked'])) {
1377  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1378  $totalarray['nbfield']++;
1379 }
1380 if (!empty($arrayfields['e.tms']['checked'])) {
1381  print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1382  $totalarray['nbfield']++;
1383 }
1384 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1385  print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1386  $totalarray['nbfield']++;
1387 }
1388 if (!empty($arrayfields['e.billed']['checked'])) {
1389  print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
1390  $totalarray['nbfield']++;
1391 }
1392 // Action column
1393 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1394  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1395  $totalarray['nbfield']++;
1396 }
1397 print "</tr>\n";
1398 
1399 $typenArray = $formcompany->typent_array(1);
1400 
1401 // Loop on record
1402 // --------------------------------------------------------------------
1403 $i = 0;
1404 $savnbfield = $totalarray['nbfield'];
1405 $totalarray = array();
1406 $totalarray['nbfield'] = 0;
1407 $imaxinloop = ($limit ? min($num, $limit) : $num);
1408 while ($i < $imaxinloop) {
1409  $obj = $db->fetch_object($resql);
1410  if (empty($obj)) {
1411  break; // Should not happen
1412  }
1413 
1414  $shipment->id = $obj->rowid;
1415  $shipment->ref = $obj->ref;
1416  $shipment->shipping_method_id = $obj->fk_shipping_method;
1417 
1418  $companystatic->id = $obj->socid;
1419  $companystatic->ref = $obj->name;
1420  $companystatic->name = $obj->name;
1421 
1422  $object = new Expedition($db);
1423  $object->fetch($obj->rowid);
1424 
1425  if ($mode == 'kanban') {
1426  if ($i == 0) {
1427  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1428  print '<div class="box-flex-container kanban">';
1429  }
1430  $object->date_delivery = $obj->delivery_date;
1431  $object->town = $obj->town;
1432 
1433  // Output Kanban
1434  $selected = -1;
1435  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1436  $selected = 0;
1437  if (in_array($object->id, $arrayofselected)) {
1438  $selected = 1;
1439  }
1440  }
1441  print $object->getKanbanView('', array('thirdparty' => $companystatic->getNomUrl(1), 'selected' => $selected));
1442  if ($i == min($num, $limit) - 1) {
1443  print '</div>';
1444  print '</td></tr>';
1445  }
1446  } else {
1447  print '<tr class="oddeven">';
1448 
1449  // Action column
1450  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1451  print '<td class="nowrap center">';
1452  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1453  $selected = 0;
1454  if (in_array($obj->rowid, $arrayofselected)) {
1455  $selected = 1;
1456  }
1457  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1458  }
1459  print '</td>';
1460  }
1461  // Ref
1462  if (!empty($arrayfields['e.ref']['checked'])) {
1463  print '<td class="nowraponall">';
1464  print $shipment->getNomUrl(1);
1465  print "</td>\n";
1466  if (!$i) {
1467  $totalarray['nbfield']++;
1468  }
1469  }
1470 
1471  // Ref customer
1472  if (!empty($arrayfields['e.ref_customer']['checked'])) {
1473  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->ref_customer).'">';
1474  print dol_escape_htmltag($obj->ref_customer);
1475  print "</td>\n";
1476  if (!$i) {
1477  $totalarray['nbfield']++;
1478  }
1479  }
1480 
1481  // Third party
1482  if (!empty($arrayfields['s.nom']['checked'])) {
1483  print '<td class="tdoverflowmax150">';
1484  print $companystatic->getNomUrl(1);
1485  print '</td>';
1486  if (!$i) {
1487  $totalarray['nbfield']++;
1488  }
1489  }
1490  // Town
1491  if (!empty($arrayfields['s.town']['checked'])) {
1492  print '<td class="nocellnopadd">';
1493  print dol_escape_htmltag($obj->town);
1494  print '</td>';
1495  if (!$i) {
1496  $totalarray['nbfield']++;
1497  }
1498  }
1499  // Zip
1500  if (!empty($arrayfields['s.zip']['checked'])) {
1501  print '<td class="nocellnopadd center">';
1502  print dol_escape_htmltag($obj->zip);
1503  print '</td>';
1504  if (!$i) {
1505  $totalarray['nbfield']++;
1506  }
1507  }
1508  // State
1509  if (!empty($arrayfields['state.nom']['checked'])) {
1510  print '<td class="center">'.$obj->state_name."</td>\n";
1511  if (!$i) {
1512  $totalarray['nbfield']++;
1513  }
1514  }
1515  // Country
1516  if (!empty($arrayfields['country.code_iso']['checked'])) {
1517  print '<td class="center">';
1518  $tmparray = getCountry($obj->fk_pays, 'all');
1519  print dol_escape_htmltag($tmparray['label']);
1520  print '</td>';
1521  if (!$i) {
1522  $totalarray['nbfield']++;
1523  }
1524  }
1525  // Type ent
1526  if (!empty($arrayfields['typent.code']['checked'])) {
1527  print '<td class="center">';
1528  if (isset($typenArray[$obj->typent_code])) {
1529  print $typenArray[$obj->typent_code];
1530  }
1531  print '</td>';
1532  if (!$i) {
1533  $totalarray['nbfield']++;
1534  }
1535  }
1536  // Weight
1537  if (!empty($arrayfields['e.weight']['checked'])) {
1538  print '<td class="center">';
1539  if (empty($object->trueWeight)) {
1540  $tmparray = $object->getTotalWeightVolume();
1541  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');
1542  print $form->textwithpicto('', $langs->trans('EstimatedWeight'), 1);
1543  } else {
1544  print $object->trueWeight;
1545  print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
1546  }
1547  print '</td>';
1548  if (!$i) {
1549  $totalarray['nbfield']++;
1550  }
1551  }
1552  // Date delivery planned
1553  if (!empty($arrayfields['e.date_delivery']['checked'])) {
1554  print '<td class="center nowraponall">';
1555  print dol_print_date($db->jdate($obj->delivery_date), "dayhour");
1556  print "</td>\n";
1557  if (!$i) {
1558  $totalarray['nbfield']++;
1559  }
1560  }
1561  if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1562  // Get code using getLabelFromKey
1563  $code = $langs->getLabelFromKey($db, $shipment->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
1564  print '<td class="center tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans("SendingMethod".strtoupper($code))).'">';
1565  if ($shipment->shipping_method_id > 0) {
1566  print $langs->trans("SendingMethod".strtoupper($code));
1567  }
1568  print '</td>';
1569  if (!$i) {
1570  $totalarray['nbfield']++;
1571  }
1572  }
1573  // Tracking number
1574  if (!empty($arrayfields['e.tracking_number']['checked'])) {
1575  $shipment->getUrlTrackingStatus($obj->tracking_number);
1576  print '<td class="center" title="'.dol_escape_htmltag($shipment->tracking_url).'">'.dol_escape_htmltag($shipment->tracking_url)."</td>\n";
1577  //print $form->editfieldval("TrackingNumber", 'tracking_number', $obj->tracking_url, $obj, $user->rights->expedition->creer, 'string', $obj->tracking_number);
1578  if (!$i) {
1579  $totalarray['nbfield']++;
1580  }
1581  }
1582 
1583  if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1584  $shipment->fetchObjectLinked($shipment->id, $shipment->element);
1585  $receiving = '';
1586  if (array_key_exists('delivery', $shipment->linkedObjects) && count($shipment->linkedObjects['delivery']) > 0) {
1587  $receiving = reset($shipment->linkedObjects['delivery']);
1588  }
1589 
1590  if (!empty($arrayfields['l.ref']['checked'])) {
1591  // Ref
1592  print '<td class="nowraponall">';
1593  print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1594  print '</td>';
1595  }
1596 
1597  if (!empty($arrayfields['l.date_delivery']['checked'])) {
1598  // Date received
1599  print '<td class="center nowraponall">';
1600  print dol_print_date($db->jdate($obj->date_reception), "day");
1601  print '</td>'."\n";
1602  }
1603  }
1604  // Note public
1605  if (!empty($arrayfields['e.note_public']['checked'])) {
1606  print '<td class="sensiblehtmlcontent center">';
1607  print dolPrintHTML($obj->note_public);
1608  print '</td>';
1609  if (!$i) {
1610  $totalarray['nbfield']++;
1611  }
1612  }
1613  // Note private
1614  if (!empty($arrayfields['e.note_private']['checked'])) {
1615  print '<td class="sensiblehtmlcontent center">';
1616  print dolPrintHTML($obj->note_private);
1617  print '</td>';
1618  if (!$i) {
1619  $totalarray['nbfield']++;
1620  }
1621  }
1622  // Extra fields
1623  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1624  // Fields from hook
1625  $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1626  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1627  print $hookmanager->resPrint;
1628  // Date creation
1629  if (!empty($arrayfields['e.datec']['checked'])) {
1630  print '<td class="center nowraponall">';
1631  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');
1632  print '</td>';
1633  if (!$i) {
1634  $totalarray['nbfield']++;
1635  }
1636  }
1637  // Date modification
1638  if (!empty($arrayfields['e.tms']['checked'])) {
1639  print '<td class="center nowraponall">';
1640  print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1641  print '</td>';
1642  if (!$i) {
1643  $totalarray['nbfield']++;
1644  }
1645  }
1646  // Status
1647  if (!empty($arrayfields['e.fk_statut']['checked'])) {
1648  print '<td class="right nowrap">'.$shipment->LibStatut($obj->fk_statut, 5).'</td>';
1649  if (!$i) {
1650  $totalarray['nbfield']++;
1651  }
1652  }
1653  // Billed
1654  if (!empty($arrayfields['e.billed']['checked'])) {
1655  print '<td class="center">'.yn($obj->billed).'</td>';
1656  if (!$i) {
1657  $totalarray['nbfield']++;
1658  }
1659  }
1660 
1661  // Action column
1662  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1663  print '<td class="nowrap center">';
1664  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1665  $selected = 0;
1666  if (in_array($obj->rowid, $arrayofselected)) {
1667  $selected = 1;
1668  }
1669  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1670  }
1671  print '</td>';
1672  }
1673  if (!$i) {
1674  $totalarray['nbfield']++;
1675  }
1676 
1677  print "</tr>\n";
1678  }
1679  $i++;
1680 }
1681 
1682 // If no record found
1683 if ($num == 0) {
1684  $colspan = 1;
1685  foreach ($arrayfields as $key => $val) {
1686  if (!empty($val['checked'])) {
1687  $colspan++;
1688  }
1689  }
1690  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1691 }
1692 
1693 $db->free($resql);
1694 
1695 $parameters = array('arrayfields' => $arrayfields, 'totalarray' => $totalarray, 'sql' => $sql);
1696 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1697 print $hookmanager->resPrint;
1698 
1699 print "</table>";
1700 print "</div>";
1701 print '</form>';
1702 
1703 $hidegeneratedfilelistifempty = 1;
1704 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1705  $hidegeneratedfilelistifempty = 0;
1706 }
1707 
1708 // Show list of available documents
1709 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1710 $urlsource .= str_replace('&amp;', '&', $param);
1711 
1712 $filedir = $diroutputmassaction;
1713 $genallowed = $user->hasRight('expedition', 'lire');
1714 $delallowed = $user->hasRight('expedition', 'creer');
1715 $title = '';
1716 
1717 print $formfile->showdocuments('massfilesarea_sendings', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1718 
1719 // End of page
1720 llxFooter();
1721 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage customers orders.
Class to manage absolute discounts.
Class to manage shipments.
Class to manage standard extra fields.
Class to manage invoices.
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.
Class 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=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
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...
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
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.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.