Files
hqland-app/app/Filament/Resources/Products/ProductResource.php
2026-04-18 04:46:01 +00:00

83 lines
3.6 KiB
PHP

<?php
namespace App\Filament\Resources\Products;
use App\Filament\Resources\Products\Pages;
use App\Models\Product;
use App\Enums\ProductType;
use App\Enums\NavigationGroup;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Repeater;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Tabs;
use App\Filament\Resources\Products\ProductResource\RelationManagers\ContractsRelationManager;
use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class ProductResource extends Resource
{
protected static ?string $model = Product::class;
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-squares-2x2';
protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::WAREHOUSE->value;
protected static ?int $navigationSort = 2;
protected static ?string $modelLabel = 'Sản phẩm';
protected static ?string $pluralModelLabel = 'Sản phẩm';
public static function form(Schema $schema): Schema
{
return $schema
->components([
Tabs::make('ProductDetails')
->tabs([
Tabs\Tab::make('Thông tin chung')
->icon('heroicon-o-information-circle')
->columns(2)
->schema([
Select::make('project_id')->label('Dự án')->relationship('project', 'name')->required(),
Select::make('product_type')->label('Loại sản phẩm')->options(ProductType::class)->required(),
TextInput::make('code')->label('Mã SP')->required()->unique(ignoreRecord: true),
Select::make('status')
->label('Trạng thái')
->options(['Đang mở bán' => 'Đang mở bán', 'Đã cọc' => 'Đã cọc', 'Đã bán' => 'Đã bán'])
->required(),
]),
Tabs\Tab::make('Tài chính')
->icon('heroicon-o-currency-dollar')
->schema([
TextInput::make('area')->label('Diện tích (m2)')->numeric()->required(),
TextInput::make('price_per_unit')->label('Đơn giá')->numeric()->required(),
TextInput::make('total_price')->label('Tổng giá')->numeric()->required(),
]),
])->columnSpanFull()
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('project.code')->label('Dự án'),
Tables\Columns\TextColumn::make('code')->label('Mã SP')->searchable(),
Tables\Columns\TextColumn::make('product_type')->label('Loại')->badge(),
Tables\Columns\TextColumn::make('total_price')->label('Giá')->money('VND'),
Tables\Columns\TextColumn::make('status')->label('Trạng thái')->badge(),
]);
}
public static function getRelations(): array { return [ContractsRelationManager::class]; }
public static function getPages(): array
{
return [
'index' => Pages\ListProducts::route('/'),
'create' => Pages\CreateProduct::route('/create'),
'edit' => Pages\EditProduct::route('/{record}/edit'),
];
}
}