Files
SGF/scripts/sgf-fiscal-coverage-proof.php
2026-11-11 09:00:17 +02:00

13 lines
2.8 KiB
PHP

<?php
require __DIR__.'/sgf-single-bootstrap.php';
use Illuminate\Support\Facades\Auth;
use App\Shared\Context\CompanyContext;
use App\Modules\Services\{ServiceFiscal,FiscalCoverage};
$checks=[];$ok=function($v,$n)use(&$checks){if(!$v)throw new RuntimeException($n);$checks[]=$n;};
$tables=['sf_proposals','sf_decisions','sf_activation_events','service_calculation_results','permission_grants'];$before=[];foreach($tables as$table)$before[$table]=$host->table($table)->orderBy('id')->get()->toJson();
$read=function($actor=13,$unit=2,$acting=null)use($app){Auth::forgetGuards();Auth::shouldUse('web');$user=App\Models\User::findOrFail($actor);Auth::guard('web')->setUser($user);$session=app('session')->driver();$session->start();$session->put('company_context',['tenant_id'=>1,'company_id'=>2,'unit_id'=>$unit,'module_id'=>'accounting','token'=>'fiscal-coverage-proof']);$r=Illuminate\Http\Request::create('/api/service-fiscal');$r->setUserResolver(fn()=>$user);$r->setLaravelSession($session);$app->instance('request',$r);try{app(CompanyContext::class)->selectFor($actor,1,2,$unit);return app(ServiceFiscal::class)->listing($acting??$actor);}finally{app(CompanyContext::class)->clear();}};
$data=$read();$c=$data['coverage'];$ok($c['version']==='SGF-FISCAL-COVERAGE-v1','versioned capability contract');$ok(array_column($c['taxes'],'id')===['iva','irps','irpc','ispc','ice','inss','other'],'all document tax families explicit');$ok($c['automatic_knowledge_import']===false&&$c['legal_validation']===false&&$c['official_submission_enabled']===false,'no automatic import legal or submission claim');$ok(count(array_filter($c['taxes'],fn($t)=>$t['state']==='partial'))===1,'only IVA partially covered');$ok(!array_filter($c['taxes'],fn($t)=>$t['legal_use']!==false),'no tax declared legally activated');$ok(count($c['rule_lifecycle'])===5,'source validity review and activation separated');$ok(count($c['management'])===3,'finance accounting analysis coverage distinguished');$ok(!str_contains(json_encode($c),'rate_percent'),'catalogue cannot select a rate');
foreach([[4,2,null],[13,1,null],[13,2,14]]as[$actor,$unit,$acting]){try{$read($actor,$unit,$acting);throw new RuntimeException('Expected access refusal');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){$ok($e->getStatusCode()===403,'actor/unit mismatch refused #'.count($checks));}}
$other=$read(14);$ok($other['coverage']===$c,'same product metadata for separately authorized QA reader');foreach($tables as$table)$ok($host->table($table)->orderBy('id')->get()->toJson()===$before[$table],'unchanged '.$table);
file_put_contents($work.'/fiscal-coverage-result.json',json_encode(['passed'=>true,'checks'=>$checks,'business_commands'=>0,'new_rights'=>0,'new_demo'=>false,'fiscal_activation'=>false],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/fiscal-coverage-result.json']).PHP_EOL;