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:
@@ -149,7 +149,20 @@ class WorkOrderResource extends Resource
|
||||
->columns(3)->collapsible()->collapsed()->compact()
|
||||
->schema([
|
||||
Forms\Components\Select::make('pay_status')->options(\App\Support\I18n::opts(WorkOrder::PAY_STATUSES))->default('unpaid')->required(),
|
||||
Forms\Components\TextInput::make('discount_pct')->label(__('Discount %'))->numeric()->default(0),
|
||||
Forms\Components\TextInput::make('discount_pct')
|
||||
->label(__('Discount %'))
|
||||
->numeric()
|
||||
->default(0)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function ($state, callable $set, $record) {
|
||||
if (! $record) return;
|
||||
$works = (float) $record->works()->sum('total');
|
||||
$parts = (float) $record->parts()->sum('total');
|
||||
$sub = (float) $record->subcontractJobs()
|
||||
->where('status', '!=', 'cancelled')->sum('client_price');
|
||||
$disc = min(100, max(0, (float) $state));
|
||||
$set('total', round(($works + $parts + $sub) * (1 - $disc / 100), 2));
|
||||
}),
|
||||
Forms\Components\Toggle::make('apply_margin')
|
||||
->label(__('Aplică marjă internă'))
|
||||
->default(true)
|
||||
|
||||
Reference in New Issue
Block a user