Skip to content

Commit

Permalink
Merge branch 'staging' into refactor/TM-851_modify_site_polygon_table
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarLima1 committed Jun 4, 2024
2 parents d1a7ca6 + f029d90 commit 5759d71
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Http/Requests/V2/Forms/StoreFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function rules()

'form_sections.*.form_questions' => ['sometimes', 'array'],
'form_sections.*.form_questions.*.linked_field_key' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.collection' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.label' => ['required', 'string'],
'form_sections.*.form_questions.*.input_type' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.name' => ['sometimes', 'nullable'],
Expand All @@ -58,6 +59,7 @@ public function rules()

'form_sections.*.form_questions.*.child_form_questions' => ['sometimes'],
'form_sections.*.form_questions.*.child_form_questions.*.linked_field_key' => ['sometimes', 'required', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.collection' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.label' => ['sometimes', 'required', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.name' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.child_form_questions.*.input_type' => ['sometimes', 'nullable'],
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/V2/Forms/UpdateFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function rules()

'form_sections.*.form_questions' => ['sometimes', 'nullable', 'array'],
'form_sections.*.form_questions.*.linked_field_key' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.collection' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.label' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.uuid' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.name' => ['sometimes', 'nullable'],
Expand Down Expand Up @@ -63,6 +64,7 @@ public function rules()
'form_sections.*.form_questions.*.child_form_questions' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.child_form_questions.*.uuid' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.linked_field_key' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.collection' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.label' => ['sometimes', 'nullable', 'string'],
'form_sections.*.form_questions.*.child_form_questions.*.name' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.child_form_questions.*.input_type' => ['sometimes', 'nullable'],
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Resources/V2/Projects/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function toArray($request)
'seeds_planted_count' => $this->seeds_planted_count,
'regenerated_trees_count' => $this->regenerated_trees_count,
'workday_count' => $this->workday_count,
// Temporary until we have bulk import completed.
'self_reported_workday_count' => $this->self_reported_workday_count,
'total_jobs_created' => $this->total_jobs_created,
'total_sites' => $this->total_sites,
'total_nurseries' => $this->total_nurseries,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Resources/V2/Sites/SiteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function toArray($request)
'site_reports_total' => $this->site_reports_total,
'overdue_site_reports_total' => $this->overdue_site_reports_total,
'workday_count' => $this->workday_count,
// Temporary until we have bulk import completed.
'self_reported_workday_count' => $this->self_reported_workday_count,
'trees_planted_count' => $this->trees_planted_count,
'regenerated_trees_count' => $this->regenerated_trees_count,
'migrated' => ! empty($this->old_model),
Expand Down
15 changes: 15 additions & 0 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Laravel\Scout\Searchable;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
Expand Down Expand Up @@ -372,6 +373,20 @@ public function getWorkdayCountAttribute(): int
)->gender()->sum('amount') ?? 0;
}

public function getSelfReportedWorkdayCountAttribute(): int
{
$sumQueries = [
DB::raw('sum(`workdays_paid`) as paid'),
DB::raw('sum(`workdays_volunteer`) as volunteer'),
];
$projectTotals = $this->reports()->hasBeenSubmitted()->get($sumQueries)->first();
// The groupBy is superfluous, but required because Laravel adds "v2_sites.project_id as laravel_through_key" to
// the SQL select.
$siteTotals = $this->submittedSiteReports()->groupBy('v2_sites.project_id')->get($sumQueries)->first();

return $projectTotals?->paid + $projectTotals?->volunteer + $siteTotals?->paid + $siteTotals?->volunteer;
}

public function getTotalJobsCreatedAttribute(): int
{
$ftTotal = ProjectReport::where('project_id', $this->id)
Expand Down
11 changes: 11 additions & 0 deletions app/Models/V2/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Laravel\Scout\Searchable;
use OwenIt\Auditing\Auditable;
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
Expand Down Expand Up @@ -311,6 +312,16 @@ public function getWorkdayCountAttribute(): int
)->gender()->sum('amount') ?? 0;
}

public function getSelfReportedWorkdayCountAttribute(): int
{
$totals = $this->reports()->hasBeenSubmitted()->get([
DB::raw('sum(`workdays_volunteer`) as volunteer'),
DB::raw('sum(`workdays_paid`) as paid'),
])->first();

return $totals?->paid + $totals?->volunteer;
}

public function getFrameworkUuidAttribute(): ?string
{
return $this->framework ? $this->framework->uuid : null;
Expand Down

0 comments on commit 5759d71

Please sign in to comment.