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
@@ -1,4 +1,5 @@
<?php
namespace Tests\Feature;
use App\Models\User;
@@ -13,42 +14,78 @@ final class IrpcSpecialCessationPriorDraftTest extends TestCase
public function test_cbf16_cessation_and_prior_quotas_recover_without_consuming_declared_balances(): 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(['cessation','prior','annual','exit','missing','negative','absent']as$case){
$d=json_decode(file_get_contents(base_path('outputs/irpc-l7-cessation-prior/'.$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']);
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$a=$m['special']['acceleration'];
$this->assertSame('IRPC-normal-adjustments/13',$m['version']);$this->assertSame($b['special']['acceleration']['monthly'],$a['monthly']['input']);
$this->assertContains('IRPC-normal-adjustments/12',array_column(array_column($b['history'],'model'),'version'));
$this->assertContains('IRPC-normal-adjustments/11',array_column(array_column($b['history'],'model'),'version'));
$this->assertSame($b['depreciation'],$a['normal']['input']);$this->assertSame(['scope'=>'L8','payable'=>null,'recoverable'=>null],$m['special']['finalBalance']);
$this->assertNull($m['tax']);$this->assertArrayHasKey('irpcWithholdings',$s);
if($case==='cessation'){
$v=$a['monthly']['assets'][0];$this->assertSame(6,$v['months']);$this->assertSame('absent',$v['exit']['state']);$this->assertSame('10',$a['additionalDeduction']['numerator']);
$this->assertSame('3120',$m['special']['taxableProfit']['numerator']);$this->assertSame(['numerator'=>'4992','denominator'=>'5'],$m['special']['colecta']);
}elseif($case==='prior'||$case==='annual'){
$v=$a['monthly']['assets'][0];$this->assertSame('150',$b['depreciation']['assets'][0]['previousAccounting']);$this->assertSame('100',$b['depreciation']['assets'][0]['previousFiscal']);$this->assertSame('50',$b['depreciation']['assets'][0]['priorAvailable']);
$this->assertSame($case==='prior'?'15':'30',$v['prior']['acceleratedUsed']['numerator']);$this->assertSame($case==='prior'?'35':'20',$v['prior']['acceleratedRemaining']['numerator']);
$this->assertSame($case==='prior'?'25':'50',$a['additionalDeduction']['numerator']);$this->assertSame($case==='prior'?'3105':'6210',$m['special']['taxableProfit']['numerator']);
$this->assertSame(['numerator'=>$case==='prior'?'4968':'9936','denominator'=>'5'],$m['special']['colecta']);$this->assertSame($b['depreciation'],$a['accelerated']['input']);
}elseif($case==='exit'){
$v=$a['monthly']['assets'][0];$this->assertSame(5,$v['months']);$this->assertSame('2026-06-20',$v['exit']['date']);
$this->assertSame(['numerator'=>'125','denominator'=>'3'],$v['normalQuota']);$this->assertSame(['numerator'=>'125','denominator'=>'6'],$a['additionalDeduction']);
}elseif($case==='missing'){
$this->assertSame('indeterminate',$a['status']);$this->assertNull($a['additionalDeduction']);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertNull($m['special']['colecta']);
}elseif($case==='negative'){
$this->assertSame('not_applicable',$a['rows'][0]['status']);$this->assertFalse($a['monthly']['assets'][0]['applied']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
}else{
$this->assertSame('absent',$a['status']);$this->assertSame([],$a['monthly']['assets']);$this->assertSame('0',$a['additionalDeduction']['numerator']);
$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 (['cessation', 'prior', 'annual', 'exit', 'missing', 'negative', 'absent'] as $case) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l7-cessation-prior/'.$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-l7-cessation-prior/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']);
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$b = $s['irpcNormal'][$d['context_opportunity']];
$m = $b['result']['model'];
$a = $m['special']['acceleration'];
$this->assertSame('IRPC-normal-adjustments/13', $m['version']);
$this->assertSame($b['special']['acceleration']['monthly'], $a['monthly']['input']);
$this->assertContains('IRPC-normal-adjustments/12', array_column(array_column($b['history'], 'model'), 'version'));
$this->assertContains('IRPC-normal-adjustments/11', array_column(array_column($b['history'], 'model'), 'version'));
$this->assertSame($b['depreciation'], $a['normal']['input']);
$this->assertSame(['scope' => 'L8', 'payable' => null, 'recoverable' => null], $m['special']['finalBalance']);
$this->assertNull($m['tax']);
$this->assertArrayHasKey('irpcWithholdings', $s);
if ($case === 'cessation') {
$v = $a['monthly']['assets'][0];
$this->assertSame(6, $v['months']);
$this->assertSame('absent', $v['exit']['state']);
$this->assertSame('10', $a['additionalDeduction']['numerator']);
$this->assertSame('3120', $m['special']['taxableProfit']['numerator']);
$this->assertSame(['numerator' => '4992', 'denominator' => '5'], $m['special']['colecta']);
} elseif ($case === 'prior' || $case === 'annual') {
$v = $a['monthly']['assets'][0];
$this->assertSame('150', $b['depreciation']['assets'][0]['previousAccounting']);
$this->assertSame('100', $b['depreciation']['assets'][0]['previousFiscal']);
$this->assertSame('50', $b['depreciation']['assets'][0]['priorAvailable']);
$this->assertSame($case === 'prior' ? '15' : '30', $v['prior']['acceleratedUsed']['numerator']);
$this->assertSame($case === 'prior' ? '35' : '20', $v['prior']['acceleratedRemaining']['numerator']);
$this->assertSame($case === 'prior' ? '25' : '50', $a['additionalDeduction']['numerator']);
$this->assertSame($case === 'prior' ? '3105' : '6210', $m['special']['taxableProfit']['numerator']);
$this->assertSame(['numerator' => $case === 'prior' ? '4968' : '9936', 'denominator' => '5'], $m['special']['colecta']);
$this->assertSame($b['depreciation'], $a['accelerated']['input']);
} elseif ($case === 'exit') {
$v = $a['monthly']['assets'][0];
$this->assertSame(5, $v['months']);
$this->assertSame('2026-06-20', $v['exit']['date']);
$this->assertSame(['numerator' => '125', 'denominator' => '3'], $v['normalQuota']);
$this->assertSame(['numerator' => '125', 'denominator' => '6'], $a['additionalDeduction']);
} elseif ($case === 'missing') {
$this->assertSame('indeterminate', $a['status']);
$this->assertNull($a['additionalDeduction']);
$this->assertSame('3130', $m['taxableProfit']['numerator']);
$this->assertNull($m['special']['colecta']);
} elseif ($case === 'negative') {
$this->assertSame('not_applicable', $a['rows'][0]['status']);
$this->assertFalse($a['monthly']['assets'][0]['applied']);
$this->assertSame('0', $a['additionalDeduction']['numerator']);
} else {
$this->assertSame('absent', $a['status']);
$this->assertSame([], $a['monthly']['assets']);
$this->assertSame('0', $a['additionalDeduction']['numerator']);
}
file_put_contents(base_path('outputs/irpc-l7-cessation-prior/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}