Stage 3 — WO photos + ETA + QR + public tracking page
- HasMedia (Spatie) on WorkOrder with `photos` collection
- eta_at + tracking_token columns; token auto-generated on create
- Public /t/{token} page — tenant-scoped via subdomain, white-label themed
- QR code SVG via chillerlan/php-qrcode (inline modal + download)
- Filament: SpatieMediaLibraryFileUpload + ETA picker + tracking section
- EditWorkOrder header action "Link client (QR)" modal
- Fix: Auditable::dontSubmitEmptyLogs() → dontLogEmptyChanges() (removed in activitylog)
- Tests: TrackingPageTest (4 pass) covering token gen + cross-tenant isolation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,35 @@ class WorkOrderResource extends Resource
|
||||
Forms\Components\Textarea::make('diagnosis')->label('Diagnostic')->rows(3)->columnSpanFull(),
|
||||
Forms\Components\Textarea::make('recommendations')->label('Recomandări')->rows(2)->columnSpanFull(),
|
||||
]),
|
||||
Schemas\Components\Section::make('Foto')
|
||||
->collapsible()
|
||||
->schema([
|
||||
\Filament\Forms\Components\SpatieMediaLibraryFileUpload::make('photos')
|
||||
->label('Fotografii')
|
||||
->collection('photos')
|
||||
->multiple()
|
||||
->reorderable()
|
||||
->image()
|
||||
->imageEditor()
|
||||
->maxFiles(20)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Schemas\Components\Section::make('Tracking & ETA')
|
||||
->columns(3)
|
||||
->collapsible()
|
||||
->schema([
|
||||
Forms\Components\DateTimePicker::make('eta_at')
|
||||
->label('Gata estimat (ETA)')
|
||||
->seconds(false),
|
||||
Forms\Components\TextInput::make('tracking_token')
|
||||
->label('Token public')
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->columnSpan(2)
|
||||
->helperText(fn (?WorkOrder $record) => $record?->tracking_token
|
||||
? 'Link client: ' . $record->trackingUrl()
|
||||
: 'Se generează la salvare'),
|
||||
]),
|
||||
Schemas\Components\Section::make('Plată & total')
|
||||
->columns(3)
|
||||
->schema([
|
||||
|
||||
@@ -15,6 +15,16 @@ class EditWorkOrder extends EditRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('tracking')
|
||||
->label('Link client (QR)')
|
||||
->icon('heroicon-m-qr-code')
|
||||
->color('primary')
|
||||
->modalHeading(fn () => 'Tracking client — WO #' . $this->record->number)
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Închide')
|
||||
->modalContent(fn () => view('filament.tenant.tracking-qr', [
|
||||
'wo' => $this->record,
|
||||
])),
|
||||
Actions\Action::make('pdf')
|
||||
->label('Descarcă PDF')
|
||||
->icon('heroicon-m-document-arrow-down')
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use App\Tenancy\TenantManager;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class TrackingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Public WO tracking page — accessed via QR code or SMS link.
|
||||
* Tenant is resolved by ResolveTenant from the host, so the global
|
||||
* BelongsToTenant scope already filters to the correct tenant.
|
||||
*/
|
||||
public function show(Request $request, string $token)
|
||||
{
|
||||
$tenant = app(TenantManager::class)->current();
|
||||
if (! $tenant) {
|
||||
throw new NotFoundHttpException('Tracking only available on tenant subdomain.');
|
||||
}
|
||||
|
||||
$wo = WorkOrder::with(['client', 'vehicle', 'master', 'media'])
|
||||
->where('tracking_token', $token)
|
||||
->first();
|
||||
|
||||
if (! $wo) {
|
||||
throw new NotFoundHttpException('Fișa nu a fost găsită.');
|
||||
}
|
||||
|
||||
return view('tracking.show', [
|
||||
'wo' => $wo,
|
||||
'tenant' => $tenant,
|
||||
'photos' => $wo->getMedia('photos'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function qr(Request $request, string $token)
|
||||
{
|
||||
$tenant = app(TenantManager::class)->current();
|
||||
if (! $tenant) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
$wo = WorkOrder::where('tracking_token', $token)->first();
|
||||
if (! $wo) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$options = new \chillerlan\QRCode\QROptions([
|
||||
'outputType' => \chillerlan\QRCode\QRCode::OUTPUT_MARKUP_SVG,
|
||||
'eccLevel' => \chillerlan\QRCode\QRCode::ECC_M,
|
||||
'scale' => 6,
|
||||
'imageBase64' => false,
|
||||
'svgViewBoxSize' => 200,
|
||||
'addQuietzone' => true,
|
||||
]);
|
||||
|
||||
$svg = (new \chillerlan\QRCode\QRCode($options))->render($wo->trackingUrl());
|
||||
|
||||
return response($svg, 200, [
|
||||
'Content-Type' => 'image/svg+xml',
|
||||
'Cache-Control' => 'public, max-age=3600',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ trait Auditable
|
||||
return LogOptions::defaults()
|
||||
->logFillable()
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs()
|
||||
->dontLogEmptyChanges()
|
||||
->setDescriptionForEvent(fn (string $event) => match ($event) {
|
||||
'created' => 'creat',
|
||||
'updated' => 'modificat',
|
||||
|
||||
@@ -8,10 +8,12 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class WorkOrder extends Model
|
||||
class WorkOrder extends Model implements HasMedia
|
||||
{
|
||||
use Auditable, BelongsToTenant, SoftDeletes;
|
||||
use Auditable, BelongsToTenant, InteractsWithMedia, SoftDeletes;
|
||||
|
||||
public const STATUSES = [
|
||||
'new' => 'Nou',
|
||||
@@ -38,17 +40,29 @@ class WorkOrder extends Model
|
||||
'complaint', 'diagnosis', 'recommendations',
|
||||
'status', 'pay_status', 'approved', 'approved_at',
|
||||
'discount_pct', 'total',
|
||||
'eta_at', 'tracking_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'opened_at' => 'date',
|
||||
'closed_at' => 'date',
|
||||
'approved_at' => 'datetime',
|
||||
'eta_at' => 'datetime',
|
||||
'approved' => 'boolean',
|
||||
'discount_pct' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection('photos');
|
||||
}
|
||||
|
||||
public function trackingUrl(): string
|
||||
{
|
||||
return url('/t/' . $this->tracking_token);
|
||||
}
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
@@ -112,6 +126,12 @@ class WorkOrder extends Model
|
||||
/** Auto-send 'ready' email + broadcast WS event on status change. */
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $wo) {
|
||||
if (empty($wo->tracking_token)) {
|
||||
$wo->tracking_token = \Illuminate\Support\Str::random(24);
|
||||
}
|
||||
});
|
||||
|
||||
static::updated(function (self $wo) {
|
||||
if (
|
||||
$wo->wasChanged('status')
|
||||
|
||||
Reference in New Issue
Block a user