Umsetzung der Warenwirtschafts-/Produktmanagement-Erweiterung gemaess Entwicklungsplan V4.0: - AP-00: Regressionsbasis fuer 5.1-Features (ProductPhase51Test) - AP-01: URL-Bugfixes B1/B2 (suppliers/packaging-items, breitere url-Spalten) - AP-04/04.1: iPad-taugliche, vereinheitlichte Tabellen-Aktionen - AP-05: Einstellungen "Allgemein" mit UST-Saetzen (tax_rates) und Lieferzeit-Vorlagen (delivery_times, inkl. Tage-Feld) - AP-06: Lieferanten um Bestellweg, Bestell-Mail/-URL und Lieferzeit erweitert - AP-07/07.1: INCI um Lieferanten-Mehrfachwahl, UST und Lieferzeit erweitert; Lieferanten-Detailansicht im Modal mit pflegbaren INCI-/Verpackungslisten - AP-08: Einkauf um UST-Snapshot, Netto/Brutto-Automatik und Duplizieren erweitert Entwicklungsplan aktualisiert: alle Klaerungspunkte (§5) vom Kunden beantwortet und in die jeweiligen APs eingearbeitet (AP-02/03/09/13/15), neues AP-18 (Hinweise-Doku unter Einstellungen) ergaenzt. Naechster Schritt eindeutig markiert: AP-09 (Produktion auf Hersteller-Rezeptur, kein Fallback, Warnung).
103 lines
4.1 KiB
PHP
103 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Inventory;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class UpdateStockEntryRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'entry_type' => ['required', Rule::in(['ingredient', 'packaging', 'shipping'])],
|
|
'ingredient_id' => ['nullable', 'integer', 'exists:ingredients,id'],
|
|
'packaging_item_id' => ['nullable', 'integer', 'exists:packaging_items,id'],
|
|
'supplier_id' => ['required', 'integer', 'exists:suppliers,id'],
|
|
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
|
'ordered_at' => ['required', 'date'],
|
|
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
|
|
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
|
|
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
|
|
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
|
|
'price_per_kg_gross' => ['nullable', 'numeric', 'min:0'],
|
|
'price_total' => ['nullable', 'numeric', 'min:0'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'quality_id.required' => __('Bitte eine Rohstoffqualität wählen.'),
|
|
'price_per_kg.required' => __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'),
|
|
'price_total.required' => __('Bitte den Gesamtpreis netto angeben.'),
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'ordered_quantity' => reFormatNumber($this->input('ordered_quantity')),
|
|
'price_per_kg' => $this->filled('price_per_kg') ? reFormatNumber($this->input('price_per_kg')) : null,
|
|
'price_per_kg_gross' => $this->filled('price_per_kg_gross') ? reFormatNumber($this->input('price_per_kg_gross')) : null,
|
|
'price_total' => $this->filled('price_total') ? reFormatNumber($this->input('price_total')) : null,
|
|
]);
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator): void {
|
|
$type = $this->input('entry_type');
|
|
if ($type === 'ingredient') {
|
|
if (empty($this->input('ingredient_id'))) {
|
|
$validator->errors()->add('ingredient_id', __('Bitte einen Inhaltsstoff wählen.'));
|
|
}
|
|
if (empty($this->input('quality_id'))) {
|
|
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
|
|
}
|
|
$net = $this->input('price_per_kg');
|
|
$gross = $this->input('price_per_kg_gross');
|
|
$hasNet = is_numeric($net) && (float) $net > 0;
|
|
$hasGross = is_numeric($gross) && (float) $gross > 0;
|
|
if (! $hasNet && ! $hasGross) {
|
|
$validator->errors()->add('price_per_kg', __('Bitte den Netto- oder Brutto-Preis pro kg angeben.'));
|
|
}
|
|
} elseif (! empty($type)) {
|
|
if (empty($this->input('packaging_item_id'))) {
|
|
$validator->errors()->add('packaging_item_id', __('Bitte einen Verpackungsartikel wählen.'));
|
|
}
|
|
if (! is_numeric($this->input('price_total')) || (float) $this->input('price_total') <= 0) {
|
|
$validator->errors()->add('price_total', __('Bitte den Gesamtpreis netto angeben.'));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function validatedPayload(): array
|
|
{
|
|
$data = $this->validated();
|
|
if (($data['entry_type'] ?? '') === 'ingredient') {
|
|
$data['packaging_item_id'] = null;
|
|
} else {
|
|
$data['ingredient_id'] = null;
|
|
$data['quality_id'] = null;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|