diff --git a/app/Console/Commands/RefreshActivityElementCompleteness.php b/app/Console/Commands/RefreshActivityElementCompleteness.php index d22a9dc71e..f9c2e681d3 100644 --- a/app/Console/Commands/RefreshActivityElementCompleteness.php +++ b/app/Console/Commands/RefreshActivityElementCompleteness.php @@ -9,6 +9,7 @@ use Exception; use Illuminate\Console\Command; use Illuminate\Contracts\Container\BindingResolutionException; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; /** @@ -52,15 +53,22 @@ public function handle(): void $methodName = dashesToCamelCase('is_' . $element . '_element_completed'); if (method_exists($elementCompleteService, $methodName)) { - $elementStatus[$element] = $elementCompleteService->$methodName($activity); + if ($element === 'reporting_org') { + $organization = $activity->organization; + $elementStatus[$element] = Arr::get($organization, 'element_status.reporting_org', false); + } else { + $elementStatus[$element] = $elementCompleteService->$methodName($activity); + } } } $elementStatus['result'] = $elementCompleteService->isResultElementCompleted($activity); $elementStatus['transactions'] = $elementCompleteService->isTransactionsElementCompleted($activity); + $complete_percentage = $elementCompleteService->calculateCompletePercentage($elementStatus); + $activity->timestamps = false; - $activity->updateQuietly(['element_status' => $elementStatus]); + $activity->updateQuietly(['element_status' => $elementStatus, 'complete_percentage' => $complete_percentage]); $this->info("Completed for activity: $activity->id"); $this->info('---------------------------------------'); diff --git a/app/IATI/Services/Activity/ActivityService.php b/app/IATI/Services/Activity/ActivityService.php index 480ea728c6..5d449ed7fd 100644 --- a/app/IATI/Services/Activity/ActivityService.php +++ b/app/IATI/Services/Activity/ActivityService.php @@ -85,17 +85,14 @@ public function getPaginatedActivities(int $page, array $queryParams): Collectio $page ); + $orgReportingOrgStatus = Arr::get(\auth()->user()->organization, 'element_status.reporting_org', false); + foreach ($activities as $idx => $activity) { $activities[$idx]['default_title_narrative'] = $activity->default_title_narrative; - $activity->setAttribute( - 'coreCompleted', - isCoreElementCompleted( - array_merge( - ['reporting_org' => $activity->organization->reporting_org_element_completed], - $activity->element_status - ) - ) - ); + $elementStatus = $activity->element_status; + $elementStatus['reporting_org'] = $orgReportingOrgStatus; + + $activity->setAttribute('coreCompleted', isCoreElementCompleted($elementStatus)); } return $activities; diff --git a/app/IATI/Services/ElementCompleteService.php b/app/IATI/Services/ElementCompleteService.php index 56f48a7c06..5e40cf84e5 100644 --- a/app/IATI/Services/ElementCompleteService.php +++ b/app/IATI/Services/ElementCompleteService.php @@ -375,7 +375,7 @@ public function isSectorElementCompleted($activity): bool foreach ($activity->sector as $sector) { $sectorVocab = Arr::get($sector, 'sector_vocabulary') ?? null; - $codeKey = $this->getSectorCodeKeyBasedOnVocab($sectorVocab); + $codeKey = $this->getSectorCodeKeyBasedOnVocab((string) $sectorVocab); if ($this->isEmptyValue(Arr::get($sector, $codeKey))) { return false; @@ -397,7 +397,7 @@ public function isSectorElementCompletedInTransaction(Activity $activity): bool foreach (Arr::get($transaction, 'transaction.sector', []) as $sector) { if (!is_array_value_empty($sector)) { $sectorVocab = Arr::get($sector, 'sector_vocabulary') ?? null; - $codeKey = $this->getSectorCodeKeyBasedOnVocab($sectorVocab); + $codeKey = $this->getSectorCodeKeyBasedOnVocab((string) $sectorVocab); if ($this->isEmptyValue(Arr::get($sector, $codeKey))) { return false; @@ -1174,7 +1174,7 @@ public function checkIfRecipientCountryElementCompleted($activity): bool })['total']; if ($firstGroupTotalPercentage === 100.0) { - return $countryStatus; + return true; } return false; @@ -1214,7 +1214,11 @@ public function refreshElementStatus($activity): void $methodName = dashesToCamelCase('is_' . $attribute . '_element_completed'); if (is_callable([$this, $methodName])) { - $elementStatus[$attribute] = call_user_func([$this, $methodName], $activity); + if ($attribute === 'reporting_org') { + $elementStatus[$attribute] = Arr::get(auth()->user()->organization, 'element_status.reporting_org', false); + } else { + $elementStatus[$attribute] = call_user_func([$this, $methodName], $activity); + } } } @@ -1320,7 +1324,7 @@ public function refreshDeprecationStatusMap($activity): void */ public function isEmptyValue($value): bool { - return trim($value ?? '') === ''; + return $value === null || (is_string($value) && trim($value) === ''); } /** diff --git a/app/Observers/TransactionObserver.php b/app/Observers/TransactionObserver.php index e940ec7766..c2f5c228e6 100644 --- a/app/Observers/TransactionObserver.php +++ b/app/Observers/TransactionObserver.php @@ -56,23 +56,10 @@ public function updateActivityElementStatus($transaction, bool $changeUpdatedAt $isSectorFilledInTransactionLevel = $transactionService->checkIfTransactionHasElementDefined($activityObj, 'sector'); $isSectorCompleteInTransactionLevel = $this->elementCompleteService->isSectorElementCompletedInTransaction($transaction->activity); - /* - * Basically performing AND operations in the switch case. - */ - switch([ - $isSectorFilledInActivityLevel, - $isSectorCompletedInActivityLevel, - $isSectorFilledInTransactionLevel, - $isSectorCompleteInTransactionLevel, - ]) { - case [false, false, true, true]: - case [false, true, true, true]: - case [true, true, false, false]: - $elementStatus['sector'] = true; - break; - default: - $elementStatus['sector'] = false; - break; + $elementStatus['sector'] = false; + + if (($isSectorFilledInActivityLevel && $isSectorCompletedInActivityLevel) || ($isSectorFilledInTransactionLevel && $isSectorCompleteInTransactionLevel)) { + $elementStatus['sector'] = true; } $recipientRegionOrCountryIsCompleteInActivity = $this->elementCompleteService->isRecipientCountryElementCompleted($activityObj) || $this->elementCompleteService->isRecipientRegionElementCompleted($activityObj); diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 7073ee7d49..a362506cf0 100755 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,10 +1,10 @@ { - "/js/app.js": "/js/app.js?id=389584d278afd9afe8aada34baecb35d", - "/js/script.js": "/js/script.js?id=5022c99737e05b78f00088f76a8a0f9f", - "/js/webportal-script.js": "/js/webportal-script.js?id=1bcae4271c042a8b79b241f34a1653fc", - "/js/formbuilder.js": "/js/formbuilder.js?id=61b98dc742ffedfa84ee6995cd9691c5", - "/manifest.js": "/manifest.js?id=3ed1124c8f4dcb98acc36de67cb80349", - "/css/webportal-app.css": "/css/webportal-app.css?id=af8ac750f9e32cd730d74440f0aa1c0a", - "/css/app.css": "/css/app.css?id=49c20c5d30e48e7ad9788f2521851589", - "/js/vendor.js": "/js/vendor.js?id=1d9dc84f31934bcf90e4083803feee6b" + "/js/app.js": "/js/app.js", + "/js/script.js": "/js/script.js", + "/js/webportal-script.js": "/js/webportal-script.js", + "/js/formbuilder.js": "/js/formbuilder.js", + "/manifest.js": "/manifest.js", + "/css/webportal-app.css": "/css/webportal-app.css", + "/css/app.css": "/css/app.css", + "/js/vendor.js": "/js/vendor.js" }