Skip to content

Commit

Permalink
feat: Updated app/Http/Controllers/ProductControll
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 11, 2024
1 parent 853700e commit ad32326
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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',
]);
}

0 comments on commit ad32326

Please sign in to comment.