make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); if(!\App\Modules\Identity\Services\LocalDatabaseGuard::allows())throw new RuntimeException('Own SGF development database required.'); $db=\Illuminate\Support\Facades\DB::class;$grants=[]; foreach([1=>['view','prepare'],2=>['view','validate']] as $user=>$rights){ $u=$db::table('users')->where('id',$user)->first(['id','name','email']);if(!$u||!$db::table('company_memberships')->where(['user_id'=>$user,'tenant_id'=>1,'company_id'=>1])->exists())throw new RuntimeException('Existing account/member required.'); foreach($rights as $r){$permission='direct_costs.'.$r;$scope=['user_id'=>$user,'tenant_id'=>1,'company_id'=>1,'unit_id'=>1,'permission'=>$permission];$grants[]=$scope+['account'=>$u,'already_granted'=>$db::table('permission_grants')->where($scope)->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('Expected scope differs.'); try{\App\Modules\Workshop\DirectCosts::guard();throw new RuntimeException('Real 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,'real_costing_blocked'=>true,'migration_090000_applied'=>$db::table('migrations')->where('migration','2026_10_27_090000_create_workshop_direct_costs')->exists()],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL;