33 lines
2.2 KiB
PHP
33 lines
2.2 KiB
PHP
<?php
|
|
namespace App\Modules\Purchasing;
|
|
|
|
/** Links to already visible records; every destination retains its own authority checks. */
|
|
final class ProcessNavigation
|
|
{
|
|
public function decorate(array $view,array $allowed,int $request):array
|
|
{
|
|
if(config('receipt_qa.focus_enabled')!==true)return $view;
|
|
$link=fn(string $stage,array $ids,string $label)=>['href'=>'/purchasing/'.$stage.'?'.http_build_query($ids),'label'=>$label];
|
|
$view['_links']=[$link('requests',['request'=>$request],'Consultar esta requisição')];
|
|
if($allowed['sourcing'])$view['_links'][]=$link('sourcing',['request'=>$request],'Consultar propostas desta requisição');
|
|
foreach($view['stages']as$key=>&$stage){
|
|
if(!($stage['accessible']??false))continue;
|
|
$stage['data']=array_map(function($record)use($key,$allowed,$request,$link){
|
|
$row=is_array($record)?$record:(method_exists($record,'toArray')?$record->toArray():(array)$record);$links=[];
|
|
if($key==='quotes'&&$allowed['sourcing'])$links[]=$link('sourcing',['request'=>$request],'Consultar propostas desta requisição');
|
|
if($key==='awards'&&$allowed['orders'])$links[]=$link('orders',['award'=>$row['id']],'Consultar esta adjudicação e ordem');
|
|
if($key==='orders'){
|
|
if($allowed['receipts'])$links[]=$link('receipts',['order'=>$row['id']],'Consultar recepções desta ordem');
|
|
if($allowed['invoices'])$links[]=$link('invoices',['order'=>$row['id']],'Consultar facturas desta ordem');
|
|
}
|
|
if($key==='receipts'&&$allowed['receipts'])$links[]=$link('receipts',['order'=>$row['purchase_order_id'],'receipt'=>$row['id']],'Consultar esta recepção e os seus anexos');
|
|
if($key==='invoices'){
|
|
if($allowed['invoices'])$links[]=$link('invoices',['order'=>$row['purchase_order_id'],'invoice'=>$row['id']],'Consultar esta factura');
|
|
if($allowed['obligations'])$links[]=$link('obligations',['invoice'=>$row['id']],'Consultar obrigação desta factura');
|
|
}
|
|
return $row+['_links'=>$links];
|
|
},$stage['data']);
|
|
}unset($stage);return $view;
|
|
}
|
|
}
|