diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml index 1934a1b1..6c4911d0 100644 --- a/config/routes/rider.yaml +++ b/config/routes/rider.yaml @@ -56,3 +56,14 @@ rider_priority_down_jo: path: /riders/{id}/priority_down/{jo_id} controller: App\Controller\RiderController::priorityDownJO methods: [GET] + +rider_ajax_avialable: + path: /riders/{id}/available + controller: App\Controller\RiderController::ajaxAvailable + methods: [GET] + +rider_ajax_rider_name: + path: /riders/{id}/name + controller: App\Controller\RiderController::ajaxRiderName + methods: [GET] + diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 3f02d1f4..32f775ab 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -3,6 +3,8 @@ class DashboardMap { this.options = options; this.rider_markers = rider_markers; this.cust_markers = cust_markers; + this.rider_availability = {}; + this.rider_names = {}; // layer groups this.layer_groups = { @@ -252,14 +254,43 @@ class DashboardMap { $.each(riders, function(id, data) { var lat = data.latitude; var lng = data.longitude; + var name = ''; - if (data.has_jo) - my.putRiderActiveJOMarker(id, lat, lng); - else - my.putRiderAvailableMarker(id, lat, lng); + if (my.rider_names.hasOwnProperty(id)) { + name = my.rider_names[id]; + + if (data.has_jo) + my.putRiderActiveJOMarker(id, lat, lng, name); + else + my.putRiderAvailableMarker(id, lat, lng, name) + + } else { + getRiderName(id, my.options.rider_name_url, function(name) { + my.rider_names[id] = name; + + if (data.has_jo) + my.putRiderActiveJOMarker(id, lat, lng, name); + else + my.putRiderAvailableMarker(id, lat, lng, name) + }); + } }); // console.log(rider_markers); }); } } + +function getRiderName(id, url, callback) { + var name = ''; + var rider_url = url.replace('[id]', id); + + $.ajax({ + method: "GET", + url: rider_url + }).done(function(response) { + name = response.rider_name; + callback(name); + }); +} + diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 0e6bdb31..75334c63 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -73,12 +73,50 @@ class MapEventHandler { } handleRider(chan_split, payload) { - console.log("rider message"); + // console.log("rider message"); + var rider_id = chan_split[1]; switch (chan_split[2]) { + case "availability": + console.log("got availability for rider " + chan_split[1] + " - " + payload); + var obj = JSON.parse(payload); + + var status = obj.status; + console.log("status " + status); + switch (status) { + case 'rider_offline': + this.dashmap.rider_availability[chan_split[1]] = false; + this.dashmap.removeRiderMarker(chan_split[1]); + break; + case 'rider_online': + this.dashmap.rider_availability[chan_split[1]] = true; + var lat = parseFloat(obj.latitude); + var lng = parseFloat(obj.longitude); + + // cheeck if rider is available / unavailable + // TODO: make url not hardcoded + var dashmap = this.dashmap; + $.get('https://cmbdev.wildcard.cc/riders/' + chan_split[1] + '/available').done(function(data) { + console.log('rider availability - ' + data); + switch (data) { + case 'available': + console.log('putting available marker ' + chan_split[1] + ' ' + lat + ':' + lng); + dashmap.switchRiderStatus(chan_split[1], 'available'); + dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); + break; + case 'unavailable': + console.log('putting active jo marker ' + chan_split[1] + ' ' + lat + ':' + lng); + dashmap.switchRiderStatus(chan_split[1], 'jo'); + dashmap.putRiderActiveJOMarker(chan_split[1], lat, lng); + break; + } + }); + break; + } + break; case "location": - console.log("got location for rider " + chan_split[1] + " - " + payload); + // console.log("got location for rider " + chan_split[1] + " - " + payload var pl_split = payload.split(':'); - console.log(pl_split); + // console.log(pl_split); // check for correct format if (pl_split.length != 2) @@ -87,8 +125,21 @@ class MapEventHandler { var lat = parseFloat(pl_split[0]); var lng = parseFloat(pl_split[1]); - // TODO: check if available or not - this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); + var display_marker = true; + if (this.dashmap.rider_availability.hasOwnProperty(chan_split[1])) { + if (!this.dashmap.rider_availability[chan_split[1]]) { + console.log('NOT displaying marker for inactive rider'); + display_marker = false; + } + } else { + console.log('rider not in availability check'); + } + + // TODO: cache rider availability (available vs active jo) status and check before displaying icon + // NOTE: we really should fix our terms since available can mean many things + if (display_marker) { + this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); + } break; case "status": console.log("got status for rider " + chan_split[1] + " - " + payload); diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php index 43f5d6d6..763d4900 100644 --- a/src/Controller/RiderController.php +++ b/src/Controller/RiderController.php @@ -596,4 +596,38 @@ class RiderController extends Controller return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]); } + + /** + * @ParamConverter("rider", class="App\Entity\Rider") + */ + public function ajaxAvailable(EntityManagerInterface $em, Rider $rider) + { + $jo = $rider->getRiderActiveJobOrder(); + if ($jo == null || $jo->isClosed()) + $avail = 'available'; + else + $avail = 'unavailable'; + + $response = new Response( + $avail, + Response::HTTP_OK, + ['content-type' => 'text/plain'] + ); + return $response; + } + + /** + * @ParamConverter("rider", class="App\Entity\Rider") + */ + public function ajaxRiderName(EntityManagerInterface $em, Rider $rider) + { + $rider_name = ''; + if ($rider != null) + $rider_name = $rider->getFullName(); + + return $this->json([ + 'rider_name' => $rider_name, + ]); + } + } diff --git a/src/Ramcar/CMBServiceType.php b/src/Ramcar/CMBServiceType.php index 63d18f96..607b9c43 100644 --- a/src/Ramcar/CMBServiceType.php +++ b/src/Ramcar/CMBServiceType.php @@ -6,11 +6,13 @@ class CMBServiceType extends NameValue { const BATTERY_REPLACEMENT_NEW = 'battery_new'; const BATTERY_REPLACEMENT_WARRANTY = 'battery_warranty'; + const WARRANTY_CLAIM = 'warranty_claim'; const JUMPSTART = 'jumpstart'; const COLLECTION = [ 'battery_new' => 'Battery Sales', - 'battery_warranty' => 'Under Warranty', + 'battery_warranty' => 'Warranty Replacement', + 'warranty_claim' => 'Warranty Claim', 'jumpstart' => 'Jumpstart', ]; } diff --git a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php index 534600fb..ba94d8ee 100644 --- a/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/CMBInvoiceGenerator.php @@ -86,6 +86,10 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface case CMBServiceType::BATTERY_REPLACEMENT_WARRANTY: $this->processWarranty($total, $criteria, $invoice); break; + case CMBServiceType::WARRANTY_CLAIM: + // TODO: this will change once we confirm what needs to be computed + $this->processOtherServices($total, $invoice, $stype); + break; //case ServiceType::POST_RECHARGED: // $this->processRecharge($total, $invoice); // break; diff --git a/templates/home.html.twig b/templates/home.html.twig index 69cb59c0..9e784ab6 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -35,7 +35,8 @@ function initMap(r_markers, c_markers, icons) { 'zoom': 13, 'rider_popup_url': '/riders/[id]/popup', 'cust_popup_url': '/job-order/[id]/popup', - 'icons': icons + 'icons': icons, + 'rider_name_url': '/riders/[id]/name' }; var dashmap = new DashboardMap(options, r_markers, c_markers);