Have warranty create customer and add customer create source field #540
This commit is contained in:
parent
3e9ae5df35
commit
ea06d922bb
3 changed files with 79 additions and 40 deletions
|
|
@ -162,6 +162,19 @@ class CustomerWarrantyController extends APIController
|
|||
$vmake_id = null;
|
||||
}
|
||||
|
||||
// customer
|
||||
$cust = $warr->getCustomer();
|
||||
if ($cust != null)
|
||||
{
|
||||
$cust_exists = true;
|
||||
$priv_promo = $cust->getPrivacyPromo();
|
||||
}
|
||||
else
|
||||
{
|
||||
$cust_exists = false;
|
||||
$priv_promo = false;
|
||||
}
|
||||
|
||||
$customer = [
|
||||
'first_name' => $warr->getFirstName(),
|
||||
'last_name' => $warr->getLastName(),
|
||||
|
|
@ -170,6 +183,8 @@ class CustomerWarrantyController extends APIController
|
|||
'email' => $warr->getEmail(),
|
||||
'contact_num' => $warr->getContactNumber(),
|
||||
'address' => $warr->getCustomerAddress(),
|
||||
'priv_promo' => $priv_promo,
|
||||
'exists' => $cust_exists,
|
||||
];
|
||||
$other_data = [
|
||||
'odometer' => $warr->getOdometer(),
|
||||
|
|
@ -193,6 +208,8 @@ class CustomerWarrantyController extends APIController
|
|||
'email' => '',
|
||||
'contact_num' => '',
|
||||
'address' => '',
|
||||
'priv_promo' => false,
|
||||
'exists' => false,
|
||||
];
|
||||
$other_data = [
|
||||
'odometer' => 0,
|
||||
|
|
@ -262,16 +279,6 @@ class CustomerWarrantyController extends APIController
|
|||
if (!$res)
|
||||
return $res;
|
||||
|
||||
|
||||
/*
|
||||
$first_name = $req->request->get('first_name');
|
||||
$last_name = $req->request->get('last_name');
|
||||
$email = $req->request->get('email');
|
||||
$plate_num = $req->request->get('plate_num');
|
||||
$odometer = $req->request->get('odometer');
|
||||
$date_purchase = $req->request->get('date_purchase');
|
||||
*/
|
||||
|
||||
// file uploads
|
||||
$invoice = $req->files->get('invoice');
|
||||
$warr_card = $req->files->get('warr_card');
|
||||
|
|
@ -282,22 +289,6 @@ class CustomerWarrantyController extends APIController
|
|||
$inv_filename = $this->handlePictureUpload($invoice, $upload_dir, $serial, 'invoice');
|
||||
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
||||
|
||||
|
||||
/*
|
||||
$data = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'email' => $email,
|
||||
'plate_num' => $plate_num,
|
||||
'odometer' => $odometer,
|
||||
'date_purchase' => $date_purchase,
|
||||
];
|
||||
|
||||
error_log(print_r($data, true));
|
||||
|
||||
error_log('updating warranty');
|
||||
*/
|
||||
|
||||
// do actual registering
|
||||
$res = $this->updateWarranty($em, $req, $serial, $inv_filename, $wcard_filename);
|
||||
|
||||
|
|
@ -306,8 +297,6 @@ class CustomerWarrantyController extends APIController
|
|||
|
||||
return $res;
|
||||
|
||||
error_log('after updating warranty');
|
||||
|
||||
return new APIResponse(true, 'Warranty registered.');
|
||||
}
|
||||
|
||||
|
|
@ -358,6 +347,7 @@ class CustomerWarrantyController extends APIController
|
|||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
|
||||
|
||||
// skip warranty if it already exists
|
||||
$cust = null;
|
||||
if ($warr != null)
|
||||
{
|
||||
$warr_plate_num = $this->cleanPlateNumber($warr->getPlateNumber());
|
||||
|
|
@ -367,18 +357,8 @@ class CustomerWarrantyController extends APIController
|
|||
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
|
||||
}
|
||||
|
||||
/*
|
||||
// check if warranty is registered to a serial owned by customer
|
||||
$warr_plate = $warr->getPlateNumber();
|
||||
$cust = $this->session->getCustomer();
|
||||
$is_customer_warranty = $this->checkCustomerPlateNumber($warr_plate, $cust);
|
||||
|
||||
if (!$is_customer_warranty)
|
||||
{
|
||||
return new APIResponse(false, 'Warranty registred to a vehicle not in your list of vehicles.');
|
||||
}
|
||||
*/
|
||||
|
||||
// get customer
|
||||
$cust = $warr->getCustomer();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -418,6 +398,27 @@ class CustomerWarrantyController extends APIController
|
|||
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
||||
}
|
||||
|
||||
// chstomer check
|
||||
$priv_promo = $req->request->get('priv_promo', false);
|
||||
if ($cust == null)
|
||||
{
|
||||
// if no customer yet, create one and fill in fields
|
||||
$cust = new Customer();
|
||||
$cust->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setEmail($req->request->get('email'))
|
||||
->setCreateSource('web_warranty')
|
||||
->setPrivacyPromo($priv_promo)
|
||||
->setPhoneMobile($req->request->get('contact_num'));
|
||||
|
||||
$em->persist($cust);
|
||||
}
|
||||
else
|
||||
{
|
||||
// only update privacy promo
|
||||
$cust->setPrivacyPromo($priv_promo);
|
||||
}
|
||||
|
||||
|
||||
error_log('update entity / database');
|
||||
// create or update warranty entry
|
||||
|
|
@ -452,6 +453,7 @@ class CustomerWarrantyController extends APIController
|
|||
->setVehicleModelYear($req->request->get('vmodel'))
|
||||
->setDealerName($req->request->get('dealer_name'))
|
||||
->setDealerAddress($req->request->get('dealer_address'))
|
||||
->setCustomer($cust)
|
||||
->setValidated(false);
|
||||
|
||||
// TODO: check for date purchase and date expire
|
||||
|
|
|
|||
|
|
@ -197,6 +197,12 @@ class Customer
|
|||
*/
|
||||
protected $flag_promo_marketing_research;
|
||||
|
||||
// where customer was created from
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80, options={"default": "legacy"})
|
||||
*/
|
||||
protected $create_source;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->numbers = new ArrayCollection();
|
||||
|
|
@ -230,6 +236,8 @@ class Customer
|
|||
$this->flag_promo_marketing_research = false;
|
||||
|
||||
$this->date_create = new DateTime();
|
||||
|
||||
$this->create_source = 'unknown';
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -572,4 +580,15 @@ class Customer
|
|||
{
|
||||
return $this->flag_promo_marketing_research;
|
||||
}
|
||||
|
||||
public function setCreateSource($source)
|
||||
{
|
||||
$this->create_source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreateSource()
|
||||
{
|
||||
return $this->create_source;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,6 +214,14 @@ class Warranty
|
|||
*/
|
||||
protected $flag_validated;
|
||||
|
||||
// link to customer
|
||||
// TODO: check if this is the best way to do it, we'll be creating a new customer for every warranty since there is no reliable way to match customer to existing
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Customer")
|
||||
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -608,4 +616,14 @@ class Warranty
|
|||
return $this->flag_validated;
|
||||
}
|
||||
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue