diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index 1445d7716..177170e9c 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -165,17 +165,33 @@ class Participated extends AbstractCases case 'IN_PROGRESS': $result = []; $i = 0; - if ($item['APP_STATUS'] === 'TO_DO') { - $taskPending = Delegation::getPendingThreads($item['APP_NUMBER']); - foreach ($taskPending as $thread) { + switch ($item['APP_STATUS']) { + case 'TO_DO': + // Get the pending task + $taskPending = Delegation::getPendingThreads($item['APP_NUMBER']); + foreach ($taskPending as $thread) { + $thread['APP_STATUS'] = $item['APP_STATUS']; + // Get the thread information + $result[$i] = $this->threadInformation($thread); + $i++; + } + $item['PENDING'] = $result; + break; + case 'COMPLETED': + // Get the last thread + $taskPending = Delegation::getLastThread($item['APP_NUMBER']); + // Get the head of array + $thread = head($taskPending); + // Define some values required for define the color status $thread['APP_STATUS'] = $item['APP_STATUS']; + $thread['APP_FINISH_DATE'] = $item['APP_FINISH_DATE']; + // Get the thread information $result[$i] = $this->threadInformation($thread); - $i++; - } - $item['PENDING'] = $result; - } else { - $result[$i] = $this->threadInformation($thread); - $item['PENDING'] = $result; + $item['PENDING'] = $result; + break; + default: // Other status + $result[$i] = $this->threadInformation($thread); + $item['PENDING'] = $result; } break; case 'COMPLETED': diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 41e71231e..241ca7e93 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -1821,6 +1821,33 @@ class Delegation extends Model return $results; } + /** + * Return the last thread created + * + * @param int $appNumber + * + * @return array + */ + public static function getLastThread(int $appNumber) + { + $query = Delegation::query()->select([ + 'TASK.TAS_TITLE', + 'TASK.TAS_ASSIGN_TYPE', + 'APP_DELEGATION.USR_ID', + 'APP_DELEGATION.DEL_TASK_DUE_DATE' + ]); + // Join with task + $query->joinTask(); + // Get the last thread created + $query->lastThread(); + // Related to the specific case number + $query->case($appNumber); + // Get the results + $results = $query->get()->values()->toArray(); + + return $results; + } + /** * Get the thread title related to the delegation *