changed logic in edit transporter bid #150

Merged
jothi merged 1 commits from ranjith-dev into master 2026-01-27 08:40:35 +00:00

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
use App\Filament\Resources\RfqTransporterBidResource;
use App\Models\RfqTransporterBid;
use App\Models\SpotRateTransportMaster;
use App\Models\User;
use App\Notifications\PushAlertNotification;
use Filament\Actions;
@@ -24,42 +25,71 @@ class EditRfqTransporterBid extends EditRecord
// dd($this->record);
$rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id)
->where('spot_rate_transport_master_id', $this->record->spot_rate_transport_master_id)
->orderBy('total_freight_charge')
->pluck('id')
->search($this->record->id) + 1;
$recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get();
$spotRate = SpotRateTransportMaster::findOrFail(
$this->record->spot_rate_transport_master_id
);
$recipients1 = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->whereHas('pushSubscriptions')->get();
$userNames = json_decode($spotRate->user_name, true);
if (!is_array($userNames)) {
$userNames = [];
}
$users = User::whereIn('name', $userNames)->get();
// $recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get();
// $recipients1 = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->whereHas('pushSubscriptions')->get();
$currentUser = Filament::auth()->user();
if ($currentUser && ! $recipients1->contains('id', $currentUser->id)) {
$recipients1->push($currentUser);
}
// if ($currentUser && ! $recipients1->contains('id', $currentUser->id)) {
// $recipients1->push($currentUser);
// }
if ($currentUser && ! $recipients->contains('id', $currentUser->id)) {
$recipients->push($currentUser);
}
// if ($currentUser && ! $recipients->contains('id', $currentUser->id)) {
// $recipients->push($currentUser);
// }
// $user1 = Filament::auth()->user();
$body = "{$currentUser->name} current rank is #{$rank}";
// Notification::make()
// ->title('Rank Updated')
// ->body("{$currentUser->name} current rank is #{$rank}")
// ->success()
// ->sendToDatabase($recipients);
// \Log::info('Notification sent', [
// 'rank' => $rank,
// 'recipients' => $recipients->pluck('id'),
// ]);
Notification::make()
->title('Rank Updated')
->body("{$currentUser->name} current rank is #{$rank}")
->success()
->sendToDatabase($recipients);
->sendToDatabase($users);
\Log::info('Notification sent', [
'rank' => $rank,
'recipients' => $recipients->pluck('id'),
]);
// foreach ($recipients1 as $user) {
// $user->notify(
// new PushAlertNotification(
// 'Rank Updated',
// $body
// )
// );
// }
foreach ($recipients1 as $user) {
foreach ($users as $user) {
if ($user->pushSubscriptions()->exists()) {
$user->notify(
new PushAlertNotification(
'Rank Updated',
@@ -67,6 +97,7 @@ class EditRfqTransporterBid extends EditRecord
)
);
}
}
}