Files
SGF/scripts/industrial-cost-proof.php
2026-10-27 13:57:09 +02:00

11 lines
2.4 KiB
PHP

<?php
require __DIR__.'/../vendor/autoload.php';$app=require __DIR__.'/../bootstrap/app.php';$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();\App\Modules\Industry\IndustrialCosts::guard();
$f=json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/browser-fixture.json'),true,32,JSON_THROW_ON_ERROR);$db=\Illuminate\Support\Facades\DB::class;$rows=$db::table('ic_results')->where('lot_id',$f['industrial']['lot'])->orderBy('version')->get();if($rows->count()<2)throw new RuntimeException('Two browser scenarios required.');
$full=json_decode($rows[0]->snapshot,true);$partial=json_decode($rows[1]->snapshot,true);
foreach(['material_exact'=>'1000','labour_exact'=>'500','indirect_rate_exact'=>'60','allocated_exact'=>'300','residual_exact'=>'300','selected_total_exact'=>'1800','unit_cost_exact'=>'180'] as $k=>$v)if($full[$k]!==$v)throw new RuntimeException('Full scenario differs.');
if($partial['known_cost_exact']!=='800'||$partial['unit_cost_exact']!==null||$partial['selected_total_exact']!==null||!$partial['incomplete']||$partial['reconciliation']['known_origins_exact']!=='1100')throw new RuntimeException('Partial scenario differs.');
foreach([$rows[0],$rows[1]] as $r){$d=$db::table('ic_decisions')->where(['result_id'=>$r->id,'decision'=>'approved'])->first();if(!$d||$d->actor_id===$r->actor_id)throw new RuntimeException('Distinct validation required.');}
if($db::table('wo_entries')->exists()||$db::table('dc_calculations')->exists())throw new RuntimeException('Workshop/direct cost events unexpectedly created.');
$proof=['policy'=>'INDUSTRIAL-COST-SIM-v1','database'=>'sgf_tempo_test','synthetic_only'=>true,'real_browser_login'=>true,'csrf_enabled'=>true,'distinct_roles'=>true,'full'=>['material'=>'1000','labour'=>'500','pool'=>'600','capacity_hm'=>'10','used_hm'=>'5','rate'=>'60','allocated'=>'300','residual'=>'300','cost'=>'1800','good_units'=>'10','unit_cost'=>'180','origins'=>'2100'],'partial'=>['known'=>'800','total'=>null,'unit_cost'=>null,'incomplete'=>true,'known_origins'=>'1100','residual'=>'300'],'workshop_events_created'=>0,'hypothesis_only'=>true,'development_migration_applied'=>false,'real_grants_applied'=>false,'user_acceptance'=>false];
file_put_contents(base_path('docs/proofs/industrial-cost-browser-results.json'),json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo "Browser results checked: 1800/180 and 800 incomplete, residual 300, distinct validations and no duplicated workshop events.\n";