Compare commits
27 Commits
eae7e76ea4
...
ranjith-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a796a670a | ||
|
|
4577f67d0a | ||
|
|
be2151a072 | ||
|
|
a4251ae532 | ||
|
|
93d55765ae | ||
|
|
17d54cc52e | ||
|
|
61467d88cd | ||
|
|
af0b17e674 | ||
|
|
dd7111a8d9 | ||
|
|
464ee6c3c7 | ||
|
|
984d686182 | ||
|
|
fd87748a38 | ||
|
|
f9aa6cd1ba | ||
|
|
d743b2df26 | ||
|
|
814281a6bf | ||
|
|
dc445b17f5 | ||
|
|
cd553651f3 | ||
|
|
ac20e96358 | ||
|
|
0fb9c91b28 | ||
|
|
21d602d86a | ||
|
|
06628072dc | ||
|
|
cdf9f60ffd | ||
|
|
b419a538dc | ||
|
|
fea15e0d1b | ||
|
|
f5a1e453d5 | ||
|
|
fd6149ccbe | ||
|
|
085a4f72fa |
@@ -3,13 +3,16 @@
|
||||
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
||||
|
||||
use App\Filament\Resources\RfqTransporterBidResource;
|
||||
use App\Models\RequestQuotation;
|
||||
use App\Models\RfqTransporterBid;
|
||||
use App\Models\SpotRateTransportMaster;
|
||||
use App\Models\User;
|
||||
use App\Notifications\PushAlertNotification;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EditRfqTransporterBid extends EditRecord
|
||||
{
|
||||
@@ -17,52 +20,145 @@ class EditRfqTransporterBid extends EditRecord
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (! $this->record->wasChanged('total_freight_charge')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// dd($this->record);
|
||||
|
||||
$rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id)
|
||||
->orderBy('total_freight_charge')
|
||||
->pluck('id')
|
||||
->search($this->record->id) + 1;
|
||||
|
||||
$recipients = User::role(['Super Admin', 'Rfq Supervisor', 'TransporterBid Employee'])->get();
|
||||
$requestQuotation = RequestQuotation::findOrFail(
|
||||
$this->record->request_quotation_id
|
||||
);
|
||||
|
||||
$spotRateId = $requestQuotation->spot_rate_transport_master_id;
|
||||
|
||||
$spotRate = SpotRateTransportMaster::findOrFail($spotRateId);
|
||||
|
||||
$userNames = $spotRate->user_name;
|
||||
|
||||
Log::info('User names from spot rate', [
|
||||
'user_name_raw' => $spotRate->user_name,
|
||||
]);
|
||||
|
||||
if (!is_array($userNames)) {
|
||||
Log::warning('user_name is not array, resetting', [
|
||||
'user_name' => $userNames,
|
||||
]);
|
||||
$userNames = [];
|
||||
}
|
||||
|
||||
|
||||
$users = User::whereIn('name', $userNames)->get();
|
||||
|
||||
Log::info('Matched users', [
|
||||
'count' => $users->count(),
|
||||
'user_ids' => $users->pluck('id'),
|
||||
]);
|
||||
|
||||
// $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 && ! $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}";
|
||||
$rfqNumber = $this->record->requestQuotation->rfq_number;
|
||||
$body = "{$currentUser->name} has updated the bid for RFQ No '{$rfqNumber}'. The 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);
|
||||
->title('Rank Updated')
|
||||
->body("{$currentUser->name} has updated the bid for RFQ No '{$rfqNumber}'. The current rank is #{$rank}.")
|
||||
->success()
|
||||
->sendToDatabase($users);
|
||||
|
||||
\Log::info('Notification sent', [
|
||||
'rank' => $rank,
|
||||
'recipients' => $recipients->pluck('id'),
|
||||
]);
|
||||
// foreach ($recipients1 as $user) {
|
||||
// $user->notify(
|
||||
// new PushAlertNotification(
|
||||
// 'Rank Updated',
|
||||
// $body
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
foreach ($recipients as $user) {
|
||||
$user->notify(
|
||||
new PushAlertNotification(
|
||||
// foreach ($users as $user) {
|
||||
|
||||
// Log::info('Checking push subscription for user', [
|
||||
// 'user_id' => $user->id,
|
||||
// 'name' => $user->name,
|
||||
// 'subscription_count' => $user->pushSubscriptions()->count(),
|
||||
// ]);
|
||||
// if ($user->pushSubscriptions()->exists()) {
|
||||
|
||||
// Log::info('Sending push notification', [
|
||||
// 'user_id' => $user->id,
|
||||
// ]);
|
||||
// $user->notify(
|
||||
// new PushAlertNotification(
|
||||
// 'Rank Updated',
|
||||
// $body
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// else {
|
||||
// Log::warning('User has NO push subscription', [
|
||||
// 'user_id' => $user->id,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
$count = $user->pushSubscriptions()->count();
|
||||
|
||||
Log::info('Checking push subscription for user', [
|
||||
'user_id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'subscription_count' => $count,
|
||||
]);
|
||||
|
||||
if ($count == 0) {
|
||||
Log::warning('User has NO push subscription', [
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
|
||||
Log::info('Sending push notification', [
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
// ✅ THIS IS ALL YOU NEED
|
||||
$user->notify(new PushAlertNotification(
|
||||
'Rank Updated',
|
||||
$body
|
||||
)
|
||||
);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||
use NotificationChannels\WebPush\PushSubscription;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
@@ -64,4 +65,9 @@ class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function pushSubscriptions()
|
||||
{
|
||||
return $this->morphMany(PushSubscription::class, 'subscribable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
},
|
||||
body: JSON.stringify(subscription)
|
||||
});
|
||||
|
||||
alert("Push notifications enabled ✅");
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -25,12 +25,15 @@ use App\Http\Controllers\ObdController;
|
||||
use App\Http\Controllers\PalletController;
|
||||
use App\Http\Controllers\PdfController;
|
||||
use App\Http\Controllers\PlantController;
|
||||
use App\Http\Controllers\PrintController;
|
||||
use App\Http\Controllers\ProductionStickerReprintController;
|
||||
use App\Http\Controllers\SapFileController;
|
||||
use App\Http\Controllers\StickerMasterController;
|
||||
// use App\Http\Controllers\TelegramController;
|
||||
use App\Http\Controllers\TestingPanelController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Models\WebPushSubscription;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -185,3 +188,46 @@ Route::post('file/store', [SapFileController::class, 'store'])->name('file.store
|
||||
// Route::post('send-telegram', [TelegramController::class, 'sendMessage']);
|
||||
|
||||
// Route::post('invoice-exit', [InvoiceValidationController::class, 'handle']);
|
||||
|
||||
|
||||
Route::post('/print-pdf', [PrintController::class, 'print']);
|
||||
|
||||
|
||||
Route::post('/push/subscribe', function (Request $request) {
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
abort_if(!$user, 401);
|
||||
|
||||
$request->validate([
|
||||
'endpoint' => 'required|string',
|
||||
'keys.p256dh' => 'required|string',
|
||||
'keys.auth' => 'required|string',
|
||||
]);
|
||||
|
||||
// WebPushSubscription::updateOrCreate(
|
||||
// ['endpoint' => $request->endpoint],
|
||||
// [
|
||||
// 'subscribable_type' => get_class($user),
|
||||
// 'subscribable_id' => $user->id,
|
||||
// 'public_key' => $request->keys['p256dh'],
|
||||
// 'auth_token' => $request->keys['auth'],
|
||||
// 'content_encoding' => $request->contentEncoding ?? 'aesgcm',
|
||||
// ]
|
||||
// );
|
||||
|
||||
WebPushSubscription::updateOrCreate(
|
||||
[
|
||||
'endpoint' => $request->endpoint,
|
||||
'subscribable_type' => get_class($user),
|
||||
'subscribable_id' => $user->id,
|
||||
],
|
||||
[
|
||||
'public_key' => $request->keys['p256dh'],
|
||||
'auth_token' => $request->keys['auth'],
|
||||
'content_encoding' => $request->contentEncoding ?? 'aesgcm',
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
});
|
||||
|
||||
@@ -59,10 +59,9 @@ use App\Http\Livewire\CustomLogin;
|
||||
]);
|
||||
|
||||
WebPushSubscription::updateOrCreate(
|
||||
// ✅ UNIQUE PER DEVICE
|
||||
['endpoint' => $request->endpoint],
|
||||
[
|
||||
'subscribable_type' => get_class($user), // 🔥 important
|
||||
'subscribable_type' => get_class($user),
|
||||
'subscribable_id' => $user->id,
|
||||
'public_key' => $request->keys['p256dh'],
|
||||
'auth_token' => $request->keys['auth'],
|
||||
@@ -70,6 +69,20 @@ use App\Http\Livewire\CustomLogin;
|
||||
]
|
||||
);
|
||||
|
||||
// WebPushSubscription::updateOrCreate(
|
||||
// [
|
||||
// 'endpoint' => $request->endpoint,
|
||||
// 'subscribable_type' => get_class($user),
|
||||
// 'subscribable_id' => $user->id,
|
||||
// ],
|
||||
// [
|
||||
// 'public_key' => $request->keys['p256dh'],
|
||||
// 'auth_token' => $request->keys['auth'],
|
||||
// 'content_encoding' => $request->contentEncoding ?? 'aesgcm',
|
||||
// ]
|
||||
// );
|
||||
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user