public function store(BookingRequest $request)
 {
     $booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part, 'ip_info' => $request->ip_info);
     $newBooking = Booking::create($booking);
     flash()->success('Your booking has been created!')->important();
     if (!empty($request->comment1)) {
         //children comment
         $comment1 = array('booking_id' => $newBooking->id, 'comment_type_id' => '1', 'role_id' => '1', 'comment' => $request->comment1);
         Comment::create($comment1);
     }
     if (!empty($request->comment2)) {
         //general comment
         $comment2 = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment2);
         Comment::create($comment2);
     }
     $change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => Auth::user()->id, 'from' => null, 'to' => null);
     Change::create($change);
     $passenger = User::firstOrNew(['email' => $request->email]);
     $passenger->name = $request->name;
     $passenger->phone = $request->phone;
     $passenger->save();
     $role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $passenger->id);
     Role::create($role);
     $price = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $request->price);
     Income::create($price);
     $locationArray = $request->location;
     foreach ($request->address as $order => $address_id) {
         $route_point = null;
         $route_point = array('booking_id' => $newBooking->id, 'location_id' => $locationArray[$order], 'address_id' => $address_id, 'order' => $order);
         Route_point::create($route_point);
     }
     return redirect('bookings');
 }
 public function store(ReservationRequest $request)
 {
     //booking
     $booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part);
     $newBooking = Booking::create($booking);
     // main passenger
     //user (main passenger)
     $mainpassenger = new User();
     $mainpassenger->name = $request->name;
     $mainpassenger->phone = $request->phone;
     $mainpassenger->save();
     //role (main passenger)
     $role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $mainpassenger->id);
     Role::create($role);
     //email receiver
     //user (email receiver)
     $emailreceiver = User::firstOrCreate(['email' => $request->email]);
     //role (email receiver)
     $role = array('booking_id' => $newBooking->id, 'role_type_id' => '5', 'user_id' => $emailreceiver->id);
     Role::create($role);
     //route points
     //start
     $route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->start_location_id, 'sub_location_id' => $request->start_sub_location_id, 'description' => $request->start_description, 'order' => 1);
     Route_point::create($route_point);
     //via points
     $descriptionArray = $request->description;
     //if via array is not empty
     if (!empty($request->location_id)) {
         foreach ($request->location_id as $order => $location_id) {
             $route_point = null;
             $route_point = array('booking_id' => $newBooking->id, 'location_id' => $location_id, 'description' => $descriptionArray[$order], 'order' => $order);
             Route_point::create($route_point);
         }
     }
     //end
     $route_point = null;
     $route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->end_location_id, 'description' => $request->end_description, 'order' => 99);
     Route_point::create($route_point);
     //general comment
     if (!empty($request->comment)) {
         $comment = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment);
         Comment::create($comment);
     }
     //price
     $price = Income_list::where('car_type_id', $request->car_type_id)->where('direction_id', $request->direction_id)->where('income_type_id', 1)->whereNull('user_id')->first();
     $income = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $price->amount_eur);
     Income::create($income);
     //cashflow
     if ($request->payment_type_id == 3) {
         $receiver_id = 1;
         //receiver is driver
         $due_date = $newBooking->pickup_time;
         //on the day of travel
     } else {
         $receiver_id = 4;
         //receiver is us (admin)
         $pickup_time = new Carbon($newBooking->pickup_time);
         $due_date = $pickup_time->subHours(48);
         //48 hours before trip
     }
     $cashflow = array('booking_id' => $newBooking->id, 'payer_id' => 2, 'receiver_id' => $receiver_id, 'payment_type_id' => $request->payment_type_id, 'payment_status_id' => 1, 'amount_eur' => $price->amount_eur, 'due_date' => $due_date);
     Cashflow::create($cashflow);
     //log reservation creation
     $change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => 1, 'from' => null, 'to' => null);
     Change::create($change);
     //send email
     Mail::queue('emails.reservation', ['passenger' => $mainpassenger], function ($message) use($emailreceiver) {
         $message->from('*****@*****.**', 'Transfer Praha')->to($emailreceiver->email, null)->subject('Booking confirmation');
     });
     flash()->success('Your booking has been created!')->important();
     return redirect('reservation/confirmation');
 }
 public function destroy($id)
 {
     Route_point::destroy($id);
 }