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,28 +1,80 @@
<?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 IrpcNormalFormPreparationDraftTest extends TestCase
{
use DatabaseTransactions;
public function test_form_classification_exact_values_and_unmapped_fields_recover_without_changing_calculation_or_history():void
{
$db=DB::selectOne('select current_database() as name,inet_server_port() as port');$this->assertSame('simulator_fiscal_delta_20261021_test',$db->name);$this->assertSame(55441,(int)$db->port);
config(['investor-path.enabled'=>true,'suitecrm.enabled'=>false]);$this->actingAs(User::factory()->create(['email_verified_at'=>now()]));$id=null;$etag=null;
foreach(['mapped','fractional','missing','unmapped','booktax']as$case){
$d=json_decode(file_get_contents(base_path('outputs/irpc-l6-values-forms/'.$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['business_plan_snapshot'],$back['business_plan_snapshot']);$this->assertSame($d['modelo_a_snapshot'],$back['modelo_a_snapshot']);
$s=json_decode($back['modelo_a_snapshot'],true,flags:JSON_THROW_ON_ERROR);$b=$s['irpcNormal'][$d['context_opportunity']];$m=$b['result']['model'];$f=$m['formPreparation'];$fields=array_column($f['fields'],null,'code');$this->assertSame('IRPC-normal-adjustments/9',$m['version']);$this->assertSame($b['forms'],$f['input']);$this->assertContains('IRPC-normal-adjustments/8',array_column(array_column($b['history'],'model'),'version'));$this->assertArrayHasKey('irpcWithholdings',$s);$this->assertSame('3130',$m['taxableProfit']['numerator']);$this->assertSame($m['taxableProfit'],$m['taxableBase']);$this->assertSame(['numerator'=>'5008','denominator'=>'5'],$m['colecta']);$this->assertNull($m['assessment']['finalBalance']['payable']);$this->assertNull($fields['309–316']['value']);$this->assertFalse($f['transport']['ready']);$this->assertSame($m['colecta'],$fields['300']['value']);
if($case==='missing'){$this->assertNull($f['netResult']);$this->assertNull($fields['200']['value']);$this->assertSame($m['taxableProfit'],$fields['260']['value']);}
elseif($case==='unmapped'||$case==='booktax'){$this->assertNull($fields['258']['value']);$this->assertNotEmpty($f['unmapped']);$this->assertFalse($f['reconciliation']['matches']);}
else{$this->assertSame('3120',$f['netResult']['numerator']);$this->assertTrue($f['reconciliation']['matches']);$this->assertSame('0',$fields['213']['value']['numerator']);}
if($case==='booktax'){$this->assertSame('2800',$f['netResult']['numerator']);$this->assertSame('0',$fields['213']['value']['numerator']);}
if($case==='fractional'){$parts=array_column($f['m20'],null,'account');$this->assertSame(['numerator'=>'601','denominator'=>'2'],$parts['6.3']['value']);$this->assertFalse($parts['6.3']['representation']['ready']);$this->assertNull($parts['6.3']['representation']['represented']);}
file_put_contents(base_path('outputs/irpc-l6-values-forms/recovered-'.$case.'.json'),json_encode($back,JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE));
}
}
use DatabaseTransactions;
public function test_form_classification_exact_values_and_unmapped_fields_recover_without_changing_calculation_or_history(): void
{
$db = DB::selectOne('select current_database() as name,inet_server_port() as port');
$this->assertSame('simulator_fiscal_delta_20261021_test', $db->name);
$this->assertSame(55441, (int) $db->port);
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
$this->actingAs(User::factory()->create(['email_verified_at' => now()]));
$id = null;
$etag = null;
foreach (['mapped', 'fractional', 'missing', 'unmapped', 'booktax'] as $case) {
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-values-forms/'.$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['business_plan_snapshot'], $back['business_plan_snapshot']);
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
$s = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR);
$b = $s['irpcNormal'][$d['context_opportunity']];
$m = $b['result']['model'];
$f = $m['formPreparation'];
$fields = array_column($f['fields'], null, 'code');
$this->assertSame('IRPC-normal-adjustments/9', $m['version']);
$this->assertSame($b['forms'], $f['input']);
$this->assertContains('IRPC-normal-adjustments/8', array_column(array_column($b['history'], 'model'), 'version'));
$this->assertArrayHasKey('irpcWithholdings', $s);
$this->assertSame('3130', $m['taxableProfit']['numerator']);
$this->assertSame($m['taxableProfit'], $m['taxableBase']);
$this->assertSame(['numerator' => '5008', 'denominator' => '5'], $m['colecta']);
$this->assertNull($m['assessment']['finalBalance']['payable']);
$this->assertNull($fields['309–316']['value']);
$this->assertFalse($f['transport']['ready']);
$this->assertSame($m['colecta'], $fields['300']['value']);
if ($case === 'missing') {
$this->assertNull($f['netResult']);
$this->assertNull($fields['200']['value']);
$this->assertSame($m['taxableProfit'], $fields['260']['value']);
} elseif ($case === 'unmapped' || $case === 'booktax') {
$this->assertNull($fields['258']['value']);
$this->assertNotEmpty($f['unmapped']);
$this->assertFalse($f['reconciliation']['matches']);
} else {
$this->assertSame('3120', $f['netResult']['numerator']);
$this->assertTrue($f['reconciliation']['matches']);
$this->assertSame('0', $fields['213']['value']['numerator']);
}
if ($case === 'booktax') {
$this->assertSame('2800', $f['netResult']['numerator']);
$this->assertSame('0', $fields['213']['value']['numerator']);
}
if ($case === 'fractional') {
$parts = array_column($f['m20'], null, 'account');
$this->assertSame(['numerator' => '601', 'denominator' => '2'], $parts['6.3']['value']);
$this->assertFalse($parts['6.3']['representation']['ready']);
$this->assertNull($parts['6.3']['representation']['represented']);
}
file_put_contents(base_path('outputs/irpc-l6-values-forms/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
}
}