diff --git a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php index 542cef76f..8d63ce409 100644 --- a/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php +++ b/app/Http/Resources/V2/ProjectReports/ProjectReportResource.php @@ -115,6 +115,13 @@ public function toArray($request) 'volunteer_scstobc' => $this->volunteer_scstobc, 'beneficiaries_scstobc_farmers' => $this->beneficiaries_scstobc_farmers, 'beneficiaries_scstobc' => $this->beneficiaries_scstobc, + 'people_knowledge_skills_increased' => $this->people_knowledge_skills_increased, + 'indirect_beneficiaries' => $this->indirect_beneficiaries, + 'indirect_beneficiaries_description' => $this->indirect_beneficiaries_description, + 'workdays_direct_total' => $this->workdays_direct, + 'workdays_convergence_total' => $this->workdays_convergence, + 'non_tree_total' => $this->non_tree_total, + 'total_community_partners' => $this->total_community_partners, ]; return $this->appendFilesToResource($data); diff --git a/app/Http/Resources/V2/SiteReports/SiteReportResource.php b/app/Http/Resources/V2/SiteReports/SiteReportResource.php index e04d30970..e79590041 100644 --- a/app/Http/Resources/V2/SiteReports/SiteReportResource.php +++ b/app/Http/Resources/V2/SiteReports/SiteReportResource.php @@ -63,6 +63,8 @@ public function toArray($request) 'migrated' => ! empty($this->old_model), 'approved_by' => new UserLiteResource($this->approvedBy), 'created_by' => $this->handleCreatedBy(), + 'regeneration_description' => $this->regeneration_description, + 'total_non_tree_species_planted_count' => $this->total_non_tree_species_planted_count, ]; return $this->appendFilesToResource($data); diff --git a/app/Models/Traits/HasWorkdays.php b/app/Models/Traits/HasWorkdays.php index f80615373..ec97f8b45 100644 --- a/app/Models/Traits/HasWorkdays.php +++ b/app/Models/Traits/HasWorkdays.php @@ -42,6 +42,16 @@ public function getWorkdaysVolunteerAttribute(): int return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['volunteer']); } + public function getWorkdaysDirectAttribute(): int + { + return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['direct']); + } + + public function getWorkdaysConvergenceAttribute(): int + { + return $this->sumTotalWorkdaysAmounts(self::WORKDAY_COLLECTIONS['convergence']); + } + public function getOtherWorkdaysDescriptionAttribute(): ?string { return $this diff --git a/app/Models/V2/Projects/ProjectReport.php b/app/Models/V2/Projects/ProjectReport.php index 9f46afe19..aa44ec361 100644 --- a/app/Models/V2/Projects/ProjectReport.php +++ b/app/Models/V2/Projects/ProjectReport.php @@ -217,6 +217,12 @@ class ProjectReport extends Model implements MediaModel, AuditableContract, Repo Workday::COLLECTION_PROJECT_DIRECT, Workday::COLLECTION_PROJECT_CONVERGENCE, ], + 'direct' => [ + Workday::COLLECTION_PROJECT_DIRECT, + ], + 'convergence' => [ + Workday::COLLECTION_PROJECT_CONVERGENCE, + ], ]; public const RESTORATION_PARTNER_COLLECTIONS = [ @@ -439,11 +445,33 @@ public function getWorkdaysTotalAttribute(): int return $projectReportTotal + $sumTotals('paid') + $sumTotals('volunteer'); } + public function getNonTreeTotalAttribute(): int + { + if (empty($this->task_id)) { + return 0; + } + + return TreeSpecies::where('speciesable_type', SiteReport::class) + ->whereIn('speciesable_id', $this->task->siteReports()->hasBeenSubmitted()->select('id')) + ->where('collection', TreeSpecies::COLLECTION_NON_TREE) + ->visible() + ->sum('amount'); + } + public function getSiteReportsCountAttribute(): int { return $this->task?->siteReports()->count() ?? 0; } + public function getTotalCommunityPartnersAttribute(): int + { + $beneficiaries = ['men', 'women', 'youth', 'scstobc', 'scstobc_farmers', 'smallholder', 'large_scale']; + + return collect($beneficiaries)->reduce(function ($sum, $beneficiary) { + return $sum + ($this->{"beneficiaries_$beneficiary"} ?? 0); + }, 0); + } + public function getNurseryReportsCountAttribute(): ?int { return $this->task?->nurseryReports()->count() ?? 0; diff --git a/app/Models/V2/Sites/SiteReport.php b/app/Models/V2/Sites/SiteReport.php index 2902a3aca..1e37b196b 100644 --- a/app/Models/V2/Sites/SiteReport.php +++ b/app/Models/V2/Sites/SiteReport.php @@ -293,6 +293,11 @@ public function getTotalTreesPlantedCountAttribute(): int return $this->treeSpecies()->visible()->sum('amount'); } + public function getTotalNonTreeSpeciesPlantedCountAttribute(): int + { + return $this->nonTreeSpecies()->visible()->sum('amount'); + } + public function getTotalSeedsPlantedCountAttribute(): int { return $this->seedings()->visible()->sum('amount'); diff --git a/app/Models/V2/Workdays/Workday.php b/app/Models/V2/Workdays/Workday.php index 9484de371..d7ef78db8 100644 --- a/app/Models/V2/Workdays/Workday.php +++ b/app/Models/V2/Workdays/Workday.php @@ -62,6 +62,8 @@ class Workday extends Model implements HandlesLinkedFieldSync self::COLLECTION_PROJECT_VOLUNTEER_NURSERY_OPERATIONS => 'Volunteer Nursery Operations', self::COLLECTION_PROJECT_VOLUNTEER_PROJECT_MANAGEMENT => 'Volunteer Project Management', self::COLLECTION_PROJECT_VOLUNTEER_OTHER => 'Volunteer Other Activities', + self::COLLECTION_PROJECT_DIRECT => 'Direct Workdays', + self::COLLECTION_PROJECT_CONVERGENCE => 'Convergence Workdays', ]; public const COLLECTION_SITE_PAID_SITE_ESTABLISHMENT = 'paid-site-establishment';