From d569c666e36e5ef88a87a8b2f70b3933b8eb5436 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 22 Jan 2020 08:18:30 +0000 Subject: [PATCH] Add warranty creation when JO is fulfilled to ResqJobOrderHandler. #305 --- .../JobOrderHandler/ResqJobOrderHandler.php | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index e91e855e..3f6a336c 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -38,6 +38,7 @@ use App\Ramcar\JORejectionReason; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; +use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\APNSClient; use App\Service\MapTools; @@ -59,12 +60,14 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface protected $validator; protected $translator; protected $country_code; + protected $wh; protected $template_hash; public function __construct(Security $security, EntityManagerInterface $em, InvoiceGeneratorInterface $ic, ValidatorInterface $validator, - TranslatorInterface $translator, string $country_code) + TranslatorInterface $translator, string $country_code, + WarrantyHandler $wh) { $this->em = $em; $this->ic = $ic; @@ -72,6 +75,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $this->validator = $validator; $this->translator = $translator; $this->country_code = $country_code; + $this->wh = $wh; $this->loadTemplates(); } @@ -703,6 +707,43 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ]; $mclient->sendEvent($obj, $payload); $mclient->sendRiderEvent($obj, $payload); + + // create the warranty if new battery only + if ($obj->getServiceType () == ServiceType::BATTERY_REPLACEMENT_NEW) + { + $serial = null; + $warranty_class = $obj->getWarrantyClass(); + $first_name = $obj->getCustomer()->getFirstName(); + $last_name = $obj->getCustomer()->getLastName(); + $mobile_number = $obj->getCustomer()->getPhoneMobile(); + + // check if date fulfilled is null + if ($obj->getDateFulfill() == null) + $date_purchase = $obj->getDateCreate(); + else + $date_purchase = $obj->getDateFulfill(); + + $plate_number = $this->wh->cleanPlateNumber($obj->getCustomerVehicle()->getPlateNumber()); + + $batt_list = array(); + $invoice = $obj->getInvoice(); + if (!empty($invoice)) + { + // get battery + $invoice_items = $invoice->getItems(); + foreach ($invoice_items as $item) + { + $battery = $item->getBattery(); + if ($battery != null) + { + $batt_list[] = $item->getBattery(); + } + } + } + + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class); + } + } }