diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Report/ReportingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Report/ReportingTest.php new file mode 100644 index 000000000..6c0cd3712 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Report/ReportingTest.php @@ -0,0 +1,109 @@ +reporting = new Reporting(); + } + + /** + * Method tearDown. + */ + public function tearDown() + { + parent::tearDown(); + } + + /** + * This tests the method fillReportByUser(). + * @test + * @covers \ProcessMaker\Report\Reporting::fillReportByUser() + */ + public function it_should_test_method_fillReportByUser() + { + $dateInit = date("YYYY-MM-DD"); + $dateFinish = date("YYYY-MM-DD"); + + factory(Delegation::class)->create([ + 'DEL_DELEGATE_DATE' => $dateInit + ]); + + $this->reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); + $this->reporting->fillReportByUser($dateInit, $dateFinish); + + $result = DB::table("USR_REPORTING")->get(); + $this->assertInstanceOf('Illuminate\Support\Collection', $result); + } + + /** + * This tests the method fillReportByUser() waiting for an exception. + * @test + * @covers \ProcessMaker\Report\Reporting::fillReportByUser() + */ + public function it_should_test_method_fillReportByUser_waiting_for_an_exception() + { + //assertion Exception + $this->expectException(Exception::class); + + $dateInit = date("YYYY-MM-DD"); + $dateFinish = date("YYYY-MM-DD"); + $this->reporting->fillReportByUser($dateInit, $dateFinish); + } + + /** + * This tests the method fillReportByProcess(). + * @test + * @covers \ProcessMaker\Report\Reporting::fillReportByProcess() + */ + public function it_should_test_method_fillReportByProcess() + { + $dateInit = date("YYYY-MM-DD"); + $dateFinish = date("YYYY-MM-DD"); + + factory(Delegation::class)->create([ + 'DEL_DELEGATE_DATE' => $dateInit + ]); + + $this->reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); + $this->reporting->fillReportByProcess($dateInit, $dateFinish); + + $result = DB::table("PRO_REPORTING")->get(); + $this->assertInstanceOf('Illuminate\Support\Collection', $result); + } + + /** + * This tests the method fillReportByProcess() waiting for an exception. + * @test + * @covers \ProcessMaker\Report\Reporting::fillReportByProcess() + */ + public function it_should_test_method_fillReportByProcess_waiting_for_an_exception() + { + //assertion Exception + $this->expectException(Exception::class); + + $dateInit = date("YYYY-MM-DD"); + $dateFinish = date("YYYY-MM-DD"); + $this->reporting->fillReportByProcess($dateInit, $dateFinish); + } +} diff --git a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql index 8e7bae1c9..089eefdea 100644 --- a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql +++ b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql @@ -45,7 +45,10 @@ SELECT 0, NULL FROM - APP_CACHE_VIEW AS ACV + APPLICATION +INNER JOIN APP_DELEGATION AS ACV ON + APPLICATION.APP_NUMBER=ACV.APP_NUMBER AND + APPLICATION.PRO_UID=ACV.PRO_UID WHERE (ACV.DEL_DELEGATE_DATE BETWEEN CAST(@INIT_DATE AS DATETIME) AND CAST(@FINISH_DATE AS DATETIME)) AND ACV.DEL_DELEGATE_DATE IS NOT NULL diff --git a/workflow/engine/src/ProcessMaker/Report/Reporting.php b/workflow/engine/src/ProcessMaker/Report/Reporting.php new file mode 100644 index 000000000..936f7c40d --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Report/Reporting.php @@ -0,0 +1,76 @@ +pathToAppCacheFiles = $path; + } + + /** + * This populates the USR_REPORTING table. + * @param string $dateInit + * @param string $dateFinish + * @return void + * @throws Exception + */ + public function fillReportByUser(string $dateInit, string $dateFinish): void + { + $filenameSql = $this->pathToAppCacheFiles . "triggerFillReportByUser.sql"; + + if (!file_exists($filenameSql)) { + throw new Exception("File {$filenameSql} doesn't exist"); + } + + DB::statement("TRUNCATE TABLE USR_REPORTING"); + + $sql = explode(';', file_get_contents($filenameSql)); + + foreach ($sql as $key => $val) { + $val = str_replace('{init_date}', $dateInit, $val); + $val = str_replace('{finish_date}', $dateFinish, $val); + DB::statement($val); + } + } + + /** + * This populates the PRO_REPORTING table + * @param string $dateInit + * @param string $dateFinish + * @return void + * @throws Exception + */ + public function fillReportByProcess(string $dateInit, string $dateFinish): void + { + $filenameSql = $this->pathToAppCacheFiles . "triggerFillReportByProcess.sql"; + + if (!file_exists($filenameSql)) { + throw new Exception("File {$filenameSql} doesn't exist"); + } + + DB::statement("TRUNCATE TABLE PRO_REPORTING"); + + $sql = explode(';', file_get_contents($filenameSql)); + + foreach ($sql as $key => $val) { + $val = str_replace('{init_date}', $dateInit, $val); + $val = str_replace('{finish_date}', $dateFinish, $val); + DB::statement($val); + } + } +} diff --git a/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php b/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php index 9de092fe1..8dd09c6a4 100644 --- a/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php +++ b/workflow/engine/src/ProcessMaker/TaskScheduler/Task.php @@ -5,7 +5,6 @@ namespace ProcessMaker\TaskScheduler; use Application; use AppAssignSelfServiceValueGroupPeer; use AppAssignSelfServiceValuePeer; -use AppCacheView; use AppDelegation; use App\Jobs\TaskScheduler; use Bootstrap; @@ -26,6 +25,7 @@ use ProcessMaker\BusinessModel\TimerEvent; use ProcessMaker\BusinessModel\WebEntry; use ProcessMaker\Core\JobsManager; use ProcessMaker\Plugins\PluginRegistry; +use ProcessMaker\Report\Reporting; use Propel; use ResultSet; use SpoolRun; @@ -493,11 +493,11 @@ class Task $dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s"); - $appCacheView = new AppCacheView(); - $appCacheView->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); + $reporting = new Reporting(); + $reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); $this->setExecutionMessage("Calculating data to fill the 'User Reporting'..."); - $appCacheView->fillReportByUser($dateInit, $dateFinish); - setExecutionResultMessage("DONE"); + $reporting->fillReportByUser($dateInit, $dateFinish); + $this->setExecutionResultMessage("DONE"); } catch (Exception $e) { $this->setExecutionResultMessage("WITH ERRORS", "error"); if ($this->asynchronous === false) { @@ -537,11 +537,11 @@ class Task try { $dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s"); - $appcv = new AppCacheView(); - $appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); + $reporting = new Reporting(); + $reporting->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP); $this->setExecutionMessage("Calculating data to fill the 'Process Reporting'..."); - $appcv->fillReportByProcess($dateInit, $dateFinish); + $reporting->fillReportByProcess($dateInit, $dateFinish); $this->setExecutionResultMessage("DONE"); } catch (Exception $e) { $this->setExecutionResultMessage("WITH ERRORS", "error");