Add checking for empty row and empty columns. #523
This commit is contained in:
parent
735bcffdd8
commit
28025a5735
1 changed files with 37 additions and 5 deletions
|
|
@ -71,25 +71,45 @@ class ImportSAPDeltaCommand extends Command
|
||||||
$added_brands = [];
|
$added_brands = [];
|
||||||
$added_sizes = [];
|
$added_sizes = [];
|
||||||
$added_batteries = [];
|
$added_batteries = [];
|
||||||
|
$not_added_batteries = [];
|
||||||
$total_processed = 0;
|
$total_processed = 0;
|
||||||
|
$total_not_processed = 0;
|
||||||
while (($fields = fgetcsv($fh)) !== false)
|
while (($fields = fgetcsv($fh)) !== false)
|
||||||
{
|
{
|
||||||
// data starts at row 2
|
// data starts at row 1
|
||||||
if ($row_num < 2)
|
if ($row_num < 1)
|
||||||
{
|
{
|
||||||
$row_num++;
|
$row_num++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if blank row
|
// 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;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// clean up fields
|
// clean up fields
|
||||||
$clean_brand = $this->normalizeName(trim($fields[0]));
|
$clean_brand = $this->normalizeName(trim($fields[0]));
|
||||||
$clean_sku = $this->normalizeName(trim($fields[1]));
|
$clean_sku = $this->normalizeName(trim($fields[1]));
|
||||||
$clean_size = $this->normalizeName(trim($fields[2]));
|
$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
|
// check if sap battery code already exists
|
||||||
if (!isset($this->sap_battery_hash[$clean_sku]))
|
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
|
// need to output the list of added and not added data
|
||||||
$this->writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries,
|
$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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +265,8 @@ class ImportSAPDeltaCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeOutputFile($report_file, $added_brands, $added_sizes, $added_batteries,
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -256,6 +278,7 @@ class ImportSAPDeltaCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs($fh, 'Total entries processed: ' . $total_processed . "\n");
|
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 brands added: ' . count($added_brands) . "\n");
|
||||||
fputs($fh, 'Total sizes added: ' . count($added_sizes) . "\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 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");
|
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
|
// write the added batteries
|
||||||
// check the existing brands array for the added ones
|
// check the existing brands array for the added ones
|
||||||
$not_added_batteries = [];
|
$not_added_batteries = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue