diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml index 1934a1b1..da41058d 100644 --- a/config/routes/rider.yaml +++ b/config/routes/rider.yaml @@ -56,3 +56,8 @@ 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] diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 3f02d1f4..c429ad79 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -3,6 +3,7 @@ class DashboardMap { this.options = options; this.rider_markers = rider_markers; this.cust_markers = cust_markers; + this.rider_availability = {}; // layer groups this.layer_groups = { @@ -146,6 +147,49 @@ class DashboardMap { } } + putMarkerWithLabel(id, lat, lng, markers, icon, layer_group, popup_url, name) { + var my = this; + // existing marker + if (markers.hasOwnProperty(id)) { + markers[id].setLatLng(L.latLng(lat, lng)); + return; + } + + // new marker + // add label + markers[id] = L.marker( + [lat, lng], + { icon: icon } + ); + + var marker_label = id + ' - ' + name; + + markers[id].bindTooltip(marker_label, + { + permanent: true, + direction: 'right' + } + ); + + markers[id].addTo(layer_group); + + if (my.options.enable_popup) { + markers[id].bindPopup('Loading...'); + + // bind ajax for popup + markers[id].on('click', function(e) { + var popup = e.target.getPopup(); + var url = popup_url.replace('[id]', id); + console.log(url); + $.get(url).done(function(data) { + popup.setContent(data); + popup.update(); + }); + }); + } + } + + putCustomerMarker(id, lat, lng) { this.putMarker( id, @@ -170,6 +214,8 @@ class DashboardMap { this.layer_groups.customer.removeLayer(markers[id]); this.layer_groups.mobile_customer.removeLayer(markers[id]); + + delete markers[id]; } putMobileCustomerMarker(id, lat, lng) { @@ -184,27 +230,29 @@ class DashboardMap { ); } - putRiderAvailableMarker(id, lat, lng) { - this.putMarker( + putRiderAvailableMarker(id, lat, lng, name) { + this.putMarkerWithLabel( id, lat, lng, this.rider_markers, this.options.icons.rider_available, this.layer_groups.rider_available, - this.options.rider_popup_url + this.options.rider_popup_url, + name ); } - putRiderActiveJOMarker(id, lat, lng) { - this.putMarker( + putRiderActiveJOMarker(id, lat, lng, name) { + this.putMarkerWithLabel( id, lat, lng, this.rider_markers, this.options.icons.rider_active_jo, this.layer_groups.rider_active_jo, - this.options.rider_popup_url + this.options.rider_popup_url, + name ); } @@ -219,6 +267,8 @@ class DashboardMap { this.layer_groups.rider_active_jo.removeLayer(markers[id]); this.layer_groups.rider_available.removeLayer(markers[id]); + + delete markers[id]; } loadLocations(location_url) { @@ -252,11 +302,12 @@ 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); + my.putRiderActiveJOMarker(id, lat, lng, name); else - my.putRiderAvailableMarker(id, lat, lng); + my.putRiderAvailableMarker(id, lat, lng, name); }); // console.log(rider_markers); diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 0e6bdb31..c3f4db0e 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -1,7 +1,8 @@ class MapEventHandler { - constructor(options, dashmap) { + constructor(options, dashmap, ssl) { this.options = options; this.dashmap = dashmap; + this.ssl = ssl; } connect(user_id, host, port) { @@ -11,7 +12,7 @@ class MapEventHandler { this.mqtt = new Paho.MQTT.Client(host, port, client_id); var options = { - // useSSL: true, + useSSL: this.ssl, timeout: 3, invocationContext: this, onSuccess: this.onConnect.bind(this), @@ -35,6 +36,10 @@ class MapEventHandler { // subscribe to rider status console.log('subscribing to ' + my.options.channels.rider_status); my.mqtt.subscribe(my.options.channels.rider_status); + + // subscribe to rider availability + console.log('subscribing to ' + my.options.channels.rider_availability); + my.mqtt.subscribe(my.options.channels.rider_availability); } if (my.options.track_jo) { @@ -55,7 +60,7 @@ class MapEventHandler { onMessage(msg) { // console.log(msg); - console.log('received message'); + // console.log('received message'); var channel = msg.destinationName; var chan_split = channel.split('/'); @@ -73,12 +78,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 +130,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/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;