diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index 494e6524..c078ac18 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -664,8 +664,12 @@ class WarrantyController extends Controller } // 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); } } diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index fd1fb2af..6b736bf2 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -41,6 +41,7 @@ use App\Ramcar\CustomerNotWaitReason; use App\Ramcar\NoTradeInReason; use App\Ramcar\WillingToWaitContent; use App\Ramcar\HubCriteria; +use App\Ramcar\WarrantySource; use App\Service\InvoiceGeneratorInterface; 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 error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber()); diff --git a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php index ae6d2199..6f1711c3 100644 --- a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php @@ -13,6 +13,7 @@ use App\Ramcar\JOEventType; use App\Ramcar\InvoiceStatus; use App\Ramcar\ModeOfPayment; use App\Ramcar\InvoiceCriteria; +use App\Ramcar\WarrantySource; use App\Service\RiderAPIHandlerInterface; 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) diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 6d01eb10..6b86849f 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -11,6 +11,8 @@ use App\Entity\SAPBattery; use App\Entity\BatteryModel; use App\Entity\CustomerVehicle; +use App\Service\WarrantyAPILogger; + use App\Ramcar\WarrantyClass; use DateTime; @@ -19,18 +21,23 @@ use DateInterval; class WarrantyHandler { protected $em; + protected $logger; - public function __construct(EntityManagerInterface $em) + public function __construct(EntityManagerInterface $em, WarrantyAPILogger $logger) { $this->em = $em; + $this->logger = $logger; } 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 $warranty = new Warranty(); + $bmodel_name = ''; + $bsize_name =''; + $sap_batt_id = ''; foreach ($batt_list as $battery) { // get the battery model and battery size @@ -43,10 +50,12 @@ class WarrantyHandler if ($bty_model != null) { $warranty->setBatteryModel($bty_model); + $bmodel_name = $bty_model->getName(); } if ($bty_size != null) { $warranty->setBatterySize($bty_size); + $bsize_name = $bty_size->getName(); } $sap_code = $battery->getSAPCode(); @@ -57,6 +66,7 @@ class WarrantyHandler if ($sap_battery != null) { $warranty->setSAPBattery($sap_battery); + $sap_batt_id = $sap_battery->getID(); } } } @@ -87,6 +97,22 @@ class WarrantyHandler $this->em->persist($warranty); $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 $this->updateCustomerVehicle($serial, $batt_list, $plate_number, $date_expire);