ranjith-dev #1378
66
app/Filament/Exports/CourierInwardExporter.php
Normal file
66
app/Filament/Exports/CourierInwardExporter.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\CourierInward;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class CourierInwardExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = CourierInward::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('date')
|
||||
->label('DATE'),
|
||||
ExportColumn::make('from_address_name')
|
||||
->label('FROM ADDRESS NAME'),
|
||||
ExportColumn::make('cover_material')
|
||||
->label('COVER/MATERIAL'),
|
||||
ExportColumn::make('pod_number')
|
||||
->label('POD NUMBER'),
|
||||
ExportColumn::make('courier_name')
|
||||
->label('COURIER NAME'),
|
||||
ExportColumn::make('place')
|
||||
->label('PLACE'),
|
||||
ExportColumn::make('to_address_name')
|
||||
->label('TO ADDRESS NAME'),
|
||||
ExportColumn::make('return_to_other_unit')
|
||||
->label('RETURN TO OTHER UNIT'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your courier inward 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;
|
||||
}
|
||||
}
|
||||
55
app/Filament/Imports/CourierInwardImporter.php
Normal file
55
app/Filament/Imports/CourierInwardImporter.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\CourierInward;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class CourierInwardImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = CourierInward::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('date')
|
||||
->rules(['date']),
|
||||
ImportColumn::make('from_address_name'),
|
||||
ImportColumn::make('cover_material'),
|
||||
ImportColumn::make('pod_number'),
|
||||
ImportColumn::make('courier_name'),
|
||||
ImportColumn::make('place'),
|
||||
ImportColumn::make('to_address_name'),
|
||||
ImportColumn::make('return_to_other_unit'),
|
||||
ImportColumn::make('created_by'),
|
||||
ImportColumn::make('updated_by'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?CourierInward
|
||||
{
|
||||
// return CourierInward::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new CourierInward();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your courier inward 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