'date', 'start_time' => 'datetime', 'end_time' => 'datetime', 'hours_worked' => 'decimal:2', 'break_hours' => 'decimal:2', 'billable_hours' => 'decimal:2', 'hourly_rate' => 'decimal:2', 'total_amount' => 'decimal:2', 'approved_at' => 'datetime', 'is_overtime' => 'boolean', 'overtime_multiplier' => 'decimal:2', ]; public function jobCard(): BelongsTo { return $this->belongsTo(JobCard::class); } public function workOrder(): BelongsTo { return $this->belongsTo(WorkOrder::class); } public function diagnosis(): BelongsTo { return $this->belongsTo(Diagnosis::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function technician(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public function supervisorApprovedBy(): BelongsTo { return $this->belongsTo(User::class, 'supervisor_approved_by_id'); } public function calculateHours(): void { if ($this->start_time && $this->end_time) { $totalMinutes = $this->end_time->diffInMinutes($this->start_time) - ($this->break_hours ?? 0) * 60; $totalHours = $totalMinutes / 60; // For diagnosis entries, all hours are typically billable $this->hours_worked = $totalHours; $this->billable_hours = $totalHours; $this->total_amount = $this->billable_hours * ($this->hourly_rate ?? 0); } } }