feat(gods table): menyesuaikan kueri

This commit is contained in:
Yoga Pangestu 2025-11-16 17:52:34 +07:00
parent 8b700bd388
commit cf0556574d
3 changed files with 62 additions and 24 deletions

View File

@ -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'))
);
}
}

View File

@ -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'))
);
}
}

View File

@ -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'))
);
}
}