Merge branch '540-paperless-warranty' into 'master'
Add API calls for warranty check and register #540 Closes #540 See merge request jankstudio/resq!632
This commit is contained in:
commit
185679fabd
4 changed files with 325 additions and 11 deletions
|
|
@ -169,3 +169,14 @@ api_schedule_option_status:
|
|||
path: /api/schedule_option_status
|
||||
controller: App\Controller\APIController::scheduleOptionStatus
|
||||
methods: [GET]
|
||||
|
||||
# paperless warranty / qr code
|
||||
api_warr_serial_check:
|
||||
path: /api/warranty/{serial}
|
||||
controller: App\Controller\APIController::warrantyCheck
|
||||
methods: [GET]
|
||||
|
||||
api_warr_serial_register:
|
||||
path: /api/warranty/{serial}
|
||||
controller: App\Controller\APIController::warrantyRegister
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ use App\Entity\Partner;
|
|||
use App\Entity\Review;
|
||||
use App\Entity\PrivacyPolicy;
|
||||
use App\Entity\Hub;
|
||||
use App\Entity\SAPBattery;
|
||||
use App\Entity\WarrantySerial;
|
||||
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
|
|
@ -401,18 +403,8 @@ class APIController extends Controller implements LoggedController
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function updateInfo(Request $req)
|
||||
protected function updateCustomerInfo($req, $em)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// create new customer if it's not there
|
||||
$cust = $this->session->getCustomer();
|
||||
if ($cust == null)
|
||||
|
|
@ -425,11 +417,28 @@ class APIController extends Controller implements LoggedController
|
|||
|
||||
$cust->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setEmail($req->request->get('email'))
|
||||
->setConfirmed($this->session->isConfirmed());
|
||||
|
||||
// update mobile phone of customer
|
||||
$cust->setPhoneMobile(substr($this->session->getPhoneNumber(), 2));
|
||||
|
||||
return $cust;
|
||||
}
|
||||
|
||||
public function updateInfo(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
];
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
$cust = $this->updateCustomerInfo($req, $em);
|
||||
|
||||
// get privacy policy for mobile
|
||||
$dotenv = new Dotenv();
|
||||
$dotenv->loadEnv(__DIR__.'/../../.env');
|
||||
|
|
@ -2741,6 +2750,180 @@ class APIController extends Controller implements LoggedController
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function warrantyCheck($serial, EntityManagerInterface $em, Request $req)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [];
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// initialize data
|
||||
$data = [
|
||||
'is_valid' => false,
|
||||
'customer' => [
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'mobile_number' => '',
|
||||
'plate_number' => '',
|
||||
],
|
||||
'battery' => [
|
||||
'brand' => '',
|
||||
'size' => '',
|
||||
],
|
||||
];
|
||||
|
||||
// check if warranty serial is there
|
||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
|
||||
$batt = null;
|
||||
$is_registered = false;
|
||||
|
||||
// if warranty serial is there
|
||||
if ($warr_serial != null)
|
||||
{
|
||||
// if we have a warranty entry for the serial already
|
||||
if ($warr != null)
|
||||
{
|
||||
$is_registered = true;
|
||||
$customer = [
|
||||
'first_name' => $warr->getFirstName(),
|
||||
'last_name' => $warr->getLastName(),
|
||||
'mobile_number' => $warr->getMobileNumber(),
|
||||
'plate_number' => $warr->getPlateNumber(),
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$customer = [
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'mobile_number' => '',
|
||||
'plate_number' => '',
|
||||
];
|
||||
}
|
||||
|
||||
$sku = $warr_serial->getSKU();
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt != null)
|
||||
{
|
||||
$battery = [
|
||||
'brand' => $batt->getBrand()->getName(),
|
||||
'size' => $batt->getSize()->getName(),
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
$battery = [
|
||||
'brand' => '',
|
||||
'size' => '',
|
||||
];
|
||||
}
|
||||
|
||||
// populate data
|
||||
$data = [
|
||||
'is_valid' => true,
|
||||
'is_registered' => $is_registered,
|
||||
'customer' => $customer,
|
||||
'battery' => $battery,
|
||||
];
|
||||
}
|
||||
|
||||
$res->setData($data);
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req)
|
||||
{
|
||||
// check required parameters and api key
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'plate_number',
|
||||
];
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// update customer information
|
||||
$cust = $this->updateCustomerInfo($req, $em);
|
||||
|
||||
// update warranty
|
||||
$res = $this->updateWarranty($res, $em, $req, $serial);
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function updateWarranty($res, $em, $req, $serial)
|
||||
{
|
||||
// get serial
|
||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||
if ($warr_serial == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Invalid warranty serial code.');
|
||||
return $res;
|
||||
}
|
||||
|
||||
// check if warranty exists already
|
||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
|
||||
|
||||
// skip warranty if it already exists
|
||||
if ($warr != null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Warranty registration entry already exists.');
|
||||
return $res;
|
||||
}
|
||||
|
||||
// get sap battery
|
||||
$sku = $warr_serial->getSKU();
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($sap_bty == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('Could not find battery entry for warranty.');
|
||||
return $res;
|
||||
}
|
||||
|
||||
$date_pur = new DateTime();
|
||||
|
||||
|
||||
// create new warranty entry
|
||||
$warr = new Warranty();
|
||||
$warr->setSerial($serial)
|
||||
->setFirstName($req->request->get('first_name'))
|
||||
->setLastName($req->request->get('last_name'))
|
||||
->setEmail($req->request->get('email'))
|
||||
->setPlateNumber($req->request->get('plate_number'))
|
||||
// TODO: figure out how to compute date of purchase
|
||||
->setDatePurchase($date_pur)
|
||||
// TODO: set status
|
||||
// ->setStatus()
|
||||
// TODO: set battery model and size id
|
||||
// ->setBatterySize()
|
||||
// ->setBatteryModel()
|
||||
->setSAPBattery($sap_bty)
|
||||
->setMobileNumber(substr($this->session->getPhoneNumber(), 2))
|
||||
->setActivated(true);
|
||||
|
||||
// TODO: check for date purchase and date expire
|
||||
|
||||
$em->persist($warr);
|
||||
|
||||
// TODO: check if we need to do anyting else
|
||||
$data = [];
|
||||
|
||||
// set data to retrun to user
|
||||
$res->setData($data);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function findCustomerByNumber($number)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
|
|
|||
|
|
@ -58,6 +58,12 @@ class Warranty
|
|||
*/
|
||||
protected $last_name;
|
||||
|
||||
// email
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80, nullable=true)
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
// customer mobile phone number
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30, nullable=true)
|
||||
|
|
@ -142,6 +148,7 @@ class Warranty
|
|||
$this->status = WarrantyStatus::ACTIVE;
|
||||
$this->date_claim = null;
|
||||
$this->flag_activated = false;
|
||||
$this->email = '';
|
||||
}
|
||||
|
||||
public function getID()
|
||||
|
|
@ -249,6 +256,17 @@ class Warranty
|
|||
return $this->last_name;
|
||||
}
|
||||
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setMobileNumber($mnum = null)
|
||||
{
|
||||
$this->mobile_number = $mnum;
|
||||
|
|
|
|||
102
src/Entity/WarrantySerial.php
Normal file
102
src/Entity/WarrantySerial.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="warranty_serial",
|
||||
* )
|
||||
*/
|
||||
class WarrantySerial
|
||||
{
|
||||
// unique id - serial number
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string", length=20)
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// date serial was entered
|
||||
/**
|
||||
* @ORM\Column(type="datetime")
|
||||
*/
|
||||
protected $date_create;
|
||||
|
||||
// battery sku
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50, nullable=true)
|
||||
*/
|
||||
protected $sku;
|
||||
|
||||
// internal battery id - points to battery table
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
protected $battery_id;
|
||||
|
||||
// source of the warranty serial record
|
||||
// list - motiv, crm
|
||||
/**
|
||||
* @ORM\Column(type="string", length=50, nullable=true)
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
}
|
||||
|
||||
public function setID($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDateCreate()
|
||||
{
|
||||
return $this->date_create;
|
||||
}
|
||||
|
||||
public function setSKU($sku)
|
||||
{
|
||||
$this->sku = $sku;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSKU()
|
||||
{
|
||||
return $this->sku;
|
||||
}
|
||||
|
||||
public function setBatteryID($id)
|
||||
{
|
||||
$this->battery_id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBatteryID()
|
||||
{
|
||||
return $this->battery_id;
|
||||
}
|
||||
|
||||
public function setSource($source)
|
||||
{
|
||||
$this->source = $source;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue