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

[RELEASE] Incredible Iroko #283

Merged
merged 16 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
13 changes: 4 additions & 9 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ protected function schedule(Schedule $schedule)
$schedule->command('generate-control-site-due-submissions')->weeklyOn(5, '00:00');

// PPC report jobs
$schedule->job(new CreateTaskDueJob('ppc', 4))->yearlyOn(1, 7);

$schedule->job(new CreateTaskDueJob('ppc', 7))->yearlyOn(3, 15);

$schedule->job(new CreateTaskDueJob('ppc', 10))->yearlyOn(7, 7);

$schedule->job(new CreateTaskDueJob('ppc', 1))->yearlyOn(10, 6);
$schedule->job(new CreateTaskDueJob('ppc', 4, 4))->yearlyOn(3, 14);
$schedule->job(new CreateTaskDueJob('ppc', 7, 5))->yearlyOn(6, 14);
$schedule->job(new CreateTaskDueJob('ppc', 10, 4))->yearlyOn(9, 13);
$schedule->job(new CreateTaskDueJob('ppc', 1, 3))->yearlyOn(12, 13);

// Terrafund report jobs
$schedule->job(new CreateTaskDueJob('terrafund'))->yearlyOn(12, 31);

$schedule->job(new CreateTaskDueJob('terrafund'))->yearlyOn(6, 30);

$schedule->job(new SendReportRemindersJob('terrafund'))->yearlyOn(5, 30);
Expand All @@ -52,7 +48,6 @@ protected function schedule(Schedule $schedule)

$schedule->command('generate-application-export')->twiceDaily(13, 20);
$schedule->command('generate-admin-all-entity-records-export')->twiceDaily(13, 20);
$schedule->command('populate-v2-temporary-sites')->hourly();
}

protected function commands()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __invoke(Request $request, EntityModel $entity)
->where('speciesable_type', get_class($entity))
->where('speciesable_id', $entity->id);

$filter = $request->query('filter');
if (! empty($filter['collection'])) {
$query->where('collection', $filter['collection']);
}

return new TreeSpeciesCollection($query->paginate());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function toArray($request)
'created_by' => $this->handleCreatedBy(),
'seedlings_grown' => $this->seedlings_grown,
'trees_planted_count' => $this->trees_planted_count,
'seeds_planted_count' => $this->seeds_planted_count,
'community_progress' => $this->community_progress,
'equitable_opportunities' => $this->equitable_opportunities,
'local_engagement' => $this->local_engagement,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/V2/SiteReports/SiteReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function toArray($request)

'total_workdays_count' => $this->total_workdays_count,
'total_trees_planted_count' => $this->total_trees_planted_count,
'total_seeds_planted_count' => $this->total_seeds_planted_count,

'due_at' => $this->due_at,
'approved_at' => $this->approved_at,
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/V2/CreateTaskDueJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class CreateTaskDueJob implements ShouldQueue

private $frameworkKey;

public function __construct(string $frameworkKey, int $dueMonth = null)
public function __construct(string $frameworkKey, int $dueMonth = null, int $dueDay = null)
{
$this->frameworkKey = $frameworkKey;

if ($dueMonth) {
$carbonDate = Carbon::createFromFormat('m', $dueMonth)->startOfMonth()->setDay(5);
$carbonDate = Carbon::createFromFormat('m', $dueMonth)->startOfMonth()->setDay($dueDay ?? 5);
$this->dueDate = $carbonDate->isPast() ? $carbonDate->addYear() : $carbonDate;
} else {
$this->dueDate = Carbon::now()->addMonth()->startOfDay();
Expand Down
16 changes: 5 additions & 11 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,7 @@ public function getSeedsPlantedCountAttribute(): int

public function getRegeneratedTreesCountAttribute(): int
{
$sites = Site::where('project_id', $this->id)->get();
$total = 0;
foreach ($sites as $site) {
$total += $site->regenerated_trees_count;
}

return $total;
return $this->submittedSiteReports()->sum('num_trees_regenerating');
}

public function getWorkdayCountAttribute(): int
Expand Down Expand Up @@ -489,11 +483,11 @@ private function submittedSiteReports(): HasManyThrough
}

/**
* @return array The array of site report IDs for all reports associated with sites that have been approved, and
* have a report status not in due or started (reports that have been submitted).
* @return HasManyThrough The query of site report IDs for all reports associated with sites that have been
* approved, and have a report status not in due or started (reports that have been submitted).
*/
private function submittedSiteReportIds(): array
private function submittedSiteReportIds(): HasManyThrough
{
return $this->submittedSiteReports()->pluck('v2_site_reports.id')->toArray();
return $this->submittedSiteReports()->select('v2_site_reports.id');
}
}
37 changes: 16 additions & 21 deletions app/Models/V2/Projects/ProjectReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use App\Models\V2\Organisation;
use App\Models\V2\Polygon;
use App\Models\V2\ReportModel;
use App\Models\V2\Sites\Site;
use App\Models\V2\Seeding;
use App\Models\V2\Sites\SiteReport;
use App\Models\V2\Tasks\Task;
use App\Models\V2\TreeSpecies\TreeSpecies;
Expand Down Expand Up @@ -319,30 +319,25 @@ public function getSeedlingsGrownToDateAttribute(): int

public function getTreesPlantedCountAttribute(): int
{
$total = 0;
if (empty($this->due_at)) {
return $total;
if (empty($this->task_id)) {
return 0;
}

$month = $this->due_at->month;
$year = $this->due_at->year;
$siteIds = Site::where('project_id', data_get($this->project, 'id'))
->isApproved()
->pluck('id')
->toArray();

if (count($siteIds) > 0) {
$reports = SiteReport::whereIn('site_id', $siteIds)
->whereMonth('due_at', $month)
->whereYear('due_at', $year)
->get();

foreach ($reports as $report) {
$total += $report->treeSpecies()->sum('amount');
}
return TreeSpecies::where('speciesable_type', SiteReport::class)
->whereIn('speciesable_id', $this->task->siteReports()->select('id'))
->where('collection', TreeSpecies::COLLECTION_PLANTED)
->sum('amount');
}

public function getSeedsPlantedCountAttribute(): int
{
if (empty($this->task_id)) {
return 0;
}

return $total;
return Seeding::where('seedable_type', SiteReport::class)
->whereIn('seedable_id', $this->task->siteReports()->select('id'))
->sum('amount');
}

public function getTotalJobsCreatedAttribute(): int
Expand Down
6 changes: 1 addition & 5 deletions app/Models/V2/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ public function getTreesPlantedCountAttribute(): int

public function getRegeneratedTreesCountAttribute(): int
{
if (empty($this->a_nat_regeneration) || empty($this->a_nat_regeneration_trees_per_hectare)) {
return 0;
} else {
return $this->a_nat_regeneration * $this->a_nat_regeneration_trees_per_hectare;
}
return $this->reports()->hasBeenSubmitted()->sum('num_trees_regenerating');
}

public function getWorkdayCountAttribute(): int
Expand Down
7 changes: 7 additions & 0 deletions app/Models/V2/Sites/SiteReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SiteReport extends Model implements MediaModel, AuditableContract, ReportM
'polygon_status',
'answers',
'paid_other_activity_description',
'num_trees_regenerating',
'regeneration_description',

// virtual (see HasWorkdays trait)
'other_workdays_description',
Expand Down Expand Up @@ -281,6 +283,11 @@ public function getTotalTreesPlantedCountAttribute(): int
return $this->treeSpecies()->sum('amount');
}

public function getTotalSeedsPlantedCountAttribute(): int
{
return $this->seedings()->sum('amount');
}

public function getOrganisationAttribute()
{
return $this->site ? $this->site->organisation : null;
Expand Down
2 changes: 2 additions & 0 deletions config/wri/linked-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@
// TODO (TM-912) Deprecated, to be removed.
'site-rep-paid-other-activity-description' => ['property' => 'paid_other_activity_description', 'label' => 'Paid Other Activities Description', 'input_type' => 'long-text'],
'site-rep-other-workdays-description' => ['property' => 'other_workdays_description', 'label' => 'Other Activities Description', 'input_type' => 'long-text'],
'site-rep-num-trees-regenerating' => ['property' => 'num_trees_regenerating', 'label' => 'Estimate Number of Trees Restored via ANR', 'input_type' => 'number'],
'site-rep-regeneration-description' => ['property' => 'regeneration_description', 'label' => 'Description of ANR Activities', 'input_type' => 'long-text'],
],
'file-collections' => [
'site-rep-col-media' => ['property' => 'media', 'label' => 'Media', 'input_type' => 'file', 'multichoice' => true],
Expand Down
39 changes: 39 additions & 0 deletions database/migrations/2024_06_07_182710_retype_shared_drive_link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('v2_project_reports', function (Blueprint $table) {
$table->text('shared_drive_link')->nullable()->change();
});
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->text('shared_drive_link')->nullable()->change();
});
Schema::table('v2_nursery_reports', function (Blueprint $table) {
$table->text('shared_drive_link')->nullable()->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('v2_project_reports', function (Blueprint $table) {
$table->string('shared_drive_link')->nullable()->change();
});
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->string('shared_drive_link')->nullable()->change();
});
Schema::table('v2_nursery_reports', function (Blueprint $table) {
$table->string('shared_drive_link')->nullable()->change();
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->integer('num_trees_regenerating')->nullable();
$table->text('regeneration_description')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('v2_site_reports', function (Blueprint $table) {
$table->dropColumn('num_trees_regenerating');
$table->dropColumn('regeneration_description');
});
}
};
Loading