10 lines
2.5 KiB
PHP
10 lines
2.5 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/supplier-search-seed.json';if(!($s['supplierSearch']??false)||is_file($out))throw new LogicException('Fresh selector fixture 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);config(['database.connections.selector_seed'=>$s['nativeConnection']]);$db=DB::connection('selector_seed');if($db->table('quotations')->count())throw new LogicException('No prior sourcing operations allowed');
|
|
$profile=$s['root'].'/binding.json';$bytes=file_get_contents($profile);$p=json_decode($bytes,true);$base=(array)$db->table('suppliers')->where('id',$n['supplier_ids'][0])->first();unset($base['id']);$ids=[];$bound=[];
|
|
$db->transaction(function()use($db,$base,$n,$f,&$ids,&$bound){for($i=1;$i<=127;$i++){$row=$base;$row['name']=$i===127?'QA Literal%_Supplier':'QA Catalog'.str_pad((string)$i,4,'0',STR_PAD_LEFT);$row['nuit']=(string)(900000000+$i);$row['blocked']=$i===121;$row['status']=$i===122?'suspended':'active';$row['next_review']=$i===123?date('Y-m-d',strtotime('-1 day')):date('Y-m-d',strtotime('+1 year'));$ids[$i]=$db->table('suppliers')->insertGetId($row);if($i<=123||$i===127)$bound[]=$ids[$i];}
|
|
foreach([125=>$f['unit'],126=>$f['foreign_unit']]as$i=>$unit){$scope=hash('sha256',implode(':',[$f['tenant'],$f['company'],$unit]));$db->table('audit_logs')->insert(['tenant_id'=>$n['tenant'],'user_id'=>$n['buyer'],'requisition_id'=>null,'action'=>'sgf.supplier.command','before'=>null,'after'=>json_encode(['supplier_scope'=>$scope,'result'=>['supplier_id'=>$ids[$i]],'qa_fixture'=>'selector volume and origin boundary']),'created_at'=>now()]);}
|
|
});
|
|
foreach($p['bindings']as&$binding)$binding['supplier_ids']=array_merge($binding['supplier_ids']??[],$bound);unset($binding);file_put_contents($profile,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|
|
file_put_contents($out,json_encode(['passed'=>true,'generated_suppliers'=>127,'expected_eligible'=>125,'ids'=>$ids,'direct_qa_fixture_rows'=>true,'explicit_scope_fixtures'=>true,'business_quotes'=>0,'target_database_connected'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo "Selector fixture prepared; no proposal or localisation created.\n";
|