# lead-export Specification ## Purpose Staff with export permission take a lead listing out of the system as an Excel file that matches what they see on screen. ## Requirements ### Requirement: Listing export The system SHALL export the Lead Listing and the Event Leads Listing as an `.xlsx` file that the browser downloads. The file SHALL hold the on-screen columns in the same order, with the current search or filters applied across all pages. Mobile numbers SHALL be stored as text and dates as dates. #### Scenario: Export what is on screen - **GIVEN** the Event Leads Listing for `KL Food Fair` filtered to temperature Hot, with 45 matching leads over 3 pages - **WHEN** the user exports - **THEN** the file has one header row and 45 lead rows - **AND** the header row lists name, mobile, email, lead type, salesperson, temperature, status, interests and next follow-up #### Scenario: Lead Listing export with a search - **WHEN** the user searches `aisyah` on Leads and exports - **THEN** the file holds only the matching leads, with the Lead Listing's columns #### Scenario: Mobile kept as text - **WHEN** the exported file is opened in Excel - **THEN** a mobile shows as `+60123456701`, not as a number ### Requirement: Export size limit An export of more than 20,000 rows SHALL be refused, and the listing page SHALL show a message asking the user to narrow the search or filters. #### Scenario: Too many rows - **WHEN** the export would hold more than 20,000 rows - **THEN** no file is produced and the page asks the user to narrow the filters ### Requirement: Export permission Exporting SHALL require `BO_LEADS_EXPORT` together with the listing's own module: `BO_LEADS` for the Lead Listing, `BO_EVENT_LEADS` for the Event Leads Listing. - **Button:** the Export button SHALL show only to users who hold the export permission. - **Audit:** each export SHALL be recorded with the username, the listing and the row count, and SHALL NOT record lead data. #### Scenario: No export permission - **WHEN** a user with `BO_EVENT_LEADS` but not `BO_LEADS_EXPORT` opens an event's leads - **THEN** no Export button shows, and calling the export endpoint responds 403 #### Scenario: Export permission without the listing - **WHEN** a user with `BO_LEADS_EXPORT` but not `BO_LEADS` calls the Lead Listing export endpoint - **THEN** it responds 403