diff --git a/app/Filament/Tenant/Pages/WorkOrderDashboard.php b/app/Filament/Tenant/Pages/WorkOrderDashboard.php index 9a77806..a977f21 100644 --- a/app/Filament/Tenant/Pages/WorkOrderDashboard.php +++ b/app/Filament/Tenant/Pages/WorkOrderDashboard.php @@ -4,6 +4,7 @@ namespace App\Filament\Tenant\Pages; use App\Models\Tenant\WorkOrder; use Filament\Pages\Page; +use Livewire\WithFileUploads; /** * Mitchell1-style 3-column dashboard view for a single WorkOrder. @@ -12,6 +13,8 @@ use Filament\Pages\Page; */ class WorkOrderDashboard extends Page { + use WithFileUploads; + protected static string|\BackedEnum|null $navigationIcon = null; protected static bool $shouldRegisterNavigation = false; @@ -191,6 +194,32 @@ class WorkOrderDashboard extends Page ->get(); } + public array $newPhotos = []; + + public function uploadPhotos(): void + { + $this->validate(['newPhotos.*' => 'image|max:15360']); + foreach ($this->newPhotos as $photo) { + $this->record->addMedia($photo->getRealPath()) + ->usingFileName($photo->getClientOriginalName()) + ->toMediaCollection('photos'); + } + $this->newPhotos = []; + $this->record->refresh(); + \Filament\Notifications\Notification::make() + ->title(__('Fotografii adăugate')) + ->success()->send(); + } + + public function deletePhoto(int $mediaId): void + { + $media = $this->record->getMedia('photos')->firstWhere('id', $mediaId); + if ($media && (int) $media->model_id === $this->record->id) { + $media->delete(); + $this->record->refresh(); + } + } + public string $newMessage = ''; public function sendMessage(): void diff --git a/app/Filament/Tenant/Resources/WorkOrderResource.php b/app/Filament/Tenant/Resources/WorkOrderResource.php index f42fb49..b572138 100644 --- a/app/Filament/Tenant/Resources/WorkOrderResource.php +++ b/app/Filament/Tenant/Resources/WorkOrderResource.php @@ -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)')) diff --git a/app/Filament/Tenant/Resources/WorkOrderResource/Pages/EditWorkOrder.php b/app/Filament/Tenant/Resources/WorkOrderResource/Pages/EditWorkOrder.php index b72d520..7a2d0ff 100644 --- a/app/Filament/Tenant/Resources/WorkOrderResource/Pages/EditWorkOrder.php +++ b/app/Filament/Tenant/Resources/WorkOrderResource/Pages/EditWorkOrder.php @@ -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(); } diff --git a/resources/views/filament/tenant/pages/work-order-dashboard.blade.php b/resources/views/filament/tenant/pages/work-order-dashboard.blade.php index cb18c56..cc8079a 100644 --- a/resources/views/filament/tenant/pages/work-order-dashboard.blade.php +++ b/resources/views/filament/tenant/pages/work-order-dashboard.blade.php @@ -696,12 +696,34 @@ {{-- ── PHOTOS TAB ── --}}