fd3a195453
Access group (Filament):
- StaffResource: manage users with an admin-tier role, gated by manage_staff
- CustomerResource: read-only view of role-less users, gated by view_customers
- RoleResource: edit permissions per role (fixed role set), gated by manage_roles
- ManageAppSettings: tabbed General/Booking settings page that reads/writes
real .env keys via new EnvFileWriter (no parallel DB settings table, so
BookingService/config('booking.*') stay unchanged)
- Moved Access above Catalog in the nav group order
- New permissions: manage_staff, manage_roles, view_customers, manage_settings
Booking soft deletes:
- bookings.deleted_at + SoftDeletes on the Booking model
- BookingPolicy::delete (manage_bookings, cancelled/expired only) and
::restore (manage_bookings)
- DeleteBookingTableAction/RestoreBookingTableAction + TrashedFilter on
BookingsTable, using authorize() so the policy is enforced at call time,
not just cosmetically hidden
Refund crash fix:
- ProcessRefundAction passed a nullable $payment->booking into
RefundBookingAction's non-nullable Booking param — a soft-deleted
booking's payment reaching the refund picker was an uncaught TypeError.
Excluded such payments from the picker and added a defensive guard.
- Same unguarded $event->payment->booking / $event->refund->payment->booking
pattern fixed in the MarkBookingPaid/MarkBookingRefunded queued listeners.
289 tests passing.
111 lines
2.9 KiB
PHP
111 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Booking\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Modules\Booking\Database\Factories\BookingFactory;
|
|
use Modules\Booking\Enums\BookingChannel;
|
|
use Modules\Booking\Enums\BookingStatus;
|
|
use Modules\Catalog\Models\DepartureTimeSlot;
|
|
use Modules\Payment\Models\Payment;
|
|
use Modules\Routing\Models\EvRoute;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
|
|
class Booking extends Model
|
|
{
|
|
/** @use HasFactory<BookingFactory> */
|
|
use HasFactory, LogsActivity, SoftDeletes;
|
|
|
|
/**
|
|
* Audit trail on status transitions and driver/vehicle assignment only —
|
|
* not every column (domain.md §6, §5a; T6.2).
|
|
*/
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['status', 'driver_name', 'driver_phone', 'car_plate_number', 'car_model'])
|
|
->logOnlyDirty()
|
|
->dontLogEmptyChanges()
|
|
->useLogName('booking');
|
|
}
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'booking_ref',
|
|
'user_id',
|
|
'openid',
|
|
'ev_route_id',
|
|
'departure_time_slot_id',
|
|
'travel_date',
|
|
'passenger_name',
|
|
'passenger_phone',
|
|
'pickup_address',
|
|
'pickup_lat',
|
|
'pickup_lng',
|
|
'dropoff_address',
|
|
'dropoff_lat',
|
|
'dropoff_lng',
|
|
'price',
|
|
'status',
|
|
'is_round_trip',
|
|
'return_travel_date',
|
|
'created_by_channel',
|
|
'driver_name',
|
|
'driver_phone',
|
|
'car_plate_number',
|
|
'car_model',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'travel_date' => 'date',
|
|
'pickup_lat' => 'decimal:7',
|
|
'pickup_lng' => 'decimal:7',
|
|
'dropoff_lat' => 'decimal:7',
|
|
'dropoff_lng' => 'decimal:7',
|
|
'price' => 'decimal:2',
|
|
'status' => BookingStatus::class,
|
|
'is_round_trip' => 'boolean',
|
|
'return_travel_date' => 'date',
|
|
'created_by_channel' => BookingChannel::class,
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function route(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EvRoute::class, 'ev_route_id');
|
|
}
|
|
|
|
public function timeSlot(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DepartureTimeSlot::class, 'departure_time_slot_id');
|
|
}
|
|
|
|
public function vehicleOptions(): HasMany
|
|
{
|
|
return $this->hasMany(BookingVehicleOption::class);
|
|
}
|
|
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(Payment::class);
|
|
}
|
|
}
|