Added filament import to import transit
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\ImportTransitExporter;
|
||||
use App\Filament\Imports\ImportTransitImporter;
|
||||
use App\Filament\Resources\ImportTransitResource\Pages;
|
||||
use App\Filament\Resources\ImportTransitResource\RelationManagers;
|
||||
use App\Models\ImportTransit;
|
||||
@@ -22,6 +23,7 @@ use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
// use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
|
||||
class ImportTransitResource extends Resource
|
||||
@@ -73,6 +75,16 @@ class ImportTransitResource extends Resource
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\DatePicker::make('inv_value')
|
||||
->label('Inv Value')
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('freight_charge')
|
||||
->label('Freight Charge')
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('customs_agent_name')
|
||||
->label('Customs Agent Name')
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
@@ -97,6 +109,11 @@ class ImportTransitResource extends Resource
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('insurance_status')
|
||||
->label('Insurance Status')
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('delivery_location')
|
||||
->label('Delivery Location')
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
@@ -232,6 +249,16 @@ class ImportTransitResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('shipper_invoice_date')
|
||||
->label('Shipper Invoice Date')
|
||||
->date()
|
||||
->formatStateUsing(fn ($state) => $state?->format('Y-m-d'))
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('inv_value')
|
||||
->label('Inv Value')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('freight_charge')
|
||||
->label('Freight Charge')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('customs_agent_name')
|
||||
@@ -240,18 +267,24 @@ class ImportTransitResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('eta_date')
|
||||
->label('ETA Date')
|
||||
->date()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label('Status')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('insurance_status')
|
||||
->label('Insurance Status')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('delivery_location')
|
||||
->label('Delivery Location')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('etd_date')
|
||||
->label('ETD Date')
|
||||
->date()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('mode')
|
||||
@@ -352,297 +385,304 @@ class ImportTransitResource extends Resource
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\Action::make('Import Transit')
|
||||
// Tables\Actions\Action::make('Import Transit')
|
||||
// ->label('Import Transit')
|
||||
// ->form([
|
||||
// FileUpload::make('import_transit_file')
|
||||
// ->label('Import Transit')
|
||||
// // ->required()
|
||||
// ->preserveFilenames()
|
||||
// ->storeFiles(false)
|
||||
// ->reactive()
|
||||
// ->required()
|
||||
// ->disk('local')
|
||||
// // ->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||
// ->directory('uploads/ImportTransit'),
|
||||
// ])
|
||||
// ->action(function (array $data) {
|
||||
// $uploadedFile = $data['import_transit_file'];
|
||||
|
||||
// $disk = Storage::disk('local');
|
||||
|
||||
// $user = Filament::auth()->user();
|
||||
|
||||
// $operatorName = $user->name;
|
||||
|
||||
// // Get original filename
|
||||
// $originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
||||
|
||||
// $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||
|
||||
// // Store manually using storeAs to keep original name
|
||||
// $path = $uploadedFile->storeAs('uploads/ImportTransit', $originalName, 'local'); // returns relative path
|
||||
|
||||
// $fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
// if ($fullPath && file_exists($fullPath)) {
|
||||
// $rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
// if ((count($rows) - 1) <= 0) {
|
||||
// Notification::make()
|
||||
// ->title('Records Not Found')
|
||||
// ->body("Import the valid 'Import Transit' file to proceed..!")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// if ($disk->exists($path))
|
||||
// {
|
||||
// $disk->delete($path);
|
||||
// }
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $invalidCriNo = [];
|
||||
|
||||
// foreach ($rows as $index => $row)
|
||||
// {
|
||||
// if ($index == 0) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $rowNumber = $index + 1;
|
||||
|
||||
// $criRfqNo = trim($row[1] ?? '');
|
||||
// $mailRcvdDate = trim($row[2] ?? '');
|
||||
// $pricolRefNo = trim($row[3] ?? '');
|
||||
// $requester = trim($row[4] ?? '');
|
||||
// $shipper = trim($row[5] ?? '');
|
||||
// $shipperLocation = trim($row[6] ?? '');
|
||||
// $shipperInv = trim($row[7] ?? '');
|
||||
// $shipperInvDate = trim($row[8] ?? '');
|
||||
// $cha = trim($row[9] ?? '');
|
||||
// $eta = trim($row[10] ?? '');
|
||||
// $status = trim($row[11] ?? '');
|
||||
// $dlyLoc = trim($row[12] ?? '');
|
||||
// $etd = trim($row[13] ?? '');
|
||||
// $mode = trim($row[14] ?? '');
|
||||
// $incoTerms = trim($row[15] ?? '');
|
||||
// $portOfLoading = trim($row[16] ?? '');
|
||||
// $portOfDischarge = trim($row[17] ?? '');
|
||||
// $deliveryCity = trim($row[18] ?? '');
|
||||
// $packages = trim($row[19] ?? '');
|
||||
// $typeOfPkg = trim($row[20] ?? '');
|
||||
// $grossWeight = trim($row[21] ?? '');
|
||||
// $volumeWeight = trim($row[22] ?? '');
|
||||
// $blNo = trim($row[23] ?? '');
|
||||
// $blRcvdDate = trim($row[24] ?? '');
|
||||
// $vesselNo = trim($row[25] ?? '');
|
||||
|
||||
// if (empty($criRfqNo)) {
|
||||
// $invalidCriNo[] = $rowNumber;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (! empty($invalidCriNo)){
|
||||
|
||||
// $errorMsg = '';
|
||||
|
||||
// if (! empty($invalidCriNo)) {
|
||||
// $errorMsg .= 'Missing CRI Rfq No in rows: '.implode(', ', $invalidCriNo).'<br>';
|
||||
// }
|
||||
|
||||
// Notification::make()
|
||||
// ->title('Missing Mandatory Fields')
|
||||
// ->body($errorMsg)
|
||||
// ->danger()
|
||||
// ->send();
|
||||
|
||||
// if ($disk->exists($path)) {
|
||||
// $disk->delete($path);
|
||||
// }
|
||||
|
||||
// return;
|
||||
|
||||
// }
|
||||
|
||||
// // $spreadsheet = IOFactory::load($fullPath);
|
||||
|
||||
// // foreach ($spreadsheet->getAllSheets() as $sheet) {
|
||||
// // $state = $sheet->getSheetState();
|
||||
// // if ($state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_HIDDEN ||
|
||||
// // $state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_VERYHIDDEN) {
|
||||
// // Notification::make()
|
||||
// // ->title('Import Failed')
|
||||
// // ->body("Hidden sheet found: \"{$sheet->getTitle()}\". Please remove all hidden sheets and try again.")
|
||||
// // ->danger()
|
||||
// // ->send();
|
||||
// // return;
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// try
|
||||
// {
|
||||
// foreach ($rows as $index => $row)
|
||||
// {
|
||||
// if ($index == 0) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $rowNumber = $index + 1;
|
||||
|
||||
// try
|
||||
// {
|
||||
|
||||
// $formattedDate = null;
|
||||
// $formattedShipperDate = null;
|
||||
// $etaDate = null;
|
||||
// $etdDate = null;
|
||||
// $formattedBlRcvdDate = null;
|
||||
|
||||
// $criRfqNo = trim($row[1] ?? '');
|
||||
// $mailRcvdDate = trim($row[2] ?? '');
|
||||
// $pricolRefNo = trim($row[3] ?? '');
|
||||
// $requester = trim($row[4] ?? '');
|
||||
// $shipper = trim($row[5] ?? '');
|
||||
// $shipperLocation = trim($row[6] ?? '');
|
||||
// $shipperInv = trim($row[7] ?? '');
|
||||
// $shipperInvDate = trim($row[8] ?? '');
|
||||
// $cha = trim($row[9] ?? '');
|
||||
// $eta = trim($row[10] ?? '');
|
||||
// $status = trim($row[11] ?? '');
|
||||
// $dlyLoc = trim($row[12] ?? '');
|
||||
// $etd = trim($row[13] ?? '');
|
||||
// $mode = trim($row[14] ?? '');
|
||||
// $incoTerms = trim($row[15] ?? '');
|
||||
// $portOfLoading = trim($row[16] ?? '');
|
||||
// $portOfDischarge = trim($row[17] ?? '');
|
||||
// $deliveryCity = trim($row[18] ?? '');
|
||||
// $packages = trim($row[19] ?? '');
|
||||
// $typeOfPkg = trim($row[20] ?? '');
|
||||
// $grossWeight = trim($row[21] ?? '');
|
||||
// $volumeWeight = trim($row[22] ?? '');
|
||||
// $blNo = trim($row[23] ?? '');
|
||||
// $blRcvdDate = trim($row[24] ?? '');
|
||||
// $vesselNo = trim($row[25] ?? '');
|
||||
|
||||
|
||||
// if (! empty($mailRcvdDate)) {
|
||||
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $mailRcvdDate)) {
|
||||
// [$day, $month, $year] = preg_split('/[-\/]/', $mailRcvdDate);
|
||||
// $formattedDate = "{$year}-{$month}-{$day}";
|
||||
// } elseif (is_numeric($mailRcvdDate)) {
|
||||
// $formattedDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($mailRcvdDate)->format('Y-m-d');
|
||||
// } else {
|
||||
// $formattedDate = date('Y-m-d', strtotime($mailRcvdDate));
|
||||
// }
|
||||
// }
|
||||
// if (! empty($shipperInvDate)) {
|
||||
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $shipperInvDate)) {
|
||||
// [$day, $month, $year] = preg_split('/[-\/]/', $shipperInvDate);
|
||||
// $formattedShipperDate = "{$year}-{$month}-{$day}";
|
||||
// } elseif (is_numeric($shipperInvDate)) {
|
||||
// $formattedShipperDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($shipperInvDate)->format('Y-m-d');
|
||||
// } else {
|
||||
// $formattedShipperDate = date('Y-m-d', strtotime($shipperInvDate));
|
||||
// }
|
||||
// }
|
||||
// if (! empty($eta)) {
|
||||
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $eta)) {
|
||||
// [$day, $month, $year] = preg_split('/[-\/]/', $eta);
|
||||
// $etaDate = "{$year}-{$month}-{$day}";
|
||||
// } elseif (is_numeric($eta)) {
|
||||
// $etaDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($eta)->format('Y-m-d');
|
||||
// } else {
|
||||
// $etaDate = date('Y-m-d', strtotime($eta));
|
||||
// }
|
||||
// }
|
||||
// if (! empty($etd)) {
|
||||
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $etd)) {
|
||||
// [$day, $month, $year] = preg_split('/[-\/]/', $etd);
|
||||
// $etdDate = "{$year}-{$month}-{$day}";
|
||||
// } elseif (is_numeric($etd)) {
|
||||
// $etdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($etd)->format('Y-m-d');
|
||||
// } else {
|
||||
// $etdDate = date('Y-m-d', strtotime($etd));
|
||||
// }
|
||||
// }
|
||||
// if (! empty($blRcvdDate)) {
|
||||
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $blRcvdDate)) {
|
||||
// [$day, $month, $year] = preg_split('/[-\/]/', $blRcvdDate);
|
||||
// $formattedBlRcvdDate = "{$year}-{$month}-{$day}";
|
||||
// } elseif (is_numeric($blRcvdDate)) {
|
||||
// $formattedBlRcvdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($blRcvdDate)->format('Y-m-d');
|
||||
// } else {
|
||||
// $formattedBlRcvdDate = date('Y-m-d', strtotime($blRcvdDate));
|
||||
// }
|
||||
// }
|
||||
|
||||
// $inserted = ImportTransit::updateOrCreate(
|
||||
// [
|
||||
// 'cri_rfq_number' => $criRfqNo,
|
||||
// ],
|
||||
// [
|
||||
// 'mail_received_date' => $formattedDate ?? null,
|
||||
// 'pricol_ref_number' => $pricolRefNo ?? null,
|
||||
// 'requester' => $requester ?? null,
|
||||
// 'shipper' => $shipper ?? null,
|
||||
// 'shipper_location' => $shipperLocation ?? null,
|
||||
// 'shipper_invoice' => $shipperInv ?? null,
|
||||
// 'shipper_invoice_date' => $formattedShipperDate ?? null,
|
||||
// 'customs_agent_name' => $cha ?? null,
|
||||
// 'eta_date' => $etaDate ?? null,
|
||||
// 'status' => $status ?? null,
|
||||
// 'delivery_location' => $dlyLoc ?? null,
|
||||
// 'etd_date' => $etdDate ?? null,
|
||||
// 'mode' => $mode ?? null,
|
||||
// 'inco_terms' => $incoTerms ?? null,
|
||||
// 'port_of_loading' => $portOfLoading ?? null,
|
||||
// 'port_of_discharge' => $portOfDischarge ?? null,
|
||||
// 'delivery_city' => $deliveryCity ?? null,
|
||||
// 'packages' => $packages ?? null,
|
||||
// 'type_of_package' => $typeOfPkg ?? null,
|
||||
// 'gross_weight' => $grossWeight ?? null,
|
||||
// 'volume' => $volumeWeight ?? null,
|
||||
// 'bill_number' => $blNo ?? null,
|
||||
// 'bill_received_date' => $formattedBlRcvdDate ?? null,
|
||||
// 'vessel_number' => $vesselNo ?? null,
|
||||
// 'created_by' => $operatorName,
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
// catch (\Exception $e) {
|
||||
// Notification::make()
|
||||
// ->title('Import Failed')
|
||||
// ->body("Error occurred while processing row. Error : {$e->getMessage()}")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// }
|
||||
// }
|
||||
// if (! $inserted) {
|
||||
// Notification::make()
|
||||
// ->title('Failed')
|
||||
// ->body("Records insertion failed!")
|
||||
// ->success()
|
||||
// ->send();
|
||||
// }
|
||||
// else{
|
||||
// Notification::make()
|
||||
// ->title('Success')
|
||||
// ->body("Records inserted successfully!")
|
||||
// ->success()
|
||||
// ->send();
|
||||
// }
|
||||
// }
|
||||
// catch (\Exception $e) {
|
||||
// Notification::make()
|
||||
// ->title('Import Failed')
|
||||
// ->body("No records were inserted. Error : {$e->getMessage()}")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// ->visible(function () {
|
||||
// return Filament::auth()->user()->can('view import transit');
|
||||
// }),
|
||||
ImportAction::make()
|
||||
->label('Import Transit')
|
||||
->form([
|
||||
FileUpload::make('import_transit_file')
|
||||
->label('Import Transit')
|
||||
// ->required()
|
||||
->preserveFilenames()
|
||||
->storeFiles(false)
|
||||
->reactive()
|
||||
->required()
|
||||
->disk('local')
|
||||
// ->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||
->directory('uploads/ImportTransit'),
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$uploadedFile = $data['import_transit_file'];
|
||||
|
||||
$disk = Storage::disk('local');
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
// Get original filename
|
||||
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
||||
|
||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||
|
||||
// Store manually using storeAs to keep original name
|
||||
$path = $uploadedFile->storeAs('uploads/ImportTransit', $originalName, 'local'); // returns relative path
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Records Not Found')
|
||||
->body("Import the valid 'Import Transit' file to proceed..!")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$invalidCriNo = [];
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rowNumber = $index + 1;
|
||||
|
||||
$criRfqNo = trim($row[1] ?? '');
|
||||
$mailRcvdDate = trim($row[2] ?? '');
|
||||
$pricolRefNo = trim($row[3] ?? '');
|
||||
$requester = trim($row[4] ?? '');
|
||||
$shipper = trim($row[5] ?? '');
|
||||
$shipperLocation = trim($row[6] ?? '');
|
||||
$shipperInv = trim($row[7] ?? '');
|
||||
$shipperInvDate = trim($row[8] ?? '');
|
||||
$cha = trim($row[9] ?? '');
|
||||
$eta = trim($row[10] ?? '');
|
||||
$status = trim($row[11] ?? '');
|
||||
$dlyLoc = trim($row[12] ?? '');
|
||||
$etd = trim($row[13] ?? '');
|
||||
$mode = trim($row[14] ?? '');
|
||||
$incoTerms = trim($row[15] ?? '');
|
||||
$portOfLoading = trim($row[16] ?? '');
|
||||
$portOfDischarge = trim($row[17] ?? '');
|
||||
$deliveryCity = trim($row[18] ?? '');
|
||||
$packages = trim($row[19] ?? '');
|
||||
$typeOfPkg = trim($row[20] ?? '');
|
||||
$grossWeight = trim($row[21] ?? '');
|
||||
$volumeWeight = trim($row[22] ?? '');
|
||||
$blNo = trim($row[23] ?? '');
|
||||
$blRcvdDate = trim($row[24] ?? '');
|
||||
$vesselNo = trim($row[25] ?? '');
|
||||
|
||||
if (empty($criRfqNo)) {
|
||||
$invalidCriNo[] = $rowNumber;
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($invalidCriNo)){
|
||||
|
||||
$errorMsg = '';
|
||||
|
||||
if (! empty($invalidCriNo)) {
|
||||
$errorMsg .= 'Missing CRI Rfq No in rows: '.implode(', ', $invalidCriNo).'<br>';
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title('Missing Mandatory Fields')
|
||||
->body($errorMsg)
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// $spreadsheet = IOFactory::load($fullPath);
|
||||
|
||||
// foreach ($spreadsheet->getAllSheets() as $sheet) {
|
||||
// $state = $sheet->getSheetState();
|
||||
// if ($state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_HIDDEN ||
|
||||
// $state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_VERYHIDDEN) {
|
||||
// Notification::make()
|
||||
// ->title('Import Failed')
|
||||
// ->body("Hidden sheet found: \"{$sheet->getTitle()}\". Please remove all hidden sheets and try again.")
|
||||
// ->danger()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rowNumber = $index + 1;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
$formattedDate = null;
|
||||
$formattedShipperDate = null;
|
||||
$etaDate = null;
|
||||
$etdDate = null;
|
||||
$formattedBlRcvdDate = null;
|
||||
|
||||
$criRfqNo = trim($row[1] ?? '');
|
||||
$mailRcvdDate = trim($row[2] ?? '');
|
||||
$pricolRefNo = trim($row[3] ?? '');
|
||||
$requester = trim($row[4] ?? '');
|
||||
$shipper = trim($row[5] ?? '');
|
||||
$shipperLocation = trim($row[6] ?? '');
|
||||
$shipperInv = trim($row[7] ?? '');
|
||||
$shipperInvDate = trim($row[8] ?? '');
|
||||
$cha = trim($row[9] ?? '');
|
||||
$eta = trim($row[10] ?? '');
|
||||
$status = trim($row[11] ?? '');
|
||||
$dlyLoc = trim($row[12] ?? '');
|
||||
$etd = trim($row[13] ?? '');
|
||||
$mode = trim($row[14] ?? '');
|
||||
$incoTerms = trim($row[15] ?? '');
|
||||
$portOfLoading = trim($row[16] ?? '');
|
||||
$portOfDischarge = trim($row[17] ?? '');
|
||||
$deliveryCity = trim($row[18] ?? '');
|
||||
$packages = trim($row[19] ?? '');
|
||||
$typeOfPkg = trim($row[20] ?? '');
|
||||
$grossWeight = trim($row[21] ?? '');
|
||||
$volumeWeight = trim($row[22] ?? '');
|
||||
$blNo = trim($row[23] ?? '');
|
||||
$blRcvdDate = trim($row[24] ?? '');
|
||||
$vesselNo = trim($row[25] ?? '');
|
||||
|
||||
|
||||
if (! empty($mailRcvdDate)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $mailRcvdDate)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $mailRcvdDate);
|
||||
$formattedDate = "{$year}-{$month}-{$day}";
|
||||
} elseif (is_numeric($mailRcvdDate)) {
|
||||
$formattedDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($mailRcvdDate)->format('Y-m-d');
|
||||
} else {
|
||||
$formattedDate = date('Y-m-d', strtotime($mailRcvdDate));
|
||||
}
|
||||
}
|
||||
if (! empty($shipperInvDate)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $shipperInvDate)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $shipperInvDate);
|
||||
$formattedShipperDate = "{$year}-{$month}-{$day}";
|
||||
} elseif (is_numeric($shipperInvDate)) {
|
||||
$formattedShipperDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($shipperInvDate)->format('Y-m-d');
|
||||
} else {
|
||||
$formattedShipperDate = date('Y-m-d', strtotime($shipperInvDate));
|
||||
}
|
||||
}
|
||||
if (! empty($eta)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $eta)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $eta);
|
||||
$etaDate = "{$year}-{$month}-{$day}";
|
||||
} elseif (is_numeric($eta)) {
|
||||
$etaDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($eta)->format('Y-m-d');
|
||||
} else {
|
||||
$etaDate = date('Y-m-d', strtotime($eta));
|
||||
}
|
||||
}
|
||||
if (! empty($etd)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $etd)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $etd);
|
||||
$etdDate = "{$year}-{$month}-{$day}";
|
||||
} elseif (is_numeric($etd)) {
|
||||
$etdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($etd)->format('Y-m-d');
|
||||
} else {
|
||||
$etdDate = date('Y-m-d', strtotime($etd));
|
||||
}
|
||||
}
|
||||
if (! empty($blRcvdDate)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $blRcvdDate)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $blRcvdDate);
|
||||
$formattedBlRcvdDate = "{$year}-{$month}-{$day}";
|
||||
} elseif (is_numeric($blRcvdDate)) {
|
||||
$formattedBlRcvdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($blRcvdDate)->format('Y-m-d');
|
||||
} else {
|
||||
$formattedBlRcvdDate = date('Y-m-d', strtotime($blRcvdDate));
|
||||
}
|
||||
}
|
||||
|
||||
$inserted = ImportTransit::updateOrCreate(
|
||||
[
|
||||
'cri_rfq_number' => $criRfqNo,
|
||||
],
|
||||
[
|
||||
'mail_received_date' => $formattedDate ?? null,
|
||||
'pricol_ref_number' => $pricolRefNo ?? null,
|
||||
'requester' => $requester ?? null,
|
||||
'shipper' => $shipper ?? null,
|
||||
'shipper_location' => $shipperLocation ?? null,
|
||||
'shipper_invoice' => $shipperInv ?? null,
|
||||
'shipper_invoice_date' => $formattedShipperDate ?? null,
|
||||
'customs_agent_name' => $cha ?? null,
|
||||
'eta_date' => $etaDate ?? null,
|
||||
'status' => $status ?? null,
|
||||
'delivery_location' => $dlyLoc ?? null,
|
||||
'etd_date' => $etdDate ?? null,
|
||||
'mode' => $mode ?? null,
|
||||
'inco_terms' => $incoTerms ?? null,
|
||||
'port_of_loading' => $portOfLoading ?? null,
|
||||
'port_of_discharge' => $portOfDischarge ?? null,
|
||||
'delivery_city' => $deliveryCity ?? null,
|
||||
'packages' => $packages ?? null,
|
||||
'type_of_package' => $typeOfPkg ?? null,
|
||||
'gross_weight' => $grossWeight ?? null,
|
||||
'volume' => $volumeWeight ?? null,
|
||||
'bill_number' => $blNo ?? null,
|
||||
'bill_received_date' => $formattedBlRcvdDate ?? null,
|
||||
'vessel_number' => $vesselNo ?? null,
|
||||
'created_by' => $operatorName,
|
||||
]
|
||||
);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Import Failed')
|
||||
->body("Error occurred while processing row. Error : {$e->getMessage()}")
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
if (! $inserted) {
|
||||
Notification::make()
|
||||
->title('Failed')
|
||||
->body("Records insertion failed!")
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
else{
|
||||
Notification::make()
|
||||
->title('Success')
|
||||
->body("Records inserted successfully!")
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->title('Import Failed')
|
||||
->body("No records were inserted. Error : {$e->getMessage()}")
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
})
|
||||
->color('warning')
|
||||
->importer(ImportTransitImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import transit');
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user