<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BookingItemsController extends Controller{
    public function index(Request $request)
    {
        $results = DB::table('booking_items')
                    ->leftJoin('services','services.id','=','booking_items.service_id')
                    ->select('booking_items.*','services.name')
                    ->where('booking_id',$request->booking_id)->get();
                    
        return view('admin/booking_items',['bookingItems'=>$results,'bookingId'=>$request->booking_id,'title'=>'Bookings Items']);
    }
    
    public function insert(Request $request){
        date_default_timezone_set("Asia/Jakarta");
        $services = $request->ar_product;
        if($services != null){
            foreach($services as $service){
                $values = array('booking_id'=>$request->id,'service_id'=>$service);
                DB::table('booking_items')->insert($values);
            }
        }
        return redirect('booking-items?booking_id='.$request->id);
    }
    
    public function create(Request $request){
        $services = DB::table('services')->get();
        return view('admin/booking_item_create',['bookingId'=>$request->booking_id,'services'=>$services]);
    }
    public function delete(Request $request){
        DB::table('booking_items')->where('id',$request->id)->delete();
        return redirect('booking-items?booking_id='.$request->booking_id);
    }
}
?>