From 4652a82fff6ba5a83851c76b65503fb7100a0ea6 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Wed, 2 May 2018 21:12:49 +0800 Subject: [PATCH] Support new services #110 --- src/Controller/APIController.php | 36 +++++++++++++++++++++----------- src/Ramcar/ServiceType.php | 2 +- src/Service/InvoiceCreator.php | 17 +++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index b8736440..4a579109 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -690,7 +690,7 @@ class APIController extends Controller $required_params = [ 'service_type', 'cv_id', - 'batt_id', + // 'batt_id', 'trade_in', 'long', 'lat', @@ -784,13 +784,19 @@ class APIController extends Controller } // check battery - $batt = $em->getRepository(Battery::class)->find($req->request->get('batt_id')); - if ($batt == null) + $batt_id = $req->request->get('batt_id'); + if ($batt_id != null) { - $res->setError(true) - ->setErrorMessage('Invalid battery id'); - return $res->getReturnResponse(); + $batt = $em->getRepository(Battery::class)->find($batt_id); + if ($batt == null) + { + $res->setError(true) + ->setErrorMessage('Invalid battery id'); + return $res->getReturnResponse(); + } } + else + $batt = null; /* // put battery in criteria @@ -860,7 +866,7 @@ class APIController extends Controller $required_params = [ 'service_type', 'cv_id', - 'batt_id', + // 'batt_id', 'trade_in', ]; $em = $this->getDoctrine()->getManager(); @@ -915,13 +921,19 @@ class APIController extends Controller } // check battery - $batt = $em->getRepository(Battery::class)->find($req->request->get('batt_id')); - if ($batt == null) + $batt_id = $req->request->get('batt_id'); + if ($batt_id != null) { - $res->setError(true) - ->setErrorMessage('Invalid battery id'); - return $res->getReturnResponse(); + $batt = $em->getRepository(Battery::class)->find($batt_id); + if ($batt == null) + { + $res->setError(true) + ->setErrorMessage('Invalid battery id'); + return $res->getReturnResponse(); + } } + else + $batt = null; /* // put battery in criteria diff --git a/src/Ramcar/ServiceType.php b/src/Ramcar/ServiceType.php index 29bc03a7..83768bdc 100644 --- a/src/Ramcar/ServiceType.php +++ b/src/Ramcar/ServiceType.php @@ -11,7 +11,7 @@ class ServiceType extends NameValue const POST_RECHARGED = 'post_recharged'; const POST_REPLACEMENT = 'post_replacement'; const TIRE_REPAIR = 'tire'; - const OVERHEAT_ASSITANCE = 'overheat'; + const OVERHEAT_ASSISTANCE = 'overheat'; const EMERGENCY_REFUEL = 'fuel'; const COLLECTION = [ diff --git a/src/Service/InvoiceCreator.php b/src/Service/InvoiceCreator.php index 695a9e2b..b0588dc8 100644 --- a/src/Service/InvoiceCreator.php +++ b/src/Service/InvoiceCreator.php @@ -256,6 +256,18 @@ class InvoiceCreator } } + public function processOtherServices(&$total, $invoice, $stype) + { + $item = new InvoiceItem(); + $item->setInvoice($invoice) + ->setTitle('Service - ' . ServiceType::getName($stype)) + ->setQuantity(1) + ->setPrice(200.00); + $invoice->addItem($item); + + $total['total_price'] = 200.00; + } + public function processCriteria(InvoiceCriteria $criteria) { // initialize @@ -296,6 +308,11 @@ class InvoiceCreator break; case ServiceType::POST_REPLACEMENT: $this->processReplacement($total, $invoice); + break; + case ServiceType::TIRE_REPAIR: + case ServiceType::OVERHEAT_ASSISTANCE: + case ServiceType::EMERGENCY_REFUEL: + $this->processOtherServices($total, $invoice, $stype); } // TODO: check if any promo is applied