Added after craete method in transporter bid #132
@@ -3,10 +3,63 @@
|
||||
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
||||
|
||||
use App\Filament\Resources\RfqTransporterBidResource;
|
||||
use App\Models\RfqTransporterBid;
|
||||
use App\Models\User;
|
||||
use App\Notifications\PushAlertNotification;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRfqTransporterBid extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RfqTransporterBidResource::class;
|
||||
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$record = $this->record;
|
||||
|
||||
// Calculate rank based on total_freight_charge
|
||||
$rank = RfqTransporterBid::where('request_quotation_id', $record->request_quotation_id)
|
||||
->orderBy('total_freight_charge')
|
||||
->pluck('id')
|
||||
->search($record->id) + 1;
|
||||
|
||||
$currentUser = Filament::auth()->user();
|
||||
|
||||
// Get recipients
|
||||
$recipients = User::whereHas('roles', function ($q) {
|
||||
$q->whereIn('name', ['Super Admin', 'Rfq Supervisor'])
|
||||
->where('guard_name', 'web');
|
||||
})->get();
|
||||
|
||||
// Exclude creator
|
||||
$recipients = $recipients->where('id', '!=', $currentUser->id);
|
||||
|
||||
$body = "{$currentUser->name} added a new bid. Current rank is #{$rank}";
|
||||
|
||||
// Filament DB notification
|
||||
Notification::make()
|
||||
->title('New Bid Added')
|
||||
->body($body)
|
||||
->success()
|
||||
->sendToDatabase($recipients);
|
||||
|
||||
// Push notification
|
||||
foreach ($recipients as $user) {
|
||||
$user->notify(
|
||||
new PushAlertNotification(
|
||||
'New Bid Added',
|
||||
$body
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
\Log::info('Create bid notification sent', [
|
||||
'bid_id' => $record->id,
|
||||
'rank' => $rank,
|
||||
'recipients' => $recipients->pluck('id'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user