list.php 47 KB

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