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;
|
namespace App\Filament\Resources\RfqTransporterBidResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\RfqTransporterBidResource;
|
use App\Filament\Resources\RfqTransporterBidResource;
|
||||||
|
use App\Models\RequestQuotation;
|
||||||
use App\Models\RfqTransporterBid;
|
use App\Models\RfqTransporterBid;
|
||||||
|
use App\Models\SpotRateTransportMaster;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\PushAlertNotification;
|
use App\Notifications\PushAlertNotification;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class EditRfqTransporterBid extends EditRecord
|
class EditRfqTransporterBid extends EditRecord
|
||||||
{
|
{
|
||||||
@@ -17,54 +20,147 @@ class EditRfqTransporterBid extends EditRecord
|
|||||||
|
|
||||||
protected function afterSave(): void
|
protected function afterSave(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (! $this->record->wasChanged('total_freight_charge')) {
|
if (! $this->record->wasChanged('total_freight_charge')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dd($this->record);
|
|
||||||
|
|
||||||
$rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id)
|
$rank = RfqTransporterBid::where('request_quotation_id', $this->record->request_quotation_id)
|
||||||
->orderBy('total_freight_charge')
|
->orderBy('total_freight_charge')
|
||||||
->pluck('id')
|
->pluck('id')
|
||||||
->search($this->record->id) + 1;
|
->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();
|
$currentUser = Filament::auth()->user();
|
||||||
|
|
||||||
|
// if ($currentUser && ! $recipients1->contains('id', $currentUser->id)) {
|
||||||
|
// $recipients1->push($currentUser);
|
||||||
|
// }
|
||||||
|
|
||||||
if ($currentUser && ! $recipients->contains('id', $currentUser->id)) {
|
// if ($currentUser && ! $recipients->contains('id', $currentUser->id)) {
|
||||||
$recipients->push($currentUser);
|
// $recipients->push($currentUser);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// $user1 = Filament::auth()->user();
|
// $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()
|
Notification::make()
|
||||||
->title('Rank Updated')
|
->title('Rank Updated')
|
||||||
->body("{$currentUser->name} current rank is #{$rank}")
|
->body("{$currentUser->name} has updated the bid for RFQ No '{$rfqNumber}'. The current rank is #{$rank}.")
|
||||||
->success()
|
->success()
|
||||||
->sendToDatabase($recipients);
|
->sendToDatabase($users);
|
||||||
|
|
||||||
\Log::info('Notification sent', [
|
// foreach ($recipients1 as $user) {
|
||||||
'rank' => $rank,
|
// $user->notify(
|
||||||
'recipients' => $recipients->pluck('id'),
|
// new PushAlertNotification(
|
||||||
|
// 'Rank Updated',
|
||||||
|
// $body
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($recipients as $user) {
|
if ($count == 0) {
|
||||||
$user->notify(
|
Log::warning('User has NO push subscription', [
|
||||||
new PushAlertNotification(
|
'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',
|
'Rank Updated',
|
||||||
$body
|
$body
|
||||||
)
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Illuminate\Notifications\Notifiable;
|
|||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||||
|
use NotificationChannels\WebPush\PushSubscription;
|
||||||
|
|
||||||
class User extends Authenticatable implements FilamentUser
|
class User extends Authenticatable implements FilamentUser
|
||||||
{
|
{
|
||||||
@@ -64,4 +65,9 @@ class User extends Authenticatable implements FilamentUser
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Plant::class);
|
return $this->belongsTo(Plant::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pushSubscriptions()
|
||||||
|
{
|
||||||
|
return $this->morphMany(PushSubscription::class, 'subscribable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,6 @@
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(subscription)
|
body: JSON.stringify(subscription)
|
||||||
});
|
});
|
||||||
|
|
||||||
alert("Push notifications enabled ✅");
|
alert("Push notifications enabled ✅");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -25,12 +25,15 @@ use App\Http\Controllers\ObdController;
|
|||||||
use App\Http\Controllers\PalletController;
|
use App\Http\Controllers\PalletController;
|
||||||
use App\Http\Controllers\PdfController;
|
use App\Http\Controllers\PdfController;
|
||||||
use App\Http\Controllers\PlantController;
|
use App\Http\Controllers\PlantController;
|
||||||
|
use App\Http\Controllers\PrintController;
|
||||||
use App\Http\Controllers\ProductionStickerReprintController;
|
use App\Http\Controllers\ProductionStickerReprintController;
|
||||||
use App\Http\Controllers\SapFileController;
|
use App\Http\Controllers\SapFileController;
|
||||||
use App\Http\Controllers\StickerMasterController;
|
use App\Http\Controllers\StickerMasterController;
|
||||||
// use App\Http\Controllers\TelegramController;
|
// use App\Http\Controllers\TelegramController;
|
||||||
use App\Http\Controllers\TestingPanelController;
|
use App\Http\Controllers\TestingPanelController;
|
||||||
use App\Http\Controllers\UserController;
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Models\WebPushSubscription;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
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('send-telegram', [TelegramController::class, 'sendMessage']);
|
||||||
|
|
||||||
// Route::post('invoice-exit', [InvoiceValidationController::class, 'handle']);
|
// 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(
|
WebPushSubscription::updateOrCreate(
|
||||||
// ✅ UNIQUE PER DEVICE
|
|
||||||
['endpoint' => $request->endpoint],
|
['endpoint' => $request->endpoint],
|
||||||
[
|
[
|
||||||
'subscribable_type' => get_class($user), // 🔥 important
|
'subscribable_type' => get_class($user),
|
||||||
'subscribable_id' => $user->id,
|
'subscribable_id' => $user->id,
|
||||||
'public_key' => $request->keys['p256dh'],
|
'public_key' => $request->keys['p256dh'],
|
||||||
'auth_token' => $request->keys['auth'],
|
'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]);
|
return response()->json(['success' => true]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user