164 lines
7.7 KiB
PHP
164 lines
7.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\SalesPhases\Schemas;
|
|
|
|
use App\Models\PaymentTemplate;
|
|
use App\Models\Product;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Repeater;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Schemas\Components\Utilities\Set;
|
|
|
|
class SalesPhaseForm
|
|
{
|
|
public static function configure(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
// SECTION 1: Thông tin đợt mở bán
|
|
Section::make('Thông tin đợt mở bán')
|
|
->columnSpanFull()
|
|
->schema([
|
|
Grid::make(3)
|
|
->schema([
|
|
Select::make('project_id')
|
|
->label('Dự án')
|
|
->relationship('project', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->required()
|
|
->live(),
|
|
|
|
TextInput::make('name')
|
|
->label('Tên đợt mở bán')
|
|
->placeholder('Đợt 1 - Mở bán tháng 5/2026')
|
|
->required(),
|
|
|
|
TextInput::make('code')
|
|
->label('Mã đợt')
|
|
->placeholder('MB1')
|
|
->required()
|
|
->unique(ignoreRecord: true),
|
|
]),
|
|
|
|
Grid::make(3)
|
|
->schema([
|
|
DatePicker::make('start_date')
|
|
->label('Ngày bắt đầu')
|
|
->required()
|
|
->default(now()),
|
|
|
|
DatePicker::make('end_date')
|
|
->label('Ngày kết thúc')
|
|
->nullable(),
|
|
|
|
Select::make('status')
|
|
->label('Trạng thái')
|
|
->options([
|
|
'Chuẩn bị' => 'Chuẩn bị',
|
|
'Đang mở bán' => 'Đang mở bán',
|
|
'Tạm dừng' => 'Tạm dừng',
|
|
'Đã đóng' => 'Đã đóng',
|
|
])
|
|
->default('Chuẩn bị')
|
|
->required(),
|
|
]),
|
|
|
|
Textarea::make('description')
|
|
->label('Mô tả')
|
|
->rows(3)
|
|
->columnSpanFull(),
|
|
]),
|
|
|
|
// SECTION 2: Chính sách & Lịch thanh toán
|
|
Section::make('Chính sách & Lịch thanh toán')
|
|
->columnSpanFull()
|
|
->schema([
|
|
Grid::make(2)
|
|
->schema([
|
|
Select::make('payment_template_id')
|
|
->label('Mẫu lịch thanh toán')
|
|
->relationship('paymentTemplate', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->helperText('Áp dụng cho các hợp đồng trong đợt mở bán này')
|
|
->columnSpan(1),
|
|
|
|
KeyValue::make('discount_policy')
|
|
->label('Chính sách chiết khấu mặc định')
|
|
->keyLabel('Loại chiết khấu')
|
|
->valueLabel('Giá trị')
|
|
->helperText('Ví dụ: open_sale => 5%, wholesale => 3%')
|
|
->columnSpan(1),
|
|
]),
|
|
]),
|
|
|
|
// SECTION 3: Danh sách sản phẩm trong đợt
|
|
Section::make('Sản phẩm trong đợt mở bán')
|
|
->columnSpanFull()
|
|
->schema([
|
|
Repeater::make('phaseProducts')
|
|
->relationship('phaseProducts')
|
|
->schema([
|
|
Grid::make(4)
|
|
->schema([
|
|
Select::make('product_id')
|
|
->label('Sản phẩm')
|
|
->options(function (callable $get, $state) {
|
|
$projectId = $get('../../project_id');
|
|
if (! $projectId) return [];
|
|
return Product::where('project_id', $projectId)
|
|
->pluck('code', 'id');
|
|
})
|
|
->searchable()
|
|
->required(),
|
|
|
|
TextInput::make('sale_price')
|
|
->label('Giá bán đợt này')
|
|
->numeric()
|
|
->prefix('VND')
|
|
->placeholder('Để trống nếu lấy giá gốc'),
|
|
|
|
TextInput::make('land_value')
|
|
->label('Giá trị QSDĐ')
|
|
->numeric()
|
|
->prefix('VND'),
|
|
|
|
TextInput::make('foundation_value')
|
|
->label('Giá trị móng')
|
|
->numeric()
|
|
->prefix('VND'),
|
|
|
|
KeyValue::make('discount_details')
|
|
->label('Chiết khấu riêng')
|
|
->keyLabel('Loại')
|
|
->valueLabel('Giá trị')
|
|
->columnSpan(2),
|
|
|
|
Select::make('status')
|
|
->label('Trạng thái')
|
|
->options([
|
|
'Còn hàng' => 'Còn hàng',
|
|
'Đã giữ' => 'Đã giữ chỗ',
|
|
'Đã bán' => 'Đã bán',
|
|
'Khóa' => 'Khóa',
|
|
])
|
|
->default('Còn hàng')
|
|
->columnSpan(2),
|
|
]),
|
|
])
|
|
->addActionLabel('Thêm sản phẩm vào đợt')
|
|
->reorderable()
|
|
->defaultItems(0)
|
|
->collapsible(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|