41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Contracts\Pages;
|
|
|
|
use App\Filament\Resources\Contracts\ContractResource;
|
|
use App\Models\Contract;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateContract extends CreateRecord
|
|
{
|
|
protected static string $resource = ContractResource::class;
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
if (($data['status'] ?? '') === 'active') {
|
|
$existing = Contract::where('product_id', $data['product_id'])
|
|
->where('category', $data['category'])
|
|
->where('status', 'active')
|
|
->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;
|
|
}
|
|
}
|