feat: phase 6 — dashboard widgets, sales & stock reports, user management, activity log
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Reports;
|
||||
|
||||
use App\Services\StockService;
|
||||
use BackedEnum;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\EmbeddedTable;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use UnitEnum;
|
||||
|
||||
class StockReport extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cube-transparent';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Laporan';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $navigationLabel = 'Posisi Stok';
|
||||
|
||||
protected static ?string $slug = 'reports/stock';
|
||||
|
||||
protected string $view = 'filament.pages.blank';
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return 'Laporan Posisi Stok';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Gate::check('view-reports');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
$service = app(StockService::class);
|
||||
|
||||
return $table
|
||||
->records(fn () => new Collection($service->paginate(perPage: 100)->items()))
|
||||
->columns([
|
||||
TextColumn::make('products.code')->label('Kode')->badge(),
|
||||
TextColumn::make('products.name')->label('Produk'),
|
||||
TextColumn::make('quantity')->label('Saldo')->numeric(),
|
||||
TextColumn::make('products.stock_minimum')->label('Min.'),
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->color(fn (string $state): string => $state === 'kritis' ? 'danger' : 'success')
|
||||
->state(fn (array $record): string => (int) $record['quantity'] <= (int) data_get($record, 'products.stock_minimum', 0) ? 'kritis' : 'aman'),
|
||||
TextColumn::make('nilai')
|
||||
->label('Nilai Stok')
|
||||
->numeric()->prefix('Rp ')
|
||||
->state(fn (array $record): int => (int) $record['quantity'] * (int) ($record['products']['cost_price'] ?? 0)),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
EmbeddedTable::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user