12 lines
3.8 KiB
PHP
12 lines
3.8 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\Auth;use Illuminate\Support\Str;use Carbon\Carbon;
|
|
use App\Shared\Context\CompanyContext;use App\Modules\Workshop\WorkshopWorkflow;
|
|
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';$profiles=json_decode(file_get_contents($s['root'].'/single-profiles.json'),true)['profiles'];$commercial=json_decode(file_get_contents($s['root'].'/single-commercial.json'),true);
|
|
config(['sgf_single_installation.enabled'=>true,'sgf_single_installation.schema_sha256'=>$host->table('sgf_composition_schema')->value('source_hash')]);$file=$s['root'].'/single-workshop-stock-input.json';if(is_file($file)){echo json_encode(['passed'=>true,'replayed'=>true,'business_commands'=>0]).PHP_EOL;exit;}
|
|
$select=function($role)use($profiles,$f,$app){$user=App\Models\User::findOrFail($profiles[$role]['user_id']);Auth::guard('web')->setUser($user);$r=Illuminate\Http\Request::create('/api/workshop','POST');$session=app('session')->driver();$session->start();$session->put('company_context',$f['scope']+['module_id'=>'workshop','token'=>'stock-source-'.$role]);$r->setLaravelSession($session);$r->setUserResolver(fn()=>$user);$r->attributes->set('sgf_module','workshop');$app->instance('request',$r);app(CompanyContext::class)->selectFor($user->id,$f['tenant'],$f['company'],$f['unit']);return $user->id;};
|
|
$oldNow=Carbon::getTestNow();try{$out=$host->transaction(function()use($select,$tag,$commercial,$host){$key=fn()=>(string)Str::uuid();$w=app(WorkshopWorkflow::class);Carbon::setTestNow(Carbon::parse('2026-11-10 08:00:00',WorkshopWorkflow::ZONE));$manager=$select('workshop_manage');$order=$w->open($manager,['reference'=>'OT-STOCK-INTEGRADO-'.$tag,'client_id'=>$commercial['client'],'equipment_identifier'=>'EQ-STOCK-'.$tag,'equipment_description'=>'Equipamento artificial para origem física','request'=>'Entregar uma unidade, consumir meia e devolver meia unidade não usada.','location'=>'Unidade QA','evidence'=>'QA-STOCK-ORIGEM'],$key())['id'];$rev=fn()=>(int)$host->selectOne('SELECT sgf_wo_revision(?) v',[$order])->v;$record=fn($actor,$kind,$data)=>$w->record($order,$actor,['kind'=>$kind,'origin'=>'QA-STOCK-'.$kind.'-'.Str::uuid(),'revision'=>$rev(),'version'=>1]+$data,$key())['id'];
|
|
$tech=$select('workshop_record');$select('workshop_manage');$record($manager,'assignment',['technician_id'=>$tech]);$select('workshop_record');$task=$record($tech,'task',['description'=>'Intervenção QA com rastreio físico individual']);$select('workshop_manage');$authorization=$record($manager,'authorization',['task_id'=>$task,'authorized_by'=>'Cliente artificial','capacity'=>'Representante QA','authorized_at'=>'2026-11-10T07:59:00+02:00','channel'=>'Documento QA','scope'=>'Tarefa seleccionada e material explícito','evidence'=>'QA-STOCK-AUTH']);
|
|
Carbon::setTestNow(Carbon::parse('2026-11-10 10:00:00',WorkshopWorkflow::ZONE));$select('workshop_record');$entries=[];foreach(['delivered'=>'1','consumed'=>'0.5','returned'=>'0.5'] as $event=>$quantity)$entries[$event]=$record($tech,'material',['task_id'=>$task,'authorization_id'=>$authorization,'starts_at'=>'2026-11-10T09:05:00+02:00','resource'=>'QA-WORKSHOP-STOCK-'.$tag,'unit'=>'UN','owner'=>'company','event'=>$event,'quantity'=>$quantity,'evidence'=>'Origem QA explicitamente destinada ao artigo físico integrado.']);
|
|
$verifier=$select('workshop_verify');foreach([$task,...array_values($entries)] as $entry)$w->verify($entry,$verifier,['version'=>1,'revision'=>$rev(),'decision'=>'verified','reason'=>'Verificação técnica independente de entrega/consumo/devolução QA.'],$key());return compact('order','task','authorization','entries')+['resource'=>'QA-WORKSHOP-STOCK-'.$tag,'unit'=>'UN','synthetic_only'=>true];});}finally{Carbon::setTestNow($oldNow);}
|
|
file_put_contents($file,json_encode($out,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode(['passed'=>true,'order'=>$out['order'],'physical_effects'=>0]).PHP_EOL;
|