Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM-1585] add condition to filter approved sites #635

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
Loading