104 lines
2.3 KiB
PHP
104 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Project extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'name',
|
|
'code',
|
|
'description',
|
|
'status',
|
|
'start_date',
|
|
'end_date',
|
|
'progress',
|
|
'budget',
|
|
'default_currency_id',
|
|
'budget_usd',
|
|
'manager_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
'progress' => 'integer',
|
|
];
|
|
|
|
public function tenant()
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function manager()
|
|
{
|
|
return $this->belongsTo(User::class, 'manager_id');
|
|
}
|
|
|
|
public function currency()
|
|
{
|
|
return $this->belongsTo(Currency::class, 'default_currency_id');
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->belongsToMany(User::class, 'project_users')
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function tasks()
|
|
{
|
|
return $this->hasMany(Task::class);
|
|
}
|
|
|
|
public function expenses()
|
|
{
|
|
return $this->hasMany(Expense::class);
|
|
}
|
|
|
|
public function pettyCashes()
|
|
{
|
|
return $this->hasMany(PettyCash::class);
|
|
}
|
|
|
|
public function workLogs()
|
|
{
|
|
return $this->hasMany(WorkLog::class);
|
|
}
|
|
|
|
public function scopeTenantScope($query)
|
|
{
|
|
return $query->where('tenant_id', session('tenant_id'));
|
|
}
|
|
|
|
public function getStatusLabelAttribute()
|
|
{
|
|
return [
|
|
'planning' => __('project.status_planning'),
|
|
'active' => __('project.status_active'),
|
|
'on_hold' => __('project.status_on_hold'),
|
|
'completed' => __('project.status_completed'),
|
|
'cancelled' => __('project.status_cancelled'),
|
|
][$this->status] ?? $this->status;
|
|
}
|
|
|
|
public function defaultCurrency()
|
|
{
|
|
return $this->belongsTo(Currency::class, 'default_currency_id');
|
|
}
|
|
|
|
public function employees()
|
|
{
|
|
return $this->belongsToMany(Employee::class, 'employee_project', 'project_id', 'employee_id')
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
}
|