@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\RequisitionExpiry;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class RequisitionExpiryTick extends Command
|
||||
{
|
||||
protected $signature = 'sgc:approval-deadlines-tick';
|
||||
|
||||
protected $description = 'Conferir prazos configurados, avisos e devoluções de requisições';
|
||||
|
||||
public function handle(RequisitionExpiry $service): int
|
||||
{
|
||||
if (! $service->ready()) {
|
||||
$this->warn('Extensão de prazos indisponível nesta composição.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
$checked = $failed = 0;
|
||||
DB::table('requisitions')->where('status', 'pending')->whereNotNull('approval_snapshot->approval_expiry')->orderBy('id')->chunkById(100,
|
||||
function ($requests) use ($service, &$checked, &$failed) {
|
||||
foreach ($requests as $request) {
|
||||
try {
|
||||
$service->scheduled($request->id);
|
||||
$checked++;
|
||||
} catch (\Throwable $error) {
|
||||
report($error);
|
||||
$failed++;
|
||||
}
|
||||
}
|
||||
});
|
||||
$this->info('Prazos: '.$checked.' pedidos conferidos; '.$failed.' pendentes de recuperação.');
|
||||
|
||||
return $failed === 0 ? self::SUCCESS : self::FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,13 @@ final class RequisitionExpiryController extends Controller
|
||||
|
||||
return back()->with('success', 'Pedido devolvido ao requisitante; decisões e reservas anteriores preservadas no histórico.');
|
||||
}
|
||||
|
||||
public function check(Request $request, Requisition $requisition, RequisitionExpiry $service): Response
|
||||
{
|
||||
$result = $service->check($this->actor($request), $requisition, $request->all());
|
||||
|
||||
return back()->with('success', $result['action'] === 'returned'
|
||||
? 'Prazo terminado: pedido devolvido ao requisitante.'
|
||||
: 'Prazos conferidos; avisos devidos registados sem duplicação.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class WorkflowNoticeController extends Controller
|
||||
$unread = $visible->whereNull('read_at')->count();
|
||||
$items = ($filter['view'] ?? 'all') === 'unread' ? $visible->whereNull('read_at')->values() : $visible;
|
||||
if (in_array($filter['view'] ?? '', ['tasks', 'outcomes'], true)) {
|
||||
$items = $visible->where('kind', $filter['view'] === 'tasks' ? 'task' : 'outcome')->values();
|
||||
$items = $filter['view'] === 'tasks' ? $visible->whereIn('kind', ['task', 'reminder'])->values() : $visible->where('kind', 'outcome')->values();
|
||||
}
|
||||
$search = trim($filter['search'] ?? '');
|
||||
if ($search !== '') {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Services\ReplenishmentRun;
|
||||
use App\Services\RequisitionExpiryRun;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait BelongsToTenant
|
||||
@@ -9,7 +11,8 @@ trait BelongsToTenant
|
||||
protected static function bootBelongsToTenant(): void
|
||||
{
|
||||
static::addGlobalScope('tenant', function (Builder $query) {
|
||||
$tenantId = auth()->check() ? auth()->user()->tenant_id : app(\App\Services\ReplenishmentRun::class)->tenantId();
|
||||
$tenantId = auth()->check() ? auth()->user()->tenant_id : (app(ReplenishmentRun::class)->tenantId()
|
||||
?? app(RequisitionExpiryRun::class)->tenantId());
|
||||
$query->where($query->getModel()->qualifyColumn('tenant_id'), $tenantId ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Services\AdministrativeGeography;
|
||||
use App\Services\BudgetDistributionArtifact;
|
||||
use App\Services\FinanceBundle;
|
||||
use App\Services\ReplenishmentRun;
|
||||
use App\Services\RequisitionExpiryRun;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -20,6 +21,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(ReplenishmentRun::class);
|
||||
$this->app->singleton(RequisitionExpiryRun::class);
|
||||
$this->app->scoped(AdministrativeGeography::class);
|
||||
require_once base_path('packages/purchasing/bootstrap.php');
|
||||
$package = config('common-budget.path');
|
||||
|
||||
@@ -12,7 +12,12 @@ class BudgetWorkflow
|
||||
/** @return array<string,mixed>|null */
|
||||
public function record(User $user, Requisition $request, string $kind, int $amount = 0, ?int $subtotal = null, ?Quotation $quote = null): ?array
|
||||
{
|
||||
abort_unless(auth()->id() === $user->id && $user->tenant_id !== null && $request->tenant_id === $user->tenant_id, 403);
|
||||
$scheduled = app(RequisitionExpiryRun::class)->isActor($user);
|
||||
abort_unless((auth()->id() === $user->id || $scheduled) && $user->tenant_id !== null && $request->tenant_id === $user->tenant_id, 403);
|
||||
if ($scheduled) {
|
||||
app(RequisitionExpiryRun::class)->assertRequest($request->id);
|
||||
abort_unless($kind === 'release', 403);
|
||||
}
|
||||
if (DB::connection()->transactionLevel() === 0) {
|
||||
throw new \LogicException('Movimentos de orçamento exigem transacção.');
|
||||
}
|
||||
|
||||
@@ -28,7 +28,14 @@ final class CommonBudget
|
||||
/** @param array<int,int> $cycles */
|
||||
public function for(User $user, array $cycles = []): BudgetControl
|
||||
{
|
||||
abort_unless(auth()->id() === $user->id && $user->tenant_id !== null, 403);
|
||||
$deadlineRun = app(RequisitionExpiryRun::class);
|
||||
abort_unless((auth()->id() === $user->id || $deadlineRun->isActor($user)) && $user->tenant_id !== null, 403);
|
||||
if ($deadlineRun->tenantId() !== null) {
|
||||
abort_unless($cycles !== [], 403);
|
||||
foreach (array_keys($cycles) as $origin) {
|
||||
$deadlineRun->assertRequest($origin);
|
||||
}
|
||||
}
|
||||
$runtime = new \ReflectionClass(BudgetControl::class);
|
||||
$cycleRuntime = $runtime->hasConstant('REQUISITION_CYCLES_VERSION') && $runtime->getConstant('REQUISITION_CYCLES_VERSION') === self::REQUISITION_CYCLES_CONTRACT;
|
||||
if (! $cycleRuntime) {
|
||||
@@ -78,6 +85,9 @@ final class CommonBudget
|
||||
|
||||
return new BudgetControl(DB::connection(), $context, '',
|
||||
function (string $action) use ($user): void {
|
||||
if (app(RequisitionExpiryRun::class)->tenantId() !== null) {
|
||||
abort_unless(in_array($action, ['record', 'estimate.release'], true), 403);
|
||||
}
|
||||
app(ConflictGuard::class)->lockCompany($user);
|
||||
abort_unless(DB::table('tenants')->where('id', $user->tenant_id)->value('currency') === 'MZN', 422, 'Moeda da organização incompatível com esta entrega.');
|
||||
$roles = in_array($action, ['create', 'approve', 'reinforcement.propose', 'reinforcement.review', 'view'], true)
|
||||
|
||||
@@ -13,6 +13,11 @@ class CurrentActor
|
||||
*/
|
||||
public function lock(User $actor, ?array $roles = null): User
|
||||
{
|
||||
if (app(RequisitionExpiryRun::class)->tenantId() !== null) {
|
||||
abort_unless($roles === null, 403);
|
||||
|
||||
return app(RequisitionExpiryRun::class)->lock($actor);
|
||||
}
|
||||
abort_unless(auth()->id() === $actor->id && $actor->tenant_id !== null, 403);
|
||||
if (DB::connection()->transactionLevel() === 0) {
|
||||
throw new \LogicException('Revalidar o operador dentro da transacção.');
|
||||
|
||||
@@ -359,7 +359,7 @@ final class ImportLandedCosts
|
||||
abort_unless($this->equivalentPreparation($this->preview($actor, $current, $plan->data), $plan->snapshot['plan']), 409, 'As origens documentais mudaram. Prepare e confira uma nova versão.');
|
||||
}
|
||||
$adapter = app(CommonBudget::class);
|
||||
$engine = $adapter->for($actor);
|
||||
$engine = $adapter->for($actor, RequisitionExpiry::orderCycles($order));
|
||||
$state = $adapter->execute(fn () => (new \ReflectionMethod($engine, 'landedCostState'))->invoke($engine, $plan->record_key));
|
||||
abort_unless($data['financial_revision'] === (is_array($state) ? $state['result']['revision'] : 0), 409, 'A posição orçamental mudou; conserve a preparação e actualize antes de continuar.');
|
||||
abort_unless(! in_array($data['action'], ['reserve', 'amend'], true) || $data['sources'] === [], 422, 'A reserva e a reafectação usam a preparação conferida completa.');
|
||||
|
||||
@@ -49,6 +49,10 @@ final class InternalRequisitionPort implements ExpiryRequisitionPort
|
||||
|
||||
public function authorize(string $action, ?array $record): void
|
||||
{
|
||||
if (app(RequisitionExpiryRun::class)->tenantId() !== null) {
|
||||
abort_unless(in_array($action, ['expire', 'view'], true) && $record !== null, 403);
|
||||
app(RequisitionExpiryRun::class)->assertRequest($record['id']);
|
||||
}
|
||||
if ($this->automaticRule !== null) {
|
||||
abort_unless($action === 'save' && $record === null, 403);
|
||||
app(AutomaticPurchases::class)->requester($this->actor, $this->automaticRule);
|
||||
|
||||
@@ -34,6 +34,7 @@ final class RequisitionExpiry
|
||||
&& constant(BudgetControl::class.'::REQUISITION_CYCLES_VERSION') === CommonBudget::REQUISITION_CYCLES_CONTRACT
|
||||
&& Schema::hasTable('budget_requisition_cycles') && Schema::hasColumn('requisitions', 'approval_cycle')
|
||||
&& Schema::hasTable('workflow_notices') && Schema::hasTable('requisition_commands') && Schema::hasColumn('requisitions', 'process_version')
|
||||
&& Schema::hasColumn('workflow_notices', 'event_kind')
|
||||
&& Schema::hasColumn('approval_steps', 'approval_cycle') && Schema::hasColumn('budget_entries', 'requisition_cycle');
|
||||
}
|
||||
|
||||
@@ -114,6 +115,7 @@ final class RequisitionExpiry
|
||||
return ['requisition' => [...$request->only(['id', 'number', 'status', 'process_version', 'requester_id']),
|
||||
'approval_cycle' => $request->getAttribute('approval_cycle') ?? 1], 'deadline' => $deadline, 'history' => $history,
|
||||
'canExpire' => $deadline['state'] === 'expired' && ! app(ConflictGuard::class)->participationBlocked($actor, $request),
|
||||
'canCheck' => in_array($deadline['state'], ['running', 'expired'], true) && ! app(ConflictGuard::class)->participationBlocked($actor, $request),
|
||||
'canEdit' => $request->status === 'draft' && (int) ($request->getAttribute('approval_cycle') ?? 1) > 1
|
||||
&& $request->requester_id === $actor->id && app(OrganizationAccess::class)->canRequest($actor),
|
||||
'actorId' => $actor->id, 'tenantId' => $actor->tenant_id];
|
||||
@@ -312,4 +314,123 @@ final class RequisitionExpiry
|
||||
app(RequisitionWorkflow::class)->audit($actor, 'requisition.expired_returned', $request, $before,
|
||||
['status' => 'draft', 'cycle' => $cycle + 1, 'expiration_record_id' => $record->id, 'reason' => $proof['reason']]);
|
||||
}
|
||||
|
||||
/** Escalation is a recorded alert to configured, currently authorised viewers; it grants no decision authority.
|
||||
* @param list<int> $profileIds
|
||||
* @return list<User>
|
||||
*/
|
||||
public function escalationRecipients(Requisition $request, array $profileIds): array
|
||||
{
|
||||
if ($profileIds === [] || ! app(OrganizationAccess::class)->active($request->tenant_id)) {
|
||||
return [];
|
||||
}
|
||||
$members = DB::table('organization_memberships as m')->join('organization_profiles as p', 'p.id', '=', 'm.profile_id')
|
||||
->where('m.tenant_id', $request->tenant_id)->where('p.tenant_id', $request->tenant_id)->whereIn('p.id', $profileIds)
|
||||
->where('m.maintenance', false)->where(fn ($q) => $q->whereNull('m.expires_at')->orWhere('m.expires_at', '>', now()))->select('m.user_id');
|
||||
$result = [];
|
||||
foreach (User::query()->where('tenant_id', $request->tenant_id)->where('id', '!=', $request->requester_id)->whereIn('id', $members)->orderBy('id')->get() as $person) {
|
||||
if (app(WorkContext::class)->enforced($person) && ! DB::table('organization_memberships as m')->join('organization_profiles as p', 'p.id', '=', 'm.profile_id')
|
||||
->where('m.tenant_id', $request->tenant_id)->where('p.tenant_id', $request->tenant_id)->where('m.user_id', $person->id)
|
||||
->whereIn('p.id', $profileIds)->where('m.maintenance', false)->where(fn ($q) => $q->whereNull('m.expires_at')->orWhere('m.expires_at', '>', now()))
|
||||
->whereJsonContains('p.work_contexts', 'procurement.internal')->exists()) {
|
||||
continue;
|
||||
}
|
||||
if (! app(OrganizationAccess::class)->maintenanceOnly($person) && app(OrganizationAccess::class)->permissions($person) !== []
|
||||
&& Requisition::query()->visibleTo($person)->whereKey($request->id)->exists()) {
|
||||
$result[] = $person;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $input
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function check(User $actor, Requisition $request, array $input): array
|
||||
{
|
||||
abort_unless($this->ready(), 503);
|
||||
$data = Validator::make($input, ['operation_key' => 'required|uuid', 'process_version' => 'required|integer|min:1'])->validate();
|
||||
$data = ['operation_key' => strtolower($data['operation_key']), 'process_version' => (int) $data['process_version']];
|
||||
$hash = hash('sha256', json_encode([$request->id, $data], JSON_THROW_ON_ERROR));
|
||||
|
||||
return DB::transaction(function () use ($actor, $request, $data, $hash) {
|
||||
app(ConflictGuard::class)->lockCompany($actor);
|
||||
$actor = app(CurrentActor::class)->lock($actor);
|
||||
abort_if(app(OrganizationAccess::class)->maintenanceOnly($actor), 403);
|
||||
abort_unless(app(OrganizationAccess::class)->permissions($actor) !== [], 403);
|
||||
$request = Requisition::query()->visibleTo($actor)->lockForUpdate()->whereKey($request->id)->firstOrFail();
|
||||
app(ConflictGuard::class)->assertParticipation($actor, $request);
|
||||
$retry = SupplyRecord::query()->where('operation_key', $data['operation_key'])->first();
|
||||
if ($retry !== null) {
|
||||
abort_unless($retry->kind === 'req_timeout_check' && $retry->created_by === $actor->id && hash_equals($retry->input_hash, $hash), 409);
|
||||
|
||||
return $retry->snapshot['result'];
|
||||
}
|
||||
abort_unless((int) $request->getAttribute('process_version') === $data['process_version'], 409, 'O pedido mudou. Reveja a etapa actual.');
|
||||
$deadline = $this->deadline($request);
|
||||
$result = ['action' => 'no_pending_deadline', 'notices_created' => 0];
|
||||
if ($deadline['state'] === 'expired') {
|
||||
$childOperation = (string) Str::uuid();
|
||||
app(RequisitionWorkflow::class)->expire($actor, $request, $deadline['basis_hash'], $childOperation, $data['process_version']);
|
||||
$result = ['action' => 'returned', 'notices_created' => 0, 'expiry_operation' => $childOperation];
|
||||
} elseif ($deadline['state'] === 'running') {
|
||||
$step = $request->steps()->whereKey($deadline['step_id'])->firstOrFail();
|
||||
$created = 0;
|
||||
if ($deadline['reminder_at'] !== null && now()->greaterThanOrEqualTo(CarbonImmutable::parse($deadline['reminder_at']))) {
|
||||
$routing = app(ApprovalRouting::class)->current($request, $actor);
|
||||
foreach ($routing['people'] as $person) {
|
||||
$created += DB::table('workflow_notices')->insertOrIgnore(['tenant_id' => $request->tenant_id, 'requisition_id' => $request->id,
|
||||
'approval_step_id' => $step->id, 'recipient_id' => $person['id'], 'reference' => $request->number,
|
||||
'role' => $step->role, 'event_kind' => 'reminder', 'created_at' => now()]);
|
||||
}
|
||||
}
|
||||
$escalationEligible = null;
|
||||
if ($deadline['escalation_at'] !== null && now()->greaterThanOrEqualTo(CarbonImmutable::parse($deadline['escalation_at']))) {
|
||||
$people = $this->escalationRecipients($request, $deadline['profile_ids']);
|
||||
$escalationEligible = count($people);
|
||||
foreach ($people as $person) {
|
||||
$created += DB::table('workflow_notices')->insertOrIgnore(['tenant_id' => $request->tenant_id, 'requisition_id' => $request->id,
|
||||
'approval_step_id' => $step->id, 'recipient_id' => $person->id, 'reference' => $request->number,
|
||||
'role' => $step->role, 'event_kind' => 'escalation', 'created_at' => now()]);
|
||||
}
|
||||
}
|
||||
$result = ['action' => 'deadline_checked', 'notices_created' => $created, 'escalation_eligible' => $escalationEligible];
|
||||
}
|
||||
$receipt = SupplyRecord::query()->create(['tenant_id' => $actor->tenant_id, 'kind' => 'req_timeout_check', 'record_key' => (string) Str::uuid(),
|
||||
'version' => 1, 'state' => 'checked', 'created_by' => $actor->id,
|
||||
'data' => ['requisition_id' => $request->id, 'process_version' => $data['process_version']],
|
||||
'snapshot' => ['result' => $result, 'deadline' => $deadline], 'reason' => 'Verificação dos prazos preservados na submissão.',
|
||||
'operation_key' => $data['operation_key'], 'input_hash' => $hash, 'created_at' => now()]);
|
||||
app(RequisitionWorkflow::class)->audit($actor, 'requisition.timeout_checked', $request, null, ['receipt_id' => $receipt->id, 'result' => $result]);
|
||||
|
||||
return $result;
|
||||
});
|
||||
}
|
||||
|
||||
/** Execute only due work, so periodic checks do not accumulate empty receipts.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function scheduled(int $id): array
|
||||
{
|
||||
return app(RequisitionExpiryRun::class)->execute($id, function () use ($id) {
|
||||
$request = Requisition::query()->whereKey($id)->firstOrFail();
|
||||
$deadline = $this->deadline($request);
|
||||
$due = $deadline['state'] === 'expired';
|
||||
if ($deadline['state'] === 'running') {
|
||||
foreach (['reminder' => 'reminder_at', 'escalation' => 'escalation_at'] as $kind => $field) {
|
||||
if ($deadline[$field] !== null && now()->greaterThanOrEqualTo(CarbonImmutable::parse($deadline[$field]))
|
||||
&& ! DB::table('workflow_notices')->where('tenant_id', $request->tenant_id)->where('approval_step_id', $deadline['step_id'])->where('event_kind', $kind)->exists()) {
|
||||
$due = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $due) {
|
||||
return ['action' => 'nothing_due'];
|
||||
}
|
||||
$actor = User::query()->whereKey($request->requester_id)->firstOrFail();
|
||||
|
||||
return $this->check($actor, $request, ['operation_key' => (string) Str::uuid(), 'process_version' => $request->getAttribute('process_version')]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/** Narrow scheduled deadline execution, never a login or authority to approve. */
|
||||
final class RequisitionExpiryRun
|
||||
{
|
||||
private ?int $tenant = null;
|
||||
|
||||
private ?int $request = null;
|
||||
|
||||
private ?int $owner = null;
|
||||
|
||||
public function tenantId(): ?int
|
||||
{
|
||||
return $this->tenant;
|
||||
}
|
||||
|
||||
public function isActor(User $actor): bool
|
||||
{
|
||||
return $this->tenant !== null && ! auth()->check() && $actor->tenant_id === $this->tenant && $actor->id === $this->owner;
|
||||
}
|
||||
|
||||
public function assertRequest(int $id): void
|
||||
{
|
||||
abort_unless($this->request === $id, 403);
|
||||
}
|
||||
|
||||
public function lock(User $actor): User
|
||||
{
|
||||
abort_unless($this->isActor($actor) && DB::transactionLevel() > 0, 403);
|
||||
$source = DB::table('requisitions')->where('tenant_id', $this->tenant)->where('id', $this->request)->lockForUpdate()->firstOrFail();
|
||||
abort_unless($source->requester_id === $this->owner, 403);
|
||||
|
||||
return User::query()->where('tenant_id', $this->tenant)->whereKey($this->owner)->lockForUpdate()->firstOrFail();
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function evidence(): array
|
||||
{
|
||||
return ['mode' => 'scheduled_approval_deadline', 'tenant_id' => $this->tenant, 'requisition_id' => $this->request,
|
||||
'requester_id' => $this->owner, 'attribution' => 'request_owner_for_context_only; not_an_interactive_action'];
|
||||
}
|
||||
|
||||
public function execute(int $id, callable $callback): mixed
|
||||
{
|
||||
abort_unless(app(RequisitionExpiry::class)->ready() && app()->runningInConsole() && ! auth()->check()
|
||||
&& ! request()->hasSession() && $this->tenant === null && app(ReplenishmentRun::class)->tenantId() === null, 403);
|
||||
$source = DB::table('requisitions')->where('id', $id)->where('status', 'pending')->firstOrFail();
|
||||
$this->tenant = $source->tenant_id;
|
||||
$this->request = $source->id;
|
||||
$this->owner = $source->requester_id;
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
$this->tenant = $this->request = $this->owner = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,10 +183,13 @@ class RequisitionWorkflow
|
||||
*/
|
||||
public function audit(User $user, string $action, ?Requisition $requisition, ?array $before, array $after): void
|
||||
{
|
||||
if (app(RequisitionExpiryRun::class)->tenantId() !== null) {
|
||||
$after += ['execution' => app(RequisitionExpiryRun::class)->evidence()];
|
||||
}
|
||||
AuditLog::query()->create([
|
||||
'tenant_id' => $user->tenant_id, 'user_id' => $user->id,
|
||||
'requisition_id' => $requisition?->id, 'action' => $action,
|
||||
'ip_address' => app(ReplenishmentRun::class)->tenantId() === null ? request()->ip() : null, 'before' => $before, 'after' => $after + (app(ReplenishmentRun::class)->tenantId() === null ? [] : ['execution' => app(ReplenishmentRun::class)->evidence()]),
|
||||
'ip_address' => app(ReplenishmentRun::class)->tenantId() === null && app(RequisitionExpiryRun::class)->tenantId() === null ? request()->ip() : null, 'before' => $before, 'after' => $after + (app(ReplenishmentRun::class)->tenantId() === null ? [] : ['execution' => app(ReplenishmentRun::class)->evidence()]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,12 +111,20 @@ class WorkflowNotices
|
||||
}
|
||||
$step = $request->steps->firstWhere('id', $notice->approval_step_id)
|
||||
?? $request->allSteps()->whereKey($notice->approval_step_id)->first();
|
||||
$event = $notice->event_kind ?? 'task';
|
||||
if ($event === 'escalation') {
|
||||
$deadline = app(RequisitionExpiry::class)->deadline($request);
|
||||
if ($deadline['state'] !== 'running' || $deadline['step_id'] !== $notice->approval_step_id
|
||||
|| ! collect(app(RequisitionExpiry::class)->escalationRecipients($request, $deadline['profile_ids']))->contains('id', $actor->id)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$outcome = $request->requester_id === $actor->id && $step !== null && in_array($step->decision, ['approved', 'rejected', 'expired'], true);
|
||||
if (! $outcome && (! $request->canDecide($actor) || $request->steps->firstWhere('decision', 'pending')?->id !== $notice->approval_step_id)) {
|
||||
if ($event !== 'escalation' && ! $outcome && (! $request->canDecide($actor) || $request->steps->firstWhere('decision', 'pending')?->id !== $notice->approval_step_id)) {
|
||||
continue;
|
||||
}
|
||||
$items[] = ['id' => $notice->id, 'reference' => $notice->reference, 'role' => $notice->role, 'role_label' => $step?->routing['name'] ?? null,
|
||||
'kind' => $outcome ? 'outcome' : 'task', 'outcome' => $outcome ? $step->decision : null, 'current_status' => $request->status,
|
||||
'kind' => $outcome ? 'outcome' : ($event === 'task' ? 'task' : $event), 'outcome' => $outcome ? $step->decision : null, 'current_status' => $request->status,
|
||||
'created_at' => $notice->created_at, 'read_at' => $notice->read_at, 'href' => '/requisicoes/'.$request->id.($outcome && $step->decision === 'expired' ? '/prazos' : '')];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user