Added pallet validation importer
This commit is contained in:
98
app/Filament/Imports/PalletValidationImporter.php
Normal file
98
app/Filament/Imports/PalletValidationImporter.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\PalletValidation;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class PalletValidationImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = PalletValidation::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('pallet_number')
|
||||
->requiredMapping()
|
||||
->label('Pallet Number')
|
||||
->example('EP-2505001'),
|
||||
ImportColumn::make('serial_number')
|
||||
->requiredMapping()
|
||||
->example('12345678901234')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('pallet_status')
|
||||
->requiredMapping()
|
||||
->label('Pallet Status')
|
||||
->example('Completed'),
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->label('Locator Number')
|
||||
->example('W05-D1B'),
|
||||
ImportColumn::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->requiredMapping()
|
||||
->numeric()
|
||||
->example(1)
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example('Ransar Industries-I')
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->requiredMapping()
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->requiredMapping()
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_at')
|
||||
->label('Scanned At')
|
||||
->requiredMapping()
|
||||
->example('01-01-2025 08:00:00')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->requiredMapping()
|
||||
->example('Jothi')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->requiredMapping()
|
||||
->example('Jothi')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->example('Jothi')
|
||||
->requiredMapping(),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?PalletValidation
|
||||
{
|
||||
// return PalletValidation::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new PalletValidation();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your pallet validation 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