diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index 77aacf5..48c97d4 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -376,7 +376,7 @@ class InvoiceValidationResource extends Resource } $invalidMatCodes = []; - $invalidSerialCodes=[]; + $invalidSerialCodes = []; $materialCodes = []; $missingSerials = []; $duplicateSerials = []; @@ -806,6 +806,7 @@ class InvoiceValidationResource extends Resource if (count($invalidCodes) > 10) { + $invalidCodes = array_unique($invalidCodes); Notification::make() ->title('Invalid item codes found') ->body('' . count($invalidCodes) . 'invalid item codes found have serial number.') @@ -819,6 +820,7 @@ class InvoiceValidationResource extends Resource } else if(count($invalidCodes) > 0) { + $invalidCodes = array_unique($invalidCodes); Notification::make() ->title('Invalid item codes found') ->body('Serial invoice Item Codes found : ' . implode(', ', $invalidCodes)) @@ -881,6 +883,10 @@ class InvoiceValidationResource extends Resource ->send(); }; + $nonNumericQtyCodes = array_unique($nonNumericQtyCodes); + $zeroQtyCodes = array_unique($zeroQtyCodes); + $notDivisibleCodes = array_unique($notDivisibleCodes); + $showValidationNotification($nonNumericQtyCodes, "The following item codes contains invalid bundle quantity:"); $showValidationNotification($zeroQtyCodes, "The following item codes quantity should be greater than '0':"); $showValidationNotification($notDivisibleCodes, "The following item codes quantity is not divisible by bundle quantity."); @@ -964,74 +970,73 @@ class InvoiceValidationResource extends Resource ->placeholder(placeholder: 'Select To DateTime') ->reactive() ->native(false), - ]) - ->query(function ($query, array $data) { - // Hide all records initially if no filters are applied - if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) { - return $query->whereRaw('1 = 0'); - } - - if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null - $query->where('plant_id', $data['Plant']); - } - - if (!empty($data['invoice_number'])) { - $query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%'); - } - - if (!empty($data['serial_number'])) { - $query->where('serial_number', 'like', '%' . $data['serial_number'] . '%'); - } - - if (!empty($data['created_from'])) { - $query->where('created_at', '>=', $data['created_from']); - } - - if (!empty($data['created_to'])) { - $query->where('created_at', '<=', $data['created_to']); - } - - if (!empty($data['sticker_master_id'])) { - $stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id']) - ->pluck('id') - ->toArray(); - - if (!empty($stickerMasterIds)) { - $query->whereIn('sticker_master_id', $stickerMasterIds); + ]) + ->query(function ($query, array $data) { + // Hide all records initially if no filters are applied + if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) { + return $query->whereRaw('1 = 0'); } - } - }) - ->indicateUsing(function (array $data) { - $indicators = []; - if (!empty($data['Plant'])) { - $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); - } + if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null + $query->where('plant_id', $data['Plant']); + } - if (!empty($data['invoice_number'])) { - $indicators[] = 'Invoice Number: ' . $data['invoice_number']; - } + if (!empty($data['invoice_number'])) { + $query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%'); + } - if (!empty($data['serial_number'])) { - $indicators[] = 'Serial Number: ' . $data['serial_number']; - } + if (!empty($data['serial_number'])) { + $query->where('serial_number', 'like', '%' . $data['serial_number'] . '%'); + } - if (!empty($data['created_from'])) { - $indicators[] = 'From: ' . $data['created_from']; - } + if (!empty($data['created_from'])) { + $query->where('created_at', '>=', $data['created_from']); + } - if (!empty($data['created_to'])) { - $indicators[] = 'To: ' . $data['created_to']; - } + if (!empty($data['created_to'])) { + $query->where('created_at', '<=', $data['created_to']); + } - if (!empty($data['sticker_master_id'])) { - $itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown'; - $indicators[] = 'Item Code: ' . $itemCode; - } + if (!empty($data['sticker_master_id'])) { + $stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id']) + ->pluck('id') + ->toArray(); - return $indicators; - }) + if (!empty($stickerMasterIds)) { + $query->whereIn('sticker_master_id', $stickerMasterIds); + } + } + }) + ->indicateUsing(function (array $data) { + $indicators = []; + if (!empty($data['Plant'])) { + $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); + } + + if (!empty($data['invoice_number'])) { + $indicators[] = 'Invoice Number: ' . $data['invoice_number']; + } + + if (!empty($data['serial_number'])) { + $indicators[] = 'Serial Number: ' . $data['serial_number']; + } + + if (!empty($data['created_from'])) { + $indicators[] = 'From: ' . $data['created_from']; + } + + if (!empty($data['created_to'])) { + $indicators[] = 'To: ' . $data['created_to']; + } + + if (!empty($data['sticker_master_id'])) { + $itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown'; + $indicators[] = 'Item Code: ' . $itemCode; + } + + return $indicators; + }) ]) ->filtersFormMaxHeight('280px') ->actions([