From e3bb74fb8a64515123a1daf6625585e6929849b0 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Mon, 5 Apr 2021 09:15:22 -0400 Subject: [PATCH 1/6] PMCORE-2847 --- .../content/translations/english/processmaker.en.po | 12 ++++++++++++ workflow/engine/data/mysql/insert.sql | 2 ++ 2 files changed, 14 insertions(+) diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index 7e1b59de9..812a95cce 100755 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -3497,6 +3497,12 @@ msgstr "Case Demo" msgid "The Case was deleted successfully." msgstr "The Case was deleted successfully." +# TRANSLATION +# LABEL/ID_CASE_UID +#: LABEL/ID_CASE_UID +msgid "Case Uid" +msgstr "Case Uid" + # TRANSLATION # LABEL/ID_CASES #: LABEL/ID_CASES @@ -11009,6 +11015,12 @@ msgstr "Last Name" msgid "Last Employee" msgstr "Last Employee" +# TRANSLATION +# LABEL/ID_LAST_DATE +#: LABEL/ID_LAST_DATE +msgid "Last Update" +msgstr "Last Update" + # TRANSLATION # LABEL/ID_LAST_LOGIN #: LABEL/ID_LAST_LOGIN diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index cfdf35eb7..2b8e07138 100755 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -57390,6 +57390,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_CASECANCEL','en','No actions available for this case.','2014-01-15') , ( 'LABEL','ID_CASEDEMO','en','Case Demo','2014-01-15') , ( 'LABEL','ID_CASE_DELETE_SUCCESFULLY','en','The Case was deleted successfully.','2020-01-08') , +( 'LABEL','ID_CASE_UID','en','Case Uid','2021-04-04') , ( 'LABEL','ID_CASES','en','HOME','2014-01-15') , ( 'LABEL','ID_CASES1','en','Cases','2015-12-15') , ( 'LABEL','ID_CASES_DELETE_SUCCESFULLY','en','All Cases were deleted successfully.','2020-01-08') , @@ -58690,6 +58691,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_LAST','en','Last','2014-01-15') , ( 'LABEL','ID_LASTNAME','en','Last Name','2014-01-15') , ( 'LABEL','ID_LAST_EMPLOYEE','en','Last Employee','2014-01-15') , +( 'LABEL','ID_LAST_DATE','en','Last Update','2021-04-04') , ( 'LABEL','ID_LAST_LOGIN','en','Last Login','2014-01-15') , ( 'LABEL','ID_LAST_MODIFIED_DATE','en','Last-Modified Date','2020-12-16') , ( 'LABEL','ID_LAST_MODIFY','en','Last Modified','2017-02-21') , From 86d73a83c23824d948e93fa2c0651e184ee41890 Mon Sep 17 00:00:00 2001 From: Henry Jordan Date: Tue, 6 Apr 2021 14:49:58 +0000 Subject: [PATCH 2/6] PMCORE-2853 update update --- resources/assets/js/components/search/CasesFilter.vue | 10 ++++++++++ .../assets/js/components/search/MyCasesFilter.vue | 11 +++++++++++ resources/assets/js/home/Draft.vue | 9 ++++----- resources/assets/js/home/Paused.vue | 9 ++++----- resources/assets/js/home/Todo.vue | 9 ++++----- resources/assets/js/home/Unassigned.vue | 9 ++++----- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/resources/assets/js/components/search/CasesFilter.vue b/resources/assets/js/components/search/CasesFilter.vue index fc4e53193..7dfbae632 100644 --- a/resources/assets/js/components/search/CasesFilter.vue +++ b/resources/assets/js/components/search/CasesFilter.vue @@ -188,6 +188,16 @@ export default { itemModel: {}, }; }, + mounted() { + // Force to load filters when mounted the component + let fils= this.filters; + if(_.isArray(this.filters)){ + _.forEach(fils,(o)=>{ + o.autoShow = false; + }); + this.setFilters(fils); + } + }, watch: { filters: function (filters) { this.searchTags = []; diff --git a/resources/assets/js/components/search/MyCasesFilter.vue b/resources/assets/js/components/search/MyCasesFilter.vue index 4eb51725d..0131d8e2f 100644 --- a/resources/assets/js/components/search/MyCasesFilter.vue +++ b/resources/assets/js/components/search/MyCasesFilter.vue @@ -230,6 +230,16 @@ export default { itemModel: {} }; }, + mounted() { + // Force to load filters when mounted the component + let fils= this.filters; + if(_.isArray(this.filters)){ + _.forEach(fils,(o)=>{ + o.autoShow = false; + }); + this.setFilters(fils); + } + }, watch: { filters: function (filters) { this.searchTags = []; @@ -276,6 +286,7 @@ export default { self.searchTags.push(component.id); self.selected = component.id; self.itemModel[component.id] = component; + self.itemModel[component.id].autoShow = typeof item.autoShow !== "undefined" ? item.autoShow : true; } }); }, diff --git a/resources/assets/js/home/Draft.vue b/resources/assets/js/home/Draft.vue index 415aee5c4..67c9e885f 100644 --- a/resources/assets/js/home/Draft.vue +++ b/resources/assets/js/home/Draft.vue @@ -60,7 +60,7 @@ export default { TaskCell, CasesFilter, }, - props: ["defaultOption"], + props: ["defaultOption", "filters"], data() { return { newCase: { @@ -80,7 +80,6 @@ export default { "actions" ], tableData: [], - filters: {}, options: { filterable: false, headings: { @@ -140,7 +139,7 @@ export default { if(this.defaultOption) { params = utils.getAllUrlParams(this.defaultOption); if (params && params.openapplicationuid) { - this.filters = [ + this.$emit("onUpdateFilters",[ { fieldId: "caseNumber", filterVar: "caseNumber", @@ -149,7 +148,7 @@ export default { value: params.openapplicationuid, autoShow: false } - ]; + ]); } } }, @@ -302,7 +301,7 @@ export default { }, onRemoveFilter(data) {}, onUpdateFilters(data) { - this.filters = data.params; + this.$emit("onUpdateFilters", data.params); if (data.refresh) { this.$nextTick(() => { this.$refs["vueTable"].getData(); diff --git a/resources/assets/js/home/Paused.vue b/resources/assets/js/home/Paused.vue index 052abd3c1..2e4cc085c 100644 --- a/resources/assets/js/home/Paused.vue +++ b/resources/assets/js/home/Paused.vue @@ -76,7 +76,7 @@ export default { ModalUnpauseCase, CasesFilter, }, - props: ["defaultOption"], + props: ["defaultOption", "filters"], data() { return { newCase: { @@ -98,7 +98,6 @@ export default { "actions", ], tableData: [], - filters: {}, options: { filterable: false, headings: { @@ -164,7 +163,7 @@ export default { if(this.defaultOption) { params = utils.getAllUrlParams(this.defaultOption); if (params && params.openapplicationuid) { - this.filters = [ + this.$emit("onUpdateFilters",[ { fieldId: "caseNumber", filterVar: "caseNumber", @@ -173,7 +172,7 @@ export default { value: params.openapplicationuid, autoShow: false } - ]; + ]); } } }, @@ -337,7 +336,7 @@ export default { }, onRemoveFilter(data) {}, onUpdateFilters(data) { - this.filters = data.params; + this.$emit("onUpdateFilters", data.params); if (data.refresh) { this.$nextTick(() => { this.$refs["vueTable"].getData(); diff --git a/resources/assets/js/home/Todo.vue b/resources/assets/js/home/Todo.vue index 9ace3eaa5..0fc783b37 100644 --- a/resources/assets/js/home/Todo.vue +++ b/resources/assets/js/home/Todo.vue @@ -70,7 +70,7 @@ export default { TaskCell, CasesFilter, }, - props: ["defaultOption"], + props: ["defaultOption", "filters"], data() { return { newCase: { @@ -92,7 +92,6 @@ export default { "actions", ], tableData: [], - filters: {}, options: { filterable: false, headings: { @@ -157,7 +156,7 @@ export default { if(this.defaultOption) { params = utils.getAllUrlParams(this.defaultOption); if (params && params.openapplicationuid) { - this.filters = [ + this.$emit("onUpdateFilters", [ { fieldId: "caseNumber", filterVar: "caseNumber", @@ -166,7 +165,7 @@ export default { value: params.openapplicationuid, autoShow: false } - ]; + ]); } } }, @@ -327,7 +326,7 @@ export default { }, onRemoveFilter(data) {}, onUpdateFilters(data) { - this.filters = data.params; + this.$emit("onUpdateFilters", data.params); if (data.refresh) { this.$nextTick(() => { this.$refs["vueTable"].getData(); diff --git a/resources/assets/js/home/Unassigned.vue b/resources/assets/js/home/Unassigned.vue index fd4603420..90a4cd5ca 100644 --- a/resources/assets/js/home/Unassigned.vue +++ b/resources/assets/js/home/Unassigned.vue @@ -70,7 +70,7 @@ export default { ModalClaimCase, CasesFilter, }, - props: ["defaultOption"], + props: ["defaultOption", "filters"], data() { return { newCase: { @@ -92,7 +92,6 @@ export default { "actions", ], tableData: [], - filters: {}, options: { filterable: false, headings: { @@ -158,7 +157,7 @@ export default { if(this.defaultOption) { params = utils.getAllUrlParams(this.defaultOption); if (params && params.openapplicationuid) { - this.filters = [ + this.$emit("onUpdateFilters",[ { fieldId: "caseNumber", filterVar: "caseNumber", @@ -167,7 +166,7 @@ export default { value: params.openapplicationuid, autoShow: false } - ]; + ]); } } }, @@ -335,7 +334,7 @@ export default { }, onRemoveFilter(data) {}, onUpdateFilters(data) { - this.filters = data.params; + this.$emit("onUpdateFilters", data.params); if (data.refresh) { this.$nextTick(() => { this.$refs["vueTable"].getData(); From ca43b8bbaa7d6f19bde8fb8e6bb0a8707a1ed889 Mon Sep 17 00:00:00 2001 From: Henry Jordan Date: Tue, 6 Apr 2021 22:29:37 +0000 Subject: [PATCH 3/6] PMCORE-2933 --- resources/assets/js/home/AdvancedSearch.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/assets/js/home/AdvancedSearch.vue b/resources/assets/js/home/AdvancedSearch.vue index 362496936..246079255 100644 --- a/resources/assets/js/home/AdvancedSearch.vue +++ b/resources/assets/js/home/AdvancedSearch.vue @@ -45,6 +45,9 @@
{{ props.row.CASE_TITLE }}
+
+ {{ props.row.APP_STATUS }} +
{{ props.row.PROCESS_NAME }}
@@ -121,6 +124,7 @@ export default { columns: [ "case_number", "case_title", + "status", "process_name", "task", "current_user", @@ -136,6 +140,7 @@ export default { info: "", case_number: this.$i18n.t("ID_MYCASE_NUMBER"), case_title: this.$i18n.t("ID_CASE_TITLE"), + status: this.$i18n.t("ID_STATUS"), process_name: this.$i18n.t("ID_PROCESS_NAME"), task: this.$i18n.t("ID_TASK"), current_user: this.$i18n.t("ID_CURRENT_USER"), @@ -242,6 +247,7 @@ export default { DURATION: v.DURATION, DEL_INDEX: v.DEL_INDEX, APP_UID: v.APP_UID, + STATUS: this.$i18n.t("ID_CASES_STATUS_"+ v.APP_STATUS.toUpperCase()), PRO_UID: v.PRO_UID, TAS_UID: v.TAS_UID, MESSAGE_COLOR: v.CASE_NOTES_COUNT > 0 ? "black":"silver" From 6c35cc2fdf2565839faf8fed80b4c735121bf6b9 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelca Date: Wed, 7 Apr 2021 20:53:50 +0000 Subject: [PATCH 4/6] PMCORE-2879: Cancel Case button does not work when it comes from a email link with new UI remove debugger --- resources/assets/js/home/Draft.vue | 6 ++ resources/assets/js/home/Home.vue | 6 +- resources/assets/js/home/Paused.vue | 6 ++ resources/assets/js/home/Unassigned.vue | 83 ++++++++------------ workflow/engine/methods/cases/viena_init.php | 5 +- 5 files changed, 50 insertions(+), 56 deletions(-) diff --git a/resources/assets/js/home/Draft.vue b/resources/assets/js/home/Draft.vue index 67c9e885f..586e0239b 100644 --- a/resources/assets/js/home/Draft.vue +++ b/resources/assets/js/home/Draft.vue @@ -308,6 +308,12 @@ export default { }); } }, + /** + * update view in component + */ + updateView(){ + this.$refs["vueTable"].getData(); + } }, }; diff --git a/resources/assets/js/home/Home.vue b/resources/assets/js/home/Home.vue index 150e46f9c..68b3022ab 100644 --- a/resources/assets/js/home/Home.vue +++ b/resources/assets/js/home/Home.vue @@ -161,6 +161,7 @@ export default { } else { this.page = "MyCases"; } + this.lastPage = this.page; }, /** * Do a mapping of vue view for menus @@ -212,9 +213,12 @@ export default { this.pageId = null; this.pageUri = item.item.href; this.page = item.item.id || "MyCases"; - if (this.$refs["component"] && this.$refs["component"].updateView) { + if (this.page === this.lastPage + && this.$refs["component"] + && this.$refs["component"].updateView) { this.$refs["component"].updateView(); } + this.lastPage = this.page; } }, setCounter() { diff --git a/resources/assets/js/home/Paused.vue b/resources/assets/js/home/Paused.vue index 2e4cc085c..598f226f3 100644 --- a/resources/assets/js/home/Paused.vue +++ b/resources/assets/js/home/Paused.vue @@ -343,6 +343,12 @@ export default { }); } }, + /** + * update view in component + */ + updateView(){ + this.$refs["vueTable"].getData(); + } }, }; diff --git a/resources/assets/js/home/Unassigned.vue b/resources/assets/js/home/Unassigned.vue index 90a4cd5ca..cd443b580 100644 --- a/resources/assets/js/home/Unassigned.vue +++ b/resources/assets/js/home/Unassigned.vue @@ -61,7 +61,7 @@ import api from "./../api/index"; import utils from "./../utils/utils"; export default { - name: "Paused", + name: "Unassigned", components: { HeaderCounter, ButtonFleft, @@ -94,6 +94,7 @@ export default { tableData: [], options: { filterable: false, + sendInitialRequest: false, headings: { case_number: this.$i18n.t("ID_MYCASE_NUMBER"), case_title: this.$i18n.t("ID_CASE_TITLE"), @@ -130,12 +131,8 @@ export default { } }; }, - created() { - this.initFilters(); - }, mounted() { - // force to open case - this.openDefaultCase(); + this.initFilters(); }, watch: {}, computed: { @@ -151,57 +148,31 @@ export default { methods: { /** * Initialize filters + * updates the filters if there is an appUid parameter */ initFilters() { - let params; + let params, + filter = {refresh: true}; if(this.defaultOption) { params = utils.getAllUrlParams(this.defaultOption); - if (params && params.openapplicationuid) { - this.$emit("onUpdateFilters",[ - { - fieldId: "caseNumber", - filterVar: "caseNumber", - label: "", - options:[], - value: params.openapplicationuid, - autoShow: false - } - ]); - } - } - }, - /** - * Open a case when the component was mounted - */ - openDefaultCase() { - let params; - if(this.defaultOption) { - params = utils.getAllUrlParams(this.defaultOption); - if (params && params.app_uid && params.del_index) { - this.openCase({ - APP_UID: params.app_uid, - DEL_INDEX: params.del_index - }); - this.$emit("cleanDefaultOption"); - } - //force to search in the parallel tasks if (params && params.openapplicationuid) { - this.onUpdateFilters({ - params: [ - { - fieldId: "caseNumber", - filterVar: "caseNumber", - label: "", - options:[], - value: params.openapplicationuid, - autoShow: false - } - ], - refresh: false - }); - this.$emit("cleanDefaultOption"); + filter = { + params: [ + { + fieldId: "caseNumber", + filterVar: "caseNumber", + label: "", + options:[], + value: params.openapplicationuid, + autoShow: false + } + ], + refresh: true + }; } + this.$emit("cleanDefaultOption"); } + this.onUpdateFilters(filter); }, /** * On row click event handler @@ -236,7 +207,7 @@ export default { paged: paged, }; - _.forIn(this.filters, function (item, key) { + _.forIn(this.$parent.filters, function (item, key) { filters[item.filterVar] = item.value; }); return new Promise((resolutionFunc, rejectionFunc) => { @@ -334,13 +305,21 @@ export default { }, onRemoveFilter(data) {}, onUpdateFilters(data) { - this.$emit("onUpdateFilters", data.params); + if (data.params) { + this.$emit("onUpdateFilters", data.params); + } if (data.refresh) { this.$nextTick(() => { this.$refs["vueTable"].getData(); }); } }, + /** + * update view in component + */ + updateView(){ + this.$refs["vueTable"].getData(); + } }, }; diff --git a/workflow/engine/methods/cases/viena_init.php b/workflow/engine/methods/cases/viena_init.php index 229ae00b0..76822b5d0 100644 --- a/workflow/engine/methods/cases/viena_init.php +++ b/workflow/engine/methods/cases/viena_init.php @@ -90,13 +90,12 @@ if (isset($_SESSION['__OPEN_APPLICATION_UID__'])) { exit(); } } - + $appNumber = Application::getCaseNumber($openAppUid); if (count($arrayDelIndex) === 1) { //We will to open the case: one thread $openCaseIE = true; - $defaultOption = '../cases/open?APP_UID=' . $openAppUid . '&DEL_INDEX=' . $arrayDelIndex[0] . '&action=' . $action; + $defaultOption = '../cases/open?APP_UID=' . $openAppUid . '&DEL_INDEX=' . $arrayDelIndex[0] . '&action=' . $action . '&openApplicationUid=' . $appNumber; } else { - $appNumber = Application::getCaseNumber($openAppUid); //We will to show the list: more than one thread $defaultOption = '../cases/casesListExtJs?action=' . $action . '&openApplicationUid=' . $appNumber; } From ae5856f1ccf5bf283ea67eaecd47374ac274e116 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 8 Apr 2021 18:56:42 -0400 Subject: [PATCH 5/6] PMCORE-1880 --- workflow/engine/classes/Cases.php | 8 +++++++- .../content/translations/english/processmaker.en.po | 6 ------ .../src/ProcessMaker/BusinessModel/ProcessPermissions.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 00fc4bda7..93c72e0f5 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -5872,7 +5872,13 @@ class Cases foreach ($permissions as $row) { $userUid = $row['USR_UID']; $opUserRelation = $row['OP_USER_RELATION']; - $opTaskSource = $row['OP_TASK_SOURCE']; + $originTask = $row['OP_TASK_SOURCE']; // We can see the steps related to this task + $targetTask = $row['TAS_UID']; // We can see the steps related to this task if is the current task + if (!empty($targetTask)) { + $opTaskSource = $targetTask; + } else { + $opTaskSource = $originTask; + } $opParticipated = (int) $row['OP_PARTICIPATE']; $opType = $row['OP_OBJ_TYPE']; $opObjUid = $row['OP_OBJ_UID']; diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index 812a95cce..ac2844a8e 100755 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -14675,12 +14675,6 @@ msgstr "Properties saved successfully" msgid "Error Update File" msgstr "Error Update File" -# TRANSLATION -# LABEL/ID_MAFE_7215ee9c7d9dc229d2921a40e899ec5f -#: LABEL/ID_MAFE_7215ee9c7d9dc229d2921a40e899ec5f -msgid "[LABEL/ID_MAFE_7215ee9c7d9dc229d2921a40e899ec5f] " -msgstr "" - # TRANSLATION # LABEL/ID_MAFE_725255d7ccc0cf426c1da6abe0afe7e4 #: LABEL/ID_MAFE_725255d7ccc0cf426c1da6abe0afe7e4 diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/ProcessPermissions.php b/workflow/engine/src/ProcessMaker/BusinessModel/ProcessPermissions.php index 7a4d21c0d..3caa1785c 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/ProcessPermissions.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/ProcessPermissions.php @@ -57,10 +57,10 @@ class ProcessPermissions $aFields = $oTask->load($aRow['TAS_UID']); $sTaskTarget = $aFields['TAS_TITLE']; } catch (\Exception $oError) { - $sTaskTarget = 'All Tasks'; + $sTaskTarget = G::LoadTranslation('ID_SELECT_ONE_OPTION'); } } else { - $sTaskTarget = G::LoadTranslation('ID_ANY_TASK'); + $sTaskTarget = G::LoadTranslation('ID_SELECT_ONE_OPTION'); } //Obtain user or group if ($aRow['OP_USER_RELATION'] == 1) { @@ -87,7 +87,7 @@ class ProcessPermissions $aFields = $oTask->load($aRow['OP_TASK_SOURCE']); $sTaskSource = $aFields['TAS_TITLE']; } catch (\Exception $oError) { - $sTaskSource = 'All Tasks'; + $sTaskSource = G::LoadTranslation('ID_ANY_TASK'); } } else { $sTaskSource = G::LoadTranslation('ID_ANY_TASK'); From 7d27947b398a75ccacccef0de14bd25a5c7eca05 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Tue, 30 Mar 2021 10:03:46 -0400 Subject: [PATCH 6/6] PMCORE-2835 --- database/factories/DelegationFactory.php | 1 + .../BusinessModel/Cases/DraftTest.php | 5 + .../BusinessModel/Cases/InboxTest.php | 9 + .../BusinessModel/Cases/ParticipatedTest.php | 8 + .../BusinessModel/Cases/PausedTest.php | 8 + .../BusinessModel/Cases/SearchTest.php | 2 + .../BusinessModel/Cases/SupervisingTest.php | 8 + .../BusinessModel/Cases/UnassignedTest.php | 8 + .../ProcessMaker/Model/ApplicationTest.php | 221 +++++++++- .../src/ProcessMaker/Model/DelegationTest.php | 400 +++++++++++++++++- .../BusinessModel/Cases/AbstractCases.php | 58 ++- .../BusinessModel/Cases/Draft.php | 9 +- .../BusinessModel/Cases/Inbox.php | 3 + .../BusinessModel/Cases/Participated.php | 2 +- .../BusinessModel/Cases/Paused.php | 8 +- .../BusinessModel/Cases/Search.php | 124 +++--- .../BusinessModel/Cases/Supervising.php | 42 +- .../src/ProcessMaker/Model/Application.php | 255 ++++++++++- .../src/ProcessMaker/Model/Delegation.php | 74 ++-- .../src/ProcessMaker/Model/TaskUser.php | 19 +- 20 files changed, 1060 insertions(+), 204 deletions(-) diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index afc2c8ca2..d2f275e3e 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -78,6 +78,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function 'DEL_INIT_DATE' => $faker->dateTime(), 'DEL_TASK_DUE_DATE' => $faker->dateTime(), 'DEL_RISK_DATE' => $faker->dateTime(), + 'DEL_LAST_INDEX' => 1, 'USR_ID' => $user->USR_ID, 'PRO_ID' => $process->PRO_ID, 'TAS_ID' => $task->TAS_ID, diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php index 2ed0c8244..8a6e82cd3 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\DB; use ProcessMaker\BusinessModel\Cases\Draft; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\User; use Tests\TestCase; /** @@ -34,9 +35,12 @@ class DraftTest extends TestCase public function createDraft() { $application = factory(Application::class)->states('draft')->create(); + $usrId = User::getId($application['APP_INIT_USER']); $delegation = factory(Delegation::class)->states('foreign_keys')->create([ 'DEL_THREAD_STATUS' => 'OPEN', 'DEL_INDEX' => 1, + 'USR_UID' => $application->APP_INIT_USER, + 'USR_ID' => $usrId, 'APP_UID' => $application->APP_UID, 'APP_NUMBER' => $application->APP_NUMBER, ]); @@ -84,6 +88,7 @@ class DraftTest extends TestCase // Create new Draft object $draft = new Draft(); $draft->setUserId($cases['USR_ID']); + $draft->setUserUid($cases['USR_UID']); $result = $draft->getCounter(); $this->assertTrue($result > 0); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php index 60edb87a8..d46f2946e 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use ProcessMaker\BusinessModel\Cases\Inbox; +use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Process; use ProcessMaker\Model\Task; @@ -20,6 +21,14 @@ class InboxTest extends TestCase { use DatabaseTransactions; + /** + * Method set up. + */ + public function setUp() + { + parent::setUp(); + } + /** * Create inbox cases factories * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php index 2102ac6fe..b024c3b11 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -19,6 +19,14 @@ class ParticipatedTest extends TestCase { use DatabaseTransactions; + /** + * Method set up. + */ + public function setUp() + { + parent::setUp(); + } + /** * Create participated cases factories * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php index de4d08af1..65c755de0 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php @@ -22,6 +22,14 @@ class PausedTest extends TestCase { use DatabaseTransactions; + /** + * Method set up. + */ + public function setUp() + { + parent::setUp(); + } + /** * Create paused cases factories * 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 52e234b6c..711248446 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SearchTest.php @@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use ProcessMaker\BusinessModel\Cases\Search; +use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use Tests\TestCase; @@ -23,6 +24,7 @@ class SearchTest extends TestCase public function setUp() { parent::setUp(); + Application::truncate(); Delegation::truncate(); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php index 4efac1a0f..8c96d0dea 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php @@ -21,6 +21,14 @@ class SupervisingTest extends TestCase { use DatabaseTransactions; + /** + * Method set up. + */ + public function setUp() + { + parent::setUp(); + } + /** * Create supervising cases factories * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php index 0d28cbf80..2e6133f96 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/UnassignedTest.php @@ -24,6 +24,14 @@ class UnassignedTest extends TestCase { use DatabaseTransactions; + /** + * Method set up. + */ + public function setUp() + { + parent::setUp(); + } + /** * Create unassigned cases factories * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php index 3f32af02e..97688a32b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ApplicationTest.php @@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Model; use G; use Illuminate\Foundation\Testing\DatabaseTransactions; use ProcessMaker\Model\Application; +use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Process; use ProcessMaker\Model\User; use Tests\TestCase; @@ -24,7 +25,7 @@ class ApplicationTest extends TestCase public function setUp() { parent::setUp(); - Application::query()->delete(); + Application::truncate(); } /** @@ -43,6 +44,22 @@ class ApplicationTest extends TestCase $this->assertInstanceOf(User::class, $application->currentUser); } + /** + * Test belongs to APP_INIT_USER + * + * @covers \ProcessMaker\Model\Application::creatorUser() + * @test + */ + public function it_has_a_creator_user() + { + $application = factory(Application::class)->create([ + 'APP_INIT_USER' => function () { + return factory(User::class)->create()->USR_UID; + } + ]); + $this->assertInstanceOf(User::class, $application->creatorUser); + } + /** * Test belongs to APP_INIT_USER * @@ -59,6 +76,116 @@ class ApplicationTest extends TestCase $this->assertInstanceOf(User::class, $application->creatoruser); } + /** + * This test scopeUserId + * + * @covers \ProcessMaker\Model\Application::scopeUserId() + * @covers \ProcessMaker\Model\Application::scopeJoinDelegation() + * @test + */ + public function it_return_scope_user_id() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $usrId = User::getId($table->APP_INIT_USER); + $this->assertCount(1, $table->joinDelegation()->userId($usrId)->get()); + } + + /** + * This test scopeCreator + * + * @covers \ProcessMaker\Model\Application::scopeCreator() + * @test + */ + public function it_return_scope_creator() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->creator($table->APP_INIT_USER)->get()); + } + + /** + * This test scopeSpecificCasesByUid + * + * @covers \ProcessMaker\Model\Application::scopeSpecificCasesByUid() + * @test + */ + public function it_return_scope_case_uids() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->specificCasesByUid([$table->APP_UID])->get()); + } + + /** + * This test scopeCase + * + * @covers \ProcessMaker\Model\Application::scopeCase() + * @test + */ + public function it_return_scope_case() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->case($table->APP_NUMBER)->get()); + } + + /** + * This test scopePositiveCases + * + * @covers \ProcessMaker\Model\Application::scopePositiveCases() + * @test + */ + public function it_return_scope_positive_cases() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->positiveCases()->get()); + } + + /** + * This test scopeSpecificCases + * + * @covers \ProcessMaker\Model\Application::scopeSpecificCases() + * @test + */ + public function it_return_scope_specific_case_numbers() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->specificCases([$table->APP_NUMBER])->get()); + } + + /** + * This test scopeRangeOfCases + * + * @covers \ProcessMaker\Model\Application::scopeRangeOfCases() + * @test + */ + public function it_return_scope_range_of_cases() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get()); + } + + /** + * This test scopeCasesFrom + * + * @covers \ProcessMaker\Model\Application::scopeCasesFrom() + * @test + */ + public function it_return_scope_case_from() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->casesFrom($table->APP_NUMBER)->get()); + } + + /** + * This test scopeCasesTo + * + * @covers \ProcessMaker\Model\Application::scopeCasesTo() + * @test + */ + public function it_return_scope_case_to() + { + $table = factory(Application::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->casesTo($table->APP_NUMBER)->get()); + } + /** * This checks if return the columns used * @@ -71,6 +198,96 @@ class ApplicationTest extends TestCase $this->assertCount(1, $table->statusId($table->APP_STATUS_ID)->get()); } + /** + * This test scopeStatusIds + * + * @covers \ProcessMaker\Model\Application::scopeStatusIds() + * @test + */ + public function it_return_cases_by_status_ids() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->statusIds([$table->APP_STATUS_ID])->get()); + } + + /** + * This test scopeStartDateFrom + * + * @covers \ProcessMaker\Model\Application::scopeStartDateFrom() + * @test + */ + public function it_return_start_date_from() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->startDateFrom($table->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeStartDateTo + * + * @covers \ProcessMaker\Model\Application::scopeStartDateTo() + * @test + */ + public function it_return_start_date_to() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->startDateTo($table->APP_CREATE_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeFinishCaseFrom + * + * @covers \ProcessMaker\Model\Application::scopeFinishCaseFrom() + * @test + */ + public function it_return_finish_date_from() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->finishCaseFrom($table->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeFinishCaseTo + * + * @covers \ProcessMaker\Model\Application::scopeFinishCaseTo() + * @test + */ + public function it_return_finish_date_to() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->finishCaseTo($table->APP_FINISH_DATE->format("Y-m-d H:i:s"))->get()); + } + + /** + * This test scopeTask + * + * @covers \ProcessMaker\Model\Application::scopeTask() + * @covers \ProcessMaker\Model\Application::scopeJoinDelegation() + * @test + */ + public function it_return_scope_task() + { + $table = factory(Application::class)->create(); + $tableJoin = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_UID' => $table->APP_UID, + 'APP_NUMBER' => $table->APP_NUMBER, + ]); + + $this->assertCount(1, $table->joinDelegation()->task($tableJoin->TAS_ID)->get()); + } + + /** + * This test scopeJoinProcess + * + * @covers \ProcessMaker\Model\Application::scopeJoinProcess() + * @test + */ + public function it_return_scope_join_process() + { + $table = factory(Application::class)->create(); + $this->assertCount(1, $table->joinProcess()->get()); + } + /** * This checks if return the columns used * @@ -156,7 +373,7 @@ class ApplicationTest extends TestCase * @covers \ProcessMaker\Model\Application::getCountByProUid() * @covers \ProcessMaker\Model\Application::scopeProUid() * @covers \ProcessMaker\Model\Application::scopeStatusId() - * @covers \ProcessMaker\Model\Application::scopePositivesCases() + * @covers \ProcessMaker\Model\Application::scopePositiveCases() * @test */ public function it_count_cases_by_process() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index f26de1584..a86a42619 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -34,9 +34,74 @@ class DelegationTest extends TestCase public function setUp() { parent::setUp(); + Application::truncate(); Delegation::truncate(); } + /** + * Test belongs to APP_UID + * + * @covers \ProcessMaker\Model\Delegation::application() + * @test + */ + public function it_has_an_application() + { + $delegation = factory(Delegation::class)->create([ + 'APP_UID' => function () { + return factory(Application::class)->create()->APP_UID; + } + ]); + $this->assertInstanceOf(Application::class, $delegation->application); + } + + /** + * Test belongs to USR_ID + * + * @covers \ProcessMaker\Model\Delegation::user() + * @test + */ + public function it_has_an_user() + { + $delegation = factory(Delegation::class)->create([ + 'USR_ID' => function () { + return factory(User::class)->create()->USR_ID; + } + ]); + $this->assertInstanceOf(User::class, $delegation->user); + } + + /** + * Test belongs to TAS_ID + * + * @covers \ProcessMaker\Model\Delegation::task() + * @test + */ + public function it_has_a_task() + { + $delegation = factory(Delegation::class)->create([ + 'TAS_ID' => function () { + return factory(Task::class)->create()->TAS_ID; + } + ]); + $this->assertInstanceOf(Task::class, $delegation->task); + } + + /** + * Test belongs to PRO_ID + * + * @covers \ProcessMaker\Model\Delegation::process() + * @test + */ + public function it_has_a_process() + { + $delegation = factory(Delegation::class)->create([ + 'PRO_ID' => function () { + return factory(Process::class)->create()->PRO_ID; + } + ]); + $this->assertInstanceOf(Process::class, $delegation->process); + } + /** * This test scopePriority * @@ -50,15 +115,27 @@ class DelegationTest extends TestCase } /** - * This test scopeIndex + * This test scopePriorities * - * @covers \ProcessMaker\Model\Delegation::scopeIndex() + * @covers \ProcessMaker\Model\Delegation::scopePriorities() * @test */ - public function it_return_scope_index() + public function it_return_scope_priorities() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->index($table->DEL_INDEX)->get()); + $this->assertCount(1, $table->priorities([$table->DEL_PRIORITY])->get()); + } + + /** + * This test scopeThreadOpen + * + * @covers \ProcessMaker\Model\Delegation::scopeThreadOpen() + * @test + */ + public function it_return_scope_thread_open() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->threadOpen()->get()); } /** @@ -74,15 +151,55 @@ class DelegationTest extends TestCase } /** - * This test scopeCaseInProgress + * This test scopeCasesInProgress * - * @covers \ProcessMaker\Model\Delegation::scopeCaseInProgress() + * @covers \ProcessMaker\Model\Delegation::scopeCasesInProgress() * @test */ public function it_return_scope_case_in_progress() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->joinApplication()->caseInProgress()->get()); + $this->assertCount(1, $table->joinApplication()->casesInProgress([2])->get()); + } + + /** + * This test scopeCasesDone + * + * @covers \ProcessMaker\Model\Delegation::scopeCasesDone() + * @test + */ + public function it_return_scope_case_done() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->joinApplication()->casesDone([2])->get()); + } + + /** + * This test scopeIndex + * + * @covers \ProcessMaker\Model\Delegation::scopeIndex() + * @test + */ + public function it_return_scope_index() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->index($table->DEL_INDEX)->get()); + } + + /** + * This test scopeCaseTodo + * + * @covers \ProcessMaker\Model\Delegation::scopeCaseTodo() + * @test + */ + public function it_return_scope_case_to_do() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->caseTodo()->get()); } /** @@ -91,7 +208,7 @@ class DelegationTest extends TestCase * @covers \ProcessMaker\Model\Delegation::scopeCaseCompleted() * @test */ - public function it_return_scope_case_in_completed() + public function it_return_scope_case_completed() { $application = factory(Application::class)->states('completed')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create([ @@ -101,6 +218,38 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->joinApplication()->caseCompleted()->get()); } + /** + * This test scopeStatus + * + * @covers \ProcessMaker\Model\Delegation::scopeStatus() + * @test + */ + public function it_return_scope_status() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->status($application->APP_STATUS_ID)->get()); + } + + /** + * This test scopeStatusIds + * + * @covers \ProcessMaker\Model\Delegation::scopeStatusIds() + * @test + */ + public function it_return_scope_status_ids() + { + $application = factory(Application::class)->states('todo')->create(); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + ]); + $this->assertCount(1, $table->joinApplication()->statusIds([$application->APP_STATUS_ID])->get()); + } + /** * This test scopeDelegateDateFrom * @@ -125,6 +274,66 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d H:i:s"))->get()); } + /** + * This test scopeFinishDateFrom + * + * @covers \ProcessMaker\Model\Delegation::scopeFinishDateFrom() + * @test + */ + public function it_return_scope_finish_date_from() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->finishDateFrom($table->DEL_FINISH_DATE)->get()); + } + + /** + * This test scopeFinishDateTo + * + * @covers \ProcessMaker\Model\Delegation::scopeFinishDateTo() + * @test + */ + public function it_return_scope_finish_date_to() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->finishDateTo($table->DEL_FINISH_DATE)->get()); + } + + /** + * This test scopeDueFrom + * + * @covers \ProcessMaker\Model\Delegation::scopeDueFrom() + * @test + */ + public function it_return_scope_due_date_from() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->dueFrom($table->DEL_TASK_DUE_DATE)->get()); + } + + /** + * This test scopeDueTo + * + * @covers \ProcessMaker\Model\Delegation::scopeDueTo() + * @test + */ + public function it_return_scope_due_date_to() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->dueTo($table->DEL_TASK_DUE_DATE)->get()); + } + + /** + * This test scopeCase + * + * @covers \ProcessMaker\Model\Delegation::scopeCase() + * @test + */ + public function it_return_scope_case() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->case($table->APP_NUMBER)->get()); + } + /** * This test scopeSpecificCases * @@ -137,6 +346,102 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->specificCases([$table->APP_NUMBER])->get()); } + /** + * This test scopeCasesFrom + * + * @covers \ProcessMaker\Model\Delegation::scopeCasesFrom() + * @test + */ + public function it_return_scope_cases_from() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->casesFrom($table->APP_NUMBER)->get()); + } + + /** + * This test scopeCasesTo + * + * @covers \ProcessMaker\Model\Delegation::scopeCasesTo() + * @test + */ + public function it_return_scope_cases_to() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->casesTo($table->APP_NUMBER)->get()); + } + + /** + * This test scopePositiveCases + * + * @covers \ProcessMaker\Model\Delegation::scopePositiveCases() + * @test + */ + public function it_return_scope_positive_cases() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->positiveCases()->get()); + } + + /** + * This test scopeRangeOfCases + * + * @covers \ProcessMaker\Model\Delegation::scopeRangeOfCases() + * @test + */ + public function it_return_scope_range_of_cases() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get()); + } + + /** + * This test scopeAppUid + * + * @covers \ProcessMaker\Model\Delegation::scopeAppUid() + * @test + */ + public function it_return_scope_app_uid() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->appUid($table->APP_UID)->get()); + } + + /** + * This test scopeLastThread + * + * @covers \ProcessMaker\Model\Delegation::scopeLastThread() + * @test + */ + public function it_return_scope_last_thread() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->lastThread()->get()); + } + + /** + * This test scopeSpecificCasesByUid + * + * @covers \ProcessMaker\Model\Delegation::scopeSpecificCasesByUid() + * @test + */ + public function it_return_scope_specific_cases_uid() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->specificCasesByUid([$table->APP_UID])->get()); + } + + /** + * This test scopeUserId + * + * @covers \ProcessMaker\Model\Delegation::scopeUserId() + * @test + */ + public function it_return_scope_user_id() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->userId($table->USR_ID)->get()); + } + /** * This test scopeWithoutUserId * @@ -151,6 +456,18 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->withoutUserId($table->TAS_ID)->get()); } + /** + * This test scopeProcessId + * + * @covers \ProcessMaker\Model\Delegation::scopeProcessId() + * @test + */ + public function it_return_scope_process_id() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->processId($table->PRO_ID)->get()); + } + /** * This test scopeTask * @@ -160,7 +477,7 @@ class DelegationTest extends TestCase public function it_return_scope_task() { $table = factory(Delegation::class)->states('foreign_keys')->create(); - $this->assertCount(1, $table->task()->get()); + $this->assertCount(1, $table->task($table->TAS_ID)->get()); } /** @@ -175,6 +492,60 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->specificTasks([$table->TAS_ID])->get()); } + /** + * This test scopeTaskAssignType + * + * @covers \ProcessMaker\Model\Delegation::scopeTaskAssignType() + * @test + */ + public function it_return_scope_assign_type() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->taskAssignType('NORMAL')->get()); + } + + /** + * This test scopeExcludeTaskTypes + * + * @covers \ProcessMaker\Model\Delegation::scopeExcludeTaskTypes() + * @test + */ + public function it_return_scope_exclude_tas_types() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(0, $table->excludeTaskTypes(['NORMAL'])->get()); + } + + /** + * This test scopeSpecificTaskTypes + * + * @covers \ProcessMaker\Model\Delegation::scopeSpecificTaskTypes() + * @test + */ + public function it_return_scope_specific_tas_types() + { + $table = factory(Delegation::class)->states('foreign_keys')->create(); + $this->assertCount(1, $table->specificTaskTypes(['NORMAL'])->get()); + } + + /** + * This test scopeAppStatusId + * + * @covers \ProcessMaker\Model\Delegation::scopeAppStatusId() + * @test + */ + public function it_return_scope_status_id() + { + $application = factory(Application::class)->create([ + 'APP_STATUS_ID' => 2, + 'APP_STATUS' => 'TO_DO' + ]); + $table = factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER + ]); + $this->assertCount(1, $table->appStatusId()->get()); + } + /** * This checks to make sure pagination is working properly * @@ -412,22 +783,19 @@ class DelegationTest extends TestCase */ public function it_should_search_and_filter_by_app_title() { - $delegations = factory(Delegation::class, 1) - ->states('foreign_keys') - ->create(); - $title = $delegations->last() - ->DEL_TITLE; + $delegations = factory(Delegation::class, 1)->states('foreign_keys')->create(); + $title = $delegations->last()->DEL_TITLE; // We need to commit the records inserted because is needed for the "fulltext" index DB::commit(); // Searching by a existent case title, result ordered by APP_NUMBER, filter by APP_NUMBER in DESC mode $results = Delegation::search(null, 0, 10, $title, null, null, 'DESC', - 'APP_NUMBER', null, null, null, 'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(1, $results['data']); $this->assertEquals($title, $results['data'][0]['APP_TITLE']); // Searching by a existent case title, result ordered by APP_NUMBER, filter by APP_NUMBER in ASC mode $results = Delegation::search(null, 0, 10, $title, null, null, 'ASC', - 'APP_NUMBER', null, null, null, 'APP_TITLE'); + 'APP_NUMBER', null, null, null, 'APP_TITLE'); $this->assertCount(1, $results['data']); $this->assertEquals($title, $results['data'][0]['APP_TITLE']); } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index b1ddc8f05..c62f3c423 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -1168,12 +1168,13 @@ class AbstractCases implements CasesInterface * Get the thread information * * @param array $thread + * @param bool $addUserInfo + * @param bool $addThreadInfo * * @return array */ - public function threadInformation(array $thread) + public function threadInformation(array $thread, $addUserInfo = false, $addThreadInfo = false) { - $result = []; $status = ''; $finishDate = 'now'; $dateToCompare = date("Y-m-d H:i:s"); @@ -1185,22 +1186,51 @@ class AbstractCases implements CasesInterface $status = 'DRAFT'; } if ($thread['APP_STATUS'] === 'COMPLETED') { - $finishDate = $thread['APP_FINISH_DATE']; + $finishDate = !empty($thread['APP_FINISH_DATE']) ? $thread['APP_FINISH_DATE'] : date("Y-m-d H:i:s"); $dateToCompare = $finishDate; } + // Variables of results + $threadTask = []; + $threadUser = []; + $threadTitle = []; // Define the thread information - $result['tas_title'] = $thread['TAS_TITLE']; - $result['user_id'] = $thread['USR_ID']; - $result['due_date'] = $thread['DEL_TASK_DUE_DATE']; - $result['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare); - $result['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : ''; - $result['tas_color_label'] = (!empty($result['tas_color'])) ? self::TASK_COLORS[$result['tas_color']] : ''; - $result['tas_status'] = self::TASK_STATUS[$result['tas_color']]; - $result['unassigned'] = ($status === 'UNASSIGNED' ? true : false); - // Get the user tooltip information - $result['user_tooltip'] = User::getInformation($thread['USR_ID']); + $threadTask['tas_uid'] = !empty($thread['TAS_UID']) ? $thread['TAS_UID'] : ''; + $threadTask['tas_title'] = $thread['TAS_TITLE']; + $threadTask['user_id'] = $thread['USR_ID']; + $threadTask['due_date'] = $thread['DEL_TASK_DUE_DATE']; + $threadTask['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare); + $threadTask['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : ''; + $threadTask['tas_color_label'] = (!empty($threadTask['tas_color'])) ? self::TASK_COLORS[$threadTask['tas_color']] : ''; + $threadTask['tas_status'] = self::TASK_STATUS[$threadTask['tas_color']]; + $threadTask['unassigned'] = ($status === 'UNASSIGNED' ? true : false); + $userInfo = User::getInformation($thread['USR_ID']); + $threadTask['user_tooltip'] = $userInfo; + // Get user information + if ($addUserInfo) { + $threadUser['user_tooltip'] = $userInfo; + $threadUser['user_id'] = $thread['USR_ID']; + $threadUser['usr_username'] = !empty($userInfo['usr_username']) ? $userInfo['usr_username'] : ''; + $threadUser['usr_lastname'] = !empty($userInfo['usr_lastname']) ? $userInfo['usr_lastname'] : ''; + $threadUser['usr_firstname'] = !empty($userInfo['usr_firstname']) ? $userInfo['usr_firstname'] : ''; + } + // Get thread titles + if ($addThreadInfo) { + $threadTitle['del_id'] = $thread['DELEGATION_ID']; + $threadTitle['del_index'] = $thread['DEL_INDEX']; + $threadTitle['thread_title'] = $thread['DEL_TITLE']; + } + // Define the array responses + $result = []; + $result['THREAD_TASK'] = $threadTask; + $result['THREAD_USER'] = $threadUser; + $result['THREAD_TITLE'] = $threadTitle; - return $result; + if (!$addUserInfo && !$addThreadInfo) { + // Only will return the pending task info + return $threadTask; + } else { + return $result; + } } /** diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php index e97c5b97a..1235ab3dd 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php @@ -3,6 +3,7 @@ namespace ProcessMaker\BusinessModel\Cases; use G; +use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; class Draft extends AbstractCases @@ -120,11 +121,13 @@ class Draft extends AbstractCases */ public function getCounter() { - $query = Delegation::query()->select(); + $query = Application::query()->select(); // Add the initial scope for draft cases - $query->draft($this->getUserId()); + $query->statusId(Application::STATUS_DRAFT); + // Filter the creator + $query->creator($this->getUserUid()); // Return the number of rows - return $query->count(['APP_DELEGATION.APP_NUMBER']); + return $query->count(['APPLICATION.APP_NUMBER']); } /** diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php index e16f617d8..3257bb3eb 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php @@ -3,6 +3,7 @@ namespace ProcessMaker\BusinessModel\Cases; use G; +use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; class Inbox extends AbstractCases @@ -82,6 +83,8 @@ class Inbox extends AbstractCases $query->joinProcess(); // Join with users $query->joinUser(); + // Join with task + $query->JoinTask(); // Join with application for add the initial scope for TO_DO cases $query->inbox($this->getUserId()); /** Apply filters */ diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index 177170e9c..afedfb453 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -232,7 +232,7 @@ class Participated extends AbstractCases case 'IN_PROGRESS': // Only distinct APP_NUMBER $query->distinct(); - // Scope for in progress: TO_DO without DRAFT + // Scope for only TO_DO cases $query->caseTodo(); break; case 'COMPLETED': diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php index eda40c53a..c05bbeb27 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php @@ -79,8 +79,10 @@ class Paused extends AbstractCases $query = Delegation::query()->select($this->getColumnsView()); // Join with process $query->joinProcess(); + // Join with task + $query->JoinTask(); // Scope that set the paused cases - $query->paused($this->getUserId(), $this->getTaskId()); + $query->paused($this->getUserId()); /** Apply filters */ $this->filters($query); /** Apply order and pagination */ @@ -121,7 +123,7 @@ class Paused extends AbstractCases { $query = Delegation::query()->select(); // Scope that set the paused cases - $query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber()); + $query->paused($this->getUserId()); // Return the number of rows return $query->count(['APP_DELEGATION.APP_NUMBER']); } @@ -135,7 +137,7 @@ class Paused extends AbstractCases { $query = Delegation::query()->select(); // Scope that set the paused cases - $query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber()); + $query->paused($this->getUserId()); // Apply filters $this->filters($query); // Return the number of rows diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index 85abbff0d..9bf8ffbbe 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -6,6 +6,7 @@ use G; use ProcessMaker\Model\Application; use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\Process; use ProcessMaker\Model\Task; use ProcessMaker\Model\User; @@ -14,17 +15,15 @@ class Search extends AbstractCases // Columns to see in the cases list public $columnsView = [ // Columns view in the cases list - 'APP_DELEGATION.APP_NUMBER', // Case # - 'APP_DELEGATION.DEL_TITLE', // Case Title + 'APPLICATION.APP_NUMBER', // Case # + 'APPLICATION.APP_TITLE AS DEL_TITLE', // Case Title 'PROCESS.PRO_TITLE', // Process 'APPLICATION.APP_STATUS', // Status 'APPLICATION.APP_CREATE_DATE', // Case create date 'APPLICATION.APP_FINISH_DATE', // Case finish date // Additional column for other functionalities - 'APP_DELEGATION.APP_UID', // Case Uid for Open case - 'APP_DELEGATION.DEL_INDEX', // Del Index for Open case - 'APP_DELEGATION.PRO_UID', // Process Uid for Case notes - 'APP_DELEGATION.TAS_UID', // Task Uid for Case notes + 'APPLICATION.APP_UID', // Case Uid for Open case + 'APPLICATION.PRO_UID', // Process Uid for Case notes ]; /** @@ -59,19 +58,35 @@ class Search extends AbstractCases } // Specific case title if (!empty($this->getCaseTitle())) { - $query->title($this->getCaseTitle()); + // Join with delegation + $query->joinDelegation(); + // Add the filter + // $query->title($this->getCaseTitle()); } // Filter by process if ($this->getProcessId()) { - $query->processId($this->getProcessId()); + $result = Process::query()->select(['PRO_UID']) + ->where('PRO_ID', '=', $this->getProcessId())->get()->toArray(); + $result = head($result); + $query->proUid($result['PRO_UID']); } // Filter by user if ($this->getUserId()) { + // Join with delegation + $query->joinDelegation(); + // Add the filter $query->userId($this->getUserId()); + // Get only the open threads related to the user + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); } // Filter by task if ($this->getTaskId()) { + // Join with delegation + $query->joinDelegation(); + // Add the filter $query->task($this->getTaskId()); + // Get only the open threads related to the task + $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); } // Specific start case date from if (!empty($this->getStartCaseFrom())) { @@ -89,41 +104,9 @@ class Search extends AbstractCases if (!empty($this->getFinishCaseTo())) { $query->finishCaseTo($this->getFinishCaseTo()); } - /** This filter define the UNION */ - // Filter related to the case status like ['DRAFT', 'TO_DO'] if (!empty($this->getCaseStatuses())) { - $statuses = $this->getCaseStatuses(); - $casesOpen = []; - $casesClosed = []; - foreach ($statuses as $row) { - if ($row === self::STATUS_DRAFT or $row === self::STATUS_TODO) { - $casesOpen[] = $row; - } else { - $casesClosed[] = $row; - } - } - if (!empty($casesOpen) && !empty($casesClosed)) { - // Only in this case need to clone the same query for the union - $cloneQuery = clone $query; - // Get the open threads - $query->casesInProgress($casesOpen); - // Get the last thread - $cloneQuery->casesDone($casesClosed); - // Union - $query->union($cloneQuery); - } else { - if (!empty($casesOpen)) { - // Get the open thread - $query->casesInProgress($casesOpen); - } - if (!empty($casesClosed)) { - // Get the last thread - $query->casesDone($casesClosed); - } - } - } else { - $query->isThreadOpen(); + $query->statusIds($this->getCaseStatuses()); } return $query; @@ -136,32 +119,9 @@ class Search extends AbstractCases */ public function getData() { - $query = Delegation::query()->select($this->getColumnsView()); - $query->selectRaw( - 'CONCAT( - \'[\', - GROUP_CONCAT( - CONCAT( - \'{"tas_id":\', - APP_DELEGATION.TAS_ID, - \', "user_id":\', - APP_DELEGATION.USR_ID, - \', "del_id":\', - APP_DELEGATION.DELEGATION_ID, - \', "due_date":"\', - APP_DELEGATION.DEL_TASK_DUE_DATE, - \'"}\' - ) - ), - \']\' - ) AS THREADS' - ); + $query = Application::query()->select($this->getColumnsView()); // Join with process $query->joinProcess(); - // Join with application - $query->joinApplication(); - // Group by AppNumber - $query->groupBy('APP_NUMBER'); /** Apply filters */ $this->filters($query); /** Exclude the web entries does not submitted */ @@ -186,12 +146,36 @@ class Search extends AbstractCases // Get total case notes $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); // Get the detail related to the open thread - if (!empty($item['THREADS'])) { - $result = $this->prepareTaskPending($item['THREADS'], false, $item['APP_STATUS'], $dateToCompare); - $item['THREAD_TASKS'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : []; - $item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : []; - $item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : []; + $taskPending = []; + $status = $item['APP_STATUS']; + switch ($status) { + case 'DRAFT': + case 'TO_DO': + $taskPending = Delegation::getPendingThreads($item['APP_NUMBER']); + break; + case 'COMPLETED': + case 'CANCELLED': + $taskPending = Delegation::getLastThread($item['APP_NUMBER']); + break; } + $i = 0; + $result = []; + foreach ($taskPending as $thread) { + $thread['APP_STATUS'] = $item['APP_STATUS']; + $information = $this->threadInformation($thread, true, true); + $result['THREAD_TASKS'][$i] = $information['THREAD_TASK']; + $result['THREAD_USERS'][$i] = $information['THREAD_USER']; + $result['THREAD_TITLES'][$i] = $information['THREAD_TITLE']; + $i++; + // Del Index for Open case + $item['DEL_INDEX'] = $information['THREAD_TITLE']['del_index']; + // Task Uid for Case notes + $item['TAS_UID'] = $information['THREAD_TASK']['tas_uid']; + } + + $item['THREAD_TASKS'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : []; + $item['THREAD_USERS'] = !empty($result['THREAD_USERS']) ? $result['THREAD_USERS'] : []; + $item['THREAD_TITLES'] = !empty($result['THREAD_TITLES']) ? $result['THREAD_TITLES'] : []; return $item; }); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index fa105c1b3..b960d344e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -102,39 +102,20 @@ class Supervising extends AbstractCases if (!empty($processes)) { // Start the query for get the cases related to the user $query = Delegation::query()->select($this->getColumnsView()); - $query->selectRaw( - 'CONCAT( - \'[\', - GROUP_CONCAT( - CONCAT( - \'{"tas_id":\', - APP_DELEGATION.TAS_ID, - \', "user_id":\', - APP_DELEGATION.USR_ID, - \', "due_date":"\', - APP_DELEGATION.DEL_TASK_DUE_DATE, - \'"}\' - ) - ), - \']\' - ) AS PENDING' - ); + // Join with application + $query->joinApplication(); // Join with process $query->joinProcess(); // Join with task $query->joinTask(); // Join with users $query->joinUser(); - // Join with application - $query->joinApplication(); - // Only cases in to_do + // Only cases in TO_DO $query->caseTodo(); // Scope the specific array of processes supervising $query->processInList($processes); - // Only open threads - $query->isThreadOpen(); - // Group by appNumber - $query->groupBy('APP_NUMBER'); + // Get only the last thread + $query->lastThread(); /** Apply filters */ $this->filters($query); /** Apply order and pagination */ @@ -159,10 +140,13 @@ class Supervising extends AbstractCases // Get total case notes $item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']); // Get the detail related to the open thread - if (!empty($item['PENDING'])) { - $result = $this->prepareTaskPending($item['PENDING']); - $item['PENDING'] = !empty($result['THREAD_TASKS']) ? $result['THREAD_TASKS'] : []; + $taskPending = Delegation::getPendingThreads($item['APP_NUMBER']); + $information = []; + foreach ($taskPending as $thread) { + $thread['APP_STATUS'] = $item['APP_STATUS']; + $information[] = $this->threadInformation($thread); } + $item['PENDING'] = $information; return $item; }); @@ -188,7 +172,7 @@ class Supervising extends AbstractCases $query->caseTodo(); // Only open threads $query->isThreadOpen(); - // Only distinct APP_NUMBER + // For parallel threads the distinct by APP_NUMBER is important $query->distinct(); // Get the list of processes of the supervisor $processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid()); @@ -213,7 +197,7 @@ class Supervising extends AbstractCases $query->caseTodo(); // Only open threads $query->isThreadOpen(); - // Only distinct APP_NUMBER + // For parallel threads the distinct by APP_NUMBER is important $query->distinct(); // Get the list of processes of the supervisor $processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid()); diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index ebbac64dd..3b9d49c9a 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -20,32 +20,45 @@ class Application extends Model // Status name and status id public static $app_status_values = ['DRAFT' => 1, 'TO_DO' => 2, 'COMPLETED' => 3, 'CANCELLED' => 4]; - public function delegations() - { - return $this->hasMany(Delegation::class, 'APP_UID', 'APP_UID'); - } - + /** + * Current user related to the application + */ public function currentUser() { return $this->belongsTo(User::class, 'APP_CUR_USER', 'USR_UID'); } + /** + * Creator user related to the application + */ public function creatorUser() { return $this->belongsTo(User::class, 'APP_INIT_USER', 'USR_UID'); } /** - * Scope for query to get the positive cases + * Scope a query to only include specific user * * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $user + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeUserId($query, $user) + { + return $query->where('APP_DELEGATION.USR_ID', '=', $user); + } + + /** + * Scope for query to get the creator + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $usrUid * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopePositivesCases($query) + public function scopeCreator($query, $usrUid) { - $result = $query->where('APP_NUMBER', '>', 0); - return $result; + return $query->where('APP_INIT_USER', '=', $usrUid); } /** @@ -58,8 +71,108 @@ class Application extends Model */ public function scopeAppUid($query, $appUid) { - $result = $query->where('APP_UID', '=', $appUid); - return $result; + return $query->where('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_UID', $cases); + } + + /** + * Scope for query to get the application by APP_NUMBER + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $appNumber + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCase($query, $appNumber) + { + return $query->where('APPLICATION.APP_NUMBER', '=', $appNumber); + } + + /** + * Scope for query to get the positive cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopePositiveCases($query) + { + return $query->where('APPLICATION.APP_NUMBER', '>', 0); + } + + /** + * Scope a query to only include specific cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $cases + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeSpecificCases($query, array $cases) + { + return $query->whereIn('APPLICATION.APP_NUMBER', $cases); + } + + /** + * Scope more than one range of cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $rangeCases + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeRangeOfCases($query, array $rangeCases) + { + foreach ($rangeCases as $fromTo) { + $fromTo = explode("-", $fromTo); + if (count($fromTo) === 2) { + $from = $fromTo[0]; + $to = $fromTo[1]; + if ($to > $from) { + $query->orWhere(function ($query) use ($from, $to) { + $query->casesFrom($from)->casesTo($to); + }); + } + } + } + } + + /** + * Scope a query to only include cases from a range + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $from + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCasesFrom($query, int $from) + { + return $query->where('APPLICATION.APP_NUMBER', '>=', $from); + } + + /** + * Scope a query to only include cases from a range + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $to + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCasesTo($query, int $to) + { + return $query->where('APPLICATION.APP_NUMBER', '<=', $to); } /** @@ -72,8 +185,20 @@ class Application extends Model */ public function scopeStatusId($query, int $status) { - $result = $query->where('APP_STATUS_ID', '=', $status); - return $result; + return $query->where('APP_STATUS_ID', '=', $status); + } + + /** + * Scope a more status + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $statuses + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeStatusIds($query, array $statuses) + { + return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses); } /** @@ -86,8 +211,104 @@ class Application extends Model */ public function scopeProUid($query, $proUid) { - $result = $query->where('PRO_UID', '=', $proUid); - return $result; + return $query->where('APPLICATION.PRO_UID', '=', $proUid); + } + + /** + * Scope a query to only include a specific start date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $from + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeStartDateFrom($query, string $from) + { + return $query->where('APPLICATION.APP_CREATE_DATE', '>=', $from); + } + + /** + * Scope a query to only include a specific start date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $to + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeStartDateTo($query, string $to) + { + return $query->where('APPLICATION.APP_CREATE_DATE', '<=', $to); + } + + /** + * Scope a query to only include a specific finish date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $from + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeFinishCaseFrom($query, string $from) + { + return $query->where('APPLICATION.APP_FINISH_DATE', '>=', $from); + } + + /** + * Scope a query to only include a specific finish date + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $to + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeFinishCaseTo($query, string $to) + { + return $query->where('APPLICATION.APP_FINISH_DATE', '<=', $to); + } + + /** + * Scope a query to only include a specific task + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $task + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTask($query, int $task) + { + return $query->where('APP_DELEGATION.TAS_ID', '=', $task); + } + + /** + * Scope join with process + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinProcess($query) + { + $query->leftJoin('PROCESS', function ($leftJoin) { + $leftJoin->on('APPLICATION.PRO_UID', '=', 'PROCESS.PRO_UID'); + }); + + return $query; + } + + /** + * Scope join with delegation + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeJoinDelegation($query) + { + $query->leftJoin('APP_DELEGATION', function ($leftJoin) { + $leftJoin->on('APPLICATION.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER'); + }); + + return $query; } /** @@ -103,7 +324,7 @@ class Application extends Model $query = Application::query() ->select() ->proUid($proUid) - ->positivesCases() + ->positiveCases() ->orderBy('APP_NUMBER', 'ASC'); return $query->get(); } @@ -183,7 +404,7 @@ class Application extends Model ->select() ->proUid($proUid) ->statusId($status) - ->positivesCases(); + ->positiveCases(); return $query->get()->count(['APP_NUMBER']); } diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 55d520bd9..0ecd28fa9 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -115,9 +115,7 @@ class Delegation extends Model */ public function scopeCasesDone($query, array $ids) { - $query->lastThread()->statusIds($ids); - - return $query; + return $query->lastThread()->statusIds($ids); } /** @@ -635,7 +633,7 @@ class Delegation extends Model */ public function scopeTaskAssignType($query, $taskType = 'SELF_SERVICE') { - $query->join('TASK', function ($join) use ($taskType) { + $query->leftJoin('TASK', function ($join) use ($taskType) { $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') ->where('TASK.TAS_ASSIGN_TYPE', '=', $taskType); }); @@ -656,7 +654,7 @@ class Delegation extends Model */ public function scopeExcludeTaskTypes($query, array $taskTypes) { - $query->join('TASK', function ($join) use ($taskTypes) { + $query->leftJoin('TASK', function ($join) use ($taskTypes) { $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') ->whereNotIn('TASK.TAS_TYPE', $taskTypes); }); @@ -675,7 +673,7 @@ class Delegation extends Model */ public function scopeSpecificTaskTypes($query, array $taskTypes) { - $query->join('TASK', function ($join) use ($taskTypes) { + $query->leftJoin('TASK', function ($join) use ($taskTypes) { $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') ->whereIn('TASK.TAS_TYPE', $taskTypes); }); @@ -693,7 +691,7 @@ class Delegation extends Model */ public function scopeAppStatusId($query, $statusId = 2) { - $query->join('APPLICATION', function ($join) use ($statusId) { + $query->leftJoin('APPLICATION', function ($join) use ($statusId) { $join->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER') ->where('APPLICATION.APP_STATUS_ID', $statusId); }); @@ -711,7 +709,7 @@ class Delegation extends Model */ public function scopeJoinCategoryProcess($query, $category = '') { - $query->join('PROCESS', function ($join) use ($category) { + $query->leftJoin('PROCESS', function ($join) use ($category) { $join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID'); if ($category) { $join->where('PROCESS.PRO_CATEGORY', $category); @@ -733,16 +731,12 @@ class Delegation extends Model { // This scope is for the join with the APP_DELEGATION table $query->joinApplication(); + // Filter the status to_do $query->status(Application::STATUS_TODO); - - // Scope for the restriction of the task that must not be searched for - $query->excludeTaskTypes(Task::DUMMY_TASKS); - - // Scope that establish that the DEL_THREAD_STATUS must be OPEN - $query->threadOpen(); - // Scope that return the results for an specific user $query->userId($userId); + // Scope that establish that the DEL_THREAD_STATUS must be OPEN + $query->threadOpen(); return $query; } @@ -759,10 +753,8 @@ class Delegation extends Model // This scope is for the join with the APP_DELEGATION table $query->joinApplication(); $query->status(Application::STATUS_TODO); - // Scope for the restriction of the task that must not be searched for $query->excludeTaskTypes(Task::DUMMY_TASKS); - // Scope that establish that the DEL_THREAD_STATUS must be OPEN $query->threadOpen(); @@ -918,6 +910,8 @@ class Delegation extends Model $query->leftJoin('APPLICATION', function ($leftJoin) { $leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER'); }); + + return $query; } /** @@ -930,8 +924,7 @@ class Delegation extends Model */ public function scopeProcessInList($query, array $processes) { - $query->whereIn('APP_DELEGATION.PRO_ID', $processes); - return $query; + return $query->whereIn('APP_DELEGATION.PRO_ID', $processes); } /** @@ -948,7 +941,6 @@ class Delegation extends Model $leftJoin->on('APP_DELAY.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER') ->on('APP_DELEGATION.DEL_INDEX', '=', 'APP_DELAY.APP_DEL_INDEX'); }); - $query->where('APP_DELAY.APP_DISABLE_ACTION_USER', '=', '0'); $query->where('APP_DELAY.APP_TYPE', '=', $type); @@ -968,10 +960,11 @@ class Delegation extends Model $query->leftJoin('USERS', function ($leftJoin) { $leftJoin->on('APP_DELAY.APP_DELEGATION_USER', '=', 'USERS.USR_UID'); }); - - if ($userId) { + // Add filter related to the user + if (!empty($userId)) { $query->where('USERS.USR_ID', $userId); } + return $query; } @@ -980,21 +973,17 @@ class Delegation extends Model * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $userId - * @param int $taskId * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopePaused($query, int $userId, int $taskId) + public function scopePaused($query, int $userId) { + // This scope is for the join with the APP_DELAY and considerate only the PAUSE $query->joinAppDelay('PAUSE'); + // This scope is for the join with the APP_DELAY with USERS table $query->joinAppDelayUsers($userId); + // This scope is for the join with the APP_DELEGATION table $query->joinApplication(); - // Exclude some specific task - $query->excludeTaskTypes(Task::DUMMY_TASKS); - // Specific task - if (!empty($taskId)) { - $query->task($taskId); - } return $query; } @@ -1009,25 +998,24 @@ class Delegation extends Model */ public function casesUnassigned(&$query, $usrUid) { - //Get the task self services related to the user + // Get the task self services related to the user $taskSelfService = TaskUser::getSelfServicePerUser($usrUid); - //Get the task self services value based related to the user + // Get the task self services value based related to the user $selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid); - - //Get the cases unassigned + // Get the cases unassigned if (!empty($selfServiceValueBased)) { $query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) { - //Get the cases related to the task self service + // Get the cases related to the task self service $query->specificTasks($taskSelfService); foreach ($selfServiceValueBased as $case) { - //Get the cases related to the task self service value based + // Get the cases related to the task self service value based $query->orWhere(function ($query) use ($case) { $query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']); }); } }); } else { - //Get the cases related to the task self service + // Get the cases related to the task self service $query->specificTasks($taskSelfService); } @@ -1804,8 +1792,12 @@ class Delegation extends Model public static function getPendingThreads(int $appNumber) { $query = Delegation::query()->select([ + 'TASK.TAS_UID', 'TASK.TAS_TITLE', 'TASK.TAS_ASSIGN_TYPE', + 'APP_DELEGATION.DELEGATION_ID', + 'APP_DELEGATION.DEL_INDEX', + 'APP_DELEGATION.DEL_TITLE', 'APP_DELEGATION.USR_ID', 'APP_DELEGATION.DEL_DELEGATE_DATE', 'APP_DELEGATION.DEL_FINISH_DATE', @@ -1834,17 +1826,21 @@ class Delegation extends Model public static function getLastThread(int $appNumber) { $query = Delegation::query()->select([ + 'TASK.TAS_UID', 'TASK.TAS_TITLE', 'TASK.TAS_ASSIGN_TYPE', + 'APP_DELEGATION.DELEGATION_ID', + 'APP_DELEGATION.DEL_INDEX', + 'APP_DELEGATION.DEL_TITLE', 'APP_DELEGATION.USR_ID', 'APP_DELEGATION.DEL_TASK_DUE_DATE' ]); // Join with task $query->joinTask(); - // Get the last thread created - $query->lastThread(); // Related to the specific case number $query->case($appNumber); + // Get the last thread created + $query->lastThread(); // Get the results $results = $query->get()->values()->toArray(); diff --git a/workflow/engine/src/ProcessMaker/Model/TaskUser.php b/workflow/engine/src/ProcessMaker/Model/TaskUser.php index 27815533f..b14fca6cf 100644 --- a/workflow/engine/src/ProcessMaker/Model/TaskUser.php +++ b/workflow/engine/src/ProcessMaker/Model/TaskUser.php @@ -66,28 +66,27 @@ class TaskUser extends Model { //Get the groups related to the user $groups = GroupUser::getGroups($usrUid, 'GRP_UID'); - // Build query $query = Task::query()->select('TASK.TAS_ID'); - //Add Join with process filtering only the active process - $query->join('PROCESS', function ($join) { + // Add Join with process filtering only the active process + $query->leftJoin('PROCESS', function ($join) { $join->on('PROCESS.PRO_UID', '=', 'TASK.PRO_UID') ->where('PROCESS.PRO_STATUS', 'ACTIVE'); }); - //Add join with with the task users - $query->join('TASK_USER', function ($join) { + // Add join with with the task users + $query->leftJoin('TASK_USER', function ($join) { $join->on('TASK.TAS_UID', '=', 'TASK_USER.TAS_UID') - //We not considered the Ad-hoc + // We not considered the Ad-hoc ->where('TASK_USER.TU_TYPE', '=', 1); }); - //Filtering only the task self-service + // Filtering only the task self-service $query->isSelfService(); - //Filtering the task related to the user + // Filtering the task related to the user $query->where(function ($query) use ($usrUid, $groups) { - //Filtering the user assigned in the task + // Filtering the user assigned in the task $query->where('TASK_USER.USR_UID', '=', $usrUid); if (!empty($groups)) { - //Consider the group related to the user + // Consider the group related to the user $query->orWhere(function ($query) use ($groups) { $query->whereIn('TASK_USER.USR_UID', $groups); });