From 48b509ad431c63f663fe07bb5fd5a72431893cdc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Jul 2019 07:42:22 +0000 Subject: [PATCH] Return warranty information with customer vehicle information for job order history. #227 --- src/Controller/APIController.php | 58 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9642bb3b..81f87f05 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1691,16 +1691,66 @@ class APIController extends Controller 'status' => $status, ]; - // customer vehicle + // customer vehicle and warranty $cv = $jo->getCustomerVehicle(); + + // NOTE: Modify the search for the latest warranty + // get latest warranty using plate number + $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cv->getPlateNumber()], + ['date_create' => 'desc']); + + $warranty = current($warranty_results); + + // check for null values for battery and date claim and date expire + $batt_model = ''; + $batt_size = ''; + $sap_batt = ''; + $claim_date = ''; + $expiry_date = ''; + + if (!(is_null($warranty->getBatteryModel()))) { + $batt_model = $warranty->getBatteryModel()->getName(); + } + if (!(is_null($warranty->getBatterySize()))) { + $batt_size = $warranty->getBattyerSize()->getName(); + } + if (!(is_null($warranty->getSAPBattery()))) { + $sap_batt = $warranty->getSAPBattery()->getID(); + } + if (!(is_null($warranty->getDateClaim()))) { + $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); + } + if (!(is_null($warranty->getDateExpire()))) { + $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); + } + + $warr = []; + $warr[] = [ + 'id' => $warranty->getID(), + 'serial' => $warranty->getSerial(), + 'warranty_class' => $warranty->getWarrantyClass(), + 'plate_number' => $warranty->getPlateNumber(), + 'first_name' => $warranty->getFirstName(), + 'last_name' => $warranty->getLastName(), + 'mobile_number' => $warranty->getMobileNumber(), + 'battery_model' => $batt_model, + 'battery_size' => $batt_size, + 'sap_battery' => $sap_batt, + 'status' => $warranty->getStatus(), + 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), + 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), + 'date_expire' => $expiry_date, + 'date_claim' => $claim_date, + 'claim_from' => $warranty->getClaimedFrom(), + 'is_activated' => $warranty->isActivated() ? 1 : 0, + ]; + $jo_data['customer_vehicle'] = [ 'id' => $cv->getID(), 'plate_number' => $cv->getPlateNumber(), + 'warranty' => $warr, ]; - // TODO: mogol get warranty object for the plate number. Return only - // latest warranty. - // rider $rider = $jo->getRider(); if ($rider != null)