Add legacy battery to current battery translation #168
This commit is contained in:
parent
6031b6c367
commit
cdbc7897ca
2 changed files with 472 additions and 0 deletions
401
src/Command/ImportLegacyJobOrderCommand.php
Normal file
401
src/Command/ImportLegacyJobOrderCommand.php
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
use App\Entity\Warranty;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Entity\BatteryModel;
|
||||
|
||||
use App\Ramcar\LegacyBattery;
|
||||
|
||||
|
||||
class ImportLegacyJobOrderCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $bmodel_hash;
|
||||
protected $bsize_hash;
|
||||
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->em = $om;
|
||||
|
||||
$this->loadBatteryModels();
|
||||
$this->loadBatterySizes();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('legacy:import_jo')
|
||||
->setDescription('Import a CSV file with legacy job orders.')
|
||||
->setHelp('Updates job order, plate number and warranty database from imported CSV entries.')
|
||||
->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$csv_file = $input->getArgument('file');
|
||||
$output->writeln("parsing $csv_file...\n");
|
||||
|
||||
/*
|
||||
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:
|
||||
*/
|
||||
|
||||
// attempt to open file
|
||||
try
|
||||
{
|
||||
$fh = fopen($csv_file, "r");
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new Exception('The file "' . $csv_file . '" could be read.');
|
||||
}
|
||||
|
||||
// get entity manager
|
||||
$em = $this->em;
|
||||
|
||||
$trans_types = [];
|
||||
$service_types = [];
|
||||
$no_sizes = [];
|
||||
|
||||
// loop through rows
|
||||
$row_num = 0;
|
||||
while (($fields = fgetcsv($fh)) !== false)
|
||||
{
|
||||
$row_num++;
|
||||
// $output->writeln("Parsing row " . $row_num . "...");
|
||||
|
||||
// skip taxes
|
||||
if ($fields[14] == 'Bureau of Internal Revenue')
|
||||
{
|
||||
// $output->writeln('Skipping BIR line');
|
||||
continue;
|
||||
}
|
||||
|
||||
// ignore first 5 rows
|
||||
if ($row_num <= 5)
|
||||
continue;
|
||||
|
||||
// check column count
|
||||
if (count($fields) != 166)
|
||||
{
|
||||
echo "*** wrong field count on row $row_num\n";
|
||||
print_r($fields);
|
||||
exit;
|
||||
}
|
||||
|
||||
// split battery into model and size
|
||||
// echo "trying match - " . $fields[92] . "\n";
|
||||
$res = preg_match("/^(.+)(GOLD|EXCEL|ENDURO|\(Trade-In\))/", $fields[92], $matches);
|
||||
if (!$res)
|
||||
{
|
||||
// echo "no match - " . $fields[92] . "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
continue;
|
||||
}
|
||||
|
||||
$found_size = $legacy_size;
|
||||
}
|
||||
|
||||
|
||||
// let's track purchases first
|
||||
if ($fields[5] != 'PURCHASE')
|
||||
continue;
|
||||
|
||||
// consolidate transaction and service types
|
||||
$trans_types[$fields[5]] = 1;
|
||||
$service_types[$fields[7]] = $fields[5];
|
||||
|
||||
// clean plate numbers
|
||||
$plate_num = Warranty::cleanPlateNumber($fields[14]);
|
||||
if (!$plate_num)
|
||||
{
|
||||
$output->writeln('Invalid plate number - ' . $fields[14]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// plate
|
||||
echo '14 - ' . $fields[14] . "\n";
|
||||
|
||||
// transaction
|
||||
echo '5 - ' . $fields[5] . "\n";
|
||||
echo '7 - ' . $fields[7] . "\n";
|
||||
|
||||
// name
|
||||
echo '22 - ' . $fields[22] . "\n";
|
||||
echo '20 - ' . $fields[20] . "\n";
|
||||
echo '21 - ' . $fields[21] . "\n";
|
||||
|
||||
// number
|
||||
echo '23 - ' . $fields[23] . "\n";
|
||||
echo '24 - ' . $fields[24] . "\n";
|
||||
echo '25 - ' . $fields[25] . "\n";
|
||||
|
||||
// vehicle
|
||||
echo '15 - ' . $fields[15] . "\n";
|
||||
echo '16 - ' . $fields[16] . "\n";
|
||||
echo '17 - ' . $fields[17] . "\n";
|
||||
echo '18 - ' . $fields[18] . "\n";
|
||||
|
||||
|
||||
// battery
|
||||
echo '10 - ' . $fields[10] . "\n";
|
||||
echo '11 - ' . $fields[11] . "\n";
|
||||
echo '50 - ' . $fields[50] . "\n";
|
||||
echo '51 - ' . $fields[51] . "\n";
|
||||
echo '40 - ' . $fields[40] . "\n";
|
||||
echo '43 - ' . $fields[43] . "\n";
|
||||
echo '44 - ' . $fields[44] . "\n";
|
||||
echo '47 - ' . $fields[47] . "\n";
|
||||
echo '54 - ' . $fields[54] . "\n";
|
||||
|
||||
// customer service record
|
||||
echo '84 - ' . $fields[84] . "\n";
|
||||
echo '85 - ' . $fields[85] . "\n";
|
||||
echo '86 - ' . $fields[86] . "\n";
|
||||
echo '87 - ' . $fields[87] . "\n";
|
||||
*/
|
||||
// echo '92 - ' . $fields[92] . "\n";
|
||||
|
||||
/*
|
||||
echo '110 - ' . $fields[110] . "\n";
|
||||
*/
|
||||
}
|
||||
|
||||
// print_r($trans_types);
|
||||
// print_r($service_types);
|
||||
print_r($no_sizes);
|
||||
// print_r($b_models);
|
||||
// print_r($batteries);
|
||||
|
||||
// save to db
|
||||
// print_r($batteries);
|
||||
}
|
||||
|
||||
protected function loadBatteryModels()
|
||||
{
|
||||
$this->bmodel_hash = [];
|
||||
|
||||
$models = $this->em->getRepository(BatteryModel::class)->findAll();
|
||||
foreach ($models as $model)
|
||||
{
|
||||
// clean name
|
||||
// $name = strtoupper(trim(str_replace(' ', '', $model->getName())));
|
||||
$name = $this->simplifyName($model->getName());
|
||||
|
||||
$this->bmodel_hash[$name] = $model->getID();
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadBatterySizes()
|
||||
{
|
||||
$this->bsize_hash = [];
|
||||
|
||||
$sizes = $this->em->getRepository(BatterySize::class)->findAll();
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
// clean name
|
||||
// $name = strtoupper(trim(str_replace(' ', '', $size->getName())));
|
||||
$name = $this->simplifyName($size->getName());
|
||||
|
||||
$this->bsize_hash[$name] = $size->getID();
|
||||
}
|
||||
}
|
||||
|
||||
protected function simplifyName($text)
|
||||
{
|
||||
return strtoupper(trim(str_replace(' ', '', $text)));
|
||||
}
|
||||
}
|
||||
71
src/Ramcar/LegacyBattery.php
Normal file
71
src/Ramcar/LegacyBattery.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
|
||||
class LegacyBattery
|
||||
{
|
||||
static public function translate($id)
|
||||
{
|
||||
switch($id)
|
||||
{
|
||||
case '1SM/NS50/D23L':
|
||||
return '1SM/D23/NS50';
|
||||
case '1SM/NS50/D23R':
|
||||
return '1SM/D23/NS50/R';
|
||||
case '1SM/NS50XL/D23L':
|
||||
return '1SM/D23/NS50';
|
||||
case '2HN/NS60ARS/B24RS':
|
||||
return 'B24/NS60/R';
|
||||
case '2HN/NS60/B24L':
|
||||
return 'B24/NS60';
|
||||
case '2SM/MG50/D26L':
|
||||
return '2SM/D26/N50';
|
||||
case '2SM/MG50/D26R':
|
||||
return '2SM/D26/N50/R';
|
||||
case '2SM/N50/D26L':
|
||||
return '2SM/D26/N50';
|
||||
case '2SM/N50XL/D26L':
|
||||
return '2SM/D26/N50';
|
||||
case '3SM/MG70/D31L':
|
||||
return '3SM/D31/N70';
|
||||
case '3SM/MG70/D31R':
|
||||
return '3SM/D31/N70/R';
|
||||
case '3SM/N70/D31L':
|
||||
return '3SM/D31/N70';
|
||||
case '3SM/N70XL/D31L':
|
||||
return '3SM/D31/N70';
|
||||
case '4SN/NS40/B20L':
|
||||
// return 'NS40/B20';
|
||||
return 'B20/NS40';
|
||||
case '4SN/NS40R/B20R':
|
||||
return 'B20/NS40/R';
|
||||
case 'DIN55R':
|
||||
return 'DIN55/R';
|
||||
case 'DIN66R':
|
||||
return 'DIN66/R';
|
||||
case 'GROUP34/78':
|
||||
return 'G34';
|
||||
case 'GROUP65':
|
||||
return 'G65';
|
||||
case 'N100/6SM':
|
||||
case 'N120/2D':
|
||||
case 'N150/4D':
|
||||
case 'N200/8D':
|
||||
return null;
|
||||
case 'N50/2SM':
|
||||
return '2SM/D26/N50';
|
||||
case 'N70/3SM':
|
||||
return '3SM/D31/N70';
|
||||
case 'NS40':
|
||||
return 'B20/NS40';
|
||||
case 'NS50/1SM':
|
||||
return '1SM/D23/NS50';
|
||||
case 'NS60/N40/1SN':
|
||||
return 'B24/NS60';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue