1
0
forked from poc/pds

Refactor readFiles method to enhance CSV row validation and ensure unique remaining rows are collected

This commit is contained in:
dhanabalan
2025-09-26 11:49:31 +05:30
parent bbe05d62b1
commit 9774cda2ad

View File

@@ -183,14 +183,15 @@ class SapFileController extends Controller
$serialNumbers = [];
$remainingRows = [];
foreach ($lines as $line) {
foreach ($lines as $line)
{
$values = str_getcsv($line);
// Debug: make sure CSV split is correct
if (count($values) < 6) {
return response()->json([
'status' => 'ERROR',
'message' => 'CSV row has fewer than 6 columns',
'message' => 'In text file has fewer than 6 columns',
'line' => $line
], 400);
}
@@ -199,9 +200,15 @@ class SapFileController extends Controller
$remainingRow = $values;
unset($remainingRow[5]);
// $remainingRow = array_values($remainingRow); // reindex
// $remainingRows[] = $remainingRow;
$remainingRow = array_values($remainingRow); // reindex
// Only add unique remaining rows
if (!in_array($remainingRow, $remainingRows, true)) {
$remainingRows[] = $remainingRow;
}
}
return response()->json([
'status' => 'SUCCESS',