116495ce0b
- PaymentsRelationManager: remove broken default() closure on amount; use fillForm() on CreateAction instead (correct Filament API) so the modal pre-fills with remaining balance (total - paid) but field stays fully editable; add minValue/step for numeric UX - WorkOrderResource: discount_pct is now live(onBlur) with afterStateUpdated that recomputes works+parts+subcontract minus discount and sets the total field immediately — no Save required to see the effect Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83 lines
3.4 KiB
PHP
83 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources\WorkOrderResource\RelationManagers;
|
|
|
|
use App\Models\Tenant\Payment;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class PaymentsRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'payments';
|
|
|
|
protected static ?string $title = null;
|
|
|
|
public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
|
|
{
|
|
return __('Plăți');
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Forms\Components\DatePicker::make('paid_at')->label(__('Data'))->default(today())->required(),
|
|
Forms\Components\TextInput::make('amount')
|
|
->label(__('Sumă'))
|
|
->numeric()
|
|
->minValue(0.01)
|
|
->step(0.01)
|
|
->required(),
|
|
Forms\Components\Select::make('method')
|
|
->options(\App\Support\I18n::opts(Payment::METHODS))
|
|
->default('cash')
|
|
->required(),
|
|
Forms\Components\TextInput::make('reference')->label(__('Referință'))->maxLength(64),
|
|
Forms\Components\Textarea::make('notes')->label(__('Notițe'))->columnSpanFull()->rows(2),
|
|
]);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('amount')
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('paid_at')->label(__('Data'))->date('d.m.Y'),
|
|
Tables\Columns\TextColumn::make('amount')->money('MDL')->alignRight()
|
|
->summarize(Tables\Columns\Summarizers\Sum::make()->money('MDL')->label(__('Plătit'))),
|
|
Tables\Columns\TextColumn::make('method')
|
|
->formatStateUsing(fn ($s) => __(Payment::METHODS[$s] ?? $s))
|
|
->badge(),
|
|
Tables\Columns\TextColumn::make('reference')->placeholder('—'),
|
|
])
|
|
->headerActions([
|
|
Actions\CreateAction::make()
|
|
->label(__('Adaugă plată'))
|
|
->modalHeading(__('Adaugă plată la fișă'))
|
|
->fillForm(function (RelationManager $livewire): array {
|
|
$wo = $livewire->getOwnerRecord();
|
|
return [
|
|
'amount' => max(0.0, round((float) $wo->total - $wo->paidAmount(), 2)),
|
|
];
|
|
})
|
|
->mutateFormDataUsing(function (array $data, RelationManager $livewire): array {
|
|
$wo = $livewire->getOwnerRecord();
|
|
$data['client_id'] = $wo->client_id;
|
|
$data['user_id'] = auth()->id();
|
|
return $data;
|
|
}),
|
|
])
|
|
->actions([
|
|
Actions\EditAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
])
|
|
->emptyStateHeading(__('Nicio plată'))
|
|
->emptyStateDescription(__('Adaugă plățile parțiale sau totale primite pentru această fișă. Statusul plății se actualizează automat.'))
|
|
->emptyStateIcon('heroicon-o-banknotes')
|
|
->defaultSort('paid_at', 'desc');
|
|
}
|
|
}
|