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