@@ -4,5 +4,6 @@ require_once __DIR__.'/src/ReplenishmentProjection.php';
|
||||
require_once __DIR__.'/src/QuotationPricing.php';
|
||||
require_once __DIR__.'/src/ProposalScoring.php';
|
||||
require_once __DIR__.'/src/RequisitionPort.php';
|
||||
require_once __DIR__.'/src/ExpiryRequisitionPort.php';
|
||||
require_once __DIR__.'/src/RequisitionFailure.php';
|
||||
require_once __DIR__.'/src/InternalRequisitions.php';
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tempo\Purchasing\Internal;
|
||||
|
||||
/** Optional cycle extension. Older host ports retain their original interface. */
|
||||
interface ExpiryRequisitionPort extends RequisitionPort
|
||||
{
|
||||
/** @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $policy
|
||||
*/
|
||||
public function prepareCycle(array $record, array $policy, ?string $operation): void;
|
||||
|
||||
/** @param array<string,mixed> $record */
|
||||
public function assertDecisionTimely(array $record): void;
|
||||
|
||||
/** Verify the frozen policy, current pending step and elapsed deadline before financial release.
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $input
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function expiration(array $record, array $input): array;
|
||||
|
||||
/** Close the released cycle and return the same origin to its requester without deleting prior steps.
|
||||
* @param array<string,mixed> $record
|
||||
* @param array<string,mixed> $proof
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function expired(array $record, array $proof): array;
|
||||
}
|
||||
@@ -15,6 +15,11 @@ final class InternalRequisitions
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function supportsExpiryCycles(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>|null
|
||||
@@ -130,8 +135,21 @@ final class InternalRequisitions
|
||||
throw new RequisitionFailure('Submissão não autorizada.', 403);
|
||||
}
|
||||
$policy = $this->port->policy($record);
|
||||
if ($this->port instanceof ExpiryRequisitionPort) {
|
||||
$this->port->prepareCycle($record, $policy, $key);
|
||||
}
|
||||
$this->port->reserve($record);
|
||||
$result = $this->port->submitted($record, $policy, self::roles($record, $policy));
|
||||
} elseif ($action === 'expire') {
|
||||
if (! $this->port instanceof ExpiryRequisitionPort) {
|
||||
throw new RequisitionFailure('O adaptador não suporta devolução por expiração.', 503);
|
||||
}
|
||||
if ($record === null || $record['status'] !== 'pending' || $key === null || $version === null) {
|
||||
throw new RequisitionFailure('A expiração exige pedido pendente, versão e operação explícitas.', 409);
|
||||
}
|
||||
$proof = $this->port->expiration($record, [...$input, 'operation_key' => $key]);
|
||||
$this->port->release($record);
|
||||
$result = $this->port->expired($record, $proof);
|
||||
} elseif ($action === 'decide') {
|
||||
$actor = $this->port->actorId();
|
||||
if ($record === null || $record['status'] !== 'pending' || $record['requester_id'] === $actor) {
|
||||
@@ -141,6 +159,9 @@ final class InternalRequisitions
|
||||
if ($step === null) {
|
||||
throw new RequisitionFailure('A decisão exige outra identidade para cada etapa.', 403);
|
||||
}
|
||||
if ($this->port instanceof ExpiryRequisitionPort) {
|
||||
$this->port->assertDecisionTimely($record);
|
||||
}
|
||||
if (! in_array($input['decision'] ?? '', ['approved', 'rejected'], true)) {
|
||||
throw new RequisitionFailure('Decisão inválida.', 422);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user