Merged in bugfix/PMCORE-2835-363 (pull request #7867)

PMCORE-2835

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Paula Quispe
2021-04-09 20:43:49 +00:00
committed by Julio Cesar Laura Avendaño
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_INIT_DATE' => $faker->dateTime(),
'DEL_TASK_DUE_DATE' => $faker->dateTime(), 'DEL_TASK_DUE_DATE' => $faker->dateTime(),
'DEL_RISK_DATE' => $faker->dateTime(), 'DEL_RISK_DATE' => $faker->dateTime(),
'DEL_LAST_INDEX' => 1,
'USR_ID' => $user->USR_ID, 'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID, 'PRO_ID' => $process->PRO_ID,
'TAS_ID' => $task->TAS_ID, 'TAS_ID' => $task->TAS_ID,

View File

@@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Draft; use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\Model\Application; use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -34,9 +35,12 @@ class DraftTest extends TestCase
public function createDraft() public function createDraft()
{ {
$application = factory(Application::class)->states('draft')->create(); $application = factory(Application::class)->states('draft')->create();
$usrId = User::getId($application['APP_INIT_USER']);
$delegation = factory(Delegation::class)->states('foreign_keys')->create([ $delegation = factory(Delegation::class)->states('foreign_keys')->create([
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'DEL_INDEX' => 1, 'DEL_INDEX' => 1,
'USR_UID' => $application->APP_INIT_USER,
'USR_ID' => $usrId,
'APP_UID' => $application->APP_UID, 'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER, 'APP_NUMBER' => $application->APP_NUMBER,
]); ]);
@@ -84,6 +88,7 @@ class DraftTest extends TestCase
// Create new Draft object // Create new Draft object
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($cases['USR_ID']); $draft->setUserId($cases['USR_ID']);
$draft->setUserUid($cases['USR_UID']);
$result = $draft->getCounter(); $result = $draft->getCounter();
$this->assertTrue($result > 0); $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\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Inbox; use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task; use ProcessMaker\Model\Task;
@@ -20,6 +21,14 @@ class InboxTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/** /**
* Create inbox cases factories * Create inbox cases factories
* *

View File

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

View File

@@ -22,6 +22,14 @@ class PausedTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
}
/** /**
* Create paused cases factories * 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\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use ProcessMaker\BusinessModel\Cases\Search; use ProcessMaker\BusinessModel\Cases\Search;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use Tests\TestCase; use Tests\TestCase;
@@ -23,6 +24,7 @@ class SearchTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Application::truncate();
Delegation::truncate(); Delegation::truncate();
} }

View File

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

View File

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

View File

@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use G; use G;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\Application; use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
use Tests\TestCase; use Tests\TestCase;
@@ -24,7 +25,7 @@ class ApplicationTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Application::query()->delete(); Application::truncate();
} }
/** /**
@@ -43,6 +44,22 @@ class ApplicationTest extends TestCase
$this->assertInstanceOf(User::class, $application->currentUser); $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 * Test belongs to APP_INIT_USER
* *
@@ -59,6 +76,116 @@ class ApplicationTest extends TestCase
$this->assertInstanceOf(User::class, $application->creatoruser); $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 * 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->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 * This checks if return the columns used
* *
@@ -156,7 +373,7 @@ class ApplicationTest extends TestCase
* @covers \ProcessMaker\Model\Application::getCountByProUid() * @covers \ProcessMaker\Model\Application::getCountByProUid()
* @covers \ProcessMaker\Model\Application::scopeProUid() * @covers \ProcessMaker\Model\Application::scopeProUid()
* @covers \ProcessMaker\Model\Application::scopeStatusId() * @covers \ProcessMaker\Model\Application::scopeStatusId()
* @covers \ProcessMaker\Model\Application::scopePositivesCases() * @covers \ProcessMaker\Model\Application::scopePositiveCases()
* @test * @test
*/ */
public function it_count_cases_by_process() public function it_count_cases_by_process()

View File

@@ -34,9 +34,74 @@ class DelegationTest extends TestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Application::truncate();
Delegation::truncate(); Delegation::truncate();
} }
/**
* Test belongs to APP_UID
*
* @covers \ProcessMaker\Model\Delegation::application()
* @test
*/
public function it_has_an_application()
{
$delegation = factory(Delegation::class)->create([
'APP_UID' => function () {
return factory(Application::class)->create()->APP_UID;
}
]);
$this->assertInstanceOf(Application::class, $delegation->application);
}
/**
* Test belongs to USR_ID
*
* @covers \ProcessMaker\Model\Delegation::user()
* @test
*/
public function it_has_an_user()
{
$delegation = factory(Delegation::class)->create([
'USR_ID' => function () {
return factory(User::class)->create()->USR_ID;
}
]);
$this->assertInstanceOf(User::class, $delegation->user);
}
/**
* Test belongs to TAS_ID
*
* @covers \ProcessMaker\Model\Delegation::task()
* @test
*/
public function it_has_a_task()
{
$delegation = factory(Delegation::class)->create([
'TAS_ID' => function () {
return factory(Task::class)->create()->TAS_ID;
}
]);
$this->assertInstanceOf(Task::class, $delegation->task);
}
/**
* Test belongs to PRO_ID
*
* @covers \ProcessMaker\Model\Delegation::process()
* @test
*/
public function it_has_a_process()
{
$delegation = factory(Delegation::class)->create([
'PRO_ID' => function () {
return factory(Process::class)->create()->PRO_ID;
}
]);
$this->assertInstanceOf(Process::class, $delegation->process);
}
/** /**
* This test scopePriority * This test scopePriority
* *
@@ -50,15 +115,27 @@ class DelegationTest extends TestCase
} }
/** /**
* This test scopeIndex * This test scopePriorities
* *
* @covers \ProcessMaker\Model\Delegation::scopeIndex() * @covers \ProcessMaker\Model\Delegation::scopePriorities()
* @test * @test
*/ */
public function it_return_scope_index() public function it_return_scope_priorities()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->index($table->DEL_INDEX)->get()); $this->assertCount(1, $table->priorities([$table->DEL_PRIORITY])->get());
}
/**
* This test scopeThreadOpen
*
* @covers \ProcessMaker\Model\Delegation::scopeThreadOpen()
* @test
*/
public function it_return_scope_thread_open()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->threadOpen()->get());
} }
/** /**
@@ -74,15 +151,55 @@ class DelegationTest extends TestCase
} }
/** /**
* This test scopeCaseInProgress * This test scopeCasesInProgress
* *
* @covers \ProcessMaker\Model\Delegation::scopeCaseInProgress() * @covers \ProcessMaker\Model\Delegation::scopeCasesInProgress()
* @test * @test
*/ */
public function it_return_scope_case_in_progress() public function it_return_scope_case_in_progress()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->joinApplication()->caseInProgress()->get()); $this->assertCount(1, $table->joinApplication()->casesInProgress([2])->get());
}
/**
* This test scopeCasesDone
*
* @covers \ProcessMaker\Model\Delegation::scopeCasesDone()
* @test
*/
public function it_return_scope_case_done()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->joinApplication()->casesDone([2])->get());
}
/**
* This test scopeIndex
*
* @covers \ProcessMaker\Model\Delegation::scopeIndex()
* @test
*/
public function it_return_scope_index()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->index($table->DEL_INDEX)->get());
}
/**
* This test scopeCaseTodo
*
* @covers \ProcessMaker\Model\Delegation::scopeCaseTodo()
* @test
*/
public function it_return_scope_case_to_do()
{
$application = factory(Application::class)->states('todo')->create();
$table = factory(Delegation::class)->states('foreign_keys')->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
]);
$this->assertCount(1, $table->joinApplication()->caseTodo()->get());
} }
/** /**
@@ -91,7 +208,7 @@ class DelegationTest extends TestCase
* @covers \ProcessMaker\Model\Delegation::scopeCaseCompleted() * @covers \ProcessMaker\Model\Delegation::scopeCaseCompleted()
* @test * @test
*/ */
public function it_return_scope_case_in_completed() public function it_return_scope_case_completed()
{ {
$application = factory(Application::class)->states('completed')->create(); $application = factory(Application::class)->states('completed')->create();
$table = factory(Delegation::class)->states('foreign_keys')->create([ $table = factory(Delegation::class)->states('foreign_keys')->create([
@@ -101,6 +218,38 @@ class DelegationTest extends TestCase
$this->assertCount(1, $table->joinApplication()->caseCompleted()->get()); $this->assertCount(1, $table->joinApplication()->caseCompleted()->get());
} }
/**
* This test scopeStatus
*
* @covers \ProcessMaker\Model\Delegation::scopeStatus()
* @test
*/
public function it_return_scope_status()
{
$application = factory(Application::class)->states('todo')->create();
$table = factory(Delegation::class)->states('foreign_keys')->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
]);
$this->assertCount(1, $table->joinApplication()->status($application->APP_STATUS_ID)->get());
}
/**
* This test scopeStatusIds
*
* @covers \ProcessMaker\Model\Delegation::scopeStatusIds()
* @test
*/
public function it_return_scope_status_ids()
{
$application = factory(Application::class)->states('todo')->create();
$table = factory(Delegation::class)->states('foreign_keys')->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
]);
$this->assertCount(1, $table->joinApplication()->statusIds([$application->APP_STATUS_ID])->get());
}
/** /**
* This test scopeDelegateDateFrom * This test scopeDelegateDateFrom
* *
@@ -125,6 +274,66 @@ class DelegationTest extends TestCase
$this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d H:i:s"))->get()); $this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d H:i:s"))->get());
} }
/**
* This test scopeFinishDateFrom
*
* @covers \ProcessMaker\Model\Delegation::scopeFinishDateFrom()
* @test
*/
public function it_return_scope_finish_date_from()
{
$table = factory(Delegation::class)->states('closed')->create();
$this->assertCount(1, $table->finishDateFrom($table->DEL_FINISH_DATE)->get());
}
/**
* This test scopeFinishDateTo
*
* @covers \ProcessMaker\Model\Delegation::scopeFinishDateTo()
* @test
*/
public function it_return_scope_finish_date_to()
{
$table = factory(Delegation::class)->states('closed')->create();
$this->assertCount(1, $table->finishDateTo($table->DEL_FINISH_DATE)->get());
}
/**
* This test scopeDueFrom
*
* @covers \ProcessMaker\Model\Delegation::scopeDueFrom()
* @test
*/
public function it_return_scope_due_date_from()
{
$table = factory(Delegation::class)->states('closed')->create();
$this->assertCount(1, $table->dueFrom($table->DEL_TASK_DUE_DATE)->get());
}
/**
* This test scopeDueTo
*
* @covers \ProcessMaker\Model\Delegation::scopeDueTo()
* @test
*/
public function it_return_scope_due_date_to()
{
$table = factory(Delegation::class)->states('closed')->create();
$this->assertCount(1, $table->dueTo($table->DEL_TASK_DUE_DATE)->get());
}
/**
* This test scopeCase
*
* @covers \ProcessMaker\Model\Delegation::scopeCase()
* @test
*/
public function it_return_scope_case()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->case($table->APP_NUMBER)->get());
}
/** /**
* This test scopeSpecificCases * This test scopeSpecificCases
* *
@@ -137,6 +346,102 @@ class DelegationTest extends TestCase
$this->assertCount(1, $table->specificCases([$table->APP_NUMBER])->get()); $this->assertCount(1, $table->specificCases([$table->APP_NUMBER])->get());
} }
/**
* This test scopeCasesFrom
*
* @covers \ProcessMaker\Model\Delegation::scopeCasesFrom()
* @test
*/
public function it_return_scope_cases_from()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->casesFrom($table->APP_NUMBER)->get());
}
/**
* This test scopeCasesTo
*
* @covers \ProcessMaker\Model\Delegation::scopeCasesTo()
* @test
*/
public function it_return_scope_cases_to()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->casesTo($table->APP_NUMBER)->get());
}
/**
* This test scopePositiveCases
*
* @covers \ProcessMaker\Model\Delegation::scopePositiveCases()
* @test
*/
public function it_return_scope_positive_cases()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->positiveCases()->get());
}
/**
* This test scopeRangeOfCases
*
* @covers \ProcessMaker\Model\Delegation::scopeRangeOfCases()
* @test
*/
public function it_return_scope_range_of_cases()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get());
}
/**
* This test scopeAppUid
*
* @covers \ProcessMaker\Model\Delegation::scopeAppUid()
* @test
*/
public function it_return_scope_app_uid()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->appUid($table->APP_UID)->get());
}
/**
* This test scopeLastThread
*
* @covers \ProcessMaker\Model\Delegation::scopeLastThread()
* @test
*/
public function it_return_scope_last_thread()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->lastThread()->get());
}
/**
* This test scopeSpecificCasesByUid
*
* @covers \ProcessMaker\Model\Delegation::scopeSpecificCasesByUid()
* @test
*/
public function it_return_scope_specific_cases_uid()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->specificCasesByUid([$table->APP_UID])->get());
}
/**
* This test scopeUserId
*
* @covers \ProcessMaker\Model\Delegation::scopeUserId()
* @test
*/
public function it_return_scope_user_id()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->userId($table->USR_ID)->get());
}
/** /**
* This test scopeWithoutUserId * This test scopeWithoutUserId
* *
@@ -151,6 +456,18 @@ class DelegationTest extends TestCase
$this->assertCount(1, $table->withoutUserId($table->TAS_ID)->get()); $this->assertCount(1, $table->withoutUserId($table->TAS_ID)->get());
} }
/**
* This test scopeProcessId
*
* @covers \ProcessMaker\Model\Delegation::scopeProcessId()
* @test
*/
public function it_return_scope_process_id()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->processId($table->PRO_ID)->get());
}
/** /**
* This test scopeTask * This test scopeTask
* *
@@ -160,7 +477,7 @@ class DelegationTest extends TestCase
public function it_return_scope_task() public function it_return_scope_task()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->task()->get()); $this->assertCount(1, $table->task($table->TAS_ID)->get());
} }
/** /**
@@ -175,6 +492,60 @@ class DelegationTest extends TestCase
$this->assertCount(1, $table->specificTasks([$table->TAS_ID])->get()); $this->assertCount(1, $table->specificTasks([$table->TAS_ID])->get());
} }
/**
* This test scopeTaskAssignType
*
* @covers \ProcessMaker\Model\Delegation::scopeTaskAssignType()
* @test
*/
public function it_return_scope_assign_type()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->taskAssignType('NORMAL')->get());
}
/**
* This test scopeExcludeTaskTypes
*
* @covers \ProcessMaker\Model\Delegation::scopeExcludeTaskTypes()
* @test
*/
public function it_return_scope_exclude_tas_types()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(0, $table->excludeTaskTypes(['NORMAL'])->get());
}
/**
* This test scopeSpecificTaskTypes
*
* @covers \ProcessMaker\Model\Delegation::scopeSpecificTaskTypes()
* @test
*/
public function it_return_scope_specific_tas_types()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->specificTaskTypes(['NORMAL'])->get());
}
/**
* This test scopeAppStatusId
*
* @covers \ProcessMaker\Model\Delegation::scopeAppStatusId()
* @test
*/
public function it_return_scope_status_id()
{
$application = factory(Application::class)->create([
'APP_STATUS_ID' => 2,
'APP_STATUS' => 'TO_DO'
]);
$table = factory(Delegation::class)->states('foreign_keys')->create([
'APP_NUMBER' => $application->APP_NUMBER
]);
$this->assertCount(1, $table->appStatusId()->get());
}
/** /**
* This checks to make sure pagination is working properly * This checks to make sure pagination is working properly
* *
@@ -412,11 +783,8 @@ class DelegationTest extends TestCase
*/ */
public function it_should_search_and_filter_by_app_title() public function it_should_search_and_filter_by_app_title()
{ {
$delegations = factory(Delegation::class, 1) $delegations = factory(Delegation::class, 1)->states('foreign_keys')->create();
->states('foreign_keys') $title = $delegations->last()->DEL_TITLE;
->create();
$title = $delegations->last()
->DEL_TITLE;
// We need to commit the records inserted because is needed for the "fulltext" index // We need to commit the records inserted because is needed for the "fulltext" index
DB::commit(); DB::commit();

View File

@@ -1168,12 +1168,13 @@ class AbstractCases implements CasesInterface
* Get the thread information * Get the thread information
* *
* @param array $thread * @param array $thread
* @param bool $addUserInfo
* @param bool $addThreadInfo
* *
* @return array * @return array
*/ */
public function threadInformation(array $thread) public function threadInformation(array $thread, $addUserInfo = false, $addThreadInfo = false)
{ {
$result = [];
$status = ''; $status = '';
$finishDate = 'now'; $finishDate = 'now';
$dateToCompare = date("Y-m-d H:i:s"); $dateToCompare = date("Y-m-d H:i:s");
@@ -1185,23 +1186,52 @@ class AbstractCases implements CasesInterface
$status = 'DRAFT'; $status = 'DRAFT';
} }
if ($thread['APP_STATUS'] === 'COMPLETED') { 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; $dateToCompare = $finishDate;
} }
// Variables of results
$threadTask = [];
$threadUser = [];
$threadTitle = [];
// Define the thread information // Define the thread information
$result['tas_title'] = $thread['TAS_TITLE']; $threadTask['tas_uid'] = !empty($thread['TAS_UID']) ? $thread['TAS_UID'] : '';
$result['user_id'] = $thread['USR_ID']; $threadTask['tas_title'] = $thread['TAS_TITLE'];
$result['due_date'] = $thread['DEL_TASK_DUE_DATE']; $threadTask['user_id'] = $thread['USR_ID'];
$result['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare); $threadTask['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$result['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : ''; $threadTask['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare);
$result['tas_color_label'] = (!empty($result['tas_color'])) ? self::TASK_COLORS[$result['tas_color']] : ''; $threadTask['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : '';
$result['tas_status'] = self::TASK_STATUS[$result['tas_color']]; $threadTask['tas_color_label'] = (!empty($threadTask['tas_color'])) ? self::TASK_COLORS[$threadTask['tas_color']] : '';
$result['unassigned'] = ($status === 'UNASSIGNED' ? true : false); $threadTask['tas_status'] = self::TASK_STATUS[$threadTask['tas_color']];
// Get the user tooltip information $threadTask['unassigned'] = ($status === 'UNASSIGNED' ? true : false);
$result['user_tooltip'] = User::getInformation($thread['USR_ID']); $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;
if (!$addUserInfo && !$addThreadInfo) {
// Only will return the pending task info
return $threadTask;
} else {
return $result; return $result;
} }
}
/** /**
* Set all properties * Set all properties

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases; namespace ProcessMaker\BusinessModel\Cases;
use G; use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
class Draft extends AbstractCases class Draft extends AbstractCases
@@ -120,11 +121,13 @@ class Draft extends AbstractCases
*/ */
public function getCounter() public function getCounter()
{ {
$query = Delegation::query()->select(); $query = Application::query()->select();
// Add the initial scope for draft cases // 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 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; namespace ProcessMaker\BusinessModel\Cases;
use G; use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
class Inbox extends AbstractCases class Inbox extends AbstractCases
@@ -82,6 +83,8 @@ class Inbox extends AbstractCases
$query->joinProcess(); $query->joinProcess();
// Join with users // Join with users
$query->joinUser(); $query->joinUser();
// Join with task
$query->JoinTask();
// Join with application for add the initial scope for TO_DO cases // Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId()); $query->inbox($this->getUserId());
/** Apply filters */ /** Apply filters */

View File

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

View File

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

View File

@@ -6,6 +6,7 @@ use G;
use ProcessMaker\Model\Application; use ProcessMaker\Model\Application;
use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\AppNotes;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task; use ProcessMaker\Model\Task;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
@@ -14,17 +15,15 @@ class Search extends AbstractCases
// Columns to see in the cases list // Columns to see in the cases list
public $columnsView = [ public $columnsView = [
// Columns view in the cases list // Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case # 'APPLICATION.APP_NUMBER', // Case #
'APP_DELEGATION.DEL_TITLE', // Case Title 'APPLICATION.APP_TITLE AS DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process 'PROCESS.PRO_TITLE', // Process
'APPLICATION.APP_STATUS', // Status 'APPLICATION.APP_STATUS', // Status
'APPLICATION.APP_CREATE_DATE', // Case create date 'APPLICATION.APP_CREATE_DATE', // Case create date
'APPLICATION.APP_FINISH_DATE', // Case finish date 'APPLICATION.APP_FINISH_DATE', // Case finish date
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case 'APPLICATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case 'APPLICATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
]; ];
/** /**
@@ -59,19 +58,35 @@ class Search extends AbstractCases
} }
// Specific case title // Specific case title
if (!empty($this->getCaseTitle())) { if (!empty($this->getCaseTitle())) {
$query->title($this->getCaseTitle()); // Join with delegation
$query->joinDelegation();
// Add the filter
// $query->title($this->getCaseTitle());
} }
// Filter by process // Filter by process
if ($this->getProcessId()) { 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 // Filter by user
if ($this->getUserId()) { if ($this->getUserId()) {
// Join with delegation
$query->joinDelegation();
// Add the filter
$query->userId($this->getUserId()); $query->userId($this->getUserId());
// Get only the open threads related to the user
$query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
} }
// Filter by task // Filter by task
if ($this->getTaskId()) { if ($this->getTaskId()) {
// Join with delegation
$query->joinDelegation();
// Add the filter
$query->task($this->getTaskId()); $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 // Specific start case date from
if (!empty($this->getStartCaseFrom())) { if (!empty($this->getStartCaseFrom())) {
@@ -89,41 +104,9 @@ class Search extends AbstractCases
if (!empty($this->getFinishCaseTo())) { if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo()); $query->finishCaseTo($this->getFinishCaseTo());
} }
/** This filter define the UNION */
// Filter related to the case status like ['DRAFT', 'TO_DO'] // Filter related to the case status like ['DRAFT', 'TO_DO']
if (!empty($this->getCaseStatuses())) { if (!empty($this->getCaseStatuses())) {
$statuses = $this->getCaseStatuses(); $query->statusIds($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();
} }
return $query; return $query;
@@ -136,32 +119,9 @@ class Search extends AbstractCases
*/ */
public function getData() public function getData()
{ {
$query = Delegation::query()->select($this->getColumnsView()); $query = Application::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'
);
// Join with process // Join with process
$query->joinProcess(); $query->joinProcess();
// Join with application
$query->joinApplication();
// Group by AppNumber
$query->groupBy('APP_NUMBER');
/** Apply filters */ /** Apply filters */
$this->filters($query); $this->filters($query);
/** Exclude the web entries does not submitted */ /** Exclude the web entries does not submitted */
@@ -186,12 +146,36 @@ class Search extends AbstractCases
// Get total case notes // Get total case notes
$item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']);
// Get the detail related to the open thread // Get the detail related to the open thread
if (!empty($item['THREADS'])) { $taskPending = [];
$result = $this->prepareTaskPending($item['THREADS'], false, $item['APP_STATUS'], $dateToCompare); $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_TASKS'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : [];
$item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : []; $item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : [];
$item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : []; $item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : [];
}
return $item; return $item;
}); });

View File

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

View File

@@ -20,32 +20,45 @@ class Application extends Model
// Status name and status id // Status name and status id
public static $app_status_values = ['DRAFT' => 1, 'TO_DO' => 2, 'COMPLETED' => 3, 'CANCELLED' => 4]; public static $app_status_values = ['DRAFT' => 1, 'TO_DO' => 2, 'COMPLETED' => 3, 'CANCELLED' => 4];
public function delegations() /**
{ * Current user related to the application
return $this->hasMany(Delegation::class, 'APP_UID', 'APP_UID'); */
}
public function currentUser() public function currentUser()
{ {
return $this->belongsTo(User::class, 'APP_CUR_USER', 'USR_UID'); return $this->belongsTo(User::class, 'APP_CUR_USER', 'USR_UID');
} }
/**
* Creator user related to the application
*/
public function creatorUser() public function creatorUser()
{ {
return $this->belongsTo(User::class, 'APP_INIT_USER', 'USR_UID'); return $this->belongsTo(User::class, 'APP_INIT_USER', 'USR_UID');
} }
/** /**
* Scope for query to get the positive cases * Scope a query to only include specific user
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @param int $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, $user)
{
return $query->where('APP_DELEGATION.USR_ID', '=', $user);
}
/**
* Scope for query to get the creator
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $usrUid
* *
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopePositivesCases($query) public function scopeCreator($query, $usrUid)
{ {
$result = $query->where('APP_NUMBER', '>', 0); return $query->where('APP_INIT_USER', '=', $usrUid);
return $result;
} }
/** /**
@@ -58,8 +71,108 @@ class Application extends Model
*/ */
public function scopeAppUid($query, $appUid) public function scopeAppUid($query, $appUid)
{ {
$result = $query->where('APP_UID', '=', $appUid); return $query->where('APP_UID', '=', $appUid);
return $result; }
/**
* Scope a query to only include specific cases by APP_UID
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $cases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSpecificCasesByUid($query, array $cases)
{
return $query->whereIn('APP_UID', $cases);
}
/**
* Scope for query to get the application by APP_NUMBER
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $appNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, $appNumber)
{
return $query->where('APPLICATION.APP_NUMBER', '=', $appNumber);
}
/**
* Scope for query to get the positive cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePositiveCases($query)
{
return $query->where('APPLICATION.APP_NUMBER', '>', 0);
}
/**
* Scope a query to only include specific cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $cases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSpecificCases($query, array $cases)
{
return $query->whereIn('APPLICATION.APP_NUMBER', $cases);
}
/**
* Scope more than one range of cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $rangeCases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRangeOfCases($query, array $rangeCases)
{
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesFrom($query, int $from)
{
return $query->where('APPLICATION.APP_NUMBER', '>=', $from);
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesTo($query, int $to)
{
return $query->where('APPLICATION.APP_NUMBER', '<=', $to);
} }
/** /**
@@ -72,8 +185,20 @@ class Application extends Model
*/ */
public function scopeStatusId($query, int $status) public function scopeStatusId($query, int $status)
{ {
$result = $query->where('APP_STATUS_ID', '=', $status); return $query->where('APP_STATUS_ID', '=', $status);
return $result; }
/**
* Scope a more status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $statuses
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatusIds($query, array $statuses)
{
return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses);
} }
/** /**
@@ -86,8 +211,104 @@ class Application extends Model
*/ */
public function scopeProUid($query, $proUid) public function scopeProUid($query, $proUid)
{ {
$result = $query->where('PRO_UID', '=', $proUid); return $query->where('APPLICATION.PRO_UID', '=', $proUid);
return $result; }
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateFrom($query, string $from)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateTo($query, string $to)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseFrom($query, string $from)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseTo($query, string $to)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific task
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $task
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTask($query, int $task)
{
return $query->where('APP_DELEGATION.TAS_ID', '=', $task);
}
/**
* Scope join with process
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinProcess($query)
{
$query->leftJoin('PROCESS', function ($leftJoin) {
$leftJoin->on('APPLICATION.PRO_UID', '=', 'PROCESS.PRO_UID');
});
return $query;
}
/**
* Scope join with delegation
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinDelegation($query)
{
$query->leftJoin('APP_DELEGATION', function ($leftJoin) {
$leftJoin->on('APPLICATION.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER');
});
return $query;
} }
/** /**
@@ -103,7 +324,7 @@ class Application extends Model
$query = Application::query() $query = Application::query()
->select() ->select()
->proUid($proUid) ->proUid($proUid)
->positivesCases() ->positiveCases()
->orderBy('APP_NUMBER', 'ASC'); ->orderBy('APP_NUMBER', 'ASC');
return $query->get(); return $query->get();
} }
@@ -183,7 +404,7 @@ class Application extends Model
->select() ->select()
->proUid($proUid) ->proUid($proUid)
->statusId($status) ->statusId($status)
->positivesCases(); ->positiveCases();
return $query->get()->count(['APP_NUMBER']); return $query->get()->count(['APP_NUMBER']);
} }

View File

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

View File

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