gruene-seele/app/Http/Requests/StoreIngredientRequest.php
Kevin Adametz ea36067831 Warenwirtschaft: AP-20 Rohstoffbestand-Filter + Kein-Rohstoffbestand-Flag
- ingredients.exclude_from_stock (Checkbox im INCI-Formular, z. B. Allergene):
  erscheint nie im Rohstoffbestand und nicht im Kritisch-Badge
- Rohstoffbestand-Uebersicht: Umschalter "Alle" / "Nur aus Herstellerrezepturen"
  (?scope=recipe, nutzt scopeUsedInActiveRecipes aus AP-21)
- Fix: AP-21-Migrationen hatten identischen Timestamp (add_storage lief vor
  create_storage und scheiterte auf MySQL am FK) - umbenannt auf 120753,
  Teilreste bereinigt, Migrationen sauber ausgefuehrt
- Hinweise-Doku fortgeschrieben

Tests: RawMaterialStockTest +2 (volle Suite 172 gruen, 624 Assertions)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 11:42:55 +00:00

71 lines
2.8 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'],
'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', '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')),
'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;
}
}