Files
SGF/scripts/direct-cost-permissions-preview.php
T
nala d10ba06edc Close isolated direct cost trial by delegated technical acceptance
Preserve verified 275 MZN and incomplete 175 MZN demonstrations. Keep 090000 and four real cost grants unapplied; real costing and fiscal blocks remain intact.
2026-10-27 12:39:41 +02:00

13 lines
1.8 KiB
PHP

<?php
// Read-only. No apply branch; four prospective cost grants only.
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 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;