diff --git a/app/Services/Manage/OwnerVerificationService.php b/app/Services/Manage/OwnerVerificationService.php index 4a19167..96cd6bc 100644 --- a/app/Services/Manage/OwnerVerificationService.php +++ b/app/Services/Manage/OwnerVerificationService.php @@ -511,6 +511,63 @@ private function requestTitle(OwnerVerificationRequest $request): string return 'Item Baru'; } + private function requestSearchTerm(OwnerVerificationRequest $request): ?string + { + if ($request->subject_type === Product::class) { + if ($request->subject instanceof Product) { + return $request->subject->name; + } + $payload = is_array($request->payload) ? $request->payload : []; + foreach (['new', 'old'] as $key) { + $section = $payload[$key] ?? null; + if (is_array($section) && isset($section['name'])) { + return (string) $section['name']; + } + } + } + + if ($request->subject_type === ProductVariant::class) { + $payload = is_array($request->payload) ? $request->payload : []; + $newData = $payload['new'] ?? []; + if (isset($newData['product_name']) && $newData['product_name'] !== '-') { + return $newData['product_name']; + } + if ($request->subject instanceof ProductVariant) { + return $request->subject->product?->name ?? $request->subject->name; + } + } + + if ($request->subject_type === RawMaterial::class) { + if ($request->subject instanceof RawMaterial) { + return $request->subject->name; + } + $payload = is_array($request->payload) ? $request->payload : []; + foreach (['new', 'old'] as $key) { + $section = $payload[$key] ?? null; + if (is_array($section) && isset($section['name'])) { + return (string) $section['name']; + } + } + } + + if ($request->subject_type === Purchase::class) { + if ($request->subject instanceof Purchase) { + $request->subject->loadMissing('supplier'); + + return $request->subject->supplier?->name; + } + $payload = is_array($request->payload) ? $request->payload : []; + foreach (['new', 'old'] as $key) { + $section = $payload[$key] ?? null; + if (is_array($section) && isset($section['supplier_name'])) { + return (string) $section['supplier_name']; + } + } + } + + return null; + } + private function notifyRequestSubmitter( OwnerVerificationRequest $request, string $title, @@ -520,10 +577,13 @@ private function notifyRequestSubmitter( return; } + $searchTerm = $this->requestSearchTerm($request); + $routeParams = $searchTerm !== null ? ['search' => $searchTerm] : []; + $url = match ($request->subject_type) { - Product::class, ProductVariant::class => route('admin.master.products.index'), - RawMaterial::class => route('admin.master.raw_materials.index'), - Purchase::class => route('admin.manage.purchases.index'), + Product::class, ProductVariant::class => route('admin.master.products.index', $routeParams), + RawMaterial::class => route('admin.master.raw_materials.index', $routeParams), + Purchase::class => route('admin.manage.purchases.index', $routeParams), MarketplaceSettings::class => route('admin.system.settings.index'), default => route('admin.dashboard'), }; diff --git a/app/Services/Manage/PurchaseService.php b/app/Services/Manage/PurchaseService.php index 3450f78..6d4df3b 100644 --- a/app/Services/Manage/PurchaseService.php +++ b/app/Services/Manage/PurchaseService.php @@ -269,7 +269,8 @@ public function create(array $validated, User $user): Purchase $user, 'Tambah Belanja', "Pengajuan belanja dari supplier {$purchase->supplier->name} senilai {$purchase->total_formatted} menunggu verifikasi owner.", - route('admin.manage.purchases.index'), + route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]), + $purchase->supplier->name, ); return $purchase; @@ -315,7 +316,8 @@ public function update(Purchase $purchase, array $validated, User $user): void $user, 'Ubah Belanja', "Pengajuan ubah belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.", - route('admin.manage.purchases.index'), + route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]), + $purchase->supplier->name, ); } @@ -351,7 +353,8 @@ public function delete(Purchase $purchase, User $user): void $user, 'Hapus Belanja', "Pengajuan hapus belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.", - route('admin.manage.purchases.index'), + route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]), + $purchase->supplier->name, ); } @@ -502,13 +505,18 @@ private function decrementStock(PurchaseItem $item): void ->decrement('stock', $item->quantity); } - private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void + private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void { + $ownerUrl = route('admin.manage.purchases.index'); + if ($search !== null) { + $ownerUrl = route('admin.manage.purchases.index', ['search' => $search]); + } + $this->pushNotificationService->sendToRoles( "📦 {$typeLabel} Menunggu Persetujuan Owner", $body, ['owner', 'developer'], - route('admin.manage.purchases.index'), + $ownerUrl, ); $this->pushNotificationService->sendToUser( diff --git a/app/Services/Manage/StockRetailService.php b/app/Services/Manage/StockRetailService.php index 4044d7d..9fab8dd 100644 --- a/app/Services/Manage/StockRetailService.php +++ b/app/Services/Manage/StockRetailService.php @@ -27,7 +27,7 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not ]); } - $variant = ProductVariant::query()->findOrFail($variantId); + $variant = ProductVariant::query()->with('product')->findOrFail($variantId); if ($variant->stock < $quantity) { throw ValidationException::withMessages([ @@ -71,18 +71,20 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not ], ]); + $productName = $variant->product?->name ?? $variant->name; + $this->pushNotificationService->sendToRoles( '📦 Transfer Stok Ecer Menunggu Persetujuan Owner', "Pengajuan transfer {$quantity} pcs stok ecer untuk varian '{$variant->name}' menunggu verifikasi owner.", ['owner', 'developer'], - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $productName]), ); $this->pushNotificationService->sendToUser( '📤 Pengajuan Transfer Terkirim', "Pengajuan transfer {$quantity} pcs stok ecer untuk varian '{$variant->name}' telah dikirim dan menunggu verifikasi owner.", $user->id, - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $productName]), ); return $request; diff --git a/app/Services/Master/ProductService.php b/app/Services/Master/ProductService.php index ce80ce2..a8e360d 100644 --- a/app/Services/Master/ProductService.php +++ b/app/Services/Master/ProductService.php @@ -163,7 +163,8 @@ public function create(array $validated, User $user): void $user, 'Tambah Produk', "Pengajuan tambah produk '{$validated['name']}' menunggu verifikasi owner.", - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $validated['name']]), + $validated['name'], ); } @@ -204,7 +205,8 @@ public function update(Product $product, array $validated, User $user): void $user, 'Ubah Produk', "Pengajuan ubah produk '{$product->name}' menunggu verifikasi owner.", - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $product->name]), + $product->name, ); } @@ -236,7 +238,8 @@ public function delete(Product $product, User $user): void $user, 'Hapus Produk', "Pengajuan hapus produk '{$product->name}' menunggu verifikasi owner.", - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $product->name]), + $product->name, ); } @@ -276,7 +279,8 @@ public function toggleStatus(Product $product, array $validated, User $user): vo $user, 'Ubah Status Produk', "Pengajuan ubah status produk '{$product->name}' menjadi {$statusLabel} menunggu verifikasi owner.", - route('admin.master.products.index'), + route('admin.master.products.index', ['search' => $product->name]), + $product->name, ); } @@ -441,13 +445,18 @@ public function applyToggleStatus(OwnerVerificationRequest $verificationRequest) ]); } - private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void + private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void { + $ownerUrl = route('admin.master.products.index'); + if ($search !== null) { + $ownerUrl = route('admin.master.products.index', ['search' => $search]); + } + $this->pushNotificationService->sendToRoles( "📦 {$typeLabel} Menunggu Persetujuan Owner", $body, ['owner', 'developer'], - route('admin.master.products.index'), + $ownerUrl, ); $this->pushNotificationService->sendToUser( diff --git a/app/Services/Master/RawMaterialService.php b/app/Services/Master/RawMaterialService.php index 4e1bd47..8b36c61 100644 --- a/app/Services/Master/RawMaterialService.php +++ b/app/Services/Master/RawMaterialService.php @@ -149,7 +149,8 @@ public function create(array $validated, User $user): void $user, 'Tambah Bahan Baku', "Pengajuan tambah bahan baku '{$validated['name']}' menunggu verifikasi owner.", - route('admin.master.raw_materials.index'), + route('admin.master.raw_materials.index', ['search' => $validated['name']]), + $validated['name'], ); } @@ -190,7 +191,8 @@ public function update(RawMaterial $rawMaterial, array $validated, User $user): $user, 'Ubah Bahan Baku', "Pengajuan ubah bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.", - route('admin.master.raw_materials.index'), + route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]), + $rawMaterial->name, ); } @@ -222,7 +224,8 @@ public function delete(RawMaterial $rawMaterial, User $user): void $user, 'Hapus Bahan Baku', "Pengajuan hapus bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.", - route('admin.master.raw_materials.index'), + route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]), + $rawMaterial->name, ); } @@ -262,7 +265,8 @@ public function toggleStatus(RawMaterial $rawMaterial, array $validated, User $u $user, 'Ubah Status Bahan Baku', "Pengajuan ubah status bahan baku '{$rawMaterial->name}' menjadi {$statusLabel} menunggu verifikasi owner.", - route('admin.master.raw_materials.index'), + route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]), + $rawMaterial->name, ); } @@ -302,13 +306,18 @@ public function clearVerificationRequestMedia(OwnerVerificationRequest $verifica } } - private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl): void + private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void { + $ownerUrl = route('admin.master.raw_materials.index'); + if ($search !== null) { + $ownerUrl = route('admin.master.raw_materials.index', ['search' => $search]); + } + $this->pushNotificationService->sendToRoles( "📦 {$typeLabel} Menunggu Persetujuan Owner", $body, ['owner', 'developer'], - route('admin.master.raw_materials.index'), + $ownerUrl, ); $this->pushNotificationService->sendToUser( diff --git a/resources/js/components/NotificationBell.vue b/resources/js/components/NotificationBell.vue index 518889c..5fd339c 100644 --- a/resources/js/components/NotificationBell.vue +++ b/resources/js/components/NotificationBell.vue @@ -76,6 +76,9 @@ async function markAsRead(notification: NotificationItem): Promise { } function openNotification(notification: NotificationItem): void { + if (!notification.is_read) { + void markAsRead(notification); + } if (notification.url) { isOpen.value = false; router.visit(notification.url); @@ -201,7 +204,7 @@ onUnmounted(() => { - Tandai semua dibaca + Tandai semua dibaca @@ -212,7 +215,7 @@ onUnmounted(() => { - Hapus semua + Hapus semua @@ -269,7 +272,7 @@ onUnmounted(() => { - Tandai dibaca + Tandai dibaca @@ -280,7 +283,7 @@ onUnmounted(() => { - Hapus + Hapus diff --git a/resources/js/pages/admin/master/products/form/ProductVariantSection.vue b/resources/js/pages/admin/master/products/form/ProductVariantSection.vue index 482dc2e..c19762b 100644 --- a/resources/js/pages/admin/master/products/form/ProductVariantSection.vue +++ b/resources/js/pages/admin/master/products/form/ProductVariantSection.vue @@ -52,7 +52,7 @@ const emit = defineEmits<{ -
+
Nama Varian