feat: send WhatsApp notification on PO confirmed
This commit is contained in:
parent
d1f40c4124
commit
358907bbed
@ -8,6 +8,7 @@ use App\Models\PurchaseOrder;
|
||||
use App\Models\PurchaseOrderItem;
|
||||
use App\Models\PurchaseRequest;
|
||||
use App\Models\Supplier;
|
||||
use App\Notifications\Purchase\PurchaseOrderConfirmedNotification;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PurchaseOrderController extends Controller
|
||||
@ -62,6 +63,10 @@ class PurchaseOrderController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
if ($order->supplier && $order->supplier->whatsapp_number) {
|
||||
$order->supplier->notify(new PurchaseOrderConfirmedNotification($order));
|
||||
}
|
||||
|
||||
return redirect()->route('purchase.orders.show', $order)->with('success', 'Purchase order created successfully.');
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Purchase;
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use PromoSeven\UltraMessage\UltraMessageChannel;
|
||||
use PromoSeven\UltraMessage\UltraMessageMessage;
|
||||
|
||||
class PurchaseOrderConfirmedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private PurchaseOrder $order) {}
|
||||
|
||||
public function via(mixed $notifiable): array
|
||||
{
|
||||
return [UltraMessageChannel::class];
|
||||
}
|
||||
|
||||
public function toUltraMessage(mixed $notifiable): UltraMessageMessage
|
||||
{
|
||||
return UltraMessageMessage::text(
|
||||
"Dear {$notifiable->name},\n\nPurchase Order *#{$this->order->po_number}* has been confirmed.\n\nTotal Amount: {$this->order->total_amount}\nExpected Delivery: {$this->order->expected_delivery_date}\n\nThank you."
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user