diff --git a/workflow/engine/classes/class.indicatorsCalculator.php b/workflow/engine/classes/class.indicatorsCalculator.php index c4fa95bd1..03f40aa20 100644 --- a/workflow/engine/classes/class.indicatorsCalculator.php +++ b/workflow/engine/classes/class.indicatorsCalculator.php @@ -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); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php b/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php index 37bd2b45b..1c702e039 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php @@ -296,5 +296,27 @@ class ReportingIndicators ); return $returnValue; } + + /** + * Get list status indicator + * + * @access public + * @param array $options, Data for list + * @return array + * + * @author Marco Antonio Nina + * @copyright Colosa - Bolivia + */ + public function getStatusIndicator($options = array()) + { + Validator::isArray($options, '$options'); + + $usrUid = isset( $options["usrUid"] ) ? $options["usrUid"] : ""; + + G::loadClass('indicatorsCalculator'); + $calculator = new \IndicatorsCalculator(); + $result = $calculator->statusIndicator($usrUid); + return $result; + } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php b/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php index 3df2ef4d3..60db98f0e 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php @@ -390,6 +390,29 @@ class ReportingIndicators extends Api throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } + + /** + * Get list Status indicator + * + * @return array + * + * @author Marco Antonio Nina + * @copyright Colosa - Bolivia + * + * @url GET /status-indicator + */ + public function doGetStatusIndicator() { + try { + $options['usrUid'] = $this->getUserId(); + + $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); + $response = $indicatorsObj->getStatusIndicator($options); + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + }