Warenwirtschaft: N-06 — Dichte-Snapshot der ml-Bestellung gilt auch im Bearbeiten

Formular, Update-Validierung und Repository nutzen bei unverändertem Rohstoff den
Snapshot als Rückfall; bei Rohstoffwechsel wird keine fremde Dichte übernommen.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-09-08 11:48:02 +00:00
parent 9acb05380a
commit 5d82875d2f
4 changed files with 73 additions and 1 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Requests\Inventory;
use App\Models\Ingredient;
use App\Models\StockEntry;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
@ -72,6 +73,12 @@ class UpdateStockEntryRequest extends FormRequest
// AP-42: ml-Erfassung nur mit hinterlegter Dichte.
if ($this->input('ordered_unit') === 'ml') {
$density = Ingredient::query()->whereKey($this->input('ingredient_id'))->value('density');
// N-06: bei unverändertem Rohstoff gilt der Dichte-Snapshot der Bestellung als Rückfall.
$entry = $this->route('stock_entry');
if (($density === null || (float) $density <= 0) && $entry instanceof StockEntry
&& (int) $entry->ingredient_id === (int) $this->input('ingredient_id') && (float) $entry->density_used > 0) {
$density = $entry->density_used;
}
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.'));
}