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'; }
if ($available_rooms >= $i['quantity']) { $reservation['status'] = 1; // means available return $reservation; } else { $reservation['status'] = 0; // means unavailable :( return $reservation; } }); Route::post('room/availability', function ($id) { $i = Input::all(); $available_rooms = 0; $room = RoomQty::with(array('roomReserved' => function ($query) use($i) { $query(function ($query2) use($i) { $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('status', '!=', 5); }))->get(); foreach ($room as $r) { if (empty($r->roomReserved)) { $available_rooms++; } } //return $room; return $available_rooms; }); /*DONT DELETE!!!*/ /*DONT DELETE!!!*/ /*DONT DELETE!!!*/ /*DONT DELETE!!!*/ /*DONT DELETE!!!*/
public function bookingStep2($id) { $i = Input::all(); $i['checkin'] = $i['checkin'] . ' 12:00:00'; // $i['checkout'] = $i['checkout'] . ' 11:59:00'; $total_price = null; $tax = null; $booking_session = []; $count = 0; //for test $count1 = 0; //for test $booked_room = []; //all picked rooms from available rooms $booked_room_id = []; //foreach(Session::get('reservation')['reservation_room'] as $rooms){ $count++; $room_id = $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('status', 1)->where('room_id', $room_id)->get(); foreach ($room_qty as $available) { if (count($available->roomReserved) == 0) { array_push($available_rooms, $available); } else { } } if (!empty($available_rooms)) { for ($counter = 0; $counter < $i['quantity']; $counter++) { array_push($booked_room, $available_rooms[$counter]); } } else { return '0'; //not available } //} //end of foreach $total_price = 0; if (!isset($_GET['bookingId'])) { $new_booking = new Booking(); $new_booking->firstname = 'WALK-IN'; $new_booking->lastname = 'WALK-IN'; $new_booking->address = 'WALK-IN'; $new_booking->contact_number = '000'; $new_booking->check_in = $i['checkin']; $new_booking->check_out = $i['checkout']; $new_booking->email_address = 'WALK-IN'; $new_booking->code = 'N/A'; $new_booking->status = 0; $new_booking->save(); } foreach ($booked_room as $b) { $ci = new Carbon($i['checkin']); $co = new Carbon($i['checkout']); $total_nights = $co->diff($ci)->days; $total_nights += 1; $total_price += $total_nights * $b->roomPrice->price; $total_price2 = $total_nights * $b->roomPrice->price; //$tax = $total_price2 * 0.12; //$total_price2+=$tax; $reserveRoom = new ReservedRoom(); $reserveRoom->room_id = $b->id; $reserveRoom->room_type = $b->room_id; $reserveRoom->booking_id = isset($_GET['bookingId']) ? $_GET['bookingId'] : $new_booking->id; $reserveRoom->check_in = $i['checkin']; $reserveRoom->check_out = $i['checkout']; $reserveRoom->code = 'N/A'; /*$reserveRoom->firstname = 'WALK-IN'; $reserveRoom->lastname = 'WALK-IN';*/ $reserveRoom->price = $total_price2; /*$reserveRoom->address = 'WALK-IN'; $reserveRoom->contact_number = '000'; $reserveRoom->email_address = 'WALK-IN';*/ $reserveRoom->status = '0'; if ($reserveRoom->save()) { array_push($booked_room_id, $reserveRoom->id); } } if (isset($_GET['bookingId'])) { $existing_booking = Booking::where('id', $_GET['bookingId'])->first(); if ($existing_booking) { $existing_booking->price = $total_price; } } else { $new_booking->price = $total_price; $new_booking->save(); } // return Session::get('reservation'); //return $booked_room; //return $counter; //return $room_qty1; $booking_session['booking_id'] = isset($_GET['bookingId']) ? $_GET['bookingId'] : $new_booking->id; $booking_session['rooms'] = $booked_room_id; return $booking_session; }