Added locator invoice validation importer and exporter file
This commit is contained in:
68
app/Filament/Exports/LocatorInvoiceValidationExporter.php
Normal file
68
app/Filament/Exports/LocatorInvoiceValidationExporter.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Exports;
|
||||||
|
|
||||||
|
use App\Models\LocatorInvoiceValidation;
|
||||||
|
use Filament\Actions\Exports\ExportColumn;
|
||||||
|
use Filament\Actions\Exports\Exporter;
|
||||||
|
use Filament\Actions\Exports\Models\Export;
|
||||||
|
|
||||||
|
class LocatorInvoiceValidationExporter extends Exporter
|
||||||
|
{
|
||||||
|
protected static ?string $model = LocatorInvoiceValidation::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
static $rowNumber = 0;
|
||||||
|
return [
|
||||||
|
// ExportColumn::make('id')
|
||||||
|
// ->label('ID'),
|
||||||
|
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('invoice_number')
|
||||||
|
->label('INVOICE NUMBER'),
|
||||||
|
ExportColumn::make('serial_number')
|
||||||
|
->label('SERIAL NUMBER'),
|
||||||
|
ExportColumn::make('pallet_number')
|
||||||
|
->label('PALLET NUMBER'),
|
||||||
|
ExportColumn::make('locator_number')
|
||||||
|
->label('LOCATOR NUMBER'),
|
||||||
|
ExportColumn::make('scanned_status')
|
||||||
|
->label('SCANNED STATUS'),
|
||||||
|
ExportColumn::make('upload_status')
|
||||||
|
->label('UPLOAD STATUS'),
|
||||||
|
ExportColumn::make('created_by')
|
||||||
|
->label('CREATED BY'),
|
||||||
|
ExportColumn::make('created_at')
|
||||||
|
->label('CREATED AT'),
|
||||||
|
ExportColumn::make('updated_by')
|
||||||
|
->label('UPDATED BY'),
|
||||||
|
ExportColumn::make('updated_at')
|
||||||
|
->label('UPDATED AT'),
|
||||||
|
ExportColumn::make('scanned_by')
|
||||||
|
->label('SCANNED BY'),
|
||||||
|
ExportColumn::make('scanned_at')
|
||||||
|
->label('SCANNED AT'),
|
||||||
|
ExportColumn::make('deleted_at')
|
||||||
|
->label('DELETED AT')
|
||||||
|
->enabledByDefault(false),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
|
{
|
||||||
|
$body = 'Your locator invoice validation 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
99
app/Filament/Imports/LocatorInvoiceValidationImporter.php
Normal file
99
app/Filament/Imports/LocatorInvoiceValidationImporter.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\LocatorInvoiceValidation;
|
||||||
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
|
use Filament\Actions\Imports\Importer;
|
||||||
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
|
||||||
|
class LocatorInvoiceValidationImporter extends Importer
|
||||||
|
{
|
||||||
|
protected static ?string $model = LocatorInvoiceValidation::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('invoice_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Invoice Number')
|
||||||
|
->example('3RA002514')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('serial_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Serial Number')
|
||||||
|
->example('2514121551420')
|
||||||
|
->label('Serial Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('pallet_number')
|
||||||
|
->exampleHeader('Pallet Number')
|
||||||
|
->example('EP-2506001')
|
||||||
|
->label('Pallet Number'),
|
||||||
|
ImportColumn::make('locator_number')
|
||||||
|
->exampleHeader('Locator Number')
|
||||||
|
->example('W05-D1B')
|
||||||
|
->label('Locator Number'),
|
||||||
|
ImportColumn::make('scanned_status')
|
||||||
|
->exampleHeader('Scanned Status')
|
||||||
|
->example('')
|
||||||
|
->label('Scanned Status'),
|
||||||
|
ImportColumn::make('upload_status')
|
||||||
|
->exampleHeader('Upload Status')
|
||||||
|
->example('Y')
|
||||||
|
->label('Upload Status'),
|
||||||
|
ImportColumn::make('created_at')
|
||||||
|
->exampleHeader('Created At')
|
||||||
|
->example('2025-06-17 01:42:16')
|
||||||
|
->label('Created At')
|
||||||
|
->rules(['date_format:Y-m-d H:i:s']),
|
||||||
|
ImportColumn::make('scanned_at')
|
||||||
|
->exampleHeader('Scanned At')
|
||||||
|
->example('2025-06-17 08:42:16')
|
||||||
|
->label('Scanned At')
|
||||||
|
->rules(['date_format:Y-m-d H:i:s']),
|
||||||
|
ImportColumn::make('created_by')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Created by')
|
||||||
|
->example('RAW002365')
|
||||||
|
->label('Created by')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('scanned_by')
|
||||||
|
->exampleHeader('Scanned by')
|
||||||
|
->example('')
|
||||||
|
->label('Scanned by'),
|
||||||
|
ImportColumn::make('updated_by')
|
||||||
|
->exampleHeader('Updated by')
|
||||||
|
->example('')
|
||||||
|
->label('Updated by'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveRecord(): ?LocatorInvoiceValidation
|
||||||
|
{
|
||||||
|
// return LocatorInvoiceValidation::firstOrNew([
|
||||||
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
|
// 'email' => $this->data['email'],
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
return new LocatorInvoiceValidation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
{
|
||||||
|
$body = 'Your locator invoice 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