public function checkAvailability(Request $request) { $this->validate($request, ['single' => 'required | numeric', 'double' => 'required | numeric', 'tripple' => 'required | numeric']); // same operation for each room type // get all empty rooms -- 1 // get all rooms that will checkout before my chech in date -- 2 // add 1 and 2 -- 2.5 // get all check in between the range of my in and out dates -- 3 // get all who chech in and end after my check in date -- 4 not sure will not do // get all who will checkin between today and my checkin // 2.5 - (3 + 4) $single_room = -1; $double_room = -1; $triple_room = -1; $form = new formaction(); $checkin = $form->make_date($request->dayin, $request->monthin); $checkout = $form->make_date($request->dayout, $request->monthout); $today = date('Y-m-d'); $form->change_room_status(); // function to check if checkin after today or not $diff_now = DB::select(DB::raw("SELECT DATEDIFF('{$checkin}','{$today}') AS day")); if ($diff_now[0]->day < 0) { return 0; } // function to check if the checkin before the checkout $diff_co = DB::select(DB::raw("SELECT DATEDIFF('{$checkout}','{$checkin}') AS day")); if ($diff_co[0]->day < 0) { return 0; } if ($request->single > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 1)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(1, $unsroom); /*** getting total room number of that room and if total bigger than it equal it with the * total number of rooms of that type ***/ $num = DB::table('table_rooms')->where('room_type_id', 1)->get(); $numRooms = sizeof($num); if ($totalEmpty > $numRooms) { $totalEmpty = $numRooms; } // getting checkin between my checkin and checkout //$broom = DB::table('reservation_table')->where('checkin','>',"$checkin",'and','checkin','<=',"$checkout")->get(); $broom = DB::select(DB::raw("select * from reservation_table where checkin >= '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(1, $broom); //echo $btw_io; //getting all who will checkin between today and my checkin and //their checkout are after my checkin //$btwroom = DB::table('reservation_table')->whereBetween("checkin", array("$today" , "$checkin"))->where("checkout",'>',"$checkin")->get(); //$btwroom = DB::select(DB::raw("select * from reservation_table where (checkin > '$today' and checkin < '$checkin') and (checkout > $checkin)")); //$btwroom = DB::select(DB::raw("SELECT * FROM reservation_table WHERE (checkin >= '$today' AND checkin < '$checkin') AND checkout > '$checkin' )")); $btwroom = DB::table('reservation_table')->where('checkin', '>=', "{$today}")->where('checkin', '<', "{$checkin}")->where('checkout', '>', "{$checkin}")->get(); $btwroom_s = $form->get_room(1, $btwroom); //echo $btwroom_s; // calculate total empty rooms $single_room = $totalEmpty - ($btw_io + $btwroom_s); } else { $single_room = -2; } if ($request->double > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 2)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(2, $unsroom); /*** getting total room number of that room and if total bigger than it equal it with the * total number of rooms of that type ***/ $num = DB::table('table_rooms')->where('room_type_id', 2)->get(); $numRooms = sizeof($num); if ($totalEmpty > $numRooms) { $totalEmpty = $numRooms; } // getting checkin between my checkin and checkout $broom = DB::select(DB::raw("select * from reservation_table where checkin >= '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(2, $broom); // echo $btw_io; //getting all who will checkin between today and my checkin //$btwroom = DB::select(DB::raw("select * from reservation_table where (checkin >= '$today' and checkin < '$checkin') and (checkout > $checkin)")); //$btwroom = DB::select(DB::raw("SELECT * FROM reservation_table WHERE checkin >= '$today' AND checkout > '$checkin' ")); $btwroom = DB::table('reservation_table')->where('checkin', '>=', "{$today}")->where('checkin', '<', "{$checkin}")->where('checkout', '>', "{$checkin}")->get(); $btwroom_s = $form->get_room(2, $btwroom); //echo $btwroom_s; // calculate total empty rooms //$room = $totalEmpty - ($btw_io + $btwroom_s); $double_room = $totalEmpty - ($btw_io + $btwroom_s); //echo $double_room; //echo $room; } else { $double_room = -2; } if ($request->tripple > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 3)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(3, $unsroom); /*** getting total room number of that room and if total bigger than it equal it with the * total number of rooms of that type ***/ $num = DB::table('table_rooms')->where('room_type_id', 3)->get(); $numRooms = sizeof($num); if ($totalEmpty > $numRooms) { $totalEmpty = $numRooms; } /**********************************************/ // getting checkin between my checkin and checkout $broom = DB::select(DB::raw("select * from reservation_table where checkin >= '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(3, $broom); // echo $btw_io; //getting all who will checkin between today and my checkin //$btwroom = DB::select(DB::raw("select * from reservation_table where (checkin >= '$today' and checkin < '$checkin') and (checkout > $checkin)")); //$btwroom = DB::select(DB::raw("SELECT * FROM reservation_table WHERE checkin >= '$today' AND checkout > '$checkin' ")); $btwroom = DB::table('reservation_table')->where('checkin', '>=', "{$today}")->where('checkin', '<', "{$checkin}")->where('checkout', '>', "{$checkin}")->get(); $btwroom_s = $form->get_room(3, $btwroom); //echo $btwroom_s; // calculate total empty rooms //$room = $totalEmpty - ($btw_io + $btwroom_s); $triple_room = $totalEmpty - ($btw_io + $btwroom_s); //echo $room; } else { $triple_room = -2; } //var_dump(); $room_av = array($single_room, $double_room, $triple_room); $req_av = array((int) $request->single, (int) $request->double, (int) $request->tripple); for ($i = 0; $i < 3; $i++) { if ($room_av[$i] != -2) { if (!($room_av[$i] >= $req_av[$i])) { return 0; } } } return 1; }
public function checkAvailability(Request $request) { // same operation for each room type // get all empty rooms -- 1 // get all rooms that will checkout before my chech in date -- 2 // add 1 and 2 -- 2.5 // get all check in between the range of my in and out dates -- 3 // get all who chech in and end after my check in date -- 4 not sure will not do // get all who will checkin between today and my checkin // 2.5 - (3 + 4) $single_room = -1; $double_room = -1; $triple_room = -1; $form = new formaction(); $checkin = $form->make_date($request->dayin, $request->monthin); $checkout = $form->make_date($request->dayout, $request->monthout); $today = date("Y-m-d"); $form->change_room_status(); $diff_now = DB::select(DB::raw("SELECT DATEDIFF('{$checkin}','{$today}') AS day")); if ($diff_now[0]->day < 0) { return 0; } $diff_co = DB::select(DB::raw("SELECT DATEDIFF('{$checkout}','{$checkin}') AS day")); if ($diff_co[0]->day < 0) { return 0; } if ($request->single > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 1)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(1, $unsroom); // getting checkin between my checkin and checkout //$broom = DB::table('reservation_table')->where('checkin','>',"$checkin",'and','checkin','<=',"$checkout")->get(); $broom = DB::select(DB::raw("select * from reservation_table where checkin > '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(1, $broom); //echo $btw_io; //getting all who will checkin between today and my checkin $btwroom = DB::table('reservation_table')->whereBetween("checkin", array("{$today}", "{$checkin}"))->get(); $btwroom_s = $form->get_room(1, $btwroom); //echo $btwroom_s; // calculate total empty rooms //$room = $totalEmpty - ($btw_io + $btwroom_s); $single_room = $totalEmpty - ($btw_io + $btwroom_s); //echo $single_room; //echo $room; } else { $single_room = -2; } if ($request->double > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 2)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(2, $unsroom); // getting checkin between my checkin and checkout $broom = DB::select(DB::raw("select * from reservation_table where checkin > '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(2, $broom); // echo $btw_io; //getting all who will checkin between today and my checkin $btwroom = DB::table('reservation_table')->whereBetween("checkin", array("{$today}", "{$checkin}"))->get(); $btwroom_s = $form->get_room(2, $btwroom); //echo $btwroom_s; // calculate total empty rooms //$room = $totalEmpty - ($btw_io + $btwroom_s); $double_room = $totalEmpty - ($btw_io + $btwroom_s); //echo $double_room; //echo $room; } else { $double_room = -2; } if ($request->tripple > 0) { // getting all empty rooms $sroom = DB::table('table_rooms')->where('room_type_id', 3)->where('room_state', 1)->get(); // getting all who will checkout between today and my checkin $unsroom = DB::table('reservation_table')->whereBetween("checkout", array("{$today}", "{$checkin}"))->get(); // add 1 and 2 which is empty rooms and rooms that will checkout before my checkin $totalEmpty = sizeof($sroom) + $form->get_room(3, $unsroom); // getting checkin between my checkin and checkout $broom = DB::select(DB::raw("select * from reservation_table where checkin > '{$checkin}' and checkin <= '{$checkout}' ")); $btw_io = $form->get_room(3, $broom); // echo $btw_io; //getting all who will checkin between today and my checkin $btwroom = DB::table('reservation_table')->whereBetween("checkin", array("{$today}", "{$checkin}"))->get(); $btwroom_s = $form->get_room(3, $btwroom); //echo $btwroom_s; // calculate total empty rooms //$room = $totalEmpty - ($btw_io + $btwroom_s); $triple_room = $totalEmpty - ($btw_io + $btwroom_s); //echo $room; } else { $triple_room = -2; } //var_dump(); $room_av = array($single_room, $double_room, $triple_room); $req_av = array((int) $request->single, (int) $request->double, (int) $request->tripple); for ($i = 0; $i < 3; $i++) { if ($room_av[$i] != -2) { if (!($room_av[$i] >= $req_av[$i])) { return 0; } } } return 1; }