From 5b2a46c753498a20c85dea549c2dc438d18220c7 Mon Sep 17 00:00:00 2001 From: Ghassan Yusuf Date: Tue, 19 May 2026 13:19:45 +0300 Subject: [PATCH] feat: send WhatsApp low stock alert to store managers --- .../Inventory/StockMovementController.php | 11 +++++++ .../Inventory/LowStockAlertNotification.php | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 app/Notifications/Inventory/LowStockAlertNotification.php diff --git a/app/Http/Controllers/Inventory/StockMovementController.php b/app/Http/Controllers/Inventory/StockMovementController.php index 38d20fb..f0c5293 100644 --- a/app/Http/Controllers/Inventory/StockMovementController.php +++ b/app/Http/Controllers/Inventory/StockMovementController.php @@ -7,6 +7,7 @@ use App\Models\Item; use App\Models\StockLevel; use App\Models\StockMovement; use App\Models\Warehouse; +use App\Notifications\Inventory\LowStockAlertNotification; use Illuminate\Http\Request; class StockMovementController extends Controller @@ -58,6 +59,16 @@ class StockMovementController extends Controller 'created_by' => auth()->id(), ]); + $stockLevel->refresh(); + $item = Item::find($request->item_id); + if ($item && $item->minimum_stock_level && $stockLevel->quantity <= $item->minimum_stock_level) { + $storeManagers = \App\Models\User::role('Store Manager')->whereNotNull('whatsapp_number')->get(); + \Illuminate\Support\Facades\Notification::send( + $storeManagers, + new LowStockAlertNotification($item, $stockLevel) + ); + } + return redirect()->route('inventory.movements.index')->with('success', 'Stock movement recorded successfully.'); } diff --git a/app/Notifications/Inventory/LowStockAlertNotification.php b/app/Notifications/Inventory/LowStockAlertNotification.php new file mode 100644 index 0000000..da5a11d --- /dev/null +++ b/app/Notifications/Inventory/LowStockAlertNotification.php @@ -0,0 +1,30 @@ +item->item_name}* ({$this->item->item_code})\nCurrent Stock: {$this->stockLevel->quantity} {$this->item->unit_of_measure}\nReorder Level: {$this->item->minimum_stock_level} {$this->item->unit_of_measure}\n\nPlease raise a purchase request." + ); + } +}