Exemplo n.º 1
0
 public static function postAccomGuest()
 {
     if (Auth::check()) {
         $validation = \App\Models\Billing::validate(Input::all());
         //dd($validation);
         if ($validation->passes()) {
             if (\App\Models\Reservation::isRoomAvailable(\Carbon\Carbon::now(), Input::get('date_to'), Input::get('room')) > 0) {
                 return Redirect::route('accomguest')->withErrors(array('message' => 'Room is occupied in this period!'))->withInput();
             }
             if (!\App\Models\Reservation::checkRoomCapacity(Input::get('room'), Input::get('persons_number'))) {
                 return Redirect::route('createreservation')->withErrors(array('message' => 'Room does not have enough capacity!'))->withInput();
             }
             if (count(\App\Models\Reservation::checkIfExistsZakaznik(Input::get('guest_id'))) == 0) {
                 /** Here, you have to check if user_id is valid ID number **/
                 DB::insert('INSERT INTO zakaznik (meno, rodnecislo, adresa, datnar, telcis, mail) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('name'), Input::get('guest_id'), Input::get('address'), Input::get('birth_date'), Input::get('telephone'), Input::get('mail')]);
             }
             $pobyt_number_query = DB::select('SELECT MAX(cispobytu) AS maxx FROM pobyt');
             $pobyt_number = $pobyt_number_query[0]->maxx + 1;
             DB::insert('INSERT INTO pobyt (cispobytu, datum, datumdo, idzak, osob, pokoj) VALUES (?, ?, ?, ?, ?, ?)', [$pobyt_number, \Carbon\Carbon::now(), Input::get('date_to'), Input::get('guest_id'), Input::get('persons_number'), Input::get('room')]);
             DB::insert('INSERT INTO obyvana (CisPobytu, IDZak) VALUES (?, ?)', [$pobyt_number, Input::get('guest_id')]);
             return Redirect::route('home')->with('message', 'Your accomodation was succesfull!');
         } else {
             return Redirect::route('accomguest')->withErrors($validation)->withInput();
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }
Exemplo n.º 2
0
 public function postEditReservation()
 {
     if (Auth::check()) {
         $validation = \App\Models\ReservationEdit::validate(Input::all());
         if ($validation->passes()) {
             $save_res = \App\Models\Reservation::showReservation(Input::get('id'));
             DB::select(DB::raw('DELETE FROM rezervace WHERE cisrezervace = :some_variable'), array('some_variable' => Input::get('id')));
             /** Check if function does not return the same reservation **/
             foreach ($save_res as $value) {
                 $res = $value;
             }
             if (!\App\Models\Reservation::checkRoomCapacity((string) Input::get('room'), (string) Input::get('persons_number'))) {
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob,cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [$res->CisRezervace, $res->Datum, $res->DatumDo, $res->IDZak, $res->osob, $res->CisPokoje]);
                 return Redirect::route('editreservation')->withErrors(array('message' => 'Room does not have enough capacity. Please divide this reservation.'))->withInput()->with('previous', $res);
             }
             if (\App\Models\Reservation::isRoomAvailable(Input::get('date_from'), Input::get('date_to'), Input::get('room')) > 0) {
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob,cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [$res->CisRezervace, $res->Datum, $res->DatumDo, $res->IDZak, $res->osob, $res->CisPokoje]);
                 return Redirect::route('editreservation')->withErrors(array('message' => 'Room is occupied in this period!'))->withInput()->with('previous', $res);
             } else {
                 /** Here you have to edit database with input data, or in this case, insert new data **/
                 DB::insert('INSERT INTO rezervace (cisrezervace, datum, datumdo, idzak, osob, cispokoje) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('id'), Input::get('date_from'), Input::get('date_to'), $res->IDZak, Input::get('persons_number'), Input::get('room')]);
                 return Redirect::route('home')->with('message', 'Your reservation was succesfully updated!');
             }
         } else {
             foreach (\App\Models\Reservation::showReservation(Input::get('id')) as $value) {
                 $my_reservation = $value;
             }
             return Redirect::route('editreservation')->withErrors($validation)->withInput()->with('previous', $my_reservation);
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }