visualbuilder/filament-export-scheduler

Configure scheduled routines for filament exporters

3.0.24 2024-11-22 07:10 UTC

README

Latest Version on Packagist run-tests Total Downloads GitHub commit activity

Email automated exports on a defined schedule - keep the management happy with timely reporting and minimise effort.

Export Schedules pack shot

Empower users to create their own reports

List Schedules

Any Filament Exporter can be used as the starting point

  • Exporters will be discovered in App\Filament\Exporters or add more locations in the config
  • Send Exports to other users
  • To ensure data security only system users can receive reports

Setup Schedules

Easy Frequency Selection

  • Choose from preset frequencies
    • daily
    • weekly
    • monthly
    • quarterly
    • half yearly
    • yearly
  • Or use a custom Cron for non standard schedules

Setup Schedules

Customise query data range

  • Choose from preset query ranges
    • today
    • yesterday
    • last 7 days
    • last week
    • last 30 days
    • last month
    • this month
    • last quarter
    • this year
    • last year
  • Custom date field if not created_at can be set in the Exporter

Users can choose which columns to include

  • Currently all columns must be defined in the exporter
  • Maybe will add ability to add user definable columns
  • All Column Formatting options set in the exporter

Edit Columns

Attractive HTML Email templates

  • Default HTML email template included
  • Or works well with Visual Builder Email Templates - if you want user editable emails
  • Custom Report Builder and Templates coming soon

Email

Installation

You can install the package via composer:

composer require visualbuilder/filament-export-scheduler

Copy views and migrations, run the migration

php artisan export-scheduler:install

Optionally seed an example schedule for the users table This will export all Users on the 1st of every month.

php artisan db:seed --class=ExportScheduleSeeder

Schedule Command in Laravel

To enable automatic sending you must add the console command to your scheduler.

1. Modify the Scheduler

Open app\Console\Kernel.php:

protected function schedule(Schedule $schedule)
{
    $schedule->command('export:run')->everyMinute();
}

2. Check servers cron

Ensure your server is set up to run Laravel's scheduler by adding this cron entry

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

3. Review the config file

Here you can

  • override the resource page
  • customise the navigation menu
  • set the disk to be used
  • customise which notification and email template is used
  • set which user classes can receive reports
return [

    /**
     * To customise the Export Schedule Resource put your own resource here
     */
    'resources' => [ExportScheduleResource::class],

    /**
     * The success Notification and Mailable to use
     */
    'notification' => ScheduledExportCompleteNotification::class,
    'mailable' => ExportReady::class,

    /**
     * Allow users to choose from Exporters in these directories
     */
    'exporter_directories' => [
        'App\Filament\Exporters',
    ],
    
    /**
     * Where the exports should be stored local or s3 
     */
    'file_disk' => 'local',
    
    /**
     * Admin Panel Navigation
     * See also Plugin options
     */
    'navigation' => [
        'enabled'      => true,
        'sort'         => 100,
        'label'        => 'Scheduled Report',
        'plural_label' => 'Scheduled Reports',
        'icon'         => 'heroicon-o-paper-airplane',
        'group'        => 'Reports',
        'cluster'      => false,
        'position'     => \Filament\Pages\SubNavigationPosition::Top
    ],

    /**
     * Which authenticatable models should be allowed to receive exports
     * Will be used to populate the Owner picker 
     */
    'user_models' => [

        [
            'model' => \App\Models\User::class,
            'title_attribute' => 'email',
        ],
    ],
];

Add the plugin to your filament panel provider

use VisualBuilder\ExportScheduler\ExportSchedulerPlugin;

public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->plugins([
                ExportSchedulerPlugin::make(),

Make some export classes with

php artisan make:filament-exporter

Testing

composer test

To prove the integrity of the system the test suite creates these schedules and simulates running the tasks every day for 4 years to ensure leap years are handled correctly.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.