commit12
This commit is contained in:
@@ -23,9 +23,10 @@ $select = function (string $role) use ($f, $mode) {
|
||||
return $u;
|
||||
};
|
||||
if ($job === 'inspect') {
|
||||
$counts = []; foreach (SettlementSchema::TABLES as $table) $counts[$table] = $db->table($table)->count();
|
||||
$counts = []; foreach (array_merge(SettlementSchema::TABLES, \Tempo\Finance\Payables\ReversalSchema::TABLES) as $table) if ($db->getSchemaBuilder()->hasTable($table)) $counts[$table] = $db->table($table)->count();
|
||||
$out = ['counts' => $counts, 'allocation_events' => $db->table('ps_events')->where('kind', 'supplier_allocation.confirmed')->count(),
|
||||
'core_sha256' => hash_file('sha256', __DIR__.'/../packages/payables/src/SupplierSettlements.php')];
|
||||
'core_sha256' => hash_file('sha256', __DIR__.'/../packages/payables/src/SupplierSettlements.php'),
|
||||
'original_hash' => hash('sha256', Payables::canonical([$db->table('ps_payments')->orderBy('id')->get()->all(), $db->table('ps_payment_decisions')->orderBy('id')->get()->all(), $db->table('ps_allocations')->orderBy('id')->first(), $db->table('pa_obligations')->orderBy('id')->get()->all()]))];
|
||||
} elseif ($job === 'worker') {
|
||||
$u = $select($input['role']); $db->select('select set_config(?, ?, false)', ['application_name', $input['label']]);
|
||||
try { $out = ['status' => 200, 'result' => app($class)->engine($u)->settlements()->command($input['action'], $input['body'], $input['key'])]; }
|
||||
@@ -56,17 +57,40 @@ if ($job === 'inspect') {
|
||||
$out = ['waits' => $waits, 'results' => $results];
|
||||
} finally { if ($db->transactionLevel()) $db->rollBack(); foreach ($processes as $p) if ($p->isRunning()) $p->stop(); }
|
||||
} elseif ($job === 'fault') {
|
||||
if ($input['enabled']) $db->unprepared("CREATE FUNCTION ps_qa_fault() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NEW.kind='supplier_allocation.confirmed' THEN RAISE EXCEPTION 'PS_QA_FAULT'; END IF; RETURN NEW; END $$; CREATE TRIGGER ps_qa_fault BEFORE INSERT ON ps_events FOR EACH ROW EXECUTE FUNCTION ps_qa_fault()");
|
||||
$kind = $input['kind'] ?? 'supplier_allocation.confirmed';
|
||||
if (! in_array($kind, ['supplier_allocation.confirmed', 'supplier_allocation.reversed'], true)) throw new LogicException('Invalid proof fault kind.');
|
||||
if ($input['enabled']) $db->unprepared("CREATE FUNCTION ps_qa_fault() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN IF NEW.kind='{$kind}' THEN RAISE EXCEPTION 'PS_QA_FAULT'; END IF; RETURN NEW; END $$; CREATE TRIGGER ps_qa_fault BEFORE INSERT ON ps_events FOR EACH ROW EXECUTE FUNCTION ps_qa_fault()");
|
||||
else $db->unprepared('DROP TRIGGER ps_qa_fault ON ps_events; DROP FUNCTION ps_qa_fault()');
|
||||
$out = ['configured' => true];
|
||||
} elseif ($job === 'grant') {
|
||||
if (! in_array($input['action'], ['payments_view', 'payment_prepare', 'payment_confirm', 'allocation_prepare', 'allocation_confirm'], true)) throw new LogicException('Invalid QA action.');
|
||||
if (! in_array($input['action'], ['payments_view', 'payment_prepare', 'payment_confirm', 'allocation_prepare', 'allocation_confirm', 'reversal_prepare', 'reversal_confirm'], true)) throw new LogicException('Invalid QA action.');
|
||||
$role = $input['role']; $match = $f['scope'] + ['user_id' => $f['accounts'][$role]['id'], 'action' => $input['action']];
|
||||
if ($input['enabled']) $db->table('pa_access')->insertOrIgnore($match + ['person' => 'synthetic-person-'.$role]); else $db->table('pa_access')->where($match)->delete();
|
||||
$out = ['changed' => true];
|
||||
} elseif ($job === 'person') {
|
||||
$db->table('pa_access')->where($f['scope'])->where(['user_id' => $f['accounts']['validacao']['id'], 'action' => 'view'])->update(['person' => $input['same'] ? 'synthetic-person-preparacao' : 'synthetic-person-validacao']);
|
||||
$out = ['changed' => true];
|
||||
} elseif ($job === 'reversal-immutable') {
|
||||
$refused = 0;
|
||||
foreach (\Tempo\Finance\Payables\ReversalSchema::TABLES as $table) {
|
||||
foreach (['update', 'delete'] as $operation) {
|
||||
try { DB::transaction(function () use ($db, $table, $operation): void {
|
||||
$q = $db->table($table)->where('id', $db->table($table)->min('id'));
|
||||
if ($operation === 'delete') $q->delete(); else $q->update(['reason' => 'Forbidden alteration']);
|
||||
}); } catch (\Illuminate\Database\QueryException) { $refused++; }
|
||||
}
|
||||
}
|
||||
$row = (array) $db->table('ps_reversals')->first(); unset($row['id']);
|
||||
$proposal = $db->table('ps_reversal_proposals')->where('id', $row['proposal_id'])->first();
|
||||
$invalid = 0;
|
||||
foreach ([['amount_minor' => (int) $row['amount_minor'] - 1], ['actor_id' => $proposal->prepared_by, 'person' => $proposal->prepared_person], ['unit_id' => 999999]] as $override) {
|
||||
try { DB::transaction(fn () => $db->table('ps_reversals')->insert(array_replace($row, $override))); }
|
||||
catch (\Illuminate\Database\QueryException $e) {
|
||||
if (! str_contains($e->getMessage(), 'Invalid full allocation compensation')) throw $e;
|
||||
$invalid++;
|
||||
}
|
||||
}
|
||||
$out = ['immutable_operations_refused' => $refused, 'invalid_compensations_refused' => $invalid];
|
||||
} elseif ($job === 'immutable') {
|
||||
$refused = 0;
|
||||
foreach (['ps_payments', 'ps_payment_decisions', 'ps_allocations'] as $table) {
|
||||
@@ -86,9 +110,9 @@ if ($job === 'inspect') {
|
||||
$db->table('company_memberships')->insert(['user_id' => $u->id, 'tenant_id' => $tenant, 'company_id' => $company]);
|
||||
foreach (['company.view' => null, 'unit.view' => $unit, 'supplier_payables.view' => $unit] as $permission => $which) $db->table('permission_grants')->insert(['tenant_id' => $tenant, 'company_id' => $company, 'unit_id' => $which, 'permission' => $permission, 'user_id' => $u->id, 'created_at' => $now, 'updated_at' => $now]);
|
||||
}
|
||||
foreach (['view', 'payments_view', 'payment_confirm', 'allocation_confirm'] as $action) $db->table('pa_access')->insert($scope + ['user_id' => $u->id, 'action' => $action, 'person' => 'foreign-synthetic-person']);
|
||||
foreach (['view', 'payments_view', 'payment_confirm', 'allocation_confirm', 'reversal_prepare', 'reversal_confirm'] as $action) $db->table('pa_access')->insert($scope + ['user_id' => $u->id, 'action' => $action, 'person' => 'foreign-synthetic-person']);
|
||||
auth()->guard()->setUser($u); if ($mode === 'sgf') app(\App\Shared\Context\CompanyContext::class)->selectFor($u->id, $tenant, $company, $unit);
|
||||
try { app($class)->engine($u)->settlements()->command('payment-decide', $input['body'], \Illuminate\Support\Str::uuid()->toString()); $out = ['refused' => false]; }
|
||||
try { app($class)->engine($u)->settlements()->command($input['action'] ?? 'payment-decide', $input['body'], \Illuminate\Support\Str::uuid()->toString()); $out = ['refused' => false]; }
|
||||
catch (\DomainException) { $out = ['refused' => true]; }
|
||||
} elseif ($job === 'multi') {
|
||||
// Core contract test with explicit synthetic source adapter, distinct from the real host source proof.
|
||||
|
||||
Reference in New Issue
Block a user