@@ -80,6 +80,23 @@ class WorkflowNotices
|
||||
}
|
||||
}
|
||||
|
||||
public function expired(Requisition $requisition, int $stepId): void
|
||||
{
|
||||
if (! Schema::hasTable('workflow_notices')) {
|
||||
return;
|
||||
}
|
||||
if (DB::transactionLevel() === 0) {
|
||||
throw new \LogicException('Aviso de devolução exige a transacção da expiração.');
|
||||
}
|
||||
$step = $requisition->allSteps()->whereKey($stepId)->firstOrFail();
|
||||
if ($requisition->status !== 'draft' || $step->decision !== 'expired') {
|
||||
throw new \LogicException('O aviso exige a devolução efectivamente registada.');
|
||||
}
|
||||
$recipient = User::query()->where('tenant_id', $requisition->tenant_id)->whereKey($requisition->requester_id)->firstOrFail();
|
||||
DB::table('workflow_notices')->insertOrIgnore(['tenant_id' => $requisition->tenant_id, 'requisition_id' => $requisition->id,
|
||||
'approval_step_id' => $step->id, 'recipient_id' => $recipient->id, 'reference' => $requisition->number, 'role' => $step->role, 'created_at' => now()]);
|
||||
}
|
||||
|
||||
/** @return list<array<string,mixed>> */
|
||||
public function visible(User $actor): array
|
||||
{
|
||||
@@ -92,14 +109,15 @@ class WorkflowNotices
|
||||
if ($request === null) {
|
||||
continue;
|
||||
}
|
||||
$step = $request->steps->firstWhere('id', $notice->approval_step_id);
|
||||
$outcome = $request->requester_id === $actor->id && $step !== null && in_array($step->decision, ['approved', 'rejected'], true);
|
||||
$step = $request->steps->firstWhere('id', $notice->approval_step_id)
|
||||
?? $request->allSteps()->whereKey($notice->approval_step_id)->first();
|
||||
$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)) {
|
||||
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,
|
||||
'created_at' => $notice->created_at, 'read_at' => $notice->read_at, 'href' => '/requisicoes/'.$request->id];
|
||||
'created_at' => $notice->created_at, 'read_at' => $notice->read_at, 'href' => '/requisicoes/'.$request->id.($outcome && $step->decision === 'expired' ? '/prazos' : '')];
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
||||
Reference in New Issue
Block a user