bug fixes, daily reports, holidays
This commit is contained in:
48
app/Http/Requests/StoreDailyReportRequest.php
Normal file
48
app/Http/Requests/StoreDailyReportRequest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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.'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user