Đóng gói cuối tuần
This commit is contained in:
@@ -4,10 +4,14 @@ 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;
|
||||
@@ -18,72 +22,38 @@ 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 = 'Quản lý kho';
|
||||
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([
|
||||
Section::make('Liên kết Dự án & Phân loại')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('project_id')
|
||||
->label('Thuộc Dự án')
|
||||
->relationship('project', 'name')
|
||||
->searchable()->preload()->required(),
|
||||
Select::make('product_type')
|
||||
->label('Loại sản phẩm')
|
||||
->options([
|
||||
'LAND' => 'Đất nền',
|
||||
'APARTMENT' => 'Căn hộ chung cư',
|
||||
'SHOPHOUSE' => 'Shophouse',
|
||||
])->required()->live(),
|
||||
]),
|
||||
|
||||
Section::make('Thông tin định danh & Diện tích')
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextInput::make('code')->label('Mã Sản Phẩm')->required()->unique(ignoreRecord: true),
|
||||
TextInput::make('area')->label('Diện tích (m2)')->numeric()->required()->live(onBlur: true)
|
||||
->afterStateUpdated(function (Get $get, $state, $set) {
|
||||
$price = (float) $get('price_per_unit');
|
||||
if ($state && $price) $set('total_price', (float) $state * $price);
|
||||
}),
|
||||
Select::make('red_book_status')->label('Sổ đỏ')
|
||||
->options(['Chưa có dữ liệu' => 'Chưa có dữ liệu', 'Đã có sổ' => 'Đã có sổ', 'Đang chờ sổ' => 'Đang chờ sổ'])
|
||||
->default('Chưa có dữ liệu'),
|
||||
]),
|
||||
|
||||
Section::make('Thông tin Tài chính')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('price_per_unit')->label('Đơn giá (VND/m2)')->numeric()->live(onBlur: true)
|
||||
->afterStateUpdated(function (Get $get, $state, $set) {
|
||||
$area = (float) $get('area');
|
||||
if ($state && $area) $set('total_price', (float) $state * $area);
|
||||
}),
|
||||
TextInput::make('total_price')->label('Tổng giá trị niêm yết')->numeric()->required(),
|
||||
]),
|
||||
|
||||
Section::make('Thông tin chi tiết')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('custom_data.block')->label('Block/Tòa')->visible(fn (Get $get) => $get('product_type') === 'APARTMENT'),
|
||||
TextInput::make('custom_data.floor')->label('Tầng')->numeric()->visible(fn (Get $get) => $get('product_type') === 'APARTMENT'),
|
||||
TextInput::make('custom_data.view')->label('Hướng View')->visible(fn (Get $get) => $get('product_type') === 'APARTMENT'),
|
||||
TextInput::make('custom_data.road_width')->label('Đường (m)')->visible(fn (Get $get) => in_array($get('product_type'), ['LAND', 'SHOPHOUSE'])),
|
||||
TextInput::make('custom_data.frontage')->label('Số mặt tiền')->numeric()->visible(fn (Get $get) => in_array($get('product_type'), ['LAND', 'SHOPHOUSE'])),
|
||||
]),
|
||||
|
||||
Section::make('Trạng thái kinh doanh')
|
||||
->schema([
|
||||
Select::make('status')
|
||||
->label('Tình trạng rổ hàng')
|
||||
->options(['Đang mở bán' => 'Đang mở bán', 'Đã giữ chỗ' => 'Đã giữ chỗ', 'Đã cọc' => 'Đã cọc', 'Đã bán' => 'Đã bán', 'Tạm khóa' => 'Tạm khóa'])
|
||||
->default('Đang mở bán')->required(),
|
||||
]),
|
||||
|
||||
// Đã loại bỏ phần Lịch sử Giao dịch nhúng thủ công tại đây để tránh trùng lặp
|
||||
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()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -91,26 +61,15 @@ class ProductResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('project.name')->label('Dự án')->sortable()->searchable(),
|
||||
Tables\Columns\TextColumn::make('code')->label('Mã SP')->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('contracts_count')->label('Số HĐ')->counts('contracts')->badge()->color('info'),
|
||||
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á niêm yết')->money('VND')->sortable(),
|
||||
Tables\Columns\SelectColumn::make('status')->label('Trạng thái')
|
||||
->options(['Đang mở bán' => 'Đang mở bán', 'Đã giữ chỗ' => 'Đã giữ chỗ', 'Đã cọc' => 'Đã cọc', 'Đã bán' => 'Đã bán', 'Tạm khóa' => 'Tạm khóa']),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('project_id')->label('Dự án')->relationship('project', 'name'),
|
||||
Tables\Filters\SelectFilter::make('product_type')->options(['LAND' => 'Đất nền', 'APARTMENT' => 'Căn hộ']),
|
||||
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 getRelations(): array { return [ContractsRelationManager::class]; }
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user