From ad32326eab4ac1567172f109b7fc5103d780a02a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:55:27 +0000 Subject: [PATCH] feat: Updated app/Http/Controllers/ProductControll --- app/Http/Controllers/ProductController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 8d7f3fc..2eafcdb 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -19,6 +19,12 @@ public function create(Request $request) ]); $product = Product::create($validatedData); + + // Create an initial inventory log entry + $product->inventoryLogs()->create([ + 'quantity_change' => $validatedData['inventory_count'], + 'reason' => 'Initial stock setup', + ]); return response()->json($product, Response::HTTP_CREATED); } @@ -75,3 +81,11 @@ public function delete($id) return response()->json(['message' => 'Product deleted successfully']); } } + // Check if inventory_count is being updated and log the change + if (isset($validatedData['inventory_count'])) { + $quantityChange = $validatedData['inventory_count'] - $product->getOriginal('inventory_count'); + $product->inventoryLogs()->create([ + 'quantity_change' => $quantityChange, + 'reason' => 'Inventory adjustment', + ]); + }