GuestController.php 5.31 KB
Newer Older
Juliper committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Notifications\Messages\NexmoMessage;
use SimpleSoftwareIO\SMS\Drivers\NexmoSMS;
use Nexmo;
use App\Feedback;
use App\Homestay;
use App\ListBook;
use App\Room;
use App\Transaksi;
use Illuminate\Support\Facades\Auth;
use App\User;
use App\Customer;
use Illuminate\Support\Facades\DB;
use Illuminate\Contracts\Auth\Guard;
use DateTime;
use PhpParser\Node\Stmt\Const_;
use Psy\Command\ListCommand\ConstantEnumerator;
Palti Sinaga committed
22
use Validator;
Juliper committed
23 24


Juliper committed
25
class GuestController extends Controller
Juliper committed
26 27 28 29 30 31 32 33 34 35 36 37
{
    public function route(){

        Nexmo::message()->send([
            'to' => '6282272194654',
            'from' => 'ASDASD',
            'text' => 'Hi ini hanya sebuah test no more'
        ]);

        return view('welcome');
    }

Juliper committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

    public function cari(Request $request){

        $data =  Homestay::all();
        //$a = null;

        //$book_start[] = null;

        $i = 0;
        foreach ($data as $a){

            $book_start = DB::table('daftar_book')
                ->select('daftar_book.*')
                ->where('daftar_book.tanggal_mulai','=',$request['tanggal_mulai'])
                ->get();

            $book_finish = DB::table('daftar_book')
                ->select('daftar_book.*')
                ->where('daftar_book.tanggal_berakhir','=',$request['tanggal_selesai'])
                ->get();

            if($book_start->count() > 0){
                dd($book_start);
                //dd($book_start[0]->jumlah_kamar);
            }else{
                if($book_finish->count() > 0){

                }else{
                    if($request['jumlah_Tamu'] > $request['jumlah_kamar'] * 2){
                        dd('ngak bisa');
                    }else{
                        $dataHomestay[$i] = DB::table('homestay')
                                            ->where('homestay.id','=',$a->id)
                                            ->get();
                    }
                }
            }
            $i++;
        }
//        $j=0;

//        //dd($dataHomestay[1][0]->nama_homestay);//,$dataHomestay[1]->nama_homestay,$dataHomestay[2]->nama_homestay);
//        foreach ($dataHomestay as $b){
//            echo $b[0]->nama_homestay;
//            //echo $j;
////            if($j==1){
////                dd($b[0]);
////            }
//            echo '<br>';
//            $j++;
//        }

        return view('searchhomestay')->with('data',$dataHomestay);
        //dd($i,$book_start[0],$book_start[1],$book_start[2],$book_finish[0],$book_finish[1],$book_finish[2]);
        //dd($request['tanggal_mulai'],$request['jumlah_hari'],$request['tanggal_selesai'],$request['jumlah_Tamu'],$request['jumlah_kamar']);
    }

Juliper committed
95 96
    //Menyimpan data Pelanggan disaat melakukan Pendaftaran
    public function registerStore(Request $data){
Palti Sinaga committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

      $validator = Validator::make($data->all(), [
          'name' => 'required',
          'username' => 'required',
          'email' => 'required|email',
          'password' => 'required',
      ], [
          'name.required' => 'Silahkan Masukkan Nama Lengkap!',
          'username.required' => 'Silahkan Masukkan Username!',
          'email.required' => 'Silahkan Masukkan Email!',
          'password.required' => 'Silahkan Masukkan Password!'
      ]);

      if ($validator->fails()) {
          return redirect('/daftar')->withErrors($validator->errors());
}else{
Juliper committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        $user = new User();
        $user->name  = $data['name'];
        $user->username = $data['username'];
        $user->email = $data['email'];
        $user->password = bcrypt($data['password']);
        $user->role = "Customer";
        $user->foto = "gravatar.png";

        $user->save();
        $dataPel = DB::table('users')
            ->select('users.id')
            ->where('users.username','=',$data['username'])
            ->get();

        $cus = new Customer();
        $cus->id_akun = $dataPel[0]->id;
        $cus->nama = $data['name'] ;
        $cus->alamat = "---";
        $cus->no_telepon = "---";
        $cus->pekerjaan = "---";

        $cus->save();

        return redirect('login');
Palti Sinaga committed
137
      }
Juliper committed
138
    }
Juliper committed
139 140 141 142 143

    public function register(){
        return view('adminlte::auth.register');
    }

Juliper committed
144 145
    public function detailhomestay($id){
        $data = DB::table('homestay')
Juliper committed
146
            ->join('pemilikhomestay','homestay.id_pemilik','=','pemilikhomestay.id')
Juliper committed
147 148 149
            ->select('pemilikhomestay.*','homestay.*')
            ->where('homestay.id','=',$id)
            ->get();
Juliper committed
150

Juliper committed
151 152 153
        $daftarBook = DB::table('daftar_book')
            ->select('daftar_book.*')
            ->where('daftar_book.homestay','=',$id)
Juliper committed
154
            ->where('daftar_book.status','=',1)
Juliper committed
155 156 157 158 159 160 161 162 163 164
            ->get();

        $now = new DateTime();
        $nowCurrent = $now->format('Y-m-d');

        $dataJumlahKamar = ListBook::all()->where('tanggal_mulai',$nowCurrent);

        $avilableRoom = 0;

        if($dataJumlahKamar->count() == null){
Juliper committed
165
            $avilableRoom = $data[0]->jumlah_kamar;
Juliper committed
166 167 168 169 170 171
        }else{
            $avilableRoom = $dataJumlahKamar[0]->jumlah_kamar;
        }

        $dataKamar = DB::table('kamar')
            ->select('kamar.*')
Juliper committed
172
            ->where('kamar.id_homestay','=',$id)
Juliper committed
173 174 175 176 177
            ->get();

        return view('adminlte::layouts.pages.Homestay')->with('data',$data[0])->with('daftarBook',$daftarBook)->with('dataKamar',$dataKamar)->with('avilable',$avilableRoom);
    }
}