diff --git a/docs/superpowers/plans/2026-05-24-purchase-request-form-upgrade.md b/docs/superpowers/plans/2026-05-24-purchase-request-form-upgrade.md new file mode 100644 index 0000000..23ea599 --- /dev/null +++ b/docs/superpowers/plans/2026-05-24-purchase-request-form-upgrade.md @@ -0,0 +1,1881 @@ +# Purchase Request Form Upgrade β€” Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Add three admin-managed lookup tables (locations, projects, urgency levels), a Settings admin section in the sidebar, and upgrade the purchase request create/edit forms with searchable dropdowns and an interactive urgency popup. + +**Architecture:** Three migrations + models + seeders for lookup tables. Three Settings controllers under `app/Http/Controllers/Settings/`. PurchaseRequestController passes lookup collections to create/edit views. The urgency picker is rendered as a floating popup using server-rendered JSON (URGENCY_LEVELS JS variable) and vanilla JS β€” no Alpine.js or Select2 needed. Dropdowns are native ` + + + + + @error('name') +

{{ $message }}

+ @enderror + + +{{-- List --}} +
+ + + + + + + + + + @forelse($locations as $location) + + + + + + @empty + + + + @endforelse + +
NameStatusActions
+ {{ $location->name }} + + @if($location->is_active) + Active + @else + Inactive + @endif + + +
+ @csrf @method('DELETE') + +
+
No locations yet. Add one above.
+
+ +{{-- Edit Modal --}} + + + +@endsection +``` + +- [ ] **Step 2: Test the page loads** + +Visit `http://localhost:8000/settings/locations` (logged in as Admin). +Expected: Empty table with "Add Location" button. + +- [ ] **Step 3: Test add a location** + +Click "Add Location", fill in "BaFa - Hidd", click Save. +Expected: Row appears, success toast shows. + +- [ ] **Step 4: Commit** + +```bash +git add resources/views/settings/locations/ +git commit -m "feat: add Settings Locations management page" +``` + +--- + +## Task 7: Settings View β€” Projects + +**Files:** +- Create: `resources/views/settings/projects/index.blade.php` + +- [ ] **Step 1: Create the directory and view** + +```bash +mkdir -p resources/views/settings/projects +``` + +Create `resources/views/settings/projects/index.blade.php`: + +```blade +@extends('layouts.app') + +@section('title', 'Projects') + +@section('content') +
+
+

Projects

+

Manage project / site names used in purchase requests.

+
+ +
+ +{{-- Add Form --}} + + +{{-- List --}} +
+ + + + + + + + + + @forelse($projects as $project) + + + + + + @empty + + + + @endforelse + +
NameStatusActions
{{ $project->name }} + @if($project->is_active) + Active + @else + Inactive + @endif + + +
+ @csrf @method('DELETE') + +
+
No projects yet. Add one above.
+
+ +{{-- Edit Modal --}} + + + +@endsection +``` + +- [ ] **Step 2: Test the page loads** + +Visit `http://localhost:8000/settings/projects` (logged in as Admin). +Expected: Empty table with "Add Project" button. + +- [ ] **Step 3: Commit** + +```bash +git add resources/views/settings/projects/ +git commit -m "feat: add Settings Projects management page" +``` + +--- + +## Task 8: Settings View β€” Urgency Levels + +**Files:** +- Create: `resources/views/settings/urgency-levels/index.blade.php` + +- [ ] **Step 1: Create the directory and view** + +```bash +mkdir -p "resources/views/settings/urgency-levels" +``` + +Create `resources/views/settings/urgency-levels/index.blade.php`: + +```blade +@extends('layouts.app') + +@section('title', 'Urgency Levels') + +@section('content') +
+
+

Urgency Levels

+

Configure the urgency options shown in purchase request forms.

+
+ +
+ +{{-- Live Preview --}} +
+

Popup Preview

+
+ @foreach($urgencyLevels->where('is_active', true) as $level) +
+
{{ $level->emoji }}
+
{{ $level->label }}
+
{{ $level->subtitle }}
+
+ @endforeach +
+
+ +{{-- Add Form --}} + + +{{-- List --}} +
+ + + + + + + + + + + + + @forelse($urgencyLevels as $level) + + + + + + + + + @empty + + + + @endforelse + +
#LabelSubtitleColorsStatusActions
{{ $level->sort_order }} + + {{ $level->emoji }} {{ $level->label }} + + @if($level->show_date_picker) + πŸ“… date picker + @endif + {{ $level->subtitle }} + + + + @if($level->is_active) + Active + @else + Inactive + @endif + + +
+ @csrf @method('DELETE') + +
+
No urgency levels yet.
+
+ +{{-- Edit Modal --}} + + + +@endsection +``` + +- [ ] **Step 2: Test the page loads** + +Visit `http://localhost:8000/settings/urgency-levels` (logged in as Admin). +Expected: Live preview showing 4 urgency cards, table listing all 4 levels. + +- [ ] **Step 3: Commit** + +```bash +git add resources/views/settings/urgency-levels/ +git commit -m "feat: add Settings Urgency Levels management page" +``` + +--- + +## Task 9: Sidebar Links + +**Files:** +- Modify: `resources/views/layouts/app.blade.php` + +- [ ] **Step 1: Add Locations, Projects, and Urgency Levels links under the System section** + +In `resources/views/layouts/app.blade.php`, find the existing "Integrations" sidebar link (around line 178). After the Integrations `` tag and **before** `@endrole`, add: + +```blade + + Locations + + + Projects + + + Urgency Levels + +``` + +- [ ] **Step 2: Verify in browser** + +Log in as Admin, check the sidebar β€” should show Integrations, Locations, Projects, Urgency Levels under the System section. + +- [ ] **Step 3: Commit** + +```bash +git add resources/views/layouts/app.blade.php +git commit -m "feat: add Settings sidebar links for Locations, Projects, Urgency Levels" +``` + +--- + +## Task 10: Update PurchaseRequestController + +**Files:** +- Modify: `app/Http/Controllers/Purchase/PurchaseRequestController.php` + +- [ ] **Step 1: Add use-imports at the top of the controller** + +After the existing `use` statements, add: + +```php +use App\Models\Settings\Location; +use App\Models\Settings\ProjectSetting; +use App\Models\Settings\UrgencyLevel; +``` + +- [ ] **Step 2: Update `create()` to pass lookup data** + +Replace: +```php +public function create() +{ + return view('purchase.requests.create'); +} +``` + +With: +```php +public function create() +{ + $locations = Location::active()->orderBy('name')->pluck('name'); + $projects = ProjectSetting::active()->orderBy('name')->pluck('name'); + $urgencyLevels = UrgencyLevel::active()->get(['id', 'label', 'emoji', 'color_bg', 'color_text', 'subtitle', 'show_date_picker']); + + return view('purchase.requests.create', compact('locations', 'projects', 'urgencyLevels')); +} +``` + +- [ ] **Step 3: Update `edit()` to pass lookup data** + +Replace: +```php +public function edit(PurchaseRequest $purchaseRequest) +{ + $purchaseRequest->load('items'); + + return view('purchase.requests.edit', compact('purchaseRequest')); +} +``` + +With: +```php +public function edit(PurchaseRequest $purchaseRequest) +{ + $purchaseRequest->load('items'); + + $locations = Location::active()->orderBy('name')->pluck('name'); + $projects = ProjectSetting::active()->orderBy('name')->pluck('name'); + $urgencyLevels = UrgencyLevel::active()->get(['id', 'label', 'emoji', 'color_bg', 'color_text', 'subtitle', 'show_date_picker']); + + return view('purchase.requests.edit', compact('purchaseRequest', 'locations', 'projects', 'urgencyLevels')); +} +``` + +- [ ] **Step 4: Verify no errors** + +```bash +php artisan route:list --name=purchase.requests.create +``` + +Expected: Route listed with no errors. + +- [ ] **Step 5: Commit** + +```bash +git add app/Http/Controllers/Purchase/PurchaseRequestController.php +git commit -m "feat: pass locations, projects, urgencyLevels to purchase request create/edit" +``` + +--- + +## Task 11: Update `create.blade.php` + +**Files:** +- Modify: `resources/views/purchase/requests/create.blade.php` + +- [ ] **Step 1: Replace the entire file content** + +Replace the full content of `resources/views/purchase/requests/create.blade.php` with: + +```blade +@extends('layouts.app') + +@section('title', 'New Material Purchase Request') + +@section('content') +
+

New Material Purchase Request

+

Purchase Requests / New

+
+ +@if($errors->any()) +
+ +
+@endif + +
+ @csrf + + {{-- Header Details --}} +
+

Project / Department Details

+
+ +
+ + +
+ + {{-- Project / Site Name β€” dropdown --}} +
+ + +
+ +
+ + +
+ + {{-- Required Date / Urgency β€” popup picker --}} +
+ +
+ Select urgency… + + + +
+ + + {{-- Urgency Popup --}} +
+
+ How soon is this needed? +
+
+ +
+
+ + {{-- Location / Site β€” dropdown --}} +
+ + +
+ +
+ + +
+ +
+
+ + {{-- Material Items --}} +
+
+

Material Details

+ +
+ +
+ + + + + + + + + + + + + + @php $oldItems = old('items', [[]]); @endphp + @foreach($oldItems as $idx => $oldItem) + + + + + + + + + + @endforeach + +
S.NoDescription of Material *UnitQty Required *Purpose / UseRequired Date
{{ $idx + 1 }} + + + + + + + + + + + +
+
+
+ + {{-- Remarks --}} +
+ + +
+ +
+ + Cancel +
+
+ + +@endsection +``` + +- [ ] **Step 2: Test form loads** + +Visit `http://localhost:8000/purchase/requests/create`. +Expected: Project and Location fields show as dropdowns. Urgency field shows clickable trigger. + +- [ ] **Step 3: Test urgency popup** + +Click the "Select urgency…" field. Expected: Popup opens with 2Γ—2 icon cards. Click "Critical" β€” popup closes, pill shows "🚨 Critical". Click field again, click "Planned" β€” date input appears. Pick a date β€” popup closes with "πŸ—“οΈ 14 Jun 2026" pill. + +- [ ] **Step 4: Test form submission** + +Fill all required fields and submit. Expected: Redirects to index with success toast. Verify in tinker: +```bash +php artisan tinker --execute="echo App\Models\PurchaseRequest::latest()->first()->required_date_text;" +``` +Expected: The urgency label you picked (e.g. "Critical" or "Planned β€” 2026-06-14"). + +- [ ] **Step 5: Commit** + +```bash +git add resources/views/purchase/requests/create.blade.php +git commit -m "feat: upgrade purchase request create form with dropdowns and urgency popup" +``` + +--- + +## Task 12: Update `edit.blade.php` + +**Files:** +- Modify: `resources/views/purchase/requests/edit.blade.php` + +- [ ] **Step 1: Replace the Project / Site Name field** + +Find: +```blade +
+ + +
+``` + +Replace with: +```blade +
+ + +
+``` + +- [ ] **Step 2: Replace the Required Date / Urgency field** + +Find: +```blade +
+ + +
+``` + +Replace with: +```blade +
+ +
+ Select urgency… + + + +
+ + +
+
+ How soon is this needed? +
+
+ +
+
+``` + +- [ ] **Step 3: Replace the Location / Site field** + +Find: +```blade +
+ + +
+``` + +Replace with: +```blade +
+ + +
+``` + +- [ ] **Step 4: Add the urgency popup JS before `@endsection`** + +At the very end of the file (before `@endsection`), add a ` +``` + +- [ ] **Step 5: Test edit form with existing urgency** + +Open an existing purchase request that has a `required_date_text` value (e.g. "Critical") and click Edit. +Expected: The urgency field pre-shows the "🚨 Critical" pill. Opening the popup shows the Critical card highlighted. + +- [ ] **Step 6: Commit** + +```bash +git add resources/views/purchase/requests/edit.blade.php +git commit -m "feat: upgrade purchase request edit form with dropdowns and urgency popup" +``` + +--- + +## Done + +At this point: +- Three lookup tables exist and are seeded with default urgency levels +- Admin can manage Locations, Projects, and Urgency Levels from Settings in the sidebar +- Purchase request create and edit forms use dropdown selects for Project and Location +- The "Required Date / Urgency" field opens a polished popup with icon cards; "Planned" shows an inline date picker +- All values are stored as strings in existing `purchase_requests` columns β€” no schema changes to that table