New Approach Project Creation Methodologies
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

This commit is contained in:
2026-06-04 20:52:29 +08:00
parent 64d4b331a8
commit 3cb68bc6b0
6 changed files with 897 additions and 67 deletions

View File

@@ -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)
{