117 lines
4.5 KiB
PHP
117 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Contracts\Tables;
|
|
|
|
use App\Models\Contract;
|
|
use App\Services\ContractScheduleService;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ForceDeleteAction;
|
|
use Filament\Actions\RestoreAction;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\TrashedFilter;
|
|
use Filament\Tables\Table;
|
|
|
|
class ContractsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('contract_number')
|
|
->label('Số HĐMB')
|
|
->searchable()
|
|
->sortable()
|
|
->copyable()
|
|
->description(fn ($record) => "Lô: {$record->product?->code}"),
|
|
|
|
TextColumn::make('customers.full_name')
|
|
->label('Khách hàng')
|
|
->searchable()
|
|
->listWithLineBreaks()
|
|
->bulleted(),
|
|
|
|
TextColumn::make('signing_date')
|
|
->label('Ngày ký')
|
|
->date('d/m/Y')
|
|
->sortable(),
|
|
|
|
TextColumn::make('total_value')
|
|
->label('Giá trị HĐ')
|
|
->money('VND')
|
|
->sortable()
|
|
->summarize(\Filament\Tables\Columns\Summarizers\Sum::make()->label('Tổng doanh thu')->money('VND')),
|
|
|
|
TextColumn::make('transfer_order')
|
|
->label('Đời CN')
|
|
->badge()
|
|
->color(fn ($state) => $state == 0 ? 'success' : 'gray')
|
|
->formatStateUsing(fn ($state) => $state == 0 ? 'Hiện tại' : "F{$state}")
|
|
->alignCenter(),
|
|
|
|
TextColumn::make('status')
|
|
->label('Trạng thái')
|
|
->badge()
|
|
->color(fn (string $state): string => match ($state) {
|
|
'Đang hiệu lực' => 'success',
|
|
'Đã hoàn thành' => 'primary',
|
|
'Đã hủy' => 'danger',
|
|
default => 'gray',
|
|
}),
|
|
|
|
TextColumn::make('paid_amount')
|
|
->label('Đã thu')
|
|
->money('VND')
|
|
->sortable()
|
|
->toggleable(),
|
|
|
|
TextColumn::make('remaining_amount')
|
|
->label('Còn lại')
|
|
->money('VND')
|
|
->sortable()
|
|
->color('danger')
|
|
->toggleable(),
|
|
])
|
|
->filters([
|
|
\Filament\Tables\Filters\SelectFilter::make('status')
|
|
->label('Trạng thái')
|
|
->options([
|
|
'Đang hiệu lực' => 'Đang hiệu lực',
|
|
'Đã hoàn thành' => 'Đã hoàn thành',
|
|
'Đã hủy' => 'Đã hủy',
|
|
]),
|
|
\Filament\Tables\Filters\TernaryFilter::make('is_current')
|
|
->label('Chủ sở hữu hiện tại')
|
|
->queries(
|
|
true: fn ($query) => $query->where('transfer_order', 0),
|
|
false: fn ($query) => $query->where('transfer_order', '>', 0),
|
|
),
|
|
TrashedFilter::make(),
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
RestoreAction::make(),
|
|
ForceDeleteAction::make(),
|
|
Action::make('generateSchedule')
|
|
->label('Tạo lịch TT')
|
|
->icon('heroicon-o-calendar-days')
|
|
->color('warning')
|
|
->requiresConfirmation()
|
|
->modalHeading('Tạo lịch thanh toán')
|
|
->modalDescription('Hành động này sẽ xóa lịch thanh toán cũ (nếu có) và tạo lại từ mẫu của dự án.')
|
|
->action(function (Contract $record) {
|
|
ContractScheduleService::generateFromTemplate($record);
|
|
})
|
|
->visible(fn (Contract $record) => $record->signing_date !== null),
|
|
])
|
|
->bulkActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->defaultSort('created_at', 'desc');
|
|
}
|
|
}
|