From 607e252aac0cca3d7efa36f2de26c0d4ddc93c88 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 3 Nov 2026 12:53:11 +0530 Subject: [PATCH 1/2] Added courier inward importer and exporter --- .../Exports/CourierInwardExporter.php | 66 +++++++++++++++++++ .../Imports/CourierInwardImporter.php | 55 ++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 app/Filament/Exports/CourierInwardExporter.php create mode 100644 app/Filament/Imports/CourierInwardImporter.php diff --git a/app/Filament/Exports/CourierInwardExporter.php b/app/Filament/Exports/CourierInwardExporter.php new file mode 100644 index 00000000..9134b5a8 --- /dev/null +++ b/app/Filament/Exports/CourierInwardExporter.php @@ -0,0 +1,66 @@ +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; + } +} diff --git a/app/Filament/Imports/CourierInwardImporter.php b/app/Filament/Imports/CourierInwardImporter.php new file mode 100644 index 00000000..8ec77df5 --- /dev/null +++ b/app/Filament/Imports/CourierInwardImporter.php @@ -0,0 +1,55 @@ +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; + } +} -- 2.49.1 From f3d1aab505f71ff787cb0b2bdc4eebde8d465f92 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 3 Nov 2026 12:54:07 +0530 Subject: [PATCH 2/2] Added courier inward and outward in page --- .../Resources/CourierInwardResource.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Filament/Resources/CourierInwardResource.php b/app/Filament/Resources/CourierInwardResource.php index 179650e2..4b2de8f3 100644 --- a/app/Filament/Resources/CourierInwardResource.php +++ b/app/Filament/Resources/CourierInwardResource.php @@ -2,6 +2,8 @@ namespace App\Filament\Resources; +use App\Filament\Exports\CourierInwardExporter; +use App\Filament\Imports\CourierInwardImporter; use App\Filament\Resources\CourierInwardResource\Pages; use App\Filament\Resources\CourierInwardResource\RelationManagers; use App\Models\CourierInward; @@ -14,6 +16,8 @@ use Filament\Tables; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; +use Filament\Tables\Actions\ExportAction; +use Filament\Tables\Actions\ImportAction; class CourierInwardResource extends Resource { @@ -192,6 +196,22 @@ class CourierInwardResource extends Resource Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), + ]) + ->headerActions([ + ImportAction::make() + ->label('Import Courier Inward') + ->color('warning') + ->importer(CourierInwardImporter::class) + ->visible(function () { + return Filament::auth()->user()->can('view import courier inward'); + }), + ExportAction::make() + ->label('Export Courier Inward') + ->color('warning') + ->exporter(CourierInwardExporter::class) + ->visible(function () { + return Filament::auth()->user()->can('view export courier inward'); + }), ]); } -- 2.49.1