From 9e354d8ef590f8668e00678d000675a256fa5bc8 Mon Sep 17 00:00:00 2001 From: Stefan Zwischenbrugger Date: Tue, 31 Mar 2026 19:47:16 +0200 Subject: [PATCH] Eintrag-Reaktivierung: erledigte Treffer statt Duplikat neu anlegen Beim Anlegen wird ein bestehender erledigter Eintrag mit gleichem Produktnamen in der aktuellen Liste wieder auf offen gesetzt (statt neuen Eintrag zu erzeugen). Made-with: Cursor --- .../Controllers/ShoppingListController.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ShoppingListController.php b/app/Http/Controllers/ShoppingListController.php index 4f4e75c..299dc1a 100644 --- a/app/Http/Controllers/ShoppingListController.php +++ b/app/Http/Controllers/ShoppingListController.php @@ -74,16 +74,35 @@ class ShoppingListController extends Controller $currentList = $this->currentShoppingList($request); $this->authorize('view', $currentList); + $productName = trim($request->string('product_name')->toString()); $storeId = $this->resolveStoreId( $request->integer('store_id') ?: null, $request->input('new_store_name'), $request->user()->id ); + $doneItem = ShoppingItem::query() + ->where('shopping_list_id', $currentList->id) + ->whereRaw('LOWER(product_name) = ?', [mb_strtolower($productName)]) + ->where('is_done', true) + ->latest('id') + ->first(); + + if ($doneItem !== null) { + $doneItem->update([ + 'is_done' => false, + 'done_at' => null, + 'store_id' => $storeId ?? $doneItem->store_id, + 'quantity' => $request->filled('quantity') ? $request->string('quantity')->toString() : $doneItem->quantity, + ]); + + return back()->with('status', 'Eintrag wurde aus erledigt nach offen uebernommen.'); + } + ShoppingItem::query()->create([ 'shopping_list_id' => $currentList->id, 'created_by' => $request->user()->id, - 'product_name' => $request->string('product_name')->toString(), + 'product_name' => $productName, 'quantity' => $request->filled('quantity') ? $request->string('quantity')->toString() : null, 'store_id' => $storeId, 'is_done' => false,