diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php index b98d054..f0cd68b 100644 --- a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -17,9 +17,9 @@ use Filament\Resources\Pages\CreateRecord; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; +use Livewire\Attributes\On; use Maatwebsite\Excel\Facades\Excel; use Str; -use Livewire\Attributes\On; class CreateInvoiceValidation extends CreateRecord { @@ -53,6 +53,7 @@ class CreateInvoiceValidation extends CreateRecord public bool $showCapacitorInput = false; public $excel_file; + public $mInvoiceNo; public function getFormActions(): array @@ -121,8 +122,7 @@ class CreateInvoiceValidation extends CreateRecord // ..GET SERIAL INVOICE API - if(strlen($invoiceNumber) > 15) - { + if (strlen($invoiceNumber) > 15) { $payloadJson = base64_decode(strtr($parts[1], '-_', '+/')); @@ -132,41 +132,44 @@ class CreateInvoiceValidation extends CreateRecord ->danger() ->seconds(1) ->send(); + return; } $payload = json_decode($payloadJson, true); - - if (!isset($payload['data'])) { + if (! isset($payload['data'])) { Notification::make() ->title('Invalid payload for scanned qr code.') ->info() ->seconds(1) ->send(); + return; } $documentData = $payload['data']; - if($documentData == '' || $documentData == ''){ + if ($documentData == '' || $documentData == '') { Notification::make() ->title('Invalid payload for scanned qr code.') ->info() ->seconds(1) ->send(); + return; } - // Extract DocNo + // Extract DocNo preg_match('/"DocNo"\s*:\s*"([^"]+)"/', $documentData, $matches); - if (!isset($matches[1])) { + if (! isset($matches[1])) { Notification::make() ->title('Invoice number not found.') ->info() ->seconds(1) ->send(); + return; } @@ -175,7 +178,7 @@ class CreateInvoiceValidation extends CreateRecord } } - //dd($invoiceNumber); + // dd($invoiceNumber); // .. @@ -1427,6 +1430,7 @@ class CreateInvoiceValidation extends CreateRecord return; } + $missingCodes = []; foreach ($rows as $index => $row) { if ($index == 0) { continue; @@ -1438,8 +1442,8 @@ class CreateInvoiceValidation extends CreateRecord if (Str::length($materialCode) < 6) { continue; } else { - $sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($materialCode) { - $query->where('plant_id', $this->plantId)->where('code', $materialCode); // Check if item.code matches Excel's materialCode + $sticker = StickerMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($plantId, $materialCode) { + $query->where('plant_id', $plantId)->where('code', $materialCode); // $this->plantId >> Check if item.code matches Excel's materialCode }); if ($sticker->exists()) { if ($sticker->first()->material_type && ! empty($sticker->first()->material_type)) { @@ -1450,6 +1454,8 @@ class CreateInvoiceValidation extends CreateRecord break; } } else { + $missingCodes[] = $materialCode; + continue; } } @@ -1458,7 +1464,26 @@ class CreateInvoiceValidation extends CreateRecord } } - if ($invoiceType == 'M') { + $uniqueCodes = array_unique($missingCodes); + + if (! empty($uniqueCodes)) { + $missingCount = count($uniqueCodes); + + $message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:
'.implode(', ', $uniqueCodes); + + Notification::make() + ->title('Unknown: Item Codes') + ->body($message) + ->danger() + ->seconds(3) + ->send(); + $this->dispatch('playWarnSound'); + + // if ($disk->exists($filePath)) { + // $disk->delete($filePath); + // } + return; + } elseif ($invoiceType == 'M') { $invalidMatCodes = []; $materialCodes = []; $missingQuantities = []; @@ -3195,7 +3220,7 @@ class CreateInvoiceValidation extends CreateRecord if (! empty($emails)) { Mail::to($emails)->send( - new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode,$mUserName,'NotFoundInvoice') + new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType, $itemCode, $mUserName, 'NotFoundInvoice') ); } else { \Log::warning("No recipients found for plant {$plantId}, module Serial, rule invalid_serial.");