first commit

This commit is contained in:
2026-10-27 12:26:52 +02:00
parent 7628645fb6
commit ea9dcb3314
19 changed files with 701 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace Tests\Support;
use App\Modules\Workshop\WorkshopWorkflow;
use App\Modules\Workshop\DirectCosts;
use App\Shared\Context\CompanyContext;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Carbon\Carbon;
final class DirectCostFixture {
public static function create(?array $base=null): array {
DirectCosts::guard();$f=WorkshopFixture::create($base);
foreach(['manager'=>['view','prepare'],'reader'=>['view','validate']] as $who=>$rights)foreach($rights as $r)IdentityFixture::grant($f[$who]->id,$f['tenant'],$f['company'],'direct_costs.'.$r,$f['unit']);
$old=Carbon::getTestNow();$day=now(WorkshopWorkflow::ZONE)->subDay()->format('Y-m-d');
$select=fn($id)=>app(CompanyContext::class)->selectFor($id,$f['tenant'],$f['company'],$f['unit']);$key=fn()=>(string)Str::uuid();$w=app(WorkshopWorkflow::class);
try {
Carbon::setTestNow(Carbon::parse($day.' 08:00:00',WorkshopWorkflow::ZONE));$select($f['manager']->id);
$order=$w->open($f['manager']->id,['reference'=>'OT-CUSTO-TEST-'.Str::uuid(),'client_id'=>$f['client'],'equipment_identifier'=>'EQ-CUSTO-'.Str::uuid(),'equipment_description'=>'Equipamento sintético','request'=>'Intervenção de teste','location'=>'Local sintético','evidence'=>'TEST-REQUEST'],$key())['id'];
$rev=fn()=>(int)DB::selectOne('SELECT sgf_wo_revision(?) AS v',[$order])->v;
$record=fn($actor,$kind,$data)=>$w->record($order,$actor,['kind'=>$kind,'origin'=>'TEST-'.$kind.'-'.Str::uuid(),'version'=>1,'revision'=>$rev()]+$data,$key())['id'];
$record($f['manager']->id,'assignment',['technician_id'=>$f['technician']->id]);$select($f['technician']->id);
$task=$record($f['technician']->id,'task',['description'=>'Tarefa de ensaio de custo directo']);$select($f['manager']->id);
$auth=$record($f['manager']->id,'authorization',['task_id'=>$task,'authorized_by'=>'Representante sintético','capacity'=>'Cliente de teste','authorized_at'=>$day.'T07:59:00+02:00','channel'=>'Documento de teste','scope'=>'Tarefa identificada','evidence'=>'TEST-AUTH']);
Carbon::setTestNow(Carbon::parse($day.' 12:00:00',WorkshopWorkflow::ZONE));$select($f['technician']->id);
$time=$record($f['technician']->id,'time',['task_id'=>$task,'authorization_id'=>$auth,'starts_at'=>$day.'T09:00:00+02:00','ends_at'=>$day.'T11:00:00+02:00','mode'=>'reported','time_type'=>'work','pauses'=>[['start'=>$day.'T10:00:00+02:00','end'=>$day.'T10:15:00+02:00']],'evidence'=>'TEST-TIME']);
$points=[$task,$time];foreach(['delivered'=>'3','consumed'=>'2','returned'=>'1'] as $event=>$quantity){$id=$record($f['technician']->id,'material',['task_id'=>$task,'authorization_id'=>$auth,'starts_at'=>$day.'T11:00:00+02:00','resource'=>'CABO-CUSTO-TEST','unit'=>'UN','owner'=>'company','event'=>$event,'quantity'=>$quantity,'evidence'=>'TEST-MATERIAL']);$points[]=$id;if($event==='consumed')$material=$id;}
$select($f['reviewer']->id);foreach($points as $id)$w->verify($id,$f['reviewer']->id,['version'=>1,'revision'=>$rev(),'decision'=>'verified','reason'=>'Verificação técnica sintética separada dos custos.'],$key());
} finally {Carbon::setTestNow($old);}
$select($f['manager']->id);return $f+compact('order','task','auth','time','material','day');
}
}