Files
SGF/scripts/invoice-progress-demo.php
T
2026-11-04 09:37:20 +02:00

4 lines
2.4 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/invoice-progress-demo.json';if(!($s['invoiceProgress']??false)||is_file($out))throw new LogicException('New matching 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.matching_demo'=>$s['nativeConnection']]);$db=DB::connection('matching_demo');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=fn()=>hash('sha256',json_encode([$db->table('requisitions')->orderBy('id')->get(),$db->table('invoices')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get(),DB::table('permission_grants')->orderBy('id')->get()]));$before=$fingerprint();$ok($db->table('requisitions')->where('tenant_id',$n['tenant'])->count()===0&&$db->table('invoices')->where('tenant_id',$n['tenant'])->count()===0,'new demo contains no main requests or invoices');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8081','http_errors'=>false,'timeout'=>25]);$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/issuer',['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$options=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];$r=$client->get('/purchasing/invoices',$options);$ok($r->getStatusCode()===200,'native-authorised finance workspace remains available');$r=$client->get('/api/purchasing-invoices',$options);$data=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$data['data']===[],'empty invoice workspace invents no matching source');foreach(['supplier-invoice-workspace.mjs','invoice-matching.mjs']as$file){$r=$client->get('/'.$file);$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/'.$file),'served matching module matches '.$file);}$ok($fingerprint()===$before,'demo probes preserve request invoice audit and permission data');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." matching demo checks passed.\n";