Refactor code structure for improved readability and maintainability and Commented imported invoice logic on warning

This commit is contained in:
dhanabalan
2025-11-15 19:27:48 +05:30
parent 95e18838ca
commit 43ee1a3502
2 changed files with 398 additions and 397 deletions

View File

@@ -491,10 +491,10 @@ class InvoiceValidationResource extends Resource
if (!empty($uniqueInvalidCodes)) { if (!empty($uniqueInvalidCodes)) {
Notification::make() Notification::make()
->title('Invalid Item Codes') ->title('Invalid Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes)) ->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
@@ -513,10 +513,10 @@ class InvoiceValidationResource extends Resource
} }
else if (!empty($uniqueSerialCodes)) { else if (!empty($uniqueSerialCodes)) {
Notification::make() Notification::make()
->title('Invalid Serial Number') ->title('Invalid Serial Number')
->body('The following serial numbers should contain minimum 9 digit alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes)) ->body('The following serial numbers should contain minimum 9 digit alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes))
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
@@ -524,10 +524,10 @@ class InvoiceValidationResource extends Resource
} }
else if (!empty($duplicateSerialCodes)) { else if (!empty($duplicateSerialCodes)) {
Notification::make() Notification::make()
->title('Duplicate Serial Numbers') ->title('Duplicate Serial Numbers')
->body('The following serial numbers are already exist in imported excel:<br>' . implode(', ', $duplicateSerialCodes)) ->body('The following serial numbers are already exist in imported excel:<br>' . implode(', ', $duplicateSerialCodes))
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
@@ -540,9 +540,9 @@ class InvoiceValidationResource extends Resource
->danger() // This makes the notification red to indicate an error ->danger() // This makes the notification red to indicate an error
->body('Uploaded Excel sheet is empty or<br>contains no valid data.') ->body('Uploaded Excel sheet is empty or<br>contains no valid data.')
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
@@ -610,7 +610,7 @@ class InvoiceValidationResource extends Resource
} }
else else
{ {
// Save full file path to session // Save full file path to session
session(['uploaded_invoice_path' => $fullPath]); session(['uploaded_invoice_path' => $fullPath]);
Notification::make() Notification::make()
->title('Serial invoice imported successfully.') ->title('Serial invoice imported successfully.')
@@ -800,16 +800,17 @@ class InvoiceValidationResource extends Resource
if (!empty($uniqueInvalidCodes)) { if (!empty($uniqueInvalidCodes)) {
Notification::make() Notification::make()
->title('Invalid Item Codes') ->title('Invalid Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes)) ->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
} }
return; return;
} }
if (!empty($uniqueaplhaMat)) { if (!empty($uniqueaplhaMat)) {
Notification::make() Notification::make()
->title('Invalid Material Quantity') ->title('Invalid Material Quantity')
@@ -822,6 +823,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} }
if (!empty($uniqueZeroMat)) { if (!empty($uniqueZeroMat)) {
Notification::make() Notification::make()
->title('Invalid Material Quantity') ->title('Invalid Material Quantity')
@@ -837,8 +839,8 @@ class InvoiceValidationResource extends Resource
if (!empty($uniqueEmptyMat)) { if (!empty($uniqueEmptyMat)) {
Notification::make() Notification::make()
->title('Missing Material Quantity') ->title('Missing Material Quantity')
->body("The following item codes doesn't have valid material quantity:<br>" . implode(', ', $uniqueEmptyMat)) ->body("The following item codes doesn't have valid material quantity:<br>" . implode(', ', $uniqueEmptyMat))
->danger() ->danger()
->send(); ->send();
@@ -854,23 +856,24 @@ class InvoiceValidationResource extends Resource
->danger() // This makes the notification red to indicate an error ->danger() // This makes the notification red to indicate an error
->body('Uploaded Excel sheet is empty or<br>contains no valid data.') ->body('Uploaded Excel sheet is empty or<br>contains no valid data.')
->send(); ->send();
if ($disk->exists($path)) {
$disk->delete($path); if ($disk->exists($path)) {
} $disk->delete($path);
}
return; return;
} }
$uniqueCodes = array_unique($materialCodes); $uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item') $matchedItems = StickerMaster::with('item')
->whereHas('item', function ($query) use ($uniqueCodes) { ->whereHas('item', function ($query) use ($uniqueCodes) {
$query->whereIn('code', $uniqueCodes); $query->whereIn('code', $uniqueCodes);
}) })
->get(); ->get();
$matchedCodes = $matchedItems->pluck('item.code')->toArray(); $matchedCodes = $matchedItems->pluck('item.code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes); $missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes)) if (!empty($missingCodes))
{ {
@@ -893,18 +896,18 @@ class InvoiceValidationResource extends Resource
} }
$invalidCodes = $matchedItems $invalidCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->material_type)) //filter invalid ->filter(fn ($sticker) => empty($sticker->material_type)) //filter invalid
->pluck('item.code') ->pluck('item.code')
->toArray(); ->toArray();
if (count($invalidCodes) > 10) if (count($invalidCodes) > 10)
{ {
$invalidCodes = array_unique($invalidCodes); $invalidCodes = array_unique($invalidCodes);
Notification::make() Notification::make()
->title('Invalid item codes found') ->title('Invalid item codes found')
->body('' . count($invalidCodes) . 'invalid item codes found have serial number.') ->body('' . count($invalidCodes) . 'invalid item codes found have serial number.')
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
@@ -915,10 +918,10 @@ class InvoiceValidationResource extends Resource
{ {
$invalidCodes = array_unique($invalidCodes); $invalidCodes = array_unique($invalidCodes);
Notification::make() Notification::make()
->title('Invalid item codes found') ->title('Invalid item codes found')
->body('Serial invoice Item Codes found : ' . implode(', ', $invalidCodes)) ->body('Serial invoice Item Codes found : ' . implode(', ', $invalidCodes))
->danger() ->danger()
->send(); ->send();
if ($disk->exists($path)) { if ($disk->exists($path)) {
$disk->delete($path); $disk->delete($path);
@@ -996,9 +999,9 @@ class InvoiceValidationResource extends Resource
// Save full file path to session // Save full file path to session
session(['uploaded_material_invoice' => $fullPath]); session(['uploaded_material_invoice' => $fullPath]);
Notification::make() Notification::make()
->title('Material invoice imported successfully.') ->title('Material invoice imported successfully.')
->success() ->success()
->send(); ->send();
} }
} }