Implement G2A health exemptions in QA and reconcile L1 branch inventory
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class IvaHealthGoodsDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
public function test_health_goods_round_trip_preserves_other_opportunity(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
|
||||
$draft = json_decode(file_get_contents(getenv('IVA_G2A_INPUT') ?: base_path('outputs/iva-l1-g2-health-20261024/calculated.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => [], 'economic_snapshot' => $draft], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$recovered = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($draft['modelo_a_snapshot'], $recovered['modelo_a_snapshot']);
|
||||
$book = json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:309'];
|
||||
$this->assertCount(5, $book['result']['rows']);
|
||||
$this->assertSame('500.00', $book['result']['periods'][0]['fields']['07']);
|
||||
$this->assertSame(json_decode($draft['modelo_a_snapshot'], true)['salesOperations']['opportunity:310'], json_decode($recovered['modelo_a_snapshot'], true)['salesOperations']['opportunity:310']);
|
||||
foreach ($book['result']['rows'] as $row) $this->assertSame('0.00', $row['vat']);
|
||||
if (getenv('IVA_G2A_RECOVERED')) file_put_contents(getenv('IVA_G2A_RECOVERED'), json_encode($recovered, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import fs from 'node:fs';
|
||||
import {operationTreatments,newSalesOperation,evaluateSalesOperation,recordSales,saveSalesBook,salesBook,salesCurrent} from '../../resources/js/lib/iva-operations.ts';
|
||||
import {createProjectDossierReport} from '../../resources/js/lib/project-dossier-report.ts';
|
||||
const ids=['health_assistive','human_materials','patient_transport','mosquito_nets','medicines'];
|
||||
export function healthFixture(){
|
||||
const draft=JSON.parse(fs.readFileSync(new URL('./fixtures/iva-services.json',import.meta.url),'utf8'));
|
||||
draft.context_opportunity='opportunity:309';draft.project_title='SYNTHETIC QA — G2A saúde';
|
||||
let book={currency:'MZN',rows:ids.map((id,i)=>({...newSalesOperation(`g2a-${i}`,'2026-02','MZN'),description:`SYNTHETIC QA ${id}`,establishment:'SYNTHETIC QA estabelecimento Manica',amount:'100',basis:i%2?'included':'net',treatment:id,confirmed:operationTreatments.find(t=>t.id===id).conditions.map((_,n)=>n),evidence:'SYNTHETIC QA — natureza, destino e autorização quando aplicável pressupostos documentados; sem certificação'})),periods:[{period:'2026-02',complete:true}]};
|
||||
book=recordSales(draft,book);draft.modelo_a_snapshot=saveSalesBook(draft,book);return {draft,book};
|
||||
}
|
||||
test('G2A five health branches require their own nature, location, purpose and authorization, not the health sector',()=>{
|
||||
const {book}=healthFixture();
|
||||
for(const row of book.rows){const r=evaluateSalesOperation(row,'MZN');assert.equal(r.field,'07');assert.equal(r.net,'100.00');assert.equal(r.vat,'0.00');assert.equal(r.gross,'100.00');assert.match(r.source,/1426\(267\)/);
|
||||
const count=operationTreatments.find(t=>t.id===row.treatment).conditions.length;
|
||||
for(let missing=0;missing<count;missing++)assert.equal(evaluateSalesOperation({...row,confirmed:row.confirmed.filter(n=>n!==missing)},'MZN').vat,null);
|
||||
assert.equal(evaluateSalesOperation({...row,evidence:''},'MZN').vat,null);
|
||||
}
|
||||
assert.equal(book.result.periods[0].fields['07'],'500.00');
|
||||
});
|
||||
test('G2A reuses saved dossier data, retains G1 unchanged, and reports recovered context without recalculating accepted treatments',()=>{
|
||||
const original=JSON.parse(fs.readFileSync(new URL('./fixtures/iva-services.json',import.meta.url),'utf8'));
|
||||
const before=JSON.parse(original.modelo_a_snapshot).salesOperations['opportunity:310'];
|
||||
const {draft}=healthFixture();const recovered=JSON.parse(JSON.stringify(draft));assert.equal(salesCurrent(recovered,salesBook(recovered)),true);
|
||||
assert.deepEqual(JSON.parse(recovered.modelo_a_snapshot).salesOperations['opportunity:310'],before);
|
||||
const model=JSON.stringify(createProjectDossierReport(recovered,{selectedSections:new Set(['finance'])}));
|
||||
for(const token of [...ids,'500.00','opportunity:309','Manica','MZN','2026-02'])assert.ok(model.includes(token),token);
|
||||
assert.equal(model.includes('financial_stamp'),false);
|
||||
assert.equal(draft.province_id,original.province_id);assert.deepEqual(draft.selection_labels,original.selection_labels);
|
||||
});
|
||||
if(process.env.IVA_G2A_OUT)fs.writeFileSync(process.env.IVA_G2A_OUT,JSON.stringify(healthFixture().draft,null,2));
|
||||
@@ -8,7 +8,7 @@ import {createProjectDossierReport} from '../../resources/js/lib/project-dossier
|
||||
|
||||
export function operationsFixture(){
|
||||
const draft=closureFixture().draft;draft.project_title='SYNTHETIC QA — L1 operações IVA';draft.province_id='cf5e81f1-ffbc-535d-b1b6-b44b445c4421';draft.selection_labels={province_id:'Manica'};
|
||||
const rows=operationTreatments.filter(t=>!['financial_stamp','insurance_stamp','public_waste','public_funeral'].includes(t.id)).map((t,i)=>({...newSalesOperation(`qa-${i}`,'2026-01','MZN'),description:`SYNTHETIC QA ${t.label}`,establishment:'SYNTHETIC QA estabelecimento Manica',amount:t.id==='general'?'1161':'100',basis:t.id==='general'?'included':'net',treatment:t.id,confirmed:t.conditions.map((_,i)=>i),evidence:'SYNTHETIC QA — pressupostos de ensaio, não documento real'}));
|
||||
const rows=operationTreatments.filter(t=>['general','private_health','private_education','private_training','personal_lessons','export_goods','housing_rent','public_health','public_education','public_training','foreign_operation','other'].includes(t.id)).map((t,i)=>({...newSalesOperation(`qa-${i}`,'2026-01','MZN'),description:`SYNTHETIC QA ${t.label}`,establishment:'SYNTHETIC QA estabelecimento Manica',amount:t.id==='general'?'1161':'100',basis:t.id==='general'?'included':'net',treatment:t.id,confirmed:t.conditions.map((_,i)=>i),evidence:'SYNTHETIC QA — pressupostos de ensaio, não documento real'}));
|
||||
const book={currency:'MZN',rows,periods:[{period:'2026-01',complete:true}]};return {draft,book};
|
||||
}
|
||||
test('each enumerated treatment calculates only with its conditions, article and source',()=>{
|
||||
|
||||
Reference in New Issue
Block a user