Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
class GroupController extends Controller
{
private array $modules = [
'vinc_orc' => 'Vinculação Orçamentária',
'termo_jur' => 'Termo Jurídico',
'extrato_jur' => 'Extrato do Termo Jurídico',
'budget_allocation' => 'Vinculação Orçamentária',
'legal_term' => 'Termo Jurídico',
'term_summary' => 'Extrato do Termo Jurídico',
'ci' => 'CI',
'despacho' => 'Despacho',
'parecer_jur' => 'Parecer Jurídico',
'parecer_orc' => 'Parecer Orçamentário',
'abertura' => 'Abertura',
'analise_jur' => 'Análise Jurídica',
'formalizacao' => 'Formalização',
'orcamento' => 'Orçamento e Parcelas',
'pagamento' => 'Pagamento Financeiro',
'usuarios' => 'Gerenciamento de Usuários',
'grupos' => 'Gerenciamento de Grupos',
'dispatch' => 'Despacho',
'legal_opinion' => 'Parecer Jurídico',
'budget_opinion' => 'Parecer Orçamentário',
'opening' => 'Abertura',
'legal' => 'Análise Jurídica',
'formalization' => 'Formalização',
'budget' => 'Orçamento e Parcelas',
'payment' => 'Pagamento Financeiro',
'users' => 'Gerenciamento de Usuários',
'groups' => 'Gerenciamento de Grupos',
];

private array $roleLabels = [
'fomento' => 'Fomento',
'coord_fomento' => 'Coord. Fomento',
'financeiro' => 'Financeiro',
'coord_financeiro' => 'Coord. Financeiro',
'juridico' => 'Jurídico',
'coord_juridico' => 'Coord. Jurídico',
'orcamentario' => 'Orçamentário',
'coord_orcamentario' => 'Coord. Orçamentário',
'monitoramento' => 'Monitoramento',
'coord_monitoramento' => 'Coord. Monitoramento',
'acompanhamento' => 'Acompanhamento',
'fomentation' => 'Fomento',
'coord_fomentation' => 'Coord. Fomento',
'financial' => 'Financeiro',
'coord_financial' => 'Coord. Financeiro',
'legal' => 'Jurídico',
'coord_legal' => 'Coord. Jurídico',
'budgetary' => 'Orçamentário',
'coord_budgetary' => 'Coord. Orçamentário',
'monitoring' => 'Monitoramento',
'coord_monitoring' => 'Coord. Monitoramento',
'tracking' => 'Acompanhamento',
'super_admin' => 'Super Admin',
];

Expand All @@ -50,6 +50,7 @@ class GroupController extends Controller
['key' => 'edit_any', 'label' => 'Editar outros'],
['key' => 'delete_own', 'label' => 'Excluir o próprio'],
['key' => 'delete_any', 'label' => 'Excluir outros'],
['key'=> 'assign_supervisor', 'label' => 'Atribuir Supervisor'],
];

public function index()
Expand Down
36 changes: 35 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
use Inertia\Inertia;
use Inertia\Response;
use App\Models\Notice;
use App\Models\User;
use App\Models\Project;
use App\Models\OpeningSupervisor;
use App\Enums\ProjectPhase;
use App\Enums\InstrumentType;
use Illuminate\Support\Facades\DB;
use App\Services\ProjectSupervisorService;

class ProjectController extends Controller
{
public function index(Request $request, Notice $notice)
{
$query = $notice->projects()
->with(['agent', 'category', 'opening'])
->with(['agent', 'category', 'opening', 'opening.supervisors'])
->withCount('openings')
->filterPhase($request->phase)
->search($request->search);
Expand All @@ -30,7 +35,36 @@ public function index(Request $request, Notice $notice)
'title' => $phase->label(),
'total' => $phase->count($query),
]),
'supervisors_available' => User::role(['monitoring', 'coord_monitoring'])
->select('id', 'name')
->get(),
]);
}

public function assignProjectSupervisor(Request $request, ProjectSupervisorService $service)
{
$data = $request->validate([
'selected_projects' => 'required|array',
'selected_projects.*' => 'exists:projects,id',

'selected_supervisors' => 'required|array',
'selected_supervisors.*' => 'exists:users,id',
]);

try {
$service->assign(
$data['selected_projects'],
$data['selected_supervisors']
);

return back()->with('success', 'Fiscais atribuídos com sucesso!');
} catch (\Throwable $e) {
report($e);

return back()->withErrors([
'message' => 'Erro ao atribuir fiscais. Tente novamente.',
]);
}
}

}
2 changes: 2 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Inertia\Middleware;
use Illuminate\Support\Facades\Route;

class HandleInertiaRequests extends Middleware
{
Expand Down Expand Up @@ -35,6 +36,7 @@ public function share(Request $request): array
'user' => $request->user(),
'roles' => $request->user()?->getRoleNames() ?? [],
'permissions' => $request->user()?->getAllPermissions()->pluck('name') ?? [],
'currentRoute' => Route::currentRouteName(),
],
];
}
Expand Down
22 changes: 22 additions & 0 deletions app/Models/Opening.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Enums\OpeningStatus;
use OwenIt\Auditing\Auditable as AuditableTrait;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Support\Facades\Auth;
class Opening extends Model implements Auditable
{
use HasFactory, SoftDeletes, AuditableTrait, HasFiles;
Expand Down Expand Up @@ -70,4 +71,25 @@ public function activeSupervisor(): HasOne
->where('is_active', true)
->latestOfMany('assigned_at');
}

public function assignSupervisors(array|Collection $supervisorIds): void
{
OpeningSupervisor::where('opening_id', $this->id)
->where('is_active', true)
->update([
'is_active' => false,
'removed_at' => now(),
]);


foreach ($supervisorIds as $supervisorId) {
OpeningSupervisor::create([
'opening_id' => $this->id,
'user_id' => $supervisorId,
'assigned_by' => Auth::id(),
'assigned_at' => now(),
'is_active' => true,
]);
}
}
}
25 changes: 25 additions & 0 deletions app/Services/ProjectSupervisorService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace App\Services;

use App\Models\Project;
use Illuminate\Support\Facades\DB;

class ProjectSupervisorService
{
public function assign(array $projectIds, array $supervisorIds): void
{
$projects = Project::with('opening')
->whereIn('id', $projectIds)
->get();

DB::transaction(function () use ($projects, $supervisorIds) {
foreach ($projects as $project) {
if (!$project->opening) {
throw new \Exception("Projeto {$project->id} não possui abertura.");
}

$project->opening->assignSupervisors($supervisorIds);
}
});
}
}
Loading