Init: Hoan thanh kien truc V3 va Filament UI
This commit is contained in:
11
app/Filament/Resources/Products/Pages/CreateProduct.php
Normal file
11
app/Filament/Resources/Products/Pages/CreateProduct.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\Pages;
|
||||
|
||||
use App\Filament\Resources\Products\ProductResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateProduct extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProductResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Products/Pages/EditProduct.php
Normal file
19
app/Filament/Resources/Products/Pages/EditProduct.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\Pages;
|
||||
|
||||
use App\Filament\Resources\Products\ProductResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditProduct extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Products/Pages/ListProducts.php
Normal file
19
app/Filament/Resources/Products/Pages/ListProducts.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\Pages;
|
||||
|
||||
use App\Filament\Resources\Products\ProductResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListProducts extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
123
app/Filament/Resources/Products/ProductResource.php
Normal file
123
app/Filament/Resources/Products/ProductResource.php
Normal 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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\ProductResource\RelationManagers;
|
||||
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
|
||||
class ContractsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'contracts';
|
||||
|
||||
protected static ?string $title = 'Lịch sử Giao dịch';
|
||||
|
||||
protected static ?string $modelLabel = 'Hợp đồng';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Thông tin Hợp đồng')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('contract_number')->label('Số Hợp đồng'),
|
||||
Select::make('contract_type')
|
||||
->label('Loại Hợp đồng')
|
||||
->options([
|
||||
'HĐMB' => 'HĐ Mua bán',
|
||||
'HĐĐC' => 'HĐ Đặt cọc',
|
||||
'HĐGV' => 'HĐ Góp vốn',
|
||||
'VBCN' => 'Văn bản chuyển nhượng',
|
||||
]),
|
||||
DatePicker::make('signing_date')->label('Ngày ký')->displayFormat('d/m/Y'),
|
||||
TextInput::make('status')->label('Trạng thái'),
|
||||
]),
|
||||
Section::make('Giá trị & Tài chính')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Placeholder::make('total_value')
|
||||
->label('Tổng giá trị')
|
||||
->content(fn ($record) => $record ? number_format($record->total_value) . ' VNĐ' : '-'),
|
||||
Placeholder::make('paid_amount')
|
||||
->label('Đã thanh toán')
|
||||
->content(fn ($record) => $record ? number_format($record->paid_amount) . ' VNĐ' : '-'),
|
||||
Placeholder::make('remaining_amount')
|
||||
->label('Số tiền còn lại')
|
||||
->content(fn ($record) => $record ? number_format($record->total_value - $record->paid_amount) . ' VNĐ' : '-'),
|
||||
]),
|
||||
Section::make('Khách hàng liên quan')
|
||||
->schema([
|
||||
Select::make('customers')
|
||||
->label('Danh sách Khách hàng')
|
||||
->relationship('customers', 'full_name')
|
||||
->multiple()
|
||||
->preload(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('contract_number')
|
||||
->columns([
|
||||
TextColumn::make('transfer_order')
|
||||
->label('Thứ tự')
|
||||
->formatStateUsing(fn ($state) => match ((int) $state) {
|
||||
0 => 'Chủ hiện tại',
|
||||
1 => 'HĐ Gốc',
|
||||
default => 'F' . ($state - 1),
|
||||
})
|
||||
->color(fn ($state) => match ((int) $state) {
|
||||
0 => 'success',
|
||||
1 => 'gray',
|
||||
default => 'warning',
|
||||
})->badge(),
|
||||
TextColumn::make('contract_number')->label('Mã HĐ')->searchable()->sortable(),
|
||||
TextColumn::make('contract_type')->label('Loại HĐ')->badge(),
|
||||
TextColumn::make('total_value')->label('Giá trị')->money('VND')->sortable(),
|
||||
TextColumn::make('signing_date')->label('Ngày ký')->date('d/m/Y')->sortable(),
|
||||
TextColumn::make('status')->label('Trạng thái')->badge(),
|
||||
])
|
||||
->defaultSort('transfer_order', 'asc')
|
||||
->actions([
|
||||
ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
16
app/Filament/Resources/Products/Schemas/ProductForm.php
Normal file
16
app/Filament/Resources/Products/Schemas/ProductForm.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\Schemas;
|
||||
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ProductForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
app/Filament/Resources/Products/Tables/ProductsTable.php
Normal file
30
app/Filament/Resources/Products/Tables/ProductsTable.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Products\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ProductsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user