This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?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 IrpcEconomicAssociationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_economic_association_uses_the_existing_private_draft_writer(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021));
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-economic-association-20261110/fixture.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$back = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$b = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$d['context_opportunity']];
|
||||
$this->assertSame('proportional', $b['economicCredits']['rows'][0]['nationalMethod']);
|
||||
$this->assertSame(['numerator' => '896', 'denominator' => '25'], $b['result']['model']['economicCredit']['rows'][0]['nationalLimit']);
|
||||
$this->assertSame(['numerator' => '688', 'denominator' => '1'], $b['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame('participation', $b['result']['model']['economicCredit']['rows'][0]['association']['kind']);
|
||||
file_put_contents(base_path('outputs/irpc-economic-association-20261110/recovered.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 IrpcEconomicInclusionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_economic_inclusion_uses_the_existing_private_draft_writer(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021));
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-economic-inclusion-20261110/fixture.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$back = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$b = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcNormal'][$d['context_opportunity']];
|
||||
$this->assertSame('IRPC-economic-inclusion/1', $b['result']['model']['economicInclusions']['version']);
|
||||
$this->assertSame(['numerator' => '112', 'denominator' => '1'], $b['result']['model']['economicInclusions']['net']);
|
||||
$this->assertSame(['numerator' => '36096', 'denominator' => '25'], $b['result']['model']['colecta']);
|
||||
$this->assertNotEmpty($b['history']);
|
||||
file_put_contents(base_path('outputs/irpc-economic-inclusion-20261110/recovered.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 IrpcEconomicLiquidationDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_economic_liquidation_uses_the_existing_private_draft_writer(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021));
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-economic-liquidation-20261110/fixture.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$back = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$b = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$d['context_opportunity']];
|
||||
$this->assertSame('proportional', $b['economicCredits']['rows'][0]['nationalMethod']);
|
||||
$this->assertSame(['numerator' => '896', 'denominator' => '25'], $b['result']['model']['economicCredit']['rows'][0]['nationalLimit']);
|
||||
$this->assertSame(['numerator' => '688', 'denominator' => '1'], $b['result']['model']['arithmeticBalance']);
|
||||
$this->assertSame(['numerator' => '50', 'denominator' => '1'], $b['result']['model']['economicCredit']['rows'][0]['liquidation']['excessCapitalGain']);
|
||||
file_put_contents(base_path('outputs/irpc-economic-liquidation-20261110/recovered.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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 IrpcEconomicQuotaDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_derived_economic_quota_uses_the_existing_private_draft_writer(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021));
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-economic-quota-20261110/fixture.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$back = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$b = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcAnnual'][$d['context_opportunity']];
|
||||
$this->assertSame('proportional', $b['economicCredits']['rows'][0]['nationalMethod']);
|
||||
$this->assertSame(['numerator' => '256', 'denominator' => '5'], $b['result']['model']['economicCredit']['rows'][0]['nationalLimit']);
|
||||
$this->assertSame(['numerator' => '3244', 'denominator' => '5'], $b['result']['model']['arithmeticBalance']);
|
||||
file_put_contents(base_path('outputs/irpc-economic-quota-20261110/recovered.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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 IrpcEconomicSpecialInclusionDraftTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_economic_special_inclusion_uses_the_existing_private_draft_writer(): void
|
||||
{
|
||||
$target = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
$this->assertSame('proactive_investment_20261027_test', $target->name);
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'suitecrm.enabled' => false]);
|
||||
$this->actingAs(User::findOrFail(1021));
|
||||
$d = json_decode(file_get_contents(base_path('outputs/irpc-economic-special-inclusion-20261110/fixture.json')), true, flags: JSON_THROW_ON_ERROR);
|
||||
$personal = ['person_type' => $d['person_type']];
|
||||
unset($d['person_type']);
|
||||
$id = $this->postJson('/api/v1/simulation-drafts', ['personal_snapshot' => $personal, 'economic_snapshot' => $d], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json('data.id');
|
||||
$back = $this->getJson('/api/v1/simulation-drafts/'.$id)->assertOk()->json('data.economic_snapshot');
|
||||
$this->assertSame($d['modelo_a_snapshot'], $back['modelo_a_snapshot']);
|
||||
$this->assertSame($d['business_plan_snapshot'], $back['business_plan_snapshot']);
|
||||
$b = json_decode($back['modelo_a_snapshot'], true, flags: JSON_THROW_ON_ERROR)['irpcNormal'][$d['context_opportunity']];
|
||||
$this->assertSame('IRPC-economic-inclusion/1', $b['result']['model']['economicInclusions']['version']);
|
||||
$this->assertSame(['numerator' => '162', 'denominator' => '1'], $b['result']['model']['economicInclusions']['net']);
|
||||
$this->assertSame(['numerator' => '36496', 'denominator' => '25'], $b['result']['model']['colecta']);
|
||||
$this->assertNotEmpty($b['history']);
|
||||
file_put_contents(base_path('outputs/irpc-economic-special-inclusion-20261110/recovered.json'), json_encode($back, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
||||
import {
|
||||
calculateAnnual,
|
||||
recordAnnual,
|
||||
saveAnnualBook,
|
||||
annualBook,
|
||||
annualCurrent,
|
||||
annualHtml,
|
||||
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
function associationCase(kind = 'participation', effectivelyTaxed = 'yes') {
|
||||
const c = economicCase();
|
||||
Object.assign(c.b.economicCredits.rows[0], {
|
||||
kind: 'association',
|
||||
association: {
|
||||
kind,
|
||||
effectivelyTaxed,
|
||||
reference:
|
||||
'SYNTHETIC QA contract and distributed income; documented adaptation64(4)',
|
||||
},
|
||||
nationalMethod: 'proportional',
|
||||
nationalBasisReference:
|
||||
'SYNTHETIC included100 plus nominal12 in current base4400',
|
||||
});
|
||||
return c;
|
||||
}
|
||||
void test('participation and quota use only the documented economic tax and preserve L6 and other deductions', () => {
|
||||
for (const kind of ['participation', 'quota']) {
|
||||
const c = associationCase(kind, kind === 'quota' ? '' : 'yes'),
|
||||
before = c.d.modelo_a_snapshot,
|
||||
m = calculateAnnual(c.d, c.b);
|
||||
assert.deepEqual(m.pending, []);
|
||||
assert.deepEqual(m.economicCredit.deducted, {
|
||||
numerator: '12',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(m.arithmeticBalance, {
|
||||
numerator: '688',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.equal(c.d.modelo_a_snapshot, before);
|
||||
}
|
||||
});
|
||||
void test('participation cannot infer effective taxation and unknown contract stays recoverable but indeterminate', () => {
|
||||
for (const patch of [
|
||||
{ kind: 'participation', effectivelyTaxed: '' },
|
||||
{ kind: 'participation', effectivelyTaxed: 'no' },
|
||||
{ kind: '', effectivelyTaxed: 'yes' },
|
||||
{ reference: '' },
|
||||
]) {
|
||||
const c = associationCase();
|
||||
Object.assign(c.b.economicCredits.rows[0].association, patch);
|
||||
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
||||
}
|
||||
});
|
||||
void test('association adaptation survives recovery and both report consumers without resetting old inputs', () => {
|
||||
const c = associationCase(),
|
||||
b = recordAnnual(c.d, c.b, '2026-11-10T16:10:00+02:00'),
|
||||
d = JSON.parse(
|
||||
JSON.stringify({
|
||||
...c.d,
|
||||
modelo_a_snapshot: saveAnnualBook(c.d, b),
|
||||
}),
|
||||
),
|
||||
back = annualBook(d);
|
||||
assert.equal(annualCurrent(d, back), true);
|
||||
assert.deepEqual(
|
||||
calculateAnnual(d, back).economicCredit,
|
||||
back.result.model.economicCredit,
|
||||
);
|
||||
assert.match(annualHtml(d), /IRPC-economic-association\/1/);
|
||||
assert.match(
|
||||
JSON.stringify(
|
||||
createProjectDossierReport(d, {
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-10T16:10:00+02:00',
|
||||
}),
|
||||
),
|
||||
/IRPC-economic-association\/1/,
|
||||
);
|
||||
});
|
||||
@@ -79,11 +79,7 @@ void test('article40 exclusion, payer exemption/foreign residence and special di
|
||||
const m = pending(c);
|
||||
assert.equal(m.internationalCredit.positions.length, 1);
|
||||
assert.equal(number(m.internationalCredit.positions[0].eligible), 8);
|
||||
if (
|
||||
patch.article40 === 'yes' ||
|
||||
patch.kind === 'liquidation' ||
|
||||
patch.kind === 'association'
|
||||
)
|
||||
if (patch.article40 === 'yes')
|
||||
assert.equal(m.economicCredit.rows[0].status, 'outside_scope');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
||||
import {
|
||||
normalBook,
|
||||
calculateNormal,
|
||||
recordNormal,
|
||||
saveNormalBook,
|
||||
normalCurrent,
|
||||
normalHtml,
|
||||
} from '../../resources/js/lib/irpc-normal.ts';
|
||||
import { calculateAnnual } from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import {
|
||||
prepareEconomicInclusion,
|
||||
calculateEconomicInclusions,
|
||||
} from '../../resources/js/lib/irpc-normal-economic.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
|
||||
function caseInput() {
|
||||
const c = economicCase();
|
||||
const source = structuredClone(c.b.economicCredits.rows[0]);
|
||||
Object.assign(source, {
|
||||
incomeIncluded: 'no',
|
||||
incomeReference: 'SYNTHETIC not yet included',
|
||||
grossUpIncluded: '0',
|
||||
grossUpReference: 'SYNTHETIC no gross-up yet',
|
||||
});
|
||||
return {
|
||||
...c,
|
||||
normal: normalBook(c.d),
|
||||
inclusion: {
|
||||
source,
|
||||
profitAlreadyIncluded: '0',
|
||||
creditAlreadyIncluded: '0',
|
||||
reference:
|
||||
'SYNTHETIC QA complete reconciliation before this map, not a real accounting assertion',
|
||||
},
|
||||
};
|
||||
}
|
||||
void test('economic inclusion adds only the missing profits and derived60percent to current L6', () => {
|
||||
const c = caseInput(),
|
||||
old = structuredClone(c.normal.result);
|
||||
const b = prepareEconomicInclusion(c.normal, c.inclusion),
|
||||
m = calculateNormal(c.d, b);
|
||||
assert.deepEqual(m.economicInclusions.pending, []);
|
||||
assert.deepEqual(m.economicInclusions.net, {
|
||||
numerator: '112',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(m.taxableProfit, { numerator: '6812', denominator: '1' });
|
||||
assert.deepEqual(m.taxableBase, { numerator: '4512', denominator: '1' });
|
||||
assert.deepEqual(m.colecta, { numerator: '36096', denominator: '25' });
|
||||
assert.deepEqual(c.normal.result, old);
|
||||
});
|
||||
void test('economic inclusion is repeatable and replaces the same parcel instead of accumulating corrections', () => {
|
||||
const c = caseInput(),
|
||||
once = prepareEconomicInclusion(c.normal, c.inclusion);
|
||||
assert.deepEqual(prepareEconomicInclusion(once, c.inclusion), once);
|
||||
const alias = structuredClone(c.inclusion);
|
||||
alias.source.distributionDocument =
|
||||
' ' + alias.source.distributionDocument.toLowerCase() + ' ';
|
||||
assert.equal(
|
||||
prepareEconomicInclusion(once, alias).economicInclusions.rows.length,
|
||||
1,
|
||||
);
|
||||
const changed = structuredClone(c.inclusion);
|
||||
changed.source.income = '200';
|
||||
const next = prepareEconomicInclusion(once, changed);
|
||||
assert.equal(next.economicInclusions.rows.length, 1);
|
||||
assert.equal(next.profit.topics.incomeCorrections.amount, '212.00');
|
||||
assert.deepEqual(calculateNormal(c.d, next).taxableProfit, {
|
||||
numerator: '6912',
|
||||
denominator: '1',
|
||||
});
|
||||
});
|
||||
void test('economic inclusion does not add amounts already considered and can correct documented over-inclusion', () => {
|
||||
const c = economicCase(),
|
||||
source = c.b.economicCredits.rows[0],
|
||||
b = normalBook(c.d);
|
||||
const row = {
|
||||
source,
|
||||
profitAlreadyIncluded: '100',
|
||||
creditAlreadyIncluded: '12',
|
||||
reference: 'SYNTHETIC already included once',
|
||||
};
|
||||
assert.deepEqual(
|
||||
calculateNormal(c.d, prepareEconomicInclusion(b, row)).colecta,
|
||||
b.result.model.colecta,
|
||||
);
|
||||
const correction = structuredClone(row);
|
||||
correction.profitAlreadyIncluded = '150';
|
||||
correction.creditAlreadyIncluded = '20';
|
||||
correction.source.grossUpIncluded = '20';
|
||||
const m = calculateNormal(c.d, prepareEconomicInclusion(b, correction));
|
||||
assert.deepEqual(m.economicInclusions.net, {
|
||||
numerator: '-58',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(m.taxableProfit, { numerator: '6642', denominator: '1' });
|
||||
});
|
||||
void test('economic inclusion rejects contradictory prior inclusion, duplicate origins, different taxpayers and unsupported fractional cents', () => {
|
||||
const c = caseInput();
|
||||
const contradiction = structuredClone(c.inclusion);
|
||||
contradiction.source.incomeIncluded = 'yes';
|
||||
assert.throws(
|
||||
() => prepareEconomicInclusion(c.normal, contradiction),
|
||||
/declara os lucros/,
|
||||
);
|
||||
const duplicate = calculateEconomicInclusions(
|
||||
{
|
||||
version: 1,
|
||||
rows: [
|
||||
c.inclusion,
|
||||
{
|
||||
...c.inclusion,
|
||||
source: { ...c.inclusion.source, id: 'another-id' },
|
||||
},
|
||||
],
|
||||
},
|
||||
c.normal.base.subjectNuit,
|
||||
'2026',
|
||||
);
|
||||
assert.ok(duplicate.pending.some((e) => e.includes('repetida')));
|
||||
const other = structuredClone(c.inclusion);
|
||||
other.source.subjectNuit = '987654321';
|
||||
assert.throws(() => prepareEconomicInclusion(c.normal, other));
|
||||
const partial = structuredClone(c.inclusion);
|
||||
partial.source.taxAmount = '20.01';
|
||||
partial.source.proofAmount = '20.01';
|
||||
assert.throws(() => prepareEconomicInclusion(c.normal, partial), /cêntimo/);
|
||||
});
|
||||
void test('economic inclusion keeps recovery, previous result and reports while making the old L8 origin stale', () => {
|
||||
const c = caseInput(),
|
||||
previous = structuredClone(c.normal.result);
|
||||
const b = recordNormal(
|
||||
c.d,
|
||||
prepareEconomicInclusion(c.normal, c.inclusion),
|
||||
'2026-11-10T15:00:00+02:00',
|
||||
);
|
||||
const d = JSON.parse(
|
||||
JSON.stringify({ ...c.d, modelo_a_snapshot: saveNormalBook(c.d, b) }),
|
||||
);
|
||||
const recovered = normalBook(d);
|
||||
assert.equal(normalCurrent(d, recovered), true);
|
||||
assert.deepEqual(recovered.history.at(-1), previous);
|
||||
assert.deepEqual(
|
||||
calculateNormal(d, recovered).economicInclusions,
|
||||
recovered.result.model.economicInclusions,
|
||||
);
|
||||
assert.match(normalHtml(d), /IRPC-economic-inclusion\/1/);
|
||||
assert.match(
|
||||
JSON.stringify(
|
||||
createProjectDossierReport(d, {
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-10T15:00:00+02:00',
|
||||
}),
|
||||
),
|
||||
/IRPC-economic-inclusion\/1/,
|
||||
);
|
||||
assert.equal(calculateAnnual(d, c.b).arithmeticBalance, null);
|
||||
});
|
||||
|
||||
void test('special inclusion reconciles the whole taxable partilha once but keeps only its eligible component in the credit', () => {
|
||||
const c = caseInput();
|
||||
Object.assign(c.inclusion.source, {
|
||||
kind: 'liquidation',
|
||||
income: '150',
|
||||
liquidation: {
|
||||
attributed: '200',
|
||||
paidInCapital: '100',
|
||||
reference:
|
||||
'SYNTHETIC capital component100 and gain50 included in taxable income150',
|
||||
},
|
||||
});
|
||||
const b = prepareEconomicInclusion(c.normal, c.inclusion),
|
||||
m = calculateNormal(c.d, b);
|
||||
assert.deepEqual(m.economicInclusions.net, {
|
||||
numerator: '162',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(m.taxableBase, { numerator: '4562', denominator: '1' });
|
||||
assert.match(m.economicInclusions.effects[0].reason, /mais-valia 50.00/);
|
||||
assert.deepEqual(prepareEconomicInclusion(b, c.inclusion), b);
|
||||
const already = structuredClone(c.inclusion);
|
||||
Object.assign(already, {
|
||||
profitAlreadyIncluded: '150',
|
||||
creditAlreadyIncluded: '12',
|
||||
});
|
||||
Object.assign(already.source, {
|
||||
incomeIncluded: 'yes',
|
||||
grossUpIncluded: '12',
|
||||
});
|
||||
assert.deepEqual(
|
||||
calculateNormal(c.d, prepareEconomicInclusion(c.normal, already))
|
||||
.colecta,
|
||||
c.normal.result.model.colecta,
|
||||
);
|
||||
});
|
||||
void test('association inclusion requires its specific evidence and does not infer effective taxation', () => {
|
||||
const c = caseInput();
|
||||
Object.assign(c.inclusion.source, {
|
||||
kind: 'association',
|
||||
association: {
|
||||
kind: 'participation',
|
||||
effectivelyTaxed: '',
|
||||
reference: 'SYNTHETIC contract',
|
||||
},
|
||||
});
|
||||
assert.throws(
|
||||
() => prepareEconomicInclusion(c.normal, c.inclusion),
|
||||
/efectivamente tributados/,
|
||||
);
|
||||
c.inclusion.source.association.effectivelyTaxed = 'yes';
|
||||
assert.deepEqual(
|
||||
calculateNormal(c.d, prepareEconomicInclusion(c.normal, c.inclusion))
|
||||
.economicInclusions.net,
|
||||
{ numerator: '112', denominator: '1' },
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
||||
import { economicIncome } from '../../resources/js/lib/irpc-economic-credit.ts';
|
||||
import {
|
||||
calculateAnnual,
|
||||
recordAnnual,
|
||||
saveAnnualBook,
|
||||
annualBook,
|
||||
annualCurrent,
|
||||
annualHtml,
|
||||
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
export function liquidationCase() {
|
||||
const c = economicCase();
|
||||
Object.assign(c.b.economicCredits.rows[0], {
|
||||
kind: 'liquidation',
|
||||
income: '150',
|
||||
liquidation: {
|
||||
attributed: '200',
|
||||
paidInCapital: '100',
|
||||
reference:
|
||||
'SYNTHETIC QA partilha: capital income150 documented; eligible100 and excess50 separately classified',
|
||||
},
|
||||
nationalMethod: 'proportional',
|
||||
nationalBasisReference:
|
||||
'SYNTHETIC eligible100 plus nominal12 in ordinary base4400',
|
||||
incomeReference:
|
||||
'SYNTHETIC150 included in current L6, eligible100 and capital gain50 distinguished',
|
||||
});
|
||||
return c;
|
||||
}
|
||||
void test('liquidation caps the economic-credit component and separates capital gain without changing L6', () => {
|
||||
const c = liquidationCase(),
|
||||
before = c.d.modelo_a_snapshot,
|
||||
m = calculateAnnual(c.d, c.b),
|
||||
r = m.economicCredit.rows[0];
|
||||
assert.deepEqual(m.pending, []);
|
||||
assert.deepEqual(r.liquidation.eligibleIncome, {
|
||||
numerator: '100',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(r.liquidation.excessCapitalGain, {
|
||||
numerator: '50',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.deepEqual(r.nationalLimit, { numerator: '896', denominator: '25' });
|
||||
assert.deepEqual(r.nominal, { numerator: '12', denominator: '1' });
|
||||
assert.equal(c.d.modelo_a_snapshot, before);
|
||||
});
|
||||
void test('liquidation handles documented lower capital income and nonpositive capital ceiling', () => {
|
||||
const c = liquidationCase(),
|
||||
r = c.b.economicCredits.rows[0];
|
||||
r.income = '40';
|
||||
assert.deepEqual(economicIncome(r).income, {
|
||||
numerator: '40',
|
||||
denominator: '1',
|
||||
});
|
||||
r.liquidation.paidInCapital = '250';
|
||||
assert.deepEqual(economicIncome(r).income, {
|
||||
numerator: '0',
|
||||
denominator: '1',
|
||||
});
|
||||
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
||||
});
|
||||
void test('liquidation rejects unknown evidence, attribution contradictions and stale collection', () => {
|
||||
for (const patch of [
|
||||
{ liquidation: undefined },
|
||||
{
|
||||
liquidation: {
|
||||
attributed: '',
|
||||
paidInCapital: '0',
|
||||
reference: 'QA',
|
||||
},
|
||||
},
|
||||
{
|
||||
liquidation: {
|
||||
attributed: '100',
|
||||
paidInCapital: '0',
|
||||
reference: 'QA',
|
||||
},
|
||||
},
|
||||
{ assessmentKey: 'stale' },
|
||||
]) {
|
||||
const c = liquidationCase();
|
||||
Object.assign(c.b.economicCredits.rows[0], patch);
|
||||
assert.equal(calculateAnnual(c.d, c.b).arithmeticBalance, null);
|
||||
}
|
||||
});
|
||||
void test('liquidation recovers the exact cap and excess in both report consumers, retaining old history', () => {
|
||||
const c = liquidationCase(),
|
||||
book = recordAnnual(c.d, c.b, '2026-11-10T16:00:00+02:00');
|
||||
const d = JSON.parse(
|
||||
JSON.stringify({
|
||||
...c.d,
|
||||
modelo_a_snapshot: saveAnnualBook(c.d, book),
|
||||
}),
|
||||
),
|
||||
b = annualBook(d);
|
||||
assert.equal(annualCurrent(d, b), true);
|
||||
assert.deepEqual(
|
||||
calculateAnnual(d, b).economicCredit,
|
||||
b.result.model.economicCredit,
|
||||
);
|
||||
assert.match(annualHtml(d), /IRPC-economic-liquidation\/1/);
|
||||
const report = JSON.stringify(
|
||||
createProjectDossierReport(d, {
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-10T16:00:00+02:00',
|
||||
}),
|
||||
);
|
||||
assert.match(report, /IRPC-economic-liquidation\/1/);
|
||||
assert.match(report, /mais-valia/);
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { economicCase } from './helpers/irpc-economic-case.mjs';
|
||||
import {
|
||||
calculateAnnual,
|
||||
recordAnnual,
|
||||
saveAnnualBook,
|
||||
annualBook,
|
||||
annualCurrent,
|
||||
annualHtml,
|
||||
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import { createProjectDossierReport } from '../../resources/js/lib/project-dossier-report.ts';
|
||||
|
||||
function quotaCase() {
|
||||
const c = economicCase();
|
||||
Object.assign(c.b.economicCredits.rows[0], {
|
||||
nationalMethod: 'proportional',
|
||||
nationalBasisReference:
|
||||
'SYNTHETIC QA: profits100 plus nominal60 already included and reconciled in current ordinary base4400',
|
||||
taxAmount: '100',
|
||||
proofAmount: '100',
|
||||
grossUpIncluded: '60',
|
||||
grossUpReference:
|
||||
'SYNTHETIC QA: nominal60 already included; no base change',
|
||||
});
|
||||
return c;
|
||||
}
|
||||
void test('economic quota derives from profits plus the existing gross-up, without changing L6', () => {
|
||||
const c = quotaCase(),
|
||||
before = c.d.modelo_a_snapshot;
|
||||
const m = calculateAnnual(c.d, c.b);
|
||||
assert.deepEqual(m.pending, []);
|
||||
assert.deepEqual(m.economicCredit.rows[0].nationalLimit, {
|
||||
numerator: '256',
|
||||
denominator: '5',
|
||||
});
|
||||
assert.deepEqual(m.economicCredit.deducted, {
|
||||
numerator: '256',
|
||||
denominator: '5',
|
||||
});
|
||||
assert.deepEqual(m.payable, { numerator: '3244', denominator: '5' });
|
||||
assert.equal(c.d.modelo_a_snapshot, before);
|
||||
assert.equal(m.economicCredit.rows[0].input.nationalLimit, '32');
|
||||
});
|
||||
void test('economic quota survives saving and recovery into both report consumers with its origin', () => {
|
||||
const c = quotaCase();
|
||||
const book = recordAnnual(c.d, c.b, '2026-11-10T14:00:00+02:00');
|
||||
const d = JSON.parse(
|
||||
JSON.stringify({
|
||||
...c.d,
|
||||
modelo_a_snapshot: saveAnnualBook(c.d, book),
|
||||
}),
|
||||
);
|
||||
const recovered = annualBook(d);
|
||||
assert.equal(annualCurrent(d, recovered), true);
|
||||
assert.deepEqual(
|
||||
calculateAnnual(d, recovered).economicCredit,
|
||||
recovered.result.model.economicCredit,
|
||||
);
|
||||
assert.match(annualHtml(d), /IRPC-economic-quota\/1/);
|
||||
assert.match(
|
||||
JSON.stringify(
|
||||
createProjectDossierReport(d, {
|
||||
selectedSections: new Set(['finance']),
|
||||
generatedAt: '2026-11-10T14:00:00+02:00',
|
||||
}),
|
||||
),
|
||||
/256\/5/,
|
||||
);
|
||||
});
|
||||
void test('economic quota requires support, positive matched base and a still-current assessment', () => {
|
||||
for (const patch of [
|
||||
{ nationalBasisReference: '' },
|
||||
{ income: '4500' },
|
||||
{ assessmentKey: 'obsolete' },
|
||||
{ grossUpIncluded: '0' },
|
||||
]) {
|
||||
const c = quotaCase();
|
||||
Object.assign(c.b.economicCredits.rows[0], patch);
|
||||
const m = calculateAnnual(c.d, c.b);
|
||||
assert.equal(m.status, 'indeterminate');
|
||||
assert.equal(m.arithmeticBalance, null);
|
||||
}
|
||||
});
|
||||
void test('economic quota defaults to the accepted documented path for old books', () => {
|
||||
const c = economicCase();
|
||||
const m = calculateAnnual(c.d, c.b);
|
||||
assert.equal(m.economicCredit.rows[0].nationalDerivation, undefined);
|
||||
assert.deepEqual(m.economicCredit.rows[0].nationalLimit, {
|
||||
numerator: '32',
|
||||
denominator: '1',
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user