diff --git a/src/Command/ImportSAPDeltaCommand.php b/src/Command/ImportSAPDeltaCommand.php index aeea6366..9c214179 100644 --- a/src/Command/ImportSAPDeltaCommand.php +++ b/src/Command/ImportSAPDeltaCommand.php @@ -71,25 +71,45 @@ class ImportSAPDeltaCommand extends Command $added_brands = []; $added_sizes = []; $added_batteries = []; + $not_added_batteries = []; $total_processed = 0; + $total_not_processed = 0; while (($fields = fgetcsv($fh)) !== false) { - // data starts at row 2 - if ($row_num < 2) + // data starts at row 1 + if ($row_num < 1) { $row_num++; continue; } // check if blank row - if (strlen(trim($fields[0])) == 0) + if ((strlen(trim($fields[0])) == 0) && + (strlen(trim($fields[1])) == 0) && + (strlen(trim($fields[2])) == 0)) + { + $total_not_processed++; continue; + } // clean up fields $clean_brand = $this->normalizeName(trim($fields[0])); $clean_sku = $this->normalizeName(trim($fields[1])); $clean_size = $this->normalizeName(trim($fields[2])); + if ((empty($clean_brand)) || + (empty($clean_sku)) || + (empty($clean_size))) + { + $not_added_batteries[] = [ + 'sku' => $clean_sku, + 'brand' => $clean_brand, + 'size' => $clean_size, + ]; + $total_not_processed++; + continue; + } + // check if sap battery code already exists if (!isset($this->sap_battery_hash[$clean_sku])) { @@ -202,7 +222,8 @@ class ImportSAPDeltaCommand extends Command // need to output the list of added and not added data $this->writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, - $existing_brands, $existing_sizes, $existing_batteries, $total_processed); + $existing_brands, $existing_sizes, $existing_batteries, $total_processed, + $not_added_batteries, $total_not_processed); return 0; } @@ -244,7 +265,8 @@ class ImportSAPDeltaCommand extends Command } protected function writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries, - $existing_brands, $existing_sizes, $existing_batteries, $total_processed) + $existing_brands, $existing_sizes, $existing_batteries, $total_processed, + $bad_battery_data, $total_not_processed) { try { @@ -256,6 +278,7 @@ class ImportSAPDeltaCommand extends Command } fputs($fh, 'Total entries processed: ' . $total_processed . "\n"); + fputs($fh, 'Total entries not processed: ' . $total_not_processed . "\n"); fputs($fh, 'Total brands added: ' . count($added_brands) . "\n"); fputs($fh, 'Total sizes added: ' . count($added_sizes) . "\n"); @@ -265,6 +288,15 @@ class ImportSAPDeltaCommand extends Command fputs($fh, 'Total number of sizes in csv file that are in the system: ' . count($existing_sizes) . "\n"); fputs($fh, 'Total number of batteries in csv file that are in the system: ' . count($existing_batteries) . "\n"); + // write the batteries with bad data + fputs($fh, 'Entry Not Added: ' . "\n"); + foreach($bad_battery_data as $bad_batt) + { + $battery_line = $bad_batt['sku'] . ' ' . $bad_batt['brand'] . ' ' . $bad_batt['size']; + fputs($fh, $battery_line, strlen($battery_line)); + fputs($fh, "\n"); + } + // write the added batteries // check the existing brands array for the added ones $not_added_batteries = [];