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
This commit is contained in:
parent
327259fb4f
commit
9e354d8ef5
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user