Init: Hoan thanh kien truc V3 va Filament UI

This commit is contained in:
2026-04-18 02:07:30 +00:00
commit 761b34916b
141 changed files with 15917 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
<?php
namespace App\Filament\Resources\Products;
use App\Filament\Resources\Products\Pages;
use App\Models\Product;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Section;
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 = 'Quản lý kho';
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
]);
}
public static function table(Table $table): Table
{
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('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ộ']),
]);
}
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'),
];
}
}