Kimi chinh sua
This commit is contained in:
@@ -4,16 +4,12 @@ namespace App\Filament\Resources\Customers;
|
||||
|
||||
use App\Filament\Resources\Customers\Pages;
|
||||
use App\Models\Customer;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Fieldset;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
use App\Enums\NavigationGroup;
|
||||
use App\Filament\Resources\Customers\Schemas\CustomerForm;
|
||||
use App\Filament\Resources\Customers\Tables\CustomersTable;
|
||||
|
||||
class CustomerResource extends Resource
|
||||
{
|
||||
@@ -22,47 +18,17 @@ class CustomerResource extends Resource
|
||||
protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::CUSTOMER->value;
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $modelLabel = 'Khách hàng';
|
||||
protected static ?string $pluralModelLabel = 'Khách hàng';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Thông tin định danh')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('full_name')->label('Họ và Tên')->required(),
|
||||
TextInput::make('cmnd_cccd')->label('Số CMND / CCCD')->required()->unique(ignoreRecord: true),
|
||||
DatePicker::make('dob')->label('Ngày sinh')->displayFormat('d/m/Y'),
|
||||
]),
|
||||
Section::make('Thông liên lạc')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('phone')->label('Số điện thoại')->tel()->required(),
|
||||
TextInput::make('email')->label('Email')->email(),
|
||||
]),
|
||||
Section::make('Địa chỉ chi tiết')
|
||||
->schema([
|
||||
Fieldset::make('address')
|
||||
->label('Cấu trúc địa chỉ')->columns(3)
|
||||
->schema([
|
||||
TextInput::make('address.street')->label('Số nhà, đường')->columnSpan(3),
|
||||
TextInput::make('address.ward')->label('Phường / Xã'),
|
||||
TextInput::make('address.district')->label('Quận / Huyện'),
|
||||
TextInput::make('address.city')->label('Tỉnh / Thành phố'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
return CustomerForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('full_name')->label('Họ Tên')->searchable(),
|
||||
Tables\Columns\TextColumn::make('cmnd_cccd')->label('CMND/CCCD')->searchable(),
|
||||
Tables\Columns\TextColumn::make('phone')->label('Điện thoại'),
|
||||
Tables\Columns\TextColumn::make('address.city')->label('Tỉnh/Thành')->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
return CustomersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
|
||||
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\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\TagsInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
|
||||
class CustomerForm
|
||||
{
|
||||
@@ -12,20 +18,75 @@ class CustomerForm
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('full_name')
|
||||
->required(),
|
||||
TextInput::make('cmnd_cccd')
|
||||
->required(),
|
||||
TextInput::make('phone')
|
||||
->tel(),
|
||||
TextInput::make('email')
|
||||
->label('Email address')
|
||||
->email(),
|
||||
TextInput::make('address_permanent'),
|
||||
TextInput::make('address_contact'),
|
||||
DatePicker::make('dob'),
|
||||
DatePicker::make('id_issue_date'),
|
||||
TextInput::make('id_issue_place'),
|
||||
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'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CustomersTable
|
||||
@@ -14,45 +15,60 @@ class CustomersTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('ID'),
|
||||
TextColumn::make('full_name')
|
||||
->searchable(),
|
||||
TextColumn::make('cmnd_cccd')
|
||||
->searchable(),
|
||||
TextColumn::make('phone')
|
||||
->searchable(),
|
||||
TextColumn::make('email')
|
||||
->label('Email address')
|
||||
->searchable(),
|
||||
TextColumn::make('address_permanent')
|
||||
->searchable(),
|
||||
TextColumn::make('address_contact')
|
||||
->searchable(),
|
||||
TextColumn::make('dob')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('id_issue_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('id_issue_place')
|
||||
->searchable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->label('Họ tên / Công ty')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->description(fn ($record) => $get_desc = $record->type === 'COMPANY' ? "ĐD: {$record->representative?->full_name}" : $record->cmnd_cccd),
|
||||
|
||||
TextColumn::make('type')
|
||||
->label('Loại')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'COMPANY' => 'warning',
|
||||
'INDIVIDUAL' => 'success',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'COMPANY' => 'Công ty',
|
||||
'INDIVIDUAL' => 'Cá nhân',
|
||||
default => $state,
|
||||
}),
|
||||
|
||||
TextColumn::make('phone')
|
||||
->label('Điện thoại')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('permanent_address')
|
||||
->label('Địa chỉ thường trú')
|
||||
->limit(30)
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('contact_address')
|
||||
->label('Địa chỉ liên hệ')
|
||||
->limit(30)
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label('Ngày tạo')
|
||||
->dateTime('d/m/Y')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
\Filament\Tables\Filters\SelectFilter::make('type')
|
||||
->label('Loại khách hàng')
|
||||
->options([
|
||||
'INDIVIDUAL' => 'Cá nhân',
|
||||
'COMPANY' => 'Công ty',
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user