Xu ly giao dien San Pham
This commit is contained in:
@@ -4,19 +4,13 @@ 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;
|
||||
use App\Filament\Resources\Products\ProductResource\RelationManagers\ContractsRelationManager;
|
||||
|
||||
use App\Filament\Resources\Products\Schemas\ProductForm;
|
||||
|
||||
class ProductResource extends Resource
|
||||
{
|
||||
@@ -30,43 +24,12 @@ class ProductResource extends Resource
|
||||
|
||||
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()
|
||||
]);
|
||||
return ProductForm::configure($schema);
|
||||
}
|
||||
|
||||
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(),
|
||||
]);
|
||||
return \App\Filament\Resources\Products\Tables\ProductsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array { return [ContractsRelationManager::class]; }
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace App\Filament\Resources\Products\Schemas;
|
||||
|
||||
use App\Enums\ProductType;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class ProductForm
|
||||
@@ -10,7 +16,76 @@ class ProductForm
|
||||
{
|
||||
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(),
|
||||
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')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('area')->label('Diện tích (m2)')->numeric()->required(),
|
||||
TextInput::make('price_per_unit')->label('Đơn giá')->numeric()->required()->prefix('VND'),
|
||||
TextInput::make('total_price')->label('Tổng giá')->numeric()->required()->prefix('VND'),
|
||||
Section::make('Bổ sung')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('qsdd_value')->label('Giá trị QSDĐ')->numeric()->prefix('VND'),
|
||||
TextInput::make('foundation_temp_value')->label('Giá trị móng (tạm tính)')->numeric()->prefix('VND'),
|
||||
])
|
||||
]),
|
||||
Tabs\Tab::make('Kỹ thuật & Hạ tầng')
|
||||
->icon('heroicon-o-cog')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('adjacent_road')->label('Đường tiếp giáp'),
|
||||
TextInput::make('frontage_count')->label('Số mặt tiền')->numeric(),
|
||||
TextInput::make('max_floors')->label('Số tầng tối đa')->numeric(),
|
||||
TextInput::make('construction_status')->label('Trạng thái XD'),
|
||||
KeyValue::make('infrastructure_status')
|
||||
->label('Trạng thái hạ tầng')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Tabs\Tab::make('Tiến độ thanh toán')
|
||||
->icon('heroicon-o-calendar-days')
|
||||
->schema([
|
||||
\Filament\Forms\Components\Repeater::make('payment_schedule_preview')
|
||||
->label('Lịch trình dự kiến / Thực tế')
|
||||
->relationship(function ($record) {
|
||||
// Nếu sản phẩm đã có hợp đồng, lấy lịch trình từ hợp đồng đầu tiên
|
||||
if ($record && $record->contracts()->exists()) {
|
||||
return $record->contracts()->first()->scheduleItems();
|
||||
}
|
||||
// Nếu chưa có, chúng ta sẽ hiển thị mẫu từ Project (phần này cần logic state giả lập hoặc view)
|
||||
return null;
|
||||
})
|
||||
->schema([
|
||||
TextInput::make('installment_no')->label('Đợt')->disabled(),
|
||||
TextInput::make('type')->label('Loại')->disabled(),
|
||||
TextInput::make('percentage')->label('%')->disabled(),
|
||||
TextInput::make('amount')->label('Số tiền (VNĐ)')->numeric()->disabled(),
|
||||
DatePicker::make('due_date')->label('Ngày đến hạn')->disabled(),
|
||||
])
|
||||
->columns(5)
|
||||
->addable(false)
|
||||
->deletable(false)
|
||||
->reorderable(false)
|
||||
->placeholder('Sản phẩm chưa có hợp đồng hoặc Dự án chưa gán mẫu thanh toán mặc định.')
|
||||
]),
|
||||
])->columnSpanFull()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ namespace App\Filament\Resources\Products\Tables;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\Project;
|
||||
|
||||
class ProductsTable
|
||||
{
|
||||
@@ -13,10 +16,45 @@ class ProductsTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
TextColumn::make('project.code')
|
||||
->label('Dự án')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
TextColumn::make('code')
|
||||
->label('Mã SP')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
TextColumn::make('product_type')
|
||||
->label('Loại')
|
||||
->badge(),
|
||||
TextColumn::make('total_price')
|
||||
->label('Giá')
|
||||
->money('VND')
|
||||
->sortable(),
|
||||
TextColumn::make('status')
|
||||
->label('Trạng thái')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'Đang mở bán' => 'success',
|
||||
'Đã cọc' => 'warning',
|
||||
'Đã bán' => 'danger',
|
||||
default => 'gray',
|
||||
}),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
SelectFilter::make('project_id')
|
||||
->label('Dự án')
|
||||
->relationship('project', 'name'),
|
||||
SelectFilter::make('status')
|
||||
->label('Trạng thái')
|
||||
->options([
|
||||
'Đang mở bán' => 'Đang mở bán',
|
||||
'Đã cọc' => 'Đã cọc',
|
||||
'Đã bán' => 'Đã bán',
|
||||
]),
|
||||
SelectFilter::make('product_type')
|
||||
->label('Loại sản phẩm')
|
||||
->options(\App\Enums\ProductType::class),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
|
||||
Reference in New Issue
Block a user