# Asset Management System - Implementation Guide

## Overview

The system has been enhanced with a comprehensive **Hierarchical Asset Management System** that enables detailed tracking of all facility assets, equipment, inspections, and maintenance activities.

## New System Structure

```
Facility
├── Category (e.g., HVAC, Electrical, Plumbing)
│   ├── Asset Type (e.g., AC Unit, Generator)
│   │   ├── Asset (e.g., AC-001)
│   │   │   ├── Location (e.g., Chairman's Office)
│   │   │   ├── Inspection Templates
│   │   │   ├── Inspection Records
│   │   │   ├── Maintenance History
│   │   │   └── Work Orders
```

## Installation Steps

### 1. Create Extended Database Schema

Run the following command to create all new tables:

```bash
mysql -u root -p facilityapp < database/schema_extended.sql
```

Or if using Docker/WAMP directly in the database:

```sql
-- Copy the contents of database/schema_extended.sql
-- Paste into your MySQL client (phpMyAdmin, MySQL Workbench, etc.)
-- Execute all queries
```

### 2. Populate Initial Data

Run the asset seeding script to populate categories, asset types, and inspection templates:

```bash
php database/seed_assets.php
```

Expected output:
```
🌱 Seeding Facility Management System...

📁 Creating Facility Categories...
  ✓ Building & Structural
  ✓ Restroom Facilities
  ... (12 categories total)

🏷️  Creating Asset Types...
  ✓ Building & Structural → Office/Building
  ✓ Building & Structural → Reception Area
  ... (100+ asset types)

📋 Creating Asset Inspection Templates...
  ✓ HVAC / Cooling → Split AC Unit
  ✓ HVAC / Cooling → Central AC System
  ... (inspection templates for key assets)

✅ Seeding completed successfully!
   Categories: 12
   Asset Types: 100+
   Inspection Templates: 50+
```

### 3. Verify Database Tables

Check that all new tables exist:

```sql
SHOW TABLES LIKE 'asset%';
SHOW TABLES LIKE '%facility_categories%';
SHOW TABLES LIKE '%work_order%';
```

Expected tables:
- `facility_categories`
- `asset_types`
- `asset_locations`
- `assets`
- `asset_inspection_templates`
- `asset_inspection_template_items`
- `asset_inspection_schedules`
- `asset_inspections`
- `asset_inspection_responses`
- `work_orders`
- `work_order_updates`
- `maintenance_history`

## Using the New System

### For Facility Managers

#### 1. Define Asset Locations

Navigate to: **Assets & Equipment → Asset Locations**

Create physical locations within your facility:
- **Name**: Chairman's Office, Server Room, Rooftop, etc.
- **Building**: Main, Annex, Extension
- **Floor**: 1, 2, 3, Ground
- **Description**: Additional details

#### 2. Register Assets

Navigate to: **Assets & Equipment**

Create individual asset records:

1. **Select Category** (e.g., HVAC / Cooling)
2. **Select Asset Type** (e.g., Split AC Unit)
3. **Asset Code**: Unique identifier (e.g., `AC-001`, `GEN-02`, `EX-05`)
4. **Asset Name**: Descriptive name
5. **Location**: Assign to physical location
6. **Specifications**:
   - Manufacturer
   - Model Number
   - Serial Number
   - Installation Date
   - Purchase Date
   - Warranty Expiration
   - Service Interval (in days)

**Example Assets:**
```
Category: HVAC / Cooling
├── AC-001 | Split AC Unit 2HP | Chairman's Office | Daikin FTXS35LVG | Service every 30 days
├── AC-002 | Split AC Unit 1.5HP | Conference Room | LG T12 | 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
└── EXT-05 | Fire Extinguisher 4kg | Entrance | Ansul | Service every 30 days
```

#### 3. Record Inspections

Navigate to: **Asset Inspections**

1. **Select Asset** to inspect
2. **Select Inspection Template** (predefined checklists)
3. **Complete Checklist**:
   - Answer all questions
   - Add notes/observations
   - Attach photos (optional)
4. **Mark Result**:
   - ✅ **Pass**: Asset functioning normally
   - ❌ **Fail**: Asset needs maintenance (auto-creates work order)
   - ⚠️ **Needs Attention**: Potential issues

**Automatic Work Order Creation:**
When an inspection is marked as "Fail", a work order is automatically generated with:
- High priority
- Asset linked
- Inspection reference
- Status: Open (awaiting assignment)

#### 4. Manage Work Orders

Navigate to: **Work Orders**

**Create Work Order:**
- Title: Descriptive name
- Work Type: Maintenance, Repair, Replacement, Inspection, Urgent
- Priority: Low, Medium, High, Urgent
- Related Asset (optional)
- Description: Detailed work requirements
- Due Date

**Workflow:**
```
Open → Assigned → In Progress → On Hold → Completed → Verified → Closed
```

**Actions:**
- View work order details
- Assign to staff member
- Update status
- Track progress
- Add update notes
- Delete (if not started)

#### 5. View Maintenance History

Each asset tracks:
- Inspection dates and results
- Maintenance activities
- Service costs
- Parts replaced
- Vendor information
- Next maintenance due date

### For Super Admin

Navigate to: **Super Admin Dashboard**

**Additional Features:**
- View all assets across all facilities
- Monitor asset health status
- Generate facility reports
- Audit asset lifecycle
- Track work order performance

## Pre-populated Facility Categories

### 1. Building & Structural
Office buildings, reception areas, conference rooms, corridors, staircases, ceilings, walls, floors, doors, windows, glass partitions, handrails, entrance points.

### 2. Restroom Facilities
Male/Female restrooms, toilets, urinals, wash basins, faucets, mirrors, soap dispensers, hand dryers, toilet paper dispensers, floor drains, ventilation.

### 3. HVAC / Cooling
Split AC units, central AC systems, indoor/outdoor units, thermostats, air vents, condensate drainage, server room cooling.

### 4. Electrical & Power
Distribution boards, electrical panels, power sockets, light fixtures, emergency lights, exit signs, UPS systems, inverters, batteries, generators, automatic transfer switches, voltage stabilizers, external lighting.

### 5. Plumbing & Water
Water supply systems, storage tanks, pumps, pressure pumps, water pipes, valves, drainage systems, sewage systems, floor drains, water meters.

### 6. Fire & Life Safety
Fire extinguishers, fire hose reels, alarm control panels, smoke detectors, heat detectors, manual call points, emergency lighting, exit signs, fire doors, emergency exits, assembly points, first aid kits.

### 7. Security
CCTV systems, cameras, network video recorders, digital video recorders, access control systems, biometric devices, security gates, perimeter fencing, security doors, intercom systems, security lighting, visitor management systems.

### 8. IT / Server
Server rooms, racks, servers, network switches, routers, UPS systems, dedicated cooling, fire protection, temperature/humidity monitoring.

### 9. Kitchen / Breakroom
Kitchens, refrigerators, microwaves, water dispensers, coffee machines, electric kettles, sinks, kitchen cabinets, countertops, waste bins.

### 10. External Facilities
Parking areas, driveways, walkways, landscaping, drainage channels, external walls, roofs, gutters, downpipes, external lighting, gates, perimeter fences, waste collection areas, signage.

### 11. Office Furniture & Fixtures
Office desks, chairs, conference tables, filing cabinets, storage cabinets, shelving, reception furniture, window blinds/curtains.

### 12. Cleaning & Housekeeping
Cleaning equipment, vacuum cleaners, mops, cleaning carts, waste bins, collection points, chemical storage, janitorial/utility rooms.

## Database Schema - Key Tables

### assets
```sql
- id: Primary Key
- facility_id: FK to facilities
- asset_type_id: FK to asset_types
- location_id: FK to asset_locations
- asset_code: Unique identifier (AC-001, GEN-02, etc.)
- asset_name: Descriptive name
- manufacturer, model, serial_number: Specifications
- installation_date, purchase_date, warranty_expires: Dates
- last_service_date, next_service_date: Maintenance dates
- service_interval_days: Days between services
- status: active, inactive, decommissioned, archived
```

### asset_inspections
```sql
- id: Primary Key
- asset_id: FK to assets
- template_id: FK to asset_inspection_templates
- inspected_by: FK to users (inspector)
- inspection_date: When inspection occurred
- result: pass, fail, needs_attention
- rating: 1-5 stars
- notes: Observations
- is_verified: Boolean - manager verified
- verified_by: FK to users (verifier)
```

### work_orders
```sql
- id: Primary Key
- facility_id: FK to facilities
- asset_id: FK to assets (optional)
- inspection_id: FK to asset_inspections (if from inspection)
- work_order_code: Unique WO-YYYYMMDDHHMM-XXXX
- title, description: Work details
- work_type: maintenance, repair, replacement, inspection, urgent
- priority: low, medium, high, urgent
- status: open, assigned, in_progress, on_hold, completed, verified, closed
- assigned_to: FK to users (staff/vendor)
- created_by: FK to users (creator)
- due_date, completed_at: Dates
- estimated_cost, actual_cost: Financial tracking
```

### maintenance_history
```sql
- id: Primary Key
- asset_id: FK to assets
- maintenance_type: routine, preventive, corrective, emergency
- work_order_id: FK to work_orders (optional)
- performed_by: FK to users (technician)
- performed_date: When maintenance occurred
- duration_minutes: How long it took
- cost: Maintenance cost
- parts_replaced, spares_used: What was replaced
- vendor, contact_person, contact_phone: Vendor info
- next_maintenance_date: When next maintenance due
```

## Key Features

✅ **Asset Registration**: Unique asset codes, detailed specifications
✅ **Hierarchical Organization**: Categories → Types → Individual Assets
✅ **Location Tracking**: Physical locations within facility
✅ **Inspection Management**: Predefined templates, pass/fail recording
✅ **Automatic Work Orders**: Failed inspections auto-create work orders
✅ **Maintenance History**: Complete audit trail of all maintenance
✅ **Work Order Workflow**: Open → Assigned → In Progress → Completed → Verified → Closed
✅ **Priority Management**: Urgent, High, Medium, Low priority levels
✅ **Status Tracking**: Asset health, work order status, maintenance schedules
✅ **Cost Tracking**: Estimated and actual costs for maintenance
✅ **Vendor Management**: Track service providers and contact info
✅ **Reporting**: Asset health, maintenance history, work order performance

## Sample Workflows

### AC Unit Maintenance Workflow
```
1. Administrator creates AC-001 (Split AC Unit)
   Location: Chairman's Office
   Service Interval: 30 days
   
2. Manager schedules inspection
   
3. Staff member performs inspection
   Result: FAIL (water leaking)
   
4. System creates Work Order WO-XXXXX
   Title: "AC Unit Leaking Water"
   Priority: HIGH
   Status: OPEN
   
5. Manager assigns to HVAC technician
   
6. Technician updates status: IN PROGRESS
   
7. Technician completes work, adds notes:
   - Replaced condensate pump
   - Cost: $500
   
8. Technician updates status: COMPLETED
   
9. Manager verifies completed work
   
10. Work order status: CLOSED
    
11. Maintenance history recorded:
    - Date: 2024-01-15
    - Type: Corrective maintenance
    - Parts replaced: Condensate pump
    - Cost: $500
    - Next service date: 2024-02-15
```

### Generator Routine Maintenance
```
1. Manager schedules generator inspection
   Template: "Generator Monthly Maintenance"
   
2. Technician performs inspection
   Checks:
   ✓ Fuel level
   ✓ Oil level
   ✓ Battery condition
   ✓ Load test passed
   Result: PASS
   
3. Maintenance history recorded
   Type: Routine maintenance
   Next service: 30 days later
```

## Troubleshooting

**Q: Work order not auto-creating from failed inspection?**
A: Ensure the inspection result is set to "Fail". Auto-creation requires failure status.

**Q: Can't see all asset types?**
A: Run `php database/seed_assets.php` to populate categories and types.

**Q: How to track costs?**
A: Record in work order (estimated) and maintenance history (actual).

**Q: How to generate maintenance schedules?**
A: Set `service_interval_days` when creating asset. System calculates `next_service_date`.

## Future Enhancements

- Automated email notifications for upcoming maintenance
- Mobile app for field inspections
- SMS alerts for urgent work orders
- Integration with maintenance vendors
- Predictive maintenance analytics
- Asset depreciation tracking
- Spare parts inventory management

---

**For support or questions, contact your system administrator.**
