From 2f8d7615a3f58d371e1bac38170bb7cfcc75c19b Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 13 Jan 2026 16:38:42 +0530 Subject: [PATCH] Updated alignment on import --- ...ReworkLocatorInvoiceValidationImporter.php | 85 +++++++++---------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php b/app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php index 730c225..3149167 100644 --- a/app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php +++ b/app/Filament/Imports/ReworkLocatorInvoiceValidationImporter.php @@ -134,55 +134,51 @@ class ReworkLocatorInvoiceValidationImporter extends Importer $updatedBy = $this->data['updated_by']; $reworkedBy = $this->data['reworked_by']; - if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) { - $warnMsg[] = "Invalid plant code found"; - } - else - { - $plant = Plant::where('code', $this->data['plant'])->first(); - if (!$plant) { - $warnMsg[] = "Plant not found"; - } - else - { - if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) { - $warnMsg[] = "Invalid invoice number found"; + if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { + $warnMsg[] = 'Invalid plant code found'; + } else { + $plant = Plant::where('code', $plantCod)->first(); + if (! $plant) { + $warnMsg[] = 'Plant not found'; + } else { + if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) { + $warnMsg[] = 'Invalid invoice number found'; } - if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) { - $warnMsg[] = "Invalid serial number found"; + if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) { + $warnMsg[] = 'Invalid serial number found'; } if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) { - $warnMsg[] = "Invalid pallet number found"; + $warnMsg[] = 'Invalid pallet number found'; } if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) { - $warnMsg[] = "Invalid locator number found"; + $warnMsg[] = 'Invalid locator number found'; } if ($scannedStat != 'Scanned') { - $warnMsg[] = "Invalid scanned status found"; + $warnMsg[] = 'Invalid scanned status found'; } if ($uploadStat != 'Y' && $uploadStat != 'N') { - $warnMsg[] = "Invalid upload status found"; + $warnMsg[] = 'Invalid upload status found'; } $created = User::where('name', $createdBy)->first(); - if (!$created) { - $warnMsg[] = "Created by not found"; + if (! $created) { + $warnMsg[] = 'Created by not found'; } $scanned = User::where('name', $scannedBy)->first(); - if (!$scanned) { - $warnMsg[] = "Scanned by not found"; + if (! $scanned) { + $warnMsg[] = 'Scanned by not found'; } if (Str::length($updatedBy) > 0) { $updated = User::where('name', $updatedBy)->first(); - if (!$updated) { - $warnMsg[] = "Updated by not found"; + if (! $updated) { + $warnMsg[] = 'Updated by not found'; } } $reworked = User::where('name', $reworkedBy)->first(); - if (!$reworked) { - $warnMsg[] = "Reworked by not found"; + if (! $reworked) { + $warnMsg[] = 'Reworked by not found'; } - $formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00' + $formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00' foreach ($formats as $format) { try { @@ -194,7 +190,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer } } - if (!isset($cDateTime)) { + if (! isset($cDateTime)) { // throw new \Exception('Invalid date time format'); $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; } @@ -209,7 +205,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer } } - if (!isset($sDateTime)) { + if (! isset($sDateTime)) { $warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; } @@ -223,11 +219,9 @@ class ReworkLocatorInvoiceValidationImporter extends Importer } } - if (!isset($uDateTime)) { + if (! isset($uDateTime)) { $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; - } - else - { + } else { if (isset($cDateTime) && isset($uDateTime)) { if ($cDateTime->greaterThan($uDateTime)) { $warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'."; @@ -245,11 +239,9 @@ class ReworkLocatorInvoiceValidationImporter extends Importer } } - if (!isset($rDateTime)) { + if (! isset($rDateTime)) { $warnMsg[] = "Invalid 'Reworked DateTime' format. Expected DD-MM-YYYY HH:MM:SS"; - } - else - { + } else { if (isset($cDateTime) && isset($rDateTime)) { if ($cDateTime->greaterThan($rDateTime)) { $warnMsg[] = "'Created DataTime' is greater than 'Reworked DateTime'."; @@ -260,10 +252,10 @@ class ReworkLocatorInvoiceValidationImporter extends Importer } // if (!is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) { - // $warnMsg[] = "Invalid locator quantity found"; + // $warnMsg[] = "Invalid locator quantity found"; // } - if (!empty($warnMsg)) { + if (! empty($warnMsg)) { throw new RowImportFailedException(implode(', ', $warnMsg)); } @@ -283,10 +275,11 @@ class ReworkLocatorInvoiceValidationImporter extends Importer 'created_by' => $createdBy, 'scanned_by' => $scannedBy, 'updated_by' => $updatedBy, - 'reworked_by' => $reworkedBy - ] - ); - return null; + 'reworked_by' => $reworkedBy, + ] + ); + + return null; // // return ReworkLocatorInvoiceValidation::firstOrNew([ // // // Update existing records, matching them by `$this->data['column_name']` // // 'email' => $this->data['email'], @@ -297,10 +290,10 @@ class ReworkLocatorInvoiceValidationImporter extends Importer public static function getCompletedNotificationBody(Import $import): string { - $body = 'Your rework locator invoice validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; + $body = 'Your rework 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.'; + $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.'; } return $body;