|
|
|
@ -15,44 +15,86 @@ class Job extends Model |
|
|
|
{ |
|
|
|
use PresentableTrait; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var \App\Entities\Projects\JobPresenter |
|
|
|
*/ |
|
|
|
protected $presenter = JobPresenter::class; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var array |
|
|
|
*/ |
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at']; |
|
|
|
|
|
|
|
/** |
|
|
|
* Show job name with link to job detail. |
|
|
|
* |
|
|
|
* @return Illuminate\Support\HtmlString |
|
|
|
*/ |
|
|
|
public function nameLink() |
|
|
|
{ |
|
|
|
return link_to_route('jobs.show', $this->name, [$this->id], [ |
|
|
|
'title' => trans( |
|
|
|
'title' => __( |
|
|
|
'app.show_detail_title', |
|
|
|
['name' => $this->name, 'type' => trans('job.job')] |
|
|
|
['name' => $this->name, 'type' => __('job.job')] |
|
|
|
), |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Job belongs to a Project relation. |
|
|
|
* |
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
|
|
*/ |
|
|
|
public function project() |
|
|
|
{ |
|
|
|
return $this->belongsTo(Project::class, 'project_id'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Job belongs to a Worker relation. |
|
|
|
* |
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
|
|
*/ |
|
|
|
public function worker() |
|
|
|
{ |
|
|
|
return $this->belongsTo(User::class, 'worker_id'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Job has many Tasks relation ordered by position. |
|
|
|
* |
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
|
|
*/ |
|
|
|
public function tasks() |
|
|
|
{ |
|
|
|
return $this->hasMany(Task::class)->orderBy('progress')->orderBy('position'); |
|
|
|
return $this->hasMany(Task::class)->orderBy('position'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the job type. |
|
|
|
* |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function type() |
|
|
|
{ |
|
|
|
return $this->type_id == 1 ? trans('job.main') : trans('job.additional'); |
|
|
|
return $this->type_id == 1 ? __('job.main') : __('job.additional'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Add progress attribute on Job model. |
|
|
|
* |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
public function getProgressAttribute() |
|
|
|
{ |
|
|
|
return $this->tasks->isEmpty() ? 0 : $this->tasks->avg('progress'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Add receiveable_earning attribute on Job model. |
|
|
|
* |
|
|
|
* @return float |
|
|
|
*/ |
|
|
|
public function getReceiveableEarningAttribute() |
|
|
|
{ |
|
|
|
return $this->price * ($this->progress / 100); |
|
|
|
|