feat: send WhatsApp low stock alert to store managers
This commit is contained in:
parent
8303df358f
commit
5b2a46c753
@ -7,6 +7,7 @@ use App\Models\Item;
|
|||||||
use App\Models\StockLevel;
|
use App\Models\StockLevel;
|
||||||
use App\Models\StockMovement;
|
use App\Models\StockMovement;
|
||||||
use App\Models\Warehouse;
|
use App\Models\Warehouse;
|
||||||
|
use App\Notifications\Inventory\LowStockAlertNotification;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class StockMovementController extends Controller
|
class StockMovementController extends Controller
|
||||||
@ -58,6 +59,16 @@ class StockMovementController extends Controller
|
|||||||
'created_by' => auth()->id(),
|
'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.');
|
return redirect()->route('inventory.movements.index')->with('success', 'Stock movement recorded successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
app/Notifications/Inventory/LowStockAlertNotification.php
Normal file
30
app/Notifications/Inventory/LowStockAlertNotification.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Inventory;
|
||||||
|
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\StockLevel;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use PromoSeven\UltraMessage\UltraMessageChannel;
|
||||||
|
use PromoSeven\UltraMessage\UltraMessageMessage;
|
||||||
|
|
||||||
|
class LowStockAlertNotification extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(private Item $item, private StockLevel $stockLevel) {}
|
||||||
|
|
||||||
|
public function via(mixed $notifiable): array
|
||||||
|
{
|
||||||
|
return [UltraMessageChannel::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toUltraMessage(mixed $notifiable): UltraMessageMessage
|
||||||
|
{
|
||||||
|
return UltraMessageMessage::text(
|
||||||
|
"⚠️ *Low Stock Alert*\n\nItem: *{$this->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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user