gruene-seele/app/Http/Requests/StoreIngredientRequest.php
Kevin Adametz fa852340ee Warenwirtschaft: AP-42 — Rohstoff-Dichte (g/ml) für ml-Erfassung im Wareneingang
Kundenentscheid 26.08.: Rohstoffe werden in Gramm geführt, dürfen aber in ml
erfasst werden; über die Dichte ergeben sich die Gramm (100 ml Propolistinktur
× 0,79 = 79 g).

- Neues Feld ingredients.density (g/ml, optional) inkl. Feld im INCI-Formular.
- Wareneingang: Einheiten-Umschalter g/ml am Mengenfeld (nur wenn Dichte
  hinterlegt; Live-Hinweis mit Gramm-Umrechnung, Dichte kommt aus der
  Rohstoff-Suche mit). Erfassung in ml wird über die Dichte in Gramm
  umgerechnet und kanonisch als Gramm gespeichert — InventoryService und alle
  Aggregationen bleiben unverändert. purchase_unit + density_used (Snapshot)
  protokollieren die ml-Erfassung für Anzeige/Bearbeitung; Detailseite zeigt
  „790 g (= 1.000 ml)". Wareneingang-Buchung rechnet gelieferte ml ebenfalls um.
- Serverseitige Validierung: ml nur mit hinterlegter Dichte.

Migrationen add_density_* auf Dev-/Live-DB. 4 Tests, Suite 318 grün.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-28 09:05:07 +00:00

73 lines
3 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreIngredientRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, array<int, mixed>>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'alt_name' => ['nullable', 'string', 'max:255'],
'inci' => ['nullable', 'string'],
'effect' => ['nullable', 'string'],
'pos' => ['nullable', 'integer', 'min:0', 'max:255'],
'default_factor' => ['nullable', 'numeric', 'min:0'],
'min_stock_alert' => ['nullable', 'numeric', 'min:0'],
'density' => ['nullable', 'numeric', 'min:0'],
'material_quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
'delivery_time' => ['nullable', 'string', 'max:255'],
'delivery_time_days' => ['nullable', 'integer', 'min:0', 'max:65535'],
'suppliers' => ['nullable', 'array'],
'suppliers.*.id' => ['nullable', 'integer', 'exists:suppliers,id'],
'suppliers.*.url' => ['nullable', 'string', 'url:http,https', 'max:2048'],
'storage_room_id' => ['nullable', 'integer', 'exists:storage_rooms,id'],
'storage_shelf_id' => ['nullable', 'integer', 'exists:storage_shelves,id'],
'storage_slot_id' => ['nullable', 'integer', 'exists:storage_slots,id'],
'active' => ['sometimes', 'boolean'],
'exclude_from_stock' => ['sometimes', 'boolean'],
];
}
protected function prepareForValidation(): void
{
$this->merge([
'active' => $this->boolean('active'),
'exclude_from_stock' => $this->boolean('exclude_from_stock'),
'default_factor' => $this->normalizeDecimal($this->input('default_factor')),
'min_stock_alert' => $this->normalizeDecimal($this->input('min_stock_alert')),
'density' => $this->normalizeDecimal($this->input('density')),
'material_quality_id' => $this->nullIfEmpty($this->input('material_quality_id')),
'tax_rate_id' => $this->nullIfEmpty($this->input('tax_rate_id')),
'delivery_time_days' => $this->nullIfEmpty($this->input('delivery_time_days')),
'storage_room_id' => $this->nullIfEmpty($this->input('storage_room_id')),
'storage_shelf_id' => $this->nullIfEmpty($this->input('storage_shelf_id')),
'storage_slot_id' => $this->nullIfEmpty($this->input('storage_slot_id')),
]);
}
private function normalizeDecimal(mixed $value): ?string
{
if ($value === null || $value === '') {
return null;
}
return (string) reFormatNumber($value);
}
private function nullIfEmpty(mixed $value): mixed
{
return $value === '' ? null : $value;
}
}