66 lines
3.6 KiB
PHP
66 lines
3.6 KiB
PHP
<?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 IrpcNormalAssessmentDraftTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_normal_colecta_and_missing_classification_recover_without_annual_settlement(): 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 (['calculated', 'missing'] as $case) {
|
|
$d = json_decode(file_get_contents(base_path('outputs/irpc-l6-colecta/'.$case.'.json')), true, flags: JSON_THROW_ON_ERROR);
|
|
$p = ['person_type' => $d['person_type']];
|
|
unset($d['person_type']);
|
|
if ($id === null) {
|
|
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $p, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
|
} else {
|
|
$this->putJson('/api/v1/simulation-drafts/'.$id, ['personal_snapshot' => $p, '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'];
|
|
$this->assertSame('IRPC-normal-adjustments/4', $m['version']);
|
|
$this->assertSame('6700', $m['taxableProfit']['numerator']);
|
|
$this->assertSame('4400', $m['taxableBase']['numerator']);
|
|
$this->assertNull($m['tax']);
|
|
$this->assertSame('2026', $m['assessment']['period']['year']);
|
|
$this->assertSame('2026-01-01', $m['assessment']['period']['from']);
|
|
$this->assertSame('2026-12-31', $m['assessment']['period']['to']);
|
|
$this->assertSame('L8', $m['assessment']['finalBalance']['scope']);
|
|
$this->assertNull($m['assessment']['finalBalance']['payable']);
|
|
$this->assertNull($m['assessment']['finalBalance']['recoverable']);
|
|
$this->assertSame('IRPC-normal-adjustments/3', $b['history'][2]['model']['version']);
|
|
$this->assertArrayHasKey('irpcWithholdings', $s);
|
|
if ($case === 'calculated') {
|
|
$this->assertSame('32', $m['assessment']['rate']['numerator']);
|
|
$this->assertSame('1408', $m['colecta']['numerator']);
|
|
$this->assertSame('general_61_1', $m['assessment']['input']['treatment']);
|
|
} else {
|
|
$this->assertNull($m['colecta']);
|
|
$this->assertNull($m['assessment']['rate']);
|
|
$this->assertSame('', $m['assessment']['input']['treatment']);
|
|
}
|
|
file_put_contents(base_path('outputs/irpc-l6-colecta/recovered-'.$case.'.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
}
|
|
}
|
|
}
|