From a64443110a805222f6a129560cc1759972506119 Mon Sep 17 00:00:00 2001 From: Ghassan Yusuf Date: Tue, 19 May 2026 13:19:36 +0300 Subject: [PATCH] feat: send WhatsApp notification on sales invoice created --- .../Sales/SalesInvoiceController.php | 7 ++++- .../Sales/InvoiceCreatedNotification.php | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/Notifications/Sales/InvoiceCreatedNotification.php diff --git a/app/Http/Controllers/Sales/SalesInvoiceController.php b/app/Http/Controllers/Sales/SalesInvoiceController.php index a17fd14..106cdb2 100644 --- a/app/Http/Controllers/Sales/SalesInvoiceController.php +++ b/app/Http/Controllers/Sales/SalesInvoiceController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\SalesInvoice; use App\Models\SalesOrder; +use App\Notifications\Sales\InvoiceCreatedNotification; use Illuminate\Http\Request; 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); - SalesInvoice::create(array_merge($request->all(), [ + $invoice = SalesInvoice::create(array_merge($request->all(), [ 'invoice_number' => $invoiceNumber, 'status' => 'unpaid', 'paid_amount' => 0, @@ -48,6 +49,10 @@ class SalesInvoiceController extends Controller 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.'); } diff --git a/app/Notifications/Sales/InvoiceCreatedNotification.php b/app/Notifications/Sales/InvoiceCreatedNotification.php new file mode 100644 index 0000000..99219bf --- /dev/null +++ b/app/Notifications/Sales/InvoiceCreatedNotification.php @@ -0,0 +1,29 @@ +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." + ); + } +}