93 lines
4.1 KiB
PHP
93 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Customers\Schemas;
|
|
|
|
use App\Models\Customer;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\TagsInput;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Schemas\Components\Utilities\Set;
|
|
|
|
class CustomerForm
|
|
{
|
|
public static function configure(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Section::make('Thông tin định danh')
|
|
->columns(2)
|
|
->schema([
|
|
Select::make('type')
|
|
->label('Loại khách hàng')
|
|
->options([
|
|
'INDIVIDUAL' => 'Cá nhân',
|
|
'COMPANY' => 'Công ty',
|
|
])
|
|
->required()
|
|
->live(),
|
|
TextInput::make('full_name')
|
|
->label(fn ($get) => $get('type') === 'COMPANY' ? 'Tên công ty' : 'Họ và tên')
|
|
->required(),
|
|
TextInput::make('cmnd_cccd')
|
|
->label(fn ($get) => $get('type') === 'COMPANY' ? 'GPKD / Mã số thuế' : 'CMND / CCCD')
|
|
->required(),
|
|
TextInput::make('tax_code')
|
|
->label('Mã số thuế')
|
|
->visible(fn ($get) => $get('type') === 'COMPANY'),
|
|
Select::make('representative_id')
|
|
->label('Người đại diện pháp luật')
|
|
->options(Customer::where('type', 'INDIVIDUAL')->pluck('full_name', 'id'))
|
|
->searchable()
|
|
->visible(fn ($get) => $get('type') === 'COMPANY')
|
|
->required(fn ($get) => $get('type') === 'COMPANY'),
|
|
]),
|
|
|
|
Section::make('Liên lạc')
|
|
->columns(2)
|
|
->schema([
|
|
TextInput::make('phone')
|
|
->label('Số điện thoại chính')
|
|
->tel(),
|
|
TagsInput::make('secondary_phones')
|
|
->label('Số điện thoại phụ')
|
|
->placeholder('Nhập số và nhấn Enter'),
|
|
TextInput::make('email')
|
|
->label('Địa chỉ Email')
|
|
->email(),
|
|
]),
|
|
|
|
Section::make('Địa chỉ')
|
|
->columns(2)
|
|
->schema([
|
|
TextInput::make('permanent_address')
|
|
->label('Địa chỉ thường trú / Trụ sở')
|
|
->required()
|
|
->suffixAction(
|
|
Action::make('clone_to_contact')
|
|
->label('Copy sang liên hệ')
|
|
->icon('heroicon-m-arrow-right-start-on-rectangle')
|
|
->action(function (Set $set, $state) {
|
|
$set('contact_address', $state);
|
|
})
|
|
),
|
|
TextInput::make('contact_address')
|
|
->label('Địa chỉ liên hệ')
|
|
->required(),
|
|
]),
|
|
|
|
Section::make('Thông tin bổ sung')
|
|
->columns(3)
|
|
->visible(fn ($get) => $get('type') === 'INDIVIDUAL')
|
|
->schema([
|
|
DatePicker::make('dob')->label('Ngày sinh'),
|
|
DatePicker::make('id_issue_date')->label('Ngày cấp CMND'),
|
|
TextInput::make('id_issue_place')->label('Nơi cấp'),
|
|
]),
|
|
]);
|
|
}
|
|
}
|