This commit is contained in:
Paula Quispe
2019-05-13 16:44:40 -04:00
parent 4064c1bebf
commit ff33075228
14 changed files with 1655 additions and 303 deletions

View File

@@ -35,6 +35,57 @@ class ListUnassigned extends Model
return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID');
}
/**
* Scope a query to only include specific tasks
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $tasks
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTasksIn($query, array $tasks)
{
return $query->whereIn('TAS_ID', $tasks);
}
/**
* Scope a query to only include a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $appNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, $appNumber)
{
return $query->where('APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $index
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, $index)
{
return $query->where('DEL_INDEX', '=', $index);
}
/**
* Scope a query to only include a specific task
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param integer $task
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTask($query, $task)
{
return $query->where('TAS_ID', '=', $task);
}
/**
* Get count
*
@@ -51,6 +102,43 @@ class ListUnassigned extends Model
return $result;
}
/**
* Count the self-services cases by user
*
* @param string $usrUid
*
* @return integer
*/
public static function countSelfService($usrUid)
{
//Get the task self services related to the user
$taskSelfService = TaskUser::getSelfServicePerUser($usrUid);
//Get the task self services value based related to the user
$selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid);
//Start the query for get the cases related to the user
$query = ListUnassigned::query()->select('APP_NUMBER');
//Get the cases unassigned
if (!empty($selfServiceValueBased)) {
$query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
foreach ($selfServiceValueBased as $case) {
//Get the cases related to the task self service value based
$query->orWhere(function ($query) use ($case) {
$query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']);
});
}
});
} else {
//Get the cases related to the task self service
$query->tasksIn($taskSelfService);
}
return $query->count();
}
/**
* Search data
*