From cf5ea8ea6ed6dabd50801f3d084708bf3c902473 Mon Sep 17 00:00:00 2001 From: cesarLima1 <105736261+cesarLima1@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:24:18 -0400 Subject: [PATCH] [TM-1585] add condition to filter approved sites (#635) * [TM-1585] add condition to filter approved sites * [TM-1585] add condition to filter approved sites --- app/Models/V2/Projects/Project.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Models/V2/Projects/Project.php b/app/Models/V2/Projects/Project.php index 4688da5c..354c6d93 100644 --- a/app/Models/V2/Projects/Project.php +++ b/app/Models/V2/Projects/Project.php @@ -305,6 +305,22 @@ public function sitePolygons(): HasManyThrough )->active(); } + public function approvedSitePolygons(): HasManyThrough + { + return $this->hasManyThrough( + SitePolygon::class, + Site::class, + 'project_id', + 'site_id', + 'id', + 'uuid' + ) + ->whereHas('site', function ($query) { + $query->whereIn('status', Site::$approvedStatuses); + }) + ->active(); + } + public function treeSpecies() { return $this->morphMany(TreeSpecies::class, 'speciesable'); @@ -615,6 +631,6 @@ public function getTotalSitePolygonsAttribute() public function getTotalHectaresRestoredSumAttribute(): float { - return round($this->sitePolygons->where('status', 'approved')->sum('calc_area')); + return $this->approvedSitePolygons->where('status', 'approved')->sum('calc_area'); } }