commit13
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Requisition;
|
||||
use App\Models\User;
|
||||
|
||||
/** Read the existing approval queue; never assign authority or change the workflow. */
|
||||
class ApprovalRouting
|
||||
{
|
||||
/** @return array<string,mixed> */
|
||||
public function current(Requisition $requisition, User $viewer): array
|
||||
{
|
||||
abort_unless($viewer->tenant_id === $requisition->tenant_id, 404);
|
||||
Requisition::query()->visibleTo($viewer)->findOrFail($requisition->id);
|
||||
$step = $requisition->status === 'pending' ? $requisition->steps->firstWhere('decision', 'pending') : null;
|
||||
if ($step === null) {
|
||||
return ['status' => 'inactive', 'step_id' => null, 'role' => null, 'people' => [], 'checked_at' => now()->toIso8601String()];
|
||||
}
|
||||
$people = [];
|
||||
foreach (User::query()->where('tenant_id', $requisition->tenant_id)->orderBy('name')->orderBy('id')->get() as $person) {
|
||||
if (! app(OrganizationAccess::class)->maintenanceOnly($person) && $requisition->canDecide($person)) {
|
||||
$people[] = $person->only(['id', 'name']);
|
||||
}
|
||||
}
|
||||
|
||||
return ['status' => $people === [] ? 'unavailable' : 'available', 'step_id' => $step->id, 'role' => $step->role,
|
||||
'task_key' => 'requisition.approve.'.$step->role,
|
||||
'people' => $people, 'checked_at' => now()->toIso8601String()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user