/**
  * This function is used to load the room modal contents.This function response to
  *a ajax call.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function roomViewLoad(Request $request)
 {
     $inputs = $request::all();
     $room_id = $inputs['room_id'];
     $image1 = ROOM_IMAGE::where('room_type_id', '=', $room_id)->first();
     if (!empty($image1)) {
         $images = ROOM_IMAGE::where('room_type_id', '=', $room_id)->where('path', '!=', $image1->path)->select('path')->get();
         $path = $image1->path;
     } else {
         $images = array();
         $path = null;
     }
     $room_furnishes = RoomTypeFurnish::where('room_type_id', '=', $room_id)->join('ROOM_FURNISHING', 'ROOM_TYPE_FURNISH.furnish_id', '=', 'ROOM_FURNISHING.rf_id')->select('name')->get();
     $room_services = RoomTypeService::where('room_type_id', '=', $room_id)->join('ROOM_SERVICES', 'ROOM_TYPE_SERVICE.service_id', '=', 'ROOM_SERVICES.rs_id')->select('name')->get();
     $room_rates = RATE::join('MEAL_TYPES', 'RATES.meal_type_id', '=', 'MEAL_TYPES.meal_type_id')->where('RATES.room_type_id', '=', $room_id)->select('MEAL_TYPES.meal_type_name', 'RATES.rate_code', 'RATES.single_rates')->get();
     $arr_dep_time = DB::table('HOTEL_INFO')->select('check_in', 'check_out')->first();
     if (!empty($arr_dep_time)) {
         $checkin = $arr_dep_time->check_in;
         $checkout = $arr_dep_time->check_out;
     } else {
         $checkin = null;
         $checkout = null;
     }
     return response()->json(['rimage1' => $path, 'rimages' => $images, 'room_furnishes' => $room_furnishes, 'room_services' => $room_services, 'room_rates' => $room_rates, 'check_in' => $checkin, 'check_out' => $checkout]);
 }
 /**
  * This function rooms selected for the reservation to the session.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function addSelectedRooms(Request $request)
 {
     $inputs = $request::all();
     //get the selected rooms details and store it to variables
     $room_type_id = $inputs['room_type_id'];
     $room_type_name = $inputs['room_type_name'];
     $no_of_rooms = $inputs['no_of_rooms'];
     $rate_code = $inputs[$room_type_id . 'rate_code'];
     $rate_price = RATE::where('rate_code', '=', $rate_code)->value('single_rates');
     //get the early rate if the selected room is already in the session
     $early_rate_price = 0;
     $meal_type_name = RATE::join('MEAL_TYPES', 'RATES.meal_type_id', '=', 'MEAL_TYPES.meal_type_id')->where('RATES.rate_code', '=', $rate_code)->value('meal_type_name');
     //this variable is to identify whether the selected room type already added in the session previously
     $session_have = config('constants.CHK_ZERO');
     //check whether session has the room type added already
     if (Session::has('room_types')) {
         foreach (session('room_types') as $room_type) {
             if ($room_type == $room_type_id) {
                 $session_have = config('constants.SESSION_HAVE');
                 $early_rate_price = RATE::where('rate_code', '=', session('rate_code' . $room_type_id))->value('single_rates');
             }
         }
     }
     //store the total payable amount from the session to a variable
     $total_payable = config('constants.CHK_ZERO');
     if (Session::has('total_payable')) {
         $total_payable = session('total_payable');
     }
     //if the room type is already in the session update that session by replacing it
     if ($session_have == config('constants.SESSION_HAVE')) {
         $total_payable = $total_payable - $early_rate_price * session('no_of_rooms' . $room_type_id) + $rate_price * $no_of_rooms;
         Session::put(['no_of_rooms' . $room_type_id => $no_of_rooms, 'rate_code' . $room_type_id => $rate_code, 'rate' . $room_type_id => $rate_price]);
         Session::put(['meal_type' . $room_type_id => $meal_type_name, 'meal_type' . $room_type_id => $meal_type_name, 'total_payable' => $total_payable]);
     } else {
         //if the room type is not available push the selected room type details to the session
         $total_payable += $rate_price * $no_of_rooms;
         Session::push('room_types', $room_type_id);
         Session::put(['no_of_rooms' . $room_type_id => $no_of_rooms, 'room_type_name' . $room_type_id => $room_type_name, 'rate_code' . $room_type_id => $rate_code]);
         Session::put(['rate' . $room_type_id => $rate_price, 'meal_type' . $room_type_id => $meal_type_name, 'total_payable' => $total_payable]);
     }
     //create arrays to store the session details to respond to a ajax request, this was done because without
     // refreshing the pages session values wont be updated in the views
     $room_types = array();
     $number_rooms = array();
     $rates = array();
     $meal = array();
     $room_type_ids = array();
     //push the values to the array
     foreach (session('room_types') as $room_type) {
         array_push($room_type_ids, $room_type);
         array_push($room_types, session('room_type_name' . $room_type));
         array_push($number_rooms, session('no_of_rooms' . $room_type));
         array_push($rates, session('rate' . $room_type));
         array_push($meal, session('meal_type' . $room_type));
     }
     return response()->json(['ids' => $room_type_ids, 'room_types' => $room_types, 'no_of_rooms' => $number_rooms, 'rates' => $rates, 'meals' => $meal]);
 }
Exemplo n.º 3
0
 /**
  * update room type
  *
  * @param Request $request
  *
  */
 public function admin_roomtype_update(Request $request)
 {
     $rt = RoomType::find($request->input('main_id'));
     $rt->type_name = $request->input('rtname');
     $rt->description = $request->input('rtdes');
     $rt->type_code = $request->input('rtcode');
     //$rt->services_provided = $request->input('wifi').";".$request->input('tv');
     $rt->save();
     $rate = RATE::where('room_type_id', $request->input('main_id'))->delete();
     $data = json_decode($request->input('data1'));
     foreach ($data as $d) {
         $rate = new RATE();
         $rate->meal_type_id = $d->meal;
         $rate->room_type_id = $rt->room_type_id;
         $rate->single_rates = $d->rate;
         $rate->save();
     }
     RoomTypeService::where('room_type_id', $request->input('main_id'))->delete();
     RoomTypeFurnish::where('room_type_id', $request->input('main_id'))->delete();
     for ($i = 100; $i < $request->input('rscount'); $i++) {
         if ($request->input("service" . $i) > 0) {
             $rts = new RoomTypeService();
             $rts->room_type_id = $rt->room_type_id;
             $rts->service_id = $request->input("service" . $i);
             $rts->save();
         }
     }
     for ($x = 100; $x < $request->input('rfcount'); $x++) {
         if ($request->input("furnish" . $x) > 0) {
             $rtf = new RoomTypeFurnish();
             $rtf->room_type_id = $rt->room_type_id;
             $rtf->furnish_id = $request->input("furnish" . $x);
             $rtf->save();
         }
     }
 }