=== Merged Lead Owner Summary Report API Test === API Endpoint: POST /api/reports/get_report_section Request Parameters: { "type": "lead_owner_summary", "startDate": "2024-01-01", "endDate": "2024-12-31" } New Response Structure (Merged with Details): { "success": true, "data": [ { "owner_id": 1, "owner_name": "Dr. Smith", "counts": { "new_call_count": 15, "converted_count": 8, "touched_count": 25, "follow_up_count": 12, "junk_lead_count": 5, "lost_count": 3, "appointment_count": 10, "total_leads": 30 }, "new_calls": [ { "id": 101, "lead_name": "John Doe", "lead_email": "john@example.com", "lead_primary_phone": "9876543210", "lead_status": "new", "lead_source": "Website", "created_at": "01-01-2024 10:30:00", "url_category": "Google Ads", "utm_source": "google", // ... all other lead fields } // ... more new call leads ], "converted": [ { "id": 102, "lead_name": "Jane Smith", "lead_status": "converted", // ... complete lead details } // ... more converted leads ], "touched": [ // ... leads that have been assigned to owners ], "follow_up": [ // ... leads with follow-up status ], "junk_leads": [ // ... junk leads ], "lost": [ // ... lost leads ], "appointments": [ // ... leads with appointments ] }, { "owner_id": null, "owner_name": "Unassigned", "counts": { "new_call_count": 20, "converted_count": 0, "touched_count": 0, "follow_up_count": 5, "junk_lead_count": 3, "lost_count": 2, "appointment_count": 0, "total_leads": 30 }, "new_calls": [ // ... unassigned new leads ], // ... other categories } ], "date_range": { "start_date": "2024-01-01", "end_date": "2024-12-31" } } === Benefits of Merged Structure === 1. Single API Call: Get both summary counts and detailed data 2. Owner-wise Grouping: All data organized by owner name 3. Category Separation: Each status type has its own array 4. Complete Lead Details: Full lead information in each category 5. Easy Frontend Processing: Direct access to counts and details === Frontend Usage Example === // JavaScript example for displaying the merged data fetch('/api/reports/get_report_section', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token }, body: JSON.stringify({ type: 'lead_owner_summary', startDate: '2024-01-01', endDate: '2024-12-31' }) }) .then(response => response.json()) .then(data => { if (data.success) { data.data.forEach(owner => { console.log('Owner:', owner.owner_name); console.log('Counts:', owner.counts); // Display summary cards displaySummaryCard(owner.owner_name, owner.counts); // Access detailed data for each category if (owner.new_calls.length > 0) { console.log('New Calls Details:', owner.new_calls); } if (owner.converted.length > 0) { console.log('Converted Details:', owner.converted); } // ... handle other categories }); } }); === Data Structure Explanation === Each owner object contains: - owner_id: The owner's ID (null for unassigned) - owner_name: The owner's name ('Unassigned' for unassigned) - counts: Object with all category counts - new_calls: Array of leads where lead_owner_id is null/empty - converted: Array of leads with status 'converted' - touched: Array of leads where lead_owner_id is not null/empty - follow_up: Array of leads with follow-up statuses - junk_leads: Array of leads with 'Junk Lead' status - lost: Array of leads with lost statuses - appointments: Array of leads with book_an_appoitment_id === Status Conditions (Unchanged) === new_call: lead_owner_id IS NULL OR lead_owner_id = '' converted: lead_status = 'converted' touched: lead_owner_id IS NOT NULL AND lead_owner_id != '' follow_up: lead_status IN ('Not Contacted', 'Contact In Future', 'Attempted to Contact', 'Pre-Qualified') junk_lead: lead_status = 'Junk Lead' lost: lead_status IN ('Not-Qualified', 'Lost Lead') appointment: book_an_appoitment_id IS NOT NULL AND book_an_appoitment_id != '' === Advantages === ✓ Eliminates need for separate detail API calls ✓ Reduces network requests ✓ Provides complete data hierarchy ✓ Maintains backward compatibility with counts ✓ Enables rich dashboard interfaces ✓ Supports drill-down functionality without additional API calls