first init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\KJCReport\Entities\KJCReport;
|
||||
use Modules\KJCReport\Jobs\GenerateTeamWeeklyReports;
|
||||
use Modules\Unit\Entities\Unit;
|
||||
use Modules\Auth\Entities\User;
|
||||
|
||||
class AutoGenerateWeeklyReportForUnit extends Command
|
||||
{
|
||||
protected $signature = 'kjc:auto-generate-weekly-report
|
||||
{unit : Unit name to generate reports for (e.g. "Jabatan Arah RAJD")}
|
||||
{--force : Force generation even if reports already exist}';
|
||||
|
||||
protected $description = 'Auto-generate weekly KJC reports for a specific unit';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$unitName = $this->argument('unit');
|
||||
|
||||
$unit = Unit::where('name', $unitName)->first();
|
||||
|
||||
if (! $unit) {
|
||||
$this->error("Unit '{$unitName}' not found.");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$month = strtolower(now()->format('F'));
|
||||
$week = (int) ceil(now()->day / 7);
|
||||
|
||||
if (! $this->option('force')) {
|
||||
$existingReports = KJCReport::where('unit_id', $unit->id)
|
||||
->where('report_type', 'weekly')
|
||||
->where('report_month', $month)
|
||||
->where('report_week', $week)
|
||||
->exists();
|
||||
|
||||
if ($existingReports) {
|
||||
$this->info("Reports for {$unitName} - {$month} week {$week} already exist. Skipping.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::where('unit_id', $unit->id)->first();
|
||||
|
||||
GenerateTeamWeeklyReports::dispatch($unit->id, $month, $week, $user?->id);
|
||||
|
||||
$this->info("✓ Queued weekly report generation for {$unitName} - {$month} week {$week}");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CaptureKJCHistoricalDataJob;
|
||||
use App\Services\KJCHistoricalDataService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TriggerKJCHistoricalDataCapture extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'kjc:historical:trigger
|
||||
{--month= : Month to capture (1-12)}
|
||||
{--year= : Year to capture (YYYY)}
|
||||
{--queue : Dispatch to queue instead of running immediately}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Manually trigger KJC historical data capture';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$month = $this->option('month');
|
||||
$year = $this->option('year');
|
||||
$useQueue = $this->option('queue');
|
||||
|
||||
// If no month/year provided, use previous month
|
||||
if (! $month || ! $year) {
|
||||
$lastMonth = Carbon::now()->subMonth();
|
||||
$month = $month ?: $lastMonth->format('m');
|
||||
$year = $year ?: $lastMonth->format('Y');
|
||||
}
|
||||
|
||||
$this->info("Triggering KJC historical data capture for {$month}/{$year}...");
|
||||
|
||||
try {
|
||||
if ($useQueue) {
|
||||
// Dispatch to queue
|
||||
CaptureKJCHistoricalDataJob::dispatch($month, $year);
|
||||
$this->info('✓ KJC historical data capture job dispatched to queue');
|
||||
$this->info('You can monitor the job in Horizon dashboard');
|
||||
} else {
|
||||
// Run immediately
|
||||
$job = new CaptureKJCHistoricalDataJob($month, $year);
|
||||
$job->handle(app(KJCHistoricalDataService::class));
|
||||
$this->info('✓ KJC historical data capture completed immediately');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error: '.$e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\CapturePKJHistoricalDataJob;
|
||||
use App\Services\PKJHistoricalDataService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class TriggerPKJHistoricalDataCapture extends Command
|
||||
{
|
||||
protected $signature = 'pkj:historical:trigger
|
||||
{--month= : Month to capture (1-12)}
|
||||
{--year= : Year to capture (YYYY)}
|
||||
{--queue : Dispatch to queue instead of running immediately}';
|
||||
|
||||
protected $description = 'Manually trigger PKJ historical data capture';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$month = $this->option('month');
|
||||
$year = $this->option('year');
|
||||
$useQueue = $this->option('queue');
|
||||
|
||||
// If no month/year provided, use previous month
|
||||
if (! $month || ! $year) {
|
||||
$lastMonth = Carbon::now()->subMonth();
|
||||
$month = $month ?: $lastMonth->format('m');
|
||||
$year = $year ?: $lastMonth->format('Y');
|
||||
}
|
||||
|
||||
$this->info("Triggering PKJ historical data capture for {$month}/{$year}...");
|
||||
|
||||
try {
|
||||
if ($useQueue) {
|
||||
// Dispatch to queue
|
||||
CapturePKJHistoricalDataJob::dispatch($month, $year);
|
||||
$this->info('✓ PKJ historical data capture job dispatched to queue');
|
||||
$this->info('You can monitor the job in Horizon dashboard');
|
||||
} else {
|
||||
// Run immediately
|
||||
$job = new CapturePKJHistoricalDataJob($month, $year);
|
||||
$job->handle(app(PKJHistoricalDataService::class));
|
||||
$this->info('✓ PKJ historical data capture completed immediately');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error: '.$e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user