commit melhorias compras5
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-22 19:39:09 +02:00
parent 36dcfdf00c
commit db1615fac1
79 changed files with 4082 additions and 120 deletions
+15 -1
View File
@@ -17,10 +17,23 @@ final class CommonBudget
{
public const DISTRIBUTIONS_CONTRACT = 'COMMON-BUDGET-DISTRIBUTION-QA-v1';
public const ORDER_PARTS_CONTRACT = 'COMMON-BUDGET-ORDER-PARTS-QA-v1';
public function for(User $user): BudgetControl
{
abort_unless(auth()->id() === $user->id && $user->tenant_id !== null, 403);
$runtime = new \ReflectionClass(BudgetControl::class);
$orderTables = ['budget_order_commands', 'budget_order_bindings', 'budget_order_allocations', 'budget_order_consumptions'];
$orderPresent = array_values(array_filter($orderTables, fn ($table) => Schema::hasTable($table)));
abort_if(count($orderPresent) !== 0 && count($orderPresent) !== count($orderTables), 503,
'Estrutura de ordens parciais incompleta; saldo não presumido.');
if (! $runtime->hasConstant('ORDER_PARTS_VERSION') || $runtime->getConstant('ORDER_PARTS_VERSION') !== self::ORDER_PARTS_CONTRACT
|| ! $runtime->hasMethod('commitOrderParts') || ! $runtime->hasMethod('consumeOrderParts')) {
foreach ($orderPresent as $table) {
abort_if(DB::table($table)->where('tenant_id', $user->tenant_id)->exists(), 503,
'Existem efeitos de ordens parciais; preserve a composição compatível antes de consultar saldos.');
}
}
$distributionsCompatible = $runtime->hasMethod('recordDistribution') && $runtime->hasConstant('DISTRIBUTIONS_VERSION')
&& $runtime->getConstant('DISTRIBUTIONS_VERSION') === self::DISTRIBUTIONS_CONTRACT;
if (! $distributionsCompatible) {
@@ -40,7 +53,8 @@ final class CommonBudget
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)
? [PurchasingRole::Admin, PurchasingRole::Finance]
: (in_array($action, ['consume', 'consume.preview', 'distribution.amend'], true) ? [PurchasingRole::Finance] : null);
: (in_array($action, ['consume', 'consume.preview', 'distribution.amend'], true) ? [PurchasingRole::Finance]
: (in_array($action, ['orders.commit', 'orders.cancel', 'orders.adopt'], true) ? [PurchasingRole::Procurement] : null));
app(CurrentActor::class)->lock($user, $roles);
},
function (string $action, array $data, ?int $origin) use ($user): void {