feat: send WhatsApp notification on sales invoice created
This commit is contained in:
parent
68c605bc69
commit
a64443110a
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
use App\Models\SalesInvoice;
|
use App\Models\SalesInvoice;
|
||||||
use App\Models\SalesOrder;
|
use App\Models\SalesOrder;
|
||||||
|
use App\Notifications\Sales\InvoiceCreatedNotification;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class SalesInvoiceController extends Controller
|
class SalesInvoiceController extends Controller
|
||||||
@ -39,7 +40,7 @@ class SalesInvoiceController extends Controller
|
|||||||
|
|
||||||
$invoiceNumber = 'INV-' . str_pad(SalesInvoice::max('id') + 1, 5, '0', STR_PAD_LEFT);
|
$invoiceNumber = 'INV-' . str_pad(SalesInvoice::max('id') + 1, 5, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
SalesInvoice::create(array_merge($request->all(), [
|
$invoice = SalesInvoice::create(array_merge($request->all(), [
|
||||||
'invoice_number' => $invoiceNumber,
|
'invoice_number' => $invoiceNumber,
|
||||||
'status' => 'unpaid',
|
'status' => 'unpaid',
|
||||||
'paid_amount' => 0,
|
'paid_amount' => 0,
|
||||||
@ -48,6 +49,10 @@ class SalesInvoiceController extends Controller
|
|||||||
|
|
||||||
SalesOrder::where('id', $request->sales_order_id)->update(['status' => 'invoiced']);
|
SalesOrder::where('id', $request->sales_order_id)->update(['status' => 'invoiced']);
|
||||||
|
|
||||||
|
if ($invoice->customer && $invoice->customer->whatsapp_number) {
|
||||||
|
$invoice->customer->notify(new InvoiceCreatedNotification($invoice));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('sales.invoices.index')->with('success', 'Invoice created successfully.');
|
return redirect()->route('sales.invoices.index')->with('success', 'Invoice created successfully.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
app/Notifications/Sales/InvoiceCreatedNotification.php
Normal file
29
app/Notifications/Sales/InvoiceCreatedNotification.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Sales;
|
||||||
|
|
||||||
|
use App\Models\SalesInvoice;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use PromoSeven\UltraMessage\UltraMessageChannel;
|
||||||
|
use PromoSeven\UltraMessage\UltraMessageMessage;
|
||||||
|
|
||||||
|
class InvoiceCreatedNotification extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(private SalesInvoice $invoice) {}
|
||||||
|
|
||||||
|
public function via(mixed $notifiable): array
|
||||||
|
{
|
||||||
|
return [UltraMessageChannel::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toUltraMessage(mixed $notifiable): UltraMessageMessage
|
||||||
|
{
|
||||||
|
return UltraMessageMessage::text(
|
||||||
|
"Dear {$notifiable->name},\n\nInvoice *#{$this->invoice->invoice_number}* is ready.\n\nAmount Due: {$this->invoice->total_amount}\nDue Date: {$this->invoice->due_date}\n\nPlease arrange payment at your earliest convenience. Thank you."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user