New Approach Project Creation Methodologies
This commit is contained in:
@@ -29,37 +29,55 @@ class ProjectController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
$query = Project::query()
|
||||
->where('current_wizard_step', '>=', 7)
|
||||
->whereNotIn('status', ['completed', 'closed'])
|
||||
->with(['personnel:id,name']);
|
||||
|
||||
$historyQuery = Project::query()
|
||||
->where('current_wizard_step', '>=', 7)
|
||||
->whereIn('status', ['completed', 'closed'])
|
||||
->with(['personnel:id,name']);
|
||||
|
||||
$draftsQuery = Project::query()
|
||||
->where('current_wizard_step', '<', 7)
|
||||
->with(['personnel:id,name']);
|
||||
|
||||
|
||||
// Non-platform admins only see projects they are assigned to
|
||||
if ($user && !$user->hasRole('Super Admin')) {
|
||||
$query->whereHas('personnel', function ($q) use ($user) {
|
||||
$q->where('users.id', $user->id);
|
||||
});
|
||||
$historyQuery->whereHas('personnel', function ($q) use ($user) {
|
||||
$q->where('users.id', $user->id);
|
||||
});
|
||||
$draftsQuery->whereHas('personnel', function ($q) use ($user) {
|
||||
$q->where('users.id', $user->id);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$projects = $query
|
||||
->when($request->search, fn ($q, $s) => $q->where('name', 'like', "%{$s}%")->orWhere('code', 'like', "%{$s}%"))
|
||||
->when($request->status, fn ($q, $s) => $q->where('status', $s))
|
||||
->latest()
|
||||
->paginate(15)
|
||||
->paginate(15, ['*'], 'page')
|
||||
->withQueryString()
|
||||
->through(fn ($p) => $p->append(['capitalization_percentage', 'is_over_budget']));
|
||||
|
||||
$history = $historyQuery
|
||||
->when($request->search, fn ($q, $s) => $q->where('name', 'like', "%{$s}%")->orWhere('code', 'like', "%{$s}%"))
|
||||
->when($request->status, fn ($q, $s) => $q->where('status', $s))
|
||||
->latest()
|
||||
->paginate(15, ['*'], 'history_page')
|
||||
->withQueryString()
|
||||
->through(fn ($p) => $p->append(['capitalization_percentage', 'is_over_budget']));
|
||||
|
||||
$drafts = $draftsQuery->latest()->get();
|
||||
|
||||
|
||||
return Inertia::render('ProjectManagement::Projects/Index', [
|
||||
'projects' => $projects,
|
||||
'history' => $history,
|
||||
'drafts' => $drafts,
|
||||
'filters' => $request->only(['search', 'status']),
|
||||
'statuses' => collect(ProjectStatus::cases())->map(fn ($s) => [
|
||||
@@ -296,14 +314,6 @@ class ProjectController extends Controller
|
||||
->with('success', "Project \"{$project->name}\" updated.");
|
||||
}
|
||||
|
||||
public function destroy(Project $project)
|
||||
{
|
||||
$name = $project->name;
|
||||
$project->delete();
|
||||
|
||||
return redirect()->route('projects.index')
|
||||
->with('success', "Project \"{$name}\" deleted.");
|
||||
}
|
||||
|
||||
public function transition(Request $request, Project $project)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user