Conferir no ano novo pagamentos do exercício anterior
Decisão de 01/12/2026: o registo e a conferência de pagamentos externos aceitam o exercício actual ou o anterior, mantendo a data original. Pagamentos mais antigos continuam recusados. Sem efeito no orçamento. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -123,8 +123,8 @@ class ExternalPaymentWorkflow
|
||||
|
||||
return $existing;
|
||||
}
|
||||
if ($reference === '' || trim($data['evidence_reference']) === '' || $data['paid_on'] < (string) $invoice->issued_on || $data['paid_on'] > today()->format('Y-m-d') || substr($data['paid_on'], 0, 4) !== now()->format('Y')) {
|
||||
$this->invalid('Referência, evidência e data válida do exercício actual são obrigatórias.');
|
||||
if ($reference === '' || trim($data['evidence_reference']) === '' || $data['paid_on'] < (string) $invoice->issued_on || $data['paid_on'] > today()->format('Y-m-d') || ! self::withinFiscalWindow((string) $data['paid_on'])) {
|
||||
$this->invalid('Referência, evidência e data válida do exercício actual ou anterior são obrigatórias.');
|
||||
}
|
||||
$bank = $this->bank($user, $invoice, (int) $data['supplier_bank_detail_id'], $amount);
|
||||
$payment = ExternalPayment::query()->create(['tenant_id' => $user->tenant_id, 'invoice_id' => $invoice->id, 'supplier_bank_detail_id' => $bank->id, 'created_by' => $user->id, 'amount_minor' => $amount, 'currency' => $bank->currency, 'paid_on' => $data['paid_on'], 'external_reference' => $reference, 'reference_hash' => $referenceHash, 'payload_hash' => $hash, 'evidence_reference' => trim($data['evidence_reference']), 'bank_snapshot' => ['bank_id' => $bank->id, 'revision' => $bank->revision, 'bank_name' => $bank->bank_name, 'country' => $bank->country, 'currency' => $bank->currency, 'beneficiary' => $bank->beneficiary, 'account_identifier' => $bank->account_identifier, 'reviewer_ids' => SupplierBankReview::query()->where('supplier_bank_detail_id', $bank->id)->pluck('reviewed_by')->all(), 'development_only' => app(StandaloneRuntime::class)->syntheticOnly(), 'bank_transfer_executed' => false]]);
|
||||
@@ -159,8 +159,8 @@ class ExternalPaymentWorkflow
|
||||
$order = PurchaseOrder::query()->findOrFail($invoice->purchase_order_id);
|
||||
app(ConflictGuard::class)->assertProcess(Requisition::query()->findOrFail($order->requisition_id), $order->supplier_id, $user);
|
||||
if ($decision === 'confirmed') {
|
||||
if (substr((string) $payment->paid_on, 0, 4) !== now()->format('Y')) {
|
||||
$this->invalid('Conferência entre exercícios não suportada.');
|
||||
if (! self::withinFiscalWindow((string) $payment->paid_on)) {
|
||||
$this->invalid('Só se conferem pagamentos do exercício actual ou do anterior.');
|
||||
}
|
||||
$this->bank($user, $invoice, $payment->supplier_bank_detail_id, $payment->amount_minor);
|
||||
$author = User::query()->where('tenant_id', $user->tenant_id)->lockForUpdate()->find($payment->created_by);
|
||||
@@ -184,6 +184,19 @@ class ExternalPaymentWorkflow
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Decisão de 01/12/2026: um pagamento do exercício anterior pode ainda ser registado e conferido
|
||||
* no ano novo (ex.: transferência de 30/12 conferida a 2/1). Não toca no orçamento: o consumo
|
||||
* foi lançado na validação da factura. A data do pagamento mantém-se a original.
|
||||
*/
|
||||
public static function withinFiscalWindow(string $paidOn): bool
|
||||
{
|
||||
$year = (int) substr($paidOn, 0, 4);
|
||||
$current = (int) now()->format('Y');
|
||||
|
||||
return $year === $current || $year === $current - 1;
|
||||
}
|
||||
|
||||
private function audit(User $user, Invoice $invoice, ExternalPayment $payment, string $action): void
|
||||
{
|
||||
$order = PurchaseOrder::query()->findOrFail($invoice->purchase_order_id);
|
||||
|
||||
Reference in New Issue
Block a user