137 lines
4.2 KiB
PHP
Raw Permalink Normal View History

2025-01-24 21:37:05 -05:00
<?php
namespace App\Filament\Admin\Resources;
2025-02-18 20:13:54 -05:00
use App\Enums\IconEnum;
use App\Filament\Admin\Resources\InvoiceResource\Pages\ListInvoices;
2025-01-24 21:37:05 -05:00
use App\Filament\Admin\Resources\PaymentResource\Pages;
2025-02-18 20:13:54 -05:00
use App\Filament\Admin\Resources\PaymentResource\RelationManagers\InvoicesRelationManager;
2025-01-24 21:37:05 -05:00
use App\Models\Payment;
2025-02-18 20:13:54 -05:00
use Filament\Forms\Components\DatePicker;
2025-01-24 21:37:05 -05:00
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class PaymentResource extends Resource
{
protected static ?string $model = Payment::class;
2025-02-18 20:13:54 -05:00
protected static ?string $navigationIcon = IconEnum::PAYMENTS->value;
2025-01-24 21:37:05 -05:00
protected static ?string $navigationGroup = 'Financial';
protected static ?int $navigationSort = 2;
public static function form(Form $form): Form
{
return $form
->schema([
Section::make([
2025-02-18 20:13:54 -05:00
DatePicker::make('date')
->default(today())
->columnSpan(2),
2025-01-24 21:37:05 -05:00
Select::make('customer_id')
->relationship('customer', 'company_name')
->required()
->searchable()
2025-02-18 20:13:54 -05:00
->hidden(fn ($livewire) => $livewire::class === ListInvoices::class)
->preload()
->columnSpan(2),
2025-01-24 21:37:05 -05:00
TextInput::make('amount')
->required()
2025-02-18 20:13:54 -05:00
->prefix('$')
->rules('numeric')
2025-01-24 21:37:05 -05:00
->minValue(0)
->maxValue(99999999)
2025-02-18 20:13:54 -05:00
->columnSpan(1),
TextInput::make('check_number')
->columnSpan(3),
Textarea::make('notes')
->columnSpan(4),
])->columns(4),
2025-01-24 21:37:05 -05:00
]);
}
2025-02-18 20:13:54 -05:00
public static function table(Table $table, ?bool $showSearchable = true): Table
2025-01-24 21:37:05 -05:00
{
return $table
->columns([
TextColumn::make('created_at')
->label('Date')
->date('Y-m-d')
2025-02-18 20:13:54 -05:00
->searchable($showSearchable),
2025-01-24 21:37:05 -05:00
TextColumn::make('customer.company_name')
2025-02-18 20:13:54 -05:00
->hidden(fn ($livewire) => $livewire::class !== Pages\ListPayments::class)
->searchable($showSearchable),
2025-01-24 21:37:05 -05:00
2025-02-18 20:13:54 -05:00
TextColumn::make('check_number')
->searchable($showSearchable)
2025-01-24 21:37:05 -05:00
->extraHeaderAttributes(['class' => 'w-full']),
TextColumn::make('amount')
2025-02-18 20:13:54 -05:00
->searchable($showSearchable)
->alignRight()
2025-01-24 21:37:05 -05:00
->money(),
TextColumn::make('unapplied_amount')
2025-02-18 20:13:54 -05:00
->searchable($showSearchable)
2025-01-24 21:37:05 -05:00
->label('Balance')
2025-02-18 20:13:54 -05:00
->alignRight()
2025-01-24 21:37:05 -05:00
->money(),
])
->actions([
2025-02-18 20:13:54 -05:00
\Filament\Tables\Actions\EditAction::make(),
]);
}
public static function paymentRelationManagerTable(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->color('primary'),
TextColumn::make('created_at')
->label('Date')
->date('Y-m-d'),
TextColumn::make('check_number')
->extraHeaderAttributes(['class' => 'w-full']),
TextColumn::make('applied_amount')
->alignRight()
->money(),
2025-01-24 21:37:05 -05:00
]);
}
public static function canAccess(): bool
{
2025-02-18 20:13:54 -05:00
return auth()->user()->is_admin ?? false;
2025-01-24 21:37:05 -05:00
}
public static function getRelations(): array
{
return [
2025-02-18 20:13:54 -05:00
InvoicesRelationManager::class,
2025-01-24 21:37:05 -05:00
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPayments::route('/'),
2025-02-18 20:13:54 -05:00
'edit' => Pages\EditPayment::route('/{record}/edit'),
2025-01-24 21:37:05 -05:00
];
}
}