From 197184e2ed2bf55c1ef58eac85e8e5c8f4f238d0 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 5 Aug 2025 12:00:26 +0530 Subject: [PATCH] Refactor Invoice Validation Logic and Update UI for Serial and Material Invoices - Improved conditional checks for invoice processing in InvoiceValidationResource on completion (or pending). - Enhanced notifications for completed scanning processes for both serial and material invoices. - Updated CreateInvoiceValidation page to pass invoice type to serial and material invoice on completion (or pending). - Modified InvoiceDataTable to include a new property for serial/material invoice handling. - Adjusted Blade view to dynamically display the correct title and messages based on invoice type (serial/material). --- .../Resources/InvoiceValidationResource.php | 170 +++++++++++++----- .../Pages/CreateInvoiceValidation.php | 165 +++++++++-------- app/Livewire/InvoiceDataTable.php | 26 +-- .../livewire/invoice-data-table.blade.php | 26 ++- 4 files changed, 255 insertions(+), 132 deletions(-) diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index dfcceaa..f0d7e37 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -148,16 +148,16 @@ class InvoiceValidationResource extends Resource ->reactive() ->hidden(fn (callable $get) => ($get('invoice_number') == null || $get('update_invoice') == '0') || !empty($get('serial_number'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { - if(!$get('plant_id')) + if (!$get('plant_id')) { $set('update_invoice', null); return; } - if($get('update_invoice') === "1") + if ($get('update_invoice') == "1") { $totQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->where('plant_id', $get('plant_id'))->count(); - if($totQuan <= 0) + if ($totQuan <= 0) { $set('update_invoice', null); return; @@ -167,9 +167,9 @@ class InvoiceValidationResource extends Resource $scanMQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $get('plant_id'))->count(); $scanSQuan = InvoiceValidation::where('invoice_number', $get('invoice_number'))->where('scanned_status', 'Scanned')->where('plant_id', $get('plant_id'))->count(); - if($totMQuan > 0) + if ($totMQuan > 0) { - if ($totQuan === $scanMQuan) + if ($totQuan == $scanMQuan) { $set('update_invoice', null); return; @@ -177,7 +177,7 @@ class InvoiceValidationResource extends Resource } else { - if ($totQuan === $scanSQuan) + if ($totQuan == $scanSQuan) { $set('update_invoice', null); return; @@ -343,15 +343,57 @@ class InvoiceValidationResource extends Resource $fullPath = Storage::disk('local')->path($path); // /home/iot-dev/projects/pds/storage/app/private/uploads/temp/3RA0018735.xlsx + $totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->count(); + if ($totQuan > 0) + { + $scanSQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->where('scanned_status', 'Scanned')->count(); + if ($totQuan == $scanSQuan) + { + $invoiceFirst = InvoiceValidation::with('plant')->where('invoice_number', $originalNameOnly)->first(); + $plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null; + + Notification::make() + ->title("Serial invoice number : '$originalNameOnly' already completed the scanning process for plant : '$plantName'.") + ->danger() + ->send(); + + if ($disk->exists($path)) + { + $disk->delete($path); + } + return; + } + else + { + $invoiceFirst = InvoiceValidation::with('plant')->where('invoice_number', $originalNameOnly)->first(); + // $plantCode = $invoiceFirst ? (String)$invoiceFirst->plant->code : null; + $plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null; + $invoicePlantId = $invoiceFirst->plant_id; + if ($plantId != $invoicePlantId) + { + Notification::make() + ->title("Serial invoice number : '$originalNameOnly' already exists for plant : '$plantName'.
Choose the valid 'Plant' to proceed!") + ->danger() + ->send(); + + if ($disk->exists($path)) + { + $disk->delete($path); + } + return; + } + } + } + $totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->where('plant_id', $plantId)->count(); $scanSQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count(); - if($totQuan == $scanSQuan && $totQuan > 0) + if ($totQuan > 0 && $totQuan == $scanSQuan) { Notification::make() - ->title('Serial invoice already completed the scanning process for selected plant.') - ->danger() - ->send(); + ->title('Serial invoice already completed the scanning process for selected plant.') + ->danger() + ->send(); if ($disk->exists($path)) { @@ -364,7 +406,7 @@ class InvoiceValidationResource extends Resource { $rows = Excel::toArray(null, $fullPath)[0]; - if((count($rows) - 1) <= 0) + if ((count($rows) - 1) <= 0) { Notification::make() ->title('Records Not Found') @@ -388,7 +430,7 @@ class InvoiceValidationResource extends Resource foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $serialNumber = trim($row[1]); @@ -399,19 +441,17 @@ class InvoiceValidationResource extends Resource if (!empty($materialCode)) { - if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode)) + if (Str::length($materialCode) < 6 || !ctype_alnum($materialCode)) { $invalidMatCodes[] = $materialCode; - } else { - if (empty($serialNumber)) { $missingSerials[] = $materialCode; } - else if(Str::length($serialNumber) < 9 || !ctype_alnum($serialNumber)) + else if (Str::length($serialNumber) < 9 || !ctype_alnum($serialNumber)) { $invalidSerialCodes[] = $serialNumber; } @@ -453,7 +493,6 @@ class InvoiceValidationResource extends Resource } return; } - else if (!empty($uniqueMissingSerials)) { Notification::make() ->title('Missing Serial Numbers') @@ -479,7 +518,7 @@ class InvoiceValidationResource extends Resource else if (!empty($duplicateSerialCodes)) { Notification::make() ->title('Duplicate Serial Numbers') - ->body('The following serial numbers are already exist in database:
' . implode(', ', $duplicateSerialCodes)) + ->body('The following serial numbers are already exist in imported excel:
' . implode(', ', $duplicateSerialCodes)) ->danger() ->send(); if ($disk->exists($path)) { @@ -532,30 +571,30 @@ class InvoiceValidationResource extends Resource // Check which codes have a material_type set (not null) $invalidCodes = $matchedItems - ->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid - ->pluck('item.code') - ->toArray(); + ->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid + ->pluck('item.code') + ->toArray(); if (count($invalidCodes) > 10) { Notification::make() - ->title('Invalid item codes found') - ->body('' . count($invalidCodes) . 'item codes found have material type.') - ->danger() - ->send(); + ->title('Invalid item codes found') + ->body('' . count($invalidCodes) . 'item codes found have material type.') + ->danger() + ->send(); if ($disk->exists($path)) { $disk->delete($path); } return; } - else if(count($invalidCodes) > 0) + else if (count($invalidCodes) > 0) { Notification::make() - ->title('Invalid item codes found') - ->body('Material invoice Item Codes found : ' . implode(', ', $invalidCodes)) - ->danger() - ->send(); + ->title('Invalid item codes found') + ->body('Material invoice Item Codes found : ' . implode(', ', $invalidCodes)) + ->danger() + ->send(); if ($disk->exists($path)) { $disk->delete($path); @@ -567,7 +606,7 @@ class InvoiceValidationResource extends Resource // Save full file path to session session(['uploaded_invoice_path' => $fullPath]); Notification::make() - ->title('Serial invoice imported successfully.') + ->title('Serial invoice imported successfully.') ->success() ->send(); } @@ -603,7 +642,6 @@ class InvoiceValidationResource extends Resource ->visible(fn (Get $get) => !empty($get('plant_id'))) ->directory('uploads/temp'), ]) - ->action(function (array $data) { $uploadedFile = $data['invoice_material']; @@ -620,10 +658,52 @@ class InvoiceValidationResource extends Resource $fullPath = Storage::disk('local')->path($path); + $totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->count(); + if ($totQuan > 0) + { + $scanMQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->whereNotNull('serial_number')->where('serial_number', '!=', '')->count(); + if ($totQuan == $scanMQuan) + { + $invoiceFirst = InvoiceValidation::with('plant')->where('invoice_number', $originalNameOnly)->first(); + $plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null; + + Notification::make() + ->title("Material invoice number : '$originalNameOnly' already completed the scanning process for plant : '$plantName'.") + ->danger() + ->send(); + + if ($disk->exists($path)) + { + $disk->delete($path); + } + return; + } + else + { + $invoiceFirst = InvoiceValidation::with('plant')->where('invoice_number', $originalNameOnly)->first(); + // $plantCode = $invoiceFirst ? (String)$invoiceFirst->plant->code : null; + $plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null; + $invoicePlantId = $invoiceFirst->plant_id; + if ($plantId != $invoicePlantId) + { + Notification::make() + ->title("Material invoice number : '$originalNameOnly' already exists for plant : '$plantName'.
Choose the valid 'Plant' to proceed!") + ->danger() + ->send(); + + if ($disk->exists($path)) + { + $disk->delete($path); + } + return; + } + } + } + $totQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->where('plant_id', $plantId)->count(); $scanMQuan = InvoiceValidation::where('invoice_number', $originalNameOnly)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); - if($totQuan == $scanMQuan && $totQuan > 0) + if ($totQuan > 0 && $totQuan == $scanMQuan) { Notification::make() ->title('Material invoice already completed the scanning process for selected plant.') @@ -639,7 +719,7 @@ class InvoiceValidationResource extends Resource { $rows = Excel::toArray(null, $fullPath)[0]; - if((count($rows) - 1) <= 0) + if ((count($rows) - 1) <= 0) { Notification::make() ->title('Records Not Found') @@ -662,7 +742,7 @@ class InvoiceValidationResource extends Resource foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $materialQuantity = trim($row[1]); @@ -672,13 +752,13 @@ class InvoiceValidationResource extends Resource } if (!empty($materialCode)) { - if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode)) + if (Str::length($materialCode) < 6 || !ctype_alnum($materialCode)) { $invalidMatCodes[] = $materialCode; } else { - if($materialQuantity == 0) + if ($materialQuantity == 0) { $invalidMaterialQuan[] = $materialCode; } @@ -686,7 +766,7 @@ class InvoiceValidationResource extends Resource { $missingQuantities[] = $materialCode; } - else if(!is_numeric($materialQuantity)) + else if (!is_numeric($materialQuantity)) { $invalidMatQuan[] = $materialCode; } @@ -821,7 +901,7 @@ class InvoiceValidationResource extends Resource } return; } - else if(count($invalidCodes) > 0) + else if (count($invalidCodes) > 0) { $invalidCodes = array_unique($invalidCodes); Notification::make() @@ -852,29 +932,29 @@ class InvoiceValidationResource extends Resource foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } - if ($totalExcelQty === 0) { + if ($totalExcelQty == 0) { $zeroQtyCodes[] = $code; } elseif (!is_numeric($totalExcelQty)) { $nonNumericQtyCodes[] = $code; // Here you may want to check divisibility condition too - } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty !== 0) { + } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty != 0) { $notDivisibleCodes[] = $code; } } } $showValidationNotification = function(array $codes, string $message) { - if (count($codes) === 0) return; + if (count($codes) == 0) return; $uniqueCodes = array_unique($codes); $codeList = implode(', ', $uniqueCodes); @@ -1013,7 +1093,7 @@ class InvoiceValidationResource extends Resource ->query(function ($query, array $data) { // Hide all records initially if no filters are applied if (empty($data['invoice_type']) || (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['operator_id']) && empty($data['scanned_status']) && empty($data['sticker_master_id']))) { - if(empty($data['invoice_type'])) + if (empty($data['invoice_type'])) { Notification::make() ->title('Please, choose invoice type to filter.') diff --git a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php index 9e86def..bee8014 100644 --- a/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php +++ b/app/Filament/Resources/InvoiceValidationResource/Pages/CreateInvoiceValidation.php @@ -8,6 +8,7 @@ use App\Imports\ExcelImport; use App\Livewire\InvoiceDataTable; use App\Models\InvoiceValidation; use App\Models\Item; +use App\Models\Plant; use App\Models\StickerMaster; use Filament\Facades\Filament; use Filament\Pages\Concerns\ExposesTableToWidgets; @@ -74,6 +75,22 @@ class CreateInvoiceValidation extends CreateRecord $this->plantId = $plantId; + $plant = Plant::find($plantId); + + if ($plant) + { + $plantCode = $plant->code; + } + else + { + $plantCode = null; + } + + //..GET SERIAL INVOICE API + + + //.. + $updateStatus = $this->form->getState()['update_invoice'] ?? null; $this->invoiceNumber = trim($this->form->getState()['invoice_number']) ?? $invoiceNumber; @@ -116,7 +133,7 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scanMQuan, ]); - if ($totQuan === $scanMQuan) + if ($totQuan == $scanMQuan) { Notification::make() ->title("Completed: Material Invoice") @@ -134,7 +151,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: false); } else { @@ -147,7 +164,7 @@ class CreateInvoiceValidation extends CreateRecord // $this->dispatch( (!empty($hasRecords) && $hasRecords) ? 'refreshMaterialInvoiceData' : 'refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); //$this->invoiceNumber $this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); - if($updateStatus === '1') + if($updateStatus == '1') { //'Material invoice update in progress...'; $filename = $invoiceNumber . '.xlsx'; @@ -185,7 +202,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $materialQuantity = trim($row[1]); @@ -390,7 +407,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -399,16 +416,16 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } - if ($totalExcelQty === 0) { + if ($totalExcelQty == 0) { $zeroQtyCodes[] = $code; } elseif (!is_numeric($totalExcelQty)) { $nonNumericQtyCodes[] = $code; // Here you may want to check divisibility condition too - } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty !== 0) { + } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty != 0) { $notDivisibleCodes[] = $code; } } @@ -420,7 +437,7 @@ class CreateInvoiceValidation extends CreateRecord } $showValidationNotification = function(array $codes, string $message) { - if (count($codes) === 0) return; + if (count($codes) == 0) return; $uniqueCodes = array_unique($codes); $codeList = implode(', ', $uniqueCodes); @@ -452,7 +469,7 @@ class CreateInvoiceValidation extends CreateRecord $inserted = 0; foreach ($matchedItems as $sticker) { - if ($newQuan === -1 && !$hasQuanTyp) + if ($newQuan == -1 && !$hasQuanTyp) { InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) { $query->whereNull('serial_number')->orWhere('serial_number', ''); @@ -461,7 +478,7 @@ class CreateInvoiceValidation extends CreateRecord $newQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count(); } - else if ($newQuan === -1 && $hasQuanTyp) + else if ($newQuan == -1 && $hasQuanTyp) { InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->where(function($query) { $query->whereNull('serial_number')->orWhere('serial_number', ''); @@ -481,7 +498,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -490,7 +507,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } @@ -522,7 +539,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -531,7 +548,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } @@ -564,7 +581,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -573,7 +590,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; } } @@ -669,7 +686,7 @@ class CreateInvoiceValidation extends CreateRecord } } - if ($inserted > 0 || $oldQuan !== $newQuan) + if ($inserted > 0 || $oldQuan != $newQuan) { Notification::make() ->title("Material invoice successfully updatad.") @@ -695,13 +712,13 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if ($totalQuantity === $scannedQuantity) + if ($totalQuantity == $scannedQuantity) { if ($disk->exists($filePath)) { $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: false); } else { @@ -775,7 +792,7 @@ class CreateInvoiceValidation extends CreateRecord //$hasRecords = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->first()->stickerMasterRelation->material_type ?? null; // $this->dispatch('refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); - if ($totQuan === $scanSQuan) + if ($totQuan == $scanSQuan) { Notification::make() ->title("Completed: Serial Invoice") @@ -793,7 +810,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { @@ -804,7 +821,7 @@ class CreateInvoiceValidation extends CreateRecord ->send(); $this->dispatch('refreshInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId); - if($updateStatus === '1') + if($updateStatus == '1') { $filename = $invoiceNumber . '.xlsx'; $directory = 'uploads/temp'; @@ -846,7 +863,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $serialNumber = trim($row[1]); @@ -1087,7 +1104,7 @@ class CreateInvoiceValidation extends CreateRecord $inserted = 0; foreach ($rows as $index => $row) { - if ($index === 0) // Skip header; + if ($index == 0) // Skip header; { InvoiceValidation::where('invoice_number', $invoiceNumber) ->where(function($query) { @@ -1138,7 +1155,7 @@ class CreateInvoiceValidation extends CreateRecord } } - if ($inserted > 0 || $oldQuan !== $newQuan) + if ($inserted > 0 || $oldQuan != $newQuan) { Notification::make() ->title("Serial invoice successfully updated.") @@ -1165,13 +1182,13 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if ($totalQuantity === $scannedQuantity) + if ($totalQuantity == $scannedQuantity) { if ($disk->exists($filePath)) { $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { @@ -1283,7 +1300,7 @@ class CreateInvoiceValidation extends CreateRecord $uploadedFilename = pathinfo($fullPath, PATHINFO_FILENAME); // Compare with invoice number - if ($uploadedFilename !== $invoiceNumber) { + if ($uploadedFilename != $invoiceNumber) { Notification::make() ->title("Uploaded file name does not match the invoice number.") ->danger() @@ -1326,7 +1343,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; + if ($index == 0) continue; $materialCode = trim($row[0]); @@ -1365,7 +1382,7 @@ class CreateInvoiceValidation extends CreateRecord } } - if($invoiceType === 'M') + if($invoiceType == 'M') { $invalidMatCodes = []; $materialCodes = []; @@ -1375,7 +1392,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $materialQuantity = trim($row[1]); @@ -1578,7 +1595,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -1587,23 +1604,23 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } - if ($totalExcelQty === 0) { + if ($totalExcelQty == 0) { $zeroQtyCodes[] = $code; } elseif (!is_numeric($totalExcelQty)) { $nonNumericQtyCodes[] = $code; // Here you may want to check divisibility condition too - } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty !== 0) { + } elseif ($bundleQty != 0 && $totalExcelQty % $bundleQty != 0) { $notDivisibleCodes[] = $code; } } } $showValidationNotification = function(array $codes, string $message) { - if (count($codes) === 0) return; + if (count($codes) == 0) return; $uniqueCodes = array_unique($codes); $codeList = implode(', ', $uniqueCodes); @@ -1642,7 +1659,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -1651,7 +1668,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } @@ -1677,7 +1694,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -1686,7 +1703,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } @@ -1711,7 +1728,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $excelCode = trim($row[0]); $excelMatQty = trim($row[1]); @@ -1720,7 +1737,7 @@ class CreateInvoiceValidation extends CreateRecord continue; } - if ($excelCode === $code && is_numeric($excelMatQty)) { + if ($excelCode == $code && is_numeric($excelMatQty)) { $totalExcelQty += $excelMatQty; // Sum up the quantities } } @@ -1759,13 +1776,13 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if ($totalQuantity === $scannedQuantity) + if ($totalQuantity == $scannedQuantity) { if ($disk->exists($filePath)) { $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: false); } else { @@ -1805,7 +1822,7 @@ class CreateInvoiceValidation extends CreateRecord } } } - else if($invoiceType === 'S') + else if($invoiceType == 'S') { $invalidMatCodes = []; $materialCodes = []; @@ -1817,7 +1834,7 @@ class CreateInvoiceValidation extends CreateRecord foreach ($rows as $index => $row) { - if ($index === 0) continue; // Skip header + if ($index == 0) continue; // Skip header $materialCode = trim($row[0]); $serialNumber = trim($row[1]); @@ -2077,7 +2094,7 @@ class CreateInvoiceValidation extends CreateRecord $inserted = 0; foreach ($rows as $index => $row) { - if ($index === 0) continue; + if ($index == 0) continue; $materialCode = trim($row[0]); $serialNumber = trim($row[1]); @@ -2123,13 +2140,13 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if ($totalQuantity === $scannedQuantity) + if ($totalQuantity == $scannedQuantity) { if ($disk->exists($filePath)) { $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { @@ -2201,9 +2218,9 @@ class CreateInvoiceValidation extends CreateRecord { $totalQuantity = InvoiceValidation::where('invoice_number', $this->invoiceNumber)->where('plant_id', $this->plantId)->count(); $scannedQuantity = InvoiceValidation::where('invoice_number', $this->invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $this->plantId)->count(); - if ($totalQuantity === $scannedQuantity) + if ($totalQuantity == $scannedQuantity) { - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $this->invoiceNumber, plantId: $this->plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $this->invoiceNumber, plantId: $this->plantId, isSerial: true); } else { @@ -2255,7 +2272,7 @@ class CreateInvoiceValidation extends CreateRecord { if ($totMQuan > 0) { - if ($totQuan === $scanMQuan) + if ($totQuan == $scanMQuan) { Notification::make() ->title('Completed: Material Invoice') @@ -2282,7 +2299,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: false); return; } else @@ -2759,7 +2776,7 @@ class CreateInvoiceValidation extends CreateRecord $scannedMQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $plantId)->count(); - if($totQuan === $scannedMQuantity) + if($totQuan == $scannedMQuantity) { Notification::make() ->title('Completed: Material Invoice') @@ -2786,7 +2803,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: false); } else { @@ -2804,7 +2821,7 @@ class CreateInvoiceValidation extends CreateRecord } else { - if ($totQuan === $scanSQuan) + if ($totQuan == $scanSQuan) { Notification::make() ->title('Completed: Serial Invoice') @@ -2831,7 +2848,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); return; } else @@ -3004,7 +3021,7 @@ class CreateInvoiceValidation extends CreateRecord ]); return; } - else if($hadMotorQr === $hasMotorQr) + else if($hadMotorQr == $hasMotorQr) { Notification::make() ->title('Duplicate: Motor QR') @@ -3027,7 +3044,7 @@ class CreateInvoiceValidation extends CreateRecord $packCnt = 1; $scanCnt = 1; $record->motor_scanned_status = 1; - //if($hadPumpQr === $hasPumpQr && $hadPumpSetQr === $hasPumpSetQr) + //if($hadPumpQr == $hasPumpQr && $hadPumpSetQr == $hasPumpSetQr) if($hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) { $packCnt = $hasPumpQr ? $packCnt + 1 : $packCnt; @@ -3038,7 +3055,7 @@ class CreateInvoiceValidation extends CreateRecord $scanCnt = $hadPumpSetQr ? $scanCnt + 1: $scanCnt; $scanCnt = $hadCapacitorQr ? $scanCnt + 1: $scanCnt; - if($packCnt === $scanCnt) + if($packCnt == $scanCnt) { $record->scanned_status = 'Scanned'; } @@ -3067,7 +3084,7 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if($totQuan === $scannedQuantity) + if($totQuan == $scannedQuantity) { Notification::make() ->title('Completed: Serial Invoice') @@ -3085,7 +3102,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { @@ -3114,7 +3131,7 @@ class CreateInvoiceValidation extends CreateRecord ]); return; } - else if($hadPumpQr === $hasPumpQr) + else if($hadPumpQr == $hasPumpQr) { Notification::make() ->title('Duplicate: Pump QR') @@ -3137,7 +3154,7 @@ class CreateInvoiceValidation extends CreateRecord $packCnt = 1; $scanCnt = 1; $record->pump_scanned_status = 1; - // if($hadMotorQr === $hasMotorQr && $hadPumpSetQr === $hasPumpSetQr && ($hadCapacitorQr === '1' && $hasCapacitorQr)) + // if($hadMotorQr == $hasMotorQr && $hadPumpSetQr == $hasPumpSetQr && ($hadCapacitorQr == '1' && $hasCapacitorQr)) if($hasMotorQr || $hasPumpSetQr || $hasCapacitorQr) { $packCnt = $hasMotorQr ? $packCnt + 1 : $packCnt; @@ -3148,7 +3165,7 @@ class CreateInvoiceValidation extends CreateRecord $scanCnt = $hadPumpSetQr ? $scanCnt + 1: $scanCnt; $scanCnt = $hadCapacitorQr ? $scanCnt + 1: $scanCnt; - if($packCnt === $scanCnt) + if($packCnt == $scanCnt) { $record->scanned_status = 'Scanned'; } @@ -3177,7 +3194,7 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if($totQuan === $scannedQuantity) + if($totQuan == $scannedQuantity) { Notification::make() ->title('Completed: Serial Invoice') @@ -3195,7 +3212,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { @@ -3226,7 +3243,7 @@ class CreateInvoiceValidation extends CreateRecord ]); return; } - else if($hadCapacitorQr === '1' && $hasCapacitorQr) + else if($hadCapacitorQr == '1' && $hasCapacitorQr) { Notification::make() ->title('Duplicate: Capacitor QR') @@ -3285,7 +3302,7 @@ class CreateInvoiceValidation extends CreateRecord ]); return; } - else if($hadPumpSetQr === $hasPumpSetQr) + else if($hadPumpSetQr == $hasPumpSetQr) { Notification::make() ->title('Duplicate: Pump Set QR') @@ -3308,7 +3325,7 @@ class CreateInvoiceValidation extends CreateRecord $packCnt = 1; $scanCnt = 1; $record->scanned_status_set = 1; - // if($hadMotorQr === $hasMotorQr && $hadPumpQr === $hasPumpQr && ($hadCapacitorQr === '1' && $hasCapacitorQr)) + // if($hadMotorQr == $hasMotorQr && $hadPumpQr == $hasPumpQr && ($hadCapacitorQr == '1' && $hasCapacitorQr)) if($hasMotorQr || $hasPumpQr || $hasCapacitorQr) { $packCnt = $hasMotorQr ? $packCnt + 1 : $packCnt; @@ -3319,7 +3336,7 @@ class CreateInvoiceValidation extends CreateRecord $scanCnt = $hadPumpQr ? $scanCnt + 1: $scanCnt; $scanCnt = $hadCapacitorQr ? $scanCnt + 1: $scanCnt; - if($packCnt === $scanCnt) + if($packCnt == $scanCnt) { $record->scanned_status = 'Scanned'; } @@ -3348,7 +3365,7 @@ class CreateInvoiceValidation extends CreateRecord 'scanned_quantity'=> $scannedQuantity, ]); - if($totQuan === $scannedQuantity) + if($totQuan == $scannedQuantity) { Notification::make() ->title('Completed: Serial Invoice') @@ -3366,7 +3383,7 @@ class CreateInvoiceValidation extends CreateRecord //$fullPath = $disk->path($filePath); $disk->delete($filePath); } - $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId); + $this->dispatch('refreshCompletedInvoice', invoiceNumber: $invoiceNumber, plantId: $plantId, isSerial: true); } else { diff --git a/app/Livewire/InvoiceDataTable.php b/app/Livewire/InvoiceDataTable.php index 286d961..a636873 100644 --- a/app/Livewire/InvoiceDataTable.php +++ b/app/Livewire/InvoiceDataTable.php @@ -19,6 +19,8 @@ class InvoiceDataTable extends Component public bool $completedInvoice = false; + public bool $isSerial = false; + public bool $emptyInvoice = false; public bool $hasSearched = false; @@ -49,11 +51,12 @@ class InvoiceDataTable extends Component public string $currentSerialNumber = ''; - public function loadCompletedData($invoiceNumber, $plantId) + public function loadCompletedData($invoiceNumber, $plantId, $isSerial) { $this->plantId = $plantId; $this->invoiceNumber = $invoiceNumber; $this->completedInvoice = true; + $this->isSerial = $isSerial; $this->emptyInvoice = false; $this->hasSearched = false; $this->materialInvoice = false; @@ -64,8 +67,8 @@ class InvoiceDataTable extends Component { $this->plantId = $plantId; $this->invoiceNumber = $invoiceNumber; - $this->emptyInvoice = true; $this->completedInvoice = false; + $this->emptyInvoice = true; $this->hasSearched = false; $this->materialInvoice = false; // $this->showCapacitorInput = false; @@ -75,9 +78,10 @@ class InvoiceDataTable extends Component { $this->plantId = $plantId; $this->invoiceNumber = $invoiceNumber; - $this->hasSearched = true; - $this->emptyInvoice = false; $this->completedInvoice = false; + $this->isSerial = true; + $this->emptyInvoice = false; + $this->hasSearched = true; $this->materialInvoice = false; // $this->showCapacitorInput = false; @@ -113,10 +117,11 @@ class InvoiceDataTable extends Component { $this->plantId = $plantId; $this->invoiceNumber = $invoiceNumber; - $this->materialInvoice = true; - $this->emptyInvoice = false; $this->completedInvoice = false; + $this->isSerial = false; + $this->emptyInvoice = false; $this->hasSearched = false; + $this->materialInvoice = true; // $this->showCapacitorInput = false; //->where('serial_number', '!=', '') @@ -171,13 +176,12 @@ class InvoiceDataTable extends Component $this->currentSerialNumber = $serialNumber; $this->showCapacitorInput = true; // $this->capacitorInput = ''; - $this->emptyInvoice = false; $this->completedInvoice = false; + $this->isSerial = true; + $this->emptyInvoice = false; $this->hasSearched = false; $this->materialInvoice = false; - $this->dispatch('focus-capacitor-input'); - - + $this->dispatch('focus-capacitor-input'); } public function cancelCapacitorInput() @@ -330,7 +334,7 @@ class InvoiceDataTable extends Component ->success() ->seconds(2) ->send(); - $this->loadCompletedData($matchingValidation->invoice_number, $matchingValidation->plant_id); + $this->loadCompletedData($matchingValidation->invoice_number, $matchingValidation->plant_id, true); } else { diff --git a/resources/views/livewire/invoice-data-table.blade.php b/resources/views/livewire/invoice-data-table.blade.php index 6364614..f0a9a2d 100644 --- a/resources/views/livewire/invoice-data-table.blade.php +++ b/resources/views/livewire/invoice-data-table.blade.php @@ -1,7 +1,23 @@
-

INVOICE DATA TABLE

+

+ @if ($hasSearched) + SERIAL INVOICE DATA TABLE + @elseif ($materialInvoice) + MATERIAL INVOICE DATA TABLE + @else + @if ($completedInvoice) + @if ($isSerial) + SERIAL INVOICE DATA TABLE + @else + MATERIAL INVOICE DATA TABLE + @endif + @else + INVOICE DATA TABLE + @endif + @endif +


@@ -10,7 +26,13 @@ {{-- Modal for completed invoice--}} @if ($completedInvoice)
-

Completed the scanning process for invoice number {{ $invoiceNumber }}.

+

+ @if ($isSerial) + Completed the scanning process for serial invoice number {{ $invoiceNumber }}. + @else + Completed the scanning process for material invoice number {{ $invoiceNumber }}. + @endif +

@endif