diff --git a/database/factories/ProcessUserFactory.php b/database/factories/ProcessUserFactory.php new file mode 100644 index 000000000..c0ab7c376 --- /dev/null +++ b/database/factories/ProcessUserFactory.php @@ -0,0 +1,12 @@ +define(\ProcessMaker\Model\ProcessUser::class, function(Faker $faker) { + return [ + 'PU_UID' => G::generateUniqueID(), + 'PRO_UID' => G::generateUniqueID(), + 'USR_UID' => G::generateUniqueID(), + 'PU_TYPE' => $faker->word + ]; +}); \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php new file mode 100644 index 000000000..83bb9d578 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php @@ -0,0 +1,1159 @@ +create(); + + // Create user + $user = factory(User::class)->create(); + + // Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + // Create 3 cases + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + // Create the registers in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + // Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising class + $Supervising = new Supervising(); + + // Set the user UID + $Supervising->setUserUid($user->USR_UID); + + // Set the user ID + $Supervising->setUserId($user->USR_ID); + + // Call the getData method + $res = $Supervising->getData(); + + // Asserts the result contains 3 registers + $this->assertCount(3, $res); + + // Asserts the user can get the list for the process in which is a supervisor + $this->assertContains($user->USR_UID, $res[0]); + $this->assertContains($user->USR_UID, $res[1]); + $this->assertContains($user->USR_UID, $res[2]); + } + + /** + * Tests the getData() method when the user belongs to a group supervisor + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_should_test_the_get_data_method_when_the_user_belong_to_a_group_supervisor() + { + //Create process + $process = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + $groupUser = factory(GroupUser::class)->create([ + 'USR_UID' => $user['USR_UID'] + ]); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $groupUser->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Call the getData method + $res = $Supervising->getData(); + + // Asserts the result contains 3 registers + $this->assertCount(3, $res); + + // Asserts the user can get the list for the process in which belong to a group supervisor + $this->assertContains($user->USR_UID, $res[0]); + $this->assertContains($user->USR_UID, $res[1]); + $this->assertContains($user->USR_UID, $res[2]); + } + + /** + * Tests the getData() method when the user is not a supervisor neither belongs to a group supervisor + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_should_test_the_get_data_method_when_the_user_is_not_supervisor() + { + //Create process + $process = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create(); + $app2 = factory(Application::class)->states('todo')->create(); + $app3 = factory(Application::class)->states('todo')->create(); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app1['APP_NUMBER'] + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app2['APP_NUMBER'] + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app3['APP_NUMBER'] + ]); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Call the getData method + $res = $Supervising->getData(); + + + // Asserts the result + $this->assertEmpty($res); + } + + /** + * Tests the getCounter() method + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getCounter() + * @test + */ + public function it_should_count_the_data() + { + //Create process + $process = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + //Create 3 cases + $app1 = factory(Application::class)->states('todo')->create(); + $app2 = factory(Application::class)->states('todo')->create(); + $app3 = factory(Application::class)->states('todo')->create(); + + //Create the registers in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app1['APP_NUMBER'] + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app2['APP_NUMBER'] + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'APP_NUMBER' => $app3['APP_NUMBER'] + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Call the getCounter method + $res = $Supervising->getCounter(); + + //Assert the counter + $this->assertEquals(3, $res); + } + + /** + * Tests the filter by APP_NUMBER + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_filters_by_app_number() + { + //Create process + $process = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + $Supervising->setCaseNumber($app3['APP_NUMBER']); + + //Call the getData method + $res = $Supervising->getData(); + + // Asserts the result contains 3 registers + $this->assertCount(1, $res); + //Asserts that the result contains the app number searched + $this->assertContains($app3['APP_NUMBER'], $res[0]); + } + + /** + * Tests the filter by process + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_filters_by_process() + { + //Create process + $process = factory(Process::class)->create(); + $process2 = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process2->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process2->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Set the process Id filter + $Supervising->setProcessId($process2['PRO_ID']); + + //Call the getData method + $res = $Supervising->getData(); + + $this->assertCount(1, $res); + $this->assertContains($process2['PRO_ID'], $res[0]); + } + + /** + * Tests the order by value + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_orders_the_query_by_column() + { + //Create process + $process = factory(Process::class)->create(); + $process2 = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process2->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process2->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Set the orderby value + $Supervising->setOrderByColumn('APPLICATION.APP_NUMBER'); + + //Call the getData method + $res = $Supervising->getData(); + + $this->assertCount(3, $res); + $this->assertTrue($res[0]['APP_NUMBER'] > $res[1]['APP_NUMBER']); + } + + /** + * Tests the limit in the order by clausule + * + * covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @test + */ + public function it_set_the_limit_in_the_order_by_clausule() + { + //Create process + $process = factory(Process::class)->create(); + $process2 = factory(Process::class)->create(); + + //Create user + $user = factory(User::class)->create(); + + //Create a task + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => '', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'NORMAL', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID, + ]); + + $app1 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app2 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + $app3 = factory(Application::class)->states('todo')->create([ + 'APP_STATUS' => 'TO_DO', + 'APP_STATUS_ID' => 2, + 'PRO_UID' => $process2->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID, + ]); + + //Create the register in delegation + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app1['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app1['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app2['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'PRO_UID' => $process->PRO_UID, + 'APP_NUMBER' => $app2['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task->TAS_ID, + 'TAS_UID' => $task->TAS_UID, + 'DEL_THREAD_STATUS' => 'CLOSED', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 1, + 'DEL_PREVIOUS' =>0 + ]); + factory(Delegation::class, 1)->create([ + "APP_UID" => $app3['APP_UID'], + 'TAS_ID' => $task2->TAS_ID, + 'TAS_UID' => $task2->TAS_UID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process2->PRO_ID, + 'PRO_UID' => $process2->PRO_UID, + 'APP_NUMBER' => $app3['APP_NUMBER'], + 'DEL_INDEX' => 2, + 'DEL_PREVIOUS' =>1 + ]); + + //Create the register in the ProcessUser table + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + factory(ProcessUser::class)->create( + [ + 'PRO_UID' => $process2->PRO_UID, + 'USR_UID' => $user->USR_UID, + 'PU_TYPE' => 'SUPERVISOR' + ] + ); + + // Instance the Supervising object + $Supervising = new Supervising(); + + //Set the user UID + $Supervising->setUserUid($user->USR_UID); + + //Set the user ID + $Supervising->setUserId($user->USR_ID); + + //Set the limit value + $Supervising->setLimit(1); + + //Call the getData method + $res = $Supervising->getData(); + + $this->assertCount(1, $res); + } +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php new file mode 100644 index 000000000..c56d72b72 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -0,0 +1,60 @@ +getUserUid()); + + // Start tthe query for get the cases related to the user + $query = Delegation::query()->select(); + + $query->inbox($this->getUserId()); + + $query->categoryProcess($this->getCategoryUid()); + + $query->processInList($processes); + + $query->joinPreviousIndex(); + + $query->joinPreviousUser(); + + if (!empty($this->getCaseNumber())) { + $query->case($this->getCaseNumber()); + } + + if (!empty($this->getProcessId())) { + $query->processId($this->getProcessId()); + } + + //The order by clause + $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); + + //The limit clause + $query->offset($this->getOffset())->limit($this->getLimit()); + + return $query->get()->values()->toArray(); + } + + /** + * Gets the total of Review cases + * + * @return int + */ + public function getCounter() + { + $quantity = $this->getData(); + return count($quantity); + } +} diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index f9b823e63..de923c180 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -62,7 +62,7 @@ class Delegation extends Model */ public function scopeThreadOpen($query) { - return $query->where('DEL_THREAD_STATUS', '=', 'OPEN'); + return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); } /** @@ -523,6 +523,53 @@ class Delegation extends Model return $query; } + /** + * Scope delegation table + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinPreviousIndex($query) + { + $query->leftJoin('APP_DELEGATION AS AD', function( $leftJoin) { + $leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'AD.APP_NUMBER') + ->on('APP_DELEGATION.DEL_PREVIOUS', '=', 'AD.DEL_INDEX'); + }); + + return $query; + } + + /** + * Scope users table as previous + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinPreviousUser($query) + { + $query->leftJoin('USERS AS PREVIOUS', function ($leftJoin) { + $leftJoin->on('AD.USR_UID', '=', 'PREVIOUS.USR_UID'); + }); + + return $query; + } + + /** + * Scope the Process is in list + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $processes + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeProcessInList($query, $processes) + { + $query->whereIn('PROCESS.PRO_ID', $processes); + return $query; + } + /** * Get specific cases unassigned that the user can view * diff --git a/workflow/engine/src/ProcessMaker/Model/ProcessUser.php b/workflow/engine/src/ProcessMaker/Model/ProcessUser.php new file mode 100644 index 000000000..7f9f3b79f --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/ProcessUser.php @@ -0,0 +1,105 @@ +where('USR_UID', $userUid); + $query->where('PU_TYPE', 'SUPERVISOR'); + $query->joinProcess(); + + return $query; + } + + /** + * Scope process group supervisor + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $userUid + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeProcessGroupSupervisor($query, $userUid) + { + $query->where('PU_TYPE', 'GROUP_SUPERVISOR'); + $query->leftJoin('GROUP_USER', function ($leftJoin) use ($userUid) { + $leftJoin->on('PROCESS_USER.USR_UID', '=', 'GROUP_USER.GRP_UID') + ->where('GROUP_USER.USR_UID', $userUid); + }); + $query->joinProcess(); + + return $query; + } + + /** + * Scope join with process table + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinProcess($query) + { + $query->leftJoin('PROCESS', function ($leftJoin) { + $leftJoin->on('PROCESS.PRO_UID', '=', 'PROCESS_USER.PRO_UID'); + }); + + return $query; + } + + /** + * It returns a list of processes ids as an array + * + * @param array $processes + * @return array + */ + public static function getListOfProcessUid($processes) + { + $res = (array_map(function ($x) { + if (array_key_exists('PRO_ID', $x)) { + return $x['PRO_ID']; + } + }, $processes)); + + return array_filter($res); + } + + /** + * It returns a list of processes of the supervisor + * + * @param string $userUid + * @return array + */ + public static function getProcessesOfSupervisor($userUid) + { + $query1 = ProcessUser::query()->select(['PRO_ID']); + $query1->processSupervisor($userUid); + $processes = $query1->get()->values()->toArray(); + + $query2 = ProcessUser::query()->select(['PRO_ID']); + $query2->processGroupSupervisor($userUid); + + array_push($processes, $query2->get()->values()->toArray()); + + $processes = ProcessUser::getListOfProcessUid($processes); + + return $processes; + } +} \ No newline at end of file