Add call to add location for customer. #632
This commit is contained in:
parent
a8eaad2a82
commit
61b897d883
1 changed files with 58 additions and 0 deletions
|
|
@ -66,6 +66,7 @@ use App\Entity\PrivacyPolicy;
|
|||
use App\Entity\Hub;
|
||||
use App\Entity\SAPBattery;
|
||||
use App\Entity\WarrantySerial;
|
||||
use App\Entity\CustomerMetadata;
|
||||
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
|
|
@ -3600,6 +3601,63 @@ class APIController extends Controller implements LoggedController
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function addLocation(Request $req)
|
||||
{
|
||||
$required_params = [
|
||||
'name',
|
||||
'address',
|
||||
'longitude',
|
||||
'latitude',
|
||||
];
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
// get customer
|
||||
$cust = $this->session->getCustomer();
|
||||
if ($cust == null)
|
||||
{
|
||||
$res->setError(true)
|
||||
->setErrorMessage('No customer information found');
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
// get the information
|
||||
$name = $req->request->get('name');
|
||||
$address = $req->request->get('address');
|
||||
$lng = $req->request->get('longitude');
|
||||
$lat = $req->request->get('latitude');
|
||||
|
||||
$loc_info = [
|
||||
'address' => $address,
|
||||
'longitude' => $lng,
|
||||
'latitude' => $lat,
|
||||
];
|
||||
|
||||
// check if customer already has existing metadata
|
||||
$c_meta = $em->getRepository(CustomerMetadata::class)->findOneBy(['customer' => $cust]);
|
||||
if ($c_meta == null)
|
||||
{
|
||||
// create new customer meta
|
||||
$cust_meta = new CustomerMetadata();
|
||||
$cust_meta->setCustomer($cust);
|
||||
$cust_meta->addMetaInfo($name, $loc_info);
|
||||
|
||||
$em->persist($cust_meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add location to existing customer meta
|
||||
$c_meta->addMetaInfo($name, $loc_info);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $res->getReturnResponse();
|
||||
|
||||
}
|
||||
|
||||
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
|
||||
$logger, $log_data, $user_id, $action, $source)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue