selectOne('SELECT current_database() AS database,inet_server_port() AS port'); if($target!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441])throw new RuntimeException('QA only'); $db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY'); try{ $proof=['at'=>gmdate('c'),'target'=>$target,'SQL_read_only'=>true,'active_writes'=>0,'browser_observed'=>false,'no_new_submission'=>true,'business_interest_records'=>[]]; $p=json_decode(file_get_contents(__DIR__.'/business-country-variants.json'),true);$refs=$p['synthetic_references']; foreach([14,15]as$id){ $i=App\Models\InterestRequest::findOrFail($id);if($i->investor_type!=='empresa')throw new RuntimeException('Prior proof does not cover entity branch'); $counts=['receipts'=>$db->table('interest_submission_receipts')->where('interest_request_id',$id)->count(),'consents'=>$db->table('consents')->where('interest_request_id',$id)->count(),'outbox'=>$db->table('outbox_events')->where('aggregate_id',$i->integration_id)->count()]; if(array_filter($counts,fn($n)=>$n!==1))throw new RuntimeException('Duplicate retained entity submission'); $proof['business_interest_records'][]=['id'=>$id,'reference'=>$i->reference,'type'=>$i->investor_type,'country'=>$i->country,'origin'=>$i->metadata['declared_origin_country_code']??null,'business_id'=>$i->existing_business_id,'single_records'=>$counts]; } $org=$db->table('organizations')->where('id','99964753-2632-4658-a687-8ebc6a178296')->first(); $proof['organization_master']=['id'=>$org->id,'version'=>$org->version_no,'country'=>$org->incorporation_country_code,'source_system'=>$org->source_system]; $proof['companies']=[];foreach($db->table('investment_company_declarations')->where('user_id',21)->get()as$c){ $v=json_decode(Illuminate\Support\Facades\Crypt::decryptString($c->payload),true);$s=$v['organization_country_snapshot']??null; $proof['companies'][]=['id'=>$c->id,'version'=>$c->version,'declared_country'=>$v['country']??null,'incorporation_country'=>$v['incorporation_country_code']??null,'snapshot'=>$s]; } $proof['submissions']=[];foreach(App\Models\InvestmentSubmission::where('user_id',21)->get()as$s){ $v=$s->payload;$proof['submissions'][]=['id'=>$s->id,'status'=>$s->status,'version'=>$s->version,'country'=>$v['country']??null,'residence_country'=>$v['residence_country_code']??null,'incorporation_country'=>$v['incorporation_country_code']??null,'origin'=>$v['declared_origin_country_code']??null,'snapshot'=>$v['organization_country_snapshot']??null]; } $dest=__DIR__.'/option-B6-reuse-countries.json';if(is_file($dest))throw new RuntimeException('Preserve read-only evidence'); file_put_contents($dest,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL; }finally{$db->rollBack();}