feat: send WhatsApp notification on production order completed

This commit is contained in:
Ghassan Yusuf 2026-05-19 13:19:49 +03:00
parent 5b2a46c753
commit a1f6e765e1
2 changed files with 36 additions and 0 deletions

View File

@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Item; use App\Models\Item;
use App\Models\ProductionCost; use App\Models\ProductionCost;
use App\Models\ProductionOrder; use App\Models\ProductionOrder;
use App\Notifications\Production\ProductionOrderCompletedNotification;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class ProductionOrderController extends Controller class ProductionOrderController extends Controller
@ -89,6 +90,12 @@ class ProductionOrderController extends Controller
'completion_date' => now(), '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.'); return redirect()->back()->with('success', 'Production order marked as completed.');
} }
} }

View File

@ -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')
);
}
}