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'); } }