commit de compras
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\DB;
|
||||
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);if(!($s['invoices']??false)||is_file($s['root'].'/invoice-baseline.json'))throw new LogicException('Fresh invoice composition required');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();App\Modules\Purchasing\BudgetAdapter::guard();$f=json_decode(file_get_contents($s['root'].'/fixture.json'),true);$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);if(!$n['finance_reviewer']||!$n['finance_auditor'])throw new LogicException('Distinct native finance identities required');$old=DB::selectOne("SELECT pg_get_constraintdef(oid) d FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'")->d;if(!preg_match('/^CHECK\s*\((.*)\)$/s',$old,$m))throw new LogicException('QA constraint required');DB::statement('ALTER TABLE permission_grants DROP CONSTRAINT permission_grants_scope_check');DB::statement("ALTER TABLE permission_grants ADD CONSTRAINT permission_grants_scope_check CHECK (({$m[1]}) OR (unit_id IS NOT NULL AND permission IN ('purchasing_invoices.view','purchasing_invoices.prepare','purchasing_invoices.validate')))");
|
||||
foreach(['reviewer','auditor']as$role){$user=App\Models\User::create(['name'=>'QA invoice '.$role,'email'=>$role.'-'.Illuminate\Support\Str::uuid().'@example.invalid','password'=>Illuminate\Support\Str::random(40)]);$f[$role]=$user->id;DB::table('company_memberships')->insert(['user_id'=>$user->id,'tenant_id'=>$f['tenant'],'company_id'=>$f['company']]);foreach(['company.view'=>null,'unit.view'=>$f['unit']]as$right=>$unit)DB::table('permission_grants')->insert(['user_id'=>$user->id,'tenant_id'=>$f['tenant'],'company_id'=>$f['company'],'unit_id'=>$unit,'permission'=>$right,'created_at'=>now(),'updated_at'=>now()]);}
|
||||
foreach(['issuer'=>['view','prepare','validate'],'reviewer'=>['view','validate'],'auditor'=>['view','validate']]as$role=>$rights)foreach($rights as$r)DB::table('permission_grants')->insert($f['scope']+['user_id'=>$f[$role],'permission'=>'purchasing_invoices.'.$r,'created_at'=>now(),'updated_at'=>now()]);$file=$s['root'].'/binding.json';$p=json_decode(file_get_contents($file),true);$prefix=implode(':',array_values($f['scope'])).':';$base=$p['bindings'][$prefix.$f['issuer']];foreach(['issuer'=>'finance','reviewer'=>'finance_reviewer','auditor'=>'finance_auditor']as$role=>$native){$p['bindings'][$prefix.$f[$role]]=$base;$p['bindings'][$prefix.$f[$role]]['actor_id']=$n[$native];}$p['internal_manifest_sha256']=hash_file('sha256',$s['root'].'/internal/manifest.json');file_put_contents($file,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));file_put_contents($s['root'].'/fixture.json',json_encode($f,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));file_put_contents($s['root'].'/invoice-baseline.json',json_encode(['passed'=>true,'approved_award'=>!($s['integrated']??false),'initial_orders'=>0,'initial_receipts'=>0,'initial_invoices'=>0,'initial_consumptions'=>0,'native_main_reserved_minor'=>10000,'native_main_committed_minor'=>0,'qa_rights'=>['purchasing_invoices.view','purchasing_invoices.prepare','purchasing_invoices.validate']],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|
||||
Reference in New Issue
Block a user