From 5d82875d2f80e4d43a98924eded2d84b7bc2af39 Mon Sep 17 00:00:00 2001 From: Kevin Adametz Date: Tue, 8 Sep 2026 11:48:02 +0000 Subject: [PATCH] =?UTF-8?q?Warenwirtschaft:=20N-06=20=E2=80=94=20Dichte-Sn?= =?UTF-8?q?apshot=20der=20ml-Bestellung=20gilt=20auch=20im=20Bearbeiten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Inventory/UpdateStockEntryRequest.php | 7 +++ app/Repositories/StockEntryRepository.php | 7 +++ .../inventory/stock-entries/_form.blade.php | 3 +- tests/Feature/IngredientDensityTest.php | 57 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Inventory/UpdateStockEntryRequest.php b/app/Http/Requests/Inventory/UpdateStockEntryRequest.php index 90affa5..62c9b28 100644 --- a/app/Http/Requests/Inventory/UpdateStockEntryRequest.php +++ b/app/Http/Requests/Inventory/UpdateStockEntryRequest.php @@ -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.')); } diff --git a/app/Repositories/StockEntryRepository.php b/app/Repositories/StockEntryRepository.php index 652bd71..35565b9 100644 --- a/app/Repositories/StockEntryRepository.php +++ b/app/Repositories/StockEntryRepository.php @@ -30,6 +30,13 @@ class StockEntryRepository { if (array_key_exists('entry_type', $data)) { $data['unit'] = ($data['entry_type'] ?? '') === 'ingredient' ? 'gram' : 'piece'; + // N-06: Dichte-Snapshot nur bei unverändertem Rohstoff als Rückfall mitgeben — + // eine fremde alte Dichte darf bei Rohstoffwechsel nicht übernommen werden. + if (($data['ordered_unit'] ?? null) === 'ml' + && (int) ($data['ingredient_id'] ?? 0) === (int) $stockEntry->ingredient_id + && (float) $stockEntry->density_used > 0) { + $data['density_used'] = (float) $stockEntry->density_used; + } $data = $this->applyPurchaseUnit($data); } diff --git a/resources/views/admin/inventory/stock-entries/_form.blade.php b/resources/views/admin/inventory/stock-entries/_form.blade.php index 2a999b6..7499b37 100644 --- a/resources/views/admin/inventory/stock-entries/_form.blade.php +++ b/resources/views/admin/inventory/stock-entries/_form.blade.php @@ -21,7 +21,8 @@