Skip to content

Commit

Permalink
[TM-1621] do not generate reports for started entities
Browse files Browse the repository at this point in the history
  • Loading branch information
pachonjcl committed Jan 15, 2025
1 parent 499a688 commit 56d546d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use App\Models\V2\TreeSpecies\TreeSpecies;
use App\Models\V2\User;
use App\Models\V2\Workdays\Workday;
use App\StateMachines\EntityStatusStateMachine;
use App\StateMachines\ReportStatusStateMachine;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -241,6 +242,11 @@ public function sites(): HasMany
return $this->hasMany(Site::class);
}

public function nonDraftSites(): HasMany
{
return $this->hasMany(Site::class)->where('status', '!=', EntityStatusStateMachine::STARTED);
}

public function controlSites(): HasMany
{
return $this->hasMany(Site::class)->where('control_site', true);
Expand All @@ -251,6 +257,11 @@ public function nurseries(): HasMany
return $this->hasMany(Nursery::class);
}

public function nonDraftNurseries(): HasMany
{
return $this->hasMany(Nursery::class)->where('status', '!=', EntityStatusStateMachine::STARTED);
}

public function reports(): HasMany
{
return $this->hasMany(ProjectReport::class);
Expand Down
6 changes: 4 additions & 2 deletions app/Models/V2/ScheduledJobs/TaskDueJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\V2\Projects\Project;
use App\Models\V2\Projects\ProjectReport;
use App\Models\V2\Tasks\Task;
use App\StateMachines\EntityStatusStateMachine;
use App\StateMachines\ReportStatusStateMachine;
use App\StateMachines\TaskStatusStateMachine;
use Carbon\Carbon;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function getPeriodKeyAttribute(): string
protected function performJob(): void
{
Project::where('framework_key', $this->framework_key)
->where('status', '!=', EntityStatusStateMachine::STARTED)
->chunkById(100, function ($projects) {
foreach ($projects as $project) {
$this->createTask($project);
Expand Down Expand Up @@ -87,7 +89,7 @@ protected function createTask(Project $project): void
]);

$hasSite = false;
foreach ($project->sites as $site) {
foreach ($project->nonDraftSites as $site) {
$hasSite = true;
$task->siteReports()->create([
'framework_key' => $this->framework_key,
Expand All @@ -98,7 +100,7 @@ protected function createTask(Project $project): void
}

$hasNursery = false;
foreach ($project->nurseries as $nursery) {
foreach ($project->nonDraftNurseries as $nursery) {
$hasNursery = true;
$task->nurseryReports()->create([
'framework_key' => $this->framework_key,
Expand Down

0 comments on commit 56d546d

Please sign in to comment.