67 lines
1.3 KiB
PHP
67 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class WorkLog extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'employee_id',
|
|
'project_id',
|
|
'task_id',
|
|
'date',
|
|
'hours_worked',
|
|
'overtime_hours',
|
|
'description',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'date' => 'date',
|
|
'hours_worked' => 'decimal:2',
|
|
'overtime_hours' => 'decimal:2',
|
|
];
|
|
|
|
public function tenant()
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function employee()
|
|
{
|
|
return $this->belongsTo(Employee::class);
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function task()
|
|
{
|
|
return $this->belongsTo(Task::class);
|
|
}
|
|
|
|
/**
|
|
* Scope: filter by date range
|
|
*/
|
|
public function scopeDateRange($query, $from, $to)
|
|
{
|
|
return $query->whereBetween('date', [$from, $to]);
|
|
}
|
|
|
|
/**
|
|
* Scope: overtime logs (overtime_hours > 0)
|
|
*/
|
|
public function scopeOvertime($query)
|
|
{
|
|
return $query->where('overtime_hours', '>', 0);
|
|
}
|
|
}
|