public function listAjax() { $result = array(); $bookings = Booking::whereHas('items', function ($query) { $query->whereBetween('start_at', array(Input::get('start'), Input::get('end'))); })->with('items')->get(); foreach ($bookings as $booking) { //var_dump($booking->items()->count()); foreach ($booking->items()->get() as $booking_item) { /** @var BookingItem $booking_item */ $result[] = $booking_item->toJsonEvent(); } } $start = strtotime(Input::get('start')); $end = strtotime(Input::get('end')); $i = $start; while ($i < $end) { if (!in_array(date('w', $i), array(0, 6))) { $result[] = $this->createBackgroundEvent($i, Config::get('booking::work_hour_start', '09:00'), Config::get('booking::work_hour_end', '18:00')); } $i += 24 * 3600; } return Response::json($result); }
/** * Update the specified booking in storage. * * @param int $id * @return Response */ public function update($id) { $booking = Booking::findOrFail($id); if (Input::has('val')) { $rules = ['val']; //dd('<pre>',Booking::with('Voucher')->where('id',$id)->first(), '</pre>'); $bookingVouchers = Booking::whereHas('Voucher', function ($q) { $q->where('vouchers.val', 1); })->where('id', $id); //dd($booking->count()); if ($bookingVouchers->count() > 0) { Session::flash("booking_cancellation_error_" . $id, "<b>Sorry</b>, You cannot cancel the above booking! You have " . $booking->first()->voucher->count() . " active vouchers"); } else { $booking->update(array('val' => Input::get('val'))); Session::flash('success', 'successfully Updated'); } return Redirect::back(); } $validator = Validator::make($data = Input::all(), Booking::$agentRules); if ($validator->fails()) { //dd($validator->errors()); return Redirect::back()->withErrors($validator)->withInput(); } $data['user_id'] = Auth::id(); $booking->update($data); return Redirect::back(); }
public function getInvoices() { $reference_number = Input::has('reference_number') ? Input::get('reference_number') : '%'; if (Entrust::hasRole('Admin')) { $agent_id = Input::get('agent_id'); $bookings = Booking::whereHas('user', function ($q) use($agent_id) { $q->where('users.id', 'like', '%' . $agent_id . '%'); })->whereHas('invoice', function ($q) use($reference_number) { $q->where('reference_number', 'like', '%' . $reference_number . '%'); }); } else { //dd('asdasd'); $bookings = Booking::whereHas('user', function ($q) { $q->where('users.id', $this->_user->id); })->with('invoice')->where('reference_number', 'like', '%' . $reference_number . '%'); } //$bookings = Booking::with('invoice')->where('user_id',Auth::id())->get(); if (Input::get('search')) { $from = Input::get('from'); $to = Input::get('to'); $agent_id = Input::get('agent_id'); $bookings = $bookings->where('arrival_date', '>=', $from)->where('arrival_date', '<=', $to); } $bookings = $bookings->get(); return View::make('accounts.invoices', compact('bookings', 'from', 'to', 'tour_type', 'status', 'reference_number')); }