Resolve "Legacy JO Migration" #1047
2 changed files with 87 additions and 29 deletions
|
|
@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\Battery;
|
||||||
use App\Entity\BatterySize;
|
use App\Entity\BatterySize;
|
||||||
use App\Entity\BatteryModel;
|
use App\Entity\BatteryModel;
|
||||||
use App\Entity\VehicleManufacturer;
|
use App\Entity\VehicleManufacturer;
|
||||||
|
|
@ -31,6 +32,7 @@ use DateTime;
|
||||||
class ImportLegacyJobOrderCommand extends Command
|
class ImportLegacyJobOrderCommand extends Command
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $batt_hash;
|
||||||
protected $bmodel_hash;
|
protected $bmodel_hash;
|
||||||
protected $bsize_hash;
|
protected $bsize_hash;
|
||||||
protected $vmfg_hash;
|
protected $vmfg_hash;
|
||||||
|
|
@ -50,6 +52,7 @@ class ImportLegacyJobOrderCommand extends Command
|
||||||
$this->loadBatterySizes();
|
$this->loadBatterySizes();
|
||||||
$this->loadVehicleManufacturers();
|
$this->loadVehicleManufacturers();
|
||||||
$this->loadVehicles();
|
$this->loadVehicles();
|
||||||
|
$this->loadBatteries();
|
||||||
|
|
||||||
$this->jo_hash = [];
|
$this->jo_hash = [];
|
||||||
|
|
||||||
|
|
@ -312,7 +315,7 @@ class ImportLegacyJobOrderCommand extends Command
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if battery is found
|
// 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)
|
if (!$found_battery)
|
||||||
{
|
{
|
||||||
// $output->writeln('battery not found - ' . $fields[92]);
|
// $output->writeln('battery not found - ' . $fields[92]);
|
||||||
|
|
@ -399,7 +402,33 @@ class ImportLegacyJobOrderCommand extends Command
|
||||||
$line .= '\N,';
|
$line .= '\N,';
|
||||||
|
|
||||||
// date claim
|
// 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");
|
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()
|
protected function loadVehicleManufacturers()
|
||||||
{
|
{
|
||||||
$this->vmfg_hash = [];
|
$this->vmfg_hash = [];
|
||||||
|
|
@ -817,16 +865,16 @@ class ImportLegacyJobOrderCommand extends Command
|
||||||
return $clean_text;
|
return $clean_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findBattery($batt_field, &$batt_model, &$batt_size)
|
protected function findBattery($batt_field, &$batt_model, &$batt_size, &$sap_code)
|
||||||
{
|
{
|
||||||
// split battery into model and size
|
// split battery into model and size
|
||||||
// echo "trying match - " . $fields[92] . "\n";
|
// echo "trying match - " . $batt_field . "\n";
|
||||||
$res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches);
|
$res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $batt_field, $matches);
|
||||||
if (!$res)
|
if (!$res)
|
||||||
{
|
{
|
||||||
// echo "no match - " . $fields[92] . "\n";
|
//echo "no match - " . $fields[92] . "\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($matches[2] == '(Trade-In)')
|
if ($matches[2] == '(Trade-In)')
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -836,29 +884,35 @@ class ImportLegacyJobOrderCommand extends Command
|
||||||
|
|
||||||
// TODO: what to do about (Trade-In)
|
// TODO: what to do about (Trade-In)
|
||||||
|
|
||||||
// check if we have the size
|
// check if we have the size
|
||||||
$found_size = $this->simplifyName($matches[1]);
|
$found_size = $this->simplifyName($matches[1]);
|
||||||
if (!isset($this->bsize_hash[$found_size]))
|
if (!isset($this->bsize_hash[$found_size]))
|
||||||
{
|
{
|
||||||
// try legacy battery lookup
|
// try legacy battery lookup
|
||||||
$legacy_size = LegacyBattery::translate($found_size);
|
$legacy_size = LegacyBattery::translate($found_size);
|
||||||
if ($legacy_size == null)
|
if ($legacy_size == null)
|
||||||
{
|
{
|
||||||
// echo "no size - $found_size\n";
|
// echo "no size - $found_size\n";
|
||||||
if (isset($no_sizes[$found_size]))
|
if (isset($no_sizes[$found_size]))
|
||||||
$no_sizes[$found_size]++;
|
$no_sizes[$found_size]++;
|
||||||
else
|
else
|
||||||
$no_sizes[$found_size] = 1;
|
$no_sizes[$found_size] = 1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$found_size = $legacy_size;
|
$found_size = $legacy_size;
|
||||||
}
|
}
|
||||||
$batt_size = $this->bsize_hash[$found_size];
|
$batt_size = $this->bsize_hash[$found_size];
|
||||||
// $batt_size = $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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findVehicle($vmfg_field, $vmake_field, $vmodel_field, &$vehicle)
|
protected function findVehicle($vmfg_field, $vmake_field, $vmodel_field, &$vehicle)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
4
utils/legacy_load/import_legacy_data.sql
Normal file
4
utils/legacy_load/import_legacy_data.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
load data local infile '/tmp/plate_numbers.csv' into table plate_number fields terminated by ',';
|
||||||
|
load data infile '/tmp/legacy_jo_row.csv' into table legacy_job_order_row fields terminated by ',' enclosed by '"' lines terminated by '\n' (job_order_id, item, qty, price, price_level, status, account, enrollee) set id = null;
|
||||||
|
load data local infile '/tmp/warranty.csv' into table warranty fields terminated by ',' (bty_model_id, bty_size_id, serial, warranty_class, plate_number, status, date_create, date_purchase, date_expire, date_claim, claim_id, sap_bty_id, first_name, last_name, mobile_number) set id = null;
|
||||||
|
load data infile '/tmp/legacy_jo.csv' into table legacy_job_order fields terminated by '|' (id, trans_date, trans_type, origin, car_brand, car_make, car_model, car_color, cust_name, cust_first_name, cust_middle_name, cust_last_name, cust_contact, cust_mobile, cust_landline, delivery_instructions, agent_notes_1, delivery_date, delivery_time, advance_order, stage, cancel_reason, cancel_reason_specify, payment_method, prepared_by, dispatch_time, dispatch_date, dispatched_by, address, landmark, date_purchase, plate_number);
|
||||||
Loading…
Reference in a new issue