public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     if ($this->adults + $this->children + $this->babies == 0) {
         \Yii::$app->session->setFlash('danger', 'Error! You must book at least one place');
         return false;
     }
     $booking = new Bookings();
     $booking->attributes = $this->attributes;
     $booking->custom_fields = serialize($this->custom_fields);
     $booking->save();
     return true;
 }
Example #2
0
 /**
  * Creates a new Bookings model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Bookings();
     $customers = $this->getCustomers();
     if (isset($_POST['Bookings'])) {
         $model->attributes = $_POST['Bookings'];
         $model->creationDate = date('Y-m-d');
         if (isset($_POST['added-items-list'])) {
             $added_items = json_decode($_POST['added-items-list']);
             $booking_id = Bookings::find(['ORDER BY' => 'id DESC'])->one();
             $this->actionAddeditems($added_items, $booking_id == null ? 1 : $booking_id->id + 1);
         }
         if ($model->save()) {
             return json_encode(1);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model, 'customers' => $customers]);
     }
 }
 public function anyBooking()
 {
     $error_msg = [];
     $success_msg = [];
     $service_types = ServiceTypes::all();
     if (Request::isMethod('POST')) {
         $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'phone' => 'required', 'address' => 'required', 'suburb' => 'required', 'city' => 'required', 'booking_date' => 'required', 'service_type_id' => 'required'];
         $validator = Validator::make(Input::all(), $rules);
         if (!$validator->fails()) {
             $booking_date = Input::get('booking_date');
             $user_booking_count = Bookings::where('user_id', User::get()->id)->where('pending', 1)->where('booking_date', date('Y-m-d', strtotime($booking_date)))->count();
             if ($user_booking_count >= 1) {
                 $error_msg[] = 'Sorry. Our system shows you have a pending booking. We are currently processing your service booking
                     and will contact you within 48 hours.';
             } else {
                 $booking = new Bookings(Input::all());
                 $booking->uid = Uuid::generate()->string;
                 $booking->user_id = User::get()->id;
                 $booking->pending = 1;
                 $booking->booking_date = date('Y-m-d', strtotime(Input::get('booking_date')));
                 $booking->save();
                 if ($booking) {
                     $success_msg[] = 'Great! We have received your service booking. You should be able to hear from us in the next 48 hours.';
                 } else {
                     $error_msg[] = 'Whoops! There was an error in your booking. Please try again.';
                 }
             }
         } else {
             return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
         }
     }
     if (User::check()) {
         return View::make('booking.booking', ['user' => User::get(), 'service_types' => $service_types, 'error_msg' => $error_msg, 'success_msg' => $success_msg]);
     } else {
         return Redirect::to('/user/login');
     }
 }