feat: partial payment field + photo upload from dashboard

- WorkOrderResource: pay_status is now live(); added _partial_amount
  TextInput (visible only when pay_status=partial) that shows current
  paid amount and accepts a new total — dehydrated so it does not save
  directly; _achitat hidden when partial is selected to avoid confusion
- EditWorkOrder.afterSave: creates a Payment record for the difference
  when pay_status=partial and entered amount > existing paidAmount
- WorkOrderDashboard: WithFileUploads + uploadPhotos / deletePhoto
  methods using Spatie MediaLibrary
- Dashboard blade: Foto tab replaced with upload form + gallery with
  per-photo delete buttons

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-08 08:16:21 +00:00
parent aa231f4b08
commit 1e7ca0fdfe
4 changed files with 83 additions and 4 deletions
@@ -148,7 +148,7 @@ class WorkOrderResource extends Resource
Schemas\Components\Section::make(__('Plată & total'))
->columns(3)->collapsible()->collapsed()->compact()
->schema([
Forms\Components\Select::make('pay_status')->label(__('Statut plată'))->options(\App\Support\I18n::opts(WorkOrder::PAY_STATUSES))->default('unpaid')->required(),
Forms\Components\Select::make('pay_status')->label(__('Statut plată'))->options(\App\Support\I18n::opts(WorkOrder::PAY_STATUSES))->default('unpaid')->required()->live(),
Forms\Components\TextInput::make('discount_pct')
->label(__('Reducere %'))
->numeric()
@@ -177,10 +177,18 @@ class WorkOrderResource extends Resource
->label(__('Total (MDL)'))
->numeric()->readOnly()->dehydrated(false)
->extraAttributes(['style' => 'font-weight:600']),
Forms\Components\TextInput::make('_partial_amount')
->label(__('Sumă achitată (MDL)'))
->numeric()->minValue(0)->step(0.01)
->dehydrated(false)
->default(fn ($record) => $record ? $record->paidAmount() : 0)
->visible(fn (Get $get) => $get('pay_status') === 'partial')
->helperText(__('Introduceți suma achitată — se înregistrează automat ca plată la salvare')),
Forms\Components\TextInput::make('_achitat')
->label(__('Achitat (MDL)'))
->readOnly()->dehydrated(false)
->default(fn ($record) => $record ? number_format($record->paidAmount(), 2, '.', '') : '0.00')
->visible(fn (Get $get) => $get('pay_status') !== 'partial')
->extraAttributes(['style' => 'color:#16a34a;font-weight:600']),
Forms\Components\TextInput::make('_rest')
->label(__('Rest de achitat (MDL)'))
@@ -31,6 +31,26 @@ class EditWorkOrder extends EditRecord
protected function afterSave(): void
{
$this->record->recalcTotal();
// Create payment for the difference when pay_status = partial
if ($this->record->pay_status === 'partial') {
$entered = (float) ($this->form->getState()['_partial_amount'] ?? 0);
$alreadyPaid = $this->record->paidAmount();
$diff = round($entered - $alreadyPaid, 2);
if ($diff > 0.005) {
\App\Models\Tenant\Payment::create([
'company_id' => $this->record->company_id,
'work_order_id' => $this->record->id,
'client_id' => $this->record->client_id,
'user_id' => auth()->id(),
'amount' => $diff,
'method' => 'cash',
'paid_at' => today(),
]);
$this->record->refresh();
}
}
$this->fillForm();
}