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>
This commit is contained in:
Kevin Adametz 2026-08-28 09:05:07 +00:00
parent d51860af39
commit fa852340ee
13 changed files with 332 additions and 11 deletions

View file

@ -2,6 +2,7 @@
namespace App\Http\Requests\Inventory;
use App\Models\Ingredient;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
@ -26,6 +27,7 @@ class StoreStockEntryRequest extends FormRequest
'location_id' => ['required', 'integer', 'exists:locations,id'],
'ordered_at' => ['required', 'date'],
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
'ordered_unit' => ['nullable', Rule::in(['gram', 'ml'])],
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
@ -67,6 +69,13 @@ class StoreStockEntryRequest extends FormRequest
if (empty($this->input('quality_id'))) {
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
}
// AP-42: ml-Erfassung nur, wenn für den Rohstoff eine Dichte hinterlegt ist.
if ($this->input('ordered_unit') === 'ml') {
$density = Ingredient::query()->whereKey($this->input('ingredient_id'))->value('density');
if ($density === null || (float) $density <= 0) {
$validator->errors()->add('ordered_quantity', __('Für diesen Rohstoff ist keine Dichte hinterlegt — bitte in Gramm erfassen oder zuerst die Dichte pflegen.'));
}
}
$net = $this->input('price_per_kg');
$gross = $this->input('price_per_kg_gross');
$hasNet = is_numeric($net) && (float) $net > 0;

View file

@ -2,6 +2,7 @@
namespace App\Http\Requests\Inventory;
use App\Models\Ingredient;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
@ -26,6 +27,7 @@ class UpdateStockEntryRequest extends FormRequest
'location_id' => ['required', 'integer', 'exists:locations,id'],
'ordered_at' => ['required', 'date'],
'ordered_quantity' => ['required', 'numeric', 'min:0.000001'],
'ordered_unit' => ['nullable', Rule::in(['gram', 'ml'])],
'quality_id' => ['nullable', 'integer', 'exists:material_qualities,id'],
'tax_rate_id' => ['nullable', 'integer', 'exists:tax_rates,id'],
'price_per_kg' => ['nullable', 'numeric', 'min:0'],
@ -67,6 +69,13 @@ class UpdateStockEntryRequest extends FormRequest
if (empty($this->input('quality_id'))) {
$validator->errors()->add('quality_id', __('Bitte eine Rohstoffqualität wählen.'));
}
// AP-42: ml-Erfassung nur mit hinterlegter Dichte.
if ($this->input('ordered_unit') === 'ml') {
$density = Ingredient::query()->whereKey($this->input('ingredient_id'))->value('density');
if ($density === null || (float) $density <= 0) {
$validator->errors()->add('ordered_quantity', __('Für diesen Rohstoff ist keine Dichte hinterlegt — bitte in Gramm erfassen oder zuerst die Dichte pflegen.'));
}
}
$net = $this->input('price_per_kg');
$gross = $this->input('price_per_kg_gross');
$hasNet = is_numeric($net) && (float) $net > 0;