Files
Verde-Web/app/Models/TripTimelineEvent.php
admin 13148fab97 feat(backend): complete Module 10 (trips + timeline)
trips, trip_stops, trip_timeline_events. Admin: schedule/show/cancel.
Driver: start, arrive/depart/skip stops, report incident, arrive at
dumpsite, release load (creates dumpsite_release row + tallies trip
load), complete. Every action writes a typed timeline event with GPS.
Trip number auto-generated TRIP-YYYYMMDD-NNN. Promotes
dumpsite_releases.trip_id to a real FK now that trips exists.

148 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 02:51:52 +08:00

65 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use MatanYadaev\EloquentSpatial\Objects\Point;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
class TripTimelineEvent extends Model
{
use HasFactory, HasSpatial;
public const TYPE_TRIP_STARTED = 'trip_started';
public const TYPE_ARRIVED_AT_STOP = 'arrived_at_stop';
public const TYPE_COLLECTION_STARTED = 'collection_started';
public const TYPE_QR_SCANNED = 'qr_scanned';
public const TYPE_COLLECTION_COMPLETED = 'collection_completed';
public const TYPE_DEPARTED_STOP = 'departed_stop';
public const TYPE_STOP_SKIPPED = 'stop_skipped';
public const TYPE_TRUCK_FULL_WARNING = 'truck_full_warning';
public const TYPE_ARRIVED_AT_DUMPSITE = 'arrived_at_dumpsite';
public const TYPE_LOAD_RELEASED = 'load_released';
public const TYPE_DEPARTED_DUMPSITE = 'departed_dumpsite';
public const TYPE_TRIP_COMPLETED = 'trip_completed';
public const TYPE_INCIDENT_REPORTED = 'incident_reported';
public const TYPE_BREAKDOWN = 'breakdown';
public $timestamps = false;
protected $dateFormat = 'Y-m-d H:i:s';
protected $fillable = [
'trip_id', 'event_type', 'event_at', 'coordinates',
'recorded_by_user_id', 'related_type', 'related_id',
'metadata', 'notes', 'created_at',
];
protected function casts(): array
{
return [
'event_at' => 'datetime',
'created_at' => 'datetime',
'coordinates' => Point::class,
'metadata' => 'array',
];
}
public function trip(): BelongsTo
{
return $this->belongsTo(Trip::class);
}
public function recordedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'recorded_by_user_id');
}
public function related(): MorphTo
{
return $this->morphTo();
}
}