Files
SGF/scripts/ledger-industrial-correction-deep-scope.php
T
2026-11-04 09:37:20 +02:00

7 lines
2.5 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
use App\Shared\Context\CompanyContext;
$out=$s['root'].'/industrial-correction-deep-scope.json';if(file_exists($out))throw new LogicException('Completed scope proof preserved');$checks=0;$ok=function($v,$m)use(&$checks){$checks++;if(!$v)throw new LogicException($m);};
foreach(['unit','company','tenant'] as $kind){DB::beginTransaction();try{$u=$enter('prepare');$company=$kind==='unit'?DB::table('companies')->where('id',$scope['company_id'])->first():($kind==='company'?DB::table('companies')->where('tenant_id',$scope['tenant_id'])->where('id','<>',$scope['company_id'])->first():DB::table('companies')->where('tenant_id','<>',$scope['tenant_id'])->first());$unit=DB::table('units')->insertGetId(['tenant_id'=>$company->tenant_id,'company_id'=>$company->id,'name'=>'Rollback-only correction foreign '.$kind,'created_at'=>now(),'updated_at'=>now()]);if(!DB::table('company_memberships')->where(['tenant_id'=>$company->tenant_id,'company_id'=>$company->id,'user_id'=>$u->id])->exists())DB::table('company_memberships')->insert(['tenant_id'=>$company->tenant_id,'company_id'=>$company->id,'user_id'=>$u->id]);foreach(['company.view'=>null,'unit.view'=>$unit,'industrial_costs.view'=>$unit,'industrial_costs.view'=>$unit,'general_ledger.view'=>$unit,'general_ledger.correct_prepare'=>$unit] as $right=>$v)Tests\Support\IdentityFixture::grant($u->id,$company->tenant_id,$company->id,$right,$v);DB::table('pa_access')->insert(['tenant_id'=>$company->tenant_id,'company_id'=>$company->id,'unit_id'=>$unit,'user_id'=>$u->id,'action'=>'view','person'=>'cost-qa-person-'.$u->id]);app(CompanyContext::class)->selectFor($u->id,$company->tenant_id,$company->id,$unit);$caught=false;try{$ledger->engine($u)->command('correct-prepare',$correctionBody,(string)Illuminate\Support\Str::uuid());}catch(DomainException|Symfony\Component\HttpKernel\Exception\HttpException){$caught=true;}$ok($caught,'Eligible foreign '.$kind.' cannot correct original');}finally{while(DB::transactionLevel())DB::rollBack();$enter('prepare');}}
$ok($originalsIntact(),'All original source/outbox/rights preserved after fully eligible foreign-context probes');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'foreign_tenant_company_unit_fully_eligible'=>true,'foreign_accounting_person_and_rights_present'=>true,'original_journal_refused_by_scope'=>true,'rollback_only'=>true,'source_outbox_rights_exact'=>true],JSON_PRETTY_PRINT));echo "Deep industrial scope: $checks checks with full foreign accounting access/person; original refused.\n";