Add logging for warranty creation in mobile API. #555
This commit is contained in:
parent
7ec5ba439c
commit
d2cae08fb0
1 changed files with 38 additions and 9 deletions
|
|
@ -30,6 +30,7 @@ use App\Ramcar\AdvanceOrderSlot;
|
||||||
use App\Ramcar\AutoAssignStatus;
|
use App\Ramcar\AutoAssignStatus;
|
||||||
use App\Ramcar\HubCriteria;
|
use App\Ramcar\HubCriteria;
|
||||||
use App\Ramcar\WillingToWaitContent;
|
use App\Ramcar\WillingToWaitContent;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
use App\Service\RisingTideGateway;
|
use App\Service\RisingTideGateway;
|
||||||
|
|
@ -42,6 +43,7 @@ use App\Service\RiderAssignmentHandlerInterface;
|
||||||
use App\Service\HubSelector;
|
use App\Service\HubSelector;
|
||||||
use App\Service\HubDistributor;
|
use App\Service\HubDistributor;
|
||||||
use App\Service\HubFilterLogger;
|
use App\Service\HubFilterLogger;
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
|
@ -3051,7 +3053,8 @@ class APIController extends Controller implements LoggedController
|
||||||
return $serial . '/' . $filename;
|
return $serial . '/' . $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans)
|
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt,
|
||||||
|
TranslatorInterface $trans, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
// check required parameters and api key
|
// check required parameters and api key
|
||||||
$required_params = [
|
$required_params = [
|
||||||
|
|
@ -3073,22 +3076,37 @@ class APIController extends Controller implements LoggedController
|
||||||
$inv_filename = $this->handlePictureUpload($invoice, $upload_dir, $serial, 'invoice');
|
$inv_filename = $this->handlePictureUpload($invoice, $upload_dir, $serial, 'invoice');
|
||||||
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
||||||
|
|
||||||
|
$user_id = $req->query->get('api_key');
|
||||||
|
$log_data = [
|
||||||
|
'plate_number' => $req->request->get('plate_num'),
|
||||||
|
'first_name' => $req->request->get('first_name'),
|
||||||
|
'last_name' => $req->request->get('last_name'),
|
||||||
|
'date_purchase' => $req->request->get('date_purchase'),
|
||||||
|
];
|
||||||
|
$action = 'create';
|
||||||
|
$source = WarrantySource::MOBILE;
|
||||||
|
|
||||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||||
if ($res->isError())
|
if ($res->isError())
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
// update customer information
|
// update customer information
|
||||||
// $cust = $this->updateCustomerInfo($req, $em);
|
// $cust = $this->updateCustomerInfo($req, $em);
|
||||||
|
|
||||||
// update warranty
|
// update warranty
|
||||||
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename);
|
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
|
||||||
|
$logger, $log_data, $user_id, $action, $source);
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
|
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
|
||||||
|
$logger, $log_data, $user_id, $action, $source)
|
||||||
{
|
{
|
||||||
// get serial
|
// get serial
|
||||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||||
|
|
@ -3096,6 +3114,7 @@ class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Invalid warranty serial code.');
|
->setErrorMessage('Invalid warranty serial code.');
|
||||||
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3120,7 +3139,8 @@ class APIController extends Controller implements LoggedController
|
||||||
if (!$is_customer_warranty)
|
if (!$is_customer_warranty)
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Warranty registred to a vehicle not in your list of vehicles.');
|
->setErrorMessage('Warranty registered to a vehicle not in your list of vehicles.');
|
||||||
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3132,14 +3152,20 @@ class APIController extends Controller implements LoggedController
|
||||||
$sms_msg = $trans->trans('warranty_register_confirm');
|
$sms_msg = $trans->trans('warranty_register_confirm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if sku is null
|
||||||
// get sap battery
|
// get sap battery
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
$sap_bty = null;
|
||||||
if ($sap_bty == null)
|
if ($sku != null)
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
->setErrorMessage('Could not find battery entry for warranty.');
|
if ($sap_bty == null)
|
||||||
return $res;
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('Could not find battery entry for warranty.');
|
||||||
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// default date purchase to today
|
// default date purchase to today
|
||||||
|
|
@ -3152,6 +3178,7 @@ class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Invalid date format for date of purchase.');
|
->setErrorMessage('Invalid date format for date of purchase.');
|
||||||
|
$logger->logWarrantyInfo($log_data, $res->getErrorMessage(), $user_id, $action, $source);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3196,6 +3223,8 @@ class APIController extends Controller implements LoggedController
|
||||||
// set data to retrun to user
|
// set data to retrun to user
|
||||||
$res->setData($data);
|
$res->setData($data);
|
||||||
|
|
||||||
|
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
// send sms
|
// send sms
|
||||||
error_log('sending sms to - ' . $this->session->getPhoneNumber());
|
error_log('sending sms to - ' . $this->session->getPhoneNumber());
|
||||||
$rt->sendSMS($this->session->getPhoneNumber(), 'MOTOLITE', $sms_msg);
|
$rt->sendSMS($this->session->getPhoneNumber(), 'MOTOLITE', $sms_msg);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue