services_list.php 34 KB

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