Merge branch '555-log-warranty-data-sent-via-api' into 'master'
Resolve "Log warranty data sent via API" Closes #555 See merge request jankstudio/resq!658
This commit is contained in:
commit
5d5ccb6645
12 changed files with 499 additions and 42 deletions
|
|
@ -284,3 +284,8 @@ services:
|
||||||
App\Service\HubFilterLogger:
|
App\Service\HubFilterLogger:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
|
|
||||||
|
# warranty api logger
|
||||||
|
App\Service\WarrantyAPILogger:
|
||||||
|
arguments:
|
||||||
|
$em: "@doctrine.orm.entity_manager"
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,25 @@ use App\Entity\JobOrder;
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
use App\Entity\SAPBattery;
|
use App\Entity\SAPBattery;
|
||||||
|
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
use App\Ramcar\WarrantyStatus;
|
use App\Ramcar\WarrantyStatus;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use DoctrineExtensions\Query\Mysql\DateFormat;
|
use DoctrineExtensions\Query\Mysql\DateFormat;
|
||||||
|
|
||||||
class GenerateWarrantyFromJobOrderCommand extends Command
|
class GenerateWarrantyFromJobOrderCommand extends Command
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $logger;
|
||||||
protected $sapbatt_hash;
|
protected $sapbatt_hash;
|
||||||
protected $warranties_hash;
|
protected $warranties_hash;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->logger = $logger;
|
||||||
|
|
||||||
$this->loadSAPBatteries();
|
$this->loadSAPBatteries();
|
||||||
|
|
||||||
|
|
@ -209,7 +214,27 @@ class GenerateWarrantyFromJobOrderCommand extends Command
|
||||||
|
|
||||||
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n";
|
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n";
|
||||||
|
|
||||||
echo $sql_statement;
|
echo $sql_statement;
|
||||||
|
|
||||||
|
$db = $this->em->getConnection();
|
||||||
|
$stmt = $db->prepare($sql_statement);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
// log warranty creation
|
||||||
|
$log_data = [
|
||||||
|
'battery_model_id' => $bty_model_id,
|
||||||
|
'battery_size_id' => $bty_size_id,
|
||||||
|
'warranty_class' => $warranty_class,
|
||||||
|
'plate_number' => $cleaned_plate_number,
|
||||||
|
'date_create' => $date_create,
|
||||||
|
'date_purchase' => $date_purchase,
|
||||||
|
'date_expire' => $date_expire,
|
||||||
|
'sap_code' => $sap_code,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name,
|
||||||
|
'mobile_number' => $mobile_number,
|
||||||
|
];
|
||||||
|
$this->logger->logWarrantyInfo($log_data, '', 'internal', 'create', WarrantySource::COMMAND);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -2977,11 +2979,7 @@ class APIController extends Controller implements LoggedController
|
||||||
}
|
}
|
||||||
|
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
|
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
// check if sku is null
|
|
||||||
$batt = null;
|
|
||||||
if ($sku != null)
|
|
||||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
|
||||||
// TODO: put this in a config file
|
// TODO: put this in a config file
|
||||||
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
||||||
if ($batt != null)
|
if ($batt != null)
|
||||||
|
|
@ -3055,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 = [
|
||||||
|
|
@ -3077,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);
|
||||||
|
|
@ -3100,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3125,6 +3140,7 @@ class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
$res->setError(true)
|
$res->setError(true)
|
||||||
->setErrorMessage('Warranty registered 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3141,7 +3157,16 @@ class APIController extends Controller implements LoggedController
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
$sap_bty = null;
|
$sap_bty = null;
|
||||||
if ($sku != null)
|
if ($sku != null)
|
||||||
|
{
|
||||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
|
if ($sap_bty == null)
|
||||||
|
{
|
||||||
|
$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
|
||||||
// NOTE: might need to change this later
|
// NOTE: might need to change this later
|
||||||
|
|
@ -3153,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3197,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);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ use Catalyst\APIBundle\Controller\APIController;
|
||||||
use Catalyst\APIBundle\Response\APIResponse;
|
use Catalyst\APIBundle\Response\APIResponse;
|
||||||
|
|
||||||
use App\Service\RisingTideGateway;
|
use App\Service\RisingTideGateway;
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use App\Entity\WarrantySerial;
|
use App\Entity\WarrantySerial;
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
|
@ -32,6 +33,7 @@ use App\Ramcar\WarrantyClass;
|
||||||
use App\Ramcar\WarrantyStatus;
|
use App\Ramcar\WarrantyStatus;
|
||||||
use App\Ramcar\FuelType;
|
use App\Ramcar\FuelType;
|
||||||
use App\Ramcar\VehicleStatusCondition;
|
use App\Ramcar\VehicleStatusCondition;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -73,13 +75,14 @@ class CustomerWarrantyController extends APIController
|
||||||
return $missing;
|
return $missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkRequiredParams(Request $req, $params)
|
protected function checkRequiredParams(Request $req, $params, $logger, $log_data, $user_id, $action, $source)
|
||||||
{
|
{
|
||||||
// check required parameters
|
// check required parameters
|
||||||
$missing = $this->checkMissingParameters($req, $params);
|
$missing = $this->checkMissingParameters($req, $params);
|
||||||
if (count($missing) > 0)
|
if (count($missing) > 0)
|
||||||
{
|
{
|
||||||
$miss_string = implode(', ', $missing);
|
$miss_string = implode(', ', $missing);
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Missing parameter(s): ' . $miss_string, $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Missing parameter(s): ' . $miss_string);
|
return new APIResponse(false, 'Missing parameter(s): ' . $miss_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,16 +99,32 @@ class CustomerWarrantyController extends APIController
|
||||||
return preg_replace('/\s+/', '', strtoupper($plate_num));
|
return preg_replace('/\s+/', '', strtoupper($plate_num));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check($serial, EntityManagerInterface $em, Request $req)
|
public function check($serial, EntityManagerInterface $em, Request $req, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
|
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $serial,
|
||||||
|
];
|
||||||
|
$action = 'check';
|
||||||
|
$source = WarrantySource::CAPI;
|
||||||
|
|
||||||
// check required parameters
|
// check required parameters
|
||||||
$required_params = [];
|
$required_params = [];
|
||||||
$res = $this->checkRequiredParams($req, $required_params);
|
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
|
||||||
if (!$res)
|
if (!$res)
|
||||||
return $res;
|
return $res;
|
||||||
|
|
||||||
error_log('check warranty serial');
|
error_log('check warranty serial');
|
||||||
|
|
||||||
|
//$keys = array_keys($_SERVER);
|
||||||
|
//foreach ($keys as $key)
|
||||||
|
//{
|
||||||
|
// error_log($key);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//error_log($_SERVER['HTTP_X_CATA_API_KEY']);
|
||||||
|
|
||||||
|
// TODO: add logging for the other scenarios
|
||||||
// check if warranty serial is there
|
// check if warranty serial is there
|
||||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
|
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $serial]);
|
||||||
|
|
@ -279,20 +298,40 @@ class CustomerWarrantyController extends APIController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function register($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans)
|
public function register($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt, TranslatorInterface $trans,
|
||||||
|
WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
error_log('HERE - register');
|
error_log('HERE - register');
|
||||||
// check required parameters
|
// check required parameters
|
||||||
// TODO: maybe add vmake_id? since warranty cannot be created with no vmake
|
// TODO: maybe add vmake_id? since warranty cannot be created with no vmake
|
||||||
// TODO: maye also add mobile and email since customer creation won't let mobile and email be null
|
// TODO: maye also add mobile and email since customer creation won't let mobile and email be null
|
||||||
|
// set up information for logging
|
||||||
|
// get user from header
|
||||||
|
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $serial,
|
||||||
|
'plate_number' => $req->request->get('plate_num'),
|
||||||
|
'first_name' => $req->request->get('first_name'),
|
||||||
|
'last_name' => $req->request->get('last_name'),
|
||||||
|
'vmake_id' => $req->request->get('vmake_id'),
|
||||||
|
'contact_number' => $req->request->get('contact_num'),
|
||||||
|
'email' => $req->request->get('email'),
|
||||||
|
'invoice' => $req->request->get('invoice'),
|
||||||
|
];
|
||||||
|
$action = 'create/update';
|
||||||
|
$source = WarrantySource::CAPI;
|
||||||
|
|
||||||
|
error_log('SOURCE: ' . $source);
|
||||||
|
|
||||||
$required_params = [
|
$required_params = [
|
||||||
'first_name',
|
'first_name',
|
||||||
'last_name',
|
'last_name',
|
||||||
'plate_num'
|
'plate_num'
|
||||||
];
|
];
|
||||||
$res = $this->checkRequiredParams($req, $required_params);
|
$res = $this->checkRequiredParams($req, $required_params, $logger, $log_data, $user_id, $action, $source);
|
||||||
if (!$res)
|
|
||||||
return $res;
|
if (!$res)
|
||||||
|
return $res;
|
||||||
|
|
||||||
// file uploads
|
// file uploads
|
||||||
$invoice = $req->files->get('invoice');
|
$invoice = $req->files->get('invoice');
|
||||||
|
|
@ -305,12 +344,13 @@ class CustomerWarrantyController extends APIController
|
||||||
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
||||||
|
|
||||||
// do actual registering
|
// do actual registering
|
||||||
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename);
|
$res = $this->updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
|
||||||
|
$logger, $log_data, $user_id, $action, $source);
|
||||||
|
|
||||||
// flush to db
|
// flush to db
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
|
||||||
return new APIResponse(true, 'Warranty registered.');
|
return new APIResponse(true, 'Warranty registered.');
|
||||||
}
|
}
|
||||||
|
|
@ -346,7 +386,8 @@ class CustomerWarrantyController extends APIController
|
||||||
return $serial . '/' . $filename;
|
return $serial . '/' . $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
|
protected function updateWarranty($em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
|
||||||
|
$logger, $log_data, $user_id, $action, $source)
|
||||||
{
|
{
|
||||||
$plate_num = $this->cleanPlateNumber($req->request->get('plate_num'));
|
$plate_num = $this->cleanPlateNumber($req->request->get('plate_num'));
|
||||||
|
|
||||||
|
|
@ -355,6 +396,7 @@ class CustomerWarrantyController extends APIController
|
||||||
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
|
||||||
if ($warr_serial == null)
|
if ($warr_serial == null)
|
||||||
{
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Invalid warranty serial code..', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Invalid warranty serial code.');
|
return new APIResponse(false, 'Invalid warranty serial code.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,6 +412,7 @@ class CustomerWarrantyController extends APIController
|
||||||
|
|
||||||
if ($plate_num != $warr_plate_num)
|
if ($plate_num != $warr_plate_num)
|
||||||
{
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Plate number does not match vehicle registered to warranty.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
|
return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,10 +436,11 @@ class CustomerWarrantyController extends APIController
|
||||||
if ($sku != null)
|
if ($sku != null)
|
||||||
{
|
{
|
||||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
//if ($sap_bty == null)
|
if ($sap_bty == null)
|
||||||
//{
|
{
|
||||||
// return new APIResponse(false, 'Could not find battery entry for warranty.');
|
$logger->logWarrantyInfo($log_data, 'Cound not find battery entry for warranty.', $user_id, $action, $source);
|
||||||
//}
|
return new APIResponse(false, 'Could not find battery entry for warranty.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vehicle fetch
|
// vehicle fetch
|
||||||
|
|
@ -407,6 +451,7 @@ class CustomerWarrantyController extends APIController
|
||||||
$vehicle = $em->getRepository(Vehicle::class)->find($vmake_id);
|
$vehicle = $em->getRepository(Vehicle::class)->find($vmake_id);
|
||||||
if ($vehicle == null)
|
if ($vehicle == null)
|
||||||
{
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Could not find vehicle specified for warranty.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Could not find vehicle specified for warranty.');
|
return new APIResponse(false, 'Could not find vehicle specified for warranty.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -423,6 +468,7 @@ class CustomerWarrantyController extends APIController
|
||||||
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
|
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
|
||||||
if (!$date_pur_cust)
|
if (!$date_pur_cust)
|
||||||
{
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Invalid date format for date of purchase.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
return new APIResponse(false, 'Invalid date format for date of purchase.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -499,14 +545,15 @@ class CustomerWarrantyController extends APIController
|
||||||
|
|
||||||
$em->persist($warr);
|
$em->persist($warr);
|
||||||
|
|
||||||
|
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
// TODO: check if we need to do anyting else
|
// TODO: check if we need to do anyting else
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
|
|
||||||
// send sms confirmation
|
// send sms confirmation
|
||||||
$this->sendSMSConfirmation($rt, $req->request->get('contact_num'), $sms_message);
|
$this->sendSMSConfirmation($rt, $req->request->get('contact_num'), $sms_message);
|
||||||
|
|
||||||
return new APIResponse(true, 'Warranty registered.', $data);
|
return new APIResponse(true, 'Warranty registered.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendSMSConfirmation($rt, $num, $message)
|
protected function sendSMSConfirmation($rt, $num, $message)
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,16 @@ use App\Entity\PrivacyPolicy;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
use App\Entity\CustomerVehicle;
|
use App\Entity\CustomerVehicle;
|
||||||
use App\Entity\Vehicle;
|
use App\Entity\Vehicle;
|
||||||
|
use App\Entity\WarrantyAPILog;
|
||||||
|
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use App\Ramcar\NameValue;
|
use App\Ramcar\NameValue;
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
use App\Ramcar\WarrantyStatus;
|
use App\Ramcar\WarrantyStatus;
|
||||||
use App\Ramcar\FuelType;
|
use App\Ramcar\FuelType;
|
||||||
use App\Ramcar\VehicleStatusCondition;
|
use App\Ramcar\VehicleStatusCondition;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -142,7 +146,7 @@ class WarrantyController extends APIController
|
||||||
return new APIResponse(true, 'Warranties found.', $data);
|
return new APIResponse(true, 'Warranties found.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(Request $req, EntityManagerInterface $em)
|
public function register(Request $req, EntityManagerInterface $em, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('warranty.register.battery', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.register.battery', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -159,10 +163,6 @@ class WarrantyController extends APIController
|
||||||
'battery_size_id',
|
'battery_size_id',
|
||||||
*/
|
*/
|
||||||
];
|
];
|
||||||
$msg = $this->checkRequiredParameters($req, $params);
|
|
||||||
error_log('msg - ' . $msg);
|
|
||||||
if ($msg)
|
|
||||||
return new APIResponse(false, $msg);
|
|
||||||
|
|
||||||
$serial = $req->request->get('serial');
|
$serial = $req->request->get('serial');
|
||||||
$date_expire_string = $req->request->get('date_expire');
|
$date_expire_string = $req->request->get('date_expire');
|
||||||
|
|
@ -175,6 +175,31 @@ class WarrantyController extends APIController
|
||||||
$lname = $req->request->get('last_name', null);
|
$lname = $req->request->get('last_name', null);
|
||||||
$mnum = $req->request->get('mobile_number', null);
|
$mnum = $req->request->get('mobile_number', null);
|
||||||
|
|
||||||
|
// set up information for logging
|
||||||
|
// get user from header
|
||||||
|
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $serial,
|
||||||
|
'date_expire' => $date_expire_string,
|
||||||
|
'date_pur_string' => $date_pur_string,
|
||||||
|
'warranty_class' => $warr_class,
|
||||||
|
'plate_number' => $plate,
|
||||||
|
'sku' => $sku,
|
||||||
|
'first_name' => $fname,
|
||||||
|
'last_name' => $lname,
|
||||||
|
'mobile_number' => $mnum,
|
||||||
|
];
|
||||||
|
$action = 'create';
|
||||||
|
$source = WarrantySource::CAPI;
|
||||||
|
|
||||||
|
$msg = $this->checkRequiredParameters($req, $params);
|
||||||
|
error_log('msg - ' . $msg);
|
||||||
|
if ($msg)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
|
||||||
|
return new APIResponse(false, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$bmodel_id = $req->request->get('battery_model_id');
|
$bmodel_id = $req->request->get('battery_model_id');
|
||||||
$bsize_id = $req->request->get('battery_size_id');
|
$bsize_id = $req->request->get('battery_size_id');
|
||||||
|
|
@ -183,21 +208,33 @@ class WarrantyController extends APIController
|
||||||
// wrong date expire format
|
// wrong date expire format
|
||||||
$date_expire = DateTime::createFromFormat('Ymd', $date_expire_string);
|
$date_expire = DateTime::createFromFormat('Ymd', $date_expire_string);
|
||||||
if ($date_expire === false)
|
if ($date_expire === false)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_expire.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Wrong date format: date_expire.');
|
return new APIResponse(false, 'Wrong date format: date_expire.');
|
||||||
|
}
|
||||||
|
|
||||||
// wrong date purchase format
|
// wrong date purchase format
|
||||||
$date_pur = DateTime::createFromFormat('Ymd', $date_pur_string);
|
$date_pur = DateTime::createFromFormat('Ymd', $date_pur_string);
|
||||||
if ($date_pur === false)
|
if ($date_pur === false)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Wrong date format: date_purchase', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Wrong date format: date_purchase.');
|
return new APIResponse(false, 'Wrong date format: date_purchase.');
|
||||||
|
}
|
||||||
|
|
||||||
// valid warranty class
|
// valid warranty class
|
||||||
if (!WarrantyClass::validate($warr_class))
|
if (!WarrantyClass::validate($warr_class))
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Invalid warranty class.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Invalid warranty class.');
|
return new APIResponse(false, 'Invalid warranty class.');
|
||||||
|
}
|
||||||
|
|
||||||
// plate number
|
// plate number
|
||||||
$plate = Warranty::cleanPlateNumber($plate);
|
$plate = Warranty::cleanPlateNumber($plate);
|
||||||
if (!$plate)
|
if (!$plate)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Invalid plate number.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Invalid plate number.');
|
return new APIResponse(false, 'Invalid plate number.');
|
||||||
|
}
|
||||||
|
|
||||||
// check if sku is blank
|
// check if sku is blank
|
||||||
if ((empty($sku)) || ($sku == null))
|
if ((empty($sku)) || ($sku == null))
|
||||||
|
|
@ -207,7 +244,10 @@ class WarrantyController extends APIController
|
||||||
// battery
|
// battery
|
||||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
if ($batt == null)
|
if ($batt == null)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Invalid battery SKU.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Invalid battery SKU.');
|
return new APIResponse(false, 'Invalid battery SKU.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -245,6 +285,7 @@ class WarrantyController extends APIController
|
||||||
}
|
}
|
||||||
catch (UniqueConstraintViolationException $e)
|
catch (UniqueConstraintViolationException $e)
|
||||||
{
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Duplicate serial encountered.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Duplicate serial encountered.');
|
return new APIResponse(false, 'Duplicate serial encountered.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,10 +294,13 @@ class WarrantyController extends APIController
|
||||||
'warranty' => $this->generateWarrantyData($warr),
|
'warranty' => $this->generateWarrantyData($warr),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// log creation of warranty data
|
||||||
|
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
return new APIResponse(true, 'Warranty registered.', $data);
|
return new APIResponse(true, 'Warranty registered.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function claim(Request $req, EntityManagerInterface $em, $id)
|
public function claim(Request $req, EntityManagerInterface $em, $id, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('warranty.claim', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.claim', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -264,26 +308,50 @@ class WarrantyController extends APIController
|
||||||
$params = [
|
$params = [
|
||||||
'serial',
|
'serial',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$serial = $req->request->get('serial');
|
||||||
|
|
||||||
|
// set up information for logging
|
||||||
|
// get user from header
|
||||||
|
$user_id = $_SERVER['HTTP_X_CATA_API_KEY'];
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $serial,
|
||||||
|
'id' => $id,
|
||||||
|
];
|
||||||
|
$action = 'claim';
|
||||||
|
$source = WarrantySource::CAPI;
|
||||||
|
|
||||||
$msg = $this->checkRequiredParameters($req, $params);
|
$msg = $this->checkRequiredParameters($req, $params);
|
||||||
if ($msg)
|
if ($msg)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, $msg, $user_id, $action, $source);
|
||||||
return new APIResponse(false, $msg);
|
return new APIResponse(false, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
// no warranty
|
// no warranty
|
||||||
$warr = $em->getRepository(Warranty::class)->find($id);
|
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||||
if ($warr == null)
|
if ($warr == null)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'No warranty found with that id.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||||
|
}
|
||||||
|
|
||||||
// warranty is not active
|
// warranty is not active
|
||||||
if (!$warr->canClaim())
|
if (!$warr->canClaim())
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Warranty is not active.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Warranty is not active.');
|
return new APIResponse(false, 'Warranty is not active.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// check if new serial has been used
|
// check if new serial has been used
|
||||||
$serial = $req->request->get('serial');
|
|
||||||
$clean_serial = $this->cleanSerial($serial);
|
$clean_serial = $this->cleanSerial($serial);
|
||||||
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||||
if ($check_warr != null)
|
if ($check_warr != null)
|
||||||
|
{
|
||||||
|
$logger->logWarrantyInfo($log_data, 'Serial for replacement has already been used.', $user_id, $action, $source);
|
||||||
return new APIResponse(false, 'Serial for replacement has already been used.');
|
return new APIResponse(false, 'Serial for replacement has already been used.');
|
||||||
|
}
|
||||||
|
|
||||||
// set status to claim
|
// set status to claim
|
||||||
$warr->setStatus(WarrantyStatus::CLAIMED)
|
$warr->setStatus(WarrantyStatus::CLAIMED)
|
||||||
|
|
@ -309,6 +377,7 @@ class WarrantyController extends APIController
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
// TODO: claim log
|
// TODO: claim log
|
||||||
|
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
return new APIResponse(true, 'Warranty claimed successfully.');
|
return new APIResponse(true, 'Warranty claimed successfully.');
|
||||||
}
|
}
|
||||||
|
|
@ -704,5 +773,4 @@ class WarrantyController extends APIController
|
||||||
$customers = $em->getRepository(Customer::class)->findBy(['phone_mobile' => $number]);
|
$customers = $em->getRepository(Customer::class)->findBy(['phone_mobile' => $number]);
|
||||||
return $customers;
|
return $customers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ use App\Entity\CustomerVehicle;
|
||||||
|
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
use App\Ramcar\WarrantyStatus;
|
use App\Ramcar\WarrantyStatus;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use App\Service\WarrantyHandler;
|
use App\Service\WarrantyHandler;
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
@ -149,7 +151,7 @@ class WarrantyController extends Controller
|
||||||
return $this->render('warranty/form.html.twig', $params);
|
return $this->render('warranty/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSubmit(Request $req, ValidatorInterface $validator)
|
public function addSubmit(Request $req, ValidatorInterface $validator, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
$this->denyAccessUnlessGranted('warranty.add', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -255,6 +257,28 @@ class WarrantyController extends Controller
|
||||||
$em->persist($obj);
|
$em->persist($obj);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
// log warranty creation
|
||||||
|
$action = 'create';
|
||||||
|
$user_id = $this->getUser()->getUsername();
|
||||||
|
$source = WarrantySource::ADMIN_PANEL;
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $req->request->get('serial'),
|
||||||
|
'warranty_class' => $req->request->get('warranty_class'),
|
||||||
|
'first_name' => $req->request->get('first_name'),
|
||||||
|
'last_name' => $req->request->get('last_name'),
|
||||||
|
'mobile_number' => $req->request->get('mobile_number'),
|
||||||
|
'date_purchase' => $req->request->get('date_purchase'),
|
||||||
|
'claim_from' => $req->request->get('claim_from'),
|
||||||
|
'status' => $req->request->get('status'),
|
||||||
|
'date_claim' => $req->request->get('date_claim'),
|
||||||
|
'date_expire' => $req->request->get('date_expire'),
|
||||||
|
'battery_model' => $req->request->get('battery_model'),
|
||||||
|
'battery_size' => $req->request->get('battery_size'),
|
||||||
|
'sap_battery' => $req->request->get('sap_battery'),
|
||||||
|
'plate_number' => $req->request->get('plate_number'),
|
||||||
|
];
|
||||||
|
$logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
|
|
||||||
// return successful response
|
// return successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => 'Changes have been saved!'
|
'success' => 'Changes have been saved!'
|
||||||
|
|
@ -640,8 +664,12 @@ class WarrantyController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
|
// error_log('Creating warranty for serial ' . $serial . ' and plate number ' . $plate_number);
|
||||||
|
$user_id = $this->getUser()->getUsername();
|
||||||
|
$source = WarrantySource::BULK_UPLOAD;
|
||||||
|
|
||||||
|
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class,
|
||||||
|
$user_id, $source);
|
||||||
|
|
||||||
$wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -677,4 +705,5 @@ class WarrantyController extends Controller
|
||||||
// remove spaces and make upper case
|
// remove spaces and make upper case
|
||||||
return strtoupper(str_replace(' ', '', $plate));
|
return strtoupper(str_replace(' ', '', $plate));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
163
src/Entity/WarrantyAPILog.php
Normal file
163
src/Entity/WarrantyAPILog.php
Normal file
|
|
@ -0,0 +1,163 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity
|
||||||
|
* @ORM\Table(name="warranty_api_log")
|
||||||
|
*/
|
||||||
|
class WarrantyAPILog
|
||||||
|
{
|
||||||
|
// unique id
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="integer")
|
||||||
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
// date created
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime")
|
||||||
|
*/
|
||||||
|
protected $date_create;
|
||||||
|
|
||||||
|
// user that created warranty
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=32)
|
||||||
|
*/
|
||||||
|
protected $api_user;
|
||||||
|
|
||||||
|
// data sent
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="json")
|
||||||
|
*/
|
||||||
|
protected $all_data;
|
||||||
|
|
||||||
|
// errors
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="array", nullable=true)
|
||||||
|
*/
|
||||||
|
protected $errors;
|
||||||
|
|
||||||
|
// action
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=20)
|
||||||
|
*/
|
||||||
|
protected $action;
|
||||||
|
|
||||||
|
// source
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=30)
|
||||||
|
*/
|
||||||
|
protected $source;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->date_create = new DateTime();
|
||||||
|
$this->errors = new ArrayCollection();
|
||||||
|
$this->all_data = [];
|
||||||
|
$this->action = '';
|
||||||
|
$this->source = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateCreate(DateTime $date_create)
|
||||||
|
{
|
||||||
|
$this->date_create = $date_create;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateCreate()
|
||||||
|
{
|
||||||
|
return $this->date_create;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setApiUser($api_user)
|
||||||
|
{
|
||||||
|
$this->api_user = $api_user;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiUser()
|
||||||
|
{
|
||||||
|
return $this->api_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAllData($id, $value)
|
||||||
|
{
|
||||||
|
$this->all_data[$id] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAllData($all_data)
|
||||||
|
{
|
||||||
|
$this->all_data = $all_data;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllData($id)
|
||||||
|
{
|
||||||
|
// return null if we don't have it
|
||||||
|
if (!isset($this->all_data[$id]))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return $this->all_data[$id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrors()
|
||||||
|
{
|
||||||
|
return $this->errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setErrors(array $errors)
|
||||||
|
{
|
||||||
|
$this->errors = new ArrayCollection();
|
||||||
|
|
||||||
|
foreach ($errors as $error)
|
||||||
|
{
|
||||||
|
$this->errors->add($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clearErrors()
|
||||||
|
{
|
||||||
|
$this->errors = new ArrayCollection();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAction($action)
|
||||||
|
{
|
||||||
|
$this->action = $action;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAction()
|
||||||
|
{
|
||||||
|
return $this->action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSource($source)
|
||||||
|
{
|
||||||
|
$this->source = $source;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return $this->source;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/Ramcar/WarrantySource.php
Normal file
22
src/Ramcar/WarrantySource.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ramcar;
|
||||||
|
|
||||||
|
class WarrantySource extends NameValue
|
||||||
|
{
|
||||||
|
const CAPI = 'capi';
|
||||||
|
const RAPI = 'rapi';
|
||||||
|
const ADMIN_PANEL = 'admin_panel';
|
||||||
|
const BULK_UPLOAD = 'bulk_upload';
|
||||||
|
const MOBILE = 'mobile';
|
||||||
|
const COMMAND = 'command';
|
||||||
|
|
||||||
|
const COLLECTION = [
|
||||||
|
'capi' => 'Third Party API',
|
||||||
|
'rapi' => 'Rider API',
|
||||||
|
'admin_panel' => 'Admin Panel',
|
||||||
|
'bulk_upload' => 'Bulk Upload',
|
||||||
|
'mobile' => 'Mobile API',
|
||||||
|
'command' => 'Command',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -41,6 +41,7 @@ use App\Ramcar\CustomerNotWaitReason;
|
||||||
use App\Ramcar\NoTradeInReason;
|
use App\Ramcar\NoTradeInReason;
|
||||||
use App\Ramcar\WillingToWaitContent;
|
use App\Ramcar\WillingToWaitContent;
|
||||||
use App\Ramcar\HubCriteria;
|
use App\Ramcar\HubCriteria;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use App\Service\InvoiceGeneratorInterface;
|
use App\Service\InvoiceGeneratorInterface;
|
||||||
use App\Service\JobOrderHandlerInterface;
|
use App\Service\JobOrderHandlerInterface;
|
||||||
|
|
@ -1025,7 +1026,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
$user_id = $user->getUsername();
|
||||||
|
$source = WarrantySource::ADMIN_PANEL;
|
||||||
|
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber());
|
error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber());
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ use App\Ramcar\JOEventType;
|
||||||
use App\Ramcar\InvoiceStatus;
|
use App\Ramcar\InvoiceStatus;
|
||||||
use App\Ramcar\ModeOfPayment;
|
use App\Ramcar\ModeOfPayment;
|
||||||
use App\Ramcar\InvoiceCriteria;
|
use App\Ramcar\InvoiceCriteria;
|
||||||
|
use App\Ramcar\WarrantySource;
|
||||||
|
|
||||||
use App\Service\RiderAPIHandlerInterface;
|
use App\Service\RiderAPIHandlerInterface;
|
||||||
use App\Service\RedisClientProvider;
|
use App\Service\RedisClientProvider;
|
||||||
|
|
@ -598,7 +599,10 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class);
|
// for riders, use rider session id
|
||||||
|
$user_id = $this->session->getID();
|
||||||
|
$source = WarrantySource::RAPI;
|
||||||
|
$this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send mqtt event (fulfilled)
|
// send mqtt event (fulfilled)
|
||||||
|
|
|
||||||
37
src/Service/WarrantyAPILogger.php
Normal file
37
src/Service/WarrantyAPILogger.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Entity\WarrantyAPILog;
|
||||||
|
|
||||||
|
class WarrantyAPILogger
|
||||||
|
{
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logWarrantyInfo($log_data, $error, $user_id, $action, $source)
|
||||||
|
{
|
||||||
|
$log_entry = new WarrantyAPILog();
|
||||||
|
|
||||||
|
$err_aray = [];
|
||||||
|
$err_array[] = $error;
|
||||||
|
|
||||||
|
$json_data = json_encode($log_data);
|
||||||
|
|
||||||
|
$log_entry->setApiUser($user_id)
|
||||||
|
->setErrors($err_array)
|
||||||
|
->setAllData($json_data)
|
||||||
|
->setAction($action)
|
||||||
|
->setSource($source);
|
||||||
|
|
||||||
|
$this->em->persist($log_entry);
|
||||||
|
$this->em->flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,8 @@ use App\Entity\SAPBattery;
|
||||||
use App\Entity\BatteryModel;
|
use App\Entity\BatteryModel;
|
||||||
use App\Entity\CustomerVehicle;
|
use App\Entity\CustomerVehicle;
|
||||||
|
|
||||||
|
use App\Service\WarrantyAPILogger;
|
||||||
|
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
@ -19,18 +21,23 @@ use DateInterval;
|
||||||
class WarrantyHandler
|
class WarrantyHandler
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em, WarrantyAPILogger $logger)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number,
|
public function createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number,
|
||||||
$batt_list, DateTime $date_purchase, $warranty_class)
|
$batt_list, DateTime $date_purchase, $warranty_class, $user_id, $source)
|
||||||
{
|
{
|
||||||
// new warranty
|
// new warranty
|
||||||
$warranty = new Warranty();
|
$warranty = new Warranty();
|
||||||
|
|
||||||
|
$bmodel_name = '';
|
||||||
|
$bsize_name ='';
|
||||||
|
$sap_batt_id = '';
|
||||||
foreach ($batt_list as $battery)
|
foreach ($batt_list as $battery)
|
||||||
{
|
{
|
||||||
// get the battery model and battery size
|
// get the battery model and battery size
|
||||||
|
|
@ -43,10 +50,12 @@ class WarrantyHandler
|
||||||
if ($bty_model != null)
|
if ($bty_model != null)
|
||||||
{
|
{
|
||||||
$warranty->setBatteryModel($bty_model);
|
$warranty->setBatteryModel($bty_model);
|
||||||
|
$bmodel_name = $bty_model->getName();
|
||||||
}
|
}
|
||||||
if ($bty_size != null)
|
if ($bty_size != null)
|
||||||
{
|
{
|
||||||
$warranty->setBatterySize($bty_size);
|
$warranty->setBatterySize($bty_size);
|
||||||
|
$bsize_name = $bty_size->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
$sap_code = $battery->getSAPCode();
|
$sap_code = $battery->getSAPCode();
|
||||||
|
|
@ -57,6 +66,7 @@ class WarrantyHandler
|
||||||
if ($sap_battery != null)
|
if ($sap_battery != null)
|
||||||
{
|
{
|
||||||
$warranty->setSAPBattery($sap_battery);
|
$warranty->setSAPBattery($sap_battery);
|
||||||
|
$sap_batt_id = $sap_battery->getID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +97,22 @@ class WarrantyHandler
|
||||||
$this->em->persist($warranty);
|
$this->em->persist($warranty);
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
|
||||||
|
// log warranty creation
|
||||||
|
$action = 'create';
|
||||||
|
$log_data = [
|
||||||
|
'serial' => $serial,
|
||||||
|
'warranty_class' => $warranty_class,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name,
|
||||||
|
'mobile_number' => $mobile_number,
|
||||||
|
'date_purchase' => $date_purchase->format('d-M-y'),
|
||||||
|
'date_expire' => $date_expire->format('d-M-y'),
|
||||||
|
'battery_model' => $bmodel_name,
|
||||||
|
'battery_size' => $bsize_name,
|
||||||
|
'sap_battery' => $sap_batt_id,
|
||||||
|
'plate_number' => $plate_number,
|
||||||
|
];
|
||||||
|
$this->logger->logWarrantyInfo($log_data, '', $user_id, $action, $source);
|
||||||
// update customer vehicle with warranty info
|
// update customer vehicle with warranty info
|
||||||
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
$this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue