Modify import legacy job order command to be compatible with sap battery data #174
This commit is contained in:
parent
97b04a8b6e
commit
34d21b4184
1 changed files with 408 additions and 90 deletions
|
|
@ -15,6 +15,7 @@ use App\Entity\BatteryModel;
|
|||
use App\Entity\VehicleManufacturer;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\PlateNumber;
|
||||
use App\Entity\SAPBattery;
|
||||
|
||||
use App\Ramcar\LegacyBattery;
|
||||
use App\Ramcar\LegacyVehicleManufacturer;
|
||||
|
|
@ -36,6 +37,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
protected $vmfg_hash;
|
||||
protected $vehicle_hash;
|
||||
protected $jo_hash;
|
||||
protected $sap_battery_hash;
|
||||
|
||||
protected $row_fields;
|
||||
protected $data_fields;
|
||||
|
|
@ -50,6 +52,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$this->loadBatterySizes();
|
||||
$this->loadVehicleManufacturers();
|
||||
$this->loadVehicles();
|
||||
$this->loadSAPBatteries();
|
||||
|
||||
$this->jo_hash = [];
|
||||
|
||||
|
|
@ -253,8 +256,10 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
// get entity manager
|
||||
$em = $this->em;
|
||||
|
||||
/*
|
||||
$trans_types = [];
|
||||
$service_types = [];
|
||||
*/
|
||||
$no_sizes = [];
|
||||
|
||||
// files
|
||||
|
|
@ -307,6 +312,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$this->jo_hash[$id]['data']['plate_number'] = $plate_num;
|
||||
|
||||
|
||||
/*
|
||||
// let's track purchases first
|
||||
if ($fields[5] != 'PURCHASE')
|
||||
continue;
|
||||
|
|
@ -332,103 +338,16 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$service_types[$fields[7]] = $fields[5];
|
||||
|
||||
fwrite($plate_outfile, $plate_num . ',' . $vehicle['id'] . "\n");
|
||||
*/
|
||||
|
||||
// warranty class
|
||||
if (isset($fields[107]))
|
||||
{
|
||||
// echo 'warranty class - ' . $fields[107] . "\n";
|
||||
|
||||
|
||||
$warr_class = WarrantyClass::convertFromLegacy($fields[107]);
|
||||
if ($warr_class)
|
||||
{
|
||||
$batt_model_id = $batt_model;
|
||||
$batt_size_id = $batt_size;
|
||||
|
||||
// model and size
|
||||
$line = $batt_model_id . ',' . $batt_size_id . ',';
|
||||
|
||||
// echo 'wclass - ' . $warr_class . "\n";
|
||||
// echo 'serial - ' . $fields[110] . "\n";
|
||||
// echo 'expiry - ' . $fields[109] . "\n";
|
||||
|
||||
// serial
|
||||
if (isset($fields[110]) && strlen(trim($fields[110])) > 0)
|
||||
$line .= $fields[110] . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// warranty class
|
||||
$line .= $warr_class . ',';
|
||||
|
||||
// plate number
|
||||
$line .= $plate_num . ',';
|
||||
|
||||
$date_today = new DateTime();
|
||||
|
||||
// status
|
||||
// check if expired
|
||||
if (isset($fields[109]) && strlen(trim($fields[109])) > 0)
|
||||
{
|
||||
$ex_date = DateTime::createFromFormat('m/d/Y', $fields[109]);
|
||||
$ex_tstamp = $ex_date->getTimestamp();
|
||||
$today_tstamp = $date_today->getTimestamp();
|
||||
if ($today_tstamp > $ex_tstamp)
|
||||
$status = WarrantyStatus::EXPIRED;
|
||||
else
|
||||
$status = WarrantyStatus::ACTIVE;
|
||||
}
|
||||
$line .= $status . ',';
|
||||
|
||||
// date create
|
||||
$line .= $date_today->format('Ymd') . ',';
|
||||
|
||||
// date purchase
|
||||
if (isset($fields[84]) && strlen(trim($fields[84])) > 0)
|
||||
{
|
||||
$pur_date = DateTime::createFromFormat('m/d/Y', $fields[84]);
|
||||
$line .= $pur_date->format('Ymd') . ',';
|
||||
}
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
|
||||
// date expire
|
||||
if (isset($fields[109]) && strlen(trim($fields[109])) > 0)
|
||||
$line .= $ex_date->format('Ymd') . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// date claim
|
||||
$line .= '\N';
|
||||
|
||||
fwrite($warr_outfile, $line . "\n");
|
||||
}
|
||||
$this->processWarrantyDump($warr_outfile, $fields);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// check if we marked it already
|
||||
if (isset($save_plates[$plate_num]))
|
||||
continue;
|
||||
|
||||
// check if already there
|
||||
$find_plate = $em->getRepository(PlateNumber::class)->find($plate_num);
|
||||
if ($find_plate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// save to db
|
||||
$o_plate = new PlateNumber();
|
||||
$o_plate->setID($plate_num)
|
||||
->setVehicle($vehicle['object']);
|
||||
|
||||
$em->persist($o_plate);
|
||||
|
||||
$save_plates[$plate_num] = true;
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
// plate
|
||||
echo '14 - ' . $fields[14] . "\n";
|
||||
|
|
@ -478,6 +397,9 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
*/
|
||||
}
|
||||
|
||||
// post process
|
||||
$this->processJODump($jo_outfile, $jorow_outfile, $fields);
|
||||
|
||||
// print_r($this->jo_hash);
|
||||
|
||||
// $em->flush();
|
||||
|
|
@ -498,6 +420,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
print_r($this->row_max_field_size);
|
||||
*/
|
||||
|
||||
/*
|
||||
// save job order
|
||||
foreach ($this->jo_hash as $jo)
|
||||
{
|
||||
|
|
@ -509,6 +432,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
foreach ($jo['rows'] as $jo_row)
|
||||
fputcsv($jorow_outfile, $jo_row);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
fclose($plate_outfile);
|
||||
|
|
@ -807,6 +731,20 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
}
|
||||
}
|
||||
|
||||
protected function loadSAPBatteries()
|
||||
{
|
||||
$this->sap_battery_hash = [];
|
||||
|
||||
$batts = $this->em->getRepository(SAPBattery::class)->findAll();
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
$brand_id = $batt->getBrand()->getName();
|
||||
$size_id = $batt->getSize()->getName();
|
||||
|
||||
$this->sap_battery_hash[$brand_id][$size_id] = $batt->getID();
|
||||
}
|
||||
}
|
||||
|
||||
protected function simplifyName($text, $replace_spaces = true)
|
||||
{
|
||||
if ($replace_spaces)
|
||||
|
|
@ -963,4 +901,384 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$vehicle = $make_list[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function processWarrantyDump($file, $fields)
|
||||
{
|
||||
$warr_class = WarrantyClass::convertFromLegacy($fields[107]);
|
||||
|
||||
// skip if invalid warranty class
|
||||
if (!$warr_class)
|
||||
return;
|
||||
|
||||
/*
|
||||
$batt_model_id = $batt_model;
|
||||
$batt_size_id = $batt_size;
|
||||
*/
|
||||
|
||||
// model and size
|
||||
// $line = $batt_model_id . ',' . $batt_size_id . ',';
|
||||
$line = '';
|
||||
|
||||
// echo 'wclass - ' . $warr_class . "\n";
|
||||
// echo 'serial - ' . $fields[110] . "\n";
|
||||
// echo 'expiry - ' . $fields[109] . "\n";
|
||||
|
||||
// serial
|
||||
if (isset($fields[110]) && strlen(trim($fields[110])) > 0)
|
||||
$line .= $fields[110] . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// warranty class
|
||||
$line .= $warr_class . ',';
|
||||
|
||||
// plate number
|
||||
// $line .= $plate_num . ',';
|
||||
|
||||
$date_today = new DateTime();
|
||||
|
||||
// status
|
||||
// check if expired
|
||||
if (isset($fields[109]) && strlen(trim($fields[109])) > 0)
|
||||
{
|
||||
$ex_date = DateTime::createFromFormat('m/d/Y', $fields[109]);
|
||||
$ex_tstamp = $ex_date->getTimestamp();
|
||||
$today_tstamp = $date_today->getTimestamp();
|
||||
if ($today_tstamp > $ex_tstamp)
|
||||
$status = WarrantyStatus::EXPIRED;
|
||||
else
|
||||
$status = WarrantyStatus::ACTIVE;
|
||||
}
|
||||
// $line .= $status . ',';
|
||||
|
||||
|
||||
// date create
|
||||
$line .= $date_today->format('Ymd') . ',';
|
||||
|
||||
// date purchase
|
||||
if (isset($fields[84]) && strlen(trim($fields[84])) > 0)
|
||||
{
|
||||
$pur_date = DateTime::createFromFormat('m/d/Y', $fields[84]);
|
||||
$line .= $pur_date->format('Ymd') . ',';
|
||||
}
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
|
||||
// date expire
|
||||
if (isset($fields[109]) && strlen(trim($fields[109])) > 0)
|
||||
$line .= $ex_date->format('Ymd') . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// date claim
|
||||
$line .= '\N';
|
||||
|
||||
// TODO: sap_bty_id (sku)
|
||||
// TODO: first name
|
||||
// TODO: last name
|
||||
// TODO: mobile number
|
||||
|
||||
// fwrite($file, $line . "\n");
|
||||
}
|
||||
|
||||
protected function processJODump($jo_file, $jorow_file, $fields)
|
||||
{
|
||||
// process all job orders
|
||||
foreach ($this->jo_hash as $id => $jo)
|
||||
{
|
||||
// skip services
|
||||
if ($jo['data']['trans_type'] == 'service')
|
||||
continue;
|
||||
|
||||
// skip post
|
||||
if ($jo['data']['trans_type'] == 'post')
|
||||
continue;
|
||||
|
||||
// process rows
|
||||
foreach ($jo['rows'] as $row)
|
||||
{
|
||||
// check for the actual item
|
||||
if (trim($row['price_level']) == 'Base Price' && trim($row['account']) == 'Sales')
|
||||
{
|
||||
$raw_battery = trim(strtoupper($row['item']));
|
||||
|
||||
switch ($raw_battery)
|
||||
{
|
||||
// skip services labelled as purchases
|
||||
case 'ANNUAL FREE SERVICE':
|
||||
case 'DIAGNOSTIC':
|
||||
case 'JUMPSTART':
|
||||
case 'RECHARGING':
|
||||
continue;
|
||||
default:
|
||||
echo "Battery - $raw_battery - " . $jo['data']['trans_type'] . "\n";
|
||||
|
||||
$sap_batt = $this->findSAPBattery($raw_battery);
|
||||
if ($sap_batt == null)
|
||||
echo "battery not found - $raw_battery\n";
|
||||
|
||||
/*
|
||||
// check if battery is found
|
||||
$batt_model = null;
|
||||
$batt_size = null;
|
||||
$found_battery = $this->findBattery($raw_battery, $batt_model, $batt_size);
|
||||
if (!$found_battery)
|
||||
{
|
||||
echo "battery not found - $raw_battery\n";
|
||||
}
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function findSAPBattery($battery)
|
||||
{
|
||||
$sap_brand = null;
|
||||
$sap_size = null;
|
||||
$res = $this->translateToSAPBattery($battery, $sap_brand, $sap_size);
|
||||
if (!$res)
|
||||
return null;
|
||||
|
||||
if (!isset($this->sap_battery_hash[$sap_brand][$sap_size]))
|
||||
return null;
|
||||
|
||||
return $this->sap_battery_hash[$sap_brand][$sap_size];
|
||||
}
|
||||
|
||||
protected function translateToSAPBattery($battery, &$sap_brand, &$sap_size)
|
||||
{
|
||||
switch ($battery)
|
||||
{
|
||||
case '1SM /NS50 / D23L ENDURO':
|
||||
$sap_size = '1SMF';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '1SM /NS50 / D23L ENFORCER':
|
||||
$sap_size = '1SMF';
|
||||
$sap_brand = 'MOTOLITE ENFORCER';
|
||||
return true;
|
||||
|
||||
case '1SM /NS50 / D23L GOLD':
|
||||
$sap_size = '1SMF';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '1SM /NS50 / D23R GOLD REVERSE':
|
||||
$sap_size = '1SMF REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '1SM / NS50XL / D23L EXCEL':
|
||||
$sap_size = '1SMF';
|
||||
$sap_brand = 'EXCEL';
|
||||
return true;
|
||||
|
||||
case '2D / N120 / F51 TRUCKMASTER':
|
||||
$sap_size = '2D';
|
||||
$sap_brand = 'TRUCKMASTER';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60ARS /B24RS ENDURO REVERSE':
|
||||
$sap_size = 'NS60 REVERSE';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60ARS /B24RS EXCEL REVERSE':
|
||||
$sap_size = 'NS60 REVERSE';
|
||||
$sap_brand = 'EXCEL';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60ARS /B24RS GOLD REVERSE':
|
||||
$sap_size = 'NS60 REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60 /B24L ENDURO':
|
||||
$sap_size = 'NS60';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60 /B24L EXCEL':
|
||||
$sap_size = 'NS60';
|
||||
$sap_brand = 'EXCEL';
|
||||
return true;
|
||||
|
||||
case '2HN / NS60 /B24L GOLD':
|
||||
$sap_size = 'NS60';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '2SM / MG50 / D26L GOLD':
|
||||
$sap_size = '2SMF';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '2SM / MG50 / D26R GOLD REVERSE':
|
||||
$sap_size = '2SMF REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '2SM / N50 / D26L ENDURO':
|
||||
$sap_size = '2SMF';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '2SM / N50 / D26L ENFORCER':
|
||||
$sap_size = '2SMF';
|
||||
$sap_brand = 'MOTOLITE ENFORCER';
|
||||
return true;
|
||||
|
||||
case '2SM / N50XL / D26L EXCEL':
|
||||
$sap_size = '2SMF';
|
||||
$sap_brand = 'EXCEL';
|
||||
return true;
|
||||
|
||||
case '3SM / MG70 / D31L GOLD':
|
||||
$sap_size = '3SMF';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '3SM / MG70 / D31R GOLD REVERSE':
|
||||
$sap_size = '3SMF REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '3SM / N70 / D31L ENDURO':
|
||||
$sap_size = '3SMF';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '3SM / N70 / D31L ENFORCER':
|
||||
$sap_size = '3SMF';
|
||||
$sap_brand = 'MOTOLITE ENFORCER';
|
||||
return true;
|
||||
|
||||
case '3SM / N70XL / D31L EXCEL':
|
||||
$sap_size = '3SMF';
|
||||
$sap_brand = 'EXCEL';
|
||||
return true;
|
||||
|
||||
case '4D / N150 / G51 TRUCKMASTER':
|
||||
$sap_size = '4D';
|
||||
$sap_brand = 'TRUCKMASTER';
|
||||
return true;
|
||||
|
||||
case '4SN / NS40 / B20L ENDURO':
|
||||
$sap_size = 'NS40';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case '4SN / NS40 / B20L GOLD':
|
||||
$sap_size = 'NS40';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '4SN / NS40R / B20R GOLD REVERSE':
|
||||
$sap_size = 'NS40 REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case '6SM / N100 / E41 TRUCKMASTER':
|
||||
$sap_size = '6SMF';
|
||||
$sap_brand = 'TRUCKMASTER';
|
||||
return true;
|
||||
|
||||
case '8D / N200 / H52 TRUCKMASTER':
|
||||
$sap_size = '8D';
|
||||
$sap_brand = 'TRUCKMASTER';
|
||||
return true;
|
||||
|
||||
case 'D20 / N50 SL':
|
||||
$sap_size = 'D20';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 110 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'DIN110';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 44 ENDURO':
|
||||
$sap_size = 'DIN44';
|
||||
$sap_brand = 'ENDURO';
|
||||
return true;
|
||||
|
||||
case 'DIN 44 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'DIN44';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 55 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'DIN55';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 55R GOLD REVERSE SPECIAL TYPE':
|
||||
$sap_size = 'DIN55 REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 66 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'DIN66';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 66R GOLD REVERSE SPECIAL TYPE':
|
||||
$sap_size = 'DIN66 REVERSE';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'DIN 88 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'DIN88';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'GOLFMASTER TOBULAR GC2 6V':
|
||||
$sap_size = 'GC2-TUBULAR';
|
||||
$sap_brand = 'SOLAR';
|
||||
return true;
|
||||
|
||||
case 'GOLFMASTER TOBULAR GC8 8V':
|
||||
$sap_size = 'GC8-TUBULAR';
|
||||
$sap_brand = 'SOLAR';
|
||||
return true;
|
||||
|
||||
case 'GROUP 34/78 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'G34';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'GROUP 65 GOLD SPECIAL TYPE':
|
||||
$sap_size = 'G65';
|
||||
$sap_brand = 'GOLD';
|
||||
return true;
|
||||
|
||||
case 'N70/3SM (TRADE-IN)':
|
||||
case 'NS60/N40/1SN (TRADE-IN)':
|
||||
case 'OM100-12 VRLA':
|
||||
case 'OM150-12 VRLA':
|
||||
case 'OM17-12 VRLA':
|
||||
case 'OM4-6 VRLA':
|
||||
case 'OM70-12 VRLA':
|
||||
case 'OM7-12 VRLA':
|
||||
case '*SAME BATTERY*':
|
||||
case 'SM100 SOLARMASTER':
|
||||
case 'SM120 SOLARMASTER':
|
||||
case 'SM150 SOLARMASTER':
|
||||
case 'SM200 SOLARMASTER':
|
||||
case 'SM40 SOLARMASTER':
|
||||
case 'SM70 SOLARMASTER':
|
||||
case '*UNKNOWN BATTERY*':
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue