164 lines
5.8 KiB
PHP
164 lines
5.8 KiB
PHP
<?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\ORM\EntityManagerInterface;
|
|
|
|
use App\Entity\CMBLegacyJobOrderRow;
|
|
|
|
class ImportCMBLegacyJobOrderCommand extends Command
|
|
{
|
|
// field index in csv file
|
|
const F_INDEX = 0;
|
|
const F_CREATED_DATE = 1;
|
|
const F_CASE_NO = 2;
|
|
const F_INSURER = 3;
|
|
const F_VEHICLE_NO = 4;
|
|
const F_CAR_MODEL = 5;
|
|
const F_NATURE_OF_CALL = 6;
|
|
const F_SERVICE_NEEDED = 7;
|
|
const F_LOCATION = 8;
|
|
const F_STATE = 9;
|
|
const F_DRIVER = 10;
|
|
const F_TRUCK = 11;
|
|
const F_WORKSHOP_ARRIVAL_TIME = 12;
|
|
const F_STATUS = 13;
|
|
const F_CUSTOMER_NAME = 14;
|
|
const F_CUSTOMER_PHONE_NO = 15;
|
|
const F_OUR_REFERENCE = 16;
|
|
const F_ODOMETER = 17;
|
|
const F_BATT_MODEL = 18;
|
|
const F_BATT_SIZE = 19;
|
|
const F_BATT_TRADE_IN = 20;
|
|
const F_REPLACED_BY = 21;
|
|
const F_REMARK = 22;
|
|
const F_SATISFACTION = 23;
|
|
|
|
protected $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
public function configure()
|
|
{
|
|
$this->setName('cmblegacyjoborderdata:import')
|
|
->setDescription('Retrieve from a CSV file CarFix data.')
|
|
->setHelp('Creates legacy job order entries based on data from imported CSV.')
|
|
->addArgument('file', InputArgument::REQUIRED, 'Path to the CSV file.');
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$csv_file = $input->getArgument('file');
|
|
|
|
// 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;
|
|
|
|
$row_num = 0;
|
|
error_log('Processing CarFix data csv file...');
|
|
while (($fields = fgetcsv($fh)) !== false)
|
|
{
|
|
if ($row_num < 1)
|
|
{
|
|
$row_num++;
|
|
continue;
|
|
}
|
|
|
|
// get the information
|
|
$entry_num = trim($fields[self::F_INDEX]);
|
|
$date_create = trim($fields[self::F_CREATED_DATE]);
|
|
$case_number = trim($fields[self::F_CASE_NO]);
|
|
$insurer = trim($fields[self::F_INSURER]);
|
|
$vehicle_number = trim($fields[self::F_VEHICLE_NO]);
|
|
$car_model = trim($fields[self::F_CAR_MODEL]);
|
|
$nature_of_call = trim($fields[self::F_NATURE_OF_CALL]);
|
|
$service_needed = trim($fields[self::F_SERVICE_NEEDED]);
|
|
$location = trim($fields[self::F_LOCATION]);
|
|
$state = trim($fields[self::F_STATE]);
|
|
$driver = trim($fields[self::F_DRIVER]);
|
|
$truck = trim($fields[self::F_TRUCK]);
|
|
$workshop_arrival_time = trim($fields[self::F_WORKSHOP_ARRIVAL_TIME]);
|
|
$status = trim($fields[self::F_STATUS]);
|
|
$customer_name = trim($fields[self::F_CUSTOMER_NAME]);
|
|
$customer_mobile = trim($fields[self::F_CUSTOMER_PHONE_NO]);
|
|
$reference = trim($fields[self::F_OUR_REFERENCE]);
|
|
$odometer = trim($fields[self::F_ODOMETER]);
|
|
$batt_model = trim($fields[self::F_BATT_MODEL]);
|
|
$batt_size = trim($fields[self::F_BATT_SIZE]);
|
|
$trade_in = trim($fields[self::F_BATT_TRADE_IN]);
|
|
$replaced_by = trim($fields[self::F_REPLACED_BY]);
|
|
$remark = trim($fields[self::F_REMARK]);
|
|
$satisfaction = trim($fields[self::F_SATISFACTION]);
|
|
|
|
$data_entry = $this->processEntry($entry_num, $date_create, $case_number, $insurer, $vehicle_number, $car_model,
|
|
$nature_of_call, $service_needed, $location, $state, $driver, $truck, $workshop_arrival_time,
|
|
$status, $customer_name, $customer_mobile, $reference, $odometer, $batt_model, $batt_size,
|
|
$trade_in, $replaced_by, $remark, $satisfaction);
|
|
|
|
$legacy_data = new CMBLegacyJobOrderRow();
|
|
$legacy_data->setData($data_entry);
|
|
|
|
$this->em->persist($legacy_data);
|
|
}
|
|
|
|
$this->em->flush();
|
|
$this->em->clear();
|
|
|
|
return 0;
|
|
}
|
|
|
|
protected function processEntry($entry_num, $date_create, $case_number, $insurer, $vehicle_number, $car_model,
|
|
$nature_of_call, $service_needed, $location, $state, $driver, $truck, $workshop_arrival_time,
|
|
$status, $customer_name, $customer_mobile, $reference, $odometer, $batt_model, $batt_size,
|
|
$trade_in, $replaced_by, $remark, $satisfaction)
|
|
{
|
|
$data_entry = [
|
|
'entry_num' => $entry_num,
|
|
'created_date' => $date_create,
|
|
'case_number' => $case_number,
|
|
'insurer' => $insurer,
|
|
'vehicle_number' => $vehicle_number,
|
|
'car_model' => $car_model,
|
|
'nature_of_call' => $nature_of_call,
|
|
'service_needed' => $service_needed,
|
|
'location' => $location,
|
|
'state' => $state,
|
|
'driver' => $driver,
|
|
'truck' => $truck,
|
|
'workshop_arrival_time' => $workshop_arrival_time,
|
|
'status' => $status,
|
|
'customer_name' => $customer_name,
|
|
'customer_phone_number' => $customer_mobile,
|
|
'reference' => $reference,
|
|
'odometer' => $odometer,
|
|
'batt_model' => $batt_model,
|
|
'batt_size' => $batt_size,
|
|
'batt_trade_in' => $trade_in,
|
|
'replaced_by' => $replaced_by,
|
|
'remark' => $remark,
|
|
'satisfaction' => $satisfaction,
|
|
];
|
|
|
|
return $data_entry;
|
|
}
|
|
|
|
}
|