130 lines
4.5 KiB
PHP
130 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports;
|
|
|
|
use App\Models\StickerMaster;
|
|
use Filament\Actions\Imports\ImportColumn;
|
|
use Filament\Actions\Imports\Importer;
|
|
use Filament\Actions\Imports\Models\Import;
|
|
|
|
class StickerMasterImporter extends Importer
|
|
{
|
|
protected static ?string $model = StickerMaster::class;
|
|
|
|
public static function getColumns(): array
|
|
{
|
|
return [
|
|
ImportColumn::make('item_id')
|
|
->requiredMapping()
|
|
->numeric()
|
|
->label('Item Code')
|
|
->exampleHeader('Item Code')
|
|
->rules(['required', 'integer']),
|
|
ImportColumn::make('plant_id')
|
|
->requiredMapping()
|
|
->relationship()
|
|
->exampleHeader('Plant Name')
|
|
->label('Plant Name')
|
|
->rules(['required']),
|
|
// ->transform(fn($value) => \App\Models\Plant::where('name', $value)->value('id') ?? null),
|
|
ImportColumn::make('serial_number_motor')
|
|
->requiredMapping()
|
|
->exampleHeader('Serial Number Motor'),
|
|
|
|
ImportColumn::make('serial_number_pump')
|
|
->requiredMapping()
|
|
->exampleHeader('Serial Number Pump'),
|
|
|
|
ImportColumn::make('serial_number_pumpset')
|
|
->requiredMapping()
|
|
->exampleHeader('Serial Number PumpSet'),
|
|
|
|
ImportColumn::make('pack_slip_motor')
|
|
->requiredMapping()
|
|
->exampleHeader('Pack Slip Motor'),
|
|
|
|
ImportColumn::make('pack_slip_pump')
|
|
->requiredMapping()
|
|
->exampleHeader('Pack Slip Pump'),
|
|
|
|
ImportColumn::make('pack_slip_pumpset')
|
|
->requiredMapping()
|
|
->exampleHeader('Pack Slip PumpSet'),
|
|
|
|
ImportColumn::make('name_plate_motor')
|
|
->requiredMapping()
|
|
->exampleHeader('Name Plate Motor'),
|
|
|
|
ImportColumn::make('name_plate_pump')
|
|
->requiredMapping()
|
|
->exampleHeader('Name Plate Pump'),
|
|
|
|
ImportColumn::make('name_plate_pumpset')
|
|
->requiredMapping()
|
|
->exampleHeader('Name Plate PumpSet'),
|
|
|
|
ImportColumn::make('tube_sticker_motor')
|
|
->requiredMapping()
|
|
->exampleHeader('Tube Sticker Motor'),
|
|
|
|
ImportColumn::make('tube_sticker_pump')
|
|
->requiredMapping()
|
|
->exampleHeader('Tube Sticker Pump'),
|
|
|
|
ImportColumn::make('tube_sticker_pumpset')
|
|
->requiredMapping()
|
|
->exampleHeader('Tube Sticker PumpSet'),
|
|
|
|
ImportColumn::make('warranty_card')
|
|
->requiredMapping()
|
|
->exampleHeader('Warranty Card'),
|
|
|
|
ImportColumn::make('part_validation1')
|
|
->requiredMapping()
|
|
->label('Part Validation 1')
|
|
->exampleHeader('Part Validation 1'),
|
|
|
|
ImportColumn::make('part_validation2')
|
|
->requiredMapping()
|
|
->label('Part Validation 2')
|
|
->exampleHeader('Part Validation 2'),
|
|
|
|
ImportColumn::make('part_validation3')
|
|
->requiredMapping()
|
|
->label('Part Validation 3')
|
|
->exampleHeader('Part Validation 3'),
|
|
|
|
ImportColumn::make('part_validation4')
|
|
->requiredMapping()
|
|
->label('Part Validation 4')
|
|
->exampleHeader('Part Validation 4'),
|
|
|
|
ImportColumn::make('part_validation5')
|
|
->requiredMapping()
|
|
->label('Part Validation 5')
|
|
->exampleHeader('Part Validation 5'),
|
|
];
|
|
}
|
|
|
|
public function resolveRecord(): ?StickerMaster
|
|
{
|
|
// return StickerMaster::firstOrNew([
|
|
// // Update existing records, matching them by `$this->data['column_name']`
|
|
// 'email' => $this->data['email'],
|
|
// ]);
|
|
|
|
return new StickerMaster();
|
|
}
|
|
|
|
public static function getCompletedNotificationBody(Import $import): string
|
|
{
|
|
$body = 'Your sticker master 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;
|
|
}
|
|
}
|