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

18 lines
2.1 KiB
PHP

<?php
use Illuminate\Support\Facades\{Auth,DB};
use Illuminate\Support\Str;
use App\Shared\Context\CompanyContext;
use App\Modules\Accounting\ComposedLedger;
$book??='regression';require __DIR__.'/sgf-single-bootstrap.php';
$profiles=json_decode(file_get_contents($s['root'].'/single-profiles.json'),true)['profiles'];$pins=json_decode(file_get_contents($s['root'].'/single-binding-pins.json'),true);
if(is_file($s['root'].'/single-material-perimeter.json'))config(['sgf_single_installation.material_perimeter_sha256'=>hash_file('sha256',$s['root'].'/single-material-perimeter.json')]);
config(['sgf_single_installation.enabled'=>true,'sgf_single_installation.ledger_enabled'=>true,'sgf_single_installation.schema_sha256'=>$host->table('sgf_composition_schema')->value('source_hash'),'sgf_single_installation.profiles_sha256'=>App\Shared\Installation\SyntheticProfiles::fingerprint(App\Shared\Installation\SyntheticProfiles::policy()),'sgf_single_installation.bindings_sha256'=>$pins['single-bindings.json']]);
$checks=[];$ok=function($v,$name)use(&$checks,$work){if(!$v)throw new RuntimeException($name);$checks[]=$name;file_put_contents($work.'/ledger-progress.json',json_encode($checks));};
$tokens=['accounting_prepare'=>'fixed-preparer-generation','accounting_review'=>'fixed-reviewer-generation','read_only'=>'fixed-reader-generation'];
$call=function($role,$action,Closure $fn)use($app,$profiles,$f,$tokens){
Auth::forgetGuards();Auth::shouldUse('web');$user=App\Models\User::findOrFail($profiles[$role]['user_id']);Auth::guard('web')->setUser($user);
$session=app('session')->driver();$session->start();$session->put('company_context',$f['scope']+['token'=>$tokens[$role],'module_id'=>'accounting']);$r=Illuminate\Http\Request::create('/api/general-ledger','GET');$r->attributes->set('sgf_module','accounting');$r->setLaravelSession($session);$r->setUserResolver(fn()=>$user);$app->instance('request',$r);app(CompanyContext::class)->selectFor($user->id,$f['tenant'],$f['company'],$f['unit']);
try{return app(ComposedLedger::class)->run($action,$fn);}finally{app(CompanyContext::class)->clear();}
};