diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php new file mode 100644 index 000000000..2b48c4247 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php @@ -0,0 +1,1575 @@ +create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the USR_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service and self-service value based + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in self service + factory(Delegation::class, 15)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self service value based + factory(Delegation::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(30, $result); + } + + /** + * This checks the counters is working properly in self-service group assigned + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_group_assigned() + { + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the GRP_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create a case + $application = factory(Application::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service user and group assigned in parallel task + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() + { + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task1 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task1->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task2 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task2->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task3 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task3->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task4 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task4->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service related to the task1 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task2 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task3 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task3->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task4 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task4->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(40, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel task + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID] + * @covers ::getCounter + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task1 self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 10)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task2 self service value based + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task2->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $result = $unassigned->getCounter(); + $this->assertEquals(25, $result); + } + + /** + * This checks to make sure pagination is working properly in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_paged() + { + //Create process + $process = factory(Process::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2001, + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2002, + ]); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + $res = factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 26)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + + + // Get first page + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + $unassigned->setOrderDirection('DESC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get second page + $unassigned->setOffset(25); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get third page + $unassigned->setOffset(50); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(1, $results); + } + + /** + * This checks to make sure pagination is working properly in elf-service-value-based when the variable has a value related with the USR_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] + * @covers ::getData + * @test + */ + public function it_should_return_self_service_value_based_usr_uid_paged() + { + //Create process + $process = factory(Process::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2001, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create application + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2002, + ]); + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + + //Create the register in delegation relate to self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 26)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + + // Get first page + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + $unassigned->setOrderDirection('DESC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get second page + $unassigned->setOffset(25); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get third page + $unassigned->setOffset(50); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(1, $results); + } + + /** + * This checks to make sure pagination is working properly in self-service group assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_group_assigned_paged() + { + // Create process + $process = factory(Process::class)->create(); + // Create group + $group = factory(Groupwf::class)->create(); + // Create user + $user = factory(User::class)->create(); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + ]); + //Create application + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + ]); + // Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + // Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + // Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + // Create a task self service + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + // Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task2->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + // Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 26)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + // Get first page + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + $unassigned->setOrderDirection('DESC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get second page + $unassigned->setOffset(25); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get third page + $unassigned->setOffset(50); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(1, $results); + } + + /** + * This checks to make sure pagination is working properly in self-service-value-based when the variable has a value related with the GRP_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] + * @covers ::getData + * @test + */ + public function it_should_return_self_service_group_value_based_assigned_paged() + { + //Create process + $process = factory(Process::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create a case + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + ]); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'APP_UID' => $application2->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 26)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + // Get first page + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + $unassigned->setOrderDirection('DESC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get second page + $unassigned->setOffset(25); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(25, $results); + // Get third page + $unassigned->setOffset(50); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertCount(1, $results); + } + + /** + * This ensures ordering ascending and descending works by case number APP_NUMBER in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_by_case_number() + { + //Create process + $process = factory(Process::class)->create(); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2001, + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2002, + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + // Get first page, the minor case id + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + $results = $unassigned->getData(); + $this->assertEquals(2001, $results[0]['APP_NUMBER']); + $this->assertEquals(2001, $results[1]['APP_NUMBER']); + $this->assertEquals(2002, $results[2]['APP_NUMBER']); + $this->assertEquals(2002, $results[3]['APP_NUMBER']); + // Get first page, the major case id + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals(2002, $results[0]['APP_NUMBER']); + $this->assertEquals(2002, $results[1]['APP_NUMBER']); + $this->assertEquals(2001, $results[2]['APP_NUMBER']); + $this->assertEquals(2001, $results[3]['APP_NUMBER']); + } + + /** + * This ensures ordering ascending and descending works by case title APP_TITLE in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_by_case_title() + { + //Create process + $process = factory(Process::class)->create(); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2001, + 'APP_TITLE' => 'Request # 2001' + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_NUMBER' => 2002, + 'APP_TITLE' => 'Request # 2002' + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APPLICATION.APP_TITLE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor case title + $results = $unassigned->getData(); + $this->assertEquals('Request # 2001', $results[0]['APP_TITLE']); + $this->assertEquals('Request # 2001', $results[1]['APP_TITLE']); + $this->assertEquals('Request # 2002', $results[2]['APP_TITLE']); + $this->assertEquals('Request # 2002', $results[3]['APP_TITLE']); + // Get first page, the major case title + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('Request # 2002', $results[0]['APP_TITLE']); + $this->assertEquals('Request # 2002', $results[1]['APP_TITLE']); + $this->assertEquals('Request # 2001', $results[2]['APP_TITLE']); + $this->assertEquals('Request # 2001', $results[3]['APP_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by case title PRO_TITLE in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_by_process() + { + //Create process + $process1 = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]); + $process2 = factory(Process::class)->create([ + 'PRO_TITLE' => 'Egypt Supplier Payment Proposal' + ]); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process1->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process1->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process2->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('PRO_TITLE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor process title + $results = $unassigned->getData(); + $this->assertEquals('China Supplier Payment Proposal', $results[0]['PRO_TITLE']); + $this->assertEquals('China Supplier Payment Proposal', $results[1]['PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[2]['PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[3]['PRO_TITLE']); + // Get first page, the major process title + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[0]['PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[1]['PRO_TITLE']); + $this->assertEquals('China Supplier Payment Proposal', $results[2]['PRO_TITLE']); + $this->assertEquals('China Supplier Payment Proposal', $results[3]['PRO_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by task title TAS_TITLE in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_by_task_title() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'TAS_TITLE' => 'Initiate Request', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'TAS_TITLE' => 'Waiting for AP Manager Validation', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task1->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task1->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('TAS_TITLE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor task title + $results = $unassigned->getData(); + $this->assertEquals('Initiate Request', $results[0]['TAS_TITLE']); + $this->assertEquals('Initiate Request', $results[1]['TAS_TITLE']); + $this->assertEquals('Waiting for AP Manager Validation', $results[2]['TAS_TITLE']); + $this->assertEquals('Waiting for AP Manager Validation', $results[3]['TAS_TITLE']); + // Get first page, the major task title + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('Waiting for AP Manager Validation', $results[0]['TAS_TITLE']); + $this->assertEquals('Waiting for AP Manager Validation', $results[1]['TAS_TITLE']); + $this->assertEquals('Initiate Request', $results[2]['TAS_TITLE']); + $this->assertEquals('Initiate Request', $results[3]['TAS_TITLE']); + } + + /** + * This ensures ordering ascending and descending works by due date DEL_TASK_DUE_DATE in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_due_date() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'TAS_TITLE' => 'Initiate Request', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_TASK_DUE_DATE' => '2019-04-01 00:00:00' + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_TASK_DUE_DATE' => '2019-01-01 00:00:00' + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('DEL_TASK_DUE_DATE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor due date + $results = $unassigned->getData(); + $this->assertEquals('2019-01-01 00:00:00', $results[0]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[1]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[2]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[3]['DEL_TASK_DUE_DATE']); + // Get first page, the major due date + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('2019-04-01 00:00:00', $results[0]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[1]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[2]['DEL_TASK_DUE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[3]['DEL_TASK_DUE_DATE']); + } + + /** + * This ensures ordering ascending and descending works by last modified APP_UPDATE_DATE in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_return_self_service_user_assigned_sort_last_modified() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_UPDATE_DATE' => '2019-04-01 00:00:00' + ]); + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_UPDATE_DATE' => '2019-01-01 00:00:00' + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'TAS_TITLE' => 'Initiate Request', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_UPDATE_DATE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor update date + $results = $unassigned->getData(); + $this->assertEquals('2019-01-01 00:00:00', $results[0]['APP_UPDATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[1]['APP_UPDATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[2]['APP_UPDATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[3]['APP_UPDATE_DATE']); + // Get first page, the major update date + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('2019-04-01 00:00:00', $results[0]['APP_UPDATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[1]['APP_UPDATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[2]['APP_UPDATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[3]['APP_UPDATE_DATE']); + } + + /** + * This ensures searching by newest than and review the page in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_search_self_service_user_assigned_by_newest_than() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_DELEGATE_DATE' => '2019-04-01 00:00:00' + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_DELEGATE_DATE' => '2019-01-01 00:00:00' + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setNewestThan('2019-01-01'); + $unassigned->setOrderByColumn('DEL_DELEGATE_DATE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get the newest than (>=) delegate date + $results = $unassigned->getData(); + $this->assertEquals('2019-01-01 00:00:00', $results[0]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[1]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[2]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[3]['DEL_DELEGATE_DATE']); + // Get the newest than (>=) delegate date + $unassigned->setNewestThan('2019-04-01'); + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('2019-04-01 00:00:00', $results[0]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[1]['DEL_DELEGATE_DATE']); + // Get the newest than (>=) delegate date + $unassigned->setNewestThan('2019-05-01'); + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEmpty($results); + } + + /** + * This ensures searching by newest than and review the page in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_search_self_service_user_assigned_by_oldest_than() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_DELEGATE_DATE' => '2019-04-01 00:00:00' + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + 'DEL_DELEGATE_DATE' => '2019-01-01 00:00:00' + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOldestThan('2019-02-01'); + $unassigned->setOrderByColumn('DEL_DELEGATE_DATE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get the oldest than (<=) delegate date + $results = $unassigned->getData(); + $this->assertEquals('2019-01-01 00:00:00', $results[0]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[1]['DEL_DELEGATE_DATE']); + // Get the oldest than (<=) delegate date + $unassigned->setOldestThan('2019-04-01'); + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEquals('2019-04-01 00:00:00', $results[0]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-04-01 00:00:00', $results[1]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[2]['DEL_DELEGATE_DATE']); + $this->assertEquals('2019-01-01 00:00:00', $results[3]['DEL_DELEGATE_DATE']); + // Get the oldest than (<=) delegate date + $unassigned->setOldestThan('2018-12-01'); + $unassigned->setOrderDirection('DESC'); + $results = $unassigned->getData(); + $this->assertEmpty($results); + } + + /** + * This ensures searching specific cases and review the page in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_search_self_service_user_assigned_specific_case_uid() + { + //Create process + $process = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]);; + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create application + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 1)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0 + ]); + factory(Delegation::class, 1)->create([ + 'APP_UID' => $application2->APP_UID, + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0 + ]); + + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_UID'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get the specific case uid + $unassigned->setCaseUid($application1->APP_UID); + $results = $unassigned->getData(); + $this->assertEquals($application1->APP_UID, $results[0]['APP_UID']); + + // Get the specific case uid + $unassigned->setCaseUid($application2->APP_UID); + $results = $unassigned->getData(); + $this->assertEquals($application2->APP_UID, $results[0]['APP_UID']); + } + + /** + * This ensures searching specific cases and review the page in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_search_self_service_user_assigned_specific_cases_uid_array() + { + //Create process + $process = factory(Process::class)->create(); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create application + $application2 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 1)->create([ + 'APP_UID' => $application1->APP_UID, + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0 + ]); + factory(Delegation::class, 1)->create([ + 'APP_UID' => $application2->APP_UID, + 'APP_NUMBER' => $application2->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0 + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setCasesUids([$application1->APP_UID, $application2->APP_UID]); + $unassigned->setOrderByColumn('APP_DELEGATION.APP_UID'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get the specific cases uid's + $results = $unassigned->getData(); + $this->assertCount(2, $results); + + // Get the specific cases uid's + $unassigned->setCasesUids([$application1->APP_UID]); + $results = $unassigned->getData(); + $this->assertEquals($application1->APP_UID, $results[0]['APP_UID']); + + // Get the specific cases uid's + $unassigned->setCasesUids([$application2->APP_UID]); + $results = $unassigned->getData(); + $this->assertEquals($application2->APP_UID, $results[0]['APP_UID']); + } + + /** + * This ensures searching specific process and review the page in self-service-user-assigned + * @covers ::getData + * @test + */ + public function it_should_search_self_service_user_assigned_specific_process() + { + //Create process + $process1 = factory(Process::class)->create([ + 'PRO_TITLE' => 'China Supplier Payment Proposal' + ]); + $process2 = factory(Process::class)->create([ + 'PRO_TITLE' => 'Egypt Supplier Payment Proposal' + ]); + //Create application + $application1 = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2 + ]); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process1->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process1->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + factory(Delegation::class, 2)->create([ + 'APP_NUMBER' => $application1->APP_NUMBER, + 'TAS_ID' => $task->TAS_ID, + 'PRO_ID' => $process2->id, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + $unassigned = new Unassigned; + $unassigned->setUserUid($user->USR_UID); + $unassigned->setOrderByColumn('PRO_TITLE'); + $unassigned->setOrderDirection('ASC'); + $unassigned->setProcessId($process1->id); + $unassigned->setOffset(0); + $unassigned->setLimit(25); + // Get first page, the minor process title + $results = $unassigned->getData(); + $this->assertEquals('China Supplier Payment Proposal', $results[0]['PRO_TITLE']); + $this->assertEquals('China Supplier Payment Proposal', $results[1]['PRO_TITLE']); + // Get first page, the major process title + $unassigned->setProcessId($process2->id); + $results = $unassigned->getData(); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[0]['PRO_TITLE']); + $this->assertEquals('Egypt Supplier Payment Proposal', $results[1]['PRO_TITLE']); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php new file mode 100644 index 000000000..559d14d1f --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php @@ -0,0 +1,72 @@ +select(); + // Add the initial scope for unassigned cases + $query->selfService($this->getUserUid()); + // Add join for application, for get the case title when the case status is TO_DO + $query->appStatusId(Application::STATUS_TODO); + // Add join for process, but only for certain scenarios such as category or process + if ($this->getCategoryUid() || $this->getProcessUid() || $this->getOrderByColumn() === 'PRO_TITLE') { + $query->categoryProcess($this->getCategoryUid()); + } + // Specific process + if ($this->getProcessId()) { + $query->processId($this->getProcessId()); + } + // Date range filter, this is used from mobile GET /light/unassigned + if ($this->getNewestThan()) { + $query->delegateDateFrom($this->getNewestThan()); + } + if ($this->getOldestThan()) { + $query->delegateDateTo($this->getOldestThan()); + } + // Specific case uid + if (!empty($this->getCaseUid())) { + $query->appUid($this->getCaseUid()); + } + // Specific cases + if (!empty($this->getCasesUids())) { + $query->specificCasesByUid($this->getCasesUids()); + } + // Add any sort if needed + if ($this->getOrderByColumn()) { + $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); + } + // Add pagination to the query + $query->offset($this->getOffset())->limit($this->getLimit()); + // Get the data + $results = $query->get(); + + return $results->values()->toArray(); + } + + /** + * Count the self-services cases by user + * + * @return int + */ + public function getCounter() + { + $query = Delegation::query()->select(); + $query->selfService($this->getUserUid()); + + return $query->count(); + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index b2cca4de3..092582f32 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -12,6 +12,11 @@ class Application extends Model public $incrementing = false; // No timestamps public $timestamps = false; + // Status id + const STATUS_DRAFT = 1; + const STATUS_TODO = 2; + const STATUS_COMPLETED = 3; + const STATUS_CANCELED = 4; public function delegations() { diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 9457679c7..76686adfe 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -10,6 +10,9 @@ use ProcessMaker\Core\System; class Delegation extends Model { + // Class constants + const PRIORITIES_MAP = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH']; + protected $table = "APP_DELEGATION"; // We don't have our standard timestamp columns @@ -51,71 +54,22 @@ class Delegation extends Model return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); } - /** - * Scope a query to get the delegations from a case by APP_UID - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $appUid - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeAppUid($query, $appUid) - { - return $query->where('APP_UID', '=', $appUid); - } - /** * Scope a query to only include open threads * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeIsThreadOpen($query) + public function scopeThreadOpen($query) { return $query->where('DEL_THREAD_STATUS', '=', 'OPEN'); } - /** - * Scope a query to only include threads without user - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeNoUserInThread($query) - { - return $query->where('USR_ID', '=', 0); - } - - /** - * Scope a query to only include specific tasks - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $tasks - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeTasksIn($query, array $tasks) - { - return $query->whereIn('APP_DELEGATION.TAS_ID', $tasks); - } - - /** - * Scope a query to only include a specific case - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param integer $appNumber - * - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeCase($query, $appNumber) - { - return $query->where('APP_NUMBER', '=', $appNumber); - } - /** * Scope a query to only include a specific index * * @param \Illuminate\Database\Eloquent\Builder $query - * @param integer $index + * @param int $index * * @return \Illuminate\Database\Eloquent\Builder */ @@ -124,11 +78,161 @@ class Delegation extends Model return $query->where('DEL_INDEX', '=', $index); } + /** + * Scope a query to only include a specific delegate date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $from + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeDelegateDateFrom($query, $from) + { + return $query->where('DEL_DELEGATE_DATE', '>=', $from); + } + + /** + * Scope a query to only include a specific delegate date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $to + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeDelegateDateTo($query, $to) + { + return $query->where('DEL_DELEGATE_DATE', '<=', $to); + } + + /** + * Scope a query to get only the date on time + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeOnTime($query) + { + return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) > 0'); + } + + /** + * Scope a query to get only the date at risk + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAtRisk($query) + { + return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) < 0 AND TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) > 0'); + } + + /** + * Scope a query to get only the date overdue + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeOverdue($query) + { + return $query->whereRaw('TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) < 0'); + } + + /** + * Scope a query to only include a specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $appNumber + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCase($query, $appNumber) + { + return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber); + } + + /** + * 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('APP_DELEGATION.APP_NUMBER', $cases); + } + + /** + * Scope a query to get the delegations from a case by APP_UID + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $appUid + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppUid($query, $appUid) + { + return $query->where('APP_DELEGATION.APP_UID', '=', $appUid); + } + + /** + * 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_DELEGATION.APP_UID', $cases); + } + + /** + * Scope a query to only include specific user + * + * @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 a query to only include threads without user + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeWithoutUserId($query) + { + return $query->where('APP_DELEGATION.USR_ID', '=', 0); + } + + /** + * Scope a query to only include specific process + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $process + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeProcessId($query, $process) + { + return $query->where('APP_DELEGATION.PRO_ID', $process); + } + /** * Scope a query to only include a specific task * * @param \Illuminate\Database\Eloquent\Builder $query - * @param integer $task + * @param int $task * * @return \Illuminate\Database\Eloquent\Builder */ @@ -137,6 +241,151 @@ class Delegation extends Model return $query->where('APP_DELEGATION.TAS_ID', '=', $task); } + /** + * Scope a query to only include specific tasks + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $tasks + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeSpecificTasks($query, array $tasks) + { + return $query->whereIn('APP_DELEGATION.TAS_ID', $tasks); + } + + /** + * Scope a join with task and include a specific task assign type: + * BALANCED|MANUAL|EVALUATE|REPORT_TO|SELF_SERVICE|STATIC_MI|CANCEL_MI|MULTIPLE_INSTANCE|MULTIPLE_INSTANCE_VALUE_BASED + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $taskType + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTaskAssignType($query, $taskType = 'SELF_SERVICE') + { + $query->join('TASK', function ($join) use ($taskType) { + $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') + ->where('TASK.TAS_ASSIGN_TYPE', '=', $taskType); + }); + + return $query; + } + + /** + * Scope a join with task and include a specific task assign type: + * NORMAL|ADHOC|SUBPROCESS|HIDDEN|GATEWAYTOGATEWAY|WEBENTRYEVENT|END-MESSAGE-EVENT|START-MESSAGE-EVENT| + * INTERMEDIATE-THROW-MESSAGE-EVENT|INTERMEDIATE-CATCH-MESSAGE-EVENT|SCRIPT-TASK|START-TIMER-EVENT| + * INTERMEDIATE-CATCH-TIMER-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-EVENT|SERVICE-TASK + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $taskTypes + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeSpecificTaskTypes($query, array $taskTypes) + { + $query->join('TASK', function ($join) use ($taskTypes) { + $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') + ->whereNotIn('TASK.TAS_TYPE', '=', $taskTypes); + }); + + return $query; + } + + /** + * Scope a join with APPLICATION with specific app status + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $statusId + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppStatusId($query, $statusId = 2) + { + $query->join('APPLICATION', function ($join) use ($statusId) { + $join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER') + ->where('APPLICATION.APP_STATUS_ID', $statusId); + }); + + return $query; + } + + /** + * Scope a join with APPLICATION with specific app status + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $category + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCategoryProcess($query, $category = '') + { + $query->join('PROCESS', function ($join) use ($category) { + $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); + if ($category) { + $join->where('PROCESS.PRO_CATEGORY', $category); + } + }); + + return $query; + } + + /** + * Scope a self service cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $user + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeSelfService($query, $user) + { + // Add Join with task filtering only the type self-service + $query->taskAssignType('SELF_SERVICE'); + // Filtering the open threads and without users + $query->threadOpen()->withoutUserId(); + // Filtering the cases unassigned that the user can view + $this->casesUnassigned($query, $user); + + return $query; + } + + /** + * Get specific cases unassigned that the user can view + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $usrUid + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function casesUnassigned(&$query, $usrUid) + { + //Get the task self services related to the user + $taskSelfService = TaskUser::getSelfServicePerUser($usrUid); + //Get the task self services value based related to the user + $selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid); + + //Get the cases unassigned + if (!empty($selfServiceValueBased)) { + $query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) { + //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 + $query->orWhere(function ($query) use ($case) { + $query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']); + }); + } + }); + } else { + //Get the cases related to the task self service + $query->specificTasks($taskSelfService); + } + + return $query; + } + /** * Searches for delegations which match certain criteria * @@ -442,7 +691,7 @@ class Delegation extends Model * @param string $appUid * @return array * - * @see ProcessMaker\BusinessModel\Cases:getStatusInfo() + * @see \ProcessMaker\BusinessModel\Cases:getStatusInfo() */ public static function getParticipatedInfo($appUid) { @@ -615,7 +864,6 @@ class Delegation extends Model $result = DB::selectOne($query); $count = $result->aggregate; } - // Return data return $count; } @@ -737,4 +985,37 @@ class Delegation extends Model return $thread; } + + /** + * Helper to get the priority code from a given value + * + * @param int $priorityValue + * + * @return string + * + * @throws Exception + */ + public static function getPriorityCode($priorityValue) + { + if (!empty(self::PRIORITIES_MAP[$priorityValue])) { + $priorityCode = self::PRIORITIES_MAP[$priorityValue]; + } else { + throw new Exception("Priority value {$priorityValue} is not valid."); + } + return $priorityCode; + } + + /** + * Helper to get the priority label from a given value + * + * @param int $priorityValue + * + * @return string + */ + public static function getPriorityLabel($priorityValue) + { + $priorityCode = self::getPriorityCode($priorityValue); + + return G::LoadTranslation("ID_PRIORITY_{$priorityCode}"); + } }