Added process order importer
This commit is contained in:
79
app/Filament/Imports/ProcessOrderImporter.php
Normal file
79
app/Filament/Imports/ProcessOrderImporter.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\ProcessOrder;
|
||||||
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
|
use Filament\Actions\Imports\Importer;
|
||||||
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
|
||||||
|
class ProcessOrderImporter extends Importer
|
||||||
|
{
|
||||||
|
protected static ?string $model = ProcessOrder::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ImportColumn::make('plant')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Plant Name')
|
||||||
|
->example('Ransar Industries-I')
|
||||||
|
->label('Plant Name')
|
||||||
|
->relationship(resolveUsing:'name')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('item_id')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Item Code')
|
||||||
|
->example('123456')
|
||||||
|
->label('Item Code')
|
||||||
|
->relationship(resolveUsing: 'code')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('process_order')
|
||||||
|
->exampleHeader('Process Order')
|
||||||
|
->example('200000166843')
|
||||||
|
->label('Process Order')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('coil_number')
|
||||||
|
->exampleHeader('Coil Number')
|
||||||
|
->example('1')
|
||||||
|
->label('Coil Number'),
|
||||||
|
ImportColumn::make('order_quantity')
|
||||||
|
->numeric()
|
||||||
|
->exampleHeader('Order Quantity')
|
||||||
|
->example('10')
|
||||||
|
->label('Order Quantity')
|
||||||
|
->rules(['integer']),
|
||||||
|
ImportColumn::make('received_quantity')
|
||||||
|
->numeric()
|
||||||
|
->exampleHeader('Received Quantity')
|
||||||
|
->example('5')
|
||||||
|
->label('Received Quantity')
|
||||||
|
->rules(['integer']),
|
||||||
|
ImportColumn::make('created_by')
|
||||||
|
->exampleHeader('Created By')
|
||||||
|
->example('Admin')
|
||||||
|
->label('Created By'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveRecord(): ?ProcessOrder
|
||||||
|
{
|
||||||
|
// return ProcessOrder::firstOrNew([
|
||||||
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
|
// 'email' => $this->data['email'],
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
return new ProcessOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
{
|
||||||
|
$body = 'Your process order 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