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
@@ -6,6 +6,8 @@ use App\Models\Requisition;
use App\Models\Supplier;
use App\Models\SupplyRecord;
use App\Models\User;
use App\Services\CapitalAssignments;
use App\Services\CapitalRegister;
use App\Services\CommonBudget;
use App\Services\ImportBankSupport;
use App\Services\ImportCostDocumentHealth;
@@ -45,7 +47,8 @@ require_once __DIR__.'/../Support/ImportLegalQaFixture.php';
require_once __DIR__.'/../Support/BudgetDistributionSchema.php';
$orderPartsAmendment = ($argv[2] ?? '') === 'order-parts-amendment';
$orderParts = $orderPartsAmendment || ($argv[2] ?? '') === 'order-parts';
$legalAmounts = ($argv[2] ?? '') === 'import-legal-amount';
$capitalRestore = ($argv[2] ?? '') === 'capital';
$legalAmounts = $capitalRestore || ($argv[2] ?? '') === 'import-legal-amount';
$legalRules = $legalAmounts || ($argv[2] ?? '') === 'import-legal';
$bankSupport = $legalRules || ($argv[2] ?? '') === 'import-bank-support';
$importEstimates = $bankSupport || ($argv[2] ?? '') === 'import-estimates';
@@ -231,6 +234,10 @@ if ($landedCosts) {
config(['import-estimates.qa_enabled' => true]);
$legalPlanRequest = $f['r']->replicate();
$legalPlanRequest->fill(['number' => 'LEGAL-RECOVERY-'.Str::random(10), 'status' => 'draft']);
if ($capitalRestore) {
$legalPlanRequest->requester_id = $partyBuyer->id;
supplyGrant($partyBuyer, ['requester']);
}
$legalPlanRequest->save();
$legalPlanItem = $f['r']->items()->sole()->replicate();
$legalPlanItem->requisition_id = $legalPlanRequest->id;
@@ -246,6 +253,18 @@ if ($landedCosts) {
'subtotal_minor' => $kind === 'duty' ? 750 : null, 'tax_minor' => $kind === 'duty' ? 0 : null,
'total_minor' => $kind === 'duty' ? 750 : null], BudgetImportEstimate::KINDS)];
$legalNativePlan = app(ImportEstimates::class)->save($partyBuyer, $legalPlanRequest, $legalNativeInput);
if ($capitalRestore) {
config(['capital-register.qa_enabled' => true]);
$capitalInput = ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0,
'type' => 'project', 'code' => 'RECOVERY-QA', 'name' => 'Projecto sintético antes da revisão', 'department_id' => $f['department']->id,
'equipment_id' => null, 'reference' => 'Documento sintético para recuperação', 'state' => 'active', 'reason' => 'Cadastro próprio de Compras no ensaio de recuperação'];
$capitalFirst = app(CapitalRegister::class)->save($partyBuyer, $capitalInput);
$capitalAssignmentInput = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'item_id' => $legalPlanItem->id,
'capital_id' => $capitalFirst->id, 'reason' => 'Destino sintético preservado na recuperação do cadastro'];
$capitalAssignment = app(CapitalAssignments::class)->save($partyBuyer, $legalPlanRequest, $capitalAssignmentInput);
$capitalArchive = app(CapitalRegister::class)->save($partyBuyer, [...$capitalInput, 'operation_key' => (string) Str::uuid(),
'record_key' => $capitalFirst->record_key, 'version' => 1, 'state' => 'archived', 'name' => 'Designação sintética posterior']);
}
}
}
$evidenceManifest = [];
@@ -391,6 +410,20 @@ try {
echo json_encode(['legal_amount_minor_restored' => 750, 'legal_amount_replay_without_effects' => true,
'native_legal_plan_total_minor' => 10750, 'native_legal_plan_source_restored' => true,
'native_legal_plan_replay_without_effects' => true], JSON_THROW_ON_ERROR).PHP_EOL;
if ($capitalRestore) {
$capitalService = app(CapitalRegister::class);
$capitalReplay = $capitalService->save($restoredBuyer, $capitalInput);
$assignmentReplay = app(CapitalAssignments::class)->save($restoredBuyer, $restoredRequest, $capitalAssignmentInput);
$capitalFrozen = app(CapitalAssignments::class)->freezeForItems($restoredBuyer, [$legalPlanItem->id]);
$capitalHead = app(SupplyPlanning::class)->latest('capital_register')->where('record_key', $capitalFirst->record_key)->firstOrFail();
if ($capitalReplay->id !== $capitalFirst->id || $assignmentReplay->id !== $capitalAssignment->id
|| $capitalHead->id !== $capitalArchive->id || $capitalHead->state !== 'archived'
|| $capitalFrozen[$legalPlanItem->id]['snapshot']['source']['id'] !== $capitalFirst->id) {
throw new RuntimeException('Capital identity versions, archival, frozen assignment or operation replay differs after recovery.');
}
echo json_encode(['capital_register_versions_restored' => 2, 'capital_assignment_source_version_restored' => 1,
'capital_archived_head_preserved' => true, 'capital_replay_without_effects' => true], JSON_THROW_ON_ERROR).PHP_EOL;
}
}
}
$readFingerprint = $fingerprint($restored, $afterColumns);