dolibarr 20.0.0
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
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
42require_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', 'orders'));
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");
84if (!$sortfield) {
85 $sortfield = "e.ref";
86}
87if (!$sortorder) {
88 $sortorder = "DESC";
89}
90if (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);
121if (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
150include 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');
158if ($user->socid) {
159 $socid = $user->socid;
160}
161$result = restrictedArea($user, 'expedition', $expeditionid, '');
162
163
164
165/*
166 * Actions
167 */
168$error = 0;
169
170if (GETPOST('cancel', 'alpha')) {
171 $action = 'list';
172 $massaction = '';
173}
174if (!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
180if ($reshook < 0) {
181 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
182}
183
184include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
185
186// Purge search criteria
187if (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
215if (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_customer = $expd->ref_customer;
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_type = '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").': '.$expdCmdSrc->ref. ' - '. $langs->trans("Shipment").': '.$expd->ref.($expd->date_shipping ? ' - '.dol_print_date($expd->date_shipping, '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->socid = $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$title = $langs->trans('ListOfSendings');
645$help_url = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
646
647llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist');
648
649$sql = 'SELECT';
650if ($search_all || $search_user > 0) {
651 $sql = 'SELECT DISTINCT';
652}
653$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,";
654if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
655 // Link for delivery fields ref and date. Does not duplicate the line because we should always have only 1 link or 0 per shipment
656 $sql .= " l.date_delivery as date_reception,";
657}
658$sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ";
659$sql .= " typent.code as typent_code,";
660$sql .= " state.code_departement as state_code, state.nom as state_name,";
661$sql .= " e.date_creation as date_creation, e.tms as date_modification,e.note_public, e.note_private,";
662$sql .= " u.login";
663// Add fields from extrafields
664if (!empty($extrafields->attributes[$object->table_element]['label'])) {
665 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
666 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
667 }
668}
669// Add fields from hooks
670$parameters = array();
671$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
672$sql .= $hookmanager->resPrint;
673
674$sqlfields = $sql; // $sql fields to remove for count total
675
676$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
677if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
678 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
679}
680if ($search_all) {
681 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition';
682}
683$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
684$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
685$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
686$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
687if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
688 // Link for delivery fields ref and date. Does not duplicate the line because we should always have only 1 link or 0 per shipment
689 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
690 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
691}
692$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user_author = u.rowid';
693if ($search_user > 0) { // Get link to order to get the order id in eesource.fk_source
694 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'";
695}
696if ($search_user > 0) {
697 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
698 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
699}
700
701// Add table from hooks
702$parameters = array();
703$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
704$sql .= $hookmanager->resPrint;
705
706$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
707
708if ($socid > 0) {
709 $sql .= " AND s.rowid = ".((int) $socid);
710}
711if ($socid) {
712 $sql .= " AND e.fk_soc = ".((int) $socid);
713}
714if ($search_status != '' && $search_status >= 0) {
715 $sql .= " AND e.fk_statut = ".((int) $search_status);
716}
717if ($search_ref_customer != '') {
718 $sql .= natural_search('e.ref_customer', $search_ref_customer);
719}
720if ($search_billed != '' && $search_billed >= 0) {
721 $sql .= ' AND e.billed = '.((int) $search_billed);
722}
723if ($search_town) {
724 $sql .= natural_search('s.town', $search_town);
725}
726if ($search_zip) {
727 $sql .= natural_search("s.zip", $search_zip);
728}
729if ($search_state) {
730 $sql .= natural_search("state.nom", $search_state);
731}
732if ($search_country) {
733 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
734}
735if (!empty($search_shipping_method_ids)) {
736 $sql .= " AND e.fk_shipping_method IN (".$db->sanitize(implode(',', $search_shipping_method_ids)).')';
737}
738if ($search_tracking) {
739 $sql .= natural_search("e.tracking_number", $search_tracking);
740}
741if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
742 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
743}
744if ($search_user > 0) {
745 // The contact on a shipment is also the contact of the order.
746 $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);
747}
748if ($search_company) {
749 $sql .= natural_search('s.nom', $search_company);
750}
751if ($search_ref_exp) {
752 $sql .= natural_search('e.ref', $search_ref_exp);
753}
754if ($search_datedelivery_start) {
755 $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'";
756}
757if ($search_datedelivery_end) {
758 $sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'";
759}
760if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
761 if ($search_ref_liv) {
762 $sql .= natural_search('l.ref', $search_ref_liv);
763 }
764 if ($search_datereceipt_start) {
765 $sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'";
766 }
767 if ($search_datereceipt_end) {
768 $sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'";
769 }
770}
771if ($search_all) {
772 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
773}
774// Search on sale representative
775if ($search_sale && $search_sale != '-1') {
776 if ($search_sale == -2) {
777 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc)";
778 } elseif ($search_sale > 0) {
779 $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).")";
780 }
781}
782// Search for tag/category ($searchCategoryCustomerList is an array of ID)
783$searchCategoryCustomerOperator = -1;
784$searchCategoryCustomerList = array($search_categ_cus);
785if (!empty($searchCategoryCustomerList)) {
786 $searchCategoryCustomerSqlList = array();
787 $listofcategoryid = '';
788 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
789 if (intval($searchCategoryCustomer) == -2) {
790 $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";
791 } elseif (intval($searchCategoryCustomer) > 0) {
792 if ($searchCategoryCustomerOperator == 0) {
793 $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).")";
794 } else {
795 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
796 }
797 }
798 }
799 if ($listofcategoryid) {
800 $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)."))";
801 }
802 if ($searchCategoryCustomerOperator == 1) {
803 if (!empty($searchCategoryCustomerSqlList)) {
804 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
805 }
806 } else {
807 if (!empty($searchCategoryCustomerSqlList)) {
808 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
809 }
810 }
811}
812// Search for tag/category ($searchCategoryProductList is an array of ID)
813$searchCategoryProductOperator = -1;
814$searchCategoryProductList = array($search_product_category);
815if (!empty($searchCategoryProductList)) {
816 $searchCategoryProductSqlList = array();
817 $listofcategoryid = '';
818 foreach ($searchCategoryProductList as $searchCategoryProduct) {
819 if (intval($searchCategoryProduct) == -2) {
820 $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)";
821 } elseif (intval($searchCategoryProduct) > 0) {
822 if ($searchCategoryProductOperator == 0) {
823 $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).")";
824 } else {
825 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
826 }
827 }
828 }
829 if ($listofcategoryid) {
830 $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)."))";
831 }
832 if ($searchCategoryProductOperator == 1) {
833 if (!empty($searchCategoryProductSqlList)) {
834 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
835 }
836 } else {
837 if (!empty($searchCategoryProductSqlList)) {
838 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
839 }
840 }
841}
842// Add where from extra fields
843include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
844
845// Add where from hooks
846$parameters = array();
847$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
848$sql .= $hookmanager->resPrint;
849
850// Add HAVING from hooks
851$parameters = array();
852$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
853$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
854
855$nbtotalofrecords = '';
856if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
857 /* The fast and low memory method to get and count full list converts the sql into a sql count */
858 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
859 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
860 $resql = $db->query($sqlforcount);
861 if ($resql) {
862 $objforcount = $db->fetch_object($resql);
863 $nbtotalofrecords = $objforcount->nbtotalofrecords;
864 } else {
865 dol_print_error($db);
866 }
867
868 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
869 $page = 0;
870 $offset = 0;
871 }
872 $db->free($resql);
873}
874
875// Complete request and execute it with limit
876$sql .= $db->order($sortfield, $sortorder);
877if ($limit) {
878 $sql .= $db->plimit($limit + 1, $offset);
879}
880
881//print $sql;
882$resql = $db->query($sql);
883if (!$resql) {
884 dol_print_error($db);
885 exit;
886}
887
888$num = $db->num_rows($resql);
889
890$arrayofselected = is_array($toselect) ? $toselect : array();
891
892$expedition = new Expedition($db);
893
894if ($socid > 0) {
895 $soc = new Societe($db);
896 $soc->fetch($socid);
897 if (empty($search_company)) {
898 $search_company = $soc->name;
899 }
900}
901
902$param = '';
903if ($socid > 0) {
904 $param .= '&socid='.urlencode((string) ($socid));
905}
906if (!empty($mode)) {
907 $param .= '&mode='.urlencode($mode);
908}
909if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
910 $param .= '&contextpage='.urlencode($contextpage);
911}
912if ($limit > 0 && $limit != $conf->liste_limit) {
913 $param .= '&limit='.((int) $limit);
914}
915if ($search_all) {
916 $param .= "&search_all=".urlencode($search_all);
917}
918if ($search_ref_exp) {
919 $param .= "&search_ref_exp=".urlencode($search_ref_exp);
920}
921if ($search_ref_liv) {
922 $param .= "&search_ref_liv=".urlencode($search_ref_liv);
923}
924if ($search_ref_customer) {
925 $param .= "&search_ref_customer=".urlencode($search_ref_customer);
926}
927if ($search_user > 0) {
928 $param .= '&search_user='.urlencode((string) ($search_user));
929}
930if ($search_sale > 0) {
931 $param .= '&search_sale='.urlencode((string) ($search_sale));
932}
933if ($search_company) {
934 $param .= "&search_company=".urlencode($search_company);
935}
936if ($search_shipping_method_ids) {
937 foreach ($search_shipping_method_ids as $value) {
938 $param .= "&amp;search_shipping_method_ids[]=".urlencode($value);
939 }
940}
941if ($search_tracking) {
942 $param .= "&search_tracking=".urlencode($search_tracking);
943}
944if ($search_town) {
945 $param .= '&search_town='.urlencode($search_town);
946}
947if ($search_zip) {
948 $param .= '&search_zip='.urlencode($search_zip);
949}
950if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
951 $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
952}
953if ($search_datedelivery_start) {
954 $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'));
955}
956if ($search_datedelivery_end) {
957 $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'));
958}
959if ($search_datereceipt_start) {
960 $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'));
961}
962if ($search_datereceipt_end) {
963 $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'));
964}
965if ($search_product_category != '') {
966 $param .= '&search_product_category='.urlencode((string) ($search_product_category));
967}
968if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
969 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
970}
971if ($search_status != '') {
972 $param .= '&search_status='.urlencode($search_status);
973}
974if ($optioncss != '') {
975 $param .= '&optioncss='.urlencode($optioncss);
976}
977// Add $param from extra fields
978include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
979
980// Add $param from hooks
981$parameters = array('param' => &$param);
982$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
983$param .= $hookmanager->resPrint;
984
985$arrayofmassactions = array(
986 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
987 'classifyclose' => img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("Close"),
988 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
989);
990if ($user->hasRight('facture', 'creer')) {
991 $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomerFromSendings");
992}
993if (in_array($massaction, array('presend', 'createbills'))) {
994 $arrayofmassactions = array();
995}
996$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
997
998// Currently: a sending can't create from sending list
999// $url = DOL_URL_ROOT.'/expedition/card.php?action=create';
1000// if (!empty($socid)) $url .= '&socid='.$socid;
1001// $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);
1002$newcardbutton = '';
1003$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'));
1004$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'));
1005$newcardbutton .= dolGetButtonTitleSeparator();
1006$newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2', '', $user->hasRight('expedition', 'creer'));
1007
1008$i = 0;
1009print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1010if ($optioncss != '') {
1011 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1012}
1013print '<input type="hidden" name="token" value="'.newToken().'">';
1014print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1015print '<input type="hidden" name="action" value="list">';
1016print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1017print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1018print '<input type="hidden" name="socid" value="'.$socid.'">';
1019print '<input type="hidden" name="mode" value="'.$mode.'">';
1020
1021// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1022print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dolly', 0, $newcardbutton, '', $limit, 0, 0, 1);
1023
1024$topicmail = "SendShippingRef";
1025$modelmail = "shipping_send";
1026$objecttmp = new Expedition($db);
1027$trackid = 'shi'.$object->id;
1028include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1029
1030if ($massaction == 'createbills') {
1031 print '<input type="hidden" name="massaction" value="confirm_createbills">';
1032
1033 print '<table class="noborder" width="100%" >';
1034 print '<tr>';
1035 print '<td class="titlefield">';
1036 print $langs->trans('DateInvoice');
1037 print '</td>';
1038 print '<td>';
1039 print $form->selectDate('', '', '', '', '', '', 1, 1);
1040 print '</td>';
1041 print '</tr>';
1042 print '<tr>';
1043 print '<td>';
1044 print $langs->trans('CreateOneBillByThird');
1045 print '</td>';
1046 print '<td>';
1047 print $form->selectyesno('createbills_onebythird', '', 1);
1048 print '</td>';
1049 print '</tr>';
1050 print '<tr>';
1051 print '<td>';
1052 print $langs->trans('ValidateInvoices');
1053 print '</td>';
1054 print '<td>';
1055 if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
1056 print $form->selectyesno('validate_invoices', 0, 1, 1);
1057 $langs->load("errors");
1058 print ' ('.$langs->trans("WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal").')';
1059 } else {
1060 print $form->selectyesno('validate_invoices', 0, 1);
1061 }
1062 if (!empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) {
1063 print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoSendingStayUnbilled").'</span>';
1064 } else {
1065 print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetSendingBilledNotEnabled").'</span>';
1066 }
1067 print '</td>';
1068 print '</tr>';
1069 print '</table>';
1070
1071 print '<br>';
1072 print '<div class="center">';
1073 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomerFromSendings').'"> ';
1074 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1075 print '</div>';
1076 print '<br>';
1077}
1078
1079if ($search_all) {
1080 foreach ($fieldstosearchall as $key => $val) {
1081 $fieldstosearchall[$key] = $langs->trans($val);
1082 }
1083 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1084}
1085
1086$moreforfilter = '';
1087
1088// If the user can view prospects other than his'
1089if ($user->hasRight('user', 'user', 'lire')) {
1090 $langs->load("commercial");
1091 $moreforfilter .= '<div class="divsearchfield">';
1092 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1093 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
1094 $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
1095 $moreforfilter .= '</div>';
1096}
1097// If the user can view other users
1098if ($user->hasRight('user', 'user', 'lire')) {
1099 $moreforfilter .= '<div class="divsearchfield">';
1100 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1101 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
1102 $moreforfilter .= $form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
1103 $moreforfilter .= '</div>';
1104}
1105// If the user can view prospects other than his'
1106if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1107 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1108 $moreforfilter .= '<div class="divsearchfield">';
1109 $tmptitle = $langs->trans('IncludingProductWithTag');
1110 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1111 //$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1112 //$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
1113 $moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'search_product_category', 1, $tmptitle);
1114
1115 $moreforfilter .= '</div>';
1116}
1117if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1118 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1119 $moreforfilter .= '<div class="divsearchfield">';
1120 $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1121 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1122 $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
1123 $moreforfilter .= '</div>';
1124}
1125$parameters = array();
1126$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1127if (empty($reshook)) {
1128 $moreforfilter .= $hookmanager->resPrint;
1129} else {
1130 $moreforfilter = $hookmanager->resPrint;
1131}
1132
1133if (!empty($moreforfilter)) {
1134 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1135 print $moreforfilter;
1136 print '</div>';
1137}
1138
1139$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1140$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
1141if ($massactionbutton) {
1142 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields
1143}
1144
1145print '<div class="div-table-responsive">';
1146print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1147
1148// Fields title search
1149// --------------------------------------------------------------------
1150print '<tr class="liste_titre_filter">';
1151// Action column
1152if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1153 print '<td class="liste_titre center maxwidthsearch">';
1154 $searchpicto = $form->showFilterButtons('left');
1155 print $searchpicto;
1156 print '</td>';
1157}
1158// Ref
1159if (!empty($arrayfields['e.ref']['checked'])) {
1160 print '<td class="liste_titre">';
1161 print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
1162 print '</td>';
1163}
1164// Ref customer
1165if (!empty($arrayfields['e.ref_customer']['checked'])) {
1166 print '<td class="liste_titre">';
1167 print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
1168 print '</td>';
1169}
1170// Thirdparty
1171if (!empty($arrayfields['s.nom']['checked'])) {
1172 print '<td class="liste_titre left">';
1173 print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
1174 print '</td>';
1175}
1176// Town
1177if (!empty($arrayfields['s.town']['checked'])) {
1178 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
1179}
1180// Zip
1181if (!empty($arrayfields['s.zip']['checked'])) {
1182 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
1183}
1184// State
1185if (!empty($arrayfields['state.nom']['checked'])) {
1186 print '<td class="liste_titre">';
1187 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1188 print '</td>';
1189}
1190// Country
1191if (!empty($arrayfields['country.code_iso']['checked'])) {
1192 print '<td class="liste_titre center">';
1193 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1194 print '</td>';
1195}
1196// Company type
1197if (!empty($arrayfields['typent.code']['checked'])) {
1198 print '<td class="liste_titre maxwidthonsmartphone center">';
1199 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);
1200 print '</td>';
1201}
1202// Weight
1203if (!empty($arrayfields['e.weight']['checked'])) {
1204 print '<td class="liste_titre maxwidthonsmartphone center">';
1205
1206 print '</td>';
1207}
1208// Date delivery planned
1209if (!empty($arrayfields['e.date_delivery']['checked'])) {
1210 print '<td class="liste_titre center">';
1211 print '<div class="nowrapfordate">';
1212 print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1213 print '</div>';
1214 print '<div class="nowrapfordate">';
1215 print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1216 print '</div>';
1217 print '</td>';
1218}
1219if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1220 // Delivery method
1221 print '<td class="liste_titre center">';
1222 $shipment->fetch_delivery_methods();
1223 print $form->selectarray("search_shipping_method_ids[]", $shipment->meths, $search_shipping_method_ids, 1, 0, 0, 'multiple', 1, 0, 0, '', 'maxwidth150');
1224 print "</td>\n";
1225}
1226// Tracking number
1227if (!empty($arrayfields['e.tracking_number']['checked'])) {
1228 print '<td class="liste_titre center">';
1229 print '<input class="flat" size="6" type="text" name="search_tracking" value="'.dol_escape_htmltag($search_tracking).'">';
1230 print '</td>';
1231}
1232if (!empty($arrayfields['l.ref']['checked'])) {
1233 // Delivery ref
1234 print '<td class="liste_titre">';
1235 print '<input class="flat width75" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';
1236 print '</td>';
1237}
1238if (!empty($arrayfields['l.date_delivery']['checked'])) {
1239 // Date received
1240 print '<td class="liste_titre center">';
1241 print '<div class="nowrapfordate">';
1242 print $form->selectDate($search_datereceipt_start ? $search_datereceipt_start : -1, 'search_datereceipt_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1243 print '</div>';
1244 print '<div class="nowrapfordate">';
1245 print $form->selectDate($search_datereceipt_end ? $search_datereceipt_end : -1, 'search_datereceipt_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1246 print '</div>';
1247 print '</td>';
1248}
1249// Note public
1250if (!empty($arrayfields['e.note_public']['checked'])) {
1251 print '<td class="liste_titre">';
1252 print '</td>';
1253}
1254// Note private
1255if (!empty($arrayfields['e.note_private']['checked'])) {
1256 print '<td class="liste_titre">';
1257 print '</td>';
1258}
1259// Extra fields
1260include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1261
1262// Fields from hook
1263$parameters = array('arrayfields' => $arrayfields);
1264$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1265print $hookmanager->resPrint;
1266// Date creation
1267if (!empty($arrayfields['e.datec']['checked'])) {
1268 print '<td class="liste_titre">';
1269 print '</td>';
1270}
1271// Date modification
1272if (!empty($arrayfields['e.tms']['checked'])) {
1273 print '<td class="liste_titre">';
1274 print '</td>';
1275}
1276// Status
1277if (!empty($arrayfields['e.fk_statut']['checked'])) {
1278 print '<td class="liste_titre right parentonrightofpage">';
1279 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');
1280 print '</td>';
1281}
1282// Status billed
1283if (!empty($arrayfields['e.billed']['checked'])) {
1284 print '<td class="liste_titre maxwidthonsmartphone center">';
1285 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
1286 print '</td>';
1287}
1288// Action column
1289if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1290 print '<td class="liste_titre center maxwidthsearch">';
1291 $searchpicto = $form->showFilterButtons();
1292 print $searchpicto;
1293 print '</td>';
1294}
1295print '</tr>'."\n";
1296
1297$totalarray = array();
1298$totalarray['nbfield'] = 0;
1299
1300// Fields title label
1301// --------------------------------------------------------------------
1302print '<tr class="liste_titre">';
1303// Action column
1304if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1305 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1306 $totalarray['nbfield']++;
1307}
1308if (!empty($arrayfields['e.ref']['checked'])) {
1309 print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
1310 $totalarray['nbfield']++;
1311}
1312if (!empty($arrayfields['e.ref_customer']['checked'])) {
1313 print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);
1314 $totalarray['nbfield']++;
1315}
1316if (!empty($arrayfields['s.nom']['checked'])) {
1317 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
1318 $totalarray['nbfield']++;
1319}
1320if (!empty($arrayfields['s.town']['checked'])) {
1321 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1322 $totalarray['nbfield']++;
1323}
1324if (!empty($arrayfields['s.zip']['checked'])) {
1325 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1326 $totalarray['nbfield']++;
1327}
1328if (!empty($arrayfields['state.nom']['checked'])) {
1329 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1330 $totalarray['nbfield']++;
1331}
1332if (!empty($arrayfields['country.code_iso']['checked'])) {
1333 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1334 $totalarray['nbfield']++;
1335}
1336if (!empty($arrayfields['typent.code']['checked'])) {
1337 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1338 $totalarray['nbfield']++;
1339}
1340if (!empty($arrayfields['e.weight']['checked'])) {
1341 print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center ');
1342 $totalarray['nbfield']++;
1343}
1344if (!empty($arrayfields['e.date_delivery']['checked'])) {
1345 print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1346 $totalarray['nbfield']++;
1347}
1348if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {
1349 print_liste_field_titre($arrayfields['e.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "e.fk_shipping_method", "", $param, '', $sortfield, $sortorder, 'center ');
1350 $totalarray['nbfield']++;
1351}
1352if (!empty($arrayfields['e.tracking_number']['checked'])) {
1353 print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center ');
1354 $totalarray['nbfield']++;
1355}
1356if (!empty($arrayfields['l.ref']['checked'])) {
1357 print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
1358 $totalarray['nbfield']++;
1359}
1360if (!empty($arrayfields['l.date_delivery']['checked'])) {
1361 print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
1362 $totalarray['nbfield']++;
1363}
1364if (!empty($arrayfields['e.note_public']['checked'])) {
1365 print_liste_field_titre($arrayfields['e.note_public']['label'], $_SERVER["PHP_SELF"], "e.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
1366}
1367if (!empty($arrayfields['e.note_private']['checked'])) {
1368 print_liste_field_titre($arrayfields['e.note_private']['label'], $_SERVER["PHP_SELF"], "e.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
1369}
1370
1371// Extra fields
1372include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1373// Hook fields
1374$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, '$totalarray' => &$totalarray);
1375$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1376print $hookmanager->resPrint;
1377if (!empty($arrayfields['e.datec']['checked'])) {
1378 print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1379 $totalarray['nbfield']++;
1380}
1381if (!empty($arrayfields['e.tms']['checked'])) {
1382 print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1383 $totalarray['nbfield']++;
1384}
1385if (!empty($arrayfields['e.fk_statut']['checked'])) {
1386 print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1387 $totalarray['nbfield']++;
1388}
1389if (!empty($arrayfields['e.billed']['checked'])) {
1390 print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
1391 $totalarray['nbfield']++;
1392}
1393// Action column
1394if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1395 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1396 $totalarray['nbfield']++;
1397}
1398print "</tr>\n";
1399
1400$typenArray = $formcompany->typent_array(1);
1401
1402// Loop on record
1403// --------------------------------------------------------------------
1404$i = 0;
1405$savnbfield = $totalarray['nbfield'];
1406$totalarray = array();
1407$totalarray['nbfield'] = 0;
1408$imaxinloop = ($limit ? min($num, $limit) : $num);
1409while ($i < $imaxinloop) {
1410 $obj = $db->fetch_object($resql);
1411 if (empty($obj)) {
1412 break; // Should not happen
1413 }
1414
1415 $companystatic->id = $obj->socid;
1416 $companystatic->ref = $obj->name;
1417 $companystatic->name = $obj->name;
1418
1419 $object = new Expedition($db);
1420 $object->fetch($obj->rowid);
1421
1422 if ($mode == 'kanban') {
1423 if ($i == 0) {
1424 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1425 print '<div class="box-flex-container kanban">';
1426 }
1427 $object->date_delivery = $obj->delivery_date;
1428 $object->town = $obj->town;
1429
1430 // Output Kanban
1431 $selected = -1;
1432 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1433 $selected = 0;
1434 if (in_array($object->id, $arrayofselected)) {
1435 $selected = 1;
1436 }
1437 }
1438 print $object->getKanbanView('', array('thirdparty' => $companystatic->getNomUrl(1), 'selected' => $selected));
1439 if ($i == min($num, $limit) - 1) {
1440 print '</div>';
1441 print '</td></tr>';
1442 }
1443 } else {
1444 print '<tr class="oddeven">';
1445
1446 // Action column
1447 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1448 print '<td class="nowrap center">';
1449 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1450 $selected = 0;
1451 if (in_array($obj->rowid, $arrayofselected)) {
1452 $selected = 1;
1453 }
1454 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1455 }
1456 print '</td>';
1457 }
1458 // Ref
1459 if (!empty($arrayfields['e.ref']['checked'])) {
1460 print '<td class="nowraponall">';
1461 print $object->getNomUrl(1);
1462 $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, '');
1463 $filename = dol_sanitizeFileName($object->ref);
1464 print $formfile->getDocumentsLink('expedition', $filename, $filedir);
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, $object->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 ($object->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 $object->getUrlTrackingStatus($obj->tracking_number);
1576 print '<td class="center" title="'.dol_escape_htmltag($object->tracking_url).'">'.$object->tracking_url."</td>\n";
1577 if (!$i) {
1578 $totalarray['nbfield']++;
1579 }
1580 }
1581
1582 if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
1583 $object->fetchObjectLinked();
1584 $receiving = '';
1585 if (array_key_exists('delivery', $object->linkedObjects) && count($object->linkedObjects['delivery']) > 0) {
1586 $receiving = reset($object->linkedObjects['delivery']);
1587 }
1588
1589 if (!empty($arrayfields['l.ref']['checked'])) {
1590 // Ref
1591 print '<td class="nowraponall">';
1592 print !empty($receiving) ? $receiving->getNomUrl($db) : '';
1593 print '</td>';
1594 }
1595
1596 if (!empty($arrayfields['l.date_delivery']['checked'])) {
1597 // Date received
1598 print '<td class="center nowraponall">';
1599 print dol_print_date($db->jdate($obj->date_reception), "day");
1600 print '</td>'."\n";
1601 }
1602 }
1603 // Note public
1604 if (!empty($arrayfields['e.note_public']['checked'])) {
1605 print '<td class="sensiblehtmlcontent center">';
1606 print dolPrintHTML($obj->note_public);
1607 print '</td>';
1608 if (!$i) {
1609 $totalarray['nbfield']++;
1610 }
1611 }
1612 // Note private
1613 if (!empty($arrayfields['e.note_private']['checked'])) {
1614 print '<td class="sensiblehtmlcontent center">';
1615 print dolPrintHTML($obj->note_private);
1616 print '</td>';
1617 if (!$i) {
1618 $totalarray['nbfield']++;
1619 }
1620 }
1621 // Extra fields
1622 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1623 // Fields from hook
1624 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1625 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1626 print $hookmanager->resPrint;
1627 // Date creation
1628 if (!empty($arrayfields['e.datec']['checked'])) {
1629 print '<td class="center nowraponall">';
1630 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');
1631 print '</td>';
1632 if (!$i) {
1633 $totalarray['nbfield']++;
1634 }
1635 }
1636 // Date modification
1637 if (!empty($arrayfields['e.tms']['checked'])) {
1638 print '<td class="center nowraponall">';
1639 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1640 print '</td>';
1641 if (!$i) {
1642 $totalarray['nbfield']++;
1643 }
1644 }
1645 // Status
1646 if (!empty($arrayfields['e.fk_statut']['checked'])) {
1647 print '<td class="right nowrap">'.$object->getLibStatut(5).'</td>';
1648 if (!$i) {
1649 $totalarray['nbfield']++;
1650 }
1651 }
1652 // Billed
1653 if (!empty($arrayfields['e.billed']['checked'])) {
1654 print '<td class="center">'.yn($obj->billed).'</td>';
1655 if (!$i) {
1656 $totalarray['nbfield']++;
1657 }
1658 }
1659
1660 // Action column
1661 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1662 print '<td class="nowrap center">';
1663 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1664 $selected = 0;
1665 if (in_array($obj->rowid, $arrayofselected)) {
1666 $selected = 1;
1667 }
1668 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1669 }
1670 print '</td>';
1671 }
1672 if (!$i) {
1673 $totalarray['nbfield']++;
1674 }
1675
1676 print "</tr>\n";
1677 }
1678 $i++;
1679}
1680
1681// If no record found
1682if ($num == 0) {
1683 $colspan = 1;
1684 foreach ($arrayfields as $key => $val) {
1685 if (!empty($val['checked'])) {
1686 $colspan++;
1687 }
1688 }
1689 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1690}
1691
1692$db->free($resql);
1693
1694$parameters = array('arrayfields' => $arrayfields, 'totalarray' => $totalarray, 'sql' => $sql);
1695$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1696print $hookmanager->resPrint;
1697
1698print "</table>";
1699print "</div>";
1700print '</form>';
1701
1702$hidegeneratedfilelistifempty = 1;
1703if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1704 $hidegeneratedfilelistifempty = 0;
1705}
1706
1707// Show list of available documents
1708$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1709$urlsource .= str_replace('&amp;', '&', $param);
1710
1711$filedir = $diroutputmassaction;
1712$genallowed = $user->hasRight('expedition', 'lire');
1713$delallowed = $user->hasRight('expedition', 'creer');
1714$title = '';
1715
1716print $formfile->showdocuments('massfilesarea_sendings', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1717
1718// End of page
1719llxFooter();
1720$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.
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...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.