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