list.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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-2018 Ferran Marcet <fmarcet@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/expedition/list.php
  22. * \ingroup expedition
  23. * \brief Page to list all shipments
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("sendings","deliveries",'companies','bills'));
  32. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'shipmentlist'; // To manage different context of search
  33. $socid=GETPOST('socid','int');
  34. // Security check
  35. $expeditionid = GETPOST('id','int');
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result = restrictedArea($user, 'expedition',$expeditionid,'');
  38. $diroutputmassaction=$conf->expedition->dir_output . '/temp/massgeneration/'.$user->id;
  39. $search_ref_exp = GETPOST("search_ref_exp", 'alpha');
  40. $search_ref_liv = GETPOST('search_ref_liv', 'alpha');
  41. $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
  42. $search_company = GETPOST("search_company", 'alpha');
  43. $search_town=GETPOST('search_town','alpha');
  44. $search_zip=GETPOST('search_zip','alpha');
  45. $search_state=trim(GETPOST("search_state"));
  46. $search_country=GETPOST("search_country",'int');
  47. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  48. $search_billed=GETPOST("search_billed",'int');
  49. $sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
  50. $optioncss = GETPOST('optioncss','alpha');
  51. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  52. $sortfield = GETPOST('sortfield','alpha');
  53. $sortorder = GETPOST('sortorder','alpha');
  54. $page = GETPOST('page','int');
  55. if (! $sortfield) $sortfield="e.ref";
  56. if (! $sortorder) $sortorder="DESC";
  57. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. $viewstatut=GETPOST('viewstatut');
  62. $object = new Expedition($db);
  63. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  64. $hookmanager->initHooks(array('shipmentlist'));
  65. $extrafields = new ExtraFields($db);
  66. // fetch optionals attributes and labels
  67. $extralabels = $extrafields->fetch_name_optionals_label('expedition');
  68. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  69. // List of fields to search into when doing a "search in all"
  70. $fieldstosearchall = array(
  71. 'e.ref'=>"Ref",
  72. 's.nom'=>"ThirdParty",
  73. 'e.note_public'=>'NotePublic',
  74. );
  75. if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
  76. $checkedtypetiers=0;
  77. $arrayfields=array(
  78. 'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  79. 'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
  80. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  81. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  82. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  83. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  84. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  85. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  86. 'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
  87. 'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  88. 'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  89. 'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  90. 'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
  91. 'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
  92. 'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
  93. );
  94. // Extra fields
  95. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  96. {
  97. foreach($extrafields->attribute_label as $key => $val)
  98. {
  99. if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
  100. }
  101. }
  102. /*
  103. * Actions
  104. */
  105. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  106. if (! GETPOST('confirmmassaction','alpha')) { $massaction=''; }
  107. $parameters=array('socid'=>$socid);
  108. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  109. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  110. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  111. // Purge search criteria
  112. 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
  113. {
  114. $search_ref_exp='';
  115. $search_ref_liv='';
  116. $search_ref_customer='';
  117. $search_company='';
  118. $search_town='';
  119. $search_zip="";
  120. $search_state="";
  121. $search_type='';
  122. $search_country='';
  123. $search_type_thirdparty='';
  124. $search_billed='';
  125. $viewstatut='';
  126. $search_array_options=array();
  127. }
  128. if (empty($reshook))
  129. {
  130. // Mass actions. Controls on number of lines checked
  131. $maxformassaction=1000;
  132. $numtoselect = (is_array($toselect)?count($toselect):0);
  133. if (! empty($massaction) && $numtoselect < 1)
  134. {
  135. $error++;
  136. setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
  137. }
  138. if (! $error && $numtoselect > $maxformassaction)
  139. {
  140. setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
  141. $error++;
  142. }
  143. }
  144. /*
  145. * View
  146. */
  147. $form=new Form($db);
  148. $companystatic=new Societe($db);
  149. $shipment=new Expedition($db);
  150. $formcompany=new FormCompany($db);
  151. $helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
  152. llxHeader('',$langs->trans('ListOfSendings'),$helpurl);
  153. $sql = "SELECT e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,";
  154. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  155. $sql.= " typent.code as typent_code,";
  156. $sql.= " state.code_departement as state_code, state.nom as state_name,";
  157. $sql.= ' e.date_creation as date_creation, e.tms as date_update';
  158. // Add fields from extrafields
  159. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  160. // Add fields from hooks
  161. $parameters=array();
  162. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  163. $sql.=$hookmanager->resPrint;
  164. $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
  165. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields as ef on (e.rowid = ef.fk_object)";
  166. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  167. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  168. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  169. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  170. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
  171. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
  172. if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
  173. {
  174. $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  175. }
  176. $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
  177. if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all
  178. {
  179. $sql.= " AND e.fk_soc = sc.fk_soc";
  180. $sql.= " AND sc.fk_user = " .$user->id;
  181. }
  182. if ($socid)
  183. {
  184. $sql.= " AND e.fk_soc = ".$socid;
  185. }
  186. if ($viewstatut <> '' && $viewstatut >= 0) {
  187. $sql.= " AND e.fk_statut = ".$viewstatut;
  188. }
  189. if ($search_ref_customer != '') $sql.=natural_search('e.ref_customer', $search_ref_customer);
  190. if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
  191. if ($search_town) $sql.= natural_search('s.town', $search_town);
  192. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  193. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  194. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  195. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  196. if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp);
  197. if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv);
  198. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  199. if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  200. // Add where from extra fields
  201. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  202. // Add where from hooks
  203. $parameters=array();
  204. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  205. $sql.=$hookmanager->resPrint;
  206. $sql.= $db->order($sortfield,$sortorder);
  207. $nbtotalofrecords = '';
  208. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  209. {
  210. $result = $db->query($sql);
  211. $nbtotalofrecords = $db->num_rows($result);
  212. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  213. {
  214. $page = 0;
  215. $offset = 0;
  216. }
  217. }
  218. $sql.= $db->plimit($limit + 1,$offset);
  219. //print $sql;
  220. $resql=$db->query($sql);
  221. if ($resql)
  222. {
  223. $num = $db->num_rows($resql);
  224. $expedition = new Expedition($db);
  225. $param='';
  226. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  227. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  228. if ($sall) $param.= "&amp;sall=".urlencode($sall);
  229. if ($search_ref_exp) $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
  230. if ($search_ref_liv) $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
  231. if ($search_ref_customer) $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
  232. if ($search_company) $param.= "&amp;search_company=".urlencode($search_company);
  233. if ($search_town) $param.= '&search_town='.urlencode($search_town);
  234. if ($search_zip) $param.= '&search_zip='.urlencode($search_zip);
  235. if ($viewstatut != '') $param.= '&viewstatut='.urlencode($viewstatut);
  236. if ($optioncss != '') $param.='&amp;optioncss='.urlencode($optioncss);
  237. // Add $param from extra fields
  238. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  239. //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  240. $newcardbutton='';
  241. if ($user->rights->expedition->creer)
  242. {
  243. $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create2"><span class="valignmiddle">'.$langs->trans('NewSending').'</span>';
  244. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  245. $newcardbutton.= '</a>';
  246. }
  247. $i = 0;
  248. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  249. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  250. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  251. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  252. print '<input type="hidden" name="action" value="list">';
  253. print '<input type="hidden" name="page" value="'.$page.'">';
  254. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  255. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  256. print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
  257. if ($sall)
  258. {
  259. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  260. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
  261. }
  262. $moreforfilter='';
  263. if (! empty($moreforfilter))
  264. {
  265. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  266. print $moreforfilter;
  267. $parameters=array('type'=>$type);
  268. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  269. print $hookmanager->resPrint;
  270. print '</div>';
  271. }
  272. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  273. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  274. print '<div class="div-table-responsive">';
  275. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  276. // Lignes des champs de filtre
  277. print '<tr class="liste_titre_filter">';
  278. // Ref
  279. if (! empty($arrayfields['e.ref']['checked']))
  280. {
  281. print '<td class="liste_titre">';
  282. print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
  283. print '</td>';
  284. }
  285. // Ref customer
  286. if (! empty($arrayfields['e.ref_customer']['checked']))
  287. {
  288. print '<td class="liste_titre">';
  289. print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
  290. print '</td>';
  291. }
  292. // Thirdparty
  293. if (! empty($arrayfields['s.nom']['checked']))
  294. {
  295. print '<td class="liste_titre" align="left">';
  296. print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  297. print '</td>';
  298. }
  299. // Town
  300. if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  301. // Zip
  302. if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
  303. // State
  304. if (! empty($arrayfields['state.nom']['checked']))
  305. {
  306. print '<td class="liste_titre">';
  307. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  308. print '</td>';
  309. }
  310. // Country
  311. if (! empty($arrayfields['country.code_iso']['checked']))
  312. {
  313. print '<td class="liste_titre" align="center">';
  314. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  315. print '</td>';
  316. }
  317. // Company type
  318. if (! empty($arrayfields['typent.code']['checked']))
  319. {
  320. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  321. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
  322. print '</td>';
  323. }
  324. // Date delivery planned
  325. if (! empty($arrayfields['e.date_delivery']['checked']))
  326. {
  327. print '<td class="liste_titre">&nbsp;</td>';
  328. }
  329. if (! empty($arrayfields['l.ref']['checked']))
  330. {
  331. // Delivery ref
  332. print '<td class="liste_titre">';
  333. print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
  334. print '</td>';
  335. }
  336. if (! empty($arrayfields['l.date_delivery']['checked']))
  337. {
  338. // Date received
  339. print '<td class="liste_titre">&nbsp;</td>';
  340. }
  341. // Extra fields
  342. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  343. // Fields from hook
  344. $parameters=array('arrayfields'=>$arrayfields);
  345. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  346. print $hookmanager->resPrint;
  347. // Date creation
  348. if (! empty($arrayfields['e.datec']['checked']))
  349. {
  350. print '<td class="liste_titre">';
  351. print '</td>';
  352. }
  353. // Date modification
  354. if (! empty($arrayfields['e.tms']['checked']))
  355. {
  356. print '<td class="liste_titre">';
  357. print '</td>';
  358. }
  359. // Status
  360. if (! empty($arrayfields['e.fk_statut']['checked']))
  361. {
  362. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  363. print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusSendingDraftShort'),'1'=>$langs->trans('StatusSendingValidatedShort'),'2'=>$langs->trans('StatusSendingProcessedShort')),$viewstatut,1);
  364. print '</td>';
  365. }
  366. // Status billed
  367. if (! empty($arrayfields['e.billed']['checked']))
  368. {
  369. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  370. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
  371. print '</td>';
  372. }
  373. // Action column
  374. print '<td class="liste_titre" align="middle">';
  375. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  376. print $searchpicto;
  377. print '</td>';
  378. print "</tr>\n";
  379. print '<tr class="liste_titre">';
  380. if (! empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
  381. if (! empty($arrayfields['e.ref_customer']['checked'])) print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
  382. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
  383. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  384. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  385. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  386. if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
  387. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  388. if (! empty($arrayfields['e.date_delivery']['checked'])) print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
  389. if (! empty($arrayfields['l.ref']['checked'])) print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
  390. if (! empty($arrayfields['l.date_delivery']['checked'])) print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
  391. // Extra fields
  392. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  393. {
  394. foreach($extrafields->attribute_label as $key => $val)
  395. {
  396. if (! empty($arrayfields["ef.".$key]['checked']))
  397. {
  398. $align=$extrafields->getAlignFlag($key);
  399. $sortonfield = "ef.".$key;
  400. if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
  401. print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  402. }
  403. }
  404. }
  405. // Hook fields
  406. $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
  407. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  408. print $hookmanager->resPrint;
  409. if (! empty($arrayfields['e.datec']['checked'])) print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  410. if (! empty($arrayfields['e.tms']['checked'])) print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  411. if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
  412. if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
  413. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  414. print "</tr>\n";
  415. $i=0;
  416. $totalarray=array();
  417. while ($i < min($num,$limit))
  418. {
  419. $obj = $db->fetch_object($resql);
  420. $shipment->id=$obj->rowid;
  421. $shipment->ref=$obj->ref;
  422. $companystatic->id=$obj->socid;
  423. $companystatic->ref=$obj->name;
  424. $companystatic->name=$obj->name;
  425. print '<tr class="oddeven">';
  426. // Ref
  427. if (! empty($arrayfields['e.ref']['checked']))
  428. {
  429. print "<td>";
  430. print $shipment->getNomUrl(1);
  431. print "</td>\n";
  432. if (! $i) $totalarray['nbfield']++;
  433. }
  434. // Ref customer
  435. if (! empty($arrayfields['e.ref_customer']['checked']))
  436. {
  437. print "<td>";
  438. print $obj->ref_customer;
  439. print "</td>\n";
  440. if (! $i) $totalarray['nbfield']++;
  441. }
  442. // Third party
  443. if (! empty($arrayfields['s.nom']['checked']))
  444. {
  445. print '<td>';
  446. print $companystatic->getNomUrl(1);
  447. print '</td>';
  448. if (! $i) $totalarray['nbfield']++;
  449. }
  450. // Town
  451. if (! empty($arrayfields['s.town']['checked']))
  452. {
  453. print '<td class="nocellnopadd">';
  454. print $obj->town;
  455. print '</td>';
  456. if (! $i) $totalarray['nbfield']++;
  457. }
  458. // Zip
  459. if (! empty($arrayfields['s.zip']['checked']))
  460. {
  461. print '<td class="nocellnopadd">';
  462. print $obj->zip;
  463. print '</td>';
  464. if (! $i) $totalarray['nbfield']++;
  465. }
  466. // State
  467. if (! empty($arrayfields['state.nom']['checked']))
  468. {
  469. print "<td>".$obj->state_name."</td>\n";
  470. if (! $i) $totalarray['nbfield']++;
  471. }
  472. // Country
  473. if (! empty($arrayfields['country.code_iso']['checked']))
  474. {
  475. print '<td align="center">';
  476. $tmparray=getCountry($obj->fk_pays,'all');
  477. print $tmparray['label'];
  478. print '</td>';
  479. if (! $i) $totalarray['nbfield']++;
  480. }
  481. // Type ent
  482. if (! empty($arrayfields['typent.code']['checked']))
  483. {
  484. print '<td align="center">';
  485. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  486. print $typenArray[$obj->typent_code];
  487. print '</td>';
  488. if (! $i) $totalarray['nbfield']++;
  489. }
  490. // Date delivery planed
  491. if (! empty($arrayfields['e.date_delivery']['checked']))
  492. {
  493. print '<td align="center">';
  494. print dol_print_date($db->jdate($obj->date_livraison),"day");
  495. /*$now = time();
  496. if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 )
  497. {
  498. }*/
  499. print "</td>\n";
  500. }
  501. if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
  502. {
  503. $shipment->fetchObjectLinked($shipment->id,$shipment->element);
  504. $receiving='';
  505. if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']);
  506. if (! empty($arrayfields['l.ref']['checked']))
  507. {
  508. // Ref
  509. print '<td>';
  510. print !empty($receiving) ? $receiving->getNomUrl($db) : '';
  511. print '</td>';
  512. }
  513. if (! empty($arrayfields['l.date_delivery']['checked']))
  514. {
  515. // Date received
  516. print '<td align="center">';
  517. print dol_print_date($db->jdate($obj->date_reception),"day");
  518. print '</td>'."\n";
  519. }
  520. }
  521. // Extra fields
  522. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  523. // Fields from hook
  524. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  525. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  526. print $hookmanager->resPrint;
  527. // Date creation
  528. if (! empty($arrayfields['e.datec']['checked']))
  529. {
  530. print '<td align="center" class="nowrap">';
  531. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  532. print '</td>';
  533. if (! $i) $totalarray['nbfield']++;
  534. }
  535. // Date modification
  536. if (! empty($arrayfields['e.tms']['checked']))
  537. {
  538. print '<td align="center" class="nowrap">';
  539. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  540. print '</td>';
  541. if (! $i) $totalarray['nbfield']++;
  542. }
  543. // Status
  544. if (! empty($arrayfields['e.fk_statut']['checked']))
  545. {
  546. print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut,5).'</td>';
  547. if (! $i) $totalarray['nbfield']++;
  548. }
  549. // Billed
  550. if (! empty($arrayfields['e.billed']['checked']))
  551. {
  552. print '<td align="center">'.yn($obj->billed).'</td>';
  553. if (! $i) $totalarray['nbfield']++;
  554. }
  555. // Action column
  556. print '<td></td>';
  557. if (! $i) $totalarray['nbfield']++;
  558. print "</tr>\n";
  559. $i++;
  560. }
  561. print "</table>";
  562. print "</div>";
  563. print '</form>';
  564. $db->free($resql);
  565. }
  566. else
  567. {
  568. dol_print_error($db);
  569. }
  570. // End of page
  571. llxFooter();
  572. $db->close();