Skip to content

Commit

Permalink
Merge pull request #39 from wri/release/aggressive-acacia
Browse files Browse the repository at this point in the history
[RELEASE] Aggressive Acacia
  • Loading branch information
roguenet authored Feb 22, 2024
2 parents 6d2b179 + f22095a commit 0f12783
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 18 deletions.
37 changes: 35 additions & 2 deletions app/Exports/V2/EntityExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,37 @@ protected function getAttachedMappedForEntity($entity): array
$entity->uuid,
$organisation->readable_type ?? null,
$organisation->name ?? null,
$entity->project->name ?? null,
$entity->status ?? null,
$entity->due_at ?? null
];

if (in_array($this->form->type, ['nursery', 'nursery-report','site', 'site-report', 'project-report'])) {
$mapped[] = $entity->project->old_id ?? ($entity->project->id ?? null);
}

if ($this->form->type === 'project-report') {
$mapped[] = $entity->project->uuid ?? null;
if($this->form->framework_key === 'ppc') {
$mapped[] = $entity->seedlings_grown ?? null;
}
}
if ($this->form->type === 'nursery-report') {
$mapped[] = $entity->nursery->old_id ?? ($entity->nursery->id ?? null);
$mapped[] = $entity->nursery->name ?? null;
}

if ($this->form->type === 'site-report') {
$mapped[] = $entity->site->old_id ?? ($entity->site->id ?? null);
$mapped[] = $entity->site->name ?? null;
$sumTreeSPecies = $entity->treeSpecies()->sum('amount');
$mapped[] = $sumTreeSPecies > 0 ? $sumTreeSPecies : null;
$mapped[] = $entity->site->trees_planted_count ?? null;
if($this->form->framework_key === 'ppc') {
$sumSeeding = $entity->seedings()->sum('amount');
$mapped[] = $sumSeeding > 0 ? $sumSeeding : null;
$mapped[] = $entity->site->seeds_planted_count ?? null;
}
}

return $mapped;
Expand All @@ -95,18 +114,32 @@ protected function getAttachedHeadingsForEntity(): array
'uuid',
'organization-readable_type',
'organization-name',
'project_name',
'status',
'due_date'
];

if (in_array($this->form->type, ['nursery', 'nursery-report','site', 'site-report', 'project-report'])) {
$initialHeadings[] = 'project-id';
}

if ($this->form->type === 'project-report') {
$initialHeadings[] = 'project_uuid';
if($this->form->framework_key === 'ppc') {
$initialHeadings[] = 'total_seedlings_grown';
}
}

if ($this->form->type === 'nursery-report') {
$initialHeadings[] = 'nursery-id';
$initialHeadings = array_merge($initialHeadings, ['nursery-id', 'nursery-name']);
}

if ($this->form->type === 'site-report') {
$initialHeadings[] = 'site-id';
$initialHeadings = array_merge($initialHeadings, ['site-id', 'site-name', 'total_trees_planted_report', 'total_trees_planted']);
if($this->form->framework_key === 'ppc') {
$initialHeadings[] = 'total_seeds_planted_report';
$initialHeadings[] = 'total_seeds_planted';
}
}

return $initialHeadings;
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Traits/HandlesUpdateRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function handleUpdateRequest($entity, array $answers): UpdateRequestRe

if (! empty($updateRequest)) {
$updateRequest->content = array_merge($updateRequest->content, $answers);
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$updateRequest->status = UpdateRequest::STATUS_DRAFT;
$updateRequest->save();
} else {
$updateRequest = UpdateRequest::create([
Expand All @@ -30,7 +30,7 @@ protected function handleUpdateRequest($entity, array $answers): UpdateRequestRe
'framework_key' => $entity->framework_key,
'updaterequestable_type' => get_class($entity),
'updaterequestable_id' => $entity->id,
'status' => UpdateRequest::STATUS_AWAITING_APPROVAL,
'status' => UpdateRequest::STATUS_DRAFT,
'content' => $answers,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __invoke(FormSubmission $formSubmission, Request $request): Form

if ($formSubmission->application) {
$formSubmission->application->update(['updated_by' => Auth::user()->id]);
$formSubmission->application->touch();
}

return new FormSubmissionResource($formSubmission);
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/V2/Forms/UpdateFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function __invoke(Form $form, UpdateFormRequest $updateFormRequest): Form

/** Update the form questions in each section */
foreach (data_get($formSection, 'form_questions', []) as $formQuestion) {
$this->handleQuestions($formQuestion, $currentFormSection);
if (data_get($formQuestion, "input_type") == "select") {
$this->updateFormQuestion($formQuestion, $currentFormSection);
} else {
$this->handleQuestions($formQuestion, $currentFormSection);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __invoke(FormSubmission $formSubmission, UpdateFormSubmissionReq
$formSubmission->update($data);
if ($formSubmission->application) {
$formSubmission->application->update(['updated_by' => Auth::user()->id]);
$formSubmission->application->touch();
}

if ($updateFormSubmissionRequest->query('lang')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __invoke(Nursery $nursery, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$nursery->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$nursery->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __invoke(NurseryReport $nurseryReport, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$nurseryReport->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$nurseryReport->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function __invoke(ApproveRejectUserRequest $request): JsonResponse
$this->authorize('approveRejectUser', $organisation);

$organisation->partners()->updateExistingPivot($user, ['status' => 'approved'], false);
$user->update([
'organisation_id' => $organisation->id,
]);

OrganisationUserRequestApprovedEvent::dispatch($request->user(), $user, $organisation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __invoke(ProjectReport $projectReport, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$projectReport->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$projectReport->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __invoke(Project $project, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$project->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$project->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __invoke(SiteReport $siteReport, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$siteReport->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$siteReport->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function __invoke(Site $site, Request $request)
->first();

if (! empty($updateRequest)) {
$updateRequest->status = UpdateRequest::STATUS_AWAITING_APPROVAL;
$site->save();
$updateRequest->update([ 'status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);
$site->update([ 'update_request_status' => UpdateRequest::STATUS_AWAITING_APPROVAL ]);

Action::where('targetable_type', UpdateRequest::class)
->where('targetable_id', $updateRequest->id)
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 @@ -30,6 +30,7 @@ public function rules()
'form_sections.*.title' => ['sometimes', 'nullable', 'string', 'max:65000'],
'form_sections.*.subtitle' => ['sometimes', 'nullable', 'string', 'max:65000'],
'form_sections.*.description' => ['sometimes', 'nullable', 'max:65000'],
'form_sections.*.options_other' => ['sometimes', 'boolean'],

'form_sections.*.form_questions' => ['sometimes', 'nullable', 'array'],
'form_sections.*.form_questions.*.linked_field_key' => ['sometimes', 'nullable', 'string'],
Expand All @@ -44,6 +45,7 @@ public function rules()
'form_sections.*.form_questions.*.additional_props' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.order' => ['sometimes', 'nullable', 'integer'],
'form_sections.*.form_questions.*.options_list' => ['sometimes', 'nullable'],
'form_sections.*.form_questions.*.options_other' => ['sometimes', 'boolean'],

'form_sections.*.form_questions.*.form_question_options' => ['sometimes', 'nullable', 'array'],
'form_sections.*.form_questions.*.form_question_options.*.uuid' => ['sometimes', 'nullable', 'string'],
Expand Down
3 changes: 2 additions & 1 deletion app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,9 @@ public function getTotalReportingTasksAttribute(): int
$projectReportPending = $this->getReportPendingCount(ProjectReport::class, $dueDate, "project_id", $siteIds, $nurseryIds);
$siteRepPending = $this->getReportPendingCount(SiteReport::class, $dueDate, "site_id", $siteIds, $nurseryIds);
$nurRepPending = $this->getReportPendingCount(NurseryReport::class, $dueDate, "nursery_id", $siteIds, $nurseryIds);
$hasPendingTask = Task::forProjectAndDate($this, $dueDate)->whereNot('status', Task::STATUS_COMPLETE)->exists();

if ($projectReportPending + $siteRepPending + $nurRepPending > 0) {
if ($projectReportPending + $siteRepPending + $nurRepPending > 0 || $hasPendingTask) {
$pendingReportingTasks++;
}
}
Expand Down

0 comments on commit 0f12783

Please sign in to comment.