82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Reports;
|
|
|
|
use App\Services\OrderService;
|
|
use BackedEnum;
|
|
use Filament\Forms\Components\DatePicker;
|
|
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\Collection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use UnitEnum;
|
|
|
|
class SalesReport extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-chart-bar';
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Laporan';
|
|
|
|
protected static ?int $navigationSort = 0;
|
|
|
|
protected static ?string $navigationLabel = 'Penjualan';
|
|
|
|
protected static ?string $slug = 'reports/sales';
|
|
|
|
protected string $view = 'filament.pages.blank';
|
|
|
|
public function getTitle(): string|Htmlable
|
|
{
|
|
return 'Laporan Penjualan';
|
|
}
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
return Gate::check('view-reports');
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
$service = app(OrderService::class);
|
|
|
|
return $table
|
|
->records(function (?array $filters) use ($service) {
|
|
$from = Arr::get($filters, 'period.date_from') ?? now()->startOfMonth()->toDateString();
|
|
$to = Arr::get($filters, 'period.date_to') ?? now()->toDateString();
|
|
|
|
return new Collection($service->salesPerProduct($from, $to));
|
|
})
|
|
->columns([
|
|
TextColumn::make('code')->label('Kode Produk')->badge(),
|
|
TextColumn::make('name')->label('Nama Produk'),
|
|
TextColumn::make('qty')->label('Qty Terjual')->numeric(),
|
|
TextColumn::make('revenue')->label('Omzet')->numeric()->prefix('Rp '),
|
|
])
|
|
->filters([
|
|
Filter::make('period')
|
|
->schema([
|
|
DatePicker::make('date_from')->label('Dari')->default(now()->startOfMonth()->toDateString()),
|
|
DatePicker::make('date_to')->label('Sampai')->default(now()->toDateString()),
|
|
]),
|
|
])
|
|
->paginated(false);
|
|
}
|
|
|
|
public function content(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
EmbeddedTable::make(),
|
|
]);
|
|
}
|
|
}
|