commit de compras
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\DB;
|
||||
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true,64,JSON_THROW_ON_ERROR);if(!($s['requests']??false)||file_exists($s['root'].'/request-baseline.json'))throw new LogicException('Fresh request 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);$c=DB::selectOne("SELECT pg_get_constraintdef(oid) definition FROM pg_constraint WHERE conrelid='permission_grants'::regclass AND conname='permission_grants_scope_check'");if(!preg_match('/^CHECK\s*\((.*)\)$/s',$c->definition,$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_requests.view','purchasing_requests.prepare','purchasing_requests.submit','purchasing_requests.approve')))");
|
||||
foreach(['requester','approver']as$role){$u=App\Models\User::create(['name'=>'QA '.$role,'email'=>$role.'-'.Illuminate\Support\Str::uuid().'@example.invalid','password'=>Illuminate\Support\Str::random(40)]);$f[$role]=$u->id;DB::table('company_memberships')->insert(['user_id'=>$u->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(['tenant_id'=>$f['tenant'],'company_id'=>$f['company'],'unit_id'=>$unit,'user_id'=>$u->id,'permission'=>$right,'created_at'=>now(),'updated_at'=>now()]);}
|
||||
foreach(['actor'=>['purchasing_requests.view'],'issuer'=>['purchasing_requests.view'],'requester'=>['purchasing_requests.view','purchasing_requests.prepare','purchasing_requests.submit'],'approver'=>['purchasing_requests.view','purchasing_requests.approve','purchasing_sourcing.view','purchasing_sourcing.evaluate','purchasing_sourcing.approve','purchasing_orders.view']]as$role=>$rights)foreach($rights as$right)DB::table('permission_grants')->insert($f['scope']+['user_id'=>$f[$role],'permission'=>$right,'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['actor']];foreach(['requester'=>'owner','approver'=>'head']as$role=>$native)$p['bindings'][$prefix.$f[$role]]=$base+['actor_id'=>$n[$native]];foreach(['requester'=>'owner','approver'=>'head']as$role=>$native)$p['bindings'][$prefix.$f[$role]]['actor_id']=$n[$native];foreach($p['bindings']as&$b){$b['centre_ids']=[$n['centre']];$b['requisition_ids']=[];}unset($b);$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'].'/request-baseline.json',json_encode(['passed'=>true,'main_requests'=>0,'main_reserved_minor'=>0,'main_committed_minor'=>0,'quotes'=>0,'awards'=>0,'orders'=>0,'receipts'=>0,'movements'=>0,'legacy_ir_not_enabled'=>true],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|
||||
Reference in New Issue
Block a user