PMCORE-2477

This commit is contained in:
Paula Quispe
2020-12-09 15:56:40 -04:00
parent ac6b4588cd
commit 899c67ebcb
2 changed files with 64 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use DateTime;
use G;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\AbstractCases;
use ProcessMaker\Core\System;
use ProcessMaker\Model\Task;
@@ -1808,4 +1809,45 @@ class Delegation extends Model
$res = $query->first();
return $res->DEL_TITLE;
}
/**
* Return the pending task related to the appNumber
*
* @param int $appNumber
*
* @return array
*/
public static function getPendingTask(int $appNumber)
{
$query = Delegation::query()->select([
'TASK.TAS_TITLE', // Task
'APP_DELEGATION.DEL_TITLE', // Thread title
'APP_DELEGATION.DEL_THREAD_STATUS', // Thread status
'APP_DELEGATION.USR_ID', // Current UserId
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]);
// Join with task
$query->joinTask();
// Join with task
$query->joinUser();
// Get the open threads
$query->threadOpen();
// Related to the specific case number
$query->case($appNumber);
// Get the results
$results = $query->get();
$results->transform(function ($item) {
$abs = new AbstractCases();
$item['TAS_COLOR'] = $abs->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = AbstractCases::TASK_COLORS[$item['TAS_COLOR']];
return $item;
});
return $results;
}
}