PHP code example of azaharizaman / nexus-reporting

1. Go to this page and download the library: Download azaharizaman/nexus-reporting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

azaharizaman / nexus-reporting example snippets


use Nexus\Reporting\Services\ReportManager;
use Nexus\Reporting\ValueObjects\ReportFormat;
use Nexus\Reporting\ValueObjects\ScheduleType;
use Nexus\Reporting\ValueObjects\ReportSchedule;

$reportId = $reportManager->createReport([
    'name' => 'Monthly Sales Report',
    'query_id' => $analyticsQueryId,
    'owner_id' => $userId,
    'format' => ReportFormat::PDF,
    'schedule' => new ReportSchedule(
        type: ScheduleType::MONTHLY,
        cronExpression: '0 9 1 * *', // 9 AM on 1st of month
        startsAt: new \DateTimeImmutable('2025-12-01'),
        endsAt: null,
        maxOccurrences: null
    ),
    'recipients' => [$customer, $manager],
    'template_config' => [
        'logo_path' => 'storage://logos/company.png',
        'css_path' => 'storage://templates/invoice.css'
    ]
]);

$result = $reportManager->generateReport($reportId, [
    'start_date' => '2025-01-01',
    'end_date' => '2025-01-31'
]);

if ($result->isSuccessful()) {
    $filePath = $result->getFilePath(); // storage://reports/active/xyz.pdf
    $fileSize = $result->getFileSize();
}

// Returns QueryResultInterface without storage
$queryResult = $reportManager->previewReport($reportId, [
    'customer_id' => '12345'
]);

// Send to AJAX endpoint for real-time dashboard
return response()->json($queryResult->getData());

// Generate invoices for 1,000 customers
$jobIds = $reportManager->generateBatch($reportId, $customerIds);

// Scheduler processes with max 10 concurrent workers
// Each job tracked independently with retry logic

'template_config' => [
    'logo_path' => 'storage://assets/logo-v2.png',
    'css_path' => 'storage://templates/branded.css',
    'header_html' => '<div class="header">Company Inc.</div>',
    'footer_html' => '<div class="footer">Page {page}</div>',
    'template_version' => '2.1.0' // Version control for rollback
]