Init: Hoan thanh kien truc V3 va Filament UI
This commit is contained in:
82
app/Filament/Resources/Contracts/ContractResource.php
Normal file
82
app/Filament/Resources/Contracts/ContractResource.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Contracts;
|
||||
|
||||
use App\Filament\Resources\Contracts\Pages;
|
||||
use App\Models\Contract;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ContractResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Contract::class;
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document-text';
|
||||
protected static string | \UnitEnum | null $navigationGroup = 'Quản lý Giao dịch';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Thông tin Liên kết')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('product_id')->label('Mã Sản phẩm')->relationship('product', 'code')->searchable()->preload()->required(),
|
||||
Select::make('customers')->label('Khách hàng')->relationship('customers', 'full_name')->multiple()->searchable()->preload()->required(),
|
||||
]),
|
||||
Section::make('Chi tiết Hợp đồng')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('contract_number')->label('Số Hợp đồng')->required()->unique(ignoreRecord: true),
|
||||
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' => 'VBCN'])->default('HĐMB'),
|
||||
DatePicker::make('signing_date')->label('Ngày ký')->displayFormat('d/m/Y'),
|
||||
TextInput::make('transfer_order')->label('Thứ tự chuyển nhượng')->numeric()->default(0),
|
||||
Select::make('status')->label('Trạng thái')
|
||||
->options(['Đang hiệu lực' => 'Đang hiệu lực', 'Đã thanh lý' => 'Đã thanh lý', 'Đã chuyển nhượng' => 'Đã chuyển nhượng'])
|
||||
->default('Đang hiệu lực'),
|
||||
]),
|
||||
Section::make('Tài chính')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('total_value')->label('Tổng giá trị (VND)')->numeric()->required(),
|
||||
TextInput::make('paid_amount')->label('Đã thanh toán (VND)')->numeric()->default(0),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('contract_number')->label('Số HĐ')->searchable(),
|
||||
Tables\Columns\TextColumn::make('contract_type')->label('Loại HĐ')->badge(),
|
||||
Tables\Columns\TextColumn::make('product.code')->label('Mã SP')->searchable(),
|
||||
Tables\Columns\TextColumn::make('customers.full_name')->label('Khách hàng')->badge(),
|
||||
Tables\Columns\TextColumn::make('status')->label('Trạng thái')
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'Đang hiệu lực' => 'success',
|
||||
'Đã thanh lý' => 'warning',
|
||||
'Đã chuyển nhượng' => 'gray',
|
||||
default => 'gray',
|
||||
})->badge(),
|
||||
Tables\Columns\TextColumn::make('total_value')->label('Tổng giá trị')->money('VND'),
|
||||
Tables\Columns\TextColumn::make('paid_amount')->label('Đã TT')->money('VND'),
|
||||
Tables\Columns\TextColumn::make('remaining_amount')->label('Còn lại')->money('VND')->color('danger'),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListContracts::route('/'),
|
||||
'create' => Pages\CreateContract::route('/create'),
|
||||
'edit' => Pages\EditContract::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user