From 23e823d2eaa4982951466bd90750e28e080275b3 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 15 Nov 2025 20:25:16 +0530 Subject: [PATCH] Add file handling for invoice processing and cleanup in LocatorInvoiceValidation --- .../Pages/CreateLocatorInvoiceValidation.php | 128 +++++++++++++----- 1 file changed, 96 insertions(+), 32 deletions(-) diff --git a/app/Filament/Resources/LocatorInvoiceValidationResource/Pages/CreateLocatorInvoiceValidation.php b/app/Filament/Resources/LocatorInvoiceValidationResource/Pages/CreateLocatorInvoiceValidation.php index a813086..bb17fc2 100644 --- a/app/Filament/Resources/LocatorInvoiceValidationResource/Pages/CreateLocatorInvoiceValidation.php +++ b/app/Filament/Resources/LocatorInvoiceValidationResource/Pages/CreateLocatorInvoiceValidation.php @@ -88,6 +88,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord return; } + $filename = $invoiceNumber . '.xlsx'; + + $folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH') + ->where('plant_id', $plantId) + ->value('c_value'); + + $fullFolderPath = "uploads/$folderPath"; + + $directory = $fullFolderPath; + $disk = Storage::disk('local'); + $filePath = $directory . '/' . $filename; + try { // $record1 = LocatorInvoiceValidation::query() @@ -117,6 +129,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -134,16 +150,16 @@ class CreateLocatorInvoiceValidation extends CreateRecord } $invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId) - ->where('invoice_number', $invoiceNumber) - ->count('invoice_number'); + ->where('invoice_number', $invoiceNumber) + ->count('invoice_number'); if($invoiceExist <= 0) { $filename = $invoiceNumber . '.xlsx'; $folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH') - ->where('plant_id', $plantId) - ->value('c_value'); + ->where('plant_id', $plantId) + ->value('c_value'); $fullFolderPath = "uploads/$folderPath"; @@ -261,9 +277,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -290,9 +306,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -351,10 +367,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) - { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) + // { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -432,10 +448,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(800) ->send(); - if ($disk->exists($filePath)) - { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) + // { + // $disk->delete($filePath); + // } $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count(); @@ -585,9 +601,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -614,10 +630,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) - { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) + // { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -677,9 +693,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(5000) ->send(); - if ($disk->exists($filePath)) { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) { + // $disk->delete($filePath); + // } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -736,10 +752,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(800) ->send(); - if ($disk->exists($filePath)) - { - $disk->delete($filePath); - } + // if ($disk->exists($filePath)) + // { + // $disk->delete($filePath); + // } $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count(); @@ -858,6 +874,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord $UnknownSerialNumbers = []; + $filename = $invoiceNumber . '.xlsx'; + + $folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH') + ->where('plant_id', $plantId) + ->value('c_value'); + + $fullFolderPath = "uploads/$folderPath"; + + $directory = $fullFolderPath; + $disk = Storage::disk('local'); + $filePath = $directory . '/' . $filename; + $invExist = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->first(); if (!$invExist) { @@ -907,6 +935,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(1000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -1206,6 +1238,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(1000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } + $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -1304,6 +1341,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(1000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } + $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -1376,6 +1418,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord $InvoiceSerialNumber = ''; + $filename = $invoiceNumber . '.xlsx'; + + $folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH') + ->where('plant_id', $plantId) + ->value('c_value'); + + $fullFolderPath = "uploads/$folderPath"; + + $directory = $fullFolderPath; + $disk = Storage::disk('local'); + $filePath = $directory . '/' . $filename; + $invExist = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->first(); if (!$invExist) { @@ -1424,6 +1478,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(1000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } + $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId, @@ -1716,6 +1775,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord ->duration(1000) ->send(); + if ($disk->exists($filePath)) + { + $disk->delete($filePath); + } + $this->dispatch('loadData', '', $plantId); $this->form->fill([ 'plant_id' => $plantId,