refactor(inventory): update stock validation rules and enforce stock_difference requirement
This commit is contained in:
@@ -33,8 +33,8 @@ class UpsertFoodVariantsRequest extends FormRequest
|
||||
'variants.*.schedule' => ['required', 'string', 'max:255'],
|
||||
'variants.*.service' => ['required', 'string', 'max:255'],
|
||||
'variants.*.description' => ['sometimes', 'nullable', 'string'],
|
||||
'variants.*.stock' => ['required', 'integer', 'min:0'],
|
||||
'variants.*.stock_difference' => ['nullable', 'integer'],
|
||||
'variants.*.stock' => ['sometimes', 'integer', 'min:0'],
|
||||
'variants.*.stock_difference' => ['sometimes', 'integer'],
|
||||
'variants.*.price' => ['required', 'numeric', 'min:0', 'max:99999999.99'],
|
||||
];
|
||||
}
|
||||
@@ -51,6 +51,20 @@ class UpsertFoodVariantsRequest extends FormRequest
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($variant['id']) && ! array_key_exists('stock_difference', $variant)) {
|
||||
$validator->errors()->add(
|
||||
"variants.{$index}.stock_difference",
|
||||
'La diferencia de stock es obligatoria al actualizar una variante.',
|
||||
);
|
||||
}
|
||||
|
||||
if (! isset($variant['id']) && ! array_key_exists('stock', $variant)) {
|
||||
$validator->errors()->add(
|
||||
"variants.{$index}.stock",
|
||||
'El stock inicial es obligatorio al crear una variante.',
|
||||
);
|
||||
}
|
||||
|
||||
$key = implode('|', [
|
||||
$variant['event_date_id'] ?? '',
|
||||
mb_strtolower(trim((string) ($variant['schedule'] ?? ''))),
|
||||
|
||||
Reference in New Issue
Block a user