From ae8a5e4ce80051b954791d4343aacdf93420da49 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Mon, 17 Nov 2025 16:07:59 +0700 Subject: [PATCH] refactor(permission): menghapus permission view cogs dan menyesuaikan kembali semua kondisi yang memakai itu dan diganti dengan roles --- app/Livewire/Chart/OutletExpense.php | 2 +- app/Livewire/Forms/Studio/Catalog/BottleForm.php | 2 +- app/Livewire/Forms/Studio/Catalog/PerfumeForm.php | 2 +- app/Livewire/Forms/Studio/Catalog/ProductForm.php | 2 +- app/Livewire/Studio/Dashboard/Analysis.php | 4 ++-- app/Livewire/Studio/Dashboard/Overview.php | 8 ++++---- database/seeders/RolePermissionSeeder.php | 5 ----- .../views/livewire/studio/catalog/bottle/form.blade.php | 3 ++- .../views/livewire/studio/catalog/perfume/form.blade.php | 2 +- .../views/livewire/studio/catalog/product/form.blade.php | 3 ++- 10 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/Livewire/Chart/OutletExpense.php b/app/Livewire/Chart/OutletExpense.php index 84bd530..7d8cf4c 100644 --- a/app/Livewire/Chart/OutletExpense.php +++ b/app/Livewire/Chart/OutletExpense.php @@ -24,7 +24,7 @@ public function mount(array $outlets) foreach ($outlets as $id => $name) { $expenseTotal = Expense::where('outlet_id', $id)->sum('amount'); - $purchaseTotal = auth()->user()?->hasPermissionTo('view cogs') ? Purchase::where('outlet_id', $id)->sum('total') : 0; + $purchaseTotal = auth()->user()->hasRole(['Developer', 'Owner']) ? Purchase::where('outlet_id', $id)->sum('total') : 0; $payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary'); diff --git a/app/Livewire/Forms/Studio/Catalog/BottleForm.php b/app/Livewire/Forms/Studio/Catalog/BottleForm.php index c31d1c2..cccb24e 100644 --- a/app/Livewire/Forms/Studio/Catalog/BottleForm.php +++ b/app/Livewire/Forms/Studio/Catalog/BottleForm.php @@ -34,7 +34,7 @@ public function rules(): array return [ 'name' => ['required', 'string', 'max:50'], 'size' => ['required', new UnsignedInteger], - 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'description' => ['nullable', 'string'], 'outlet_ids' => ['required', 'array', 'min:1'], diff --git a/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php b/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php index 9983cb3..98f5844 100644 --- a/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php +++ b/app/Livewire/Forms/Studio/Catalog/PerfumeForm.php @@ -53,7 +53,7 @@ public function rules(): array Rule::unique('perfumes', 'sku')->ignore($this->perfume), ], 'brand_id' => ['nullable', Rule::exists('brands', 'id')], - 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'base_notes' => ['nullable', 'string', 'max:255'], 'middle_notes' => ['nullable', 'string', 'max:255'], diff --git a/app/Livewire/Forms/Studio/Catalog/ProductForm.php b/app/Livewire/Forms/Studio/Catalog/ProductForm.php index e7c27e1..e15f6e5 100644 --- a/app/Livewire/Forms/Studio/Catalog/ProductForm.php +++ b/app/Livewire/Forms/Studio/Catalog/ProductForm.php @@ -39,7 +39,7 @@ public function rules(): array 'max:20', Rule::unique('products', 'sku')->ignore($this->product), ], - 'cost_price' => [Rule::requiredIf(auth()->user()->can('view cogs')), new UnsignedInteger], + 'cost_price' => [Rule::requiredIf(auth()->user()->hasRole(['Developer', 'Owner'])), new UnsignedInteger], 'sale_price' => ['required', new UnsignedInteger], 'description' => ['nullable', 'string'], 'outlet_ids' => ['required', 'array', 'min:1'], diff --git a/app/Livewire/Studio/Dashboard/Analysis.php b/app/Livewire/Studio/Dashboard/Analysis.php index 6217f92..d740e76 100644 --- a/app/Livewire/Studio/Dashboard/Analysis.php +++ b/app/Livewire/Studio/Dashboard/Analysis.php @@ -185,7 +185,7 @@ protected function loadData() ), ], - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'HPP', 'value' => currency( Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) @@ -249,7 +249,7 @@ protected function loadData() ), ], - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'Belanja Barang', 'value' => currency( Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) diff --git a/app/Livewire/Studio/Dashboard/Overview.php b/app/Livewire/Studio/Dashboard/Overview.php index 772e181..609bab1 100644 --- a/app/Livewire/Studio/Dashboard/Overview.php +++ b/app/Livewire/Studio/Dashboard/Overview.php @@ -162,7 +162,7 @@ protected function loadStats() 'formatted' => currency($todayIncome, 'Rp'), ], - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'HPP', 'value' => currency($todayCogs, 'Rp'), 'previous' => currency($yesterdayCogs, 'Rp'), @@ -202,7 +202,7 @@ protected function loadStats() 'trendUp' => $todayExpense > $yesterdayExpense, ], - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'Belanja Barang', 'value' => currency($todayPurchase, 'Rp'), 'previous' => currency($yesterdayPurchase, 'Rp'), @@ -212,7 +212,7 @@ protected function loadStats() 'trendUp' => $todayPurchase > $yesterdayPurchase, ] : null, - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'Laba Kotor', 'value' => currency($todayGrossProfit, 'Rp'), 'previous' => currency($yesterdayGrossProfit, 'Rp'), @@ -222,7 +222,7 @@ protected function loadStats() 'trendUp' => $todayGrossProfit > $yesterdayGrossProfit, ] : null, - auth()->user()?->hasPermissionTo('view cogs') ? [ + auth()->user()->hasRole(['Developer', 'Owner']) ? [ 'title' => 'Laba Bersih', 'value' => currency($todayNetProfit, 'Rp'), 'previous' => currency($yesterdayNetProfit, 'Rp'), diff --git a/database/seeders/RolePermissionSeeder.php b/database/seeders/RolePermissionSeeder.php index 7551cb9..191688f 100644 --- a/database/seeders/RolePermissionSeeder.php +++ b/database/seeders/RolePermissionSeeder.php @@ -158,9 +158,6 @@ public function run(): void // partner 'view partner overview', - - // other - 'view cogs', ]; foreach ($permissions as $permission) { @@ -271,7 +268,6 @@ public function run(): void 'view social settings', 'update social settings', - 'view cogs', ])); $admin->syncPermissions(array_diff($permissions, [ @@ -383,7 +379,6 @@ public function run(): void 'view social settings', 'update social settings', - 'view cogs', ])); $partner->syncPermissions([ diff --git a/resources/views/livewire/studio/catalog/bottle/form.blade.php b/resources/views/livewire/studio/catalog/bottle/form.blade.php index f2fa58e..9485ccc 100644 --- a/resources/views/livewire/studio/catalog/bottle/form.blade.php +++ b/resources/views/livewire/studio/catalog/bottle/form.blade.php @@ -45,7 +45,8 @@ @endcan - + Harga Jual * Rp diff --git a/resources/views/livewire/studio/catalog/perfume/form.blade.php b/resources/views/livewire/studio/catalog/perfume/form.blade.php index 5ab484d..53508bb 100644 --- a/resources/views/livewire/studio/catalog/perfume/form.blade.php +++ b/resources/views/livewire/studio/catalog/perfume/form.blade.php @@ -34,7 +34,7 @@
+ class="grid grid-cols-1 md:grid-cols-{{ auth()->user()->hasRole(['Developer', 'Owner'])? '3': '2' }} gap-6"> @foreach ($brands as $key => $value) diff --git a/resources/views/livewire/studio/catalog/product/form.blade.php b/resources/views/livewire/studio/catalog/product/form.blade.php index e48ee2c..810d48c 100644 --- a/resources/views/livewire/studio/catalog/product/form.blade.php +++ b/resources/views/livewire/studio/catalog/product/form.blade.php @@ -45,7 +45,8 @@ @endcan - + Harga Jual * Rp