Files
SGF/scripts/stock-period-demo.php
2026-11-04 09:37:20 +02:00

16 lines
3.2 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/stock-period-demo.json';if(!($s['stockPeriod']??false)||is_file($out))throw new LogicException('Fresh period demonstration required');
require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.period_demo'=>$s['nativeConnection']]);$db=DB::connection('period_demo');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};
$fingerprint=fn()=>hash('sha256',json_encode([$db->table('stock_items')->orderBy('id')->get(),$db->table('stock_movements')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get(),DB::table('permission_grants')->orderBy('id')->get(),DB::table('identity_audit')->orderBy('id')->get()]));$before=$fingerprint();
$ok($db->table('requisitions')->where('tenant_id',$n['tenant'])->count()===0&&$db->table('stock_movements')->count()===0,'new demo starts without main requests or physical fixtures');
$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8085','http_errors'=>false,'timeout'=>25]);$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/validator',['cookies'=>$jar,'query'=>['module'=>'stock']]);$v=json_decode((string)$r->getBody(),true);$options=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];
$r=$client->get('/api/session',$options);$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['context']['stock']['period_report']===true,'existing session enables the period report only in its QA composition');
$r=$client->get('/api/stock-read?view=period&from=2026-11-01&to=2026-11-03',$options);$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['rows']===[]&&$d['pagination']['total']===0&&$d['period']['timezone']==='UTC','empty source supplies an authorised empty report without invented zero balances');
$r=$client->get('/api/stock-read?view=balances',$options);$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['rows']===[],'existing current-balance view remains available without report date parameters');
$r=$client->get('/',$options);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'id="app"'),'existing React shell is served for report navigation');
$manifest=json_decode(file_get_contents($s['app'].'/public/build/manifest.json'),true);$entry=$manifest['resources/js/app.jsx']['file'];$r=$client->get('/build/'.$entry);$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/build/'.$entry),'served report bundle matches the local build manifest');
$ok($fingerprint()===$before,'demo report reads preserve metadata stock audit and grants');
file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'business_commands'=>0,'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." stock period demo checks passed.\n";