/**
  * controller buat handle request post ke URI /report_location
  * attribut post ada rute_id, lat, long, speed, semua dikirim plain form request
  *
  * @param Request $requests
  * @return \Illuminate\Http\JsonResponse
  */
 public function postLocation(Request $requests)
 {
     $routeModel = new route();
     $plat = $requests->input('plat');
     $this->plat_nomor = $plat;
     $input_token = $requests->input('token');
     $bus = new BusOperation();
     $reference_token = $bus->select('token')->where('plat_nomor', '=', $plat)->get()->toArray();
     try {
         if ($input_token == $reference_token[0]['token']) {
             $location = new StoreLocationModel();
             $location->route_id = $requests->input('rute_id');
             $this->rute_id = $requests->input('rute_id');
             $routeModel->where('rute_id', '=', $this->rute_id)->firstOrFail();
             $flagCheck = $this->checkBusIteration();
             $location->latitude = $requests->input('lat');
             $this->busLat = $requests->input('lat');
             $location->longitude = $requests->input('long');
             $this->busLon = $requests->input('long');
             $location->avg_speed = $requests->input('speed');
             $this->avg_speed = $requests->input('speed');
             $location->plat_nomor = $plat;
             $location->save();
             if ($flagCheck) {
                 if ($location->save()) {
                     $this->getLastBusStop();
                     $this->selectBusHistory();
                     try {
                         $this->getAllBusStop();
                     } catch (\Exception $e) {
                         $this->response['data']['msg'] = 'internal error, cannot make request to third pary service or temporary connection down, please try again or report it';
                         $this->response['code'] = 500;
                         header("Access-Control-Allow-Origin: *");
                         return response()->json($this->response);
                     }
                     $this->updateBusOperation();
                     $this->checkBusLocationStatus();
                     $this->checkBusStopHistory();
                     $this->detectSpeedViolation();
                     //all operation successfull
                     header("Access-Control-Allow-Origin: *");
                     return response()->json($this->response);
                 } else {
                     $this->response['data']['msg'] = 'internal error, cannot save data to database, please try again or report it';
                     $this->response['code'] = 500;
                     header("Access-Control-Allow-Origin: *");
                     return response()->json($this->response);
                 }
             } else {
                 $this->updateBusOperation();
                 $this->response['code'] = 200;
                 $this->response['data']['msg'] = 'update bus coordinate location';
                 header("Access-Control-Allow-Origin: *");
                 return response()->json($this->response);
             }
         } else {
             $this->response['data']['msg'] = 'transaction failed, make sure you enter a valid token';
             $this->response['code'] = 400;
             header("Access-Control-Allow-Origin: *");
             return response()->json($this->response);
         }
     } catch (\Exception $e) {
         $this->response['data']['msg'] = 'one or more of your parameter value is invalid, make sure you send correct parameter';
         $this->response['code'] = 400;
         header("Access-Control-Allow-Origin: *");
         return response()->json($this->response);
     }
 }