Files
SGF/scripts/sgf-human-resources-personnel-access-readonly.php
2026-11-11 09:00:17 +02:00

4 lines
1.6 KiB
PHP

<?php
$book=$argv[1]??'8085';require __DIR__.'/sgf-single-bootstrap.php';$rights=[];foreach(['contracts','attendance','leave']as$area)foreach(['view','prepare','review']as$action)$rights[]='human_resources.'.$area.'.'.$action;
$host->beginTransaction();$host->statement('SET TRANSACTION READ ONLY');try{$rows=$host->table('hr_qa_profiles')->orderBy('profile_key')->get();$pin=App\Shared\Installation\HumanResourcesProfiles::fingerprint(App\Shared\Installation\HumanResourcesProfiles::policy());if($rows->count()!==3||!$rows->every(fn($r)=>hash_equals($pin,$r->source_hash)&&$r->tenant_id===1&&$r->company_id===2&&$r->unit_id===2))throw new LogicException('Existing approved HR profiles required');$grants=$host->table('permission_grants')->whereIn('permission',$rights)->get(['user_id','permission','tenant_id','company_id','unit_id'])->all();if($grants!==[])throw new LogicException('Reconcile current personnel grants before proposal');$versions=$host->table('rm_versions')->count();$receipts=$host->table('rm_commands')->count();$out=['passed'=>true,'book'=>$book,'proposed_rights'=>$rights,'existing_proposed_grants'=>$grants,'existing_profile_keys'=>$rows->pluck('profile_key')->all(),'original_hr_profile_pin'=>$pin,'payroll_versions'=>$versions,'payroll_receipts'=>$receipts,'new_grants'=>0,'new_users'=>0,'business_writes'=>0];}finally{$host->rollBack();}file_put_contents($work.'/hr-personnel-access-readonly.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'book'=>$book,'missing_right_names'=>count($rights),'existing_proposed_grants'=>count($grants),'proof'=>$work.'/hr-personnel-access-readonly.json']).PHP_EOL;