Add logging for raffle when doing a serial check, creating and updating a warranty. #717

This commit is contained in:
Korina Cordero 2022-11-14 06:32:24 +00:00
parent b1d7777726
commit f2a661f696
6 changed files with 432 additions and 192 deletions

View file

@ -277,8 +277,8 @@ services:
arguments:
$em: "@doctrine.orm.entity_manager"
# warranty logger for app
App\Service\WarrantyLogger:
# warranty logger for raffle
App\Service\WarrantyRaffleLogger:
arguments:
$em: "@doctrine.orm.entity_manager"

View file

@ -41,7 +41,8 @@ use App\Service\RiderTracker;
use App\Service\MapTools;
use App\Service\InventoryManager;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\WarrantyLogger;
use App\Service\WarrantyRaffleLogger;
use App\Service\WarrantyAPILogger;
use App\Service\PromoLogger;
use App\Service\HubSelector;
use App\Service\HubDistributor;
@ -3362,7 +3363,7 @@ class APIController extends Controller implements LoggedController
return $clean_serial;
}
public function warrantyCheck($serial, EntityManagerInterface $em, Request $req)
public function warrantyCheck($serial, EntityManagerInterface $em, Request $req, WarrantyRaffleLogger $raffle_logger)
{
// check required parameters and api key
$required_params = [];
@ -3386,6 +3387,24 @@ class APIController extends Controller implements LoggedController
$today = new DateTime();
$user_id = $req->query->get('api_key');
$raffle_data = [
'user_id' => $user_id,
'serial' => $serial,
'warranty_id' => null,
'action' => '',
'bmodel_name' => '',
'bsize_name' => '',
'first_name' => '',
'last_name' => '',
'plate_number' => '',
'contact_num' => '',
'email' => '',
'address' => '',
];
$data_sent = [];
// if we have a warranty entry for the serial already
if ($warr != null)
{
@ -3445,6 +3464,16 @@ class APIController extends Controller implements LoggedController
'dealer_address' => $warr->getDealerAddress() ?? '',
'branch_code' => $warr->getDealerBranchCode() ?? '',
];
// set customer info and action for raffle log
$raffle_data['action'] = 'serial_check_customer';
$raffle_data['first_name'] = $customer['first_name'];
$raffle_data['last_name'] = $customer['last_name'];
$raffle_data['plate_number'] = $customer['plate_number'];
$raffle_data['email'] = $customer['email'];
$raffle_data['contact_num'] = $customer['contact_num'];
$raffle_data['address'] = $customer['address'];
$raffle_data['warranty_id'] = $warr->getID();
}
else
{
@ -3467,6 +3496,9 @@ class APIController extends Controller implements LoggedController
'dealer_address' => '',
'branch_code' => '',
];
// set action for raffle log
$raffle_data['action'] = 'serial_check_not_customer';
}
}
else
@ -3490,6 +3522,9 @@ class APIController extends Controller implements LoggedController
'dealer_address' => '',
'branch_code' => '',
];
// set action for raffle log
$raffle_data['action'] = 'serial_check_customer';
}
$sku = $warr_serial->getSKU();
@ -3544,6 +3579,13 @@ class APIController extends Controller implements LoggedController
$res->setData($data);
// set the rest of the raffle log entry
$raffle_data['bmodel_name'] = $battery['brand'];
$raffle_data['bsize_name'] = $battery['size'];
// log the raffle log
$raffle_logger->logRaffleInfo($data_sent, $raffle_data);
return $res->getReturnResponse();
}
@ -3578,7 +3620,7 @@ class APIController extends Controller implements LoggedController
}
public function warrantyRegister($serial, EntityManagerInterface $em, Request $req, KernelInterface $kernel, RisingTideGateway $rt,
TranslatorInterface $trans, WarrantyLogger $logger)
TranslatorInterface $trans, WarrantyRaffleLogger $raffle_logger, WarrantyAPILogger $logger)
{
// check required parameters and api key
$required_params = [
@ -3593,7 +3635,7 @@ class APIController extends Controller implements LoggedController
$warr_card = $req->files->get('warr_card');
// normalize serial
$serial = $this->cleanSerial($serial);
$serial = $this->cleanSerial($serial);
// $serial = trim(strtoupper($serial));
// process picture uploads
@ -3623,7 +3665,7 @@ class APIController extends Controller implements LoggedController
// update warranty
$res = $this->updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename, $wcard_filename,
$logger, $log_data, $user_id, $action, $source);
$logger, $log_data, $user_id, $action, $source, $raffle_logger);
$em->flush();
@ -3943,9 +3985,24 @@ class APIController extends Controller implements LoggedController
}
*/
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null,
$logger, $log_data, $user_id, $action, $source)
protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null, $logger, $log_data, $user_id, $action, $source, $raffle_logger)
{
// prepare raffle log entry
$raffle_data = [
'user_id' => $user_id,
'serial' => $serial,
'warranty_id' => null,
'action' => '',
'bmodel_name' => '',
'bsize_name' => '',
'first_name' => '',
'last_name' => '',
'plate_number' => '',
'contact_num' => '',
'email' => '',
'address' => '',
];
// get serial
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
if ($warr_serial == null)
@ -3985,6 +4042,9 @@ class APIController extends Controller implements LoggedController
}
$sms_msg = $trans->trans('warranty_update_confirm');
// update raffle data action
$raffle_data['action'] = 'warranty_update';
}
else
{
@ -3993,6 +4053,9 @@ class APIController extends Controller implements LoggedController
// set warranty source
$warr->setCreateSource($source);
// update raffle data action
$raffle_data['action'] = 'warranty_create';
}
// get sap battery
@ -4090,6 +4153,30 @@ class APIController extends Controller implements LoggedController
// error_log('sending sms to - ' . $this->session->getPhoneNumber());
$rt->sendSMS($this->session->getPhoneNumber(), $trans->trans('message.battery_brand_allcaps'), $sms_msg);
// prepare the rest of the raffle log entry
$raffle_data['warranty_id'] = $warr->getID();
$raffle_data['bmodel_name'] = $sap_bty->getBrand()->getName();
$raffle_data['bsize_name'] = $sap_bty->getSize()->getName();
$raffle_data['first_name'] = $req->request->get('first_name', '');
$raffle_data['last_name'] = $req->request->get('last_name', '');
$raffle_data['plate_number'] = $plate;
$raffle_data['contact_num'] = $req->request->get('contact_num', '');
$raffle_data['email'] = $req->request->get('email', '');
$raffle_data['address'] = $req->request->get('cust_address', '');
$data_sent = [
'plate_number' => $req->request->get('plate_number'),
'first_name' => $req->request->get('first_name'),
'last_name' => $req->request->get('last_name'),
'date_purchase' => $req->request->get('date_purchase'),
'address' => $req->request->get('cust_address', ''),
'email' => $req->request->get('email', ''),
'contact_num' => $req->request->get('contact_num', ''),
];
// log raffle data
$raffle_logger->logRaffleInfo($data_sent, $raffle_data);
return $res;
}

View file

@ -1,150 +0,0 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="warranty_log")
*/
class WarrantyLog
{
// 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 $data_sent;
// errors
/**
* @ORM\Column(type="string", length=80)
*/
protected $error;
// 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->error = '';
$this->data_sent = [];
$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 addDataSent($id, $value)
{
$this->data_sent[$id] = $value;
return $this;
}
public function setDataSent($data_sent)
{
$this->data_sent = $data_sent;
return $this;
}
public function getDataSent($id)
{
// return null if we don't have it
if (!isset($this->data_sent[$id]))
return null;
return $this->data_sent[$id];
}
public function getError()
{
return $this->error;
}
public function setError($error)
{
return $this->error;
}
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;
}
}

View file

@ -0,0 +1,295 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use DateTime;
/**
* @ORM\Entity
* @ORM\Table(name="warranty_raffle_log")
*/
class WarrantyRaffleLog
{
// 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 $data_sent;
// serial
/**
* @ORM\Column(type="string", length=20)
*/
protected $serial;
// warranty id
/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $warranty_id;
// action done
/**
* @ORM\Column(type="string", length=50)
*/
protected $action;
// battery model name
/**
* @ORM\Column(type="string", length=80)
*/
protected $batt_model_name;
// battery size name
/**
* @ORM\Column(type="string", length=80)
*/
protected $batt_size_name;
// customer first name
/**
* @ORM\Column(type="string", length=80)
*/
protected $first_name;
// customer last name
/**
* @ORM\Column(type="string", length=80)
*/
protected $last_name;
// plate number
/**
* @ORM\Column(type="string", length=100)
*/
protected $plate_number;
// contact number
/**
* @ORM\Column(type="string", length=30)
*/
protected $contact_num;
// email
/**
* @ORM\Column(type="string", length=80)
*/
protected $email;
// customer address
/**
* @ORM\Column(type="string", length=280)
*/
protected $address;
public function __construct()
{
$this->date_create = new DateTime();
$this->data_sent = [];
$this->serial = '';
$this->api_user = '';
$this->action = '';
$this->batt_model_name = '';
$this->batt_size_name = '';
$this->first_name = '';
$this->last_name = '';
$this->plate_number = '';
$this->contact_num = '';
$this->email = '';
$this->address = '';
}
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 addDataSent($id, $value)
{
$this->data_sent[$id] = $value;
return $this;
}
public function setDataSent($data_sent)
{
$this->data_sent = $data_sent;
return $this;
}
public function getDataSent($id)
{
// return null if we don't have it
if (!isset($this->data_sent[$id]))
return null;
return $this->data_sent[$id];
}
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
public function getSerial()
{
return $this->serial;
}
public function setWarrantyID($warranty_id)
{
$this->warranty_id = $warranty_id;
return $this;
}
public function getWarrantyID()
{
return $this->warranty_id;
}
public function setAction($action)
{
$this->action = $action;
return $this;
}
public function getAction()
{
return $this->action;
}
public function setBattModelName($batt_model_name)
{
$this->batt_model_name = $batt_model_name;
return $this;
}
public function getBattModelName()
{
return $this->batt_model_name;
}
public function setBattSizeName($batt_size_name)
{
$this->batt_size_name = $batt_size_name;
return $this;
}
public function getBattSizeName()
{
return $this->batt_size_name;
}
public function setFirstName($first_name)
{
$this->first_name = $first_name;
return $this;
}
public function getFirstName()
{
return $this->first_name;
}
public function setLastName($last_name)
{
$this->last_name = $last_name;
return $this;
}
public function getLastName()
{
return $this->last_name;
}
public function setPlateNumber($plate_number)
{
$this->plate_number = $plate_number;
return $this;
}
public function getPlateNumber()
{
return $this->plate_number;
}
public function setContactNumber($contact_num)
{
$this->contact_num = $contact_num;
return $this;
}
public function getContactNumber()
{
return $this->contact_num;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setAddress($address)
{
$this->cust_address = $address;
return $this;
}
public function getAddress()
{
return $this->cust_address;
}
}

View file

@ -1,33 +0,0 @@
<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\WarrantyLog;
class WarrantyLogger
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function logWarrantyInfo($log_data, $error, $user_id, $action, $source)
{
$log_entry = new WarrantyAPILog();
$log_entry->setApiUser($user_id)
->setError($error)
->setDataSent($log_data)
->setAction($action)
->setSource($source);
$this->em->persist($log_entry);
$this->em->flush();
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\WarrantyRaffleLog;
class WarrantyRaffleLogger
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function logRaffleInfo($data_sent, $raffle_log_data)
{
$log_entry = new WarrantyRaffleLog();
$log_entry->setApiUser($raffle_log_data['user_id'])
->setDataSent($data_sent)
->setSerial($raffle_log_data['serial'])
->setWarrantyID($raffle_log_data['warranty_id'])
->setAction($raffle_log_data['action'])
->setBattModelName($raffle_log_data['bmodel_name'])
->setBattSizename($raffle_log_data['bsize_name'])
->setFirstName($raffle_log_data['first_name'])
->setLastName($raffle_log_data['last_name'])
->setPlateNumber($raffle_log_data['plate_number'])
->setContactNumber($raffle_log_data['contact_num'])
->setEmail($raffle_log_data['email'])
->setAddress($raffle_log_data['address']);
$this->em->persist($log_entry);
$this->em->flush();
}
}