33 lines
1000 B
PHP
33 lines
1000 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PurchasingRole;
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class PurchasePlanItem extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $attributes = ['version' => 1];
|
|
|
|
/** @param Builder<PurchasePlanItem> $query */
|
|
public function scopeVisibleTo(Builder $query, User $user): void
|
|
{
|
|
match ($user->purchasing_role) {
|
|
PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance => null,
|
|
PurchasingRole::DepartmentHead => $query->where(fn ($visible) => $visible->where('department_id', $user->department_id)->orWhere('responsible_id', $user->id)),
|
|
default => $query->where('responsible_id', $user->id),
|
|
};
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(fn () => throw new \LogicException('Preservar o planeamento.'));
|
|
}
|
|
}
|