libra/docs/stories/story-6.4-data-export-user-...

1.6 KiB

Story 6.4: Data Export - User Lists

Epic Reference

Epic 6: Admin Dashboard

User Story

As an admin, I want to export user data in CSV and PDF formats, So that I can generate reports and maintain offline records.

Acceptance Criteria

Export Options

  • Export all users
  • Export individual clients only
  • Export company clients only

Filters

  • Date range (created)
  • Status (active/deactivated)

CSV Export Includes

  • Name, email, phone
  • User type
  • National ID / Company registration
  • Status
  • Created date

PDF Export Includes

  • Same data with professional formatting
  • Libra branding header
  • Generation timestamp

Bilingual

  • Column headers based on admin language

Technical Notes

Use league/csv for CSV and barryvdh/laravel-dompdf for PDF.

public function exportCsv(): StreamedResponse
{
    return response()->streamDownload(function () {
        $csv = Writer::createFromString();
        $csv->insertOne([__('export.name'), __('export.email'), ...]);

        User::whereIn('user_type', ['individual', 'company'])
            ->cursor()
            ->each(fn($user) => $csv->insertOne([
                $user->name,
                $user->email,
                // ...
            ]));

        echo $csv->toString();
    }, 'users-export.csv');
}

Definition of Done

  • CSV export works with all filters
  • PDF export works with branding
  • Large datasets handled efficiently
  • Tests pass

Estimation

Complexity: Medium | Effort: 3-4 hours