Neuer Helper reFormatWawiNumber(): '5.1'/'5.12' werden als 5,1/5,12 gelesen (kommt beim Kopieren von Daten vor); '1.500' bleibt Tausender. Gilt nur für die WaWi-Eingaben (Mengen, Preise, Gewichte, Rezeptur) — reFormatNumber() app-weit unverändert. JS-Parser (parseGerman, parseDeNumber) auf dieselbe Regel vereinheitlicht; parseDeNumber behandelte '1.500' bisher sogar als 1,5. Tests: +1 (Parsing-Matrix). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Inventory;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class ReceiveStockEntryRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'received_at' => ['required', 'date'],
|
|
'received_quantity' => ['required', 'numeric', 'min:0.000001'],
|
|
'batch_number' => ['nullable', 'string', 'max:100'],
|
|
'best_before' => ['nullable', 'date'],
|
|
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'received_quantity' => reFormatWawiNumber($this->input('received_quantity')),
|
|
]);
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator): void {
|
|
$stockEntry = $this->route('stockEntry') ?? $this->route('stock_entry');
|
|
if ($stockEntry && $stockEntry->entry_type === 'ingredient') {
|
|
if (empty($this->input('batch_number'))) {
|
|
$validator->errors()->add('batch_number', __('Bitte eine Chargennummer angeben.'));
|
|
}
|
|
if (empty($this->input('best_before'))) {
|
|
$validator->errors()->add('best_before', __('Bitte die Mindesthaltbarkeit angeben.'));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|