/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Booking::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'time' => $this->time, 'group_num' => $this->group_num, 'agency_id' => $this->agency_id, 'adults' => $this->adults, 'childs' => $this->childs, 'infants' => $this->infants, 'tour_id' => $this->tour_id, 'pick_up' => $this->pick_up, 'drop_off' => $this->drop_off]); $query->andFilterWhere(['like', 'address', $this->address]); return $dataProvider; }
/** * Lists all Booking models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Booking::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function postEditBooking(Request $request) { if (Session::get('member')->property_id != null) { if (Session::get('member')->type > 2) { return redirect()->back()->withErrors(['คุณไม่มีสิทธิ์เข้าใช้งานส่วนนี้'])->withInput(); } } $messages = ['room_code.required' => 'กรุณาใส่รหัสห้อง', 'customer_name.required' => 'กรุณาใส่ชื่อผู้พัก', 'check_in.required' => 'กรุณาระบุวันเข้าพัก', 'check_out.required' => 'กรุณาระบุวันออกจากที่พัก', 'customer_tel.required' => 'กรุณาระบุเบอร์ติดต่อผู้พัก', 'status.required' => 'กรุณาระบุสถานะการจอง']; $validator = Validator::make($request->all(), ['room_code' => 'required', 'check_in' => 'required', 'check_out' => 'required', 'customer_name' => 'required', 'customer_tel' => 'required', 'status' => 'required'], $messages); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $room = Session::get('property')->rooms()->where('code', '=', $request->room_code)->first(); if ($room) { $existBooking = Session::get('property')->bookings()->where('room_id', '=', $room->id)->whereBetween('check_out', [$request->check_in, $request->check_out])->first(); if ($existBooking && $existBooking->id != $request->c) { return redirect()->back()->withErrors(['ห้องพักดังกล่าวมีการจองหรือพักแล้ว จนถึง ' . date("d M Y H:i", strtotime($existBooking->check_out))])->withInput(); } else { $checkIn = new DateTime($request->check_in); $checkOut = new DateTime($request->check_out); $dateCount = $checkIn->diff($checkOut); $booking = \App\Models\Booking::find($request->c); $booking->property_id = $room->property()->first()->id; $booking->check_in = $request->check_in; $booking->check_out = $request->check_out; $booking->customer_name = $request->customer_name; $booking->customer_tel = $request->customer_tel; $booking->remark = $request->remark; $booking->status = $request->status; $booking->total = $dateCount->format('%a') * $room->price; $room->bookings()->save($booking); } } else { return redirect()->back()->withErrors(['ไม่มีห้องพักดังกล่าวในโรงแรมของคุณ'])->withInput(); } return redirect('/property/check-in'); }