93 lines
3.4 KiB
PHP
93 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Exports;
|
|
|
|
use App\Models\MfmReading;
|
|
use Filament\Actions\Exports\ExportColumn;
|
|
use Filament\Actions\Exports\Exporter;
|
|
use Filament\Actions\Exports\Models\Export;
|
|
|
|
class MfmReadingExporter extends Exporter
|
|
{
|
|
protected static ?string $model = MfmReading::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('plant.name')
|
|
->label('PLANT'),
|
|
ExportColumn::make('mfmMeter.name')
|
|
->label('MFM METER NAME'),
|
|
ExportColumn::make('apparent_energy_received')
|
|
->label('APPARENT ENERGY RECEIVED'),
|
|
ExportColumn::make('reactive_energy_received')
|
|
->label('REACTIVE ENERGY RECEIVED'),
|
|
ExportColumn::make('active_energy_received')
|
|
->label('ACTIVE ENERGY RECEIVED'),
|
|
ExportColumn::make('active_power_r')
|
|
->label('ACTIVE POWER R'),
|
|
ExportColumn::make('active_power_y')
|
|
->label('ACTIVE POWER Y'),
|
|
ExportColumn::make('active_power_b')
|
|
->label('ACTIVE POWER B'),
|
|
ExportColumn::make('active_power_total')
|
|
->label('ACTIVE POWER TOTAL'),
|
|
ExportColumn::make('voltage_ry')
|
|
->label('VOLTAGE RY'),
|
|
ExportColumn::make('voltage_yb')
|
|
->label('VOLTAGE YB'),
|
|
ExportColumn::make('voltage_br')
|
|
->label('VOLTAGE BR'),
|
|
ExportColumn::make('current_r')
|
|
->label('CURRENT R'),
|
|
ExportColumn::make('current_y')
|
|
->label('CURRENT Y'),
|
|
ExportColumn::make('current_b')
|
|
->label('CURRENT B'),
|
|
ExportColumn::make('current_n')
|
|
->label('CURRENT N'),
|
|
ExportColumn::make('voltage_r_n')
|
|
->label('VOLTAGE R N'),
|
|
ExportColumn::make('voltage_y_n')
|
|
->label('VOLTAGE Y N'),
|
|
ExportColumn::make('voltage_b_n')
|
|
->label('VOLTAGE B N'),
|
|
ExportColumn::make('frequency')
|
|
->label('FREQUENCY'),
|
|
ExportColumn::make('power_factor_r')
|
|
->label('POWER FACTOR R'),
|
|
ExportColumn::make('power_factor_y')
|
|
->label('POWER FACTOR Y'),
|
|
ExportColumn::make('power_factor_b')
|
|
->label('POWER FACTOR B'),
|
|
ExportColumn::make('power_factor_total')
|
|
->label('POWER FACTOR TOTAL'),
|
|
ExportColumn::make('created_at')
|
|
->label('CREATED AT'),
|
|
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 mfm reading 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;
|
|
}
|
|
}
|