# Feedback Export Functionality Guide

## Overview
The feedback/GRM system now supports **detailed exports** that include all conversation threads, responses, and submitter information per provider.

## Export Options

### 1. **Summary Exports** (Existing - Enhanced)
Quick overview reports without conversation details:
- **Summary PDF** - Basic feedback list with key metrics
- **Summary DOCX** - Word document version of summary

**Columns:**
- Reference Code
- Category
- Status
- Subject
- Provider
- Submitted Date
- Due Date

---

### 2. **Detailed Exports** (NEW)
Complete feedback records including all responses and conversation threads:

#### **Detailed CSV** ✨ Recommended for Analysis
Full-featured export with conversation threads in a single CSV file:

**Columns:**
1. Reference
2. Category
3. Status
4. Subject
5. Description (full feedback text)
6. Provider
7. Submitter Name
8. Submitter Email
9. Submitter Phone
10. Region
11. Submitted At (date + time)
12. Due At (date + time)
13. First Response At (date + time)
14. Resolved At (date + time)
15. Timely Response (Yes/No/Pending)
16. Response Count
17. **Conversation Thread** - Complete message history including:
    - Timestamp
    - Author name
    - Author type (public/admin/tp)
    - Message body
    - Email delivery status

**Best For:**
- Data analysis in Excel/Google Sheets
- Filtering and sorting feedback records
- Importing into other systems
- Complete audit trail with all responses

#### **Detailed PDF**
Professional report format with key details:

**Columns:**
- Reference
- Subject
- Provider
- Status
- Submitted Date
- First Response Date
- Timely (Yes/No/Pending)

**Note:** For full conversation threads, use CSV export. PDF provides overview with response timing.

---

## How to Export

### From Feedback List Page

1. Navigate to **Feedback / GRM** page
2. Click one of the export buttons in the header:
   - **Summary PDF** - Quick overview
   - **Summary DOCX** - Word document summary
   - **Detailed CSV** - Full data with responses ✨
   - **Detailed PDF** - Professional detailed report

### Export Scope

**Project-Level Users (Admin/M&E):**
- Exports include ALL feedbacks across all providers in the project

**Training Provider Users (TP Staff):**
- Exports are automatically filtered to only their provider's feedbacks
- Cannot see feedbacks from other providers

---

## Use Cases

### CSV Export Use Cases
1. **Monthly Provider Reports**
   - Export to CSV
   - Filter by provider
   - Share with specific TP for their records

2. **Response Time Analysis**
   - Open in Excel
   - Use pivot tables to analyze timely response rates
   - Group by category, provider, or region

3. **Audit Trail**
   - Complete conversation history
   - Email delivery confirmations
   - Timestamp tracking for compliance

4. **Stakeholder Reports**
   - Filter resolved feedbacks
   - Export conversation threads
   - Share with donors/partners

### PDF Export Use Cases
1. **Executive Summaries**
   - Quick overview for management
   - Professional format for presentations

2. **Printed Records**
   - Archive hard copies
   - Meeting documentation

---

## Data Included

### Summary Reports
```
Metrics:
- Total feedbacks
- Open count
- In Progress count
- Resolved count
- Timely response rate (%)

Per Feedback:
- Basic info (ref, category, status, subject)
- Provider name
- Key dates (submitted, due)
```

### Detailed Reports
```
Metrics: (same as summary)

Per Feedback:
- Complete submission details
- Full description text
- Submitter contact information
- Response timing analysis
- Complete conversation thread:
  * All messages (initial + responses)
  * Message timestamps
  * Author names and types
  * Email delivery status per message
```

---

## Technical Details

### File Naming Convention
```
feedback-summary-[PROJECT_CODE]-[DATE].pdf
feedback-summary-[PROJECT_CODE]-[DATE].docx
feedback-detailed-[PROJECT_CODE]-[DATE].csv
feedback-detailed-[PROJECT_CODE]-[DATE].pdf
```

Example:
```
feedback-detailed-PBPS-2026-08-14.csv
```

### CSV Format
- UTF-8 encoding
- Comma-separated
- Quoted strings for text with commas/newlines
- Excel-compatible

### Conversation Thread Format (CSV)
Messages are concatenated with `|` separator:
```
[2026-08-14 09:30] John Doe (public): Original feedback text | [2026-08-15 10:45] Jane Admin (admin): Thank you for your feedback [Email sent: 2026-08-15 10:45] | [2026-08-16 14:20] Provider Staff (tp): Issue resolved [Email sent: 2026-08-16 14:20]
```

---

## Permissions

Required permission: `view:feedback`

**Who can export:**
- ✅ Project Administrators
- ✅ M&E Officers
- ✅ TP Staff (their provider only)
- ❌ Public users

---

## Performance Limits

- Maximum 500 feedbacks per export
- Large exports may take 5-10 seconds to generate
- CSV exports process faster than PDF/DOCX

If you need more than 500 records, contact system administrator for database export.

---

## Audit Trail

All exports are logged in the audit system:
- Who exported the report
- When it was exported
- Report type and format
- Project context

Access via: Admin → Audit Logs → Filter by "formal_report_generated"

---

## Tips & Best Practices

### For CSV Analysis
1. **Open in Excel**: Double-click CSV file
2. **Enable text wrapping**: For conversation column
3. **Freeze header row**: View → Freeze Top Row
4. **Apply filters**: Data → Filter
5. **Create pivot tables**: For statistical analysis

### For Provider Sharing
1. Export Detailed CSV
2. Filter by specific provider
3. Remove other providers' data
4. Share filtered file with TP

### For Donor Reports
1. Export Detailed PDF for overview
2. Export Detailed CSV for appendix
3. Include both in report package

---

## Troubleshooting

**Q: Export shows no data**
- Check your provider scope (TP users see only their feedbacks)
- Verify feedbacks exist in the system

**Q: CSV doesn't open correctly**
- Use Excel or Google Sheets
- For other tools, specify UTF-8 encoding and comma delimiter

**Q: Conversation thread is cut off**
- Increase cell/column width
- Enable text wrapping in Excel

**Q: Export takes too long**
- Normal for large datasets (500 feedbacks)
- Consider using filters first, then export

**Q: Need more than 500 records**
- Contact system administrator
- Request direct database export

---

## API Endpoints

For developers/integrations:

```
GET /api/projects/:projectId/reports/feedback/summary.pdf
GET /api/projects/:projectId/reports/feedback/summary.docx
GET /api/projects/:projectId/reports/feedback/detailed.csv
GET /api/projects/:projectId/reports/feedback/detailed.pdf
```

Requires authentication token with `view:feedback` permission.

---

## Future Enhancements (Roadmap)

Potential improvements for consideration:
- [ ] Date range filters for exports
- [ ] Category-specific exports
- [ ] Excel (.xlsx) format with multiple sheets
- [ ] Email scheduled reports
- [ ] Dashboard export scheduling
- [ ] Custom column selection

---

## Support

For questions or issues with exports:
1. Check this guide first
2. Review audit logs for export history
3. Contact system administrator
4. Report bugs via feedback system

---

**Last Updated:** August 14, 2026
**Version:** 1.0
