Add file handling for invoice processing and cleanup in LocatorInvoiceValidation

This commit is contained in:
dhanabalan
2025-11-15 20:25:16 +05:30
parent 3e41bad7f1
commit 23e823d2ea

View File

@@ -88,6 +88,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord
return; 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 try
{ {
// $record1 = LocatorInvoiceValidation::query() // $record1 = LocatorInvoiceValidation::query()
@@ -117,6 +129,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -134,16 +150,16 @@ class CreateLocatorInvoiceValidation extends CreateRecord
} }
$invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId) $invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId)
->where('invoice_number', $invoiceNumber) ->where('invoice_number', $invoiceNumber)
->count('invoice_number'); ->count('invoice_number');
if($invoiceExist <= 0) if($invoiceExist <= 0)
{ {
$filename = $invoiceNumber . '.xlsx'; $filename = $invoiceNumber . '.xlsx';
$folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH') $folderPath = Configuration::where('c_name', 'INVOICE_FOLDER_PATH')
->where('plant_id', $plantId) ->where('plant_id', $plantId)
->value('c_value'); ->value('c_value');
$fullFolderPath = "uploads/$folderPath"; $fullFolderPath = "uploads/$folderPath";
@@ -261,9 +277,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) { // if ($disk->exists($filePath)) {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -290,9 +306,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) { // if ($disk->exists($filePath)) {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -351,10 +367,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) // if ($disk->exists($filePath))
{ // {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -432,10 +448,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(800) ->duration(800)
->send(); ->send();
if ($disk->exists($filePath)) // if ($disk->exists($filePath))
{ // {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count(); $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count();
@@ -585,9 +601,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) { // if ($disk->exists($filePath)) {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -614,10 +630,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) // if ($disk->exists($filePath))
{ // {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -677,9 +693,9 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(5000) ->duration(5000)
->send(); ->send();
if ($disk->exists($filePath)) { // if ($disk->exists($filePath)) {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -736,10 +752,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(800) ->duration(800)
->send(); ->send();
if ($disk->exists($filePath)) // if ($disk->exists($filePath))
{ // {
$disk->delete($filePath); // $disk->delete($filePath);
} // }
$snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count(); $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->count();
@@ -858,6 +874,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord
$UnknownSerialNumbers = []; $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(); $invExist = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->first();
if (!$invExist) if (!$invExist)
{ {
@@ -907,6 +935,10 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(1000) ->duration(1000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -1206,6 +1238,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(1000) ->duration(1000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -1304,6 +1341,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(1000) ->duration(1000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -1376,6 +1418,18 @@ class CreateLocatorInvoiceValidation extends CreateRecord
$InvoiceSerialNumber = ''; $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(); $invExist = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNumber)->first();
if (!$invExist) if (!$invExist)
{ {
@@ -1424,6 +1478,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(1000) ->duration(1000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -1716,6 +1775,11 @@ class CreateLocatorInvoiceValidation extends CreateRecord
->duration(1000) ->duration(1000)
->send(); ->send();
if ($disk->exists($filePath))
{
$disk->delete($filePath);
}
$this->dispatch('loadData', '', $plantId); $this->dispatch('loadData', '', $plantId);
$this->form->fill([ $this->form->fill([
'plant_id' => $plantId, 'plant_id' => $plantId,