Files
SGF/scripts/receipt-workspace-seed.php
T
2026-11-04 09:37:20 +02:00

6 lines
1.5 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/receipt-workspace-seed.json';if(!($s['receiptWorkspace']??false)||is_file($out))throw new LogicException('Fresh receipt catalogue 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();$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.receipt_seed'=>$s['nativeConnection']]);$db=DB::connection('receipt_seed');if($db->table('goods_receipts')->count())throw new LogicException('No receipt commands before catalogue seeding');$base=(array)$db->table('stock_items')->where('id',$n['stock'])->first();unset($base['id']);$ids=[];
$db->transaction(function()use($db,$base,&$ids){for($i=1;$i<=127;$i++){$row=$base;$row['code']='QA-CATALOG-'.str_pad((string)$i,4,'0',STR_PAD_LEFT);$row['name']=$i===127?'QA Literal%_Article':'QA catalogue article '.$i;$row['unit']=$i===126?'KG':($i===125?' un ':'UN');$ids[$i]=$db->table('stock_items')->insertGetId($row);}});
file_put_contents($out,json_encode(['passed'=>true,'synthetic_articles'=>127,'eligible_un'=>127,'ids'=>$ids,'physical_movements'=>0,'real_catalogue_changed'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo "Synthetic article catalogue prepared without physical movements.\n";