Fix payment amount editable + discount live recalculation

- 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>
This commit is contained in:
2026-09-08 07:41:02 +00:00
parent 7c0c728347
commit 116495ce0b
2 changed files with 23 additions and 6 deletions
@@ -28,11 +28,9 @@ class PaymentsRelationManager extends RelationManager
Forms\Components\TextInput::make('amount')
->label(__('Sumă'))
->numeric()
->required()
->default(function (RelationManager $livewire): float {
$wo = $livewire->getOwnerRecord();
return max(0.0, (float) $wo->total - $wo->paidAmount());
}),
->minValue(0.01)
->step(0.01)
->required(),
Forms\Components\Select::make('method')
->options(\App\Support\I18n::opts(Payment::METHODS))
->default('cash')
@@ -59,6 +57,12 @@ class PaymentsRelationManager extends RelationManager
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;