From d885af0843bc7ddd377764b96474dc84e7595eb2 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 10 Feb 2026 16:03:36 +0530 Subject: [PATCH] Updated item code validations and warning messages on import --- .../Resources/InvoiceValidationResource.php | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index eca071d..589a9fe 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -624,9 +624,7 @@ class InvoiceValidationResource extends Resource } return; - } - - if (! $validRowsFound) { + } elseif (! $validRowsFound) { Notification::make() ->title('Invalid Serial Invoice') ->danger() // This makes the notification red to indicate an error @@ -641,9 +639,9 @@ class InvoiceValidationResource extends Resource $uniqueCodes = array_unique($materialCodes); - $matchedItems = StickerMaster::with('item') - ->whereHas('item', function ($query) use ($uniqueCodes) { - $query->whereIn('code', $uniqueCodes); + $matchedItems = StickerMaster::with('item')->where('plant_id', $plantId) + ->whereHas('item', function ($query) use ($uniqueCodes, $plantId) { + $query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId); }) ->get(); @@ -654,7 +652,7 @@ class InvoiceValidationResource extends Resource if (! empty($missingCodes)) { $missingCount = count($missingCodes); - $message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:
'.implode(', ', $missingCodes); + $message = $missingCount > 10 ? "'$missingCount' item codes are not found in sticker master." : 'The following item codes are not found in sticker master:
'.implode(', ', $missingCodes); Notification::make() ->title('Unknown Item Codes') @@ -678,7 +676,7 @@ class InvoiceValidationResource extends Resource if (count($invalidCodes) > 10) { Notification::make() ->title('Invalid item codes found') - ->body(''.count($invalidCodes).'item codes found have material type.') + ->body(''.count($invalidCodes).' item codes have material type.') ->danger() ->send(); @@ -920,9 +918,7 @@ class InvoiceValidationResource extends Resource } return; - } - - if (! empty($uniqueaplhaMat)) { + } elseif (! empty($uniqueaplhaMat)) { Notification::make() ->title('Invalid Material Quantity') ->body('The following item codes material quantity must be a numeric values :
'.implode(', ', $uniqueaplhaMat)) @@ -934,9 +930,7 @@ class InvoiceValidationResource extends Resource } return; - } - - if (! empty($uniqueZeroMat)) { + } elseif (! empty($uniqueZeroMat)) { Notification::make() ->title('Invalid Material Quantity') ->body('The following item codes material quantity should be greater than 0:
'.implode(', ', $uniqueZeroMat)) @@ -948,9 +942,7 @@ class InvoiceValidationResource extends Resource } return; - } - - if (! empty($uniqueEmptyMat)) { + } elseif (! empty($uniqueEmptyMat)) { Notification::make() ->title('Missing Material Quantity') ->body("The following item codes doesn't have valid material quantity:
".implode(', ', $uniqueEmptyMat)) @@ -962,9 +954,7 @@ class InvoiceValidationResource extends Resource } return; - } - - if (! $validRowsFound) { + } elseif (! $validRowsFound) { Notification::make() ->title('Invalid Material Invoice') ->danger() // This makes the notification red to indicate an error @@ -980,9 +970,9 @@ class InvoiceValidationResource extends Resource $uniqueCodes = array_unique($materialCodes); - $matchedItems = StickerMaster::with('item') - ->whereHas('item', function ($query) use ($uniqueCodes) { - $query->whereIn('code', $uniqueCodes); + $matchedItems = StickerMaster::with('item')->where('plant_id', $plantId) + ->whereHas('item', function ($query) use ($uniqueCodes, $plantId) { + $query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId); }) ->get(); @@ -993,9 +983,7 @@ class InvoiceValidationResource extends Resource if (! empty($missingCodes)) { $missingCount = count($missingCodes); - $message = $missingCount > 10 - ? "'$missingCount' Item Codes are not found in sticker master." - : 'Item Codes are not found in sticker master:
'.implode(', ', $missingCodes); + $message = $missingCount > 10 ? "'$missingCount' item codes are not found in sticker master." : 'The following item codes are not found in sticker master:
'.implode(', ', $missingCodes); Notification::make() ->title('Unknown Item Codes') @@ -1019,7 +1007,7 @@ class InvoiceValidationResource extends Resource $invalidCodes = array_unique($invalidCodes); Notification::make() ->title('Invalid item codes found') - ->body(''.count($invalidCodes).'invalid item codes found have serial number.') + ->body(''.count($invalidCodes).' item codes have serial type.') ->danger() ->send();