diff --git a/database/factories/ApplicationFactory.php b/database/factories/ApplicationFactory.php index 7223e9974..2688502b8 100644 --- a/database/factories/ApplicationFactory.php +++ b/database/factories/ApplicationFactory.php @@ -67,6 +67,15 @@ $factory->state(\ProcessMaker\Model\Application::class, 'foreign_keys', function ]; }); +$factory->state(\ProcessMaker\Model\Application::class, 'web_entry', function (Faker $faker) { + $appNumber = $faker->unique()->numberBetween(5000); + return [ + 'APP_NUMBER' => $appNumber * -1, + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]; +}); + $factory->state(\ProcessMaker\Model\Application::class, 'todo', function (Faker $faker) { return [ 'APP_NUMBER' => $faker->unique()->numberBetween(1000), diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index b86c42285..afc2c8ca2 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -86,6 +86,51 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function ]; }); +// Create a delegation with the foreign keys +$factory->state(\ProcessMaker\Model\Delegation::class, 'web_entry', function (Faker $faker) { + // Create values in the foreign key relations + $user = factory(\ProcessMaker\Model\User::class)->create(); + $category = factory(\ProcessMaker\Model\ProcessCategory::class)->create(); + $process = factory(\ProcessMaker\Model\Process::class)->create([ + 'PRO_CATEGORY' => $category->CATEGORY_UID, + 'CATEGORY_ID' => $category->CATEGORY_ID + ]); + $task = factory(\ProcessMaker\Model\Task::class)->create([ + 'PRO_UID' => $process->PRO_UID, + 'PRO_ID' => $process->PRO_ID + ]); + $application = factory(\ProcessMaker\Model\Application::class)->states('web_entry')->create([ + 'PRO_UID' => $process->PRO_UID, + 'APP_INIT_USER' => $user->USR_UID, + 'APP_CUR_USER' => $user->USR_UID + ]); + + // Return with default values + return [ + 'DELEGATION_ID' => $faker->unique()->numberBetween(5000), + 'APP_UID' => $application->APP_UID, + 'DEL_INDEX' => 1, + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_PREVIOUS' => 0, + 'PRO_UID' => $process->PRO_UID, + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'DEL_TYPE' => 'NORMAL', + 'DEL_THREAD' => 1, + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_PRIORITY' => 3, + 'DEL_DELEGATE_DATE' => $faker->dateTime(), + 'DEL_INIT_DATE' => $faker->dateTime(), + 'DEL_TASK_DUE_DATE' => $faker->dateTime(), + 'DEL_RISK_DATE' => $faker->dateTime(), + 'USR_ID' => $user->USR_ID, + 'PRO_ID' => $process->PRO_ID, + 'TAS_ID' => $task->TAS_ID, + 'DEL_DATA' => '', + 'DEL_TITLE' => $faker->word() + ]; +}); + // Create a open delegation $factory->state(\ProcessMaker\Model\Delegation::class, 'open', function (Faker $faker) { // Create dates with sense diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php index 5f3788ef6..52e234b6c 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php @@ -238,6 +238,27 @@ class SearchTest extends TestCase $this->assertNotEmpty($result); } + /** + * It tests web entry with negative appNumbers + * + * @covers \ProcessMaker\BusinessModel\Cases\Search::getData() + * @test + */ + public function it_get_web_entry_not_submitted() + { + // Create factories related to the delegation cases + $cases = $this->createSearch(); + $casesNotSubmitted = factory(Delegation::class, 5)->states('web_entry')->create(); + // Create new Search object + $search = new Search(); + // Set order by column value + $search->setOrderByColumn('APP_NUMBER'); + $result = $search->getData(); + // Review if the cases not submitted are not considered + $this->assertNotEmpty($result); + $this->assertEquals(count($result) , count($cases)); + } + /** * It tests the getCounter method * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index ac175ef45..8e39b420e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -162,6 +162,8 @@ class Search extends AbstractCases $query->groupBy('APP_NUMBER'); /** Apply filters */ $this->filters($query); + /** Exclude the web entries does not submitted */ + $query->positiveCases($query); /** Apply order and pagination */ // The order by clause $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 140c8535c..afbc1fe3c 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -455,6 +455,18 @@ class Delegation extends Model return $query->where('APP_DELEGATION.APP_NUMBER', '<=', $to); } + /** + * Scope for query to get the positive cases for avoid the web entry + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopePositiveCases($query) + { + return $query->where('APP_DELEGATION.APP_NUMBER', '>', 0); + } + /** * Scope more than one range of cases *