@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BusinessClient;
|
||||
use App\Services\BusinessClients;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class BusinessClientController extends Controller
|
||||
{
|
||||
public function index(Request $request, BusinessClients $clients): Response
|
||||
{
|
||||
$actor = $this->staffIdentity($request);
|
||||
abort_unless($clients->ready(), 503);
|
||||
abort_unless($clients->canRead($actor), 403);
|
||||
$filters = $request->validate(['search' => 'nullable|string|max:180', 'page' => 'nullable|integer|min:1']);
|
||||
$query = BusinessClient::query()->where('tenant_id', $actor->tenant_id)
|
||||
->select(['id', 'client_key', 'code', 'name', 'tax_number', 'address', 'email', 'active', 'version']);
|
||||
if (trim($filters['search'] ?? '') !== '') {
|
||||
$query->where(fn ($q) => $q->where('name', 'like', '%'.$filters['search'].'%')->orWhere('code', 'like', '%'.$filters['search'].'%'));
|
||||
}
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('company/clients', ['clients' => $query->orderBy('name')->paginate(20)->withQueryString(),
|
||||
'filters' => $filters, 'canManage' => $clients->canManage($actor)])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function store(Request $request, BusinessClients $clients): Response
|
||||
{
|
||||
$clients->save($this->staffIdentity($request), null, $request->all());
|
||||
|
||||
return redirect('/empresa/clientes')->with('success', 'Cliente registado.');
|
||||
}
|
||||
|
||||
public function update(Request $request, int $client, BusinessClients $clients): Response
|
||||
{
|
||||
$clients->save($this->staffIdentity($request), $client, $request->all());
|
||||
|
||||
return redirect('/empresa/clientes')->with('success', 'Cliente actualizado; os processos anteriores conservam a sua identificação original.');
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,12 @@ use App\Models\PeopleProcess;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\AiPreparationPlan;
|
||||
use App\Services\BusinessClients;
|
||||
use App\Services\CandidateTriage;
|
||||
use App\Services\IntelligencePolicy;
|
||||
use App\Services\PeopleAccess;
|
||||
use App\Services\PeopleClarifications;
|
||||
use App\Services\PeopleContractFormalization;
|
||||
use App\Services\PeopleEvidenceBrief;
|
||||
use App\Services\PeopleForms;
|
||||
use App\Services\PeopleHiring;
|
||||
@@ -18,10 +20,12 @@ use App\Services\PeopleOperationalInsights;
|
||||
use App\Services\PeopleProcessProjection;
|
||||
use App\Services\PeopleRegistry;
|
||||
use App\Services\PeopleWorkdesk;
|
||||
use App\Services\WorkContext;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -37,6 +41,7 @@ class PeopleHiringController extends Controller
|
||||
$kinds = $workflow->kinds($this->actor($request));
|
||||
abort_unless($kinds !== [], 403);
|
||||
$availableKinds = $kinds;
|
||||
$clientMode = app(WorkContext::class)->active($request) === 'people.third_party';
|
||||
$filter = $request->validate(['kind' => 'nullable|in:service,staff', 'search' => 'nullable|string|max:100', 'status' => ['nullable', Rule::in(PeopleWorkdesk::STATES)],
|
||||
'from' => 'nullable|date_format:Y-m-d', 'to' => ['nullable', 'date_format:Y-m-d', Rule::when($request->filled('from'), 'after_or_equal:from')]]);
|
||||
if (isset($filter['kind'])) {
|
||||
@@ -47,8 +52,11 @@ class PeopleHiringController extends Controller
|
||||
$query = app(PeopleAccess::class)->visible(PeopleProcess::query()->whereIn('kind', $kinds), $this->actor($request));
|
||||
if (($filter['search'] ?? '') !== '') {
|
||||
$search = $filter['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$query->where(function ($q) use ($search, $clientMode) {
|
||||
$q->whereLike('title', '%'.$search.'%');
|
||||
if ($clientMode) {
|
||||
$q->orWhere('rules->client->name', 'like', '%'.$search.'%')->orWhere('rules->client->code', 'like', '%'.$search.'%');
|
||||
}
|
||||
if (preg_match('/^(?:PES-)?([1-9][0-9]*)$/D', $search, $matches)) {
|
||||
$reference = filter_var($matches[1], FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
|
||||
if ($reference !== false) {
|
||||
@@ -67,14 +75,18 @@ class PeopleHiringController extends Controller
|
||||
$query->whereDate('created_at', '<=', $filter['to']);
|
||||
}
|
||||
$workdesk = $ready ? app(PeopleWorkdesk::class)->build(clone $query, $this->actor($request)) : null;
|
||||
$processes = $ready ? (clone $query)->select(['id', 'title', 'kind', 'status', 'closes_on', 'created_at', 'rules'])->latest('id')->paginate(15)->withQueryString()
|
||||
->through(fn (PeopleProcess $process) => [...$process->only(['id', 'title', 'kind', 'status', 'closes_on', 'created_at']),
|
||||
...($clientMode ? ['client' => array_intersect_key($process->rules['client'] ?? [], array_flip(['id', 'code', 'name', 'version']))] : [])]) : null;
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('people/index', ['ready' => $ready, 'kinds' => $kinds, 'availableKinds' => $availableKinds,
|
||||
'filters' => $filter, 'workdesk' => $workdesk, 'insights' => $workdesk === null ? null : app(PeopleOperationalInsights::class)->build($workdesk),
|
||||
'clientMode' => $clientMode, 'clients' => $clientMode ? app(BusinessClients::class)->choices($this->actor($request)) : [],
|
||||
'company' => Tenant::query()->findOrFail($this->actor($request)->tenant_id)->only(['name']),
|
||||
'canPrepare' => array_values(array_filter($availableKinds, fn ($kind) => $workflow->allowed($this->actor($request), $kind, 'prepare'))),
|
||||
'formFields' => ['staff' => PeopleForms::STAFF, 'service' => PeopleForms::SERVICE],
|
||||
'administration' => $ready && $this->actor($request)->hasFunctions(['admin']) ? PeopleProcess::query()->whereIn('kind', $kinds)->orderByDesc('id')->get(['id', 'kind', 'status']) : [],
|
||||
'processes' => $ready ? (clone $query)->select(['id', 'title', 'kind', 'status', 'closes_on', 'created_at'])->latest('id')->paginate(15)->withQueryString() : null])->toResponse($request);
|
||||
'processes' => $processes])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
|
||||
return $response;
|
||||
@@ -107,8 +119,9 @@ class PeopleHiringController extends Controller
|
||||
'canPrepare' => $workflow->allowed($this->actor($request), $record->kind, 'prepare') && $access->can($this->actor($request), $record, 'prepare'),
|
||||
'canViewElectronicSources' => app(CandidateTriage::class)->canRead($this->actor($request), $record),
|
||||
'canReview' => $workflow->allowed($this->actor($request), $record->kind, 'review') && $access->can($this->actor($request), $record, 'review') && $this->actor($request)->id !== $record->created_by,
|
||||
'canApprove' => $workflow->allowed($this->actor($request), $record->kind, 'review') && $access->can($this->actor($request), $record, 'approve') && ! in_array($this->actor($request)->id, $workflow->decisionContributors($record), true),
|
||||
'canApprove' => $workflow->canConfirm($this->actor($request), $record) && ! in_array($this->actor($request)->id, $workflow->decisionContributors($record), true),
|
||||
'canContract' => $workflow->allowed($this->actor($request), $record->kind, 'prepare') && $access->can($this->actor($request), $record, 'contract'),
|
||||
'canFormalize' => app(PeopleContractFormalization::class)->can($this->actor($request), $record),
|
||||
'canManage' => $access->manages($this->actor($request), $record),
|
||||
'history' => AuditLog::query()->where('action', 'like', 'people.%')->where('after->id', $record->id)->orderBy('id')->get(['id', 'action', 'user_id', 'created_at'])])->toResponse($request);
|
||||
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
||||
@@ -126,8 +139,8 @@ class PeopleHiringController extends Controller
|
||||
$record = PeopleProcess::query()->findOrFail($process);
|
||||
$data = $projection->read($this->actor($request), $record);
|
||||
|
||||
return response()->json(['schema' => 'sgc.people.process-dossier.v1', 'exported_at' => now()->toIso8601String(),
|
||||
'effect' => 'preparation_only',
|
||||
return response()->json(['schema' => $record->status === 'contract_formalized' ? 'sgc.people.process-dossier.v2' : 'sgc.people.process-dossier.v1', 'exported_at' => now()->toIso8601String(),
|
||||
'effect' => $record->status === 'contract_formalized' ? 'signed_contract_record_only' : 'preparation_only',
|
||||
'process' => Arr::only($data['process'], ['id', 'kind', 'title', 'purpose', 'closes_on', 'status', 'version', 'selected_application_id', 'rules', 'selection', 'contract']),
|
||||
'candidates' => $data['candidates']])
|
||||
->header('Content-Disposition', 'attachment; filename="PES-'.$record->id.'-dossier-v'.$record->version.'.json"')
|
||||
@@ -167,6 +180,26 @@ class PeopleHiringController extends Controller
|
||||
return redirect('/pessoas/'.$record->id);
|
||||
}
|
||||
|
||||
public function formalize(Request $request, int $process, PeopleContractFormalization $service): Response
|
||||
{
|
||||
$record = $service->confirm($this->actor($request), $process, $request->all());
|
||||
|
||||
return redirect('/pessoas/'.$record->id);
|
||||
}
|
||||
|
||||
public function signedContract(Request $request, int $process): Response
|
||||
{
|
||||
$record = PeopleProcess::query()->findOrFail($process);
|
||||
$data = app(PeopleProcessProjection::class)->read($this->actor($request), $record);
|
||||
abort_unless(isset($data['process']['contract']['signed_document']) && $record->status === 'contract_formalized', 404);
|
||||
$document = $record->contract['signed_document'];
|
||||
$disk = Storage::disk('people_contracts');
|
||||
abort_unless($disk->exists($document['path']) && hash_equals($document['sha256'], hash('sha256', $disk->get($document['path']))), 409);
|
||||
|
||||
return $disk->download($document['path'], 'contrato-assinado-'.$record->id.'.pdf', [
|
||||
'Cache-Control' => 'private, no-store', 'X-Content-Type-Options' => 'nosniff']);
|
||||
}
|
||||
|
||||
public function store(Request $request, PeopleHiring $workflow): Response
|
||||
{
|
||||
abort_unless(Schema::hasTable('people_processes'), 503);
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Services\PeopleDeadlineReport;
|
||||
use App\Services\PeopleHiring;
|
||||
use App\Services\PeopleSelectionReport;
|
||||
use App\Services\PeopleWorkdesk;
|
||||
use App\Services\WorkContext;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -38,6 +39,7 @@ class PeopleReportController extends Controller
|
||||
'to' => ['nullable', 'date_format:Y-m-d', Rule::when($request->filled('from'), 'after_or_equal:from')],
|
||||
]);
|
||||
$query = app(PeopleAccess::class)->visible(PeopleProcess::query()->whereIn('kind', $kinds), $actor);
|
||||
$clientMode = app(WorkContext::class)->active($request) === 'people.third_party';
|
||||
foreach (['kind', 'status'] as $field) {
|
||||
if (! empty($filters[$field])) {
|
||||
$query->where($field, $filters[$field]);
|
||||
@@ -45,8 +47,11 @@ class PeopleReportController extends Controller
|
||||
}
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$query->where(function ($q) use ($search, $clientMode) {
|
||||
$q->whereLike('title', '%'.$search.'%');
|
||||
if ($clientMode) {
|
||||
$q->orWhere('rules->client->name', 'like', '%'.$search.'%')->orWhere('rules->client->code', 'like', '%'.$search.'%');
|
||||
}
|
||||
if (preg_match('/^(?:PES-)?([1-9][0-9]*)$/D', $search, $matches)) {
|
||||
$id = filter_var($matches[1], FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
|
||||
if ($id !== false) {
|
||||
@@ -61,7 +66,9 @@ class PeopleReportController extends Controller
|
||||
if (! empty($filters['to'])) {
|
||||
$query->whereDate('created_at', '<=', $filters['to']);
|
||||
}
|
||||
$columns = ['id', 'title', 'kind', 'status', 'closes_on', 'created_at'];
|
||||
$baseColumns = ['id', 'title', 'kind', 'status', 'closes_on', 'created_at'];
|
||||
$columns = [...$baseColumns, ...($clientMode ? ['rules'] : [])];
|
||||
$displayTitle = static fn (PeopleProcess $process): string => $process->title.($clientMode && isset($process->rules['client']['name']) ? ' · Cliente: '.$process->rules['client']['name'] : '');
|
||||
$page = $request->routeIs('people.reports.csv') ? null : (clone $query)->latest('id')->paginate(25, $columns)->withQueryString();
|
||||
$applications = ($filters['view'] ?? 'processes') === 'applications';
|
||||
$selections = ($filters['view'] ?? 'processes') === 'selections';
|
||||
@@ -89,7 +96,7 @@ class PeopleReportController extends Controller
|
||||
} elseif ($request->routeIs('people.reports.csv')) {
|
||||
// Materialise within the read-only snapshot; streaming runs after the transaction.
|
||||
$rows = (clone $query)->orderBy('id')->get($columns);
|
||||
$response = response()->streamDownload(function () use ($rows, $applications, $selections, $metrics) {
|
||||
$response = response()->streamDownload(function () use ($rows, $applications, $selections, $metrics, $displayTitle) {
|
||||
$file = fopen('php://output', 'w');
|
||||
if ($file === false) {
|
||||
throw new \RuntimeException('Não foi possível abrir a exportação.');
|
||||
@@ -99,7 +106,8 @@ class PeopleReportController extends Controller
|
||||
$selectionColumns = ['Situação da selecção', 'Proposta em', 'Decisão em', 'Pendência', 'Acesso à minuta', 'Referência da minuta', 'Minuta preparada em', 'Início previsto na minuta'];
|
||||
fputcsv($file, ['Referência', 'Título', 'Percurso', 'Estado', 'Fecho de candidaturas', 'Criado em', ...($applications ? $extra : ($selections ? $selectionColumns : []))], ';', '"', '');
|
||||
foreach ($rows as $row) {
|
||||
$title = preg_match('/^[\s]*[=+@-]/u', $row->title) ? "'".$row->title : $row->title;
|
||||
$title = $displayTitle($row);
|
||||
$title = preg_match('/^[\s]*[=+@-]/u', $title) ? "'".$title : $title;
|
||||
$counts = $metrics[$row->id] ?? [];
|
||||
$values = $applications ? array_values(array_map(fn ($value) => $value === null ? 'Sem acesso' : ($value === 'selection_snapshot' ? 'Selecção preservada' : ($value === 'current_eligibility' ? 'Elegibilidade actual' : $value)), $counts)) : [];
|
||||
if ($selections) {
|
||||
@@ -111,6 +119,7 @@ class PeopleReportController extends Controller
|
||||
}, 'relatorio-pessoas.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
|
||||
} else {
|
||||
$summary = (clone $query)->selectRaw('kind, status, count(*) as total')->groupBy('kind', 'status')->get();
|
||||
$page?->through(fn (PeopleProcess $process) => [...$process->only($baseColumns), 'title' => $displayTitle($process)]);
|
||||
Inertia::encryptHistory();
|
||||
$response = Inertia::render('people/reports', [
|
||||
'filters' => $filters, 'kinds' => $kinds, 'summary' => $summary,
|
||||
@@ -151,6 +160,6 @@ class PeopleReportController extends Controller
|
||||
private static function states(): array
|
||||
{
|
||||
return ['draft' => 'Abertura por conferir', 'open' => 'Recepção de candidaturas', 'assessment' => 'Avaliação',
|
||||
'selection_review' => 'Selecção por conferir', 'selected' => 'Selecção aprovada', 'contract_draft' => 'Minuta contratual preparada'];
|
||||
'selection_review' => 'Selecção por conferir', 'selected' => 'Selecção aprovada', 'contract_draft' => 'Minuta contratual preparada', 'contract_formalized' => 'Contrato formalizado'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ final class PrivateAuditController extends Controller
|
||||
{
|
||||
$scope = $access->current($this->staffIdentity($request));
|
||||
$request->validate(['page' => 'nullable|integer|min:1|max:1000000']);
|
||||
$exports = PrivateAuditExport::query()->where('created_by', $scope['actor']->id)->where('work_context', $scope['context'])->latest('id')->paginate(20)
|
||||
$legacyIds = $access->legacyExportIds($scope['actor'], $scope['context']);
|
||||
$exports = PrivateAuditExport::query()->where('created_by', $scope['actor']->id)
|
||||
->where(fn ($query) => $query->where('work_context', $scope['context'])->orWhereIn('id', $legacyIds))->latest('id')->paginate(20)
|
||||
->through(fn (PrivateAuditExport $export) => ['id' => $export->id, 'families' => $export->families,
|
||||
'created_at' => $export->created_at, 'size' => $export->size, 'sha256' => $export->sha256,
|
||||
'download_url' => '/auditoria/privada/'.$export->id.'/download']);
|
||||
|
||||
Reference in New Issue
Block a user