MIF_E31221305/TA_API/app/Models/Booking.php

105 lines
2.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\TailorRating;
class Booking extends Model
{
use HasFactory;
protected $fillable = [
'customer_id',
'tailor_id',
'transaction_code',
'appointment_date',
'appointment_time',
'service_type',
'category',
'design_photo',
'notes',
'status',
'total_price',
'completion_date',
'payment_status',
'payment_method',
'midtrans_snap_token',
'measurements',
'repair_details',
'repair_photo',
'repair_notes',
'completion_photo',
'completion_notes',
'accepted_at',
'rejected_at',
'completed_at',
'rejection_reason',
'pickup_date'
];
protected $casts = [
'id' => 'integer',
'customer_id' => 'integer',
'tailor_id' => 'integer',
'total_price' => 'decimal:2',
'appointment_date' => 'date',
'appointment_time' => 'datetime:H:i',
'completion_date' => 'date',
'measurements' => 'array',
'repair_details' => 'array',
'accepted_at' => 'datetime',
'rejected_at' => 'datetime',
'completed_at' => 'datetime',
'pickup_date' => 'date'
];
/**
* Get the customer that owns the booking.
*/
public function customer()
{
return $this->belongsTo(User::class, 'customer_id');
}
/**
* Get the tailor that owns the booking.
*/
public function tailor()
{
return $this->belongsTo(User::class, 'tailor_id');
}
/**
* Get the ratings for the booking.
*/
public function ratings()
{
return $this->hasMany(TailorRating::class);
}
/**
* Check if booking can be cancelled
*/
public function canBeCancelled()
{
return $this->status === 'reservasi';
}
/**
* Check if booking can be processed
*/
public function canBeProcessed()
{
return $this->status === 'reservasi' && $this->payment_status === 'paid';
}
/**
* Check if booking can be marked as completed
*/
public function canBeCompleted()
{
return $this->status === 'diproses';
}
}