# 🚀 Asset Management System - Quick Start Guide

## ✅ What Has Been Implemented

Your facility management system has been completely restructured with a hierarchical asset management framework:

### New Database Tables (12 tables)
1. `facility_categories` - 12 predefined facility categories
2. `asset_types` - 100+ asset types across all categories
3. `asset_locations` - Physical locations within facilities
4. `assets` - Individual asset records with unique codes
5. `asset_inspection_templates` - Reusable inspection checklists
6. `asset_inspection_template_items` - Specific checklist items
7. `asset_inspection_schedules` - Inspection scheduling
8. `asset_inspections` - Inspection records and results
9. `asset_inspection_responses` - Individual item responses
10. `work_orders` - Maintenance work orders
11. `work_order_updates` - Work order progress tracking
12. `maintenance_history` - Complete maintenance records

### New Facility Manager Features

#### 📍 Asset Locations
- Define physical locations in your facility
- Organize by building, floor, room
- Track multiple locations

**Path:** `public/manager/asset_locations.php`

#### 🏷️ Assets & Equipment
- Register individual assets with unique codes (AC-001, GEN-02, EX-05)
- Track manufacturer, model, serial number
- Set service intervals
- Store installation and warranty dates

**Path:** `public/manager/assets.php`

#### 📋 Asset Inspections
- Record inspection results (Pass/Fail/Needs Attention)
- Use predefined templates for consistency
- Auto-generate work orders from failures
- Add photos and notes
- Manager verification workflow

**Path:** `public/manager/asset_inspections.php`

#### 🔧 Work Orders
- Create work orders manually or from failed inspections
- Assign to staff members
- Track status through complete workflow
- Set priority levels (Low, Medium, High, Urgent)
- Record costs and maintenance details

**Path:** `public/manager/work_orders.php`

### Pre-populated System Data

**12 Facility Categories:**
1. Building & Structural (14 asset types)
2. Restroom Facilities (12 asset types)
3. HVAC / Cooling (8 asset types)
4. Electrical & Power (14 asset types)
5. Plumbing & Water (10 asset types)
6. Fire & Life Safety (12 asset types)
7. Security (13 asset types)
8. IT / Server (10 asset types)
9. Kitchen / Breakroom (10 asset types)
10. External Facilities (14 asset types)
11. Office Furniture & Fixtures (11 asset types)
12. Cleaning & Housekeeping (8 asset types)

**50+ Inspection Templates** with predefined checklists for:
- AC Units (monthly)
- Central AC Systems (quarterly)
- Generators (monthly)
- UPS Systems (weekly)
- Fire Extinguishers (monthly)
- Smoke Detectors (monthly)
- CCTV Cameras (weekly)
- Access Control Readers (monthly)
- Water Pumps (monthly)
- And more...

---

## 📥 Installation Steps

### Step 1: Create Database Tables

**Option A: Using phpMyAdmin or MySQL Workbench**

1. Open your database tool
2. Go to your `facilityapp` database
3. Click "Import" or "New Query"
4. Open file: `database/schema_extended.sql`
5. Execute the entire script

**Option B: Using Command Line**

```bash
cd /c/wamp64/www/facilityapp
mysql -u root -p facilityapp < database/schema_extended.sql
```

When prompted, enter your MySQL password (usually blank for local WAMP).

### Step 2: Populate Categories and Templates

Run the seeding script:

```bash
cd /c/wamp64/www/facilityapp
php database/seed_assets.php
```

Expected output:
```
🌱 Seeding Facility Management System...

📁 Creating Facility Categories...
  ✓ Building & Structural
  ✓ Restroom Facilities
  ... (12 categories)

🏷️  Creating Asset Types...
  ✓ 100+ asset types created

📋 Creating Asset Inspection Templates...
  ✓ 50+ inspection templates created

✅ Seeding completed successfully!
   Categories: 12
   Asset Types: 105
   Inspection Templates: 52
```

### Step 3: Verify Installation

Run this SQL query to check all tables exist:

```sql
SELECT COUNT(*) as table_count 
FROM information_schema.tables 
WHERE table_schema = 'facilityapp' 
AND table_name LIKE 'asset%' OR table_name LIKE '%facility_categories%' OR table_name LIKE '%work_order%';
```

Should return **12** tables.

### Step 4: Access the New Features

**For Facility Managers:**

Navigate to your facility's dashboard. You'll see new menu items:

```
Dashboard
├── Assets & Equipment          (new)
├── Asset Locations             (new)
├── Asset Inspections           (new)
├── Work Orders                 (new)
├── Checklist Templates         (existing)
├── Assign Tasks                (existing)
├── Staff                       (existing)
├── Attendance                  (existing)
└── Reports                     (existing)
```

---

## 🎯 Getting Started - First Steps

### 1. Create Asset Locations (5 minutes)

**Menu:** Asset Management → Asset Locations

Define where assets are located in your facility:

```
Examples:
- Chairman's Office (Building: Main, Floor: 2)
- Server Room (Building: Main, Floor: Basement)
- Rooftop (Building: Main, Floor: 4)
- Conference Room A (Building: Main, Floor: 1)
- General Office (Building: Annex, Floor: 1)
```

### 2. Register Your First Asset (10 minutes)

**Menu:** Asset Management → Assets & Equipment

Example: Register your AC Unit

```
Category:           HVAC / Cooling
Asset Type:         Split AC Unit
Asset Code:         AC-001
Asset Name:         Split AC Unit 2HP - Chairman's Office
Location:           Chairman's Office
Manufacturer:       Daikin
Model:              FTXS35LVG
Serial Number:      SN-123456
Installation Date:  2023-01-15
Service Interval:   30 days
```

### 3. Record Your First Inspection (5 minutes)

**Menu:** Asset Management → Asset Inspections

```
1. Select Asset:        AC-001
2. Select Template:      AC Unit Monthly Inspection
3. Complete Checklist:
   ✓ AC operational?
   ✓ Temperature satisfactory?
   ✓ Filter condition: Good
   ✓ Unusual noise? No
   ✓ Water leakage? No
   ✓ Remote working? Yes
4. Result:              Pass
5. Submit
```

**If marked as "FAIL":**
→ System automatically creates Work Order with HIGH priority

---

## 📊 Key Workflows

### Workflow 1: Routine Inspection - All Pass

```
Asset Registered (AC-001)
    ↓
Schedule Inspection
    ↓
Manager/Staff Performs Inspection
    ↓
All Items Pass
    ↓
Result Recorded: PASS
    ↓
Inspection Added to Maintenance History
    ↓
Next Service Date Auto-calculated
```

### Workflow 2: Failed Inspection - Creates Work Order

```
Asset Registered (AC-001)
    ↓
Inspection Scheduled
    ↓
Manager/Staff Performs Inspection
    ↓
Item Failed: "Water Leaking"
    ↓
Result Recorded: FAIL
    ↓
✨ AUTOMATIC: Work Order Created ✨
    ↓
Work Order: WO-20240115153025-4821
Title: AC Unit Leaking Water
Priority: HIGH
Status: OPEN
    ↓
Manager Assigns to HVAC Technician
    ↓
Technician Updates Status: IN PROGRESS
    ↓
Technician Completes: Replaced Condensate Pump
    ↓
Technician Updates Status: COMPLETED
    ↓
Manager Verifies: VERIFIED
    ↓
Work Order Status: CLOSED
    ↓
Maintenance History Recorded
Cost: $500 | Parts: Condensate Pump
Next Service: 30 days later
```

### Workflow 3: Create Manual Work Order

```
Navigate to Work Orders
    ↓
Click "New Work Order"
    ↓
Fill Details:
   - Title: "AC Filter Replacement"
   - Type: Maintenance
   - Priority: Medium
   - Asset: AC-002
   - Due Date: 2024-02-15
    ↓
Assign to Staff
    ↓
Track Progress
    ↓
Close When Complete
```

---

## 📈 Checklist: System Setup

- [x] Database tables created (`schema_extended.sql`)
- [x] Categories populated (12 categories)
- [x] Asset types created (100+ types)
- [x] Inspection templates created (50+ templates)
- [x] Facility manager interface ready
- [x] Asset locations feature available
- [x] Assets management feature available
- [x] Inspections recording feature available
- [x] Work orders management feature available
- [x] Navigation menu updated

**Next Steps:**
- [ ] Create asset locations for your facility
- [ ] Register your assets with unique codes
- [ ] Assign inspection templates to assets
- [ ] Record first inspection
- [ ] Verify work order auto-creation
- [ ] Test work order workflow

---

## 🔍 Database Schema - Quick Reference

### assets
```
asset_code (unique)         → AC-001, GEN-02, EX-05
asset_name                  → Split AC Unit 2HP
manufacturer, model         → Daikin FTXS35LVG
serial_number               → SN-123456
installation_date           → 2023-01-15
service_interval_days       → 30
status                      → active, inactive, decommissioned
```

### asset_inspections
```
asset_id                    → Link to asset (AC-001)
template_id                 → Link to inspection template
inspected_by                → Staff member who inspected
inspection_date             → When inspection occurred
result                      → pass, fail, needs_attention
rating                      → 1-5 stars
is_verified                 → Verified by manager
```

### work_orders
```
work_order_code             → WO-20240115153025-4821
asset_id                    → AC-001
inspection_id               → Link to failed inspection
status                      → open, assigned, in_progress, completed, closed
priority                    → low, medium, high, urgent
assigned_to                 → Staff member assigned
```

### maintenance_history
```
asset_id                    → AC-001
maintenance_type            → routine, preventive, corrective
performed_by                → Technician
performed_date              → When work was done
cost                        → $500
parts_replaced              → Condensate pump
next_maintenance_date       → 2024-02-15
```

---

## ⚠️ Troubleshooting

**Q: Tables not created**
A: Check MySQL error log. Ensure `schema_extended.sql` was fully executed without errors.

**Q: Categories/types missing**
A: Run `php database/seed_assets.php` again.

**Q: Work order not creating from failed inspection**
A: Ensure inspection result is set to "Fail" (not "Needs Attention").

**Q: Can't see new menu items**
A: Log out and back in to refresh the session.

**Q: Asset code duplicate error**
A: Asset codes must be unique per facility. Use different codes like AC-001, AC-002, etc.

---

## 📞 Support

**For questions or issues:**

1. Check [ASSET_MANAGEMENT_GUIDE.md](../ASSET_MANAGEMENT_GUIDE.md)
2. Review database schema: `database/schema_extended.sql`
3. Check error logs: `debug-logs/` in VS Code

---

## 🎓 Example Data to Try

### Assets to Register
```
Category: HVAC / Cooling
├── AC-001 | Split AC Unit 2HP | Chairman's Office | Daikin | Service every 30 days
├── AC-002 | Split AC Unit 1.5HP | Conference Room | LG | Service every 30 days
└── AC-003 | Central AC System | Whole Building | Carrier | Service every 90 days

Category: Electrical & Power
├── GEN-01 | Diesel Generator 100kVA | Rooftop | Perkins | Service every 60 days
└── UPS-01 | UPS System 20kVA | Server Room | Eaton | Service every 7 days

Category: Fire & Life Safety
├── EX-01 | Fire Extinguisher 4kg | Entrance | Ansul | Service every 12 months
└── EX-02 | Fire Extinguisher 6kg | Office Area | Ansul | Service every 12 months
```

### Try This Inspection
```
1. Navigate to: Asset Inspections
2. Select: AC-001 (Split AC Unit)
3. Template: AC Unit Monthly Inspection
4. Check Items:
   ✓ AC operational? → YES
   ✓ Temperature satisfactory? → YES
   ✓ Filter condition → GOOD
   ✓ Unusual noise? → NO
   ✓ Water leakage? → YES ← Mark this as FAILED
   ✓ Remote working? → YES
5. Result: FAIL
6. Notes: "Water dripping from outdoor unit"
7. Submit → Work Order Created Automatically!
```

---

**Congratulations! Your Asset Management System is ready! 🎉**

Start by creating locations, then assets, then recording inspections.

