PMCORE-2835

This commit is contained in:
Paula Quispe
2021-03-30 10:03:46 -04:00
parent d66c567259
commit 7d27947b39
20 changed files with 1060 additions and 204 deletions

View File

@@ -78,6 +78,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function
'DEL_INIT_DATE' => $faker->dateTime(),
'DEL_TASK_DUE_DATE' => $faker->dateTime(),
'DEL_RISK_DATE' => $faker->dateTime(),
'DEL_LAST_INDEX' => 1,
'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID,
'TAS_ID' => $task->TAS_ID,

View File

@@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
use Tests\TestCase;
/**
@@ -34,9 +35,12 @@ class DraftTest extends TestCase
public function createDraft()
{
$application = factory(Application::class)->states('draft')->create();
$usrId = User::getId($application['APP_INIT_USER']);
$delegation = factory(Delegation::class)->states('foreign_keys')->create([
'DEL_THREAD_STATUS' => 'OPEN',
'DEL_INDEX' => 1,
'USR_UID' => $application->APP_INIT_USER,
'USR_ID' => $usrId,
'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER,
]);
@@ -84,6 +88,7 @@ class DraftTest extends TestCase
// Create new Draft object
$draft = new Draft();
$draft->setUserId($cases['USR_ID']);
$draft->setUserUid($cases['USR_UID']);
$result = $draft->getCounter();
$this->assertTrue($result > 0);
}

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
@@ -20,6 +21,14 @@ class InboxTest extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* Create inbox cases factories
*

View File

@@ -19,6 +19,14 @@ class ParticipatedTest extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* Create participated cases factories
*

View File

@@ -22,6 +22,14 @@ class PausedTest extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* Create paused cases factories
*

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Search;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use Tests\TestCase;
@@ -23,6 +24,7 @@ class SearchTest extends TestCase
public function setUp()
{
parent::setUp();
Application::truncate();
Delegation::truncate();
}

View File

@@ -21,6 +21,14 @@ class SupervisingTest extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* Create supervising cases factories
*

View File

@@ -24,6 +24,14 @@ class UnassignedTest extends TestCase
{
use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/**
* Create unassigned cases factories
*

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use Tests\TestCase;
@@ -24,7 +25,7 @@ class ApplicationTest extends TestCase
public function setUp()
{
parent::setUp();
Application::query()->delete();
Application::truncate();
}
/**
@@ -43,6 +44,22 @@ class ApplicationTest extends TestCase
$this->assertInstanceOf(User::class, $application->currentUser);
}
/**
* Test belongs to APP_INIT_USER
*
* @covers \ProcessMaker\Model\Application::creatorUser()
* @test
*/
public function it_has_a_creator_user()
{
$application = factory(Application::class)->create([
'APP_INIT_USER' => function () {
return factory(User::class)->create()->USR_UID;
}
]);
$this->assertInstanceOf(User::class, $application->creatorUser);
}
/**
* Test belongs to APP_INIT_USER
*
@@ -59,6 +76,116 @@ class ApplicationTest extends TestCase
$this->assertInstanceOf(User::class, $application->creatoruser);
}
/**
* This test scopeUserId
*
* @covers \ProcessMaker\Model\Application::scopeUserId()
* @covers \ProcessMaker\Model\Application::scopeJoinDelegation()
* @test
*/
public function it_return_scope_user_id()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$usrId = User::getId($table->APP_INIT_USER);
$this->assertCount(1, $table->joinDelegation()->userId($usrId)->get());
}
/**
* This test scopeCreator
*
* @covers \ProcessMaker\Model\Application::scopeCreator()
* @test
*/
public function it_return_scope_creator()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->creator($table->APP_INIT_USER)->get());
}
/**
* This test scopeSpecificCasesByUid
*
* @covers \ProcessMaker\Model\Application::scopeSpecificCasesByUid()
* @test
*/
public function it_return_scope_case_uids()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->specificCasesByUid([$table->APP_UID])->get());
}
/**
* This test scopeCase
*
* @covers \ProcessMaker\Model\Application::scopeCase()
* @test
*/
public function it_return_scope_case()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->case($table->APP_NUMBER)->get());
}
/**
* This test scopePositiveCases
*
* @covers \ProcessMaker\Model\Application::scopePositiveCases()
* @test
*/
public function it_return_scope_positive_cases()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->positiveCases()->get());
}
/**
* This test scopeSpecificCases
*
* @covers \ProcessMaker\Model\Application::scopeSpecificCases()
* @test
*/
public function it_return_scope_specific_case_numbers()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->specificCases([$table->APP_NUMBER])->get());
}
/**
* This test scopeRangeOfCases
*
* @covers \ProcessMaker\Model\Application::scopeRangeOfCases()
* @test
*/
public function it_return_scope_range_of_cases()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get());
}
/**
* This test scopeCasesFrom
*
* @covers \ProcessMaker\Model\Application::scopeCasesFrom()
* @test
*/
public function it_return_scope_case_from()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->casesFrom($table->APP_NUMBER)->get());
}
/**
* This test scopeCasesTo
*
* @covers \ProcessMaker\Model\Application::scopeCasesTo()
* @test
*/
public function it_return_scope_case_to()
{
$table = factory(Application::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->casesTo($table->APP_NUMBER)->get());
}
/**
* This checks if return the columns used
*
@@ -71,6 +198,96 @@ class ApplicationTest extends TestCase
$this->assertCount(1, $table->statusId($table->APP_STATUS_ID)->get());
}
/**
* This test scopeStatusIds
*
* @covers \ProcessMaker\Model\Application::scopeStatusIds()
* @test
*/
public function it_return_cases_by_status_ids()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->statusIds([$table->APP_STATUS_ID])->get());
}
/**
* This test scopeStartDateFrom
*
* @covers \ProcessMaker\Model\Application::scopeStartDateFrom()
* @test
*/
public function it_return_start_date_from()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->startDateFrom($table->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get());
}
/**
* This test scopeStartDateTo
*
* @covers \ProcessMaker\Model\Application::scopeStartDateTo()
* @test
*/
public function it_return_start_date_to()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->startDateTo($table->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get());
}
/**
* This test scopeFinishCaseFrom
*
* @covers \ProcessMaker\Model\Application::scopeFinishCaseFrom()
* @test
*/
public function it_return_finish_date_from()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->finishCaseFrom($table->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get());
}
/**
* This test scopeFinishCaseTo
*
* @covers \ProcessMaker\Model\Application::scopeFinishCaseTo()
* @test
*/
public function it_return_finish_date_to()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->finishCaseTo($table->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get());
}
/**
* This test scopeTask
*
* @covers \ProcessMaker\Model\Application::scopeTask()
* @covers \ProcessMaker\Model\Application::scopeJoinDelegation()
* @test
*/
public function it_return_scope_task()
{
$table = factory(Application::class)->create();
$tableJoin = factory(Delegation::class)->states('foreign_keys')->create([
'APP_UID' => $table->APP_UID,
'APP_NUMBER' => $table->APP_NUMBER,
]);
$this->assertCount(1, $table->joinDelegation()->task($tableJoin->TAS_ID)->get());
}
/**
* This test scopeJoinProcess
*
* @covers \ProcessMaker\Model\Application::scopeJoinProcess()
* @test
*/
public function it_return_scope_join_process()
{
$table = factory(Application::class)->create();
$this->assertCount(1, $table->joinProcess()->get());
}
/**
* This checks if return the columns used
*
@@ -156,7 +373,7 @@ class ApplicationTest extends TestCase
* @covers \ProcessMaker\Model\Application::getCountByProUid()
* @covers \ProcessMaker\Model\Application::scopeProUid()
* @covers \ProcessMaker\Model\Application::scopeStatusId()
* @covers \ProcessMaker\Model\Application::scopePositivesCases()
* @covers \ProcessMaker\Model\Application::scopePositiveCases()
* @test
*/
public function it_count_cases_by_process()

View File

@@ -1168,12 +1168,13 @@ class AbstractCases implements CasesInterface
* Get the thread information
*
* @param array $thread
* @param bool $addUserInfo
* @param bool $addThreadInfo
*
* @return array
*/
public function threadInformation(array $thread)
public function threadInformation(array $thread, $addUserInfo = false, $addThreadInfo = false)
{
$result = [];
$status = '';
$finishDate = 'now';
$dateToCompare = date("Y-m-d H:i:s");
@@ -1185,22 +1186,51 @@ class AbstractCases implements CasesInterface
$status = 'DRAFT';
}
if ($thread['APP_STATUS'] === 'COMPLETED') {
$finishDate = $thread['APP_FINISH_DATE'];
$finishDate = !empty($thread['APP_FINISH_DATE']) ? $thread['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
$dateToCompare = $finishDate;
}
// Variables of results
$threadTask = [];
$threadUser = [];
$threadTitle = [];
// Define the thread information
$result['tas_title'] = $thread['TAS_TITLE'];
$result['user_id'] = $thread['USR_ID'];
$result['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$result['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare);
$result['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : '';
$result['tas_color_label'] = (!empty($result['tas_color'])) ? self::TASK_COLORS[$result['tas_color']] : '';
$result['tas_status'] = self::TASK_STATUS[$result['tas_color']];
$result['unassigned'] = ($status === 'UNASSIGNED' ? true : false);
// Get the user tooltip information
$result['user_tooltip'] = User::getInformation($thread['USR_ID']);
$threadTask['tas_uid'] = !empty($thread['TAS_UID']) ? $thread['TAS_UID'] : '';
$threadTask['tas_title'] = $thread['TAS_TITLE'];
$threadTask['user_id'] = $thread['USR_ID'];
$threadTask['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$threadTask['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare);
$threadTask['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : '';
$threadTask['tas_color_label'] = (!empty($threadTask['tas_color'])) ? self::TASK_COLORS[$threadTask['tas_color']] : '';
$threadTask['tas_status'] = self::TASK_STATUS[$threadTask['tas_color']];
$threadTask['unassigned'] = ($status === 'UNASSIGNED' ? true : false);
$userInfo = User::getInformation($thread['USR_ID']);
$threadTask['user_tooltip'] = $userInfo;
// Get user information
if ($addUserInfo) {
$threadUser['user_tooltip'] = $userInfo;
$threadUser['user_id'] = $thread['USR_ID'];
$threadUser['usr_username'] = !empty($userInfo['usr_username']) ? $userInfo['usr_username'] : '';
$threadUser['usr_lastname'] = !empty($userInfo['usr_lastname']) ? $userInfo['usr_lastname'] : '';
$threadUser['usr_firstname'] = !empty($userInfo['usr_firstname']) ? $userInfo['usr_firstname'] : '';
}
// Get thread titles
if ($addThreadInfo) {
$threadTitle['del_id'] = $thread['DELEGATION_ID'];
$threadTitle['del_index'] = $thread['DEL_INDEX'];
$threadTitle['thread_title'] = $thread['DEL_TITLE'];
}
// Define the array responses
$result = [];
$result['THREAD_TASK'] = $threadTask;
$result['THREAD_USER'] = $threadUser;
$result['THREAD_TITLE'] = $threadTitle;
return $result;
if (!$addUserInfo && !$addThreadInfo) {
// Only will return the pending task info
return $threadTask;
} else {
return $result;
}
}
/**

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
class Draft extends AbstractCases
@@ -120,11 +121,13 @@ class Draft extends AbstractCases
*/
public function getCounter()
{
$query = Delegation::query()->select();
$query = Application::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
$query->statusId(Application::STATUS_DRAFT);
// Filter the creator
$query->creator($this->getUserUid());
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
return $query->count(['APPLICATION.APP_NUMBER']);
}
/**

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
class Inbox extends AbstractCases
@@ -82,6 +83,8 @@ class Inbox extends AbstractCases
$query->joinProcess();
// Join with users
$query->joinUser();
// Join with task
$query->JoinTask();
// Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId());
/** Apply filters */

View File

@@ -232,7 +232,7 @@ class Participated extends AbstractCases
case 'IN_PROGRESS':
// Only distinct APP_NUMBER
$query->distinct();
// Scope for in progress: TO_DO without DRAFT
// Scope for only TO_DO cases
$query->caseTodo();
break;
case 'COMPLETED':

View File

@@ -79,8 +79,10 @@ class Paused extends AbstractCases
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->JoinTask();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId());
$query->paused($this->getUserId());
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
@@ -121,7 +123,7 @@ class Paused extends AbstractCases
{
$query = Delegation::query()->select();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber());
$query->paused($this->getUserId());
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
@@ -135,7 +137,7 @@ class Paused extends AbstractCases
{
$query = Delegation::query()->select();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber());
$query->paused($this->getUserId());
// Apply filters
$this->filters($query);
// Return the number of rows

View File

@@ -6,6 +6,7 @@ use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\AppNotes;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
@@ -14,17 +15,15 @@ class Search extends AbstractCases
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.DEL_TITLE', // Case Title
'APPLICATION.APP_NUMBER', // Case #
'APPLICATION.APP_TITLE AS DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'APPLICATION.APP_STATUS', // Status
'APPLICATION.APP_CREATE_DATE', // Case create date
'APPLICATION.APP_FINISH_DATE', // Case finish date
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
'APPLICATION.APP_UID', // Case Uid for Open case
'APPLICATION.PRO_UID', // Process Uid for Case notes
];
/**
@@ -59,19 +58,35 @@ class Search extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
$query->title($this->getCaseTitle());
// Join with delegation
$query->joinDelegation();
// Add the filter
// $query->title($this->getCaseTitle());
}
// Filter by process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
$result = Process::query()->select(['PRO_UID'])
->where('PRO_ID', '=', $this->getProcessId())->get()->toArray();
$result = head($result);
$query->proUid($result['PRO_UID']);
}
// Filter by user
if ($this->getUserId()) {
// Join with delegation
$query->joinDelegation();
// Add the filter
$query->userId($this->getUserId());
// Get only the open threads related to the user
$query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
}
// Filter by task
if ($this->getTaskId()) {
// Join with delegation
$query->joinDelegation();
// Add the filter
$query->task($this->getTaskId());
// Get only the open threads related to the task
$query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
}
// Specific start case date from
if (!empty($this->getStartCaseFrom())) {
@@ -89,41 +104,9 @@ class Search extends AbstractCases
if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo());
}
/** This filter define the UNION */
// Filter related to the case status like ['DRAFT', 'TO_DO']
if (!empty($this->getCaseStatuses())) {
$statuses = $this->getCaseStatuses();
$casesOpen = [];
$casesClosed = [];
foreach ($statuses as $row) {
if ($row === self::STATUS_DRAFT or $row === self::STATUS_TODO) {
$casesOpen[] = $row;
} else {
$casesClosed[] = $row;
}
}
if (!empty($casesOpen) && !empty($casesClosed)) {
// Only in this case need to clone the same query for the union
$cloneQuery = clone $query;
// Get the open threads
$query->casesInProgress($casesOpen);
// Get the last thread
$cloneQuery->casesDone($casesClosed);
// Union
$query->union($cloneQuery);
} else {
if (!empty($casesOpen)) {
// Get the open thread
$query->casesInProgress($casesOpen);
}
if (!empty($casesClosed)) {
// Get the last thread
$query->casesDone($casesClosed);
}
}
} else {
$query->isThreadOpen();
$query->statusIds($this->getCaseStatuses());
}
return $query;
@@ -136,32 +119,9 @@ class Search extends AbstractCases
*/
public function getData()
{
$query = Delegation::query()->select($this->getColumnsView());
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
\'{"tas_id":\',
APP_DELEGATION.TAS_ID,
\', "user_id":\',
APP_DELEGATION.USR_ID,
\', "del_id":\',
APP_DELEGATION.DELEGATION_ID,
\', "due_date":"\',
APP_DELEGATION.DEL_TASK_DUE_DATE,
\'"}\'
)
),
\']\'
) AS THREADS'
);
$query = Application::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with application
$query->joinApplication();
// Group by AppNumber
$query->groupBy('APP_NUMBER');
/** Apply filters */
$this->filters($query);
/** Exclude the web entries does not submitted */
@@ -186,12 +146,36 @@ class Search extends AbstractCases
// Get total case notes
$item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']);
// Get the detail related to the open thread
if (!empty($item['THREADS'])) {
$result = $this->prepareTaskPending($item['THREADS'], false, $item['APP_STATUS'], $dateToCompare);
$item['THREAD_TASKS'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : [];
$item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : [];
$item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : [];
$taskPending = [];
$status = $item['APP_STATUS'];
switch ($status) {
case 'DRAFT':
case 'TO_DO':
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
break;
case 'COMPLETED':
case 'CANCELLED':
$taskPending = Delegation::getLastThread($item['APP_NUMBER']);
break;
}
$i = 0;
$result = [];
foreach ($taskPending as $thread) {
$thread['APP_STATUS'] = $item['APP_STATUS'];
$information = $this->threadInformation($thread, true, true);
$result['THREAD_TASKS'][$i] = $information['THREAD_TASK'];
$result['THREAD_USERS'][$i] = $information['THREAD_USER'];
$result['THREAD_TITLES'][$i] = $information['THREAD_TITLE'];
$i++;
// Del Index for Open case
$item['DEL_INDEX'] = $information['THREAD_TITLE']['del_index'];
// Task Uid for Case notes
$item['TAS_UID'] = $information['THREAD_TASK']['tas_uid'];
}
$item['THREAD_TASKS'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : [];
$item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : [];
$item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : [];
return $item;
});

View File

@@ -102,39 +102,20 @@ class Supervising extends AbstractCases
if (!empty($processes)) {
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
\'{"tas_id":\',
APP_DELEGATION.TAS_ID,
\', "user_id":\',
APP_DELEGATION.USR_ID,
\', "due_date":"\',
APP_DELEGATION.DEL_TASK_DUE_DATE,
\'"}\'
)
),
\']\'
) AS PENDING'
);
// Join with application
$query->joinApplication();
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Join with application
$query->joinApplication();
// Only cases in to_do
// Only cases in TO_DO
$query->caseTodo();
// Scope the specific array of processes supervising
$query->processInList($processes);
// Only open threads
$query->isThreadOpen();
// Group by appNumber
$query->groupBy('APP_NUMBER');
// Get only the last thread
$query->lastThread();
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
@@ -159,10 +140,13 @@ class Supervising extends AbstractCases
// Get total case notes
$item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']);
// Get the detail related to the open thread
if (!empty($item['PENDING'])) {
$result = $this->prepareTaskPending($item['PENDING']);
$item['PENDING'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : [];
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
$information = [];
foreach ($taskPending as $thread) {
$thread['APP_STATUS'] = $item['APP_STATUS'];
$information[] = $this->threadInformation($thread);
}
$item['PENDING'] = $information;
return $item;
});
@@ -188,7 +172,7 @@ class Supervising extends AbstractCases
$query->caseTodo();
// Only open threads
$query->isThreadOpen();
// Only distinct APP_NUMBER
// For parallel threads the distinct by APP_NUMBER is important
$query->distinct();
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
@@ -213,7 +197,7 @@ class Supervising extends AbstractCases
$query->caseTodo();
// Only open threads
$query->isThreadOpen();
// Only distinct APP_NUMBER
// For parallel threads the distinct by APP_NUMBER is important
$query->distinct();
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());

File diff suppressed because it is too large Load Diff

View File

@@ -115,9 +115,7 @@ class Delegation extends Model
*/
public function scopeCasesDone($query, array $ids)
{
$query->lastThread()->statusIds($ids);
return $query;
return $query->lastThread()->statusIds($ids);
}
/**
@@ -635,7 +633,7 @@ class Delegation extends Model
*/
public function scopeTaskAssignType($query, $taskType = 'SELF_SERVICE')
{
$query->join('TASK', function ($join) use ($taskType) {
$query->leftJoin('TASK', function ($join) use ($taskType) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->where('TASK.TAS_ASSIGN_TYPE', '=', $taskType);
});
@@ -656,7 +654,7 @@ class Delegation extends Model
*/
public function scopeExcludeTaskTypes($query, array $taskTypes)
{
$query->join('TASK', function ($join) use ($taskTypes) {
$query->leftJoin('TASK', function ($join) use ($taskTypes) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->whereNotIn('TASK.TAS_TYPE', $taskTypes);
});
@@ -675,7 +673,7 @@ class Delegation extends Model
*/
public function scopeSpecificTaskTypes($query, array $taskTypes)
{
$query->join('TASK', function ($join) use ($taskTypes) {
$query->leftJoin('TASK', function ($join) use ($taskTypes) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->whereIn('TASK.TAS_TYPE', $taskTypes);
});
@@ -693,7 +691,7 @@ class Delegation extends Model
*/
public function scopeAppStatusId($query, $statusId = 2)
{
$query->join('APPLICATION', function ($join) use ($statusId) {
$query->leftJoin('APPLICATION', function ($join) use ($statusId) {
$join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER')
->where('APPLICATION.APP_STATUS_ID', $statusId);
});
@@ -711,7 +709,7 @@ class Delegation extends Model
*/
public function scopeJoinCategoryProcess($query, $category = '')
{
$query->join('PROCESS', function ($join) use ($category) {
$query->leftJoin('PROCESS', function ($join) use ($category) {
$join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID');
if ($category) {
$join->where('PROCESS.PRO_CATEGORY', $category);
@@ -733,16 +731,12 @@ class Delegation extends Model
{
// This scope is for the join with the APP_DELEGATION table
$query->joinApplication();
// Filter the status to_do
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
// Scope that return the results for an specific user
$query->userId($userId);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
return $query;
}
@@ -759,10 +753,8 @@ class Delegation extends Model
// This scope is for the join with the APP_DELEGATION table
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
@@ -918,6 +910,8 @@ class Delegation extends Model
$query->leftJoin('APPLICATION', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
return $query;
}
/**
@@ -930,8 +924,7 @@ class Delegation extends Model
*/
public function scopeProcessInList($query, array $processes)
{
$query->whereIn('APP_DELEGATION.PRO_ID', $processes);
return $query;
return $query->whereIn('APP_DELEGATION.PRO_ID', $processes);
}
/**
@@ -948,7 +941,6 @@ class Delegation extends Model
$leftJoin->on('APP_DELAY.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER')
->on('APP_DELEGATION.DEL_INDEX', '=', 'APP_DELAY.APP_DEL_INDEX');
});
$query->where('APP_DELAY.APP_DISABLE_ACTION_USER', '=', '0');
$query->where('APP_DELAY.APP_TYPE', '=', $type);
@@ -968,10 +960,11 @@ class Delegation extends Model
$query->leftJoin('USERS', function ($leftJoin) {
$leftJoin->on('APP_DELAY.APP_DELEGATION_USER', '=', 'USERS.USR_UID');
});
if ($userId) {
// Add filter related to the user
if (!empty($userId)) {
$query->where('USERS.USR_ID', $userId);
}
return $query;
}
@@ -980,21 +973,17 @@ class Delegation extends Model
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $userId
* @param int $taskId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePaused($query, int $userId, int $taskId)
public function scopePaused($query, int $userId)
{
// This scope is for the join with the APP_DELAY and considerate only the PAUSE
$query->joinAppDelay('PAUSE');
// This scope is for the join with the APP_DELAY with USERS table
$query->joinAppDelayUsers($userId);
// This scope is for the join with the APP_DELEGATION table
$query->joinApplication();
// Exclude some specific task
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Specific task
if (!empty($taskId)) {
$query->task($taskId);
}
return $query;
}
@@ -1009,25 +998,24 @@ class Delegation extends Model
*/
public function casesUnassigned(&$query, $usrUid)
{
//Get the task self services related to the user
// Get the task self services related to the user
$taskSelfService = TaskUser::getSelfServicePerUser($usrUid);
//Get the task self services value based related to the user
// Get the task self services value based related to the user
$selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid);
//Get the cases unassigned
// Get the cases unassigned
if (!empty($selfServiceValueBased)) {
$query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) {
//Get the cases related to the task self service
// Get the cases related to the task self service
$query->specificTasks($taskSelfService);
foreach ($selfServiceValueBased as $case) {
//Get the cases related to the task self service value based
// 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
// Get the cases related to the task self service
$query->specificTasks($taskSelfService);
}
@@ -1804,8 +1792,12 @@ class Delegation extends Model
public static function getPendingThreads(int $appNumber)
{
$query = Delegation::query()->select([
'TASK.TAS_UID',
'TASK.TAS_TITLE',
'TASK.TAS_ASSIGN_TYPE',
'APP_DELEGATION.DELEGATION_ID',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.DEL_TITLE',
'APP_DELEGATION.USR_ID',
'APP_DELEGATION.DEL_DELEGATE_DATE',
'APP_DELEGATION.DEL_FINISH_DATE',
@@ -1834,17 +1826,21 @@ class Delegation extends Model
public static function getLastThread(int $appNumber)
{
$query = Delegation::query()->select([
'TASK.TAS_UID',
'TASK.TAS_TITLE',
'TASK.TAS_ASSIGN_TYPE',
'APP_DELEGATION.DELEGATION_ID',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.DEL_TITLE',
'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 last thread created
$query->lastThread();
// Get the results
$results = $query->get()->values()->toArray();

View File

@@ -66,28 +66,27 @@ class TaskUser extends Model
{
//Get the groups related to the user
$groups = GroupUser::getGroups($usrUid, 'GRP_UID');
// Build query
$query = Task::query()->select('TASK.TAS_ID');
//Add Join with process filtering only the active process
$query->join('PROCESS', function ($join) {
// Add Join with process filtering only the active process
$query->leftJoin('PROCESS', function ($join) {
$join->on('PROCESS.PRO_UID', '=', 'TASK.PRO_UID')
->where('PROCESS.PRO_STATUS', 'ACTIVE');
});
//Add join with with the task users
$query->join('TASK_USER', function ($join) {
// Add join with with the task users
$query->leftJoin('TASK_USER', function ($join) {
$join->on('TASK.TAS_UID', '=', 'TASK_USER.TAS_UID')
//We not considered the Ad-hoc
// We not considered the Ad-hoc
->where('TASK_USER.TU_TYPE', '=', 1);
});
//Filtering only the task self-service
// Filtering only the task self-service
$query->isSelfService();
//Filtering the task related to the user
// Filtering the task related to the user
$query->where(function ($query) use ($usrUid, $groups) {
//Filtering the user assigned in the task
// Filtering the user assigned in the task
$query->where('TASK_USER.USR_UID', '=', $usrUid);
if (!empty($groups)) {
//Consider the group related to the user
// Consider the group related to the user
$query->orWhere(function ($query) use ($groups) {
$query->whereIn('TASK_USER.USR_UID', $groups);
});