Commit 2652cc7c by Palti Sinaga
parents 02e91aee 51e742ea
...@@ -171,20 +171,49 @@ class CustomerController extends Controller ...@@ -171,20 +171,49 @@ class CustomerController extends Controller
public function booking(Request $request){ public function booking(Request $request){
$lb = new ListBook(); $lb = new ListBook();
$data = DB::table('homestay') $dataHomestay = DB::table('homestay')
->join('kamar','homestay.id','=','kamar.idHomestay') ->join('kamar','homestay.id','=','kamar.idHomestay')
->select('kamar.*','homestay.harga','homestay.') ->select('kamar.*','homestay.harga','homestay.jumlahKamar')
->where('homestay.id','=',$request['id']) ->where('homestay.id','=',$request['id'])
->get(); ->get();
dd($data); $homestayJumlahKamar = DB::table('homestay')->select('homestay.jumlahKamar')->where('homestay.id','=',$request['id'])->get();
$dataBookingMulai = DB::table('daftar_book')
->select('daftar_book.*')
->where('daftar_book.tanggal_mulai','=',$request['tanggal'])
->get();
$dataBookingBerakhir = DB::table('daftar_book')
->select('daftar_book.*')
->where('daftar_book.tanggal_mulai','=',$request['tanggal'])
->get();
if($dataBookingMulai->count() > 0){
$currentJumlahKamar = $homestayJumlahKamar[0]->jumlahKamar - $dataBookingMulai[0]->jumlah_kamar;
$data2 = DB::table('users') if($currentJumlahKamar >= $request['jumlah_kamar']){
dd("masuk gan" ,$request['jumlah_kamar'],$request['tanggal']);
}else{
dd("nggak boleh");
}
}else{
echo ('langsung aja');
}
//dd('dataBooking',$dataBooking,'dataHomestay',$dataHomestay);
$dataPelanggan = DB::table('users')
->join('pelanggan','users.id','=','pelanggan.id_Akun') ->join('pelanggan','users.id','=','pelanggan.id_Akun')
->select('pelanggan.id','pelanggan.nama') ->select('pelanggan.id','pelanggan.nama')
->where('users.id','=',Auth::user()->id) ->where('users.id','=',Auth::user()->id)
->get(); ->get();
//dd($dataHomestay,$dataPelanggan);
$time = explode('-', $request['tanggal']); $time = explode('-', $request['tanggal']);
$time[2] +=$request['jumlah_hari']; $time[2] +=$request['jumlah_hari'];
...@@ -192,17 +221,17 @@ class CustomerController extends Controller ...@@ -192,17 +221,17 @@ class CustomerController extends Controller
//Insert Table Transaksi //Insert Table Transaksi
$trans = new Transaksi(); $trans = new Transaksi();
$trans->id_pelanggan = $data2[0]->id; $trans->id_pelanggan = $dataPelanggan[0]->id;
$trans->id_homestay = $request['id']; $trans->id_homestay = $request['id'];
$trans->tanggal_mulai = $request['tanggal']; $trans->tanggal_mulai = $request['tanggal'];
$trans->tanggal_berakhir = $baru; $trans->tanggal_berakhir = $baru;
$trans->jumlah_kamar =$request['jumlah_kamar']; $trans->jumlah_kamar =$request['jumlah_kamar'];
$trans->lama_menginap = $request['jumlah_hari']; $trans->lama_menginap = $request['jumlah_hari'];
$trans->total_pembayaran = $request['jumlah_kamar'] * $data[0]->harga; $trans->total_pembayaran = $request['jumlah_kamar'] * $dataHomestay[0]->harga;
//Insert Table Daftar Booking //Insert Table Daftar Booking
$lb->homestay = $request['id']; $lb->homestay = $request['id'];
$lb->nama_pemesan = $data2[0]->nama; $lb->nama_pemesan = $dataPelanggan[0]->nama;
$lb->jumlah_kamar = $request['jumlah_kamar']; $lb->jumlah_kamar = $request['jumlah_kamar'];
$lb->tanggal_mulai = $request['tanggal'] ; $lb->tanggal_mulai = $request['tanggal'] ;
$lb->tanggal_berakhir = $baru; $lb->tanggal_berakhir = $baru;
......
...@@ -9,7 +9,7 @@ class ListBook extends Model ...@@ -9,7 +9,7 @@ class ListBook extends Model
protected $table = "daftar_book"; protected $table = "daftar_book";
protected $fillable = [ protected $fillable = [
'nama_pemesan','tanggal_mulai','tanggal_berakhir','homestay' 'nama_pemesan','tanggal_mulai','tanggal_berakhir','homestay','jumlah_kamar'
]; ];
public $timestamps = false; public $timestamps = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment