Skip to content

Commit

Permalink
[TM-1386] make command to approve but july,30
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Nov 1, 2024
1 parent ce647b5 commit 80c0e93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?php

namespace Database\Seeders;
namespace App\Console\Commands;

use App\Models\V2\Projects\Project;
use App\Models\V2\Projects\ProjectReport;
use App\Models\V2\Sites\SiteReport;
use App\Models\V2\Tasks\Task;
use Illuminate\Database\Seeder;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;

class UpdateProjectStatusSeeder extends Seeder
class BulkApproveProjects extends Command
{
/**
* Run the database seeds.
*/
public function run()
protected $signature = 'bulk-approve-projects {file}';

protected $description = 'Bulk approve projects from a CSV file';

public function handle(): void
{
$filePath = __DIR__ . '/../../resources/seeds/bulk_approve_projects.csv';
$filePath = $this->argument('file');

if (! File::exists($filePath)) {
$this->command->error("CSV file not found at {$filePath}");
$this->error("CSV file not found at {$filePath}");

return;
}
Expand All @@ -34,6 +35,8 @@ public function run()

$progressBar->start();


$excludeDueDate = '2024-07-30';
foreach ($data as $row) {
$uuid = $row[0];

Expand All @@ -42,17 +45,20 @@ public function run()
if ($project) {
ProjectReport::where('project_id', $project->id)
->whereIn('status', ['awaiting-approval', 'needs-more-information'])
->whereDate('due_at', '!=', $excludeDueDate)
->update(['status' => 'approved']);

$sites = $project->sites;
foreach ($sites as $site) {
SiteReport::where('site_id', $site->id)
->whereIn('status', ['awaiting-approval', 'needs-more-information'])
->whereDate('due_at', '!=', $excludeDueDate)
->update(['status' => 'approved']);
}

Task::where('project_id', $project->id)
->whereIn('status', ['awaiting-approval', 'needs-more-information'])
->whereDate('due_at', '!=', $excludeDueDate)
->update(['status' => 'approved']);
}

Expand Down
84 changes: 0 additions & 84 deletions resources/seeds/bulk_approve_projects.csv

This file was deleted.

0 comments on commit 80c0e93

Please sign in to comment.