diff --git a/app/Services/Manage/PurchaseService.php b/app/Services/Manage/PurchaseService.php index 30407b7..fa2dcce 100644 --- a/app/Services/Manage/PurchaseService.php +++ b/app/Services/Manage/PurchaseService.php @@ -430,7 +430,7 @@ function () use ($validated, $user, $isOwner): Purchase { $this->notifyForPendingRequest( $user, 'Tambah Belanja', - "Pengajuan belanja dari supplier {$purchase->supplier->name} senilai {$purchase->total_formatted} menunggu verifikasi owner.", + "Pengajuan belanja dari supplier {$purchase->supplier->name} senilai {$purchase->total_formatted} oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.purchases.index', ['search_id' => $purchase->id]), (string) $purchase->id, ); @@ -482,7 +482,7 @@ function () use ($purchase, $validated, $user, $isOwner): void { $this->notifyForPendingRequest( $user, 'Ubah Belanja', - "Pengajuan ubah belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.", + "Pengajuan ubah belanja dari supplier {$purchase->supplier->name} oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.purchases.index', ['search_id' => $purchase->id]), (string) $purchase->id, ); @@ -526,7 +526,7 @@ function () use ($purchase, $user): void { $this->notifyForPendingRequest( $user, 'Hapus Belanja', - "Pengajuan hapus belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.", + "Pengajuan hapus belanja dari supplier {$purchase->supplier->name} oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.purchases.index', ['search_id' => $purchase->id]), (string) $purchase->id, ); diff --git a/app/Services/Manage/RestockService.php b/app/Services/Manage/RestockService.php index cd42e6d..a9233ea 100644 --- a/app/Services/Manage/RestockService.php +++ b/app/Services/Manage/RestockService.php @@ -278,7 +278,7 @@ function () use ($validated, $user, $isOwner): Restock { $this->notifyForPendingRequest( $user, 'Tambah Restock', - "Pengajuan restock senilai {$restock->total_formatted} menunggu verifikasi owner.", + "Pengajuan restock senilai {$restock->total_formatted} oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.restocks.index', ['search_id' => $restock->id]), (string) $restock->id, ); @@ -328,7 +328,7 @@ function () use ($restock, $validated, $user, $isOwner): void { $this->notifyForPendingRequest( $user, 'Ubah Restock', - 'Pengajuan ubah restock menunggu verifikasi owner.', + "Pengajuan ubah restock oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.restocks.index', ['search_id' => $restock->id]), (string) $restock->id, ); @@ -370,7 +370,7 @@ function () use ($restock, $user): void { $this->notifyForPendingRequest( $user, 'Hapus Restock', - 'Pengajuan hapus restock menunggu verifikasi owner.', + "Pengajuan hapus restock oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.manage.restocks.index', ['search_id' => $restock->id]), (string) $restock->id, ); diff --git a/app/Services/Master/ProductService.php b/app/Services/Master/ProductService.php index 8bc8f90..b413e8d 100644 --- a/app/Services/Master/ProductService.php +++ b/app/Services/Master/ProductService.php @@ -171,13 +171,19 @@ function () use ($validated, $user, $isOwner): Product { if ($isOwner) { $this->cacheForgetByPattern('master:products:*'); + + $this->notifyOwner( + 'Tambah Produk', + "Produk '{$validated['name']}' telah ditambahkan oleh {$user->profile?->full_name}.", + route('admin.master.products.index', ['search_id' => $product->id]), + ); } if (! $isOwner) { $this->notifyForPendingRequest( $user, 'Tambah Produk', - "Pengajuan tambah produk '{$validated['name']}' menunggu verifikasi owner.", + "Pengajuan tambah produk '{$validated['name']}' oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.master.products.index', ['search_id' => $product->id]), (string) $product->id, ); @@ -250,6 +256,14 @@ function () use ($validated, $product, $user, $isOwner): void { $this->cacheForgetByPattern('master:products:*'); $this->cacheForget('homepage:page_data'); + if ($isOwner) { + $this->notifyOwner( + 'Ubah Produk', + "Produk '{$product->name}' telah diperbarui oleh {$user->profile?->full_name}.", + route('admin.master.products.index', ['search_id' => $product->id]), + ); + } + if (! $isOwner) { $changedVariants = []; foreach ($validated['variants'] as $variantData) { @@ -290,7 +304,7 @@ function () use ($validated, $product, $user, $isOwner): void { $this->notifyForPendingRequest( $user, 'Ubah Varian Produk', - "Pengajuan ubah varian '{$variantsStr}' pada produk '{$product->name}' menunggu verifikasi owner.", + "Pengajuan ubah varian '{$variantsStr}' pada produk '{$product->name}' oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.master.products.index', ['search_id' => $product->id]), (string) $product->id, ); @@ -298,7 +312,7 @@ function () use ($validated, $product, $user, $isOwner): void { $this->notifyForPendingRequest( $user, 'Ubah Produk', - "Pengajuan ubah produk '{$product->name}' menunggu verifikasi owner.", + "Pengajuan ubah produk '{$product->name}' oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.master.products.index', ['search_id' => $product->id]), (string) $product->id, ); @@ -311,10 +325,17 @@ public function delete(Product $product, User $user): void $isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value); if ($isOwner) { + $name = $product->name; $this->applyDeleteSubject($product); $this->cacheForgetByPattern('master:products:*'); $this->cacheForget('homepage:page_data'); + $this->notifyOwner( + 'Hapus Produk', + "Produk '{$name}' telah dihapus oleh {$user->profile?->full_name}.", + route('admin.master.products.index'), + ); + return; } @@ -338,7 +359,7 @@ function () use ($product, $user): void { $this->notifyForPendingRequest( $user, 'Hapus Produk', - "Pengajuan hapus produk '{$product->name}' menunggu verifikasi owner.", + "Pengajuan hapus produk '{$product->name}' oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.master.products.index', ['search_id' => $product->id]), (string) $product->id, ); @@ -356,6 +377,14 @@ public function toggleStatus(Product $product, array $validated, User $user): vo $this->cacheForgetByPattern('master:products:*'); $this->cacheForget('homepage:page_data'); + $statusLabel = $validated['is_active'] ? 'aktif' : 'nonaktif'; + + $this->notifyOwner( + 'Ubah Status Produk', + "Status produk '{$product->name}' telah diubah menjadi {$statusLabel} oleh {$user->profile?->full_name}.", + route('admin.master.products.index', ['search_id' => $product->id]), + ); + return; } @@ -387,7 +416,7 @@ function () use ($product, $validated, $user): void { $this->notifyForPendingRequest( $user, 'Ubah Status Produk', - "Pengajuan ubah status produk '{$product->name}' menjadi {$statusLabel} menunggu verifikasi owner.", + "Pengajuan ubah status produk '{$product->name}' menjadi {$statusLabel} oleh {$user->profile?->full_name} menunggu verifikasi owner.", route('admin.master.products.index', ['search_id' => $product->id]), (string) $product->id, ); @@ -585,6 +614,16 @@ public function applyToggleStatus(OwnerVerificationRequest $verificationRequest) ]); } + private function notifyOwner(string $typeLabel, string $body, string $url): void + { + $this->pushNotificationService->sendToRoles( + "📦 {$typeLabel}", + $body, + ['owner', 'developer', 'direktur'], + $url, + ); + } + private function notifyForPendingRequest(User $user, string $typeLabel, string $body, string $submitterUrl, ?string $search = null): void { $ownerUrl = route('admin.master.products.index'); diff --git a/app/Services/System/Setting/MarketplaceService.php b/app/Services/System/Setting/MarketplaceService.php index c499018..d0226cb 100644 --- a/app/Services/System/Setting/MarketplaceService.php +++ b/app/Services/System/Setting/MarketplaceService.php @@ -132,7 +132,7 @@ function () use ($validated, $user): void { $this->pushNotificationService->sendToUser( '📤 Pengajuan Terkirim', - 'Pengajuan ubah pengaturan marketplace menunggu verifikasi owner.', + \"Pengajuan ubah pengaturan marketplace oleh {$user->profile?->full_name} menunggu verifikasi owner.\", $user->id, route('admin.system.settings.index'), );