Implementa planeamento de compras com marcos e responsabilidades por empresa

This commit is contained in:
2026-10-28 18:30:41 +02:00
parent 76d2463f36
commit 513f430edf
18 changed files with 1604 additions and 2 deletions
+32
View File
@@ -0,0 +1,32 @@
<?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.'));
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class PurchasePlanMilestone extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
protected $attributes = ['version' => 1, 'actual_on' => null];
protected static function booted(): void
{
static::deleting(fn () => throw new \LogicException('Preservar marcos e datas anteriores na auditoria.'));
}
}