commit compras3 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 18:56:24 +02:00
parent 930064269e
commit 9cf9764710
87 changed files with 2856 additions and 195 deletions
+12 -2
View File
@@ -23,10 +23,19 @@ final class CommonBudget
public const IMPORT_ESTIMATE_CONTRACT = 'COMMON-BUDGET-IMPORT-ESTIMATE-QA-v1';
public function for(User $user): BudgetControl
public const REQUISITION_CYCLES_CONTRACT = 'COMMON-BUDGET-REQUISITION-CYCLES-QA-v1';
/** @param array<int,int> $cycles */
public function for(User $user, array $cycles = []): BudgetControl
{
abort_unless(auth()->id() === $user->id && $user->tenant_id !== null, 403);
$runtime = new \ReflectionClass(BudgetControl::class);
$cycleRuntime = $runtime->hasConstant('REQUISITION_CYCLES_VERSION') && $runtime->getConstant('REQUISITION_CYCLES_VERSION') === self::REQUISITION_CYCLES_CONTRACT;
if (! $cycleRuntime) {
abort_if(($cycles !== [] && max($cycles) > 1) || (Schema::hasTable('budget_requisition_cycles')
&& DB::table('budget_requisition_cycles')->where('tenant_id', $user->tenant_id)->where('cycle', '>', 1)->exists()), 503,
'Existem novos ciclos de requisição. Preserve o núcleo compatível antes de operar ou consultar saldos.');
}
$landedTables = ['budget_landed_commands', 'budget_landed_entries'];
$landedPresent = array_values(array_filter($landedTables, fn ($table) => Schema::hasTable($table)));
abort_if(count($landedPresent) !== 0 && count($landedPresent) !== count($landedTables), 503, 'Estrutura de aterragem incompleta; saldo não presumido.');
@@ -64,7 +73,8 @@ final class CommonBudget
}
}
abort_unless(DB::table('tenants')->where('id', $user->tenant_id)->value('currency') === 'MZN', 422, 'Controlo comum desta entrega suporta apenas MZN; câmbio permanece pendente.');
$context = new BudgetContext($user->id, ['tenant_id' => (int) $user->tenant_id], (int) now()->year, 'MZN');
$context = $cycleRuntime ? (new \ReflectionClass(BudgetContext::class))->newInstanceArgs([$user->id, ['tenant_id' => (int) $user->tenant_id], (int) now()->year, 'MZN', $cycles])
: new BudgetContext($user->id, ['tenant_id' => (int) $user->tenant_id], (int) now()->year, 'MZN');
return new BudgetControl(DB::connection(), $context, '',
function (string $action) use ($user): void {