70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\HrmAddon\App\Models;
|
||
|
|
|
||
|
|
use App\Models\Branch;
|
||
|
|
use App\Models\Scopes\BranchScope;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
|
||
|
|
class Attendance extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'business_id',
|
||
|
|
'branch_id',
|
||
|
|
'employee_id',
|
||
|
|
'shift_id',
|
||
|
|
'time_in',
|
||
|
|
'time_out',
|
||
|
|
'date',
|
||
|
|
'duration',
|
||
|
|
'month',
|
||
|
|
'note',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function branch(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Branch::class)->withTrashed();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected static function booted()
|
||
|
|
{
|
||
|
|
static::addGlobalScope(new BranchScope);
|
||
|
|
|
||
|
|
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
|
||
|
|
static::addGlobalScope('withBranch', function ($builder) {
|
||
|
|
$builder->with('branch:id,name');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function boot()
|
||
|
|
{
|
||
|
|
parent::boot();
|
||
|
|
|
||
|
|
static::creating(function ($model) {
|
||
|
|
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public function employee()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Employee::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function shift()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Shift::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'business_id' => 'integer',
|
||
|
|
'branch_id' => 'integer',
|
||
|
|
'employee_id' => 'integer',
|
||
|
|
'shift_id' => 'integer',
|
||
|
|
];
|
||
|
|
}
|