Add warranty migration for legacy data #168

This commit is contained in:
Kendrick Chan 2019-01-03 05:51:33 +08:00
parent 1f0060d6c5
commit d39d554ba1
5 changed files with 375 additions and 11 deletions

View file

@ -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;
}

View file

@ -0,0 +1,262 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
/*
CSV column order:
0 - Internal ID
1 - Type
2 - Transaction Number
3 - Primary Information : Date of Transaction
4 - Primary Information : Job Order Number
5 - Primary Information : MEH : Transaction Type
6 - Primary Information : Reference JO Number
7 - Primary Information : Type of Service
8 - Primary Information : Warranty Status
9 - Primary Information : Transaction Origin
10 - Primary Information : Existing Battery
11 - Primary Information : Existing Battery Type
12 - Primary Information : Recommended Battery
13 - Primary Infromation : Alternative Battery
14 - Primary Information : Vehicle Plate Number
15 - Primary Information : Brand
16 - Primary Information : Make
17 - Primary Information : Model
18 - Primary Information : Vehicle Color
19 - Primary Information : Caller Name
20 - First Name
21 - Middle Name
22 - Last Name
23 - Primary Information : Caller Contact
24 - Primary Information : Caller Mobile No.
25 - Primary Information : Caller Landline No.
26 - Primary Information : Invoice / Company Name
27 - Primary Information : New Name?
28 - Primary Information : New Invoice / Company Name
29 - Primary Information : Delivery Instructions
30 - Primary Information : Agent Notes - Tier 1
31 - Primary Information : Delivery Date
32 - Primary Information : Delivery Time
33 - Primary Information : Advance Order
34 - Primary Information : Stages
35 - Primary Information : Reason for Cancellation
36 - Primary Information : Specify the Reason for Cancellation
37 - Primary Information : Payment Method
38 - Primary Information : Change for:
39 - Primary Information : Prepared by
40 - Current Battery Details : Serial No.:
41 - Current Battery Details : DR No.:
42 - Current Battery Details : Date of Replacement
43 - Current Battery Details : Battery Brand
44 - Current Battery Details : Type
45 - Current Battery Details : Issued By:
46 - Current Battery Details : Issued By Direct
47 - Original Battery Details : Serial No.
48 - Original Battery Details : OR No.:
49 - Original Battery Details : Date of Purchase
50 - Original Battery Details : Battery Brand:
51 - Original Battery Details : Battery Type:
52 - Original Battery Details : Purchased From:
53 - Original Battery Details : Purchase from Direct
54 - Original Battery Details : Current Warranty Expiration Date
55 - Original Battery Details : Trade-In Battery
56 - Dispatching : Agent Notes : Tier 2
57 - Dispatching : Notes (Customer Classification)
58 - Dispatching : Pending
59 - Dispatching : Pending - Awaiting Stocks
60 - Dispatching : Date started from Awaiting Stock
61 - Dispatching : 4TH Due
62 - Dispatching : 8TH Due
63 - Dispatching : 12TH Due
64 - Dispatching : 14TH Due
65 - Dispatching : Currently Assigned Enrollee
66 - Dispatching : Non-HUB?
67 - Dispatching : HUB Catered?
68 - Dispatching : Thru Annex?
69 - Dispatching : HUB List
70 - Dispatching : Annex List
71 - Dispatching : Exempted to 6%
72 - Dispatching : Rider Name List
73 - Dispatching : Rider Name
74 - Dispatching : Rider Contact Information
75 - DIspatching : Dispatch Time
76 - Dispatching : Dispatch Date
77 - Dispatching : Dispatched By
78 - Dispatching : Time of Arrival
79 - Dispatching : Time Job Completed
80 - Dispatching : For Line Up?
81 - DIspatching : Order
82 - Vehicle Location : Address
83 - Vehicle Location : Landmark
84 - Customer Service Record : Purchase Date
85 - Customer Service Record : Battery / Item
86 - Customer Service Record : Battery / Item Warranty in Months
87 - Customer Service Record : Warranty Inquiry (Expiration Date)
88 - JO : Amount
89 - JO : TAX
90 - JO : Discount
91 - JO : Final Amount
92 - Line Details : Item
93 - Line Details : Quantity
94 - Line Details : Item Rate
95 - Line Details : Price Level
96 - Line Details : Item Base Price
97 - Line Details : Price Level Amount Deductions
98 - Line Details : Final Amount
99 - Line Details : No Trade-In
100 - Line Details : Reason for No Trade-In
101 - Line Details : Battery Class
102 - Line Details : Discount Items
103 - Line Details : Discount Code
104 - Line Details : Percentage
105 - Line Details : Converted Rate
106 - Line Details : Discount Amount
107 - Line Details : Warranty Classification
108 - Line Details : Warranty in Months
109 - Line Details : Warranty Expiration Date
110 - Line Details : Serial Number
111 - Line Details : Invoice/DR Number
112 - Line Details : Repalcement
113 - Line Details : Employee / Card No. / Referred by
114 - Line Details : Amount
115 - Line Details : Gross Amount
116 - Line Details : Gross Amount
117 - Time Stamp : Date / Time (JO Open)
118 - Time Stamp : Date / Time JO Saved
119 - Time Stamp : Ticket Handle TIme (in mins)
120 - Time Stamp : Idle Time
121 - Time Stamp : Date and Time (Dispatched By)
122 - Time Stamp : In-Transit Date and Time
123 - TIme Stamp : Completion Date and TIme
124 - TIme Stamp : Dispatch By to In-Transit Time (Time difference in Mins)
125 - Time Stamp : In-Transit to Completed (Time difference in Mins)
126 - Time Stamp : Raw Ticket Handle TIme (Decimal)
127 - Time Stamp : Raw Idle Time (Decimal)
128 - Account
129 - Status
130 - Tracking Numbers
131 - Memo
132 - Posting
133 - Notes
134 - Originally Assigned Enrollee
135 - Remarks
136 - Follow Up Transactions
137 - CARD TYPE
138 - CARD NO.
139 - Ongoing Editing
140 - Current User
141 - Cancellation Date
142 - Cancellation Time
143 - Ticket Completion Date
144 - Ticket Completion Time
145 - Date Created
146 - Time Created
147 - PREVIOUS STAGE
148 - DISPATCHED BY EDITED?
149 - Previous Dispatched By
150 - POST SERVICE
151 - Pending (2)
152 - COMPLETED MANUALLY
153 - THRU HUB NOTE
154 - CURRENTLY ASSIGNED ENROLLEE (free-form)
155 - IN-TRANSIT ALLOWANCE
156 - COPY FROM JO #
157 - NO. OF POSSIBLE DUPLICATE
158 - Call Status
159 - DISTRIBUTOR OUTLETS
160 - CURRENTLY ASSIGNED ENROLLEE (free-form)
161 - HUB LIST
162 - HUB LIST 2
163 - Enrollee
164 - Currently Assigned Enrollee
165 - Payment:
*/
/**
* @ORM\Entity
* @ORM\Table(name="legacy_job_order")
*/
class LegacyJobOrder
{
// legacy internal id
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $id;
protected $data;
/*
protected $type;
protected $trans_num;
protected $trans_date;
protected $jo_num;
protected $meh_trans_type;
protected $ref_jo_num;
protected $service_type;
protected $warr_status;
protected $trans_origin;
protected $exist_batt;
protected $exist_batt_type;
protected $reco_batt;
protected $alt_batt;
protected $car_plate_num;
protected $car_brand;
protected $car_make;
protected $car_model;
protected $car_color;
protected $cust_name;
protected $cust_first_name;
protected $cust_middle_name;
protected $cust_last_name;
protected $cust_contact_num;
protected $cust_mobile_num;
protected $cust_landline_num;
protected $invoice_name;
protected $new_name;
protected $new_invoice_name;
protected $delivery_instructions;
protected $agent_notes;
protected $del_date;
protected $del_time;
protected $advance_order;
protected $stage;
protected $cancel_reason;
protected $specify_reason;
protected $payment_method;
protected $change_for;
protected $perpared_by;
protected $curr_batt_serial;
protected $curr_batt_dr_num;
protected $curr_batt_date_replace;
protected $curr_batt_brand;
protected $curr_batt_type;
protected $curr_batt_issued_by;
protected $curr_batt_issued_direct;
protected $orig_batt_serial;
protected $orig_batt_or_num;
protected $orig_batt_date_purchase;
protected $orig_batt_brand;
protected $orig_batt_type;
protected $orig_batt_pur_from;
protected $orig_batt_pur_from_direct;
protected $orig_batt_warr_expire_date;
protected $orig_trade_in_batt;
*/
public function setID($id)
{
$this->id = $id;
return $this;
}
public function getID()
{
return $this->id;
}
}

View file

@ -25,9 +25,6 @@ class PlateNumber
*/
protected $vehicle;
// the batteries under this plate number
protected $batteries;
public function setID($id)
{
$this->id = $id;

View file

@ -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;

View file

@ -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;
}
}