Commit b2389697 by Alen Jose

Merge branch 'alen' into 'master'

amount calc See merge request alen/CMC-driver!3
parents 26911884 a7587807
...@@ -14,7 +14,7 @@ import { driver } from "../models/mymodel"; ...@@ -14,7 +14,7 @@ import { driver } from "../models/mymodel";
export class MyApp { export class MyApp {
@ViewChild(Nav) nav: Nav; @ViewChild(Nav) nav: Nav;
rootPage: any = "LandingPage"; rootPage:string;
pages: Array<{title: string, component: any}>; pages: Array<{title: string, component: any}>;
local:driver local:driver
...@@ -92,6 +92,7 @@ export class MyApp { ...@@ -92,6 +92,7 @@ export class MyApp {
this.oneSignal.handleNotificationOpened().subscribe(() => { this.oneSignal.handleNotificationOpened().subscribe(() => {
// do something when a notification is opened // do something when a notification is opened
// this.nav.setRoot('QuickridePage')
}); });
this.oneSignal.endInit(); this.oneSignal.endInit();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</div> </div>
<div class="cab_sidemenu_list"> <div class="cab_sidemenu_list">
<ul> <ul>
<li menuClose>Book Ride</li> <li menuClose (click)="openPage('HomePage')">My Rides</li>
<li menuClose>My Trips</li> <li menuClose>My Trips</li>
<li menuClose>Settings</li> <li menuClose>Settings</li>
<li menuClose (click)="openPage('LandingPage')">Logout</li> <li menuClose (click)="openPage('LandingPage')">Logout</li>
......
...@@ -19,6 +19,7 @@ import { fireService } from "../providers/firebase.service"; ...@@ -19,6 +19,7 @@ import { fireService } from "../providers/firebase.service";
import { AngularFireDatabase } from 'angularfire2/database'; import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFireModule } from 'angularfire2'; import { AngularFireModule } from 'angularfire2';
import { dataService } from "../providers/common.service"; import { dataService } from "../providers/common.service";
import { DatePipe } from '@angular/common';
export const firebaseConfig = { export const firebaseConfig = {
apiKey: "AIzaSyDLrbLd4RCCh86xuTVu7-cfJ28We_cG1sU", apiKey: "AIzaSyDLrbLd4RCCh86xuTVu7-cfJ28We_cG1sU",
...@@ -56,6 +57,7 @@ export const firebaseConfig = { ...@@ -56,6 +57,7 @@ export const firebaseConfig = {
fireService, fireService,
AngularFireDatabase, AngularFireDatabase,
dataService, dataService,
DatePipe,
] ]
}) })
export class AppModule {} export class AppModule {}
...@@ -3,6 +3,7 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular'; ...@@ -3,6 +3,7 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Storage } from "@ionic/storage"; import { Storage } from "@ionic/storage";
import { Myservice } from "../../providers/myservice"; import { Myservice } from "../../providers/myservice";
import { dataService } from "../../providers/common.service"; import { dataService } from "../../providers/common.service";
@IonicPage() @IonicPage()
@Component({ @Component({
selector: 'page-home', selector: 'page-home',
...@@ -14,10 +15,11 @@ upcoming:any; ...@@ -14,10 +15,11 @@ upcoming:any;
completed:any; completed:any;
baseurl = this.myservice.base_url baseurl = this.myservice.base_url
constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, private myservice: Myservice, private data:dataService) { constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage, private myservice: Myservice, private data: dataService) {
} }
ionViewDidEnter(){ ionViewDidEnter(){
this.storage.get('driver_data').then(data=>{ this.storage.get('driver_data').then(data=>{
if(data){ if(data){
this.myservice.load_post({id:data.id},'getMyRides').subscribe(response=>{ this.myservice.load_post({id:data.id},'getMyRides').subscribe(response=>{
......
...@@ -4,7 +4,7 @@ import { dataService } from "../../providers/common.service"; ...@@ -4,7 +4,7 @@ import { dataService } from "../../providers/common.service";
import { Myservice } from "../../providers/myservice"; import { Myservice } from "../../providers/myservice";
import { Storage } from "@ionic/storage"; import { Storage } from "@ionic/storage";
import * as firebase from 'firebase'; import * as firebase from 'firebase';
import { DatePipe } from '@angular/common';
declare var google; declare var google;
@IonicPage() @IonicPage()
...@@ -19,8 +19,9 @@ export class PaymentPage { ...@@ -19,8 +19,9 @@ export class PaymentPage {
public unregisterBackButtonAction: any; public unregisterBackButtonAction: any;
ride: any; ride: any;
waypoints = this.data.getwaypointData() waypoints = this.data.getwaypointData()
rate = this.data.getrateData();
constructor(public navCtrl: NavController, public navParams: NavParams, private data: dataService, private zone: NgZone, private myservice: Myservice, private storage: Storage, public platform: Platform) { constructor(public navCtrl: NavController, public navParams: NavParams, private data: dataService, private zone: NgZone, private myservice: Myservice, private storage: Storage, public platform: Platform, private datePipe: DatePipe) {
} }
ionViewDidEnter() { ionViewDidEnter() {
...@@ -54,13 +55,27 @@ export class PaymentPage { ...@@ -54,13 +55,27 @@ export class PaymentPage {
} }
totalDist = totalDist / 1000. totalDist = totalDist / 1000.
console.log(totalDist) console.log(totalDist)
This.myservice.load_post({},'updateRideDetails').subscribe(response=>{
if(response.status == 'success'){
if (totalDist > This.rate.intialkm){
var extra = totalDist - This.rate.intialkm
var rate = ((extra * This.rate.standardrate) + (This.rate.intailrate)) + This.book.timeAmount
rate = rate - This.book.discount
}
else{
var rate = This.rate.intailrate + This.book.timeAmount;
rate = rate - This.book.discount
} }
else var data = { 'pickup_time': This.datePipe.transform(This.book.actualPick, 'h:mm a'), 'drop_time': This.datePipe.transform(This.book.actualDrop, 'h:mm a'), 'drop_date': This.datePipe.transform(This.book.actualDrop, 'MM/dd/yyyy'), 'distance': totalDist, 'amount': rate, 'km': totalDist}
This.myservice.show_alert('',response.message)
}) This.myservice.hide_loader();
console.log(data);
// This.myservice.load_post({},'updateRideDetails').subscribe(response=>{
// if(response.status == 'success'){
// }
// else
// This.myservice.show_alert('',response.message)
// })
} else { } else {
window.alert('Directions request failed due to ' + status); window.alert('Directions request failed due to ' + status);
} }
...@@ -79,7 +94,7 @@ export class PaymentPage { ...@@ -79,7 +94,7 @@ export class PaymentPage {
} }
done() { done() {
this.myservice.load_post({ status: 'Completed', id: this.book.id }, 'changeStatus')
} }
} }
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<div class="jr_clear"></div> <div class="jr_clear"></div>
</div> </div>
<div class="jr_bottom_button_bay" *ngIf="details.status=='Booking'"> <div class="jr_bottom_button_bay" *ngIf="details.status=='Booking' && temp">
<button ion-button class="cab_footer_btn" (click)="pick()">Pick Up</button> <button ion-button class="cab_footer_btn" (click)="pick()">Pick Up</button>
</div> </div>
</div> </div>
......
...@@ -2,6 +2,7 @@ import { Component } from '@angular/core'; ...@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular'; import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Myservice } from "../../providers/myservice"; import { Myservice } from "../../providers/myservice";
import { dataService } from "../../providers/common.service"; import { dataService } from "../../providers/common.service";
import { DatePipe } from '@angular/common';
@IonicPage() @IonicPage()
@Component({ @Component({
...@@ -11,11 +12,23 @@ import { dataService } from "../../providers/common.service"; ...@@ -11,11 +12,23 @@ import { dataService } from "../../providers/common.service";
export class RidedetailsPage { export class RidedetailsPage {
details = this.data.getrideData() details = this.data.getrideData()
baseurl = this.myservice.base_url baseurl = this.myservice.base_url
now:any;
// rideDate:any
temp:boolean = false;
constructor(public navCtrl: NavController, public navParams: NavParams, private myservice: Myservice, private data:dataService) { constructor(public navCtrl: NavController, public navParams: NavParams, private myservice: Myservice, private data: dataService, private datePipe: DatePipe) {
} }
ionViewDidEnter(){
this.now = this.datePipe.transform(new Date(), 'MM/dd/yyyy')
console.log(this.now)
console.log(this.details.pickup_date)
if (this.now == this.details.pickup_date){
this.temp = true;
}
}
ionViewDidLoad() { ionViewDidLoad() {
var tempf = this.details.pickup_area.split(',') var tempf = this.details.pickup_area.split(',')
this.details.from = tempf[0] this.details.from = tempf[0]
...@@ -27,6 +40,8 @@ export class RidedetailsPage { ...@@ -27,6 +40,8 @@ export class RidedetailsPage {
this.details.toAd = this.details.drop_area this.details.toAd = this.details.drop_area
console.log(this.details) console.log(this.details)
this.details.discount = Number(this.details.discount)
this.data.setrideData(this.details) this.data.setrideData(this.details)
} }
......
...@@ -29,6 +29,7 @@ export class UserlocationPage { ...@@ -29,6 +29,7 @@ export class UserlocationPage {
started: boolean = false; started: boolean = false;
myloc = [] myloc = []
waypoints = [] waypoints = []
ride:any;
constructor(public navCtrl: NavController, public navParams: NavParams, private geolocation: Geolocation, private db: AngularFireDatabase, private storage: Storage, private myservice: Myservice, private menu: MenuController, private data: dataService) { constructor(public navCtrl: NavController, public navParams: NavParams, private geolocation: Geolocation, private db: AngularFireDatabase, private storage: Storage, private myservice: Myservice, private menu: MenuController, private data: dataService) {
this.loadMap() this.loadMap()
...@@ -143,6 +144,8 @@ export class UserlocationPage { ...@@ -143,6 +144,8 @@ export class UserlocationPage {
} }
startRide() { startRide() {
this.myservice.load_post({status:'Started',id:this.details.id},'changeStatus')
this.details.actualPick = new Date().getTime()
this.started = true; this.started = true;
this.temp = false this.temp = false
...@@ -156,11 +159,49 @@ export class UserlocationPage { ...@@ -156,11 +159,49 @@ export class UserlocationPage {
} }
complete() { complete() {
var This = this; this.myservice.show_loader()
this.details.actualDrop = new Date().getTime()
var pick = this.details.pickup_latlng.split(',')
var drop = this.details.drop_latlng.split(',')
var origin = new google.maps.LatLng(pick[0], pick[1]);
var destination = new google.maps.LatLng(drop[0], drop[1]);
var service = new google.maps.DistanceMatrixService();
var This = this
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.DirectionsTravelMode.DRIVING,
avoidHighways: true,
avoidTolls: true,
}, function (response, status) {
if (response.originAddresses[0] != '') {
var calcTime = response.rows[0].elements[0].duration.value
var realTime = (This.details.actualDrop - This.details.actualPick) / 1000//in seconds
// var realTime = (1530183600000 - 1530182700000) / 1000 //in seconds
// console.log('google time', calcTime);
// console.log('time taken',realTime);
if (calcTime < realTime){
var extraHr = Math.round(((realTime - calcTime) / 3600) * 100) / 100 //in hrs
// console.log('extra time',extraHr)
This.details.timeAmount = Math.round(This.details.extrahour * extraHr)
// console.log('amt', This.details.timeAmount)
}
else
This.details.timeAmount = 0;
}
});
This.data.setrideData(This.details);
This.data.setwaypointData(This.waypoints) This.data.setwaypointData(This.waypoints)
firebase.database().ref("drivers/" + This.pushId + "/").update({ started: false }) firebase.database().ref("drivers/" + This.pushId + "/").update({ started: false })
This.navCtrl.push('PaymentPage') This.navCtrl.push('PaymentPage')
// console.log(This.locSubs)
} }
getStorage() { getStorage() {
...@@ -174,6 +215,12 @@ export class UserlocationPage { ...@@ -174,6 +215,12 @@ export class UserlocationPage {
This.pushId = snapshot.val().push_id This.pushId = snapshot.val().push_id
console.log(This.pushId) console.log(This.pushId)
}); });
This.myservice.load_post({ id: data.id, timetype: This.ride.timetype},'getRateCard').subscribe(response=>{
if(response.status == 'success'){
This.ride = response.data
This.data.setrateData(This.ride)
}
})
} }
}) })
} }
......
...@@ -5,7 +5,7 @@ export class dataService { ...@@ -5,7 +5,7 @@ export class dataService {
rideData:any; rideData:any;
waypointData:any; waypointData:any;
driverData:any; rateData:any;
constructor() { } constructor() { }
...@@ -25,12 +25,12 @@ driverData:any; ...@@ -25,12 +25,12 @@ driverData:any;
return this.waypointData; return this.waypointData;
} }
public setdriverData(val){ public setrateData(val){
this.driverData = val; this.rateData = val;
} }
public getdriverData(){ public getrateData(){
return this.driverData; return this.rateData;
} }
......
...@@ -42,21 +42,5 @@ export class fireService { ...@@ -42,21 +42,5 @@ export class fireService {
}); });
return promise; return promise;
} }
removeItem(url){
return this.db.object(url).remove();
}
listItem(url){
return this.db.list(url);
}
listItemQuery(url,query){
return this.db.list(url,query);
}
checkItem(url){
return this.db.list(url);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment