list.php 48 KB

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