105 lines
3.8 KiB
PHP
105 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Inventory;
|
|
|
|
use App\Services\StockMovementService;
|
|
use BackedEnum;
|
|
use Filament\Forms\Components\Select;
|
|
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\Filters\Filter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\Arr;
|
|
use UnitEnum;
|
|
|
|
class StockMovements extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-arrows-right-left';
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Inventori';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
protected static ?string $navigationLabel = 'Mutasi Stok';
|
|
|
|
protected static ?string $slug = 'inventory/stock-movements';
|
|
|
|
protected string $view = 'filament.pages.blank';
|
|
|
|
public function getTitle(): string|Htmlable
|
|
{
|
|
return 'Mutasi Stok';
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
/** @var StockMovementService $service */
|
|
$service = app(StockMovementService::class);
|
|
|
|
return $table
|
|
->records(function (?string $search, ?string $sortColumn, ?string $sortDirection, int|string $page, int|string $recordsPerPage, ?array $filters) use ($service) {
|
|
$type = Arr::get($filters, 'type.value') ?? Arr::get($filters, 'type');
|
|
|
|
return $service->paginate(
|
|
search: $search,
|
|
sortColumn: $sortColumn,
|
|
sortDirection: $sortDirection,
|
|
page: (int) $page,
|
|
perPage: (int) $recordsPerPage,
|
|
filters: array_filter(['type' => is_array($type) ? ($type['value'] ?? null) : $type]),
|
|
);
|
|
})
|
|
->columns([
|
|
TextColumn::make('created_at')->label('Waktu')->dateTime('d M Y H:i', 'Asia/Jakarta')->sortable(),
|
|
TextColumn::make('products.code')->label('Kode')->badge(),
|
|
TextColumn::make('products.name')->label('Produk'),
|
|
TextColumn::make('type')
|
|
->label('Tipe')
|
|
->badge()
|
|
->color(fn (string $state): string => match ($state) {
|
|
'restock' => 'success',
|
|
'adjustment' => 'warning',
|
|
'order_out' => 'info',
|
|
default => 'gray',
|
|
})
|
|
->formatStateUsing(fn (string $state): string => match ($state) {
|
|
'restock' => 'Restok',
|
|
'adjustment' => 'Koreksi',
|
|
'order_out' => 'Order Keluar',
|
|
default => $state,
|
|
}),
|
|
TextColumn::make('quantity')
|
|
->label('Qty')
|
|
->numeric()
|
|
->color(fn (string $state): string => str_starts_with((string) $state, '-') ? 'danger' : 'success'),
|
|
TextColumn::make('notes')->label('Catatan')->limit(40),
|
|
])
|
|
->filters([
|
|
Filter::make('type')
|
|
->schema([
|
|
Select::make('value')->label('Tipe Mutasi')->options([
|
|
'restock' => 'Restok',
|
|
'adjustment' => 'Koreksi',
|
|
'order_out' => 'Order Keluar',
|
|
]),
|
|
]),
|
|
])
|
|
->paginated([10, 25, 50]);
|
|
}
|
|
|
|
public function content(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
EmbeddedTable::make(),
|
|
]);
|
|
}
|
|
}
|