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

13 lines
2.3 KiB
PHP

<?php
require __DIR__.'/sgf-ledger-proof-bootstrap.php';$scope=['tenant_id'=>1,'company_id'=>2,'unit_id'=>2];$before=$native->table('gl_cost_sources')->where($scope)->count();$native->beginTransaction();
try{
$base=(array)$native->table('gl_cost_sources')->where($scope)->first();unset($base['id']);for($i=1;$i<=127;$i++)$native->table('gl_cost_sources')->insert(array_replace($base,['order_id'=>900000+$i,'material_origin'=>'QA-CATALOGUE-ONLY-'.$i,'time_origin'=>'QA-CATALOGUE-TIME-'.$i]));
$native->table('gl_cost_sources')->insert(array_replace($base,['unit_id'=>99,'order_id'=>999999,'material_origin'=>'QA-FOREIGN-CATALOGUE','time_origin'=>'QA-FOREIGN-TIME']));
foreach([25,100] as $size){$seen=[];$page=1;do{
$out=$call('accounting_prepare','view',function($e,$a,$b,$o,$s,$stock,$hostRead)use($page,$size,$native,$ok){$native->enableQueryLog();$start=count($native->getQueryLog());$value=app(App\Modules\Accounting\ComposedLedgerCandidates::class)->read(['source_kind'=>'workshop.direct_cost.validated','source_page'=>$page,'source_per_page'=>$size],$a,$s,$stock,$hostRead);$count=count($native->getQueryLog())-$start;$native->disableQueryLog();$native->flushQueryLog();$ok($count===2,'cost candidate page'.$page.'/'.$size.' uses exactly count and bounded rows queries');return $value;});
$ok(count($out['sources'])<=$size,'candidate page never exceeds requested size'.$size);foreach($out['sources'] as $row){$ok($row['kind']==='workshop.direct_cost.validated'&&$row['id']!==999999,'family filter and unit isolation are retained');$seen[]=$row['id'];}$page++;
}while($page<=$out['source_pagination']['last_page']);$ok(count($seen)===$before+127&&count(array_unique($seen))===count($seen),'all catalogue fixtures traversed once for page size'.$size);}
}finally{while($native->transactionLevel()>0)$native->rollBack();}
$ok($native->table('gl_cost_sources')->where($scope)->count()===$before,'catalogue-only metadata fixtures rolled back; no business source was created');
file_put_contents($work.'/candidate-pages-result.json',json_encode(['passed'=>true,'checks'=>$checks,'catalogue_metadata_fixtures'=>127,'not_business_workflows'=>true,'new_business_effects'=>0,'rolled_back'=>true],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/candidate-pages-result.json']).PHP_EOL;