DONE: merge heir tab into profile tab, santize userIcNum and name, rename to malay, add stat card on user list
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -113,8 +113,6 @@ abstract class BaseCrudController extends Controller
|
||||
|
||||
$item = $this->repository->create($data);
|
||||
|
||||
ActivityLogger::log("Created {$this->resourceName}: {$this->getItemName($item)}", $item);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => new $this->resourceClass($item),
|
||||
@@ -175,8 +173,6 @@ abstract class BaseCrudController extends Controller
|
||||
|
||||
$item->update($data);
|
||||
|
||||
ActivityLogger::log("Updated {$this->resourceName}: {$this->getItemName($item)}", $item);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => new $this->resourceClass($item),
|
||||
@@ -221,8 +217,6 @@ abstract class BaseCrudController extends Controller
|
||||
|
||||
$this->repository->delete($id);
|
||||
|
||||
ActivityLogger::log("Deleted {$this->resourceName}: {$this->getItemName($item)}", $item);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $this->getSuccessMessage('destroy'),
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\KJCHistoricalDataService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CaptureKJCHistoricalDataJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 300; // 5 minutes timeout
|
||||
|
||||
public $tries = 3; // Retry 3 times if failed
|
||||
|
||||
public $backoff = 60; // Wait 60 seconds between retries
|
||||
|
||||
protected $month;
|
||||
|
||||
protected $year;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($month = null, $year = null)
|
||||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
|
||||
// Set queue name for Horizon monitoring
|
||||
$this->onQueue('kjc-historical-data');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(KJCHistoricalDataService $kjcHistoricalService)
|
||||
{
|
||||
try {
|
||||
Log::info('Starting KJC historical data capture job', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
|
||||
$success = $kjcHistoricalService->captureMonthlySnapshots($this->month, $this->year);
|
||||
|
||||
if ($success) {
|
||||
Log::info('KJC historical data capture job completed successfully', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
} else {
|
||||
Log::error('KJC historical data capture job failed', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
|
||||
throw new \Exception('KJC historical data capture failed');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('KJC historical data capture job exception', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a job failure.
|
||||
*/
|
||||
public function failed(\Throwable $exception)
|
||||
{
|
||||
Log::error('KJC historical data capture job failed permanently', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
'error' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tags that should be assigned to the job.
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return ['kjc-historical-data', "month-{$this->month}", "year-{$this->year}"];
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\PKJHistoricalDataService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CapturePKJHistoricalDataJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 300; // 5 minutes timeout
|
||||
|
||||
public $tries = 3; // Retry 3 times if failed
|
||||
|
||||
public $backoff = 60; // Wait 60 seconds between retries
|
||||
|
||||
protected $month;
|
||||
|
||||
protected $year;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($month = null, $year = null)
|
||||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
|
||||
// Set queue name for Horizon monitoring
|
||||
$this->onQueue('pkj-historical-data');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(PKJHistoricalDataService $historicalService)
|
||||
{
|
||||
try {
|
||||
Log::info('Starting PKJ historical data capture job', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
|
||||
$success = $historicalService->captureMonthlySnapshots($this->month, $this->year);
|
||||
|
||||
if ($success) {
|
||||
Log::info('PKJ historical data capture job completed successfully', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
} else {
|
||||
Log::error('PKJ historical data capture job failed', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
]);
|
||||
|
||||
throw new \Exception('PKJ historical data capture failed');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('PKJ historical data capture job exception', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a job failure.
|
||||
*/
|
||||
public function failed(\Throwable $exception)
|
||||
{
|
||||
Log::error('PKJ historical data capture job failed permanently', [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'job_id' => $this->job ? $this->job->getJobId() : 'manual-execution',
|
||||
'error' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tags that should be assigned to the job.
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return ['pkj-historical-data', "month-{$this->month}", "year-{$this->year}"];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user