diff --git a/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php b/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php index 92b3206..285bdbe 100644 --- a/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/BottlesTable.php @@ -65,7 +65,8 @@ public function columns(): array }) ->searchable() ->sortable() - ->html(), + ->html() + ->hideIf(auth()->user()->cannot('view cogs')), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp')) @@ -81,12 +82,14 @@ public function columns(): array ArrayColumn::make('Outlet') ->data( - fn ($value, $row) => $row->outlets->map(fn ($outlet) => [ - 'id' => $outlet->hash, - 'bottle_id' => $row->hash, - 'name' => $outlet->name, - 'stock' => currency($outlet->pivot->stock, ''), - ])->toArray() + fn ($value, $row) => $row->outlets + ->filter(fn ($outlet) => auth()->user()->outlets->pluck('id')->contains($outlet->id)) + ->map(fn ($outlet) => [ + 'id' => $outlet->hash, + 'bottle_id' => $row->hash, + 'name' => $outlet->name, + 'stock' => currency($outlet->pivot->stock, ''), + ])->toArray() ) ->outputFormat(function ($index, $value) { $route = route('studio.catalog.bottle.audit', [$value['id'], $value['bottle_id']]); @@ -135,6 +138,11 @@ class='flex items-center space-x-2 bg-gray-50 border border-gray-200 rounded-lg public function builder(): Builder { - return Bottle::select('id', 'name', 'size', 'cost_price', 'sale_price')->with('outlets'); + return Bottle::select('id', 'name', 'size', 'cost_price', 'sale_price') + ->with('outlets') + ->whereHas( + 'outlets', + fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id')) + ); } } diff --git a/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php b/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php index 0ba5fc7..4c0d0da 100644 --- a/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/PerfumesTable.php @@ -75,7 +75,8 @@ public function columns(): array }) ->searchable() ->sortable() - ->html(), + ->html() + ->hideIf(auth()->user()->cannot('view cogs')), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp')) @@ -84,12 +85,14 @@ public function columns(): array ArrayColumn::make('Outlet') ->data( - fn ($value, $row) => $row->outlets->map(fn ($outlet) => [ - 'id' => $outlet->hash, - 'perfume_id' => $row->hash, - 'name' => $outlet->name, - 'stock' => currency($outlet->pivot->stock, ''), - ])->toArray() + fn ($value, $row) => $row->outlets + ->filter(fn ($outlet) => auth()->user()->outlets->pluck('id')->contains($outlet->id)) + ->map(fn ($outlet) => [ + 'id' => $outlet->hash, + 'perfume_id' => $row->hash, + 'name' => $outlet->name, + 'stock' => currency($outlet->pivot->stock, ''), + ])->toArray() ) ->outputFormat(function ($index, $value) { $route = route('studio.catalog.perfume.audit', [$value['id'], $value['perfume_id']]); @@ -138,6 +141,25 @@ class='flex items-center space-x-2 bg-gray-50 border border-gray-200 rounded-lg public function builder(): Builder { - return Perfume::select('perfumes.id', 'sku', 'perfumes.name', 'concentration', 'cost_price', 'sale_price', 'base_notes', 'middle_notes', 'top_notes')->with(['categories', 'brand', 'outlets']); + return Perfume::select( + 'perfumes.id', + 'sku', + 'perfumes.name', + 'concentration', + 'cost_price', + 'sale_price', + 'base_notes', + 'middle_notes', + 'top_notes' + ) + ->with([ + 'categories', + 'brand', + 'outlets', + ]) + ->whereHas( + 'outlets', + fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id')) + ); } } diff --git a/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php b/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php index 1014db8..770ebe6 100644 --- a/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php +++ b/app/Livewire/Datatable/Studio/Catalog/ProductsTable.php @@ -64,7 +64,8 @@ public function columns(): array }) ->searchable() ->sortable() - ->html(), + ->html() + ->hideIf(auth()->user()->cannot('view cogs')), Column::make('Harga Jual', 'sale_price') ->label(fn ($row, $column) => currency($row->sale_price, 'Rp')) @@ -73,12 +74,14 @@ public function columns(): array ArrayColumn::make('Outlet') ->data( - fn ($value, $row) => $row->outlets->map(fn ($outlet) => [ - 'id' => $outlet->hash, - 'product_id' => $row->hash, - 'name' => $outlet->name, - 'stock' => currency($outlet->pivot->stock, ''), - ])->toArray() + fn ($value, $row) => $row->outlets + ->filter(fn ($outlet) => auth()->user()->outlets->pluck('id')->contains($outlet->id)) + ->map(fn ($outlet) => [ + 'id' => $outlet->hash, + 'product_id' => $row->hash, + 'name' => $outlet->name, + 'stock' => currency($outlet->pivot->stock, ''), + ])->toArray() ) ->outputFormat(function ($index, $value) { $route = route('studio.catalog.product.audit', [$value['id'], $value['product_id']]); @@ -127,6 +130,11 @@ class='flex items-center space-x-2 bg-gray-50 border border-gray-200 rounded-lg public function builder(): Builder { - return Product::select('products.id', 'sku', 'products.name', 'cost_price', 'sale_price')->with('outlets'); + return Product::select('products.id', 'sku', 'products.name', 'cost_price', 'sale_price') + ->with('outlets') + ->whereHas( + 'outlets', + fn ($q) => $q->whereIn('outlets.id', auth()->user()->outlets()->pluck('outlets.id')) + ); } }