feat: phase 6 — dashboard widgets, sales & stock reports, user management, activity log
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user