Added vehicle entry importer and exporter
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
65
app/Filament/Exports/VehicleEntryExporter.php
Normal file
65
app/Filament/Exports/VehicleEntryExporter.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\VehicleEntry;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class VehicleEntryExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = VehicleEntry::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('uuid')
|
||||
->label('UUID'),
|
||||
ExportColumn::make('boom_opened')
|
||||
->label('BOOM OPENED'),
|
||||
ExportColumn::make('vehicle_number')
|
||||
->label('VEHICLE NUMBER'),
|
||||
ExportColumn::make('entry_time')
|
||||
->label('ENTRY TIME'),
|
||||
ExportColumn::make('exit_time')
|
||||
->label('EXIT TIME'),
|
||||
ExportColumn::make('duration')
|
||||
->label('DURATION'),
|
||||
ExportColumn::make('type')
|
||||
->label('TYPE'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your vehicle entry 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;
|
||||
}
|
||||
}
|
||||
88
app/Filament/Imports/VehicleEntryImporter.php
Normal file
88
app/Filament/Imports/VehicleEntryImporter.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\VehicleEntry;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class VehicleEntryImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = VehicleEntry::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('PLANT CODE')
|
||||
->example('1000')
|
||||
->label('PLANT CODE')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('vehicle_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('VEHICLE NUMBER')
|
||||
->example('ABC123')
|
||||
->label('VEHICLE NUMBER')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('uuid')
|
||||
->label('UUID')
|
||||
->exampleHeader('UUID')
|
||||
->example('ABC123'),
|
||||
ImportColumn::make('boom_opened')
|
||||
->exampleHeader('BOOM OPENED')
|
||||
->example('Auto')
|
||||
->label('BOOM OPENED'),
|
||||
ImportColumn::make('entry_time')
|
||||
->requiredMapping()
|
||||
->exampleHeader('ENTRY TIME')
|
||||
->example('2023-01-01 09:00:00')
|
||||
->label('ENTRY TIME'),
|
||||
ImportColumn::make('exit_time')
|
||||
->exampleHeader('EXIT TIME')
|
||||
->example('2023-01-01 17:00:00')
|
||||
->label('EXIT TIME'),
|
||||
ImportColumn::make('duration')
|
||||
->exampleHeader('DURATION (HOURS)')
|
||||
->example('8')
|
||||
->label('DURATION (HOURS)'),
|
||||
ImportColumn::make('type')
|
||||
->exampleHeader('TYPE')
|
||||
->example('TRUCK')
|
||||
->label('TYPE'),
|
||||
ImportColumn::make('created_by')
|
||||
->exampleHeader('CREATED BY')
|
||||
->example('John Doe')
|
||||
->label('CREATED BY'),
|
||||
ImportColumn::make('updated_by')
|
||||
->exampleHeader('UPDATED BY')
|
||||
->example('Jane Doe')
|
||||
->label('UPDATED BY'),
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?VehicleEntry
|
||||
{
|
||||
// return VehicleEntry::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new VehicleEntry();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your vehicle entry import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user