@@ -6,6 +6,7 @@ use App\Enums\PurchasingRole;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Models\Concerns\HasWorkContext;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\RequisitionApprovalLevels;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -27,6 +28,7 @@ use Tempo\Purchasing\Internal\InternalRequisitions;
|
||||
* @property Carbon|null $submitted_at
|
||||
* @property Carbon|null $needed_by
|
||||
* @property array<string,mixed>|null $comparison_policy
|
||||
* @property array<string,mixed>|null $budget_distribution_preparation
|
||||
* @property Collection<int, ApprovalStep> $steps
|
||||
* @property Collection<int, RequisitionItem> $items
|
||||
*/
|
||||
@@ -37,9 +39,12 @@ class Requisition extends Model
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
// Stage-specific controllers expose authorised preparation explicitly, never quotation details through generic request JSON.
|
||||
protected $hidden = ['budget_distribution_preparation'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['draft_input' => 'array', 'approval_snapshot' => 'array', 'comparison_policy' => 'array', 'submitted_at' => 'datetime', 'needed_by' => 'date:Y-m-d'];
|
||||
return ['draft_input' => 'array', 'budget_distribution_preparation' => 'array', 'approval_snapshot' => 'array', 'comparison_policy' => 'array', 'submitted_at' => 'datetime', 'needed_by' => 'date:Y-m-d'];
|
||||
}
|
||||
|
||||
/** @return HasMany<RequisitionItem, $this> */
|
||||
@@ -75,10 +80,11 @@ class Requisition extends Model
|
||||
/** @param Builder<Requisition> $query */
|
||||
public function scopeVisibleTo(Builder $query, User $user): void
|
||||
{
|
||||
if ($user->departmentScoped()) {
|
||||
$query->where('department_id', $user->department_id);
|
||||
} elseif (! $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance])) {
|
||||
$query->where('requester_id', $user->id);
|
||||
if ($user->departmentScoped() || ! $user->hasFunctions([PurchasingRole::Admin, PurchasingRole::Procurement, PurchasingRole::Finance])) {
|
||||
$query->where(function ($visible) use ($user) {
|
||||
$visible->where($user->departmentScoped() ? 'department_id' : 'requester_id', $user->departmentScoped() ? $user->department_id : $user->id);
|
||||
app(RequisitionApprovalLevels::class)->includeVisible($visible, $user);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +96,9 @@ class Requisition extends Model
|
||||
|
||||
$next = InternalRequisitions::nextStep(['status' => $this->status, 'requester_id' => $this->requester_id, 'steps' => $this->steps->toArray()], $user->id);
|
||||
|
||||
return $next !== null && $user->hasFunctions([$next['role']])
|
||||
&& ($next['role'] !== 'department_head' || $this->department_id === $user->department_id)
|
||||
return $next !== null && (str_starts_with($next['role'], 'configured_')
|
||||
? app(RequisitionApprovalLevels::class)->eligible($user, $this, $next)
|
||||
: ($user->hasFunctions([$next['role']]) && ($next['role'] !== 'department_head' || $this->department_id === $user->department_id)))
|
||||
&& ! app(ConflictGuard::class)->participationBlocked($user, $this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user