From d39d554ba1a314e11ece3cbf08c5e7097e1a3225 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Thu, 3 Jan 2019 05:51:33 +0800 Subject: [PATCH] Add warranty migration for legacy data #168 --- src/Command/ImportLegacyJobOrderCommand.php | 94 ++++++- src/Entity/LegacyJobOrder.php | 262 ++++++++++++++++++++ src/Entity/PlateNumber.php | 3 - src/Entity/Warranty.php | 6 +- src/Ramcar/WarrantyClass.php | 21 ++ 5 files changed, 375 insertions(+), 11 deletions(-) create mode 100644 src/Entity/LegacyJobOrder.php diff --git a/src/Command/ImportLegacyJobOrderCommand.php b/src/Command/ImportLegacyJobOrderCommand.php index 34715623..07a300cb 100644 --- a/src/Command/ImportLegacyJobOrderCommand.php +++ b/src/Command/ImportLegacyJobOrderCommand.php @@ -19,6 +19,10 @@ use App\Entity\PlateNumber; use App\Ramcar\LegacyBattery; use App\Ramcar\LegacyVehicleManufacturer; use App\Ramcar\LegacyVehicle; +use App\Ramcar\WarrantyClass; +use App\Ramcar\WarrantyStatus; + +use DateTime; class ImportLegacyJobOrderCommand extends Command @@ -241,7 +245,8 @@ class ImportLegacyJobOrderCommand extends Command $service_types = []; $no_sizes = []; - $outfile = fopen('/tmp/plate_numbers.csv', 'a'); + $plate_outfile = fopen('/tmp/plate_numbers.csv', 'a'); + $warr_outfile = fopen('/tmp/warranty.csv', 'a'); // loop through rows $save_plates = []; @@ -302,7 +307,79 @@ class ImportLegacyJobOrderCommand extends Command continue; } - fwrite($outfile, $plate_num . ',' . $vehicle['id'] . "\n"); + fwrite($plate_outfile, $plate_num . ',' . $vehicle['id'] . "\n"); + + 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"); + } + } /* // check if we marked it already @@ -389,7 +466,8 @@ class ImportLegacyJobOrderCommand extends Command // print_r($this->vehicle_hash); // print_r($no_makes); - fclose($outfile); + fclose($plate_outfile); + fclose($warr_outfile); } protected function loadBatteryModels() @@ -480,7 +558,12 @@ class ImportLegacyJobOrderCommand extends Command // echo "no match - " . $fields[92] . "\n"; return false; } - $batt_model = $matches[2]; + + if ($matches[2] == '(Trade-In)') + return false; + + $batt_model = $this->bmodel_hash[$matches[2]]; + // $batt_model = $matches[2]; // TODO: what to do about (Trade-In) @@ -502,7 +585,8 @@ class ImportLegacyJobOrderCommand extends Command $found_size = $legacy_size; } - $batt_size = $found_size; + $batt_size = $this->bsize_hash[$found_size]; + // $batt_size = $found_size; return true; } diff --git a/src/Entity/LegacyJobOrder.php b/src/Entity/LegacyJobOrder.php new file mode 100644 index 00000000..d9143352 --- /dev/null +++ b/src/Entity/LegacyJobOrder.php @@ -0,0 +1,262 @@ +id = $id; + return $this; + } + + public function getID() + { + return $this->id; + } +} diff --git a/src/Entity/PlateNumber.php b/src/Entity/PlateNumber.php index 97047383..fb543772 100644 --- a/src/Entity/PlateNumber.php +++ b/src/Entity/PlateNumber.php @@ -25,9 +25,6 @@ class PlateNumber */ protected $vehicle; - // the batteries under this plate number - protected $batteries; - public function setID($id) { $this->id = $id; diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 6ea1f0cb..480e7251 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -29,7 +29,7 @@ class Warranty // serial number /** - * @ORM\Column(type="string", length=50) + * @ORM\Column(type="string", length=50, nullable=true) */ protected $serial; @@ -41,7 +41,7 @@ class Warranty // plate /** - * @ORM\Column(type="string", length=10) + * @ORM\Column(type="string", length=20) */ protected $plate_number; @@ -79,7 +79,7 @@ class Warranty // date expires /** - * @ORM\Column(type="date") + * @ORM\Column(type="date", nullable=true) */ protected $date_expire; diff --git a/src/Ramcar/WarrantyClass.php b/src/Ramcar/WarrantyClass.php index 992ee1c6..8c7b1be1 100644 --- a/src/Ramcar/WarrantyClass.php +++ b/src/Ramcar/WarrantyClass.php @@ -13,4 +13,25 @@ class WarrantyClass extends NameValue 'commercial' => 'Commercial', 'tnv' => 'TNV', ]; + + public static function convertFromLegacy($legacy_wclass) + { + switch($legacy_wclass) + { + case '1YEAR': + case '1YR': + case 'Old Private': + case 'PRIAVTE': + case 'PRIVATE': + return self::WTY_PRIVATE; + + case 'COMMERCIAL': + return self::WTY_COMMERCIAL; + + case 'GRAB': + return self::WTY_TNV; + } + + return false; + } }