public function clientBookingStep5()
 {
     //return Session::get('reservation');
     $tax = null;
     $total_price = null;
     $i = [];
     $i['checkin'] = Session::get('reservation')['checkin'] . ' 12:00:00';
     $i['checkout'] = Session::get('reservation')['checkout'] . '11:59:00';
     $customerinformation = Session::get('reservation.customerinformation');
     $count = 0;
     //for test
     $count1 = 0;
     //for test
     $booked_room = [];
     //all picked rooms from available rooms
     $new_booking = new Booking();
     $new_booking->firstname = $customerinformation['firstname'];
     $new_booking->lastname = $customerinformation['lastname'];
     $new_booking->address = $customerinformation['address'];
     $new_booking->contact_number = $customerinformation['contact_no'];
     $new_booking->email_address = $customerinformation['email'];
     $new_booking->check_in = $i['checkin'];
     $new_booking->check_out = $i['checkout'];
     $new_booking->save();
     foreach (Session::get('reservation')['reservation_room'] as $rooms) {
         $count++;
         $room_id = $rooms['room_details']['id'];
         $available_rooms = [];
         $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
             $query->where(function ($query2) use($i, $room_id) {
                 $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
             })->where(function ($query3) {
                 $query3->where('status', '!=', 5)->where('status', '!=', 3);
             });
         }))->where('room_id', $room_id)->get();
         foreach ($room_qty as $available) {
             if ($available->roomReserved == '[]') {
                 array_push($available_rooms, $available);
             }
         }
         for ($counter = 0; $counter < $rooms['quantity']; $counter++) {
             array_push($booked_room, $available_rooms[$counter]);
         }
     }
     //end of foreach
     $total = 0;
     if (!empty($booked_room)) {
         foreach ($booked_room as $b) {
             $total += $b->roomPrice->price * Session::get('reservation.nights');
             $tax = $total * 0.12;
             $total = $total + $tax;
             $reserveRoom = new ReservedRoom();
             $reserveRoom->booking_id = $new_booking->id;
             $reserveRoom->room_id = $b->id;
             $reserveRoom->price = $total;
             /*$reserveRoom->check_in = $i['checkin'];
             		$reserveRoom->check_out = $i['checkout'];
             		$reserveRoom->firstname = $customerinformation['firstname'];
             		$reserveRoom->lastname = $customerinformation['lastname'];
             		$reserveRoom->address = $customerinformation['address'];
             		$reserveRoom->contact_number = $customerinformation['contact_no'];
             		$reserveRoom->email_address = $customerinformation['email'];*/
             $reserveRoom->save();
         }
     }
     $tax = $total * 0.12;
     $total = $total + $tax;
     $new_booking->price = $total;
     $new_booking->save();
     return Redirect::to('booking/step5');
 }
 public function getPaymentStatus()
 {
     // Get the payment ID before session clear
     $payment_id = Session::get('paypal_payment_id');
     // clear the session payment ID
     Session::forget('paypal_payment_id');
     if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
         return Redirect::route('original.route')->with('error', 'Payment failed');
     }
     $payment = Payment::get($payment_id, $this->_api_context);
     // PaymentExecution object includes information necessary
     // to execute a PayPal account payment.
     // The payer_id is added to the request query parameters
     // when the user is redirected from paypal back to your site
     $execution = new PaymentExecution();
     $execution->setPayerId(Input::get('PayerID'));
     //Execute the payment
     $result = $payment->execute($execution, $this->_api_context);
     /*echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later*/
     if ($result->getState() == 'approved') {
         // payment made
         // $tax = null;
         $total_price = null;
         $i = [];
         $i['checkin'] = Session::get('reservation')['checkin'] . '12:00:00';
         $i['checkout'] = Session::get('reservation')['checkout'] . '11:59:00';
         $customerinformation = Session::get('reservation.customerinformation');
         $count = 0;
         //for test
         $count1 = 0;
         //for test
         $booked_room = [];
         //all picked rooms from available rooms
         $new_booking = new Booking();
         $new_booking->firstname = $customerinformation['firstname'];
         $new_booking->lastname = $customerinformation['lastname'];
         $new_booking->address = $customerinformation['address'];
         $new_booking->contact_number = $customerinformation['contact_no'];
         $new_booking->email_address = $customerinformation['email'];
         $new_booking->check_in = $i['checkin'];
         $new_booking->check_out = $i['checkout'];
         $new_booking->payment_type = 'paypal';
         $new_booking->paypal_paymentId = Input::get('PayerID');
         $new_booking->save();
         if (Session::has('hasMembershipDiscount')) {
             $booking_remarks = new BookingRemarksHistory();
             $booking_remarks->remarks = "Membership Discount";
             $booking_remarks->deduction = Session::get('hasMembershipDiscount');
             $booking_remarks->booking_id = $new_booking->id;
             $booking_remarks->save();
             Session::forget('hasMembershipDiscount');
         }
         if (Session::has('hasCouponDiscount')) {
             $booking_remarks = new BookingRemarksHistory();
             $booking_remarks->remarks = "Coupon Discount";
             $booking_remarks->deduction = Session::get('hasCouponDiscount');
             $booking_remarks->booking_id = $new_booking->id;
             $booking_remarks->save();
             Session::forget('hasCouponDiscount');
         }
         foreach (Session::get('reservation')['reservation_room'] as $rooms) {
             $count++;
             $room_id = $rooms['room_details']['id'];
             $available_rooms = [];
             $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
                 $query->where(function ($query2) use($i, $room_id) {
                     $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
                 })->where(function ($query3) {
                     $query3->where('status', '!=', 5)->orWhere('status', '!=', 3);
                 });
             }))->where('room_id', $room_id)->where('status', 1)->get();
             foreach ($room_qty as $available) {
                 if ($available->roomReserved == '[]') {
                     array_push($available_rooms, $available);
                 }
             }
             for ($counter = 0; $counter < $rooms['quantity']; $counter++) {
                 array_push($booked_room, $available_rooms[$counter]);
             }
         }
         $total = 0;
         if (!empty($booked_room)) {
             foreach ($booked_room as $b) {
                 $roomprice = $b->roomPrice->price * Session::get('reservation.nights');
                 $total += $b->roomPrice->price * Session::get('reservation.nights');
                 //$roomprice+=$tax;
                 //$total = $total + $tax;
                 $reserveRoom = new ReservedRoom();
                 $reserveRoom->booking_id = $new_booking->id;
                 $reserveRoom->room_id = $b->id;
                 $reserveRoom->room_type = $b->room_id;
                 $reserveRoom->price = $roomprice;
                 $reserveRoom->check_in = $i['checkin'];
                 $reserveRoom->check_out = $i['checkout'];
                 $reserveRoom->status = 1;
                 $reserveRoom->firstname = $customerinformation['firstname'];
                 $reserveRoom->lastname = $customerinformation['lastname'];
                 $reserveRoom->address = $customerinformation['address'];
                 $reserveRoom->contact_number = $customerinformation['contact_no'];
                 $reserveRoom->email_address = $customerinformation['email'];
                 $reserveRoom->save();
             }
         }
         //$tax = $total * 0.12;
         //$total = $total + $tax;
         $new_booking->price = Session::get('total_price');
         $new_booking->paid = Session::get('total_price');
         $new_booking->status = 1;
         $date = date('Ymd');
         $code = strtolower(Str::random(5) . $date);
         $new_booking->code = $code;
         $new_booking->save();
         Session::forget('reservation');
         Session::forget('total_price');
         return Redirect::to('booking/step5')->with('code', $code);
     }
     return 'error in payment';
 }
 Route::get('dashboard/departure/aPassword::sendReminder(user, token, callback)jax', 'DashboardController@ajax_todayDeparture');
 Route::get('dashboard/occupied_booking/ajax', 'DashboardController@ajax_todayBookingOccupied');
 Route::get('dashboard/preparing_booking/ajax', 'DashboardController@ajax_todayBookingPreparing');
 Route::get('dashboard/success_booking', 'DashboardController@todayBookingSuccess');
 Route::get('dashboard/cancelled_booking', 'DashboardController@todayBookingCancelled');
 Route::get('dashboard/pending_booking', 'DashboardController@todayBookingPending');
 Route::get('dashboard/arrival', 'DashboardController@todayArrival');
 Route::get('dashboard/departure', 'DashboardController@todayDeparture');
 Route::get('dashboard/occupied', 'DashboardController@todayBookingOccupied');
 Route::get('dashboard/preparing', 'DashboardController@todayBookingPreparing');
 Route::get('reservation/list/ajax', 'BookingController@thisYearList');
 Route::get('activity', 'ActivitiesController@index');
 Route::get('room', 'RoomController@index');
 Route::get('room/all', 'RoomController@allrooms');
 Route::get('room/search/{query}', function ($query) {
     $r = RoomQty::where('room_no', $query)->first();
     if (!empty($r)) {
         $room_id = $r->room_id;
         $rooms = Room::with('roomQty', 'roomImages.photo')->where('id', $room_id)->get();
         //return 'heyt';
         return $rooms;
     } else {
         return '0';
     }
     return 'hey';
 });
 Route::get('user', 'UsersController@index');
 Route::post('user/create', 'UsersController@store');
 Route::post('user/{id}/delete', 'UsersController@destroy');
 Route::post('user/{id}/update', 'UsersController@update');
 Route::get('settings', function () {
 public function updateSpecific($id)
 {
     $i = Input::all();
     $today = Date('Y-m-d H:i:s');
     $tomorrow = new DateTime('tomorrow');
     $tomorrow = $tomorrow->format('Y-m-d') . ' 11:59:00';
     $r = RoomQty::where('id', $id)->with(array('roomReserved' => function ($query) use($today, $tomorrow) {
         $query->where(function ($query2) use($today, $tomorrow) {
             $query2->whereBetween('check_in', array($today, $tomorrow))->orWhereBetween('check_out', array($today, $tomorrow))->orWhereRaw('"' . $today . '" between check_in and check_out')->orWhereRaw('"' . $tomorrow . '" between check_in and check_out');
         })->where(function ($query3) {
             $query3->where('status', '!=', 5)->where('status', '!=', 3);
         });
     }))->first();
     if (!empty($r)) {
         $r->room_no = $i['room_no'];
         $r->status = $i['status'];
         if ($r->save()) {
             return $r;
         } else {
             return '0';
             //means failed
         }
     }
 }