42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Reports;
|
|
|
|
use App\Enums\ExpenseCategory;
|
|
use App\Enums\FundingSource;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreMedicationExpenseValuesRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user() !== null;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'report_period_id' => ['required', 'integer', 'exists:report_periods,id'],
|
|
'department_id' => ['required', 'integer', 'exists:departments,id'],
|
|
'values' => ['required', 'array'],
|
|
];
|
|
|
|
foreach (FundingSource::cases() as $fundingSource) {
|
|
foreach (ExpenseCategory::cases() as $expenseCategory) {
|
|
$rules["values.{$fundingSource->value}.{$expenseCategory->value}"] = ['nullable', 'numeric', 'min:0'];
|
|
}
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|