Merge pull request 'Added alert mail rule exporter file' (#161) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
Reviewed-on: #161
This commit was merged in pull request #161.
This commit is contained in:
73
app/Filament/Exports/AlertMailRuleExporter.php
Normal file
73
app/Filament/Exports/AlertMailRuleExporter.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\Plant;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class AlertMailRuleExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = AlertMailRule::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('module')
|
||||
->label('MODULE'),
|
||||
ExportColumn::make('rule_name')
|
||||
->label('RULE NAME'),
|
||||
ExportColumn::make('email')
|
||||
->label('EMAIL'),
|
||||
ExportColumn::make('schedule_type')
|
||||
->label('SCHEDULE TYPE'),
|
||||
ExportColumn::make('plant')
|
||||
->label('PLANT CODE')
|
||||
->formatStateUsing(function ($state) {
|
||||
// $state is the plant ID from the database
|
||||
if ($state == 0) {
|
||||
return 'All Plants';
|
||||
}
|
||||
|
||||
$plant = Plant::find($state);
|
||||
return $plant ? $plant->code : 'Unknown';
|
||||
}),
|
||||
ExportColumn::make('cc_emails')
|
||||
->label('CC EMAILS'),
|
||||
ExportColumn::make('invoiceMaster.receiving_plant_name')
|
||||
->label('RECEIVING PLANT NAME'),
|
||||
ExportColumn::make('invoiceMaster.transport_name')
|
||||
->label('TRANSPORT NAME'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your alert mail rule export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
|
||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user