Add migration script and initial sql dump for customer and customer vehicle #52

This commit is contained in:
Kendrick Chan 2018-03-22 03:23:11 +08:00
parent 8435d0e832
commit 1e2df32443
8 changed files with 1084 additions and 31 deletions

View file

@ -11,5 +11,5 @@ return [
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
DataDog\AuditBundle\DataDogAuditBundle::class => ['all' => true],
// DataDog\AuditBundle\DataDogAuditBundle::class => ['all' => true],
];

View file

@ -0,0 +1,3 @@
load data local infile '/root/www/ramcar/data/customer_import.csv' into table customer fields terminated by '|' lines terminated by '\n';
load data local infile '/root/www/ramcar/data/cv_import.csv' into table customer_vehicle fields terminated by '|' lines terminated by '\n' (customer_id, vehicle_id, name, plate_number, model_year, status_condition, fuel_type, flag_motolite_battery, flag_active, color);

File diff suppressed because one or more lines are too long

View file

@ -15,28 +15,33 @@ use App\Entity\Customer;
use App\Entity\CustomerVehicle;
use App\Entity\Vehicle;
use App\Entity\VehicleManufacturer;
use App\Ramcar\FuelType;
use App\Ramcar\VehicleStatusCondition;
class ImportCustomerCommand extends Command
{
// field index in csv file
const F_ID = 0;
const F_TITLE = 1;
const F_FIRST_NAME = 2;
// role
// meh contact
const F_MOBILE_PHONE = 5;
const F_LANDLINE = 6;
const F_OFFICE_PHONE = 7;
const F_FAX = 8;
const F_EMAIL = 9;
const F_PLATE_NUMBER = 10;
const F_V_BRAND = 11;
const F_V_MAKE = 12;
const F_V_MODEL = 13;
const F_V_COLOR = 14;
const F_CUSTOMER_CLASS = 15;
const F_COMMENTS = 16;
const F_NOTES = 17;
const F_DATE_CREATED = 1;
const F_TITLE = 2;
const F_FIRST_NAME = 3;
const F_MIDDLE_NAME = 4;
const F_LAST_NAME = 5;
const F_ROLE = 6;
const F_MEH_CONTACT = 7;
const F_MOBILE_PHONE = 8;
const F_LANDLINE = 9;
const F_OFFICE_PHONE = 10;
const F_FAX = 11;
const F_EMAIL = 12;
const F_PLATE_NUMBER = 13;
const F_V_BRAND = 14;
const F_V_MAKE = 15;
const F_V_MODEL = 16;
const F_V_COLOR = 17;
const F_CUSTOMER_CLASS = 18;
const F_COMMENTS = 19;
const F_NOTES = 20;
protected $em;
@ -198,6 +203,9 @@ class ImportCustomerCommand extends Command
$em = $this->em;
$row_num = 1;
$save_counter = 0;
$cust_file = fopen('/root/www/ramcar/data/customer_import.csv', 'w');
$cv_file = fopen('/root/www/ramcar/data/cv_import.csv', 'w');
while (($fields = fgetcsv($fh)) !== false)
{
// $output->writeln("Parsing row " . $row_num . "...");
@ -211,17 +219,97 @@ class ImportCustomerCommand extends Command
$id = trim($fields[self::F_ID]);
$fname = trim($fields[self::F_FIRST_NAME]);
$lname = trim($fields[self::F_LAST_NAME]);
$title = trim($fields[self::F_TITLE]);
$plate_num = strtoupper(trim($fields[self::F_PLATE_NUMBER]));
$color = trim($fields[self::F_V_COLOR]);
// TODO: current csv has no last name yet
// $lname = trim($fields[self::F_LAST_NAME]);
$lname = "TEMP";
// NOTE: we have to export this to csv then load data infile
// because doctrine is eating up 100% cpu
/*
// customer
$cust = new Customer();
$cust->setTitle($title)
->setFirstName($fname)
->setLastName($lname)
->setCustomerNotes($fields[self::F_NOTES])
->setPhoneMobile($fields[self::F_MOBILE_PHONE])
->setPhoneLandline($fields[self::F_LANDLINE])
->setPhoneOffice($fields[self::F_OFFICE_PHONE])
->setPhoneFax($fields[self::F_FAX])
->setEmail($fields[self::F_EMAIL]);
$this->em->persist($cust);
*/
$cust_fields = [
$id,
$fname,
$lname,
0,
'',
0,
$title,
1,
$fields[self::F_MOBILE_PHONE],
$fields[self::F_LANDLINE],
$fields[self::F_OFFICE_PHONE],
$fields[self::F_FAX],
$fields[self::F_EMAIL],
$fields[self::F_NOTES]
];
$cust_row = str_replace('\\', '\\\\', implode('|', $cust_fields)) . "\n";
fputs($cust_file, $cust_row);
// $output->writeln($id . ' - ' . $fname . ' ' . $lname);
// get vehicle object
$vehicle = $this->findVehicle($output, $fields);
if ($vehicle != null)
{
/*
// customer vehicle
$cv = new CustomerVehicle();
$cv->setName('')
->setCustomer($cust)
->setVehicle($vehicle)
->setPlateNumber($plate_num)
->setModelYear(0)
->setColor($color)
->setStatusCondition(VehicleStatusCondition::BRAND_NEW)
->setFuelType(FuelTYpe::GAS)
->setHasMotoliteBattery(false);
$this->em->persist($cv);
*/
$cv_fields = [
$id,
$vehicle->getID(),
'',
$plate_num,
0,
VehicleStatusCondition::BRAND_NEW,
FuelType::GAS,
0,
1,
$color
];
$cv_row = str_replace('\\', '\\\\', implode('|', $cv_fields)) . "\n";
fputs($cv_file, $cv_row);
}
$row_num++;
/*
$save_counter++;
// flush every 100
if ($save_counter >= 100000)
{
$this->em->flush();
$save_counter = 0;
}
*/
}
fclose($cust_file);
fclose($cv_file);
}
}

View file

@ -127,7 +127,7 @@ class JobOrderController extends BaseController
// db loaded
$params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
$params['customers'] = $em->getRepository(Customer::class)->findAll();
// $params['customers'] = $em->getRepository(Customer::class)->findAll();
$params['promos'] = $em->getRepository(Promo::class)->findAll();
// name values

View file

@ -60,7 +60,7 @@ class Battery
// product code
/**
* @ORM\Column(type="string", length=80, unique=true)
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $prod_code;

View file

@ -24,7 +24,7 @@ class Customer
// title
/**
* @ORM\Column(type="string", length=10)
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $title;
@ -51,7 +51,7 @@ class Customer
protected $customer_classification;
/**
* @ORM\Column(type="text", length=80)
* @ORM\Column(type="text", length=65535)
*/
protected $customer_notes;
@ -63,25 +63,25 @@ class Customer
// mobile phone
/**
* @ORM\Column(type="text", length=12)
* @ORM\Column(type="string", length=30)
*/
protected $phone_mobile;
// landline
/**
* @ORM\Column(type="text", length=12)
* @ORM\Column(type="string", length=30)
*/
protected $phone_landline;
// office phone
/**
* @ORM\Column(type="text", length=12)
* @ORM\Column(type="string", length=30)
*/
protected $phone_office;
// fax
/**
* @ORM\Column(type="text", length=12)
* @ORM\Column(type="string", length=30)
*/
protected $phone_fax;

View file

@ -45,7 +45,7 @@ class CustomerVehicle
// plate number
/**
* @ORM\Column(type="string", length=10)
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank()
*/
protected $plate_number;
@ -59,7 +59,7 @@ class CustomerVehicle
// color of customer's vehicle
/**
* @ORM\Column(type="string", length=25)
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank()
*/
protected $color;
@ -116,6 +116,11 @@ class CustomerVehicle
*/
protected $flag_active;
public function __construct()
{
$this->flag_active = true;
}
public function getID()
{
return $this->id;