services_list.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/contrat/services_list.php
  25. * \ingroup contrat
  26. * \brief Page to list services in contracts
  27. */
  28. require "../main.inc.php";
  29. require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
  30. require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
  31. require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('products', 'contracts', 'companies'));
  34. $optioncss = GETPOST('optioncss', 'aZ09');
  35. $mode = GETPOST("mode");
  36. $massaction = GETPOST('massaction', 'alpha');
  37. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  38. $sortfield = GETPOST('sortfield', 'aZ09comma');
  39. $sortorder = GETPOST('sortorder', 'aZ09comma');
  40. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  41. if (empty($page) || $page == -1) {
  42. $page = 0;
  43. } // If $page is not defined, or '' or -1
  44. $offset = $limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (!$sortfield) {
  48. $sortfield = "c.rowid";
  49. }
  50. if (!$sortorder) {
  51. $sortorder = "ASC";
  52. }
  53. $filter = GETPOST("filter", 'alpha');
  54. $search_name = GETPOST("search_name", 'alpha');
  55. $search_subprice = GETPOST("search_subprice", 'alpha');
  56. $search_qty = GETPOST("search_qty", 'alpha');
  57. $search_total_ht = GETPOST("search_total_ht", 'alpha');
  58. $search_total_tva = GETPOST("search_total_tva", 'alpha');
  59. $search_total_ttc = GETPOST("search_total_ttc", 'alpha');
  60. $search_contract = GETPOST("search_contract", 'alpha');
  61. $search_service = GETPOST("search_service", 'alpha');
  62. $search_status = GETPOST("search_status", 'alpha');
  63. $search_product_category = GETPOST('search_product_category', 'int');
  64. $socid = GETPOST('socid', 'int');
  65. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractservicelist'.$mode;
  66. $opouvertureprevuemonth = GETPOST('opouvertureprevuemonth');
  67. $opouvertureprevueday = GETPOST('opouvertureprevueday');
  68. $opouvertureprevueyear = GETPOST('opouvertureprevueyear');
  69. $filter_opouvertureprevue = GETPOST('filter_opouvertureprevue');
  70. $op1month = GETPOST('op1month', 'int');
  71. $op1day = GETPOST('op1day', 'int');
  72. $op1year = GETPOST('op1year', 'int');
  73. $filter_op1 = GETPOST('filter_op1', 'alpha');
  74. $op2month = GETPOST('op2month', 'int');
  75. $op2day = GETPOST('op2day', 'int');
  76. $op2year = GETPOST('op2year', 'int');
  77. $filter_op2 = GETPOST('filter_op2', 'alpha');
  78. $opcloturemonth = GETPOST('opcloturemonth', 'int');
  79. $opclotureday = GETPOST('opclotureday', 'int');
  80. $opclotureyear = GETPOST('opclotureyear', 'int');
  81. $filter_opcloture = GETPOST('filter_opcloture', 'alpha');
  82. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  83. $object = new ContratLigne($db);
  84. $hookmanager->initHooks(array('contractservicelist'));
  85. $extrafields = new ExtraFields($db);
  86. // fetch optionals attributes and labels
  87. $extrafields->fetch_name_optionals_label($object->table_element);
  88. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  89. // Security check
  90. $contratid = GETPOST('id', 'int');
  91. if (!empty($user->socid)) {
  92. $socid = $user->socid;
  93. }
  94. $result = restrictedArea($user, 'contrat', $contratid);
  95. if ($search_status != '') {
  96. $tmp = explode('&', $search_status);
  97. if (empty($tmp[1])) {
  98. $filter = '';
  99. } else {
  100. if ($tmp[1] == 'filter=notexpired') {
  101. $filter = 'notexpired';
  102. }
  103. if ($tmp[1] == 'filter=expired') {
  104. $filter = 'expired';
  105. }
  106. }
  107. }
  108. $staticcontrat = new Contrat($db);
  109. $staticcontratligne = new ContratLigne($db);
  110. $companystatic = new Societe($db);
  111. $arrayfields = array(
  112. 'c.ref'=>array('label'=>"Contract", 'checked'=>1, 'position'=>80),
  113. 'p.description'=>array('label'=>"Service", 'checked'=>1, 'position'=>80),
  114. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>90),
  115. 'cd.tva_tx'=>array('label'=>"VATRate", 'checked'=>-1, 'position'=>100),
  116. 'cd.subprice'=>array('label'=>"PriceUHT", 'checked'=>-1, 'position'=>105),
  117. 'cd.qty'=>array('label'=>"Qty", 'checked'=>1, 'position'=>108),
  118. 'cd.total_ht'=>array('label'=>"TotalHT", 'checked'=>-1, 'position'=>109, 'isameasure'=>1),
  119. 'cd.total_tva'=>array('label'=>"TotalVAT", 'checked'=>-1, 'position'=>110),
  120. 'cd.date_ouverture_prevue'=>array('label'=>"DateStartPlannedShort", 'checked'=>1, 'position'=>150),
  121. 'cd.date_ouverture'=>array('label'=>"DateStartRealShort", 'checked'=>1, 'position'=>160),
  122. 'cd.date_fin_validite'=>array('label'=>"DateEndPlannedShort", 'checked'=>1, 'position'=>170),
  123. 'cd.date_cloture'=>array('label'=>"DateEndRealShort", 'checked'=>1, 'position'=>180),
  124. //'cd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  125. 'cd.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  126. 'status'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
  127. );
  128. // Extra fields
  129. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  130. $object->fields = dol_sort_array($object->fields, 'position');
  131. $arrayfields = dol_sort_array($arrayfields, 'position');
  132. /*
  133. * Actions
  134. */
  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. if (empty($reshook)) {
  147. // Selection of new fields
  148. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  149. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
  150. $search_product_category = 0;
  151. $search_name = "";
  152. $search_subprice = "";
  153. $search_qty = "";
  154. $search_total_ht = "";
  155. $search_total_tva = "";
  156. $search_total_ttc = "";
  157. $search_contract = "";
  158. $search_service = "";
  159. $search_status = -1;
  160. $opouvertureprevuemonth = "";
  161. $opouvertureprevueday = "";
  162. $opouvertureprevueyear = "";
  163. $filter_opouvertureprevue = "";
  164. $op1month = "";
  165. $op1day = "";
  166. $op1year = "";
  167. $filter_op1 = "";
  168. $op2month = "";
  169. $op2day = "";
  170. $op2year = "";
  171. $filter_op2 = "";
  172. $opcloturemonth = "";
  173. $opclotureday = "";
  174. $opclotureyear = "";
  175. $filter_opcloture = "";
  176. $filter = '';
  177. $toselect = array();
  178. $search_array_options = array();
  179. }
  180. }
  181. /*
  182. * View
  183. */
  184. $now = dol_now();
  185. $form = new Form($db);
  186. $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut, c.ref_customer, c.ref_supplier,";
  187. $sql .= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur,";
  188. $sql .= " cd.rowid, cd.description, cd.statut, cd.product_type as type,";
  189. $sql .= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.tobuy, p.tosell, p.barcode, p.entity as pentity,";
  190. if (empty($user->rights->societe->client->voir) && !$socid) {
  191. $sql .= " sc.fk_soc, sc.fk_user,";
  192. }
  193. $sql .= " cd.date_ouverture_prevue,";
  194. $sql .= " cd.date_ouverture,";
  195. $sql .= " cd.date_fin_validite,";
  196. $sql .= " cd.date_cloture,";
  197. $sql .= " cd.qty,";
  198. $sql .= " cd.total_ht,";
  199. $sql .= " cd.total_tva,";
  200. $sql .= " cd.tva_tx,";
  201. $sql .= " cd.subprice,";
  202. //$sql.= " cd.date_c as date_creation,";
  203. $sql .= " cd.tms as date_update";
  204. // Add fields from extrafields
  205. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  206. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  207. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  208. }
  209. }
  210. // Add fields from hooks
  211. $parameters = array();
  212. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  213. $sql .= $hookmanager->resPrint;
  214. $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
  215. $sql .= " ".MAIN_DB_PREFIX."societe as s,";
  216. if (empty($user->rights->societe->client->voir) && !$socid) {
  217. $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  218. }
  219. $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
  220. if (!empty($extrafields->attributes[$object->table_element]['label']) && 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 (cd.rowid = ef.fk_object)";
  222. }
  223. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  224. if ($search_product_category > 0) {
  225. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
  226. }
  227. $sql .= " WHERE c.entity IN (".getEntity($object->element).")";
  228. $sql .= " AND c.rowid = cd.fk_contrat";
  229. if ($search_product_category > 0) {
  230. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  231. }
  232. $sql .= " AND c.fk_soc = s.rowid";
  233. if (empty($user->rights->societe->client->voir) && !$socid) {
  234. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  235. }
  236. if ($search_status == "0") {
  237. $sql .= " AND cd.statut = 0";
  238. }
  239. if ($search_status == "4") {
  240. $sql .= " AND cd.statut = 4";
  241. }
  242. if ($search_status == "5") {
  243. $sql .= " AND cd.statut = 5";
  244. }
  245. if ($filter == "expired") {
  246. $sql .= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  247. }
  248. if ($filter == "notexpired") {
  249. $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'";
  250. }
  251. if ($search_subprice) {
  252. $sql .= natural_search("cd.subprice", $search_subprice, 1);
  253. }
  254. if ($search_qty) {
  255. $sql .= natural_search("cd.qty", $search_qty, 1);
  256. }
  257. if ($search_total_ht) {
  258. $sql .= natural_search("cd.total_ht", $search_total_ht, 1);
  259. }
  260. if ($search_total_tva) {
  261. $sql .= natural_search("cd.total_tva", $search_total_tva, 1);
  262. }
  263. if ($search_total_ttc) {
  264. $sql .= natural_search("cd.total_ttc", $search_total_ttc, 1);
  265. }
  266. if ($search_name) {
  267. $sql .= natural_search("s.nom", $search_name);
  268. }
  269. if ($search_contract) {
  270. $sql .= natural_search("c.ref", $search_contract);
  271. }
  272. if ($search_service) {
  273. $sql .= natural_search(array("p.ref", "p.description", "cd.description"), $search_service);
  274. }
  275. if ($socid > 0) {
  276. $sql .= " AND s.rowid = ".((int) $socid);
  277. }
  278. $filter_dateouvertureprevue = '';
  279. $filter_date1 = '';
  280. $filter_date2 = '';
  281. $filter_opcloture = '';
  282. $filter_dateouvertureprevue_start = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
  283. $filter_dateouvertureprevue_end = dol_mktime(23, 59, 59, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
  284. if ($filter_dateouvertureprevue_start != '' && $filter_opouvertureprevue == -1) {
  285. $filter_opouvertureprevue = ' BETWEEN ';
  286. }
  287. $filter_date1_start = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);
  288. $filter_date1_end = dol_mktime(23, 59, 59, $op1month, $op1day, $op1year);
  289. if ($filter_date1_start != '' && $filter_op1 == -1) {
  290. $filter_op1 = ' BETWEEN ';
  291. }
  292. $filter_date2_start = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);
  293. $filter_date2_end = dol_mktime(23, 59, 59, $op2month, $op2day, $op2year);
  294. if ($filter_date2_start != '' && $filter_op2 == -1) {
  295. $filter_op2 = ' BETWEEN ';
  296. }
  297. $filter_datecloture_start = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);
  298. $filter_datecloture_end = dol_mktime(23, 59, 59, $opcloturemonth, $opclotureday, $opclotureyear);
  299. if ($filter_datecloture_start != '' && $filter_opcloture == -1) {
  300. $filter_opcloture = ' BETWEEN ';
  301. }
  302. if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') {
  303. $sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."'";
  304. }
  305. if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue == ' BETWEEN ') {
  306. $sql .= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue_start)."' AND '".$db->idate($filter_dateouvertureprevue_end)."'";
  307. }
  308. if (!empty($filter_op1) && $filter_op1 != -1 && $filter_op1 != ' BETWEEN ' && $filter_date1_start != '') {
  309. $sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."'";
  310. }
  311. if (!empty($filter_op1) && $filter_op1 == ' BETWEEN ') {
  312. $sql .= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1_start)."' AND '".$db->idate($filter_date1_end)."'";
  313. }
  314. if (!empty($filter_op2) && $filter_op2 != -1 && $filter_op2 != ' BETWEEN ' && $filter_date2_start != '') {
  315. $sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."'";
  316. }
  317. if (!empty($filter_op2) && $filter_op2 == ' BETWEEN ') {
  318. $sql .= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2_start)."' AND '".$db->idate($filter_date2_end)."'";
  319. }
  320. if (!empty($filter_opcloture) && $filter_opcloture != ' BETWEEN ' && $filter_opcloture != -1 && $filter_datecloture_start != '') {
  321. $sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."'";
  322. }
  323. if (!empty($filter_opcloture) && $filter_opcloture == ' BETWEEN ') {
  324. $sql .= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture_start)."' AND '".$db->idate($filter_datecloture_end)."'";
  325. }
  326. // Add where from extra fields
  327. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  328. $sql .= $db->order($sortfield, $sortorder);
  329. //print $sql;
  330. $nbtotalofrecords = '';
  331. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  332. $result = $db->query($sql);
  333. $nbtotalofrecords = $db->num_rows($result);
  334. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  335. $page = 0;
  336. $offset = 0;
  337. }
  338. }
  339. $sql .= $db->plimit($limit + 1, $offset);
  340. //print $sql;
  341. dol_syslog("contrat/services_list.php", LOG_DEBUG);
  342. $resql = $db->query($sql);
  343. if (!$resql) {
  344. dol_print_error($db);
  345. exit;
  346. }
  347. $num = $db->num_rows($resql);
  348. /*
  349. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
  350. {
  351. $obj = $db->fetch_object($resql);
  352. $id = $obj->id;
  353. header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');
  354. exit;
  355. }*/
  356. llxHeader(null, $langs->trans("Services"));
  357. $param = '';
  358. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  359. $param .= '&contextpage='.urlencode($contextpage);
  360. }
  361. if ($limit > 0 && $limit != $conf->liste_limit) {
  362. $param .= '&limit='.$limit;
  363. }
  364. if ($mode) {
  365. $param .= '&amp;mode='.urlencode($mode);
  366. }
  367. if ($search_contract) {
  368. $param .= '&amp;search_contract='.urlencode($search_contract);
  369. }
  370. if ($search_name) {
  371. $param .= '&amp;search_name='.urlencode($search_name);
  372. }
  373. if ($search_subprice) {
  374. $param .= '&amp;search_subprice='.urlencode($search_subprice);
  375. }
  376. if ($search_qty) {
  377. $param .= '&amp;search_qty='.urlencode($search_qty);
  378. }
  379. if ($search_total_ht) {
  380. $param .= '&amp;search_total_ht='.urlencode($search_total_ht);
  381. }
  382. if ($search_total_tva) {
  383. $param .= '&amp;search_total_tva='.urlencode($search_total_tva);
  384. }
  385. if ($search_total_ttc) {
  386. $param .= '&amp;search_total_ttc='.urlencode($search_total_ttc);
  387. }
  388. if ($search_service) {
  389. $param .= '&amp;search_service='.urlencode($search_service);
  390. }
  391. if ($search_status) {
  392. $param .= '&amp;search_status='.urlencode($search_status);
  393. }
  394. if ($filter) {
  395. $param .= '&amp;filter='.urlencode($filter);
  396. }
  397. if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) {
  398. $param .= '&amp;filter_opouvertureprevue='.urlencode($filter_opouvertureprevue);
  399. }
  400. if (!empty($filter_op1) && $filter_op1 != -1) {
  401. $param .= '&amp;filter_op1='.urlencode($filter_op1);
  402. }
  403. if (!empty($filter_op2) && $filter_op2 != -1) {
  404. $param .= '&amp;filter_op2='.urlencode($filter_op2);
  405. }
  406. if (!empty($filter_opcloture) && $filter_opcloture != -1) {
  407. $param .= '&amp;filter_opcloture='.urlencode($filter_opcloture);
  408. }
  409. if ($filter_dateouvertureprevue_start != '') {
  410. $param .= '&amp;opouvertureprevueday='.((int) $opouvertureprevueday).'&amp;opouvertureprevuemonth='.((int) $opouvertureprevuemonth).'&amp;opouvertureprevueyear='.((int) $opouvertureprevueyear);
  411. }
  412. if ($filter_date1_start != '') {
  413. $param .= '&amp;op1day='.((int) $op1day).'&amp;op1month='.((int) $op1month).'&amp;op1year='.((int) $op1year);
  414. }
  415. if ($filter_date2_start != '') {
  416. $param .= '&amp;op2day='.((int) $op2day).'&amp;op2month='.((int) $op2month).'&amp;op2year='.((int) $op2year);
  417. }
  418. if ($filter_datecloture_start != '') {
  419. $param .= '&amp;opclotureday='.((int) $op2day).'&amp;opcloturemonth='.((int) $op2month).'&amp;opclotureyear='.((int) $op2year);
  420. }
  421. if ($optioncss != '') {
  422. $param .= '&optioncss='.urlencode($optioncss);
  423. }
  424. // Add $param from extra fields
  425. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  426. // List of mass actions available
  427. $arrayofmassactions = array(
  428. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  429. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  430. );
  431. //if ($user->hasRight('contrat', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  432. //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  433. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  434. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  435. if ($optioncss != '') {
  436. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  437. }
  438. print '<input type="hidden" name="token" value="'.newToken().'">';
  439. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  440. print '<input type="hidden" name="action" value="list">';
  441. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  442. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  443. print '<input type="hidden" name="page" value="'.$page.'">';
  444. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  445. $title = $langs->trans("ListOfServices");
  446. if ($search_status == "0") {
  447. $title = $langs->trans("ListOfInactiveServices"); // Must use == "0"
  448. }
  449. if ($search_status == "4" && $filter != "expired") {
  450. $title = $langs->trans("ListOfRunningServices");
  451. }
  452. if ($search_status == "4" && $filter == "expired") {
  453. $title = $langs->trans("ListOfExpiredServices");
  454. }
  455. if ($search_status == "5") {
  456. $title = $langs->trans("ListOfClosedServices");
  457. }
  458. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, '', '', $limit);
  459. if (!empty($sall)) {
  460. foreach ($fieldstosearchall as $key => $val) {
  461. $fieldstosearchall[$key] = $langs->trans($val);
  462. }
  463. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  464. }
  465. $morefilter = '';
  466. $moreforfilter = '';
  467. // If the user can view categories of products
  468. if (isModEnabled('categorie') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
  469. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  470. $moreforfilter .= '<div class="divsearchfield">';
  471. $tmptitle = $langs->trans('IncludingProductWithTag');
  472. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  473. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);
  474. $moreforfilter .= '</div>';
  475. }
  476. $parameters = array();
  477. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  478. if (empty($reshook)) {
  479. $moreforfilter .= $hookmanager->resPrint;
  480. } else {
  481. $moreforfilter = $hookmanager->resPrint;
  482. }
  483. if (!empty($moreforfilter)) {
  484. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  485. print $moreforfilter;
  486. print '</div>';
  487. }
  488. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  489. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  490. print '<div class="div-table-responsive">';
  491. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  492. print '<tr class="liste_titre">';
  493. if (!empty($arrayfields['c.ref']['checked'])) {
  494. print '<td class="liste_titre">';
  495. print '<input type="hidden" name="filter" value="'.$filter.'">';
  496. print '<input type="hidden" name="mode" value="'.$mode.'">';
  497. print '<input type="text" class="flat maxwidth75" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  498. print '</td>';
  499. }
  500. // Service label
  501. if (!empty($arrayfields['p.description']['checked'])) {
  502. print '<td class="liste_titre">';
  503. print '<input type="text" class="flat maxwidth100" name="search_service" value="'.dol_escape_htmltag($search_service).'">';
  504. print '</td>';
  505. }
  506. // detail lines
  507. if (!empty($arrayfields['cd.tva_tx']['checked'])) {
  508. print '<td class="liste_titre">';
  509. print '</td>';
  510. }
  511. if (!empty($arrayfields['cd.subprice']['checked'])) {
  512. print '<td class="liste_titre right">';
  513. print '<input type="text" class="flat maxwidth50 right" name="search_subprice" value="'.dol_escape_htmltag($search_subprice).'">';
  514. print '</td>';
  515. }
  516. if (!empty($arrayfields['cd.qty']['checked'])) {
  517. print '<td class="liste_titre right">';
  518. print '<input type="text" class="flat maxwidth50 right" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
  519. print '</td>';
  520. }
  521. if (!empty($arrayfields['cd.total_ht']['checked'])) {
  522. print '<td class="liste_titre right">';
  523. print '<input type="text" class="flat maxwidth50" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
  524. print '</td>';
  525. }
  526. if (!empty($arrayfields['cd.total_tva']['checked'])) {
  527. print '<td class="liste_titre right">';
  528. print '<input type="text" class="flat maxwidth50" name="search_total_tva" value="'.dol_escape_htmltag($search_total_tva).'">';
  529. print '</td>';
  530. }
  531. // Third party
  532. if (!empty($arrayfields['s.nom']['checked'])) {
  533. print '<td class="liste_titre">';
  534. print '<input type="text" class="flat maxwidth100" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
  535. print '</td>';
  536. }
  537. if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
  538. print '<td class="liste_titre center">';
  539. $arrayofoperators = array('<'=>'<', '>'=>'>');
  540. print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $filter_opouvertureprevue, 1, 0, 0, '', 0, 0, 0, '', 'width50');
  541. print ' ';
  542. $filter_dateouvertureprevue = dol_mktime(0, 0, 0, $opouvertureprevuemonth, $opouvertureprevueday, $opouvertureprevueyear);
  543. print $form->selectDate($filter_dateouvertureprevue, 'opouvertureprevue', 0, 0, 1, '', 1, 0);
  544. print '</td>';
  545. }
  546. if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
  547. print '<td class="liste_titre center">';
  548. $arrayofoperators = array('<'=>'<', '>'=>'>');
  549. print $form->selectarray('filter_op1', $arrayofoperators, $filter_op1, 1, 0, 0, '', 0, 0, 0, '', 'width50');
  550. print ' ';
  551. $filter_date1 = dol_mktime(0, 0, 0, $op1month, $op1day, $op1year);
  552. print $form->selectDate($filter_date1, 'op1', 0, 0, 1, '', 1, 0);
  553. print '</td>';
  554. }
  555. if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
  556. print '<td class="liste_titre center">';
  557. $arrayofoperators = array('<'=>'<', '>'=>'>');
  558. print $form->selectarray('filter_op2', $arrayofoperators, $filter_op2, 1, 0, 0, '', 0, 0, 0, '', 'width50');
  559. print ' ';
  560. $filter_date2 = dol_mktime(0, 0, 0, $op2month, $op2day, $op2year);
  561. print $form->selectDate($filter_date2, 'op2', 0, 0, 1, '', 1, 0);
  562. print '</td>';
  563. }
  564. if (!empty($arrayfields['cd.date_cloture']['checked'])) {
  565. print '<td class="liste_titre center">';
  566. $arrayofoperators = array('<'=>'<', '>'=>'>');
  567. print $form->selectarray('filter_opcloture', $arrayofoperators, $filter_opcloture, 1, 0, 0, '', 0, 0, 0, '', 'width50');
  568. print ' ';
  569. $filter_date_cloture = dol_mktime(0, 0, 0, $opcloturemonth, $opclotureday, $opclotureyear);
  570. print $form->selectDate($filter_date_cloture, 'opcloture', 0, 0, 1, '', 1, 0);
  571. print '</td>';
  572. }
  573. // Extra fields
  574. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  575. // Fields from hook
  576. $parameters = array('arrayfields'=>$arrayfields);
  577. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  578. print $hookmanager->resPrint;
  579. if (!empty($arrayfields['cd.datec']['checked'])) {
  580. // Date creation
  581. print '<td class="liste_titre">';
  582. print '</td>';
  583. }
  584. if (!empty($arrayfields['cd.tms']['checked'])) {
  585. // Date modification
  586. print '<td class="liste_titre">';
  587. print '</td>';
  588. }
  589. if (!empty($arrayfields['status']['checked'])) {
  590. // Status
  591. print '<td class="liste_titre right parentonrightofpage">';
  592. $arrayofstatus = array(
  593. '0'=>$langs->trans("ServiceStatusInitial"),
  594. '4'=>$langs->trans("ServiceStatusRunning"),
  595. '4&filter=notexpired'=>$langs->trans("ServiceStatusNotLate"),
  596. '4&filter=expired'=>$langs->trans("ServiceStatusLate"),
  597. '5'=>$langs->trans("ServiceStatusClosed")
  598. );
  599. print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status, ',') ?-1 : $search_status), 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
  600. print '</td>';
  601. }
  602. // Action column
  603. print '<td class="liste_titre maxwidthsearch">';
  604. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  605. print $searchpicto;
  606. print '</td>';
  607. print "</tr>\n";
  608. print '<tr class="liste_titre">';
  609. if (!empty($arrayfields['c.ref']['checked'])) {
  610. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder);
  611. }
  612. if (!empty($arrayfields['p.description']['checked'])) {
  613. print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder);
  614. }
  615. if (!empty($arrayfields['cd.tva_tx']['checked'])) {
  616. print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  617. }
  618. if (!empty($arrayfields['cd.subprice']['checked'])) {
  619. print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  620. }
  621. if (!empty($arrayfields['cd.qty']['checked'])) {
  622. print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
  623. }
  624. if (!empty($arrayfields['cd.total_ht']['checked'])) {
  625. print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
  626. }
  627. if (!empty($arrayfields['cd.total_tva']['checked'])) {
  628. print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
  629. }
  630. if (!empty($arrayfields['s.nom']['checked'])) {
  631. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
  632. }
  633. if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
  634. print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center ');
  635. }
  636. if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
  637. print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center ');
  638. }
  639. if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
  640. print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center ');
  641. }
  642. if (!empty($arrayfields['cd.date_cloture']['checked'])) {
  643. print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center ');
  644. }
  645. // Extra fields
  646. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  647. // Hook fields
  648. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  649. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  650. print $hookmanager->resPrint;
  651. if (!empty($arrayfields['cd.datec']['checked'])) {
  652. print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  653. }
  654. if (!empty($arrayfields['cd.tms']['checked'])) {
  655. print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  656. }
  657. if (!empty($arrayfields['status']['checked'])) {
  658. print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right ');
  659. }
  660. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  661. print "</tr>\n";
  662. $contractstatic = new Contrat($db);
  663. $productstatic = new Product($db);
  664. $i = 0;
  665. $totalarray = array('nbfield'=>0, 'cd.qty'=>0, 'cd.total_ht'=>0, 'cd.total_tva'=>0);
  666. while ($i < min($num, $limit)) {
  667. $obj = $db->fetch_object($resql);
  668. $contractstatic->id = $obj->cid;
  669. $contractstatic->ref = $obj->ref ? $obj->ref : $obj->cid;
  670. $contractstatic->ref_customer = $obj->ref_customer;
  671. $contractstatic->ref_supplier = $obj->ref_supplier;
  672. $companystatic->id = $obj->socid;
  673. $companystatic->name = $obj->name;
  674. $companystatic->email = $obj->email;
  675. $companystatic->client = $obj->client;
  676. $companystatic->fournisseur = $obj->fournisseur;
  677. $productstatic->id = $obj->pid;
  678. $productstatic->type = $obj->ptype;
  679. $productstatic->ref = $obj->pref;
  680. $productstatic->entity = $obj->pentity;
  681. $productstatic->status = $obj->tosell;
  682. $productstatic->status_buy = $obj->tobuy;
  683. $productstatic->label = $obj->label;
  684. $productstatic->description = $obj->description;
  685. $productstatic->barcode = $obj->barcode;
  686. print '<tr class="oddeven">';
  687. // Ref
  688. if (!empty($arrayfields['c.ref']['checked'])) {
  689. print '<td class="nowraponall">';
  690. print $contractstatic->getNomUrl(1, 16);
  691. print '</td>';
  692. if (!$i) {
  693. $totalarray['nbfield']++;
  694. }
  695. }
  696. // Service
  697. if (!empty($arrayfields['p.description']['checked'])) {
  698. print '<td class="tdoverflowmax300">';
  699. if ($obj->pid > 0) {
  700. print $productstatic->getNomUrl(1, '', 24);
  701. print $obj->label ? ' - '.dol_trunc($obj->label, 16) : '';
  702. if (!empty($obj->description) && !empty($conf->global->PRODUCT_DESC_IN_LIST)) {
  703. print '<br><span class="small">'.dol_nl2br($obj->description).'</span>';
  704. }
  705. } else {
  706. if ($obj->type == 0) {
  707. print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24);
  708. }
  709. if ($obj->type == 1) {
  710. print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24);
  711. }
  712. }
  713. print '</td>';
  714. if (!$i) {
  715. $totalarray['nbfield']++;
  716. }
  717. }
  718. if (!empty($arrayfields['cd.tva_tx']['checked'])) {
  719. print '<td class="right nowraponall">';
  720. print price2num($obj->tva_tx).'%';
  721. print '</td>';
  722. if (!$i) {
  723. $totalarray['nbfield']++;
  724. }
  725. }
  726. if (!empty($arrayfields['cd.subprice']['checked'])) {
  727. print '<td class="right nowraponall">';
  728. print price($obj->subprice);
  729. print '</td>';
  730. if (!$i) {
  731. $totalarray['nbfield']++;
  732. }
  733. }
  734. if (!empty($arrayfields['cd.qty']['checked'])) {
  735. print '<td class="right nowraponall">';
  736. print $obj->qty;
  737. print '</td>';
  738. if (!$i) {
  739. $totalarray['nbfield']++;
  740. }
  741. if (!$i) {
  742. $totalarray['pos'][$totalarray['nbfield']] = 'cd.qty';
  743. }
  744. if (!$i) {
  745. $totalarray['val']['cd.qty'] = $obj->qty;
  746. }
  747. $totalarray['val']['cd.qty'] += $obj->qty;
  748. }
  749. if (!empty($arrayfields['cd.total_ht']['checked'])) {
  750. print '<td class="right nowraponall">';
  751. print '<span class="amount">'.price($obj->total_ht).'</span>';
  752. print '</td>';
  753. if (!$i) {
  754. $totalarray['nbfield']++;
  755. }
  756. if (!$i) {
  757. $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht';
  758. }
  759. $totalarray['val']['cd.total_ht'] += $obj->total_ht;
  760. }
  761. if (!empty($arrayfields['cd.total_tva']['checked'])) {
  762. print '<td class="right nowraponall">';
  763. print '<span class="amount">'.price($obj->total_tva).'</span>';
  764. print '</td>';
  765. if (!$i) {
  766. $totalarray['nbfield']++;
  767. }
  768. if (!$i) {
  769. $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva';
  770. }
  771. $totalarray['val']['cd.total_tva'] += $obj->total_tva;
  772. }
  773. // Third party
  774. if (!empty($arrayfields['s.nom']['checked'])) {
  775. print '<td class="tdoverflowmax100">';
  776. print $companystatic->getNomUrl(1, 'customer', 28);
  777. print '</td>';
  778. if (!$i) {
  779. $totalarray['nbfield']++;
  780. }
  781. }
  782. // Start date
  783. if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
  784. print '<td class="center nowraponall">';
  785. print ($obj->date_ouverture_prevue ?dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : '&nbsp;');
  786. if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0) {
  787. print ' '.img_picto($langs->trans("Late"), "warning");
  788. } else {
  789. print '&nbsp;&nbsp;&nbsp;&nbsp;';
  790. }
  791. print '</td>';
  792. if (!$i) {
  793. $totalarray['nbfield']++;
  794. }
  795. }
  796. if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
  797. print '<td class="center nowraponall">'.($obj->date_ouverture ?dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : '&nbsp;').'</td>';
  798. if (!$i) {
  799. $totalarray['nbfield']++;
  800. }
  801. }
  802. // End date
  803. if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
  804. print '<td class="center nowraponall">'.($obj->date_fin_validite ?dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : '&nbsp;');
  805. if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) {
  806. $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
  807. $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
  808. print img_warning($textlate);
  809. } else {
  810. print '&nbsp;&nbsp;&nbsp;&nbsp;';
  811. }
  812. print '</td>';
  813. if (!$i) {
  814. $totalarray['nbfield']++;
  815. }
  816. }
  817. // Close date (real end date)
  818. if (!empty($arrayfields['cd.date_cloture']['checked'])) {
  819. print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').'</td>';
  820. if (!$i) {
  821. $totalarray['nbfield']++;
  822. }
  823. }
  824. // Extra fields
  825. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  826. // Fields from hook
  827. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  828. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  829. print $hookmanager->resPrint;
  830. // Date creation
  831. if (!empty($arrayfields['cd.datec']['checked'])) {
  832. print '<td class="center">';
  833. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  834. print '</td>';
  835. if (!$i) {
  836. $totalarray['nbfield']++;
  837. }
  838. }
  839. // Date modification
  840. if (!empty($arrayfields['cd.tms']['checked'])) {
  841. print '<td class="center nowraponall">';
  842. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  843. print '</td>';
  844. if (!$i) {
  845. $totalarray['nbfield']++;
  846. }
  847. }
  848. // Status
  849. if (!empty($arrayfields['status']['checked'])) {
  850. print '<td class="right">';
  851. if ($obj->cstatut == 0) {
  852. // If contract is draft, we say line is also draft
  853. print $contractstatic->LibStatut(0, 5);
  854. } else {
  855. print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0);
  856. }
  857. print '</td>';
  858. if (!$i) {
  859. $totalarray['nbfield']++;
  860. }
  861. }
  862. // Action column
  863. print '<td class="nowrap center">';
  864. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  865. $selected = 0;
  866. if (in_array($obj->rowid, $arrayofselected)) {
  867. $selected = 1;
  868. }
  869. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  870. }
  871. print '</td>';
  872. if (!$i) {
  873. $totalarray['nbfield']++;
  874. }
  875. print "</tr>\n";
  876. $i++;
  877. }
  878. // Show total line
  879. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  880. // If no record found
  881. if ($num == 0) {
  882. $colspan = 1;
  883. foreach ($arrayfields as $key => $val) {
  884. if (!empty($val['checked'])) {
  885. $colspan++;
  886. }
  887. }
  888. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  889. }
  890. $db->free($resql);
  891. $parameters = array('sql' => $sql);
  892. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  893. print $hookmanager->resPrint;
  894. print '</table>';
  895. print '</div>';
  896. print '</form>';
  897. llxFooter();
  898. $db->close();