dolibarr 25.0.0-alpha
services_list.php
Go to the documentation of this file.
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-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2023-2024 William Mead <william.mead@manchenumerique.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33require "../main.inc.php";
42require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
43require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
44require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
45
46// Load translation files required by the page
47$langs->loadLangs(array('products', 'contracts', 'companies'));
48
49// Get parameters
50$massaction = GETPOST('massaction', 'alpha');
51$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
52$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
53$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
54$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')).$mode; // To manage different context of search
55
56// Load variable for pagination
57$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
62 // If $page is not defined, or '' or -1 or if we click on clear filters
63 $page = 0;
64}
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68if (!$sortfield) {
69 $sortfield = "c.rowid";
70}
71if (!$sortorder) {
72 $sortorder = "ASC";
73}
74
75$search_id = trim(GETPOST("search_id", "int"));
76$search_contract_id = trim(GETPOST("search_contract_id", "int"));
77$search_name = GETPOST("search_name", 'alpha');
78$search_subprice = GETPOST("search_subprice", 'alpha');
79$search_qty = GETPOST("search_qty", 'alpha');
80$search_total_ht = GETPOST("search_total_ht", 'alpha');
81$search_total_tva = GETPOST("search_total_tva", 'alpha');
82$search_total_ttc = GETPOST("search_total_ttc", 'alpha');
83$search_contract = GETPOST("search_contract", 'alpha');
84$search_service = GETPOST("search_service", 'alpha');
85$search_type = (GETPOSTISSET('search_type') ? GETPOSTINT('search_type') : -1);
86$search_status = GETPOST("search_status", 'alpha');
87$search_option = GETPOST('search_option', 'alpha');
88$search_product_category = GETPOSTINT('search_product_category');
89
90// To support selection into combo list of status with detailed status '4&filter'
91$filter = '';
92if ($search_status == '4&filter=notexpired') {
93 $search_status = '4';
94 $filter = 'notexpired';
95}
96if ($search_status == '4&filter=expired') {
97 $search_status = '4';
98 $filter = 'expired';
99}
100
101$socid = GETPOSTINT('socid');
102
103$opouvertureprevuemonth = GETPOST('opouvertureprevuemonth');
104$opouvertureprevueday = GETPOST('opouvertureprevueday');
105$opouvertureprevueyear = GETPOST('opouvertureprevueyear');
106$sqlfilter_opouvertureprevue = GETPOST('filter_opouvertureprevue', 'alphawithlgt'); // @phan-suppress-current-line SqlInjection
107
108$op1month = GETPOSTINT('op1month');
109$op1day = GETPOSTINT('op1day');
110$op1year = GETPOSTINT('op1year');
111$sqlfilter_op1 = GETPOST('filter_op1', 'alphawithlgt'); // @phan-suppress-current-line SqlInjection
112
113$op2month = GETPOSTINT('op2month');
114$op2day = GETPOSTINT('op2day');
115$op2year = GETPOSTINT('op2year');
116$sqlfilter_op2 = GETPOST('filter_op2', 'alphawithlgt'); // @phan-suppress-current-line SqlInjection
117
118$opcloturemonth = GETPOSTINT('opcloturemonth');
119$opclotureday = GETPOSTINT('opclotureday');
120$opclotureyear = GETPOSTINT('opclotureyear');
121$sqlfilter_opcloture = GETPOST('filter_opcloture', 'alphawithlgt'); // @phan-suppress-current-line SqlInjection
122
123
124// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
125$object = new ContratLigne($db);
126$hookmanager->initHooks(array('contractservicelist'));
127
128// fetch optionals attributes and labels
129$extrafields->fetch_name_optionals_label($object->table_element);
130
131$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
132
133$search_all = GETPOST('search_all', 'alphanohtml');
134
135$fieldstosearchall = [
136 'p.label' => 'Product',
137 's.nom' => 'ThirdParty',
138];
139$parameters = ['fieldstosearchall' => $fieldstosearchall];
140$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action);
141if ($reshook < 0) {
142 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
143}
144$fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray);
145
146// Security check
147$contratid = GETPOSTINT('id');
148if (!empty($user->socid)) {
149 $socid = $user->socid;
150}
151$result = restrictedArea($user, 'contrat', $contratid);
152
153$staticcontrat = new Contrat($db);
154$staticcontratligne = new ContratLigne($db);
155$companystatic = new Societe($db);
156
157$arrayfields = array(
158 'cd.rowid' => array('label' => "TechnicalID", 'checked' => (string) getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'enabled' => (string) getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'position' => 1),
159 'c.rowid' => array('label' => "ContractID", 'checked' => (string) getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'enabled' => (string) getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'position' => 2),
160 'c.ref' => array('label' => "Contract", 'checked' => '1', 'position' => 80),
161 'c.fk_contract_type' => array('label' => "ContractType", 'checked' => '1', 'position' => 82),
162 'p.description' => array('label' => "Service", 'checked' => '1', 'position' => 85),
163 's.nom' => array('label' => "ThirdParty", 'checked' => '1', 'position' => 90),
164 'cd.tva_tx' => array('label' => "VATRate", 'checked' => '-1', 'position' => 100),
165 'cd.subprice' => array('label' => "PriceUHT", 'checked' => '-1', 'position' => 105),
166 'cd.qty' => array('label' => "Qty", 'checked' => '1', 'position' => 108),
167 'cd.total_ht' => array('label' => "TotalHT", 'checked' => '-1', 'position' => 109, 'isameasure' => 1),
168 'cd.total_tva' => array('label' => "TotalVAT", 'checked' => '-1', 'position' => 110),
169 'cd.date_ouverture_prevue' => array('label' => "DateStartPlannedShort", 'checked' => '1', 'position' => 150),
170 'cd.date_ouverture' => array('label' => "DateStartRealShort", 'checked' => '1', 'position' => 160),
171 'cd.date_fin_validite' => array('label' => "DateEndPlannedShort", 'checked' => '1', 'position' => 170),
172 'cd.date_cloture' => array('label' => "DateEndRealShort", 'checked' => '1', 'position' => 180),
173 //'cd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
174 'cd.tms' => array('label' => "DateModificationShort", 'checked' => '0', 'position' => 500),
175 'status' => array('label' => "Status", 'checked' => '1', 'position' => 1000)
176);
177// Extra fields
178include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
179// Add hook to complete $arrayfield
180$parameters = array('arrayfields' => &$arrayfields);
181$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
182
183$object->fields = dol_sort_array($object->fields, 'position');
184$arrayfields = dol_sort_array($arrayfields, 'position');
185
186$permissiontoread = $user->hasRight('contrat', 'lire');
187$permissiontoadd = $user->hasRight('contrat', 'creer');
188$permissiontodelete = $user->hasRight('contrat', 'supprimer');
189
190$result = restrictedArea($user, 'contrat', 0);
191
192
193/*
194 * Actions
195 */
196
197if (GETPOST('cancel', 'alpha')) {
198 $action = 'list';
199 $massaction = '';
200}
201if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
202 $massaction = '';
203}
204
205$parameters = array('socid' => $socid);
206$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
207if ($reshook < 0) {
208 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
209}
210
211if (empty($reshook)) {
212 // Selection of new fields
213 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
214
215 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
216 $search_id = "";
217 $search_contract_id = "";
218 $search_product_category = 0;
219 $search_name = "";
220 $search_subprice = "";
221 $search_qty = "";
222 $search_total_ht = "";
223 $search_total_tva = "";
224 $search_total_ttc = "";
225 $search_contract = "";
226 $search_service = "";
227 $search_type = -1;
228 $search_status = "";
229 $search_option = '';
230 $opouvertureprevuemonth = "";
231 $opouvertureprevueday = "";
232 $opouvertureprevueyear = "";
233 $sqlfilter_opouvertureprevue = "";
234 $op1month = "";
235 $op1day = "";
236 $op1year = "";
237 $sqlfilter_op1 = "";
238 $op2month = "";
239 $op2day = "";
240 $op2year = "";
241 $sqlfilter_op2 = "";
242 $opcloturemonth = "";
243 $opclotureday = "";
244 $opclotureyear = "";
245 $sqlfilter_opcloture = "";
246 $filter = '';
247 $toselect = array();
248 $search_array_options = array();
249 }
250}
251
252
253/*
254 * View
255 */
256
257$form = new Form($db);
258
259$now = dol_now();
260
261$title = $langs->trans("ListOfServices");
262if ($search_status == "0") {
263 $title = $langs->trans("ListOfInactiveServices"); // Must use == "0"
264}
265if ($search_status == "4" && $filter != "expired") {
266 $title = $langs->trans("ListOfRunningServices");
267}
268if ($search_status == "4" && $filter == "expired") {
269 $title = $langs->trans("ListOfExpiredServices");
270}
271if ($search_status == "5") {
272 $title = $langs->trans("ListOfClosedServices");
273}
274$help_url = 'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
275
276// Build and execute select
277// --------------------------------------------------------------------
278$sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut, c.ref_customer, c.ref_supplier, c.fk_contract_type,";
279$sql .= " s.rowid as socid, s.nom as name, s.email, s.client, s.fournisseur,";
280$sql .= " cd.rowid, cd.description, cd.statut, cd.product_type as type,";
281$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,";
282if (!$user->hasRight('societe', 'client', 'voir')) {
283 $sql .= " sc.fk_soc, sc.fk_user,";
284}
285$sql .= " cd.date_ouverture_prevue,";
286$sql .= " cd.date_ouverture,";
287$sql .= " cd.date_fin_validite,";
288$sql .= " cd.date_cloture,";
289$sql .= " cd.qty,";
290$sql .= " cd.total_ht,";
291$sql .= " cd.total_tva,";
292$sql .= " cd.tva_tx,";
293$sql .= " cd.subprice,";
294//$sql.= " cd.date_c as date_creation,";
295$sql .= " cd.tms as date_modification";
296// Add fields from extrafields
297if (!empty($extrafields->attributes[$object->table_element]['label'])) {
298 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
299 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
300 }
301}
302// Add fields from hooks
303$parameters = array();
304$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
305$sql .= $hookmanager->resPrint;
306$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
307$sql .= " ".MAIN_DB_PREFIX."societe as s,";
308if (!$user->hasRight('societe', 'client', 'voir')) {
309 $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
310}
311$sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
312if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
313 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cd.rowid = ef.fk_object)";
314}
315
316// Add table from hooks
317$parameters = [];
318$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
319$sql .= $hookmanager->resPrint;
320
321$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
322if ($search_product_category > 0) {
323 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
324}
325$sql .= " WHERE c.entity IN (".getEntity($object->element).")";
326$sql .= " AND c.rowid = cd.fk_contrat";
327if ($search_product_category > 0) {
328 $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
329}
330$sql .= " AND c.fk_soc = s.rowid";
331if (!$user->hasRight('societe', 'client', 'voir')) {
332 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
333}
334if ($search_status == "0") {
335 $sql .= " AND cd.statut = 0";
336}
337if ($search_status == "4") {
338 $sql .= " AND cd.statut = 4";
339}
340if ($search_status == "4&filter=expired" || ($search_status == '4' && $filter == 'expired')) {
341 $sql .= " AND cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."'";
342}
343if ($search_status == "4&filter=notexpired" || ($search_status == '4' && $filter == 'notexpired')) {
344 $sql .= " AND cd.statut = 4 AND cd.date_fin_validite >= '".$db->idate($now)."'";
345}
346if ($search_status == "5") {
347 $sql .= " AND cd.statut = 5";
348}
349if ($search_id > 0) {
350 $sql .= natural_search("cd.rowid", $search_id, 1);
351}
352if ($search_contract_id > 0) {
353 $sql .= natural_search("c.rowid", $search_contract_id, 1);
354}
355if ($search_option == 'late' && $search_status != '0') {
356 $warning_date = $db->idate(dol_now() - (int) $conf->contract->services->expires->warning_delay);
357 $sql .= " AND cd.date_fin_validite < '".$db->escape($warning_date)."'";
358}
359if ($search_option == 'late' && $search_status == '0') {
360 $warning_date = $db->idate(dol_now() - (int) $conf->contract->services->expires->warning_delay);
361 $sql .= " AND (cd.date_ouverture_prevue < '".$db->escape($warning_date)."' OR cd.date_fin_validite < '".$db->escape($warning_date)."')";
362}
363if ($search_subprice) {
364 $sql .= natural_search("cd.subprice", $search_subprice, 1);
365}
366if ($search_qty) {
367 $sql .= natural_search("cd.qty", $search_qty, 1);
368}
369if ($search_total_ht) {
370 $sql .= natural_search("cd.total_ht", $search_total_ht, 1);
371}
372if ($search_total_tva) {
373 $sql .= natural_search("cd.total_tva", $search_total_tva, 1);
374}
375if ($search_total_ttc) {
376 $sql .= natural_search("cd.total_ttc", $search_total_ttc, 1);
377}
378if ($search_name) {
379 $sql .= natural_search("s.nom", $search_name);
380}
381if ($search_contract) {
382 $sql .= natural_search("c.ref", $search_contract);
383}
384if ($search_type >= 0) {
385 $sql .= " AND c.fk_contract_type = ".((int) $search_type);
386}
387if ($search_service) {
388 $sql .= natural_search(array("p.ref", "p.description", "cd.description"), $search_service);
389}
390if ($socid > 0) {
391 $sql .= " AND s.rowid = ".((int) $socid);
392}
393
394$filter_dateouvertureprevue = '';
395$filter_date1 = '';
396$filter_date2 = '';
397$filter_date_cloture = '';
398
399$filter_dateouvertureprevue_start = dol_mktime(0, 0, 0, (int) $opouvertureprevuemonth, (int) $opouvertureprevueday, (int) $opouvertureprevueyear);
400$filter_dateouvertureprevue_end = dol_mktime(23, 59, 59, (int) $opouvertureprevuemonth, (int) $opouvertureprevueday, (int) $opouvertureprevueyear);
401if ($filter_dateouvertureprevue_start != '' && $sqlfilter_opouvertureprevue == -1) {
402 $sqlfilter_opouvertureprevue = ' BETWEEN ';
403}
404
405$filter_date1_start = dol_mktime(0, 0, 0, (int) $op1month, (int) $op1day, (int) $op1year);
406$filter_date1_end = dol_mktime(23, 59, 59, (int) $op1month, (int) $op1day, (int) $op1year);
407if ($filter_date1_start != '' && $sqlfilter_op1 == -1) {
408 $sqlfilter_op1 = ' BETWEEN ';
409}
410
411$filter_date2_start = dol_mktime(0, 0, 0, (int) $op2month, (int) $op2day, (int) $op2year);
412$filter_date2_end = dol_mktime(23, 59, 59, (int) $op2month, (int) $op2day, (int) $op2year);
413if ($filter_date2_start != '' && $sqlfilter_op2 == -1) {
414 $sqlfilter_op2 = ' BETWEEN ';
415}
416
417$filter_datecloture_start = dol_mktime(0, 0, 0, (int) $opcloturemonth, (int) $opclotureday, (int) $opclotureyear);
418$filter_datecloture_end = dol_mktime(23, 59, 59, (int) $opcloturemonth, (int) $opclotureday, (int) $opclotureyear);
419if ($filter_datecloture_start != '' && $sqlfilter_opcloture == -1) {
420 $sqlfilter_opcloture = ' BETWEEN ';
421}
422
423if (!empty($sqlfilter_opouvertureprevue) && $sqlfilter_opouvertureprevue != -1 && $sqlfilter_opouvertureprevue != ' BETWEEN ' && $filter_dateouvertureprevue_start != '') {
424 $sql .= " AND cd.date_ouverture_prevue ".preg_replace('/[^<>]/', '', $sqlfilter_opouvertureprevue)." '".$db->idate($filter_dateouvertureprevue_start)."'";
425}
426if (!empty($sqlfilter_opouvertureprevue) && $sqlfilter_opouvertureprevue == ' BETWEEN ') {
427 $sql .= " AND cd.date_ouverture_prevue ".$db->sanitize($sqlfilter_opouvertureprevue)." '".$db->idate($filter_dateouvertureprevue_start)."' AND '".$db->idate($filter_dateouvertureprevue_end)."'";
428}
429if (!empty($sqlfilter_op1) && $sqlfilter_op1 != -1 && $sqlfilter_op1 != ' BETWEEN ' && $filter_date1_start != '') {
430 $sql .= " AND cd.date_ouverture ".preg_replace('/[^<>]/', '', $sqlfilter_op1)." '".$db->idate($filter_date1_start)."'";
431}
432if (!empty($sqlfilter_op1) && $sqlfilter_op1 == ' BETWEEN ') {
433 $sql .= " AND cd.date_ouverture ".$db->sanitize($sqlfilter_op1)." '".$db->idate($filter_date1_start)."' AND '".$db->idate($filter_date1_end)."'";
434}
435if (!empty($sqlfilter_op2) && $sqlfilter_op2 != -1 && $sqlfilter_op2 != ' BETWEEN ' && $filter_date2_start != '') {
436 $sql .= " AND cd.date_fin_validite ".preg_replace('/[^<>]/', '', $sqlfilter_op2)." '".$db->idate($filter_date2_start)."'";
437}
438if (!empty($sqlfilter_op2) && $sqlfilter_op2 == ' BETWEEN ') {
439 $sql .= " AND cd.date_fin_validite ".$db->sanitize($sqlfilter_op2)." '".$db->idate($filter_date2_start)."' AND '".$db->idate($filter_date2_end)."'";
440}
441if (!empty($sqlfilter_opcloture) && $sqlfilter_opcloture != ' BETWEEN ' && $sqlfilter_opcloture != -1 && $filter_datecloture_start != '') {
442 $sql .= " AND cd.date_cloture ".preg_replace('/[^<>]/', '', $sqlfilter_opcloture)." '".$db->idate($filter_datecloture_start)."'";
443}
444if (!empty($sqlfilter_opcloture) && $sqlfilter_opcloture == ' BETWEEN ') {
445 $sql .= " AND cd.date_cloture ".$db->sanitize($sqlfilter_opcloture)." '".$db->idate($filter_datecloture_start)."' AND '".$db->idate($filter_datecloture_end)."'";
446}
447if ($search_all) {
448 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
449}
450// Add where from extra fields
451include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
452
453// Add where from hooks
454$parameters = array();
455$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
456$sql .= $hookmanager->resPrint;
457
458// Count total nb of records
459$nbtotalofrecords = '';
460if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
461 $result = $db->query($sql);
462 $nbtotalofrecords = $db->num_rows($result);
463 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
464 $page = 0;
465 $offset = 0;
466 }
467}
468
469// Complete request and execute it with order and limit
470$sql .= $db->order($sortfield, $sortorder);
471if ($limit) {
472 $sql .= $db->plimit($limit + 1, $offset);
473}
474
475//print $sql;
476dol_syslog("contrat/services_list.php", LOG_DEBUG);
477$resql = $db->query($sql);
478if (!$resql) {
479 dol_print_error($db);
480 exit;
481}
482
483$num = $db->num_rows($resql);
484
485/*
486// Direct jump if only one record found
487if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
488 $obj = $db->fetch_object($resql);
489 $id = $obj->id;
490 header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');
491 exit;
492}*/
493
494
495// Output page
496// --------------------------------------------------------------------
497
498llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-contrat page-list_services bodyforlist');
499
500$arrayofselected = is_array($toselect) ? $toselect : array();
501
502$param = '';
503if (!empty($mode)) {
504 $param .= '&mode='.urlencode($mode);
505}
506if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
507 $param .= '&contextpage='.urlencode($contextpage);
508}
509if ($limit > 0 && $limit != $conf->liste_limit) {
510 $param .= '&limit='.((int) $limit);
511}
512if ($search_all != '') {
513 $param .= '&sall='.urlencode($search_all);
514}
515if ($optioncss != '') {
516 $param .= '&optioncss='.urlencode($optioncss);
517}
518if ($search_id > 0) {
519 $param .= '&search_id='.urlencode($search_id);
520}
521if ($search_contract_id > 0) {
522 $param .= '&search_contract_id='.urlencode($search_contract_id);
523}
524if ($search_contract) {
525 $param .= '&amp;search_contract='.urlencode($search_contract);
526}
527if ($search_type >= 0) {
528 $param .= '&amp;search_type='.$search_type;
529}
530if ($search_name) {
531 $param .= '&amp;search_name='.urlencode($search_name);
532}
533if ($search_subprice) {
534 $param .= '&amp;search_subprice='.urlencode($search_subprice);
535}
536if ($search_qty) {
537 $param .= '&amp;search_qty='.urlencode($search_qty);
538}
539if ($search_total_ht) {
540 $param .= '&amp;search_total_ht='.urlencode($search_total_ht);
541}
542if ($search_total_tva) {
543 $param .= '&amp;search_total_tva='.urlencode($search_total_tva);
544}
545if ($search_total_ttc) {
546 $param .= '&amp;search_total_ttc='.urlencode($search_total_ttc);
547}
548if ($search_service) {
549 $param .= '&amp;search_service='.urlencode($search_service);
550}
551if ($search_status != '') {
552 if ($filter == 'expired' || $filter == 'notexpired') {
553 $param .= '&amp;search_status='.urlencode($search_status.'&filter='.$filter);
554 } else {
555 $param .= '&amp;search_status='.urlencode($search_status);
556 }
557}
558if ($search_option) {
559 $param .= "&amp;search_option=".urlencode($search_option);
560}
561if (!empty($sqlfilter_opouvertureprevue) && $sqlfilter_opouvertureprevue != -1) {
562 $param .= '&amp;filter_opouvertureprevue='.urlencode($sqlfilter_opouvertureprevue);
563}
564if (!empty($sqlfilter_op1) && $sqlfilter_op1 != -1) {
565 $param .= '&amp;filter_op1='.urlencode($sqlfilter_op1);
566}
567if (!empty($sqlfilter_op2) && $sqlfilter_op2 != -1) {
568 $param .= '&amp;filter_op2='.urlencode($sqlfilter_op2);
569}
570if (!empty($sqlfilter_opcloture) && $sqlfilter_opcloture != -1) {
571 $param .= '&amp;filter_opcloture='.urlencode($sqlfilter_opcloture);
572}
573if ($filter_dateouvertureprevue_start != '') {
574 $param .= '&amp;opouvertureprevueday='.((int) $opouvertureprevueday).'&amp;opouvertureprevuemonth='.((int) $opouvertureprevuemonth).'&amp;opouvertureprevueyear='.((int) $opouvertureprevueyear);
575}
576if ($filter_date1_start != '') {
577 $param .= '&amp;op1day='.((int) $op1day).'&amp;op1month='.((int) $op1month).'&amp;op1year='.((int) $op1year);
578}
579if ($filter_date2_start != '') {
580 $param .= '&amp;op2day='.((int) $op2day).'&amp;op2month='.((int) $op2month).'&amp;op2year='.((int) $op2year);
581}
582if ($filter_datecloture_start != '') {
583 $param .= '&amp;opclotureday='.((int) $op2day).'&amp;opcloturemonth='.((int) $op2month).'&amp;opclotureyear='.((int) $op2year);
584}
585// Add $param from extra fields
586include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
587// Add $param from hooks
588$parameters = array();
589$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
590$param .= $hookmanager->resPrint;
591
592// List of mass actions available
593$arrayofmassactions = array(
594 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
595 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
596);
597//if ($user->hasRight('contrat', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
598//if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
599$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
600
601print '<form method="POST" id="searchFormList" spellcheck="false" action="'.$_SERVER["PHP_SELF"].'">'."\n";
602if ($optioncss != '') {
603 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
604}
605print '<input type="hidden" name="token" value="'.newToken().'">';
606print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
607print '<input type="hidden" name="action" value="list">';
608print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
609print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
610print '<input type="hidden" name="page" value="'.$page.'">';
611print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
612print '<input type="hidden" name="page_y" value="">';
613print '<input type="hidden" name="mode" value="'.$mode.'">';
614
615$newcardbutton = '';
616
617
618print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, '', '', $limit);
619
620if (!empty($search_all)) {
621 $fieldstosearchall = array();
622 foreach ($fieldstosearchall as $key => $val) { // @phan-suppress-current-line PhanEmptyForeach
623 $fieldstosearchall[$key] = $langs->trans($val);
624 }
625 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
626}
627
628$morefilter = '';
629$moreforfilter = '';
630
631// If the user can view categories of products
632if (isModEnabled('category') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
633 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
634 $moreforfilter .= '<div class="divsearchfield">';
635 $tmptitle = $langs->trans('IncludingProductWithTag');
636 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, 0, 1);
637 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, '', 'widthcentpercentminusx maxwidth300', 1);
638 $moreforfilter .= '</div>';
639}
640// alert on late date
641$moreforfilter .= '<div class="divsearchfield">';
642$moreforfilter .= '<label for="search_option">'.$langs->trans('Alert').'</label> <input type="checkbox" name="search_option" id="search_option" value="late"'.($search_option == 'late' ? ' checked' : '').'>';
643$moreforfilter .= '</div>';
644
645$parameters = array();
646$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
647if (empty($reshook)) {
648 $moreforfilter .= $hookmanager->resPrint;
649} else {
650 $moreforfilter = $hookmanager->resPrint;
651}
652
653
654if (!empty($moreforfilter)) {
655 print '<div class="liste_titre liste_titre_bydiv centpercent">';
656 print $moreforfilter;
657 print '</div>';
658}
659
660$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
661$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
662$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
663$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
664
665
666print '<div class="div-table-responsive">';
667print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
668
669// Fields title search
670// --------------------------------------------------------------------
671print '<tr class="liste_titre_filter">';
672// Action column
673if ($conf->main_checkbox_left_column) {
674 print '<td class="liste_titre center maxwidthsearch">';
675 $searchpicto = $form->showFilterButtons('left');
676 print $searchpicto;
677 print '</td>';
678}
679if (!empty($arrayfields['cd.rowid']['checked'])) {
680 print '<td class="liste_titre">';
681 print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
682 print '</td>';
683}
684if (!empty($arrayfields['c.rowid']['checked'])) {
685 print '<td class="liste_titre">';
686 print '<input class="flat searchstring" type="text" name="search_contract_id" size="1" value="'.dol_escape_htmltag($search_contract_id).'">';
687 print '</td>';
688}
689if (!empty($arrayfields['c.ref']['checked'])) {
690 print '<td class="liste_titre">';
691 print '<input type="hidden" name="mode" value="'.$mode.'">';
692 print '<input type="text" class="flat maxwidth75" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
693 print '</td>';
694}
695if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
696 print '<td class="liste_titre">';
697 print $form->selectarray('search_type', array('-1' => '', '0' => $langs->trans('CustomerContract'), '1' => $langs->trans('SupplierContract')), $search_type, 0, 0, 0, '', 0, 0, 0, '', 'flat maxwidth100');
698 print '</td>';
699}
700// Service label
701if (!empty($arrayfields['p.description']['checked'])) {
702 print '<td class="liste_titre">';
703 print '<input type="text" class="flat maxwidth100" name="search_service" value="'.dol_escape_htmltag($search_service).'">';
704 print '</td>';
705}
706// detail lines
707if (!empty($arrayfields['cd.tva_tx']['checked'])) {
708 print '<td class="liste_titre">';
709 print '</td>';
710}
711if (!empty($arrayfields['cd.subprice']['checked'])) {
712 print '<td class="liste_titre right">';
713 print '<input type="text" class="flat maxwidth50 right" name="search_subprice" value="'.dol_escape_htmltag($search_subprice).'">';
714 print '</td>';
715}
716if (!empty($arrayfields['cd.qty']['checked'])) {
717 print '<td class="liste_titre right">';
718 print '<input type="text" class="flat maxwidth50 right" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
719 print '</td>';
720}
721if (!empty($arrayfields['cd.total_ht']['checked'])) {
722 print '<td class="liste_titre right">';
723 print '<input type="text" class="flat maxwidth50" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
724 print '</td>';
725}
726if (!empty($arrayfields['cd.total_tva']['checked'])) {
727 print '<td class="liste_titre right">';
728 print '<input type="text" class="flat maxwidth50" name="search_total_tva" value="'.dol_escape_htmltag($search_total_tva).'">';
729 print '</td>';
730}
731// Third party
732if (!empty($arrayfields['s.nom']['checked'])) {
733 print '<td class="liste_titre">';
734 print '<input type="text" class="flat maxwidth100" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
735 print '</td>';
736}
737
738if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
739 print '<td class="liste_titre center">';
740 $arrayofoperators = array('<' => '<', '>' => '>');
741 print $form->selectarray('filter_opouvertureprevue', $arrayofoperators, $sqlfilter_opouvertureprevue, 1, 0, 0, '', 0, 0, 0, '', 'width50');
742 print ' ';
743 $filter_dateouvertureprevue = dol_mktime(0, 0, 0, (int) $opouvertureprevuemonth, (int) $opouvertureprevueday, (int) $opouvertureprevueyear);
744 print $form->selectDate($filter_dateouvertureprevue, 'opouvertureprevue', 0, 0, 1, '', 1, 0);
745 print '</td>';
746}
747if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
748 print '<td class="liste_titre center">';
749 $arrayofoperators = array('<' => '<', '>' => '>');
750 print $form->selectarray('filter_op1', $arrayofoperators, $sqlfilter_op1, 1, 0, 0, '', 0, 0, 0, '', 'width50');
751 print ' ';
752 $filter_date1 = dol_mktime(0, 0, 0, (int) $op1month, (int) $op1day, (int) $op1year);
753 print $form->selectDate($filter_date1, 'op1', 0, 0, 1, '', 1, 0);
754 print '</td>';
755}
756if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
757 print '<td class="liste_titre center">';
758 $arrayofoperators = array('<' => '<', '>' => '>');
759 print $form->selectarray('filter_op2', $arrayofoperators, $sqlfilter_op2, 1, 0, 0, '', 0, 0, 0, '', 'width50');
760 print ' ';
761 $filter_date2 = dol_mktime(0, 0, 0, (int) $op2month, (int) $op2day, (int) $op2year);
762 print $form->selectDate($filter_date2, 'op2', 0, 0, 1, '', 1, 0);
763 print '</td>';
764}
765if (!empty($arrayfields['cd.date_cloture']['checked'])) {
766 print '<td class="liste_titre center">';
767 $arrayofoperators = array('<' => '<', '>' => '>');
768 print $form->selectarray('filter_opcloture', $arrayofoperators, $sqlfilter_opcloture, 1, 0, 0, '', 0, 0, 0, '', 'width50');
769 print ' ';
770 $filter_date_cloture = dol_mktime(0, 0, 0, (int) $opcloturemonth, (int) $opclotureday, (int) $opclotureyear);
771 print $form->selectDate($filter_date_cloture, 'opcloture', 0, 0, 1, '', 1, 0);
772 print '</td>';
773}
774// Extra fields
775include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
776
777// Fields from hook
778$parameters = array('arrayfields' => $arrayfields);
779$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
780print $hookmanager->resPrint;
781if (!empty($arrayfields['cd.datec']['checked'])) {
782 // Date creation
783 print '<td class="liste_titre">';
784 print '</td>';
785}
786if (!empty($arrayfields['cd.tms']['checked'])) {
787 // Date modification
788 print '<td class="liste_titre">';
789 print '</td>';
790}
791if (!empty($arrayfields['status']['checked'])) {
792 // Status
793 print '<td class="liste_titre right parentonrightofpage">';
794 $arrayofstatus = array(
795 '0' => $langs->trans("ServiceStatusInitial"),
796 '4' => $langs->trans("ServiceStatusRunning"),
797 '4&filter=notexpired' => $langs->trans("ServiceStatusNotLate"),
798 '4&filter=expired' => $langs->trans("ServiceStatusLate"),
799 '5' => $langs->trans("ServiceStatusClosed")
800 );
801 $search_status_new = GETPOST('search_status', 'alpha');
802 if ($filter == 'expired' && !preg_match('/expired/', $search_status_new)) {
803 $search_status_new .= '&filter=expired';
804 }
805 print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status_new, ',') ? -1 : $search_status_new), 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
806 print '</td>';
807}
808// Action column
809if (!$conf->main_checkbox_left_column) {
810 print '<td class="liste_titre center maxwidthsearch">';
811 $searchpicto = $form->showFilterButtons();
812 print $searchpicto;
813 print '</td>';
814}
815print '</tr>'."\n";
816
817$totalarray = array();
818$totalarray['nbfield'] = 0;
819
820// Fields title label
821// --------------------------------------------------------------------
822print '<tr class="liste_titre">';
823// Action column
824if ($conf->main_checkbox_left_column) {
825 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
826 $totalarray['nbfield']++;
827}
828if (!empty($arrayfields['cd.rowid']['checked'])) {
829 print_liste_field_titre($arrayfields['cd.rowid']['label'], $_SERVER["PHP_SELF"], "cd.rowid", "", $param, "", $sortfield, $sortorder);
830}
831if (!empty($arrayfields['c.rowid']['checked'])) {
832 print_liste_field_titre($arrayfields['c.rowid']['label'], $_SERVER["PHP_SELF"], "c.rowid", "", $param, "", $sortfield, $sortorder);
833}
834if (!empty($arrayfields['c.ref']['checked'])) {
835 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
836 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, "", $sortfield, $sortorder);
837}
838if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
839 print_liste_field_titre($arrayfields['c.fk_contract_type']['label'], $_SERVER["PHP_SELF"], "c.fk_contract_type", "", $param, "", $sortfield, $sortorder);
840}
841if (!empty($arrayfields['p.description']['checked'])) {
842 print_liste_field_titre($arrayfields['p.description']['label'], $_SERVER["PHP_SELF"], "p.description", "", $param, "", $sortfield, $sortorder);
843}
844if (!empty($arrayfields['cd.tva_tx']['checked'])) {
845 print_liste_field_titre($arrayfields['cd.tva_tx']['label'], $_SERVER["PHP_SELF"], "cd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
846}
847if (!empty($arrayfields['cd.subprice']['checked'])) {
848 print_liste_field_titre($arrayfields['cd.subprice']['label'], $_SERVER["PHP_SELF"], "cd.subprice", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
849}
850if (!empty($arrayfields['cd.qty']['checked'])) {
851 print_liste_field_titre($arrayfields['cd.qty']['label'], $_SERVER["PHP_SELF"], "cd.qty", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
852}
853if (!empty($arrayfields['cd.total_ht']['checked'])) {
854 print_liste_field_titre($arrayfields['cd.total_ht']['label'], $_SERVER["PHP_SELF"], "cd.total_ht", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
855}
856if (!empty($arrayfields['cd.total_tva']['checked'])) {
857 print_liste_field_titre($arrayfields['cd.total_tva']['label'], $_SERVER["PHP_SELF"], "cd.total_tva", "", $param, '', $sortfield, $sortorder, 'right nowrap ');
858}
859if (!empty($arrayfields['s.nom']['checked'])) {
860 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
861}
862if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
863 print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture_prevue", "", $param, '', $sortfield, $sortorder, 'center ');
864}
865if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
866 print_liste_field_titre($arrayfields['cd.date_ouverture']['label'], $_SERVER["PHP_SELF"], "cd.date_ouverture", "", $param, '', $sortfield, $sortorder, 'center ');
867}
868if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
869 print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'], $_SERVER["PHP_SELF"], "cd.date_fin_validite", "", $param, '', $sortfield, $sortorder, 'center ');
870}
871if (!empty($arrayfields['cd.date_cloture']['checked'])) {
872 print_liste_field_titre($arrayfields['cd.date_cloture']['label'], $_SERVER["PHP_SELF"], "cd.date_cloture", "", $param, '', $sortfield, $sortorder, 'center ');
873}
874// Extra fields
875include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
876// Hook fields
877$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
878$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
879print $hookmanager->resPrint;
880if (!empty($arrayfields['cd.datec']['checked'])) {
881 print_liste_field_titre($arrayfields['cd.datec']['label'], $_SERVER["PHP_SELF"], "cd.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
882}
883if (!empty($arrayfields['cd.tms']['checked'])) {
884 print_liste_field_titre($arrayfields['cd.tms']['label'], $_SERVER["PHP_SELF"], "cd.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
885}
886if (!empty($arrayfields['status']['checked'])) {
887 print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "cd.statut,c.statut", "", $param, '', $sortfield, $sortorder, 'right ');
888}
889// Action column
890if (!$conf->main_checkbox_left_column) {
891 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
892 $totalarray['nbfield']++;
893}
894print '</tr>'."\n";
895
896
897// Loop on record
898// --------------------------------------------------------------------
899
900$contractstatic = new Contrat($db);
901$productstatic = new Product($db);
902
903$i = 0;
904$savnbfield = $totalarray['nbfield'];
905$totalarray = array('nbfield' => 0, 'val' => array('cd.qty' => 0, 'cd.total_ht' => 0, 'cd.total_tva' => 0));
906$imaxinloop = ($limit ? min($num, $limit) : $num);
907while ($i < $imaxinloop) {
908 $obj = $db->fetch_object($resql);
909 if (empty($obj)) {
910 break; // Should not happen
911 }
912
913 $contractstatic->id = $obj->cid;
914 $contractstatic->ref = $obj->ref ? $obj->ref : $obj->cid;
915 $contractstatic->ref_customer = $obj->ref_customer;
916 $contractstatic->ref_supplier = $obj->ref_supplier;
917
918 $companystatic->id = $obj->socid;
919 $companystatic->name = $obj->name;
920 $companystatic->email = $obj->email;
921 $companystatic->client = $obj->client;
922 $companystatic->fournisseur = $obj->fournisseur;
923
924 $productstatic->id = $obj->pid;
925 $productstatic->type = $obj->ptype;
926 $productstatic->ref = $obj->pref;
927 $productstatic->entity = $obj->pentity;
928 $productstatic->status = $obj->tosell;
929 $productstatic->status_buy = $obj->tobuy;
930 $productstatic->label = $obj->label;
931 $productstatic->description = $obj->description;
932 $productstatic->barcode = $obj->barcode;
933
934 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
935
936 // Action column
937 if ($conf->main_checkbox_left_column) {
938 print '<td class="nowrap center">';
939 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
940 $selected = 0;
941 if (in_array($obj->rowid, $arrayofselected)) {
942 $selected = 1;
943 }
944 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
945 }
946 print '</td>';
947 if (!$i) {
948 $totalarray['nbfield']++;
949 }
950 }
951
952 // Technical ID
953 if (!empty($arrayfields['cd.rowid']['checked'])) {
954 print '<td class="tdoverflowmax50" data-key="id">';
955 print $obj->rowid;
956 print "</td>\n";
957 if (!$i) {
958 $totalarray['nbfield']++;
959 }
960 }
961
962 // Contract ID
963 if (!empty($arrayfields['c.rowid']['checked'])) {
964 print '<td class="nowraponall">';
965 print $obj->cid;
966 print '</td>';
967 if (!$i) {
968 $totalarray['nbfield']++;
969 }
970 }
971
972 // Ref
973 if (!empty($arrayfields['c.ref']['checked'])) {
974 print '<td class="nowraponall">';
975 print $contractstatic->getNomUrl(1, 16);
976 print '</td>';
977 if (!$i) {
978 $totalarray['nbfield']++;
979 }
980 }
981 if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
982 $contractTypeLabels = array(0 => $langs->trans('CustomerContract'), 1 => $langs->trans('SupplierContract'));
983 print '<td>'.dol_escape_htmltag($contractTypeLabels[(int) $obj->fk_contract_type] ?? '').'</td>';
984 if (!$i) {
985 $totalarray['nbfield']++;
986 }
987 }
988 // Service
989 if (!empty($arrayfields['p.description']['checked'])) {
990 print '<td class="tdoverflowmax300">';
991 if ($obj->pid > 0) {
992 print $productstatic->getNomUrl(1, '', 24);
993 print $obj->label ? ' - '.dol_trunc($obj->label, 16) : '';
994 if (!empty($obj->description) && getDolGlobalString('PRODUCT_DESC_IN_LIST')) {
995 print '<br><div class="small lineheightsmall">'.dol_nl2br($obj->description).'</div>';
996 }
997 } else {
998 if ($obj->type == 0) {
999 print img_object($obj->description, 'product').' '.dol_trunc($obj->description, 24);
1000 }
1001 if ($obj->type == 1) {
1002 print img_object($obj->description, 'service').' '.dol_trunc($obj->description, 24);
1003 }
1004 }
1005 print '</td>';
1006 if (!$i) {
1007 $totalarray['nbfield']++;
1008 }
1009 }
1010
1011 if (!empty($arrayfields['cd.tva_tx']['checked'])) {
1012 print '<td class="right nowraponall">';
1013 print price2num($obj->tva_tx).'%';
1014 print '</td>';
1015 if (!$i) {
1016 $totalarray['nbfield']++;
1017 }
1018 }
1019 if (!empty($arrayfields['cd.subprice']['checked'])) {
1020 print '<td class="right nowraponall">';
1021 print price($obj->subprice);
1022 print '</td>';
1023 if (!$i) {
1024 $totalarray['nbfield']++;
1025 }
1026 }
1027 if (!empty($arrayfields['cd.qty']['checked'])) {
1028 print '<td class="right nowraponall">';
1029 print $obj->qty;
1030 print '</td>';
1031 if (!$i) {
1032 $totalarray['nbfield']++;
1033 }
1034 if (!$i) {
1035 $totalarray['pos'][$totalarray['nbfield']] = 'cd.qty';
1036 }
1037 $totalarray['val']['cd.qty'] += $obj->qty;
1038 }
1039 if (!empty($arrayfields['cd.total_ht']['checked'])) {
1040 print '<td class="right nowraponall">';
1041 print '<span class="amount">'.price($obj->total_ht).'</span>';
1042 print '</td>';
1043 if (!$i) {
1044 $totalarray['nbfield']++;
1045 }
1046 if (!$i) {
1047 $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_ht';
1048 }
1049 $totalarray['val']['cd.total_ht'] += $obj->total_ht;
1050 }
1051 if (!empty($arrayfields['cd.total_tva']['checked'])) {
1052 print '<td class="right nowraponall">';
1053 print '<span class="amount">'.price($obj->total_tva).'</span>';
1054 print '</td>';
1055 if (!$i) {
1056 $totalarray['nbfield']++;
1057 }
1058 if (!$i) {
1059 $totalarray['pos'][$totalarray['nbfield']] = 'cd.total_tva';
1060 }
1061 $totalarray['val']['cd.total_tva'] += $obj->total_tva;
1062 }
1063
1064 // Third party
1065 if (!empty($arrayfields['s.nom']['checked'])) {
1066 print '<td class="tdoverflowmax100">';
1067 print $companystatic->getNomUrl(1, 'customer', 28);
1068 print '</td>';
1069 if (!$i) {
1070 $totalarray['nbfield']++;
1071 }
1072 }
1073
1074 // Start date
1075 if (!empty($arrayfields['cd.date_ouverture_prevue']['checked'])) {
1076 print '<td class="center nowraponall">';
1077 print($obj->date_ouverture_prevue ? dol_print_date($db->jdate($obj->date_ouverture_prevue), 'dayhour') : '&nbsp;');
1078 if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0) {
1079 print ' '.img_picto($langs->trans("Late"), "warning");
1080 } else {
1081 print '&nbsp;&nbsp;&nbsp;&nbsp;';
1082 }
1083 print '</td>';
1084 if (!$i) {
1085 $totalarray['nbfield']++;
1086 }
1087 }
1088 if (!empty($arrayfields['cd.date_ouverture']['checked'])) {
1089 print '<td class="center nowraponall">'.($obj->date_ouverture ? dol_print_date($db->jdate($obj->date_ouverture), 'dayhour') : '&nbsp;').'</td>';
1090 if (!$i) {
1091 $totalarray['nbfield']++;
1092 }
1093 }
1094 // End date
1095 if (!empty($arrayfields['cd.date_fin_validite']['checked'])) {
1096 print '<td class="center nowraponall">'.($obj->date_fin_validite ? dol_print_date($db->jdate($obj->date_fin_validite), 'dayhour') : '&nbsp;');
1097 if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) {
1098 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1099 $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
1100 print img_warning($textlate);
1101 } else {
1102 print '&nbsp;&nbsp;&nbsp;&nbsp;';
1103 }
1104 print '</td>';
1105 if (!$i) {
1106 $totalarray['nbfield']++;
1107 }
1108 }
1109 // Close date (real end date)
1110 if (!empty($arrayfields['cd.date_cloture']['checked'])) {
1111 print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_cloture), 'dayhour').'</td>';
1112 if (!$i) {
1113 $totalarray['nbfield']++;
1114 }
1115 }
1116
1117 // Extra fields
1118 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1119 // Fields from hook
1120 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1121 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1122 print $hookmanager->resPrint;
1123 // Date creation
1124 if (!empty($arrayfields['cd.datec']['checked'])) {
1125 print '<td class="center">';
1126 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1127 print '</td>';
1128 if (!$i) {
1129 $totalarray['nbfield']++;
1130 }
1131 }
1132 // Date modification
1133 if (!empty($arrayfields['cd.tms']['checked'])) {
1134 print '<td class="center nowraponall">';
1135 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1136 print '</td>';
1137 if (!$i) {
1138 $totalarray['nbfield']++;
1139 }
1140 }
1141 // Status
1142 if (!empty($arrayfields['status']['checked'])) {
1143 print '<td class="right">';
1144 if ($obj->cstatut == 0) {
1145 // If contract is draft, we say line is also draft
1146 //print $contractstatic->LibStatut(0, 5);
1147 print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0, '', ' - '.$langs->trans("Draft"));
1148 } else {
1149 print $staticcontratligne->LibStatut($obj->statut, 5, ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now) ? 1 : 0);
1150 }
1151 print '</td>';
1152 if (!$i) {
1153 $totalarray['nbfield']++;
1154 }
1155 }
1156 // Action column
1157 if (!$conf->main_checkbox_left_column) {
1158 print '<td class="nowrap center">';
1159 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1160 $selected = 0;
1161 if (in_array($obj->rowid, $arrayofselected)) {
1162 $selected = 1;
1163 }
1164 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1165 }
1166 print '</td>';
1167 if (!$i) {
1168 $totalarray['nbfield']++;
1169 }
1170 }
1171
1172 print '</tr>'."\n";
1173 $i++;
1174}
1175
1176// Show total line
1177include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1178
1179// If no record found
1180if ($num == 0) {
1181 $colspan = 1;
1182 foreach ($arrayfields as $key => $val) {
1183 if (!empty($val['checked'])) {
1184 $colspan++;
1185 }
1186 }
1187 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1188}
1189
1190$db->free($resql);
1191
1192$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1193$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1194print $hookmanager->resPrint;
1195
1196print '</table>'."\n";
1197print '</div>'."\n";
1198
1199print '</form>'."\n";
1200
1201
1202// End of page
1203llxFooter();
1204$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage lines of contracts.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.