list.php 41 KB

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