public function types()
 {
     $types = ProviderType::where('is_visible', '=', 1)->get();
     /* $setbase_price = Settings::where('key', 'base_price')->first();
        $base_price = $setbase_price->value;
        $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
        $distance_price = $setdistance_price->value;
        $settime_price = Settings::where('key', 'price_per_unit_time')->first();
        $time_price = $settime_price->value; */
     $type_array = array();
     $settunit = Settings::where('key', 'default_distance_unit')->first();
     $unit = $settunit->value;
     if ($unit == 0) {
         $unit_set = 'kms';
     } elseif ($unit == 1) {
         $unit_set = 'miles';
     }
     /* $currency_selected = Keywords::find(5); */
     foreach ($types as $type) {
         $data = array();
         $data['id'] = $type->id;
         $data['name'] = $type->name;
         $data['min_fare'] = $type->base_price;
         $data['max_size'] = $type->max_size;
         $data['icon'] = $type->icon;
         $data['is_default'] = $type->is_default;
         $data['price_per_unit_time'] = currency_converted($type->price_per_unit_time);
         $data['price_per_unit_distance'] = currency_converted($type->price_per_unit_distance);
         $data['base_price'] = currency_converted($type->base_price);
         $data['base_distance'] = currency_converted($type->base_distance);
         /* $data['currency'] = $currency_selected->keyword; */
         $data['currency'] = Config::get('app.generic_keywords.Currency');
         $data['unit'] = $unit_set;
         array_push($type_array, $data);
     }
     $response_array = array();
     $response_array['success'] = true;
     $response_array['types'] = $type_array;
     $response_code = 200;
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function get_credits()
 {
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry)) {
                 /* $currency_selected = Keywords::find(5); */
                 $ledger = Ledger::where('owner_id', $owner_id)->first();
                 if ($ledger) {
                     $credits['balance'] = currency_converted($ledger->amount_earned - $ledger->amount_spent);
                     /* $credits['currency'] = $currency_selected->keyword; */
                     $credits['currency'] = Config::get('app.generic_keywords.Currency');
                     $response_array = array('success' => true, 'credits' => $credits);
                 } else {
                     $response_array = array('success' => false, 'error' => 'No Credit Found', 'error_code' => 475);
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
         } else {
             $response_array = array('success' => false, 'error' => 'User Not Found', 'error_code' => 402);
         }
         $response_code = 200;
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function get_completed_requests()
 {
     $walker_id = Input::get('id');
     $token = Input::get('token');
     $from = Input::get('from_date');
     // 2015-03-11 07:45:01
     $to_date = Input::get('to_date');
     //2015-03-11 07:45:01
     $validator = Validator::make(array('walker_id' => $walker_id, 'token' => $token), array('walker_id' => 'required|integer', 'token' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($walker_data->token_expiry) || $is_admin) {
                 if ($from != "" && $to_date != "") {
                     $request_data = DB::table('request')->where('request.confirmed_walker', $walker_id)->where('request.is_completed', 1)->where('request_start_time', '>', $from)->where('request_start_time', '<', $to_date)->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('request_services', 'request_services.request_id', '=', 'request.id')->select('request.*', 'request.request_start_time', 'request.transfer_amount', 'owner.first_name', 'owner.last_name', 'owner.phone', 'owner.email', 'owner.picture', 'owner.bio', 'request.distance', 'request.time', 'request.promo_code', 'request_services.base_price', 'request_services.distance_cost', 'request_services.time_cost', 'request.total')->get();
                 } else {
                     $request_data = DB::table('request')->where('request.confirmed_walker', $walker_id)->where('request.is_completed', 1)->leftJoin('owner', 'request.owner_id', '=', 'owner.id')->leftJoin('request_services', 'request_services.request_id', '=', 'request.id')->select('request.*', 'request.request_start_time', 'request.transfer_amount', 'owner.first_name', 'owner.last_name', 'owner.phone', 'owner.email', 'owner.picture', 'owner.bio', 'request.distance', 'request.time', 'request.promo_code', 'request_services.base_price', 'request_services.distance_cost', 'request_services.time_cost', 'request.total')->get();
                 }
                 $requests = array();
                 $settings = Settings::where('key', 'default_distance_unit')->first();
                 /* $setbase_price = Settings::where('key', 'base_price')->first();
                    $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                    $settime_price = Settings::where('key', 'price_per_unit_time')->first(); */
                 $unit = $settings->value;
                 if ($unit == 0) {
                     $unit_set = 'kms';
                 } elseif ($unit == 1) {
                     $unit_set = 'miles';
                 }
                 $walker = Walker::where('id', $walker_id)->first();
                 foreach ($request_data as $data) {
                     $discount = 0;
                     if ($data->promo_id != "") {
                         $promo_code = PromoCodes::where('id', $data->promo_id)->first();
                         if (isset($promo_code->id)) {
                             $promo_value = $promo_code->value;
                             $promo_type = $promo_code->type;
                             if ($promo_type == 1) {
                                 // Percent Discount
                                 $discount = $data->total * $promo_value / 100;
                             } elseif ($promo_type == 2) {
                                 // Absolute Discount
                                 $discount = $promo_value;
                             }
                         }
                     }
                     $is_multiple_service = Settings::where('key', 'allow_multiple_service')->first();
                     if ($is_multiple_service->value == 0) {
                         $requestserv = RequestServices::where('request_id', $data->id)->first();
                         $request_typ = ProviderType::where('id', '=', $requestserv->type)->first();
                         $request['id'] = $data->id;
                         $request['date'] = $data->request_start_time;
                         $request['distance'] = (string) $data->distance;
                         $request['unit'] = $unit_set;
                         $request['time'] = $data->time;
                         $request['base_distance'] = $request_typ->base_distance;
                         /* $currency = Keywords::where('alias', 'Currency')->first();
                            $request['currency'] = $currency->keyword; */
                         $request['currency'] = Config::get('app.generic_keywords.Currency');
                         if ($requestserv->base_price != 0) {
                             $request['base_price'] = currency_converted($requestserv->base_price);
                             $request['distance_cost'] = currency_converted($requestserv->distance_cost);
                             $request['time_cost'] = currency_converted($requestserv->time_cost);
                         } else {
                             /* $setbase_price = Settings::where('key', 'base_price')->first();
                                $request['base_price'] = currency_converted($setbase_price->value);
                                $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                $request['distance_cost'] = currency_converted($setdistance_price->value);
                                $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                $request['time_cost'] = currency_converted($settime_price->value); */
                             $request['base_price'] = currency_converted($request_typ->base_price);
                             $request['distance_cost'] = currency_converted($request_typ->price_per_unit_distance);
                             $request['time_cost'] = currency_converted($request_typ->price_per_unit_time);
                         }
                         $admins = Admin::first();
                         $request['walker']['email'] = $walker->email;
                         $request['admin']['email'] = $admins->username;
                         if ($data->transfer_amount != 0) {
                             $request['walker']['amount'] = currency_converted($data->total - $data->transfer_amount);
                             $request['admin']['amount'] = currency_converted($data->transfer_amount);
                         } else {
                             $request['walker']['amount'] = currency_converted($data->transfer_amount);
                             $request['admin']['amount'] = currency_converted($data->total - $data->transfer_amount);
                         }
                         $request['total'] = currency_converted($data->total + $data->ledger_payment + $discount);
                         $rserv = RequestServices::where('request_id', $data->id)->get();
                         $typs = array();
                         $typi = array();
                         $typp = array();
                         $total_price = 0;
                         foreach ($rserv as $typ) {
                             $typ1 = ProviderType::where('id', $typ->type)->first();
                             $typ_price = ProviderServices::where('provider_id', $data->confirmed_walker)->where('type', $typ->type)->first();
                             if ($typ_price->base_price > 0) {
                                 $typp1 = 0.0;
                                 $typp1 = $typ_price->base_price;
                             } elseif ($typ_price->price_per_unit_distance > 0) {
                                 $typp1 = 0.0;
                                 foreach ($rserv as $key) {
                                     $typp1 = $typp1 + $key->distance_cost;
                                 }
                             } else {
                                 $typp1 = 0.0;
                             }
                             $typs['name'] = $typ1->name;
                             $typs['price'] = currency_converted($typp1);
                             $total_price = $total_price + $typp1;
                             array_push($typi, $typs);
                         }
                         $request['type'] = $typi;
                     } else {
                         $request['id'] = $data->id;
                         $request['date'] = $data->request_start_time;
                         $request['distance'] = (string) $data->distance;
                         $request['unit'] = $unit_set;
                         $request['time'] = $data->time;
                         /* $currency = Keywords::where('alias', 'Currency')->first();
                            $request['currency'] = $currency->keyword; */
                         $request['currency'] = Config::get('app.generic_keywords.Currency');
                         //print_r($data);
                         $rserv = RequestServices::where('request_id', $data->id)->get();
                         $typs = array();
                         $typi = array();
                         $typp = array();
                         $total_price = 0;
                         foreach ($rserv as $typ) {
                             $typ1 = ProviderType::where('id', $typ->type)->first();
                             $typ_price = ProviderServices::where('provider_id', $data->confirmed_walker)->where('type', $typ->type)->first();
                             if ($typ_price->base_price > 0) {
                                 $typp1 = 0.0;
                                 $typp1 = $typ_price->base_price;
                             } elseif ($typ_price->price_per_unit_distance > 0) {
                                 $typp1 = 0.0;
                                 foreach ($rserv as $key) {
                                     $typp1 = $typp1 + $key->distance_cost;
                                 }
                             } else {
                                 $typp1 = 0.0;
                             }
                             $typs['name'] = $typ1->name;
                             $typs['price'] = currency_converted($typp1);
                             $total_price = $total_price + $typp1;
                             array_push($typi, $typs);
                         }
                         $request['type'] = $data->{$typi};
                         //  print_r($typp1);
                         //print_r($request);
                         $base_price = 0;
                         $distance_cost = 0;
                         $time_cost = 0;
                         foreach ($rserv as $key) {
                             $base_price = $base_price + $key->base_price;
                             $distance_cost = $distance_cost + $key->distance_cost;
                             $time_cost = $time_cost + $key->time_cost;
                         }
                         $request['base_price'] = currency_converted($base_price);
                         $request['distance_cost'] = currency_converted($distance_cost);
                         $request['time_cost'] = currency_converted($time_cost);
                         $request['total'] = currency_converted($total_price);
                     }
                     /* path */
                     $id = $data->id;
                     $locations = WalkLocation::where('request_id', $data->id)->orderBy('id')->get();
                     $start = $end = $map = "";
                     if (count($locations) >= 1) {
                         $start = WalkLocation::where('request_id', $id)->orderBy('id')->first();
                         $end = WalkLocation::where('request_id', $id)->orderBy('id', 'desc')->first();
                         $map = "https://maps-api-ssl.google.com/maps/api/staticmap?size=249x249&scale=2&markers=shadow:true|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-start@2x.png|{$start->latitude},{$start->longitude}&markers=shadow:false|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-finish@2x.png|{$end->latitude},{$end->longitude}&path=color:0x2dbae4ff|weight:4";
                         foreach ($locations as $location) {
                             $map .= "|{$location->latitude},{$location->longitude}";
                         }
                         /* $map.="&key=" . Config::get('app.gcm_browser_key'); */
                     }
                     $request['start_lat'] = "";
                     if (isset($start->latitude)) {
                         $request['start_lat'] = $start->latitude;
                     }
                     $request['start_long'] = "";
                     if (isset($start->longitude)) {
                         $request['start_long'] = $start->longitude;
                     }
                     $request['end_lat'] = "";
                     if (isset($end->latitude)) {
                         $request['end_lat'] = $end->latitude;
                     }
                     $request['end_long'] = "";
                     if (isset($end->longitude)) {
                         $request['end_long'] = $end->longitude;
                     }
                     $request['map_url'] = $map;
                     /* path END */
                     /* $request['owner']['first_name'] = $data->first_name;
                        $request['owner']['last_name'] = $data->last_name;
                        $request['owner']['phone'] = $data->phone;
                        $request['owner']['email'] = $data->email;
                        $request['owner']['picture'] = $data->picture;
                        $request['owner']['bio'] = $data->bio;
                        $request['owner']['payment_opt'] = $data->payment_mode; */
                     $request['base_price'] = currency_converted($data->base_price);
                     $request['distance_cost'] = currency_converted($data->distance_cost);
                     $request['time_cost'] = currency_converted($data->time_cost);
                     $request['total'] = currency_converted($data->total - $data->ledger_payment - $data->promo_payment);
                     $request['main_total'] = currency_converted($data->total);
                     $request['referral_bonus'] = currency_converted($data->ledger_payment);
                     $request['promo_bonus'] = currency_converted($data->promo_payment);
                     $request['payment_type'] = $data->payment_mode;
                     $request['is_paid'] = $data->is_paid;
                     $request['promo_id'] = $data->promo_id;
                     $request['promo_code'] = $data->promo_code;
                     $request['owner']['first_name'] = $data->first_name;
                     $request['owner']['last_name'] = $data->last_name;
                     $request['owner']['phone'] = $data->phone;
                     $request['owner']['email'] = $data->email;
                     $request['owner']['picture'] = $data->picture;
                     $request['owner']['bio'] = $data->bio;
                     $request['owner']['payment_opt'] = $data->payment_mode;
                     array_push($requests, $request);
                 }
                 $response_array = array('success' => true, 'requests' => $requests);
                 $response_code = 200;
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 /* $var = Keywords::where('id', 1)->first();
                    $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                 $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.Provider') . ' ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function get_request()
 {
     $request_id = Input::get('request_id');
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'owner_id' => $owner_id), array('request_id' => 'required|integer', 'token' => 'required', 'owner_id' => 'required|integer'));
     /* $var = Keywords::where('id', 2)->first(); */
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 /* SEND REFERRAL & PROMO INFO */
                 $settings = Settings::where('key', 'referral_code_activation')->first();
                 $referral_code_activation = $settings->value;
                 if ($referral_code_activation) {
                     $referral_code_activation_txt = "referral on";
                 } else {
                     $referral_code_activation_txt = "referral off";
                 }
                 $settings = Settings::where('key', 'promotional_code_activation')->first();
                 $promotional_code_activation = $settings->value;
                 if ($promotional_code_activation) {
                     $promotional_code_activation_txt = "promo on";
                 } else {
                     $promotional_code_activation_txt = "promo off";
                 }
                 /* SEND REFERRAL & PROMO INFO */
                 // Do necessary operations
                 if ($request = Requests::find($request_id)) {
                     if ($request->owner_id == $owner_data->id) {
                         if ($request->current_walker != 0) {
                             if ($request->confirmed_walker != 0) {
                                 $walker = Walker::where('id', $request->confirmed_walker)->first();
                                 $walker_data = array();
                                 $walker_data['unique_id'] = 1;
                                 $walker_data['id'] = $walker->id;
                                 $walker_data['first_name'] = $walker->first_name;
                                 $walker_data['last_name'] = $walker->last_name;
                                 $walker_data['phone'] = $walker->phone;
                                 $walker_data['bio'] = $walker->bio;
                                 $walker_data['picture'] = $walker->picture;
                                 $walker_data['latitude'] = $walker->latitude;
                                 $walker_data['longitude'] = $walker->longitude;
                                 if ($request->D_latitude != NULL) {
                                     $walker_data['d_latitude'] = $request->D_latitude;
                                     $walker_data['d_longitude'] = $request->D_longitude;
                                 }
                                 $walker_data['type'] = $walker->type;
                                 $walker_data['rating'] = $walker->rate;
                                 $walker_data['num_rating'] = $walker->rate_count;
                                 $walker_data['car_model'] = $walker->car_model;
                                 $walker_data['car_number'] = $walker->car_number;
                                 $walker_data['bearing'] = $walker->bearing;
                                 /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0;
                                    $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 if ($unit == 0) {
                                     $unit_set = 'kms';
                                 } elseif ($unit == 1) {
                                     $unit_set = 'miles';
                                 }
                                 $requestserv = RequestServices::where('request_id', $request->id)->first();
                                 $bill = array();
                                 $request_typ = ProviderType::where('id', '=', $requestserv->type)->first();
                                 /* $currency_selected = Keywords::find(5);
                                    $cur_symb = $currency_selected->keyword; */
                                 $cur_symb = Config::get('app.generic_keywords.Currency');
                                 if ($request->is_completed == 1) {
                                     $bill['unit'] = $unit_set;
                                     $bill['payment_mode'] = $request->payment_mode;
                                     $bill['distance'] = (string) $request->distance;
                                     $bill['time'] = $request->time;
                                     if ($requestserv->base_price != 0) {
                                         $bill['base_distance'] = $request_typ->base_distance;
                                         $bill['base_price'] = currency_converted($requestserv->base_price);
                                         $bill['distance_cost'] = currency_converted($requestserv->distance_cost);
                                         $bill['time_cost'] = currency_converted($requestserv->time_cost);
                                     } else {
                                         /* $setbase_price = Settings::where('key', 'base_price')->first();
                                            $bill['base_price'] = currency_converted($setbase_price->value);
                                            $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                            $bill['distance_cost'] = currency_converted($setdistance_price->value);
                                            $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                            $bill['time_cost'] = currency_converted($settime_price->value); */
                                         $bill['base_distance'] = $request_typ->base_distance;
                                         $bill['base_price'] = currency_converted($request_typ->base_price);
                                         $bill['distance_cost'] = currency_converted($request_typ->price_per_unit_distance);
                                         $bill['time_cost'] = currency_converted($request_typ->price_per_unit_time);
                                     }
                                     if ($request->payment_mode == 2) {
                                         $bill['walker']['email'] = $walker->email;
                                         $bill['walker']['amount'] = currency_converted($request->transfer_amount);
                                         $admins = Admin::first();
                                         $bill['admin']['email'] = $admins->username;
                                         $bill['admin']['amount'] = currency_converted($request->total - $request->transfer_amount);
                                     }
                                     $bill['currency'] = $cur_symb;
                                     /* $bill['total'] = currency_converted($request->total); */
                                     $bill['main_total'] = currency_converted($request->total);
                                     $bill['total'] = currency_converted($request->total - $request->ledger_payment - $request->promo_payment);
                                     $bill['referral_bonus'] = currency_converted($request->ledger_payment);
                                     $bill['promo_bonus'] = currency_converted($request->promo_payment);
                                     //   $bill['payment_type'] = $owner_data->cash_or_card;
                                     $bill['payment_type'] = "";
                                     $bill['is_paid'] = $request->is_paid;
                                     $discount = 0;
                                     if ($request->promo_code != "") {
                                         if ($request->promo_code != "") {
                                             $promo_code = PromoCodes::where('id', $request->promo_code)->first();
                                             if ($promo_code) {
                                                 $promo_value = $promo_code->value;
                                                 $promo_type = $promo_code->type;
                                                 if ($promo_type == 1) {
                                                     // Percent Discount
                                                     $discount = $request->total * $promo_value / 100;
                                                 } elseif ($promo_type == 2) {
                                                     // Absolute Discount
                                                     $discount = $promo_value;
                                                 }
                                             }
                                         }
                                     }
                                     $bill['promo_discount'] = currency_converted($discount);
                                     $bill['actual_total'] = currency_converted($request->total + $request->ledger_payment + $discount);
                                 }
                                 $cards = "";
                                 /* $cards['none'] = ""; */
                                 $dif_card = 0;
                                 $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first();
                                 /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */
                                 if (count($cardlist) >= 1) {
                                     $cards = array();
                                     $default = $cardlist->is_default;
                                     if ($default == 1) {
                                         $dif_card = $cardlist->id;
                                         $cards['is_default_text'] = "default";
                                     } else {
                                         $cards['is_default_text'] = "not_default";
                                     }
                                     $cards['card_id'] = $cardlist->id;
                                     $cards['owner_id'] = $cardlist->owner_id;
                                     $cards['customer_id'] = $cardlist->customer_id;
                                     $cards['last_four'] = $cardlist->last_four;
                                     $cards['card_token'] = $cardlist->card_token;
                                     $cards['card_type'] = $cardlist->card_type;
                                     $cards['is_default'] = $default;
                                 }
                                 $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first();
                                 $owner = array();
                                 $owner['owner_lat'] = $owner_data->latitude;
                                 $owner['owner_long'] = $owner_data->longitude;
                                 $owner['owner_dist_lat'] = $request->D_latitude;
                                 $owner['owner_dist_long'] = $request->D_longitude;
                                 $owner['payment_type'] = $request->payment_mode;
                                 $owner['default_card'] = $dif_card;
                                 $owner['dest_latitude'] = $request->D_latitude;
                                 $owner['dest_longitude'] = $request->D_longitude;
                                 $owner['referral_code'] = $code_data->referral_code;
                                 $owner['is_referee'] = $owner_data->is_referee;
                                 $owner['promo_count'] = $owner_data->promo_count;
                                 $charge = array();
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 if ($unit == 0) {
                                     $unit_set = 'kms';
                                 } elseif ($unit == 1) {
                                     $unit_set = 'miles';
                                 }
                                 $charge['unit'] = $unit_set;
                                 if ($requestserv->base_price != 0) {
                                     $charge['base_distance'] = $request_typ->base_distance;
                                     $charge['base_price'] = currency_converted($requestserv->base_price);
                                     $charge['distance_price'] = currency_converted($requestserv->distance_cost);
                                     $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost);
                                 } else {
                                     /* $setbase_price = Settings::where('key', 'base_price')->first();
                                        $charge['base_price'] = currency_converted($setbase_price->value);
                                        $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                        $charge['distance_price'] = currency_converted($setdistance_price->value);
                                        $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                        $charge['price_per_unit_time'] = currency_converted($settime_price->value); */
                                     $charge['base_distance'] = $request_typ->base_distance;
                                     $charge['base_price'] = currency_converted($request_typ->base_price);
                                     $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance);
                                     $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time);
                                 }
                                 $charge['total'] = currency_converted($request->total);
                                 $charge['is_paid'] = $request->is_paid;
                                 $loc1 = WalkLocation::where('request_id', $request->id)->first();
                                 $loc2 = WalkLocation::where('request_id', $request->id)->orderBy('id', 'desc')->first();
                                 if ($loc1) {
                                     $time1 = strtotime($loc2->created_at);
                                     $time2 = strtotime($loc1->created_at);
                                     $difference = intval(($time1 - $time2) / 60);
                                 } else {
                                     $difference = 0;
                                 }
                                 $difference = $request->time;
                                 /* $rserv = RequestServices::where('request_id', $request_id)->get();
                                                                     $typs = array();
                                                                     $typi = array();
                                                                     $typp = array();
                                                                     $total_price = 0;
                                                                     foreach ($rserv as $typ) {
                                                                         $typ1 = ProviderType::where('id', $typ->type)->first();
                                                                         $typ_price = ProviderServices::where('provider_id', $request->confirmed_walker)->where('type', $typ->type)->first();
                                 
                                                                         if ($typ_price->base_price > 0) {
                                                                             $typp1 = 0.00;
                                                                             $typp1 = $typ_price->base_price;
                                                                         } elseif ($typ_price->price_per_unit_distance > 0) {
                                                                             $typp1 = 0.00;
                                                                             foreach ($rserv as $key) {
                                                                                 $typp1 = $typp1 + $key->distance_cost;
                                                                             }
                                                                         } else {
                                                                             $typp1 = 0.00;
                                                                         }
                                                                         $typs['name'] = $typ1->name;
                                                                         $typs['price'] = currency_converted($typp1);
                                                                         $total_price = $total_price + $typp1;
                                                                         array_push($typi, $typs);
                                                                     }
                                                                     $bill['type'] = $typi;*/
                                 $rserv = RequestServices::where('request_id', $request_id)->get();
                                 $typs = array();
                                 $typi = array();
                                 $typp = array();
                                 $total_price = 0;
                                 foreach ($rserv as $typ) {
                                     $typ1 = ProviderType::where('id', $typ->type)->first();
                                     $typ_price = ProviderServices::where('provider_id', $request->confirmed_walker)->where('type', $typ->type)->first();
                                     $typp1 = 0.0;
                                     if (isset($typ_price->base_price)) {
                                         if ($typ_price->base_price > 0) {
                                             $typp1 = 0.0;
                                             $typp1 = $typ_price->base_price;
                                         } elseif ($typ_price->price_per_unit_distance > 0) {
                                             $typp1 = 0.0;
                                             foreach ($rserv as $key) {
                                                 $typp1 = $typp1 + $key->distance_cost;
                                             }
                                         } else {
                                             $typp1 = 0.0;
                                         }
                                     }
                                     $typs['name'] = $typ1->name;
                                     $typs['price'] = currency_converted($typp1);
                                     $total_price = $total_price + $typp1;
                                     array_push($typi, $typs);
                                 }
                                 $bill['type'] = $typi;
                                 $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => $walker_data, 'time' => $difference, 'bill' => $bill, 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge);
                                 $user_timezone = $walker->timezone;
                                 $default_timezone = Config::get('app.timezone');
                                 $accepted_time = get_user_time($default_timezone, $user_timezone, $request->request_start_time);
                                 $time = DB::table('walk_location')->where('request_id', $request_id)->min('created_at');
                                 $end_time = get_user_time($default_timezone, $user_timezone, $time);
                                 $response_array['accepted_time'] = $accepted_time;
                                 if ($request->is_started == 1) {
                                     $response_array['start_time'] = DB::table('walk_location')->where('request_id', $request_id)->min('created_at');
                                     $settings = Settings::where('key', 'default_distance_unit')->first();
                                     $unit = $settings->value;
                                     $response_array['distance'] = DB::table('walk_location')->where('request_id', $request_id)->max('distance');
                                     $response_array['distance'] = (string) convert($response_array['distance'], $unit);
                                     if ($unit == 0) {
                                         $unit_set = 'kms';
                                     } elseif ($unit == 1) {
                                         $unit_set = 'miles';
                                     }
                                     $response_array['unit'] = $unit_set;
                                 }
                                 if ($request->is_completed == 1) {
                                     $response_array['end_time'] = $end_time;
                                 }
                             } else {
                                 if ($request->current_walker != 0) {
                                     $walker = Walker::find($request->current_walker);
                                     $walker_data = array();
                                     $walker_data['unique_id'] = 1;
                                     $walker_data['id'] = $walker->id;
                                     $walker_data['first_name'] = $walker->first_name;
                                     $walker_data['last_name'] = $walker->last_name;
                                     $walker_data['phone'] = $walker->phone;
                                     $walker_data['bio'] = $walker->bio;
                                     $walker_data['picture'] = $walker->picture;
                                     $walker_data['latitude'] = $walker->latitude;
                                     $walker_data['longitude'] = $walker->longitude;
                                     $walker_data['type'] = $walker->type;
                                     $walker_data['car_model'] = $walker->car_model;
                                     $walker_data['car_number'] = $walker->car_number;
                                     $walker_data['bearing'] = $walker->bearing;
                                     // $walker_data['payment_type'] = $request->cash_or_card;
                                     $walker_data['rating'] = $walker->rate;
                                     $walker_data['num_rating'] = $walker->rate_count;
                                 }
                                 $cards = "";
                                 /* $cards['none'] = ""; */
                                 $dif_card = 0;
                                 $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first();
                                 /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */
                                 if (count($cardlist) >= 1) {
                                     $cards = array();
                                     $default = $cardlist->is_default;
                                     if ($default == 1) {
                                         $dif_card = $cardlist->id;
                                         $cards['is_default_text'] = "default";
                                     } else {
                                         $cards['is_default_text'] = "not_default";
                                     }
                                     $cards['card_id'] = $cardlist->id;
                                     $cards['owner_id'] = $cardlist->owner_id;
                                     $cards['customer_id'] = $cardlist->customer_id;
                                     $cards['last_four'] = $cardlist->last_four;
                                     $cards['card_token'] = $cardlist->card_token;
                                     $cards['card_type'] = $cardlist->card_type;
                                     $cards['is_default'] = $default;
                                 }
                                 $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first();
                                 $owner = array();
                                 $owner['owner_lat'] = $owner_data->latitude;
                                 $owner['owner_long'] = $owner_data->longitude;
                                 $owner['owner_dist_lat'] = $request->D_latitude;
                                 $owner['owner_dist_long'] = $request->D_longitude;
                                 //$owner['payment_type'] = $owner_data->cash_or_card;
                                 $owner['payment_type'] = "";
                                 $owner['default_card'] = $dif_card;
                                 $owner['dest_latitude'] = $request->D_latitude;
                                 $owner['dest_longitude'] = $request->D_longitude;
                                 $owner['referral_code'] = $code_data->referral_code;
                                 $owner['is_referee'] = $owner_data->is_referee;
                                 $owner['promo_count'] = $owner_data->promo_count;
                                 /* $driver = Keywords::where('id', 1)->first(); */
                                 $requestserv = RequestServices::where('request_id', $request->id)->first();
                                 $charge = array();
                                 $request_typ = ProviderType::where('id', '=', $requestserv->type)->first();
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 if ($unit == 0) {
                                     $unit_set = 'kms';
                                 } elseif ($unit == 1) {
                                     $unit_set = 'miles';
                                 }
                                 $charge['unit'] = $unit_set;
                                 if ($requestserv->base_price != 0) {
                                     $charge['base_distance'] = $request_typ->base_distance;
                                     $charge['base_price'] = currency_converted($requestserv->base_price);
                                     $charge['distance_price'] = currency_converted($requestserv->distance_cost);
                                     $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost);
                                 } else {
                                     /* $setbase_price = Settings::where('key', 'base_price')->first();
                                        $charge['base_price'] = currency_converted($setbase_price->value);
                                        $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                        $charge['distance_price'] = currency_converted($setdistance_price->value);
                                        $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                        $charge['price_per_unit_time'] = currency_converted($settime_price->value); */
                                     $charge['base_distance'] = $request_typ->base_distance;
                                     $charge['base_price'] = currency_converted($request_typ->base_price);
                                     $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance);
                                     $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time);
                                 }
                                 $charge['total'] = currency_converted($request->total);
                                 $charge['is_paid'] = $request->is_paid;
                                 $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => 0, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => $walker_data, 'bill' => "", 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge, 'confirmed_walker' => 0, 'error_code' => 484, 'error' => 'Searching for ' . Config::get('app.generic_keywords.Provider') . 's.');
                             }
                         } else {
                             /* $driver = Keywords::where('id', 1)->first(); */
                             if ($request->current_walker != 0) {
                                 $walker = Walker::find($request->current_walker);
                                 $walker_data = array();
                                 $walker_data['unique_id'] = 1;
                                 $walker_data['id'] = $walker->id;
                                 $walker_data['first_name'] = $walker->first_name;
                                 $walker_data['last_name'] = $walker->last_name;
                                 $walker_data['phone'] = $walker->phone;
                                 $walker_data['bio'] = $walker->bio;
                                 $walker_data['picture'] = $walker->picture;
                                 $walker_data['latitude'] = $walker->latitude;
                                 $walker_data['longitude'] = $walker->longitude;
                                 $walker_data['type'] = $walker->type;
                                 $walker_data['car_model'] = $walker->car_model;
                                 $walker_data['car_number'] = $walker->car_number;
                                 $walker_data['bearing'] = $walker->bearing;
                                 $walker_data['payment_type'] = $request->cash_or_card;
                                 $walker_data['rating'] = $walker->rate;
                                 $walker_data['num_rating'] = $walker->rate_count;
                             }
                             $cards = "";
                             /* $cards['none'] = ""; */
                             $dif_card = 0;
                             $cardlist = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first();
                             /* $cardlist = Payment::where('id', $owner_data->default_card_id)->first(); */
                             if (count($cardlist) >= 1) {
                                 $cards = array();
                                 $default = $cardlist->is_default;
                                 if ($default == 1) {
                                     $dif_card = $cardlist->id;
                                     $cards['is_default_text'] = "default";
                                 } else {
                                     $cards['is_default_text'] = "not_default";
                                 }
                                 $cards['card_id'] = $cardlist->id;
                                 $cards['owner_id'] = $cardlist->owner_id;
                                 $cards['customer_id'] = $cardlist->customer_id;
                                 $cards['last_four'] = $cardlist->last_four;
                                 $cards['card_token'] = $cardlist->card_token;
                                 $cards['card_type'] = $cardlist->card_type;
                                 $cards['is_default'] = $default;
                             }
                             $code_data = Ledger::where('owner_id', '=', $owner_data->id)->first();
                             $owner = array();
                             $owner['owner_lat'] = $owner_data->latitude;
                             $owner['owner_long'] = $owner_data->longitude;
                             $owner['owner_dist_lat'] = $request->D_latitude;
                             $owner['owner_dist_long'] = $request->D_longitude;
                             // $owner['payment_type'] = $owner_data->cash_or_card;
                             $owner['payment_type'] = "";
                             $owner['default_card'] = $dif_card;
                             $owner['dest_latitude'] = $request->D_latitude;
                             $owner['dest_longitude'] = $request->D_longitude;
                             $owner['referral_code'] = $code_data->referral_code;
                             $owner['is_referee'] = $owner_data->is_referee;
                             $owner['promo_count'] = $owner_data->promo_count;
                             /* $driver = Keywords::where('id', 1)->first(); */
                             $requestserv = RequestServices::where('request_id', $request->id)->first();
                             $charge = array();
                             $request_typ = ProviderType::where('id', '=', $requestserv->type)->first();
                             $settings = Settings::where('key', 'default_distance_unit')->first();
                             $unit = $settings->value;
                             if ($unit == 0) {
                                 $unit_set = 'kms';
                             } elseif ($unit == 1) {
                                 $unit_set = 'miles';
                             }
                             $charge['unit'] = $unit_set;
                             if ($requestserv->base_price != 0) {
                                 $charge['base_distance'] = $request_typ->base_distance;
                                 $charge['base_price'] = currency_converted($requestserv->base_price);
                                 $charge['distance_price'] = currency_converted($requestserv->distance_cost);
                                 $charge['price_per_unit_time'] = currency_converted($requestserv->time_cost);
                             } else {
                                 /* $setbase_price = Settings::where('key', 'base_price')->first();
                                    $charge['base_price'] = currency_converted($setbase_price->value);
                                    $setdistance_price = Settings::where('key', 'price_per_unit_distance')->first();
                                    $charge['distance_price'] = currency_converted($setdistance_price->value);
                                    $settime_price = Settings::where('key', 'price_per_unit_time')->first();
                                    $charge['price_per_unit_time'] = currency_converted($settime_price->value); */
                                 $charge['base_distance'] = $request_typ->base_distance;
                                 $charge['base_price'] = currency_converted($request_typ->base_price);
                                 $charge['distance_price'] = currency_converted($request_typ->price_per_unit_distance);
                                 $charge['price_per_unit_time'] = currency_converted($request_typ->price_per_unit_time);
                             }
                             $charge['total'] = currency_converted($request->total);
                             $charge['is_paid'] = $request->is_paid;
                             $response_array = array('success' => true, 'unique_id' => 1, 'status' => $request->status, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, 'confirmed_walker' => 0, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'is_cancelled' => $request->is_cancelled, 'dest_latitude' => $request->D_latitude, 'dest_longitude' => $request->D_longitude, 'promo_id' => $request->promo_id, 'promo_code' => $request->promo_code, 'walker' => "", 'bill' => "", 'owner' => $owner, 'card_details' => $cards, 'charge_details' => $charge, 'current_walker' => 0, 'error_code' => 483, 'error' => 'No ' . Config::get('app.generic_keywords.Provider') . 's are available currently. Please try after sometime.');
                         }
                         $response_code = 200;
                     } else {
                         /* $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */
                         $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with ' . Config::get('app.generic_keywords.User') . ' ID', 'error_code' => 407);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408);
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 /* $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                 $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }