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

13 lines
1.8 KiB
PHP

<?php
// Read-only proposal. No apply or activation branch.
require __DIR__.'/../vendor/autoload.php';$app=require __DIR__.'/../bootstrap/app.php';$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
if(!\App\Modules\Identity\Services\LocalDatabaseGuard::allows())throw new RuntimeException('Own SGF development application database required.');
$db=\Illuminate\Support\Facades\DB::class;$grants=[];
foreach([1=>['view','prepare'],2=>['view','validate']] as $id=>$rights){
$u=$db::table('users')->where('id',$id)->first(['id','name','email']);if(!$u||!$db::table('company_memberships')->where(['user_id'=>$id,'tenant_id'=>1,'company_id'=>1])->exists())throw new RuntimeException('Existing account/member required.');
foreach($rights as $r){$g=['user_id'=>$id,'tenant_id'=>1,'company_id'=>1,'unit_id'=>1,'permission'=>'industrial_costs.'.$r];$grants[]=$g+['account'=>$u,'already_granted'=>$db::table('permission_grants')->where($g)->exists()];}
}
$company=$db::table('companies')->where(['id'=>1,'tenant_id'=>1])->value('name');$unit=$db::table('units')->where(['id'=>1,'company_id'=>1,'tenant_id'=>1])->value('name');if($company!=='Tempo Lda'||$unit!=='SEGI')throw new RuntimeException('Scope differs.');
try{\App\Modules\Industry\IndustrialCosts::guard();throw new RuntimeException('Real industry costing not blocked.');}catch(\Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==403)throw $e;}
echo json_encode(['mode'=>'preview_only','company'=>$company,'unit'=>$unit,'proposed_grants'=>$grants,'applied'=>false,'industrial_real_blocked'=>true,'migration_100000_applied'=>$db::table('migrations')->where('migration','2026_10_27_100000_create_industrial_cost_simulation')->exists()],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL;