services_list.php 41 KB

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