feat: add bounded current-year PEC deduction to annual IRPC QA

This commit is contained in:
2026-10-27 13:15:18 +02:00
parent dc14f01e14
commit 7fdb6b424b
15 changed files with 874 additions and 18 deletions
+15
View File
@@ -0,0 +1,15 @@
<?php
$root=dirname(__DIR__);$operation=$argv[1]??'';
if(!in_array($operation,['routes','test'],true)||basename($root)!=='portal-investidor-sequential-delivery-20261027')throw new RuntimeException('Explicit PEC QA workspace and routes/test operation required.');
foreach(['storage/framework/views','storage/framework/cache','storage/framework/sessions','bootstrap/cache','storage/logs','outputs/irpc-l8-pec-20261027']as$dir)if(!is_dir($root.'/'.$dir))mkdir($root.'/'.$dir,0700,true);
foreach(['APP_BASE_PATH'=>$root,'APP_ENV'=>'testing','APP_KEY'=>'base64:'.base64_encode(str_repeat('Q',32)),'DB_CONNECTION'=>'pgsql','DB_HOST'=>'127.0.0.1','DB_PORT'=>'55441','DB_DATABASE'=>'proactive_investment_20261027_test','DB_USERNAME'=>'postgres','DB_PASSWORD'=>'','DB_URL'=>'','CACHE_STORE'=>'array','SESSION_DRIVER'=>'array','QUEUE_CONNECTION'=>'sync','MAIL_MAILER'=>'array','INVESTMOZ_PEC_QA_OUTPUT'=>'1']as$k=>$v){putenv($k.'='.$v);$_ENV[$k]=$_SERVER[$k]=$v;}
require $root.'/vendor/autoload.php';
spl_autoload_register(function($class)use($root){foreach(['App\\'=>'app/','Tests\\'=>'tests/','Database\\Factories\\'=>'database/factories/']as$prefix=>$dir)if(str_starts_with($class,$prefix)){$file=$root.'/'.$dir.str_replace('\\','/',substr($class,strlen($prefix))).'.php';if(is_file($file)){require $file;return;}}},true,true);
$app=require $root.'/bootstrap/app.php';
(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app);
$c=config('database.connections.pgsql');
if($app->configurationIsCached()||$c['host']!=='127.0.0.1'||(int)$c['port']!==55441||$c['database']!=='proactive_investment_20261027_test'||!empty($c['url']))throw new RuntimeException('PEC QA target rejected');
$pdo=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$c['database'],$c['username'],$c['password']);
if($pdo->query('select current_database()')->fetchColumn()!==$c['database'])throw new RuntimeException('PEC QA identity');
if($operation==='routes'){$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$status=Illuminate\Support\Facades\Artisan::call('wayfinder:generate',['--with-form'=>true]);echo Illuminate\Support\Facades\Artisan::output();exit($status);}
$argv=['phpunit','-c','phpunit.investmoz.xml','tests/Feature/IrpcPecDraftTest.php'];$argc=count($argv);$_SERVER['argv']=$argv;$_SERVER['argc']=$argc;require $root.'/vendor/phpunit/phpunit/phpunit';
+25
View File
@@ -0,0 +1,25 @@
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {fileURLToPath} from 'node:url';
import {annualBook,annualCurrent,calculateAnnual,annualHtml,annualReportRows} from '../resources/js/lib/irpc-annual-settlement.ts';
import {createProjectDossierReport} from '../resources/js/lib/project-dossier-report.ts';
const root=path.dirname(path.dirname(fileURLToPath(import.meta.url)));
assert.equal(path.basename(root),'portal-investidor-sequential-delivery-20261027');
const output=path.join(root,'outputs/irpc-l8-pec-20261027');
const results=[];
for(const name of ['payable','capped','recoverable','missing','prior-use']){
const d=JSON.parse(fs.readFileSync(path.join(output,'recovered-'+name+'.json'),'utf8'));
const book=annualBook(d),model=book.result.model;
assert.equal(annualCurrent(d,book),true);
assert.equal(calculateAnnual(d,book).status,model.status);
const html=annualHtml(d),rows=annualReportRows(d);
const dossier=createProjectDossierReport(d,{selectedSections:new Set(['finance']),generatedAt:'2026-10-27T15:00:00+02:00'});
assert.match(html,/PEC — dedução limitada/);assert.match(JSON.stringify(dossier),/PEC — dedução limitada/);
if(name==='missing'){assert.match(html,/Indeterminado/);assert.equal(model.arithmeticBalance,null);}
fs.writeFileSync(path.join(output,'report-'+name+'.html'),html);
fs.writeFileSync(path.join(output,'dossier-'+name+'.json'),JSON.stringify(dossier));
results.push({case:name,status:model.status,balance:model.arithmeticBalance,pec:model.pecDeduction,rows:rows.length,history:book.history.length,apiRoundTrip:true,current:true,dossier:true});
}
fs.writeFileSync(path.join(output,'recovered-report-receipt.json'),JSON.stringify({synthetic:true,activeChanged:false,results},null,2));
console.log(JSON.stringify(results.map(({case:name,status,balance,history})=>({case:name,status,balance,history})),null,2));