list.php 43 KB

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