Add the customer name, mobile, and sap battery fields to the warranty csv file. #202
This commit is contained in:
parent
2c5b0b250c
commit
e39289bb54
1 changed files with 83 additions and 29 deletions
|
|
@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
use App\Entity\Warranty;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Entity\BatteryModel;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
|
|
@ -31,6 +32,7 @@ use DateTime;
|
|||
class ImportLegacyJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $batt_hash;
|
||||
protected $bmodel_hash;
|
||||
protected $bsize_hash;
|
||||
protected $vmfg_hash;
|
||||
|
|
@ -50,6 +52,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$this->loadBatterySizes();
|
||||
$this->loadVehicleManufacturers();
|
||||
$this->loadVehicles();
|
||||
$this->loadBatteries();
|
||||
|
||||
$this->jo_hash = [];
|
||||
|
||||
|
|
@ -312,7 +315,7 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
continue;
|
||||
|
||||
// check if battery is found
|
||||
$found_battery = $this->findBattery($fields[92], $batt_model, $batt_size);
|
||||
$found_battery = $this->findBattery($fields[92], $batt_model, $batt_size, $sap_code);
|
||||
if (!$found_battery)
|
||||
{
|
||||
// $output->writeln('battery not found - ' . $fields[92]);
|
||||
|
|
@ -399,7 +402,33 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
$line .= '\N,';
|
||||
|
||||
// date claim
|
||||
$line .= '\N';
|
||||
$line .= '\N,';
|
||||
|
||||
// claim id
|
||||
$line .= '\N,';
|
||||
|
||||
// sap battery id
|
||||
if (isset($sap_code))
|
||||
$line .= $sap_code . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
// first name
|
||||
if (isset($fields[20]) && strlen(trim($fields[20])) > 0)
|
||||
$line .= $fields[20] . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// last name
|
||||
if (isset($fields[22]) && strlen(trim($fields[22])) > 0)
|
||||
$line .= $fields[22] . ',';
|
||||
else
|
||||
$line .= '\N,';
|
||||
|
||||
// mobile number
|
||||
if (isset($fields[24]) && strlen(trim($fields[24])) > 0)
|
||||
$line .= $fields[24] . ',';
|
||||
else
|
||||
$line .= '\N';
|
||||
|
||||
fwrite($warr_outfile, $line . "\n");
|
||||
}
|
||||
|
|
@ -769,6 +798,25 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
}
|
||||
}
|
||||
|
||||
protected function loadBatteries()
|
||||
{
|
||||
$this->batt_hash = [];
|
||||
|
||||
$batts = $this->em->getRepository(Battery::class)->findAll();
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
if (($batt->getModel() == null) or ($batt->getSize() == null) or ($batt->getSAPCode() == null))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$model_id = $batt->getModel()->getID();
|
||||
$size_id = $batt->getSize()->getID();
|
||||
|
||||
$this->batt_hash[$model_id][$size_id] = $batt->getSAPCode();
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadVehicleManufacturers()
|
||||
{
|
||||
$this->vmfg_hash = [];
|
||||
|
|
@ -817,16 +865,16 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
return $clean_text;
|
||||
}
|
||||
|
||||
protected function findBattery($batt_field, &$batt_model, &$batt_size)
|
||||
{
|
||||
// split battery into model and size
|
||||
// echo "trying match - " . $fields[92] . "\n";
|
||||
$res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches);
|
||||
if (!$res)
|
||||
{
|
||||
// echo "no match - " . $fields[92] . "\n";
|
||||
protected function findBattery($batt_field, &$batt_model, &$batt_size, &$sap_code)
|
||||
{
|
||||
// split battery into model and size
|
||||
// echo "trying match - " . $batt_field . "\n";
|
||||
$res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches);
|
||||
if (!$res)
|
||||
{
|
||||
//echo "no match - " . $fields[92] . "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($matches[2] == '(Trade-In)')
|
||||
return false;
|
||||
|
|
@ -836,29 +884,35 @@ class ImportLegacyJobOrderCommand extends Command
|
|||
|
||||
// TODO: what to do about (Trade-In)
|
||||
|
||||
// check if we have the size
|
||||
$found_size = $this->simplifyName($matches[1]);
|
||||
if (!isset($this->bsize_hash[$found_size]))
|
||||
{
|
||||
// try legacy battery lookup
|
||||
$legacy_size = LegacyBattery::translate($found_size);
|
||||
if ($legacy_size == null)
|
||||
{
|
||||
// echo "no size - $found_size\n";
|
||||
if (isset($no_sizes[$found_size]))
|
||||
$no_sizes[$found_size]++;
|
||||
else
|
||||
$no_sizes[$found_size] = 1;
|
||||
return false;
|
||||
}
|
||||
// check if we have the size
|
||||
$found_size = $this->simplifyName($matches[1]);
|
||||
if (!isset($this->bsize_hash[$found_size]))
|
||||
{
|
||||
// try legacy battery lookup
|
||||
$legacy_size = LegacyBattery::translate($found_size);
|
||||
if ($legacy_size == null)
|
||||
{
|
||||
// echo "no size - $found_size\n";
|
||||
if (isset($no_sizes[$found_size]))
|
||||
$no_sizes[$found_size]++;
|
||||
else
|
||||
$no_sizes[$found_size] = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$found_size = $legacy_size;
|
||||
}
|
||||
$found_size = $legacy_size;
|
||||
}
|
||||
$batt_size = $this->bsize_hash[$found_size];
|
||||
// $batt_size = $found_size;
|
||||
|
||||
//get battery using ids of batt_model and batt_size
|
||||
if (!isset($this->batt_hash[$batt_model][$batt_size]))
|
||||
return false;
|
||||
|
||||
$sap_code = $this->batt_hash[$batt_model][$batt_size];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function findVehicle($vmfg_field, $vmake_field, $vmodel_field, &$vehicle)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue