93 lines
2.1 KiB
PHP
93 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Employee extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'project_id',
|
|
'national_code',
|
|
'first_name',
|
|
'last_name',
|
|
'phone',
|
|
'job_title',
|
|
'contract_type',
|
|
'hire_date',
|
|
'termination_date',
|
|
'status',
|
|
'base_salary',
|
|
'currency_id',
|
|
'bank_account',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'hire_date' => 'date',
|
|
'termination_date' => 'date',
|
|
'national_code' => 'encrypted',
|
|
'bank_account' => 'encrypted',
|
|
'base_salary' => 'decimal:0', // ✅ جایگزین
|
|
];
|
|
|
|
public function tenant()
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function currency()
|
|
{
|
|
return $this->belongsTo(Currency::class);
|
|
}
|
|
|
|
public function workLogs()
|
|
{
|
|
return $this->hasMany(WorkLog::class);
|
|
}
|
|
|
|
public function financials()
|
|
{
|
|
return $this->hasMany(EmployeeFinancial::class);
|
|
}
|
|
|
|
public function expenses()
|
|
{
|
|
return $this->hasMany(Expense::class, 'employee_id');
|
|
}
|
|
|
|
public function getFullNameAttribute()
|
|
{
|
|
return $this->first_name . ' ' . $this->last_name;
|
|
}
|
|
|
|
public function getContractTypeLabelAttribute()
|
|
{
|
|
return [
|
|
'full_time' => __('employee.contract_full_time'),
|
|
'part_time' => __('employee.contract_part_time'),
|
|
'contractor' => __('employee.contract_contractor'),
|
|
'daily' => __('employee.contract_daily'),
|
|
][$this->contract_type] ?? $this->contract_type;
|
|
}
|
|
|
|
public function getStatusLabelAttribute()
|
|
{
|
|
return [
|
|
'active' => __('employee.active'),
|
|
'inactive' => __('employee.inactive'),
|
|
'terminated' => __('employee.terminated'),
|
|
][$this->status] ?? $this->status;
|
|
}
|
|
}
|