49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Carbon\Carbon;
|
|
use App\Models\ReportOverride;
|
|
|
|
class StoreDailyReportRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'report_date' => 'required|date|before_or_equal:today',
|
|
'content' => 'required|string',
|
|
];
|
|
}
|
|
|
|
public function withValidator($validator)
|
|
{
|
|
$validator->after(function ($validator) {
|
|
$reportDate = Carbon::parse($this->report_date)->startOfDay();
|
|
|
|
// Calculate standard deadline: 48 hours from the end of the report date
|
|
$deadline = $reportDate->copy()->endOfDay()->addHours(48);
|
|
|
|
if (now()->greaterThan($deadline)) {
|
|
// Check if a valid override exists
|
|
$hasOverride = ReportOverride::where('user_id', auth()->id())
|
|
->where('report_date', $this->report_date)
|
|
->where('expires_at', '>', now())
|
|
->exists();
|
|
|
|
if (!$hasOverride) {
|
|
$validator->errors()->add(
|
|
'report_date',
|
|
'The 48-hour submission window for this date has expired. Please contact management for an override.'
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|