Add logging for warranty creation for rider API and JO fulfillment. #555

This commit is contained in:
Korina Cordero 2021-04-30 09:31:10 +00:00
parent c1d54ec626
commit e235667952
4 changed files with 42 additions and 5 deletions

View file

@ -664,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);
} }
} }

View file

@ -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());

View file

@ -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)

View file

@ -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);