86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports;
|
|
|
|
use App\Models\Shift;
|
|
use Filament\Actions\Imports\ImportColumn;
|
|
use Filament\Actions\Imports\Importer;
|
|
use Filament\Actions\Imports\Models\Import;
|
|
|
|
class ShiftImporter extends Importer
|
|
{
|
|
protected static ?string $model = Shift::class;
|
|
|
|
public static function getColumns(): array
|
|
{
|
|
return [
|
|
ImportColumn::make('name')
|
|
->requiredMapping()
|
|
->exampleHeader('Shift Name')
|
|
->example('Day')
|
|
->label('Shift Name')
|
|
->rules(['required']),
|
|
ImportColumn::make('block')
|
|
->requiredMapping()
|
|
->exampleHeader('Block Name')
|
|
->example('Block A')
|
|
->label('Block Name')
|
|
->relationship(resolveUsing:'name')
|
|
->rules(['required']),
|
|
ImportColumn::make('plant')
|
|
->requiredMapping()
|
|
->exampleHeader('Plant Name')
|
|
->example('Ransar Industries-I')
|
|
->label('Plant Name')
|
|
->relationship(resolveUsing:'name')
|
|
->rules(['required']),
|
|
ImportColumn::make('start_time')
|
|
->requiredMapping()
|
|
->exampleHeader('Start Time')
|
|
->example('08:00:00')
|
|
->label('Start Time')
|
|
->rules(['required']),
|
|
ImportColumn::make('duration')
|
|
->requiredMapping()
|
|
->numeric()
|
|
->exampleHeader('Shift Duration')
|
|
->example('11.30')
|
|
->label('Shift Duration')
|
|
->rules(['required']),
|
|
ImportColumn::make('end_time')
|
|
->requiredMapping()
|
|
->exampleHeader('End Time')
|
|
->example('19:30:00')
|
|
->label('End Time')
|
|
->rules(['required']),
|
|
ImportColumn::make('status')
|
|
->requiredMapping()
|
|
->exampleHeader('Active Status')
|
|
->example('Active')
|
|
->label('Active Status')
|
|
->rules(['required']),
|
|
];
|
|
}
|
|
|
|
public function resolveRecord(): ?Shift
|
|
{
|
|
// return Shift::firstOrNew([
|
|
// // Update existing records, matching them by `$this->data['column_name']`
|
|
// 'email' => $this->data['email'],
|
|
// ]);
|
|
|
|
return new Shift();
|
|
}
|
|
|
|
public static function getCompletedNotificationBody(Import $import): string
|
|
{
|
|
$body = 'Your shift 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;
|
|
}
|
|
}
|