Unverified Commit aa429b19 authored by Stanislas's avatar Stanislas Committed by GitHub

fix(dashboard): fix query criteria (#8497)

* fix(dashboard): fix query criteria

* refactor(code): refactor code for SLA / OLA computation
parent 3026324a
......@@ -3345,13 +3345,7 @@ abstract class CommonITILObject extends CommonDBTM {
'name' => __('Time to resolve exceedeed'),
'datatype' => 'bool',
'massiveaction' => false,
'computation' =>
'IF(' . $DB->quoteName('TABLE.time_to_resolve') . ' IS NOT NULL
AND ' . $DB->quoteName('TABLE.status') . ' <> 4
AND (' . $DB->quoteName('TABLE.solvedate') . ' > ' . $DB->quoteName('TABLE.time_to_resolve') . '
OR (' . $DB->quoteName('TABLE.solvedate') . ' IS NULL
AND ' . $DB->quoteName('TABLE.time_to_resolve') . ' < NOW())),
1, 0)'
'computation' => self::generateSLAOLAComputation('time_to_resolve')
];
$tab[] = [
......@@ -3803,6 +3797,34 @@ abstract class CommonITILObject extends CommonDBTM {
return $tab;
}
static function generateSLAOLAComputation($type, $table = "TABLE") {
global $DB;
switch ($type) {
case 'internal_time_to_own':
case 'time_to_own':
return 'IF('.$DB->quoteName($table.'.'.$type).' IS NOT NULL
AND '.$DB->quoteName($table.'.status').' <> '.self::WAITING.'
AND ('.$DB->quoteName($table.'.takeintoaccount_delay_stat').'
> TIME_TO_SEC(TIMEDIFF('.$DB->quoteName($table.'.'.$type).',
'.$DB->quoteName($table.'.date').'))
OR ('.$DB->quoteName($table.'.takeintoaccount_delay_stat').' = 0
AND '.$DB->quoteName($table.'.'.$type).' < NOW())),
1, 0)';
break;
case 'internal_time_to_resolve':
case 'time_to_resolve':
return 'IF(' . $DB->quoteName($table.'.'.$type) . ' IS NOT NULL
AND ' . $DB->quoteName($table.'.status') . ' <> 4
AND (' . $DB->quoteName($table.'.solvedate') . ' > ' . $DB->quoteName($table.'.'.$type) . '
OR (' . $DB->quoteName($table.'.solvedate') . ' IS NULL
AND ' . $DB->quoteName($table.'.'.$type) . ' < NOW())),
1, 0)';
break;
}
}
/**
* Get status icon
*
......
......@@ -40,6 +40,7 @@ use CommonITILActor;
use CommonITILValidation;
use CommonTreeDropdown;
use CommonDBTM;
use CommonITILObject;
use Group;
use Group_Ticket;
use Problem;
......@@ -269,10 +270,10 @@ class Provider extends CommonGLPI {
$query_criteria['WHERE']+= [
"$table.status" => Ticket::getNotSolvedStatusArray(),
'OR' => [
'time_to_resolve' => ['<', new QueryExpression('NOW()')],
'time_to_own' => ['<', new QueryExpression('NOW()')],
'internal_time_to_own' => ['<', new QueryExpression('NOW()')],
'internal_time_to_resolve' => ['<', new QueryExpression('NOW()')],
CommonITILObject::generateSLAOLAComputation('time_to_resolve', 'glpi_tickets'),
CommonITILObject::generateSLAOLAComputation('internal_time_to_resolve', 'glpi_tickets'),
CommonITILObject::generateSLAOLAComputation('time_to_own', 'glpi_tickets'),
CommonITILObject::generateSLAOLAComputation('internal_time_to_own', 'glpi_tickets'),
]
];
break;
......
......@@ -2620,14 +2620,7 @@ class Ticket extends CommonITILObject {
'name' => __('Time to own exceedeed'),
'datatype' => 'bool',
'massiveaction' => false,
'computation' => 'IF('.$DB->quoteName('TABLE.time_to_own').' IS NOT NULL
AND '.$DB->quoteName('TABLE.status').' <> '.self::WAITING.'
AND ('.$DB->quoteName('TABLE.takeintoaccount_delay_stat').'
> TIME_TO_SEC(TIMEDIFF('.$DB->quoteName('TABLE.time_to_own').',
'.$DB->quoteName('TABLE.date').'))
OR ('.$DB->quoteName('TABLE.takeintoaccount_delay_stat').' = 0
AND '.$DB->quoteName('TABLE.time_to_own').' < NOW())),
1, 0)'
'computation' => self::generateSLAOLAComputation('time_to_own')
];
$tab[] = [
......@@ -2658,12 +2651,7 @@ class Ticket extends CommonITILObject {
'name' => __('Internal time to resolve exceedeed'),
'datatype' => 'bool',
'massiveaction' => false,
'computation' => 'IF('.$DB->quoteName('TABLE.internal_time_to_resolve').' IS NOT NULL
AND '.$DB->quoteName('TABLE.status').' <> 4
AND ('.$DB->quoteName('TABLE.solvedate').' > '.$DB->quoteName('TABLE.internal_time_to_resolve').'
OR ('.$DB->quoteName('TABLE.solvedate').' IS NULL
AND '.$DB->quoteName('TABLE.internal_time_to_resolve').' < NOW())),
1, 0)'
'computation' => self::generateSLAOLAComputation('internal_time_to_resolve')
];
$tab[] = [
......@@ -2694,14 +2682,7 @@ class Ticket extends CommonITILObject {
'name' => __('Internal time to own exceedeed'),
'datatype' => 'bool',
'massiveaction' => false,
'computation' => 'IF('.$DB->quoteName('TABLE.internal_time_to_own').' IS NOT NULL
AND '.$DB->quoteName('TABLE.status').' <> '.self::WAITING.'
AND ('.$DB->quoteName('TABLE.takeintoaccount_delay_stat').'
> TIME_TO_SEC(TIMEDIFF('.$DB->quoteName('TABLE.internal_time_to_own').',
'.$DB->quoteName('TABLE.date').'))
OR ('.$DB->quoteName('TABLE.takeintoaccount_delay_stat').' = 0
AND '.$DB->quoteName('TABLE.internal_time_to_own').' < NOW())),
1, 0)'
'computation' => self::generateSLAOLAComputation('internal_time_to_own')
];
$max_date = '99999999';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment