GuestController.php 9.25 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
    //{id}/{tm}/{lm}/{ts}/{jt}/{jk}

    public function homestay($id,$tm,$lm,$ts,$jt,$jk){

        $data = DB::table('homestay')
            ->join('pemilikhomestay','homestay.id_pemilik','=','pemilikhomestay.id')
            ->select('pemilikhomestay.*','homestay.*')
            ->where('homestay.id','=',$id)
            ->get();

        //dd($data);

        $dataKamar = DB::table('kamar')
                     ->where('kamar.id_homestay','=',$id)
                     ->get();


        return view('adminlte::layouts.pages.detilSHomestay')->with('data',$data[0])->with('tm',$tm)->with('lm',$lm)->with('ts',$ts)->with('jt',$jt)->with('jk',$jk)->with('dataKamar',$dataKamar);
    }
Juliper committed
57 58 59 60 61

    public function cari(Request $request){

        $data =  Homestay::all();

Juliper committed
62
        $dataBook = ListBook::all();
Juliper committed
63

Juliper committed
64 65 66 67 68 69 70
        $tanggal_mulai = $request['tanggal_mulai'];
        $jumlah_hari = $request['jumlah_hari'];
        $tanggal_selesai = $request['tanggal_selesai'];
        $jumlah_Tamu = $request['jumlah_Tamu'];
        $jumlah_kamar =  $request['jumlah_kamar'];
        //$book_start[] = null;
        $dataHomestay[] =  null;
Juliper committed
71
        $i = 0;
Juliper committed
72 73 74


        //Melakukan Looping pengecekan Homestay yang avilable
Juliper committed
75 76
        foreach ($data as $a){

Juliper committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            $tm = explode('-',$request['tanggal_mulai']);
            $ts = explode('-',$request['tanggal_selesai']);
            $counter = 0;
            $j=0;
            //Mencocokkan data pesanan untuk mendapat current room avilable
            foreach ($dataBook as $db){

                $ldbm = explode('-',$db->tanggal_mulai);
                $ldbs = explode('-',$db->tanggal_berakhir);

                if($tm[1]==$ts[1]){
                    if($tm[1] == $ldbm[1] && $ts[1] == $ldbs[1]){
                        if(($tm[2] >= $ldbm[2]  && $tm[2] <= $ldbs[2] ) && ($ts[2] >= $ldbm[2] && $ts[2]<= $ldbs[2]) ){
                            //dd('beriirisan total');
                            $dataCurrent[$j] = $db->id;
                            $counter +=1;
                            $j++;
                            echo 'beririsan';
                        }
                        else if(($tm[2] < $ldbm[2]  && $tm[2] <= $ldbs[2] ) && ($ts[2] >= $ldbm[2] && $ts[2]<= $ldbs[2])){
                            $dataCurrent[$j] = $db->id;
                            $counter +=1;
                            $j++;
                            echo 'beririsan sebagian batas atas';
                            //dd('beririsan sebagian batas atas');
                        }else if(($tm[2] >= $ldbm[2]  && $tm[2] <= $ldbs[2] ) && ($ts[2] >= $ldbm[2] && $ts[2] > $ldbs[2])){
                            $dataCurrent[$j] = $db->id;
                            $counter +=1;
                            $j++;
                            echo 'beririsan sebagian batas bawah';
                            //dd('beririsan sebagian batas bawah');
                        }
                    }
                }else if($tm[1] < $ts[1]){
                    dd('jangan dulu');
                }
Juliper committed
113

Juliper committed
114
            }
Juliper committed
115

Juliper committed
116 117 118 119 120 121 122 123
            if($counter==0){
                if($request['jumlah_kamar'] <= $a->jumlah_kamar){
                    if($request['jumlah_Tamu'] <= ($request['jumlah_kamar']*2)*2){
                        $dataHomestay[$i] = DB::table('homestay')
                                        ->where('homestay.id','=',$a->id)
                                        ->get();
                    }
                }
Juliper committed
124 125
            }else{

Juliper committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
                $currentKamar = null;

                //$dataKamarHomestay = ListBook::find(14);
                //dd($dataKamarHomestay);
                //dd($dataCurrent);

                for ($l = 0; $l<$counter;$l++){
                   // echo $dataCurrent[$l];
                    $dataKamarHomestay[$l] = DB::table('daftar_book')
                                            ->where('daftar_book.id','=',$dataCurrent[$l])
                                            //->where('daftar_book.homestay','=',$a->id)
                                            ->get();

                    if ($dataKamarHomestay[$l][0]->homestay == $a->id){
                        $currentKamar = ($a->jumlah_kamar - $dataKamarHomestay[$l][0]->jumlah_kamar) - $currentKamar;
Juliper committed
141
                    }else{
Juliper committed
142 143 144 145 146 147 148 149 150 151 152
                        $currentKamar = $a->jumlah_kamar;
                    }
                }
                //dd($dataKamarHomestay[1][0]->homestay);


                //dd($dataKamarHomestay);
               // echo $currentKamar;
                //dd('asd');
                if($request['jumlah_kamar'] <= $currentKamar){
                    if($request['jumlah_Tamu'] <= ($request['jumlah_kamar']*2)*2){
Juliper committed
153
                        $dataHomestay[$i] = DB::table('homestay')
Juliper committed
154 155
                            ->where('homestay.id','=',$a->id)
                            ->get();
Juliper committed
156 157 158 159 160
                    }
                }
            }
            $i++;
        }
Juliper committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180

        //dd($dataHomestay);

        if($dataHomestay == null){
            dd('salah');
            return redirect('')->with('message','Jumlah Kamar yang Avilable tidak mencukupi');
        }
        if($dataHomestay[0] == null){
            return redirect('')->with('message','Jumlah Kamar yang Avilable tidak mencukupi');
            dd('salah');
        }

        //dd('benar');

        return view('searchhomestay')->with('data',$dataHomestay)
                                     ->with('tm',$tanggal_mulai)
                                     ->with('lm',$jumlah_hari)
                                     ->with('ts',$tanggal_selesai)
                                     ->with('jt',$jumlah_Tamu)
                                     ->with('jk',$jumlah_kamar);
Juliper committed
181 182 183 184
        //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
185 186
    //Menyimpan data Pelanggan disaat melakukan Pendaftaran
    public function registerStore(Request $data){
Palti Sinaga committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

      $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
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        $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
227
      }
Juliper committed
228
    }
Juliper committed
229 230 231 232 233

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

Juliper committed
234 235
    public function detailhomestay($id){
        $data = DB::table('homestay')
Juliper committed
236
            ->join('pemilikhomestay','homestay.id_pemilik','=','pemilikhomestay.id')
Juliper committed
237 238 239
            ->select('pemilikhomestay.*','homestay.*')
            ->where('homestay.id','=',$id)
            ->get();
Juliper committed
240

Juliper committed
241 242 243
        $daftarBook = DB::table('daftar_book')
            ->select('daftar_book.*')
            ->where('daftar_book.homestay','=',$id)
Juliper committed
244
            ->where('daftar_book.status','=',1)
Juliper committed
245 246 247 248 249 250 251 252 253 254
            ->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
255
            $avilableRoom = $data[0]->jumlah_kamar;
Juliper committed
256 257 258 259 260 261
        }else{
            $avilableRoom = $dataJumlahKamar[0]->jumlah_kamar;
        }

        $dataKamar = DB::table('kamar')
            ->select('kamar.*')
Juliper committed
262
            ->where('kamar.id_homestay','=',$id)
Juliper committed
263 264 265 266 267
            ->get();

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