Skip to content

Commit

Permalink
[TM-1585] add condition to filter approved sites (#635)
Browse files Browse the repository at this point in the history
* [TM-1585] add condition to filter approved sites

* [TM-1585] add condition to filter approved sites
  • Loading branch information
cesarLima1 authored Dec 26, 2024
1 parent b7fc5aa commit cf5ea8e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
}

0 comments on commit cf5ea8e

Please sign in to comment.