@@ -31,6 +31,8 @@ use App\Models\User;
|
||||
use App\Models\Warehouse;
|
||||
use App\Services\AgreementOrderLimits;
|
||||
use App\Services\BudgetWorkflow;
|
||||
use App\Services\CapitalAssignments;
|
||||
use App\Services\CapitalRegister;
|
||||
use App\Services\CommonBudget;
|
||||
use App\Services\ComparisonPolicy;
|
||||
use App\Services\ConflictGuard;
|
||||
@@ -71,6 +73,67 @@ require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/BudgetDistributionSchema.php';
|
||||
|
||||
function nativeCapitalAssignment(object $test): array
|
||||
{
|
||||
config(['capital-register.qa_enabled' => true]);
|
||||
$test->actingAs($test->buyer);
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'record_key' => null, 'version' => 0, 'type' => 'project',
|
||||
'code' => 'PRJ-NATIVE-QA', 'name' => 'Projecto sintético da ordem', 'department_id' => $test->department->id,
|
||||
'equipment_id' => null, 'reference' => 'Documento sintético de investimento', 'state' => 'active', 'reason' => 'Cadastro estritamente sintético da ligação à ordem'];
|
||||
$source = app(CapitalRegister::class)->save($test->buyer, $input);
|
||||
// Extend the pre-approved synthetic fixture with a choice made while it was a draft.
|
||||
$test->r->update(['status' => 'draft']);
|
||||
$test->actingAs($test->owner);
|
||||
$assignment = app(CapitalAssignments::class)->save($test->owner, $test->r, ['operation_key' => (string) Str::uuid(),
|
||||
'version' => 0, 'item_id' => $test->item->id, 'capital_id' => $source->id, 'reason' => 'Destino documental escolhido pelo requisitante sintético']);
|
||||
$test->r->update(['status' => 'approved']);
|
||||
$test->actingAs($test->buyer);
|
||||
|
||||
return [$source, $assignment, $input];
|
||||
}
|
||||
|
||||
test('native order preserves the capital destination and print after the independent register is archived', function () {
|
||||
[$source, $assignment, $input] = nativeCapitalAssignment($this);
|
||||
$award = selectPurchaseAward($this);
|
||||
$order = issuePurchaseOrder($this, $award);
|
||||
expect($order->snapshot['capital_assignments'][$this->item->id]['id'])->toBe($assignment->id)
|
||||
->and($order->total_minor)->toBe($award->total_minor);
|
||||
app(CapitalRegister::class)->save($this->buyer, [...$input, 'operation_key' => (string) Str::uuid(),
|
||||
'record_key' => $source->record_key, 'version' => 1, 'name' => 'Nome posterior ao documento', 'state' => 'archived']);
|
||||
$this->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('PRJ-NATIVE-QA')->assertSee('Projecto sintético da ordem')->assertDontSee('Nome posterior ao documento');
|
||||
expect($order->fresh()->snapshot['capital_assignments'][$this->item->id]['snapshot']['source']['version'])->toBe(1);
|
||||
$this->withoutVite();
|
||||
$this->get('/projectos-imobilizado?history='.$source->record_key)->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->has('trace.orders.data', 1)->where('trace.orders.data.0.order_number', $order->number)->has('trace.receipts.data', 0));
|
||||
$receiver = User::factory()->create(['tenant_id' => $this->tenant->id, 'department_id' => $this->department->id, 'purchasing_role' => PurchasingRole::Warehouse]);
|
||||
$this->actingAs($receiver);
|
||||
$warehouse = Warehouse::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $receiver->id, 'code' => 'CAPITAL-QA', 'name' => 'Armazém sintético']);
|
||||
$stock = StockItem::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $receiver->id, 'code' => 'CAPITAL-QA', 'name' => 'Artigo sintético', 'unit' => 'un']);
|
||||
$receipt = app(ReceiptWorkflow::class)->confirm($receiver, $order, ['idempotency_key' => (string) Str::uuid(), 'delivery_note' => 'CAPITAL-NATIVE-RECEIPT',
|
||||
'received_on' => today()->toDateString(), 'warehouse_id' => $warehouse->id,
|
||||
'items' => [['purchase_order_item_id' => $order->items()->sole()->id, 'received_quantity' => '1.000', 'accepted_quantity' => '1.000', 'quality_status' => 'compliant', 'stock_item_id' => $stock->id]]]);
|
||||
$this->actingAs($this->buyer);
|
||||
$before = DB::table('stock_movements')->get()->toJson();
|
||||
$this->get('/projectos-imobilizado?history='.$source->record_key)->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page->has('trace.receipts.data', 1)->where('trace.receipts.data.0.receipt_id', $receipt->id)
|
||||
->where('trace.receipts.data.0.accepted_quantity', '1.000')->where('trace.receipts.data.0.returned_quantity', '0.000')->where('trace.receipts.data.0.reversed', false));
|
||||
expect(DB::table('stock_movements')->get()->toJson())->toBe($before);
|
||||
});
|
||||
|
||||
test('native partial order freezes the same explicit capital origin without changing its financial allocation', function () {
|
||||
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
|
||||
$this->markTestSkipped('Select the approved isolated-QA common source for native order parts.');
|
||||
}
|
||||
[, $assignment] = nativeCapitalAssignment($this);
|
||||
$award = nativeOrderPartsAward($this);
|
||||
$input = nativeOrderPartsInput($this, $award, '0.400', 0);
|
||||
$this->actingAs($this->buyer);
|
||||
$order = app(OrderPartsWorkflow::class)->issue($this->buyer, $input);
|
||||
expect($order->snapshot['capital_assignments'][$this->item->id]['id'])->toBe($assignment->id)
|
||||
->and($order->total_minor)->toBe(4000)->and(DB::table('budget_order_commands')->count())->toBe(1);
|
||||
$this->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('PRJ-NATIVE-QA');
|
||||
});
|
||||
|
||||
test('confirmed import classifications freeze in a newly issued native order and survive later proposals', function () {
|
||||
config(['import-tariffs.qa_enabled' => true]);
|
||||
$tariffs = app(ImportTariffCodes::class);
|
||||
|
||||
Reference in New Issue
Block a user