From 0b3bf891cc48a6e42bcbe7986d431a3243c504d3 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sun, 5 Jul 2026 17:35:47 +0700 Subject: [PATCH] refactor: streamline RetailStockService and OwnerVerificationService by removing unused verification logic and updating notification messages for stock changes --- .../Manage/OwnerVerificationService.php | 2 - app/Services/Manage/RetailStockService.php | 90 ++----------------- .../modal/RetailStockTransferModal.vue | 9 +- .../products/table/data-table-actions.vue | 3 +- 4 files changed, 13 insertions(+), 91 deletions(-) diff --git a/app/Services/Manage/OwnerVerificationService.php b/app/Services/Manage/OwnerVerificationService.php index f62d046..b9dbc24 100644 --- a/app/Services/Manage/OwnerVerificationService.php +++ b/app/Services/Manage/OwnerVerificationService.php @@ -283,7 +283,6 @@ private function rejectVerificationRequest(OwnerVerificationRequest $request): v RawMaterial::class => $this->rawMaterialService->rejectVerificationRequest($request), Purchase::class => $this->purchaseService->rejectVerificationRequest($request), MarketplaceSettings::class => null, - ProductVariant::class => $this->retailStockService->rejectRetailStockTransfer($request), default => throw ValidationException::withMessages([ 'subject_type' => 'Tipe data verifikasi tidak didukung.', ]), @@ -297,7 +296,6 @@ private function applyVerificationRequest(OwnerVerificationRequest $request): vo RawMaterial::class => $this->rawMaterialService->applyVerificationRequest($request), Purchase::class => $this->purchaseService->applyVerificationRequest($request), MarketplaceSettings::class => $this->marketplaceService->applyVerificationRequest($request), - ProductVariant::class => $this->retailStockService->applyRetailStockTransfer($request), default => throw ValidationException::withMessages([ 'subject_type' => 'Tipe data verifikasi tidak didukung.', ]), diff --git a/app/Services/Manage/RetailStockService.php b/app/Services/Manage/RetailStockService.php index 4083ce8..2f50e60 100644 --- a/app/Services/Manage/RetailStockService.php +++ b/app/Services/Manage/RetailStockService.php @@ -2,16 +2,11 @@ namespace App\Services\Manage; -use App\Enums\OwnerVerificationAction; -use App\Enums\OwnerVerificationStatus; -use App\Enums\Permission; -use App\Models\OwnerVerificationRequest; use App\Models\ProductVariant; use App\Models\RetailStockHistory; use App\Models\User; use App\Services\System\PushNotificationService; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; use Illuminate\Validation\ValidationException; class RetailStockService @@ -20,7 +15,7 @@ public function __construct( private readonly PushNotificationService $pushNotificationService, ) {} - public function transfer(int $variantId, int $quantity, User $user, ?string $notes = null): ?OwnerVerificationRequest + public function transfer(int $variantId, int $quantity, User $user, ?string $notes = null): void { if ($quantity <= 0) { throw ValidationException::withMessages([ @@ -36,78 +31,16 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not ]); } - $isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value); + $this->executeTransfer($variant, $quantity, $user, $notes); - if ($isOwner) { - $this->executeTransfer($variant, $quantity, $user, $notes); + $productName = $variant->product?->name ?? $variant->name; - return null; - } - - $existingPending = OwnerVerificationRequest::query() - ->where('subject_type', ProductVariant::class) - ->where('subject_id', $variant->id) - ->where('action', OwnerVerificationAction::RETAIL_STOCK_TRANSFER) - ->where('status', OwnerVerificationStatus::PENDING) - ->exists(); - - if ($existingPending) { - throw ValidationException::withMessages([ - 'quantity' => 'Masih ada pengajuan transfer stok ecer yang menunggu verifikasi untuk varian ini.', - ]); - } - - try { - $request = OwnerVerificationRequest::create([ - 'action' => OwnerVerificationAction::RETAIL_STOCK_TRANSFER, - 'status' => OwnerVerificationStatus::PENDING, - 'subject_type' => ProductVariant::class, - 'subject_id' => $variant->id, - 'submitted_by_id' => $user->id, - 'payload' => [ - 'old' => [ - 'stock' => $variant->stock, - 'retail_stock' => $variant->retail_stock, - ], - 'new' => [ - 'quantity' => $quantity, - 'stock' => $variant->stock - $quantity, - 'retail_stock' => $variant->retail_stock + $quantity, - 'notes' => $notes, - 'variant_name' => $variant->name, - 'product_name' => $variant->product?->name ?? '-', - ], - ], - ]); - - $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', 'direktur'], - 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', ['search' => $productName]), - ); - - return $request; - } catch (ValidationException $e) { - throw $e; - } catch (\Throwable $e) { - Log::error('Gagal mengajukan transfer stok ecer: '.$e->getMessage(), [ - 'trace' => $e->getTraceAsString(), - ]); - - throw ValidationException::withMessages([ - 'system' => 'Terjadi kesalahan pada server. Silakan laporkan masalah ini ke pihak terkait.', - ]); - } + $this->pushNotificationService->sendToRoles( + '📦 Perubahan Stok Ecer', + "Perubahan {$quantity} pcs stok ecer untuk varian '{$variant->name}' telah diterapkan.", + ['owner', 'developer', 'direktur'], + route('admin.master.products.index', ['search' => $productName]), + ); } public function applyRetailStockTransfer(OwnerVerificationRequest $request): void @@ -156,9 +89,4 @@ private function executeTransfer(ProductVariant $variant, int $quantity, User $u ]); }); } - - public function rejectRetailStockTransfer(OwnerVerificationRequest $request): void - { - // No-op: nothing was changed yet, so nothing to rollback. - } } diff --git a/resources/js/components/modal/RetailStockTransferModal.vue b/resources/js/components/modal/RetailStockTransferModal.vue index 2918fe2..c66b61a 100644 --- a/resources/js/components/modal/RetailStockTransferModal.vue +++ b/resources/js/components/modal/RetailStockTransferModal.vue @@ -115,7 +115,7 @@ async function submit() { emit('submitted'); open.value = false; - toast.success('Pengajuan perubahan stok ecer berhasil dikirim. Menunggu verifikasi owner.'); + toast.success('Perubahan stok ecer berhasil diterapkan.'); } catch (error) { const message = error instanceof Error ? error.message : 'Gagal menyimpan data.'; @@ -186,11 +186,6 @@ function formatNumber(value: number): string { {{ formatNumber(displayRetailStock) }} - -

- Perubahan stok ecer memerlukan persetujuan owner. Stok akan berubah setelah disetujui. -

-
@@ -231,7 +226,7 @@ function formatNumber(value: number): string { diff --git a/resources/js/pages/admin/master/products/table/data-table-actions.vue b/resources/js/pages/admin/master/products/table/data-table-actions.vue index 6fbb0ca..d2a13ee 100644 --- a/resources/js/pages/admin/master/products/table/data-table-actions.vue +++ b/resources/js/pages/admin/master/products/table/data-table-actions.vue @@ -1,4 +1,5 @@