From a1a77e6564d9b87407ec089a8d80d9c88b983f6f Mon Sep 17 00:00:00 2001 From: William Mead Date: Sun, 1 Sep 2024 14:56:24 +0200 Subject: [PATCH] FIX late contract services search option (#30741) * Fixed search late contract services. Added search late contract services checkbox. Cleaned code. * Cleaned code * Fixed escaped string --- htdocs/contrat/class/contrat.class.php | 16 +++++++++------- htdocs/contrat/services_list.php | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 1055e5bf9b4b9..ba6a803d36e26 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2312,20 +2312,21 @@ public function load_board($user, $mode) $now = dol_now(); if ($mode == 'inactive') { - $warning_delay = $conf->contrat->services->inactifs->warning_delay; + $warning_delay = $conf->contract->services->inactifs->warning_delay; $label = $langs->trans("BoardNotActivatedServices"); $labelShort = $langs->trans("BoardNotActivatedServicesShort"); $url = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_status=0&sortfield=cd.date_fin_validite&sortorder=asc'; - } elseif ($mode == 'expired') { - $warning_delay = $conf->contrat->services->expires->warning_delay; + $url_late = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_status=0&search_option=late'; + } elseif ($mode == 'active') { + $warning_delay = $conf->contract->services->expires->warning_delay; $url = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_status=4&filter=expired&sortfield=cd.date_fin_validite&sortorder=asc'; + $url_late = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_status=4&search_option=late'; $label = $langs->trans("BoardExpiredServices"); $labelShort = $langs->trans("BoardExpiredServicesShort"); } else { - $warning_delay = $conf->contrat->services->expires->warning_delay; - $url = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_status=4&sortfield=cd.date_fin_validite&sortorder=asc'; - //$url.= '&op2day='.$arraydatetouse['mday'].'&op2month='.$arraydatetouse['mon'].'&op2year='.$arraydatetouse['year']; - //if ($warning_delay >= 0) $url.='&filter=expired'; + $warning_delay = $conf->contract->services->expires->warning_delay; + $url = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&sortfield=cd.date_fin_validite&sortorder=asc'; + $url_late = DOL_URL_ROOT.'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&search_option=late'; $label = $langs->trans("BoardRunningServices"); $labelShort = $langs->trans("BoardRunningServicesShort"); } @@ -2335,6 +2336,7 @@ public function load_board($user, $mode) $response->label = $label; $response->labelShort = $labelShort; $response->url = $url; + $response->url_late = $url_late; $response->img = img_object('', "contract"); while ($obj = $this->db->fetch_object($resql)) { diff --git a/htdocs/contrat/services_list.php b/htdocs/contrat/services_list.php index 31da214be984b..7166427716ea8 100644 --- a/htdocs/contrat/services_list.php +++ b/htdocs/contrat/services_list.php @@ -73,6 +73,7 @@ $search_contract = GETPOST("search_contract", 'alpha'); $search_service = GETPOST("search_service", 'alpha'); $search_status = GETPOST("search_status", 'alpha'); +$search_option = GETPOST('search_option', 'alpha'); $search_product_category = GETPOSTINT('search_product_category'); // To support selection into combo list of status with detailed status '4&filter' @@ -194,6 +195,7 @@ $search_contract = ""; $search_service = ""; $search_status = ""; + $search_option = ''; $opouvertureprevuemonth = ""; $opouvertureprevueday = ""; $opouvertureprevueyear = ""; @@ -307,6 +309,14 @@ if ($search_status == "5") { $sql .= " AND cd.statut = 5"; } +if ($search_option == 'late' && $search_status != '0') { + $warning_date = $db->idate(dol_now() - $conf->contract->services->expires->warning_delay); + $sql .= " AND cd.date_fin_validite < '".addslashes($warning_date)."'"; +} +if ($search_option == 'late' && $search_status == '0') { + $warning_date = $db->idate(dol_now() - $conf->contract->services->expires->warning_delay); + $sql .= " AND (cd.date_ouverture_prevue < '".addslashes($warning_date)."' OR cd.date_fin_validite < '".addslashes($warning_date)."')"; +} if ($search_subprice) { $sql .= natural_search("cd.subprice", $search_subprice, 1); } @@ -477,6 +487,9 @@ if ($search_status) { $param .= '&search_status='.urlencode($search_status); } +if ($search_option) { + $param .= "&search_option=".urlencode($search_option); +} if (!empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) { $param .= '&filter_opouvertureprevue='.urlencode($filter_opouvertureprevue); } @@ -552,6 +565,10 @@ $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1); $moreforfilter .= ''; } +// alert on late date +$moreforfilter .= '
'; +$moreforfilter .= $langs->trans('Alert').' '; +$moreforfilter .= '
'; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook