50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Contracts\Pages;
|
|
|
|
use App\Filament\Resources\Contracts\ContractResource;
|
|
use App\Models\Contract;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditContract extends EditRecord
|
|
{
|
|
protected static string $resource = ContractResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
DeleteAction::make(),
|
|
];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeSave(array $data): array
|
|
{
|
|
if (($data['status'] ?? '') === 'active') {
|
|
$existing = Contract::where('product_id', $data['product_id'])
|
|
->where('category', $data['category'])
|
|
->where('status', 'active')
|
|
->where('id', '!=', $this->getRecord()->id)
|
|
->first();
|
|
|
|
if ($existing) {
|
|
Notification::make()
|
|
->title(__('feedback.contract_duplicate_title', [
|
|
'category' => \App\Enums\ContractCategory::from($data['category'])->label(),
|
|
]))
|
|
->body(__('feedback.contract_duplicate_body', [
|
|
'product' => $existing->product?->name ?? '?',
|
|
'customer' => $existing->customer?->name ?? '?',
|
|
]))
|
|
->warning()
|
|
->send();
|
|
|
|
$this->halt();
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|