Version 2.0
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Contracts;
|
||||
|
||||
use App\Enums\ContractCategory;
|
||||
use App\Filament\Resources\Contracts\Pages\CreateContract;
|
||||
use App\Filament\Resources\Contracts\Pages\EditContract;
|
||||
use App\Filament\Resources\Contracts\Pages\ListContracts;
|
||||
@@ -64,7 +65,6 @@ class ContractResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
// GlobalSearch customization
|
||||
public static function getGlobalSearchEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getGlobalSearchEloquentQuery()
|
||||
@@ -89,6 +89,7 @@ class ContractResource extends Resource
|
||||
return [
|
||||
__('app.product') => $record->product?->name ?? '-',
|
||||
__('app.widget_customer') => $record->customer?->name ?? '-',
|
||||
__('enums.contract_category_label') => ContractCategory::from($record->category)->label(),
|
||||
__('app.blade_status') => \App\Enums\ContractStatus::from($record->status)->label(),
|
||||
__('app.signed_status') => $record->signed_status ?? '-',
|
||||
];
|
||||
|
||||
@@ -3,9 +3,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
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
|
||||
@@ -16,4 +18,32 @@ class EditContract extends EditRecord
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Contracts\Schemas;
|
||||
|
||||
use App\Enums\ContractCategory;
|
||||
use App\Enums\ContractStatus;
|
||||
use App\Enums\ContractType;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
@@ -16,6 +17,36 @@ class ContractForm
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make(__('app.contract_category_section'))
|
||||
->schema([
|
||||
Select::make('category')
|
||||
->label(__('enums.contract_category_label'))
|
||||
->options(ContractCategory::options())
|
||||
->required()
|
||||
->native(false)
|
||||
->live(),
|
||||
Select::make('type')
|
||||
->label(__('enums.contract_type_label'))
|
||||
->options(function ($get): array {
|
||||
$category = $get('category');
|
||||
if ($category === 'ownership') {
|
||||
return collect(ContractType::ownershipCases())->mapWithKeys(fn ($c) => [
|
||||
$c->value => $c->label(),
|
||||
])->toArray();
|
||||
}
|
||||
if ($category === 'business') {
|
||||
return collect(ContractType::businessCases())->mapWithKeys(fn ($c) => [
|
||||
$c->value => $c->label(),
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
return ContractType::options();
|
||||
})
|
||||
->required()
|
||||
->native(false),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make(__('app.contract_info'))
|
||||
->schema([
|
||||
Select::make('product_id')
|
||||
@@ -28,11 +59,6 @@ class ContractForm
|
||||
->relationship('customer', 'name')
|
||||
->searchable()
|
||||
->required(),
|
||||
Select::make('type')
|
||||
->label(__('app.contract'))
|
||||
->options(ContractType::options())
|
||||
->required()
|
||||
->native(false),
|
||||
Select::make('status')
|
||||
->label(__('app.status'))
|
||||
->options(ContractStatus::ACTIVE->options())
|
||||
@@ -50,6 +76,22 @@ class ContractForm
|
||||
->maxLength(255),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make(__('app.representative_info'))
|
||||
->description(__('app.representative_desc'))
|
||||
->schema([
|
||||
TextInput::make('representative_name')
|
||||
->label(__('app.name'))
|
||||
->maxLength(255),
|
||||
TextInput::make('representative_phone')
|
||||
->label(__('app.phone'))
|
||||
->maxLength(20),
|
||||
TextInput::make('representative_email')
|
||||
->label(__('app.email'))
|
||||
->email()
|
||||
->maxLength(255),
|
||||
])
|
||||
->columns(3),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace App\Filament\Resources\Contracts\Tables;
|
||||
|
||||
use App\Enums\ContractCategory;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ContractsTable
|
||||
@@ -17,15 +19,25 @@ class ContractsTable
|
||||
TextColumn::make('id')
|
||||
->sortable(),
|
||||
TextColumn::make('product.name')
|
||||
->label(__('app.product'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('customer.name')
|
||||
->label(__('app.widget_customer'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('type')
|
||||
TextColumn::make('category')
|
||||
->label(__('enums.contract_category_label'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state): string => \App\Enums\ContractType::from($state)->label()),
|
||||
->formatStateUsing(fn (string $state): string => ContractCategory::from($state)->label())
|
||||
->color(fn (string $state): string => ContractCategory::from($state)->color()),
|
||||
TextColumn::make('type')
|
||||
->label(__('enums.contract_type_label'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state): string => \App\Enums\ContractType::from($state)->label())
|
||||
->color(fn (string $state): string => \App\Enums\ContractType::from($state)->color()),
|
||||
TextColumn::make('status')
|
||||
->label(__('app.status'))
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'active' => 'success',
|
||||
@@ -34,15 +46,22 @@ class ContractsTable
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn (string $state): string => \App\Enums\ContractStatus::from($state)->label()),
|
||||
TextColumn::make('representative_name')
|
||||
->label(__('app.representative'))
|
||||
->placeholder('-')
|
||||
->toggleable(),
|
||||
TextColumn::make('start_date')
|
||||
->label(__('app.start_date'))
|
||||
->date()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
TextColumn::make('end_date')
|
||||
->label(__('app.end_date'))
|
||||
->date()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
TextColumn::make('signed_status')
|
||||
->label(__('app.signed_status'))
|
||||
->toggleable(),
|
||||
TextColumn::make('feedbacks_count')
|
||||
->counts('feedbacks')
|
||||
@@ -53,7 +72,12 @@ class ContractsTable
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
SelectFilter::make('category')
|
||||
->label(__('enums.contract_category_label'))
|
||||
->options(ContractCategory::options()),
|
||||
SelectFilter::make('status')
|
||||
->label(__('app.status'))
|
||||
->options(\App\Enums\ContractStatus::ACTIVE->options()),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
|
||||
Reference in New Issue
Block a user