Esempio n. 1
0
 /**
  * Updates an existing Tour model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $booking = new Booking();
     $bookingFields = $booking->attributeLabels();
     unset($bookingFields['id']);
     unset($bookingFields['tour_id']);
     $data = Yii::$app->request->post();
     if ($model->load($data)) {
         if (isset($data['sort'])) {
             $model->sort = Json::encode($data['sort']);
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'bookingFields' => $bookingFields]);
     }
 }
Esempio n. 2
0
 public function actionView($id)
 {
     $model = Booking::findOne($id);
     if ($model !== null) {
         return $this->render('view', ['model' => $model]);
     } else {
         throw new NotFoundHttpException("Not found");
     }
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 public function actionBook($id)
 {
     $model = new Booking();
     $bookingModelAttributes = ['group_num', 'agency_id'];
     $customFieldsAttributes = array_map(function ($item) {
         return 'field' . $item['id'];
     }, $this->findModel($id)->getFields()->all());
     $dynamicModelAttributes = array_merge($bookingModelAttributes, $customFieldsAttributes);
     $dynamicModel = new DynamicModel($dynamicModelAttributes);
     $dynamicModel->addRule($dynamicModelAttributes, 'required');
     if ($dynamicModel->load(Yii::$app->request->post()) && $dynamicModel->validate()) {
         $attributes = $dynamicModel->getAttributes($bookingModelAttributes);
         $model->link('tour', $this->findModel($id));
         $model->agency_id = $attributes['agency_id'];
         $model->group_num = $attributes['group_num'];
         $model->time = time();
         if ($model->validate()) {
             $fields = [];
             $keys = ['booking_id', 'tour_id', 'field_id', 'value'];
             foreach ($dynamicModel->getAttributes($customFieldsAttributes) as $key => $field) {
                 if (in_array($key, $customFieldsAttributes)) {
                     $fields[] = [$model->id, $id, str_replace('field', '', $key), $field];
                 }
             }
             if (!empty($fields)) {
                 Yii::$app->db->createCommand()->batchInsert('booking_fields', $keys, $fields)->execute();
                 $model->save();
                 return $this->redirect('/booking');
             }
         } else {
             var_dump($model);
             $model->delete();
         }
     }
     return $this->render('book', ['model' => $dynamicModel, 'tourModel' => $this->findModel($id)]);
 }
 /**
  * Finds the Tour model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tour the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Booking::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBooking()
 {
     return $this->hasOne(Booking::className(), ['id' => 'id_booking']);
 }
Esempio n. 7
0
 public function getBookings()
 {
     return $this->hasMany(Booking::className(), ['employee_id' => 'id']);
 }
 /**
  * select booking for tours params
  * @param $id
  * @return string
  */
 public function actionBooking($id)
 {
     $booking = Booking::searchByTour($id);
     return $this->render('booking', compact('booking', 'id'));
 }
Esempio n. 9
0
 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');
 }