芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Models/Project.php
$contracts * @property-read int|null $contracts_count * @property-read int|null $project_members_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionNote * @property-read int|null $mention_note_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionUser * @property-read int|null $mention_user_count * @property-read \Illuminate\Database\Eloquent\Collection
$incompleteMilestones * @property-read int|null $incomplete_milestones_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionProject * @property-read int|null $mention_project_count * @property-read \Illuminate\Database\Eloquent\Collection
$mentionUser * @property-read \App\Models\Project|null $due_date * @mixin \Eloquent */ class Project extends BaseModel { use CustomFieldsTrait, HasFactory; use SoftDeletes; use HasCompany; protected $casts = [ 'start_date' => 'datetime', 'deadline' => 'datetime', 'created_at' => 'datetime', ]; protected $guarded = ['id']; protected $with = ['members']; protected $appends = ['isProjectAdmin']; const CUSTOM_FIELD_MODEL = 'App\Models\Project'; public function category(): BelongsTo { return $this->belongsTo(ProjectCategory::class, 'category_id'); } public function client(): BelongsTo { return $this->belongsTo(User::class, 'client_id')->withoutGlobalScope(ActiveScope::class); } public function clientdetails(): BelongsTo { return $this->belongsTo(ClientDetails::class, 'client_id', 'user_id'); } public function members(): HasMany { return $this->hasMany(ProjectMember::class, 'project_id'); } public function projectMembers(): BelongsToMany { return $this->belongsToMany(User::class, 'project_members')->using(ProjectMember::class); } public function tasks(): HasMany { return $this->hasMany(Task::class, 'project_id')->orderBy('id', 'desc'); } public function files(): HasMany { return $this->hasMany(ProjectFile::class, 'project_id')->orderBy('id', 'desc'); } public function invoices(): HasMany { return $this->hasMany(Invoice::class, 'project_id')->orderBy('id', 'desc'); } public function contracts(): HasMany { return $this->hasMany(Contract::class, 'project_id')->orderBy('id', 'desc'); } public function issues(): HasMany { return $this->hasMany(Issue::class, 'project_id')->orderBy('id', 'desc'); } public function times(): HasMany { return $this->hasMany(ProjectTimeLog::class, 'project_id')->with('breaks')->orderBy('id', 'desc'); } public function milestones(): HasMany { return $this->hasMany(ProjectMilestone::class, 'project_id')->orderBy('id', 'desc'); } public function incompleteMilestones(): HasMany { return $this->hasMany(ProjectMilestone::class, 'project_id')->whereNot('status', 'complete')->orderBy('id', 'desc'); } public function expenses(): HasMany { return $this->hasMany(Expense::class, 'project_id')->orderBy('id', 'desc'); } public function notes(): HasMany { return $this->hasMany(ProjectNote::class, 'project_id')->orderBy('id', 'desc'); } public function payments(): HasMany { return $this->hasMany(Payment::class, 'project_id')->orderBy('id', 'desc'); } public function currency(): BelongsTo { return $this->belongsTo(Currency::class, 'currency_id'); } public function discussions(): HasMany { return $this->hasMany(Discussion::class, 'project_id')->orderBy('id', 'desc'); } public function rating(): HasOne { return $this->hasOne(ProjectRating::class); } /** * @return bool */ public function checkProjectUser() { return ProjectMember::where('project_id', $this->id) ->where('user_id', user()->id) ->exists(); } /** * @return bool */ public function checkProjectClient() { return Project::where('id', $this->id) ->where('client_id', user()->id) ->exists(); } public static function clientProjects($clientId) { return Project::where('client_id', $clientId)->get(); } /** * @param string $search * Search Parameter is passed the get only search results and 20 * @return \Illuminate\Support\Collection */ public static function allProjects($search = '') { $projects = Project::leftJoin('project_members', 'project_members.project_id', 'projects.id') ->select('projects.*') ->orderBy('project_name'); if (!isRunningInConsoleOrSeeding()) { if (user()->permission('view_projects') == 'added') { $projects->where('projects.added_by', user()->id); } if (user()->permission('view_projects') == 'both') { $projects->where('projects.added_by', user()->id)->orWhere('project_members.user_id', user()->id); } if (user()->permission('view_projects') == 'owned' && in_array('employee', user_roles())) { $projects->where('project_members.user_id', user()->id); } if (user()->permission('view_projects') == 'owned' && in_array('client', user_roles())) { $projects->where('projects.client_id', user()->id); } } $projects = $projects->groupBy('projects.id'); if ($search !== '') { return $projects->where('project_name', 'like', '%' . $search . '%') ->take(GlobalSetting::SELECT2_SHOW_COUNT) ->get(); } return $projects->get(); } public static function allProjectsHavingClient() { $projects = Project::with('currency')->leftJoin('project_members', 'project_members.project_id', 'projects.id') ->whereNotNull('client_id') ->select('projects.*') ->orderBy('project_name'); if (!isRunningInConsoleOrSeeding()) { if (user()->permission('view_projects') == 'added') { $projects->where('projects.added_by', user()->id); } if (user()->permission('view_projects') == 'owned' && in_array('employee', user_roles())) { $projects->where('project_members.user_id', user()->id); } if (user()->permission('view_projects') == 'owned' && in_array('client', user_roles())) { $projects->where('projects.client_id', user()->id); } } return $projects->groupBy('projects.id')->get(); } public static function byEmployee($employeeId) { return Project::join('project_members', 'project_members.project_id', '=', 'projects.id') ->where('project_members.user_id', $employeeId) ->select('projects.*') ->get(); } public function scopeCompleted($query) { return $query->where('completion_percent', '100'); } public function scopeInProcess($query) { return $query->where('status', 'in progress'); } public function scopeOnHold($query) { return $query->where('status', 'on hold'); } public function scopeFinished($query) { return $query->where('status', 'finished'); } public function scopeNotStarted($query) { return $query->where('status', 'not started'); } public function scopeCanceled($query) { return $query->where('status', 'canceled'); } public function scopeOverdue($query) { $setting = company(); return $query->where('completion_percent', '<>', '100') ->where('deadline', '<', Carbon::today()->timezone($setting->timezone)); } public function getIsProjectAdminAttribute() { if (auth()->user() && $this->project_admin == user()->id) { return true; } return false; } public function pinned() { $pin = Pinned::where('user_id', user()->id)->where('project_id', $this->id)->first(); if (!is_null($pin)) { return true; } return false; } public function mentionUser(): BelongsToMany { return $this->belongsToMany(User::class, 'mention_users')->withoutGlobalScope(ActiveScope::class)->using(MentionUser::class); } public function mentionProject(): HasMany { return $this->hasMany(MentionUser::class, 'project_id'); } }