fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+67 -37
View File
@@ -1,4 +1,5 @@
<?php
namespace Tests\Feature;
use App\Models\User;
@@ -13,44 +14,73 @@ final class IrpcAnnualSettlementDraftTest extends TestCase
public function test_annual_simulated_balances_round_trip_with_proofs_states_and_preserved_books(): 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()]));
$id=null;$etag=null;
foreach(['payable','recoverable','balanced','absent','missing','duplicate','pec']as$case){
$d=json_decode(file_get_contents(base_path('outputs/irpc-l8-settlement/'.$case.'.json')),true,flags:JSON_THROW_ON_ERROR);
$personal=['person_type'=>$d['person_type']];unset($d['person_type']);
if($id===null)$id=$this->postJson('/api/v1/simulation-drafts',['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['Idempotency-Key'=>(string)Str::uuid()])->assertCreated()->json('data.id');
else $this->putJson('/api/v1/simulation-drafts/'.$id,['personal_snapshot'=>$personal,'economic_snapshot'=>$d],['If-Match'=>$etag])->assertOk();
$r=$this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();$etag=$r->headers->get('ETag');$back=$r->json('data.economic_snapshot');
$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
$this->assertSame($d['business_plan_snapshot'],$back['business_plan_snapshot']);
$before=json_decode($d['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$scope=$d['context_opportunity'];
$b=$s['irpcAnnual'][$scope];$m=$b['result']['model'];
foreach(['irpcNormal','irpcWithholdings','books','currencyEvents','ispcQuarters']as$map)$this->assertSame($before[$map],$s[$map]);
$this->assertSame('IRPC-annual-settlement/1',$m['version']);
$this->assertSame('123456789',$m['subjectNuit']);$this->assertSame('2026',$m['year']);
$this->assertSame(['numerator'=>'1408','denominator'=>'1'],$m['assessment']['colecta']);
$this->assertFalse($m['officialBalancesConsumed']);$this->assertFalse($m['submitted']);$this->assertFalse($m['refundReceived']);
$this->assertSame('known',$m['input']['credits']['state']);$this->assertSame('0',$m['input']['credits']['amount']);
if(in_array($case,['missing','duplicate','pec'],true)){
$this->assertSame('indeterminate',$m['status']);$this->assertNotEmpty($m['pending']);
$this->assertNull($m['arithmeticBalance']);$this->assertNull($m['payable']);$this->assertNull($m['recoverable']);
if($case==='missing')$this->assertSame('',$m['input']['ppc']['rows'][0]['effective']);
if($case==='pec')$this->assertSame('10',$m['input']['pec']['amount']);
if($case==='duplicate')$this->assertCount(2,$m['input']['ppc']['rows']);
}else{
$this->assertEmpty($m['pending']);
$this->assertSame(['payable'=>'payable','recoverable'=>'recoverable','balanced'=>'balanced','absent'=>'payable'][$case],$m['status']);
$this->assertSame(['numerator'=>['payable'=>'608','recoverable'=>'-192','balanced'=>'0','absent'=>'1408'][$case],'denominator'=>'1'],$m['arithmeticBalance']);
$this->assertSame(['numerator'=>$case==='recoverable'?'192':'0','denominator'=>'1'],$m['recoverable']);
if($case==='absent'){$this->assertSame('absent',$m['input']['withholdings']['state']);$this->assertSame('absent',$m['input']['ppc']['state']);}
else{$this->assertSame('yes',$m['input']['withholdings']['rows'][0]['incomeIncluded']);$this->assertSame('yes',$m['input']['ppc']['rows'][0]['effective']);}
$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()]));
$id = null;
$etag = null;
foreach (['payable', 'recoverable', 'balanced', 'absent', 'missing', 'duplicate', 'pec'] as $case) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l8-settlement/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
$personal = ['person_type' => $d['person_type']];
unset($d['person_type']);
if ($id === null) {
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
} else {
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['If-Match' => $etag])->assertOk();
}
file_put_contents(base_path('outputs/irpc-l8-settlement/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
$r = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk();
$etag = $r->headers->get('ETag');
$back = $r->json('data.economic_snapshot');
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
$before = json_decode($d['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$scope = $d['context_opportunity'];
$b = $s['irpcAnnual'][$scope];
$m = $b['result']['model'];
foreach (['irpcNormal', 'irpcWithholdings', 'books', 'currencyEvents', 'ispcQuarters'] as $map) {
$this->assertSame($before[$map], $s[$map]);
}
$this->assertSame('IRPC-annual-settlement/1', $m['version']);
$this->assertSame('123456789', $m['subjectNuit']);
$this->assertSame('2026', $m['year']);
$this->assertSame(['numerator' => '1408', 'denominator' => '1'], $m['assessment']['colecta']);
$this->assertFalse($m['officialBalancesConsumed']);
$this->assertFalse($m['submitted']);
$this->assertFalse($m['refundReceived']);
$this->assertSame('known', $m['input']['credits']['state']);
$this->assertSame('0', $m['input']['credits']['amount']);
if (in_array($case, ['missing', 'duplicate', 'pec'], true)) {
$this->assertSame('indeterminate', $m['status']);
$this->assertNotEmpty($m['pending']);
$this->assertNull($m['arithmeticBalance']);
$this->assertNull($m['payable']);
$this->assertNull($m['recoverable']);
if ($case === 'missing') {
$this->assertSame('', $m['input']['ppc']['rows'][0]['effective']);
}
if ($case === 'pec') {
$this->assertSame('10', $m['input']['pec']['amount']);
}
if ($case === 'duplicate') {
$this->assertCount(2, $m['input']['ppc']['rows']);
}
} else {
$this->assertEmpty($m['pending']);
$this->assertSame(['payable' => 'payable', 'recoverable' => 'recoverable', 'balanced' => 'balanced', 'absent' => 'payable'][$case], $m['status']);
$this->assertSame(['numerator' => ['payable' => '608', 'recoverable' => '-192', 'balanced' => '0', 'absent' => '1408'][$case], 'denominator' => '1'], $m['arithmeticBalance']);
$this->assertSame(['numerator' => $case === 'recoverable' ? '192' : '0', 'denominator' => '1'], $m['recoverable']);
if ($case === 'absent') {
$this->assertSame('absent', $m['input']['withholdings']['state']);
$this->assertSame('absent', $m['input']['ppc']['state']);
} else {
$this->assertSame('yes', $m['input']['withholdings']['rows'][0]['incomeIncluded']);
$this->assertSame('yes', $m['input']['ppc']['rows'][0]['effective']);
}
}
file_put_contents(base_path('outputs/irpc-l8-settlement/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}