Merge pull request 'Added after craete method in transporter bid' (#132) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Reviewed-on: #132
This commit was merged in pull request #132.
This commit is contained in:
@@ -3,10 +3,63 @@
|
|||||||
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\RfqTransporterBidResource;
|
use App\Filament\Resources\RfqTransporterBidResource;
|
||||||
|
use App\Models\RfqTransporterBid;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Notifications\PushAlertNotification;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
class CreateRfqTransporterBid extends CreateRecord
|
class CreateRfqTransporterBid extends CreateRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = RfqTransporterBidResource::class;
|
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