Commit 2652cc7c by Palti Sinaga
parents 02e91aee 51e742ea
......@@ -171,20 +171,49 @@ class CustomerController extends Controller
public function booking(Request $request){
$lb = new ListBook();
$data = DB::table('homestay')
$dataHomestay = DB::table('homestay')
->join('kamar','homestay.id','=','kamar.idHomestay')
->select('kamar.*','homestay.harga','homestay.')
->select('kamar.*','homestay.harga','homestay.jumlahKamar')
->where('homestay.id','=',$request['id'])
->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')
->select('pelanggan.id','pelanggan.nama')
->where('users.id','=',Auth::user()->id)
->get();
//dd($dataHomestay,$dataPelanggan);
$time = explode('-', $request['tanggal']);
$time[2] +=$request['jumlah_hari'];
......@@ -192,17 +221,17 @@ class CustomerController extends Controller
//Insert Table Transaksi
$trans = new Transaksi();
$trans->id_pelanggan = $data2[0]->id;
$trans->id_pelanggan = $dataPelanggan[0]->id;
$trans->id_homestay = $request['id'];
$trans->tanggal_mulai = $request['tanggal'];
$trans->tanggal_berakhir = $baru;
$trans->jumlah_kamar =$request['jumlah_kamar'];
$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
$lb->homestay = $request['id'];
$lb->nama_pemesan = $data2[0]->nama;
$lb->nama_pemesan = $dataPelanggan[0]->nama;
$lb->jumlah_kamar = $request['jumlah_kamar'];
$lb->tanggal_mulai = $request['tanggal'] ;
$lb->tanggal_berakhir = $baru;
......
......@@ -9,7 +9,7 @@ class ListBook extends Model
protected $table = "daftar_book";
protected $fillable = [
'nama_pemesan','tanggal_mulai','tanggal_berakhir','homestay'
'nama_pemesan','tanggal_mulai','tanggal_berakhir','homestay','jumlah_kamar'
];
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