73 lines
3.0 KiB
PHP
73 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Contracts;
|
|
|
|
use App\Filament\Resources\Contracts\Pages;
|
|
use App\Models\Contract;
|
|
use App\Enums\NavigationGroup;
|
|
use App\Services\ContractScheduleService;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use App\Filament\Resources\Contracts\ContractResource\RelationManagers\ScheduleItemsRelationManager;
|
|
use App\Filament\Resources\Contracts\Schemas\ContractForm;
|
|
|
|
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 = NavigationGroup::TRANSACTION->value;
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
protected static ?string $modelLabel = 'Hợp đồng';
|
|
protected static ?string $pluralModelLabel = 'Hợp đồng';
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return ContractForm::configure($schema);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('contract_number')->label('Số HĐ')->searchable(),
|
|
Tables\Columns\TextColumn::make('product.code')->label('Sản phẩm'),
|
|
Tables\Columns\TextColumn::make('total_value')->label('Giá trị')->money('VND'),
|
|
Tables\Columns\TextColumn::make('paid_amount')->label('Đã thu')->money('VND'),
|
|
Tables\Columns\TextColumn::make('remaining_amount')->label('Còn lại')->money('VND'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\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) {
|
|
try {
|
|
ContractScheduleService::generateFromTemplate($record);
|
|
} catch (\InvalidArgumentException $e) {
|
|
// Filament sẽ tự động hiển thị lỗi nếu throw ra trong action
|
|
throw $e;
|
|
}
|
|
})
|
|
->visible(fn (Contract $record) => $record->signing_date !== null),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array { return [ScheduleItemsRelationManager::class]; }
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListContracts::route('/'),
|
|
'create' => Pages\CreateContract::route('/create'),
|
|
'edit' => Pages\EditContract::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|