Merge branch '202-legacy-jo-migration' into 'master'

Resolve "Legacy JO Migration"

Closes #202

See merge request jankstudio/resq!236
This commit is contained in:
Kendrick Chan 2019-04-09 14:52:03 +00:00
commit 2a469dd469
2 changed files with 87 additions and 29 deletions

View file

@ -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)
{

View 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);