@@ -28,6 +28,9 @@ class RequisitionDraftInput
|
||||
'items.*.catalogue_entry_id' => 'nullable|integer|min:1',
|
||||
'items.*.catalogue_version' => 'nullable|required_with:items.*.catalogue_entry_id|integer|min:1',
|
||||
'items.*.source_line_id' => 'nullable|integer|min:1',
|
||||
'items.*.procurement_category' => $this->categoriesAvailable()
|
||||
? ['nullable', Rule::in(array_keys(RequisitionCategories::LABELS))] : ['prohibited'],
|
||||
'items.*.category_reason' => $this->categoriesAvailable() ? 'nullable|string|max:2000' : 'prohibited',
|
||||
'items.*.description' => ['required_without:items.*.catalogue_entry_id', 'string', 'max:255'],
|
||||
'items.*.category' => ['required_without:items.*.catalogue_entry_id', 'string', 'max:100'],
|
||||
'items.*.purchase_type' => ['required_without:items.*.catalogue_entry_id', Rule::in(['consumable', 'service', 'other', 'equipment', 'spare_part'])],
|
||||
@@ -42,6 +45,11 @@ class RequisitionDraftInput
|
||||
];
|
||||
}
|
||||
|
||||
private function categoriesAvailable(): bool
|
||||
{
|
||||
return app(RequisitionCategories::class)->available();
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function rules(User $user): array
|
||||
{
|
||||
@@ -64,7 +72,16 @@ class RequisitionDraftInput
|
||||
/** @param array<string,mixed> $data */
|
||||
public function complete(User $user, array $data): bool
|
||||
{
|
||||
return Validator::make($data, $this->completeRules($user))->passes();
|
||||
if (! Validator::make($data, $this->completeRules($user))->passes() || ! is_array($data['items'] ?? null)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($data['items'] as $line) {
|
||||
if (! is_array($line) || app(RequisitionCategories::class)->incomplete($line)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $data
|
||||
|
||||
Reference in New Issue
Block a user