feat: phase 2 — master data (products, customers, drivers) via InsForge-backed Filament pages
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Masters;
|
||||
|
||||
use App\Services\CustomerService;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Component;
|
||||
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 UnitEnum;
|
||||
|
||||
class Customers extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-users';
|
||||
|
||||
protected static UnitEnum|string|null $navigationGroup = 'Master';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $navigationLabel = 'Pelanggan';
|
||||
|
||||
protected static ?string $slug = 'masters/customers';
|
||||
|
||||
protected string $view = 'filament.pages.blank';
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return 'Pelanggan';
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var CustomerService $service */
|
||||
$service = app(CustomerService::class);
|
||||
|
||||
return $table
|
||||
->records(fn (?string $search, ?string $sortColumn, ?string $sortDirection, int|string $page, int|string $recordsPerPage) => $service->paginate(
|
||||
search: $search,
|
||||
sortColumn: $sortColumn,
|
||||
sortDirection: $sortDirection,
|
||||
page: (int) $page,
|
||||
perPage: (int) $recordsPerPage,
|
||||
))
|
||||
->columns([
|
||||
TextColumn::make('customer_code')->label('Kode')->sortable(),
|
||||
TextColumn::make('name')->label('Nama')->searchable()->sortable(),
|
||||
TextColumn::make('address')->label('Alamat')->limit(40),
|
||||
TextColumn::make('phone')->label('Telepon'),
|
||||
TextColumn::make('notes')->label('Catatan')->limit(30),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::customerFormSchema()))
|
||||
->using(function (array $data): void {
|
||||
app(CustomerService::class)->create($data);
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::customerFormSchema()))
|
||||
->fillForm(fn (array $record): array => $record)
|
||||
->action(function (array $data, array $record): void {
|
||||
app(CustomerService::class)->update($record['id'], $data);
|
||||
}),
|
||||
Action::make('hapus')
|
||||
->label('Hapus')
|
||||
->color('danger')
|
||||
->icon('heroicon-o-trash')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Yakin menghapus pelanggan ini?')
|
||||
->action(function (array $record): void {
|
||||
app(CustomerService::class)->delete($record['id']);
|
||||
}),
|
||||
])
|
||||
->paginated([10, 25, 50]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Component>
|
||||
*/
|
||||
private static function customerFormSchema(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('customer_code')->label('Kode')->default(fn () => app(CustomerService::class)->nextCode())->required()->maxLength(20),
|
||||
TextInput::make('name')->label('Nama Pelanggan')->required()->maxLength(150),
|
||||
TextInput::make('address')->label('Alamat')->maxLength(255),
|
||||
TextInput::make('phone')->label('Telepon')->tel()->maxLength(30),
|
||||
Textarea::make('notes')->label('Catatan')->columnSpanFull(),
|
||||
];
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
EmbeddedTable::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Masters;
|
||||
|
||||
use App\Services\DriverService;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\EmbeddedTable;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
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\Facades\Gate;
|
||||
use UnitEnum;
|
||||
|
||||
class Drivers extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-truck';
|
||||
|
||||
protected static UnitEnum|string|null $navigationGroup = 'Master';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $navigationLabel = 'Pengemudi';
|
||||
|
||||
protected static ?string $slug = 'masters/drivers';
|
||||
|
||||
protected string $view = 'filament.pages.blank';
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return 'Pengemudi';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Gate::check('manage-drivers');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var DriverService $service */
|
||||
$service = app(DriverService::class);
|
||||
|
||||
return $table
|
||||
->records(fn (?string $search, ?string $sortColumn, ?string $sortDirection, int|string $page, int|string $recordsPerPage) => $service->paginate(
|
||||
search: $search,
|
||||
sortColumn: $sortColumn,
|
||||
sortDirection: $sortDirection,
|
||||
page: (int) $page,
|
||||
perPage: (int) $recordsPerPage,
|
||||
))
|
||||
->columns([
|
||||
TextColumn::make('driver_code')->label('Kode')->sortable(),
|
||||
TextColumn::make('name')->label('Nama')->searchable()->sortable(),
|
||||
TextColumn::make('phone')->label('Telepon'),
|
||||
IconColumn::make('is_active')->label('Aktif')->boolean(),
|
||||
TextColumn::make('notes')->label('Catatan')->limit(30),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::driverFormSchema()))
|
||||
->using(function (array $data): void {
|
||||
$data['is_active'] = true;
|
||||
app(DriverService::class)->create($data);
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::driverFormSchema(withStatus: true)))
|
||||
->fillForm(fn (array $record): array => $record)
|
||||
->action(function (array $data, array $record): void {
|
||||
$data['is_active'] = (bool) ($data['is_active'] ?? true);
|
||||
app(DriverService::class)->update($record['id'], $data);
|
||||
}),
|
||||
Action::make('hapus')
|
||||
->label('Hapus')
|
||||
->color('danger')
|
||||
->icon('heroicon-o-trash')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Yakin menghapus pengemudi ini?')
|
||||
->action(function (array $record): void {
|
||||
app(DriverService::class)->delete($record['id']);
|
||||
}),
|
||||
])
|
||||
->paginated([10, 25, 50]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Component>
|
||||
*/
|
||||
private static function driverFormSchema(bool $withStatus = false): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('driver_code')->label('Kode')->default(fn () => app(DriverService::class)->nextCode())->required()->maxLength(20),
|
||||
TextInput::make('name')->label('Nama Pengemudi')->required()->maxLength(150),
|
||||
TextInput::make('phone')->label('Telepon')->tel()->maxLength(30),
|
||||
Textarea::make('notes')->label('Catatan')->columnSpanFull(),
|
||||
...($withStatus ? [Select::make('is_active')->label('Status')->options([1 => 'Aktif', 0 => 'Nonaktif'])->default(1)->required()] : []),
|
||||
];
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
EmbeddedTable::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Masters;
|
||||
|
||||
use App\Services\ProductService;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\EmbeddedTable;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
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\Facades\Gate;
|
||||
use UnitEnum;
|
||||
|
||||
class Products extends Page implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cube';
|
||||
|
||||
protected static UnitEnum|string|null $navigationGroup = 'Inventori';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $navigationLabel = 'Produk';
|
||||
|
||||
protected static ?string $slug = 'masters/products';
|
||||
|
||||
protected string $view = 'filament.pages.blank';
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return 'Produk';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Gate::check('manage-products');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var ProductService $service */
|
||||
$service = app(ProductService::class);
|
||||
|
||||
return $table
|
||||
->records(fn (?string $search, ?string $sortColumn, ?string $sortDirection, int|string $page, int|string $recordsPerPage) => $service->paginate(
|
||||
search: $search,
|
||||
sortColumn: $sortColumn,
|
||||
sortDirection: $sortDirection,
|
||||
page: (int) $page,
|
||||
perPage: (int) $recordsPerPage,
|
||||
))
|
||||
->columns([
|
||||
TextColumn::make('code')->label('Kode')->sortable(),
|
||||
TextColumn::make('name')->label('Nama')->searchable()->sortable(),
|
||||
TextColumn::make('unit')->label('Satuan'),
|
||||
TextColumn::make('weight')->label('Berat'),
|
||||
TextColumn::make('stock_minimum')->label('Stok Minimum')->numeric()->sortable(),
|
||||
TextColumn::make('cost_price')->label('Harga Beli')->numeric()->prefix('Rp ')->sortable(),
|
||||
IconColumn::make('is_active')->label('Aktif')->boolean(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::productFormSchema()))
|
||||
->using(function (array $data): void {
|
||||
$data['is_active'] = true;
|
||||
app(ProductService::class)->create($data);
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->schema(fn (Schema $schema): Schema => $schema->components(self::productFormSchema(withStatus: true)))
|
||||
->fillForm(fn (array $record): array => $record)
|
||||
->action(function (array $data, array $record): void {
|
||||
app(ProductService::class)->update($record['id'], $data);
|
||||
}),
|
||||
Action::make('hapus')
|
||||
->label('Hapus')
|
||||
->color('danger')
|
||||
->icon('heroicon-o-trash')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Yakin menghapus produk ini?')
|
||||
->action(function (array $record): void {
|
||||
app(ProductService::class)->delete($record['id']);
|
||||
}),
|
||||
])
|
||||
->paginated([10, 25, 50]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Component>
|
||||
*/
|
||||
private static function productFormSchema(bool $withStatus = false): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('code')->label('Kode')->default(fn () => app(ProductService::class)->nextCode())->required()->maxLength(50),
|
||||
TextInput::make('name')->label('Nama Produk')->required()->maxLength(150),
|
||||
Select::make('unit')->label('Satuan')->options(['kg' => 'Kilogram', 'sak' => 'Sak', 'ton' => 'Ton'])->default('kg')->required(),
|
||||
TextInput::make('weight')->label('Berat')->numeric()->default(0),
|
||||
TextInput::make('stock_minimum')->label('Stok Minimum')->numeric()->default(0),
|
||||
TextInput::make('cost_price')->label('Harga Beli')->numeric()->default(0),
|
||||
...($withStatus ? [Select::make('is_active')->label('Status')->options([1 => 'Aktif', 0 => 'Nonaktif'])->default(1)->required()] : []),
|
||||
];
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
EmbeddedTable::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user