Add endpoint status indicator

This commit is contained in:
Marco Antonio Nina Mena
2015-04-15 12:07:21 -04:00
parent c309a913fc
commit 639210ef71
3 changed files with 114 additions and 0 deletions

View File

@@ -468,6 +468,75 @@ class indicatorsCalculator
return $retval;
}
public function statusIndicator($usrUid)
{
$params[':usrUid'] = $usrUid;
$response = array();
$sqlString = "SELECT
COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) < 0 ) , 0 ) AS OVERDUE,
COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) > 0 ) , 0 ) AS ONTIME,
COALESCE( SUM( DATEDIFF( DEL_RICK_DATE , NOW( ) ) < 0 ) , 0 ) AS ATRISK
FROM LIST_INBOX
WHERE USR_UID = :usrUid
AND APP_STATUS = 'TO_DO'
AND DEL_DUE_DATE IS NOT NULL ";
$result = $this->pdoExecutor($sqlString, $params);
$response['overdue'] = 0;
$response['atRisk'] = 0;
$response['onTime'] = 0;
$response['porcentageOverdue'] = 0;
$response['porcentageAtRisk'] = 0;
$response['procentageOnTime'] = 0;
$response['DATALIST'] = array();
if (is_array($result) && isset($result[0])) {
$response['overdue'] = $result[0]['OVERDUE'];
$response['atRisk'] = $result[0]['ONTIME'];
$response['onTime'] = $result[0]['ATRISK'];
$total = $response['overdue'] + $response['atRisk'] + $response['onTime'];
if ($total != 0) {
$response['porcentageOverdue'] = ($response['overdue']*100)/$total;
$response['porcentageAtRisk'] = ($response['atRisk']*100)/$total;
$response['procentageOnTime'] = ($response['onTime']*100)/$total;
}
}
$sqlString = "SELECT
TAS_UID,
PRO_UID,
APP_TAS_TITLE AS taskTitle,
APP_PRO_TITLE AS proTitle,
COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) < 0 ) , 0 ) AS overdue,
COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) > 0 ) , 0 ) AS onTime,
COALESCE( SUM( DATEDIFF( DEL_RICK_DATE , NOW( ) ) < 0 ) , 0 ) AS atRisk
FROM LIST_INBOX
WHERE USR_UID = :usrUid
AND APP_STATUS = 'TO_DO'
AND DEL_DUE_DATE IS NOT NULL
GROUP BY TAS_UID";
$result = $this->pdoExecutor($sqlString, $params);
foreach ($result as $key => $value) {
$result[$key]['overdue'] = $value['overdue'];
$result[$key]['atRisk'] = $value['atRisk'];
$result[$key]['onTime'] = $value['onTime'];
$total = $value['overdue'] + $value['onTime'] + $value['atRisk'];
if ($total != 0) {
$result[$key]['porcentageOverdue'] = ($value['overdue']*100)/$total;
$result[$key]['porcentageAtRisk'] = ($value['atRisk']*100)/$total;
$result[$key]['procentageOnTime'] = ($value['onTime']*100)/$total;
}
}
$response['DATALIST'] = $result;
return $response;
}
private function periodicityFieldsForSelect($periodicity) {
$periodicityFields = $this->periodicityFieldsString($periodicity);