Files
SGF/scripts/sgf-workshop-stock-bindings.php
T
2026-11-11 09:00:17 +02:00

10 lines
3.0 KiB
PHP

<?php
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';$profiles=json_decode(file_get_contents($s['root'].'/single-profiles.json'),true)['profiles'];$input=json_decode(file_get_contents($s['root'].'/single-workshop-stock-input.json'),true);$physical=json_decode(file_get_contents($s['root'].'/single-stock-physical-input.json'),true);$original=json_decode(file_get_contents($s['root'].'/binding.json'),true);$key=implode(':',array_values($f['scope']));
$source=['schema'=>'public','source_tenant_id'=>$nf['tenant'],'lots'=>false,'reservations'=>false,'spare_parts'=>false,'stock_returns'=>true,'partial_delivery_links'=>true,'eligible_order_ids'=>[$input['order']],'eligible_deliveries'=>[$physical['issue_movement']=>['order_id'=>$input['order']]],'resources'=>[$input['resource'].'|UN'=>['stock_item_id'=>$physical['stock_item'],'stock_unit'=>'UN','warehouse_ids'=>[$physical['warehouse']]]]];
$path=$s['root'].'/workshop-stock-binding.json';$value=json_encode(['composition'=>$tag,'scope'=>$f['scope'],'source'=>$source,'decision'=>'Vinculação individual dos novos registos QA expressamente autorizados, sem adoptar observações antigas.'],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);if(is_file($path)&&file_get_contents($path)!==$value)throw new LogicException('Preserve differing workshop material mapping');file_put_contents($path,$value);
$bindingsFile=$s['root'].'/single-bindings.json';$b=json_decode(file_get_contents($bindingsFile),true);$stockFile=$s['root'].'/stock-operations-binding.json';$stock=json_decode(file_get_contents($stockFile),true);copy($bindingsFile,$work.'/single-bindings-before.json');copy($stockFile,$work.'/stock-binding-before.json');
foreach(['workshop_record','workshop_verify'] as $role){$id=$profiles[$role]['user_id'];$target=$key.':'.$id;$binding=$original['bindings'][$key.':'.$f['actor']];$binding['warehouse_ids']=[$nf['warehouse'],$physical['warehouse']];if(isset($b['bindings'][$target])&&$b['bindings'][$target]!==$binding)throw new LogicException('Existing workshop actor binding differs');$b['bindings'][$target]=$binding;$stock['warehouse_bindings'][$target]=$binding['warehouse_ids'];}
$warehouse=$original['bindings'][$key.':'.$f['validator']];$warehouse['warehouse_ids']=[$nf['warehouse'],$physical['warehouse']];$warehouse['order_ids']=array_values(array_unique([...($warehouse['order_ids']??[]),$physical['order']]));$b['bindings'][$key.':'.$f['validator']]=$warehouse;
file_put_contents($bindingsFile,json_encode($b,JSON_PRETTY_PRINT));file_put_contents($stockFile,json_encode($stock,JSON_PRETTY_PRINT));$pins=json_decode(file_get_contents($s['root'].'/single-binding-pins.json'),true);foreach(['single-bindings.json','stock-operations-binding.json','workshop-stock-binding.json'] as $name)$pins[$name]=hash_file('sha256',$s['root'].'/'.$name);file_put_contents($s['root'].'/single-binding-pins.json',json_encode($pins,JSON_PRETTY_PRINT));
echo json_encode(['passed'=>true,'book'=>$book,'source_mapping_count'=>1,'original_bindings_unchanged'=>true,'new_rights'=>0]).PHP_EOL;