40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Services\StockService;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Filament\Widgets\TableWidget;
|
|
|
|
class CriticalStock extends TableWidget
|
|
{
|
|
protected static ?int $sort = 1;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
$service = app(StockService::class);
|
|
|
|
$rows = collect($service->paginate(perPage: 100)->items())
|
|
->filter(fn (array $row): bool => (int) $row['quantity'] <= (int) data_get($row, 'products.stock_minimum', 0))
|
|
->values();
|
|
|
|
return $table
|
|
->heading('Stok Kritis')
|
|
->records(fn () => $rows)
|
|
->columns([
|
|
TextColumn::make('products.code')->label('Kode')->badge(),
|
|
TextColumn::make('products.name')->label('Produk'),
|
|
TextColumn::make('quantity')->label('Saldo')->numeric()->color('danger'),
|
|
TextColumn::make('products.stock_minimum')->label('Min.'),
|
|
TextColumn::make('status')
|
|
->badge()
|
|
->color('danger')
|
|
->state(fn (array $record): string => (int) $record['quantity'] <= (int) data_get($record, 'products.stock_minimum', 0) ? 'kritis' : 'aman'),
|
|
])
|
|
->paginated(false);
|
|
}
|
|
}
|