feat: send WhatsApp notification on production order completed
This commit is contained in:
parent
5b2a46c753
commit
a1f6e765e1
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Item;
|
||||
use App\Models\ProductionCost;
|
||||
use App\Models\ProductionOrder;
|
||||
use App\Notifications\Production\ProductionOrderCompletedNotification;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductionOrderController extends Controller
|
||||
@ -89,6 +90,12 @@ class ProductionOrderController extends Controller
|
||||
'completion_date' => now(),
|
||||
]);
|
||||
|
||||
$productionManagers = \App\Models\User::role('Production Manager')->whereNotNull('whatsapp_number')->get();
|
||||
\Illuminate\Support\Facades\Notification::send(
|
||||
$productionManagers,
|
||||
new ProductionOrderCompletedNotification($productionOrder)
|
||||
);
|
||||
|
||||
return redirect()->back()->with('success', 'Production order marked as completed.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Production;
|
||||
|
||||
use App\Models\ProductionOrder;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use PromoSeven\UltraMessage\UltraMessageChannel;
|
||||
use PromoSeven\UltraMessage\UltraMessageMessage;
|
||||
|
||||
class ProductionOrderCompletedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private ProductionOrder $order) {}
|
||||
|
||||
public function via(mixed $notifiable): array
|
||||
{
|
||||
return [UltraMessageChannel::class];
|
||||
}
|
||||
|
||||
public function toUltraMessage(mixed $notifiable): UltraMessageMessage
|
||||
{
|
||||
return UltraMessageMessage::text(
|
||||
"✅ *Production Complete*\n\nProduction Order *#{$this->order->order_number}* has been completed.\n\nProduct: {$this->order->product->item_name}\nQuantity: {$this->order->quantity_to_produce}\nCompleted: " . now()->format('d M Y')
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user