Merge branch '540-paperless-warranty' into 'master'

Add battery image_url to warranty check and other improvements #540

Closes #540

See merge request jankstudio/resq!634
This commit is contained in:
Kendrick Chan 2021-03-05 15:07:23 +00:00
commit 033a16f02a
2 changed files with 23 additions and 1 deletions

BIN
public/battery/generic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\RequestStack;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
@ -2758,9 +2759,11 @@ class APIController extends Controller implements LoggedController
if ($res->isError())
return $res->getReturnResponse();
/*
// initialize data
$data = [
'is_valid' => false,
'is_registered' => false,
'customer' => [
'first_name' => '',
'last_name' => '',
@ -2772,6 +2775,7 @@ class APIController extends Controller implements LoggedController
'size' => '',
],
];
*/
// check if warranty serial is there
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
@ -2779,6 +2783,13 @@ class APIController extends Controller implements LoggedController
$batt = null;
$is_registered = false;
if ($warr_serial == null)
{
$res->setError(true)
->setErrorMessage('Invalid warranty serial code.');
return $res->getReturnResponse();
}
// if warranty serial is there
if ($warr_serial != null)
{
@ -2786,10 +2797,17 @@ class APIController extends Controller implements LoggedController
if ($warr != null)
{
$is_registered = true;
// null mobile number should be blank string instead
if ($warr->getMobileNumber() == null)
$mobile_num = '';
else
$mobile_num = $warr->getMobileNumber();
$customer = [
'first_name' => $warr->getFirstName(),
'last_name' => $warr->getLastName(),
'mobile_number' => $warr->getMobileNumber(),
'mobile_number' => $mobile_num,
'plate_number' => $warr->getPlateNumber(),
];
}
@ -2805,11 +2823,14 @@ class APIController extends Controller implements LoggedController
$sku = $warr_serial->getSKU();
$batt = $em->getRepository(SAPBattery::class)->find($sku);
// TODO: put this in a config file
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
if ($batt != null)
{
$battery = [
'brand' => $batt->getBrand()->getName(),
'size' => $batt->getSize()->getName(),
'image_url' => $image_url,
];
}
else
@ -2817,6 +2838,7 @@ class APIController extends Controller implements LoggedController
$battery = [
'brand' => '',
'size' => '',
'image_url' => '',
];
}