@@ -67,6 +67,30 @@ final class CapitalRegister
|
||||
});
|
||||
}
|
||||
|
||||
/** Read-only backlink; equipment access does not grant access to a capital reference.
|
||||
* @return array{record_key:string,code:string,name:string,version:int,state:string,href:string}|null
|
||||
*/
|
||||
public function referenceForEquipment(User $actor, Equipment $equipment): ?array
|
||||
{
|
||||
if (! $this->ready() || auth()->id() !== $actor->id || $actor->tenant_id !== $equipment->tenant_id) {
|
||||
return null;
|
||||
}
|
||||
$actor = User::query()->where('tenant_id', $actor->tenant_id)->find($actor->id);
|
||||
if ($actor === null || app(OrganizationAccess::class)->maintenanceOnly($actor)
|
||||
|| ! $actor->hasFunctions(['admin', 'warehouse', 'procurement', 'finance', 'department_head'])
|
||||
|| ($actor->departmentScoped() && $actor->department_id !== $equipment->department_id)) {
|
||||
return null;
|
||||
}
|
||||
$record = $this->visible($actor)->where('tenant_id', $actor->tenant_id)->where('data->type', 'asset')
|
||||
->where('data->equipment_id', $equipment->id)->first();
|
||||
if ($record === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['record_key' => $record->record_key, 'code' => (string) $record->data['code'], 'name' => (string) $record->data['name'],
|
||||
'version' => $record->version, 'state' => $record->state, 'href' => '/projectos-imobilizado?history='.rawurlencode($record->record_key)];
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $input */
|
||||
public function save(User $actor, array $input): SupplyRecord
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user