# ═══════════════════════════════════════════════════════════════
# PHASE 5: CARDS, ACCESS CONTROL & GUESTS MODULE
# Module directory: /modules/cards/
# ═══════════════════════════════════════════════════════════════
# READ THE MASTER PROMPT FIRST.

## YOUR TABLES
card_types, card_designs, member_cards, card_requests, card_print_batches,
card_print_batch_items, access_points, access_control_rules, member_access_log,
guest_pass_types, guest_passes, guest_visits, guest_visit_facilities,
guest_policy_rules, guest_blacklist, carnet_types, carnets, carnet_entries

## PAGES TO BUILD

### 1. Cards Listing (`GET /cards`)
- DataTable: Card#, Member, Type, Issue Date, Expiry, Status, Actions
- Expiring cards highlighted

### 2. Card Requests (`GET /cards/requests`)
- DataTable of card_requests
- Create new request (new/replacement/renewal)
- Approve/reject workflow
- Link to member

### 3. Card Production & Printing
- Print batch management
- Batch creation from approved requests
- Print batch items tracking

### 4. Card Types Management
- CRUD for card_types

### 5. Access Points (`GET /access/points`)
- CRUD for access_points
- Configure hardware type, direction

### 6. Access Control Rules (`GET /access/rules`)
- Per access point rules
- Membership type restrictions, time restrictions, day restrictions

### 7. Access Log (`GET /access/log`)
- DataTable: Time, Direction, Member, Access Point, Method, Granted, Reason
- Use vw_today_access view
- Date range filter
- Real-time view (auto-refresh)

### 8. Guest Pass Management (`GET /guests`)
- DataTable: Pass#, Host Member, Guest Name, Date, Type, Status
- Issue guest pass form: Host member lookup, guest details, pass type, date, fee
- Check-in / check-out tracking
- Validate against guest_policy_rules (max visits, same guest limits, etc.)

### 9. Guest Blacklist (`GET /guests/blacklist`)
- CRUD for guest_blacklist
- Check during pass issuance

### 10. Carnet Management (`GET /carnets`)
- Carnet types CRUD
- Issue carnet to member
- Track entries (carnet_entries)
- Entry recording interface

## BUSINESS LOGIC
- Card request fee creates invoice
- Card number generated via SequenceGenerator
- Guest pass number generated via SequenceGenerator
- Guest pass issuance checks blacklist
- Guest policy rules enforce limits
- Access log records every entry/exit
- Carnet entry updates remaining count (DB trigger handles decrement)

## DASHBOARD WIDGETS
1. **Expiring Cards** — Cards expiring in 30 days
2. **Today's Access** — Entry count today
3. **Active Guest Passes** — Today's active guest passes

## PERMISSIONS
cards.view, cards.manage, cards.print,
guests.view, guests.create,
access.view, access.manage