예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($shipment_id = '')
 {
     $model = new Booking();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $awb = '';
     if (is_numeric($shipment_id)) {
         $shipment = Shipment::model()->findByPk($shipment_id);
         if ($shipment instanceof Shipment) {
             $model->address = $shipment->shipper_address;
             $model->city = $shipment->shipper_city;
             $model->postal = $shipment->shipper_postal;
             $model->country = $shipment->shipper_country;
             $model->phone = $shipment->shipper_phone;
             $model->shipment_id = $shipment->id;
             $awb = $shipment->awb;
         }
     }
     if (isset($_POST['Booking'])) {
         $model->attributes = $_POST['Booking'];
         $model->setAttribute('booking_code', dechex(time()));
         if ($model->save()) {
             if (!empty($model->shipment_id) || $model->shipment_id != '') {
                 $shipment->booking_id = $model->id;
                 $tes = $shipment->update();
             }
             Yii::app()->user->setFlash('success', 'Success to add new booking, ' . $model->booking_code);
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model, 'awb' => $awb));
 }
예제 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Booking();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Booking'])) {
         $model->attributes = $_POST['Booking'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->booking_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $booking = new Booking();
     $input = Input::all();
     $booking->userId = Input::get('userId');
     $booking->source = Input::get('source');
     $booking->destination = Input::get('destination');
     $booking->date = Input::get('date');
     $booking->time = Input::get('time');
     $booking->capacity = Input::get('capacity');
     $booking->save();
     return Response::json(array('code' => '200', 'info' => 'New booking has been created.', 'id' => $booking->id));
 }
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Booking::$rules);
     if ($validator->passes()) {
         $booking = new Booking();
         $booking->car_id = Input::get('car_id');
         $booking->user_id = Auth::user()->id;
         $booking->book_from = Input::get('pick_up_date');
         $booking->book_to = Input::get('drop_off_date');
         $booking->save();
         return Redirect::to('bookings')->with('message', 'Your booking has sent to us. Thank you!');
     }
     return Redirect::back()->with('message', 'Something went wrong')->withErrors($validator)->withInput();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($id)
 {
     $listing = Listing::where('isPublic', '=', 1)->where('id', '=', $id)->first();
     if (!$listing) {
         throw new \Symfony\Component\Routing\Exception\ResourceNotFoundException();
     }
     $input = Input::all();
     //return print_r($input,true);
     $yesterday = \Carbon\Carbon::now('Australia/Sydney');
     $yesterday = $yesterday->format('Y-m-d H:i:s');
     // return $yesterday;
     $rules = array('comments' => array('required', 'min:3'), 'user_phone' => array('required', 'min:9', 'max:30'), 'request_start_datetime' => array('required', 'date', 'dateformat: Y-m-d H:i:s', 'before: ' . $input['request_end_datetime']), 'request_end_datetime' => array('required', 'date', 'dateformat: Y-m-d H:i:s', 'after: ' . $yesterday));
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withInput($input)->withErrors($validator);
     }
     $comments = $this->sanitizeStringAndParseMarkdown($input['comments']);
     $authuser = Auth::user();
     $name = $authuser->name;
     $bookings = new Booking();
     $bookings->user_id = $authuser->id;
     $bookings->user_name = $name;
     $bookings->listing_id = $id;
     $bookings->user_phone = $input['user_phone'];
     $bookings->request_start_datetime = $input['request_start_datetime'];
     $bookings->request_end_datetime = $input['request_end_datetime'];
     $bookings->status = "Booking request submitted. Awaiting Open Source Collaborative Consumption Marketplace review.";
     $bookings->user_comments = $comments;
     $bookings->space_owner_id = $listing->owner_id;
     $address = $listing->address1 . ", " . $listing->suburb . ", " . $listing->city . " " . $listing->country;
     $data = $input;
     $data['address'] = $address;
     $data['title'] = $listing->title;
     $data['id'] = $id;
     $data['type'] = $listing->space_type;
     $data['user_name'] = $name;
     $data['status'] = $bookings->status;
     /* TODO: Make it email the user and space owner */
     Mail::send("booking.mail.newbookingfounders", $data, function ($message) {
         $message->to('*****@*****.**')->subject('New booking on Open Source Collaborative Consumption Marketplace');
     });
     $email = Auth::user()->email;
     Mail::send("booking.mail.newbookinguser", $data, function ($message) use($email) {
         $message->to($email)->subject('Your new booking on Open Source Collaborative Consumption Marketplace!');
     });
     $bookings->save();
     return Redirect::to('dashboard')->with('flash_message_good', "Your booking has been sent. We'll be in touch soon with confirmation or questions!");
 }
예제 #6
0
 public function stageEnterCredentials()
 {
     $valid = true;
     $booking = new BookingForm();
     if (isset($_POST['BookingForm'])) {
         $booking->attributes = $_POST['BookingForm'];
         $valid = $booking->validate() && $valid;
     } else {
         $valid = false;
     }
     $passport = new AviaPassportForm();
     if (isset($_POST['PassportForm'])) {
         $passport->attributes = $_POST['PassportForm'];
         $valid = $valid && $passport->validate();
     }
     if ($valid) {
         //saving data to objects
         $bookingAr = new Booking();
         $bookingAr->email = $booking->contactEmail;
         $bookingAr->phone = $booking->contactPhone;
         if (!Yii::app()->user->isGuest) {
             $bookingAr->userId = Yii::app()->user->id;
         }
         $bookingPassports = array();
         $bookingPassport = new BookingPassport();
         $bookingPassport->birthday = $passport->birthday;
         $bookingPassport->firstName = $passport->firstName;
         $bookingPassport->lastName = $passport->lastName;
         $bookingPassport->countryId = $passport->countryId;
         $bookingPassport->number = $passport->number;
         $bookingPassport->series = $passport->series;
         $bookingPassport->genderId = $passport->genderId;
         $bookingPassport->documentTypeId = $passport->documentTypeId;
         $bookingPassports[] = $bookingPassport;
         $bookingAr->bookingPassports = $bookingPassports;
         $bookingAr->flightId = Yii::app()->flightBooker->current->flightVoyage->flightKey;
         if ($bookingAr->save()) {
             Yii::app()->flightBooker->current->bookingId = $bookingAr->id;
             Yii::app()->flightBooker->status('booking');
             $this->refresh();
         } else {
             $this->render('enterCredentials', array('passport' => $passport, 'booking' => $booking));
         }
     } else {
         $this->render('enterCredentials', array('passport' => $passport, 'booking' => $booking));
     }
 }
 /**
  * POST /bookings/create
  */
 public function create()
 {
     self::authorize_user();
     if (isset($_POST['patient_id']) && isset($_POST['doctor_id']) && isset($_POST['time__date']) && isset($_POST['time__hour'])) {
         date_default_timezone_set('America/Buenos_Aires');
         $patient_id = $_POST['patient_id'];
         $doctor_id = $_POST['doctor_id'];
         $time = $_POST['time__date'] . " " . $_POST['time__hour'];
         // Cambiamos al formato que maneja la base de datos
         $time = date_create_from_format('d-m-Y H:i', $time)->format('Y-m-d H:i');
         $booking = new Booking($patient_id, $doctor_id, $time);
         $booking->save();
         self::redirect_to('bookings');
     } else {
         self::redirect_to('bookings/new');
     }
 }
 private function showCreateBookingPage()
 {
     if (WebRequest::wasPosted()) {
         try {
             // get variables
             $bcust = WebRequest::postInt("bcust");
             $badults = WebRequest::postInt("badults");
             $bchildren = WebRequest::postInt("bchildren");
             $bstart = WebRequest::post("bstart");
             $bend = WebRequest::post("bend");
             $bpromo = WebRequest::postInt("bpromo");
             $broom = WebRequest::postInt("broom");
             // data validation
             if ($badults == 0) {
                 throw new CreateBookingException("no-adults");
             }
             if ($bstart == null) {
                 throw new CreateBookingException("no-start-date");
             }
             if ($bend == null) {
                 throw new CreateBookingException("no-end-date");
             }
             if ($bcust == 0) {
                 throw new CreateBookingException("no-customer-for-booking");
             }
             $booking = new Booking();
             // set values
             $booking->setCustomer($bcust);
             $booking->setAdults($badults);
             $booking->setChildren($bchildren);
             $booking->setStartDate($bstart);
             $booking->setEndDate($bend);
             $booking->setPromocode($bpromo);
             $booking->setRoom($broom);
             $booking->save();
             global $cScriptPath;
             $this->mHeaders[] = "Location: {$cScriptPath}/Bookings";
         } catch (CreateBookingException $ex) {
             $this->mBasePage = "mgmt/bookingCreate.tpl";
             $this->error($ex->getMessage());
         }
     } else {
         $this->mBasePage = "mgmt/bookingCreate.tpl";
     }
 }
예제 #9
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     if (!empty($id) && !Yii::app()->user->isGuest) {
         $user_email = Yii::app()->user->name;
         $userModel = User::model()->findByAttributes(array('user_email' => $user_email));
         $listingId = $id;
         $listingModel = Listing::model()->findByPk($listingId);
         $model = new Booking();
         $model->booking_listing_id = $listingModel->listing_id;
         $model->booking_user_id = $userModel->user_id;
         $model->booking_amount = $listingModel->listing_price;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->booking_id));
         }
     } else {
         echo "Booking failed";
     }
 }
예제 #10
0
 public function book($userId, $post)
 {
     $offer = $this->getOffer($userId, $post['origin'], $post['destination'], $post['date'], $post['time']);
     $response = new \StdClass();
     $response->success = "no";
     if ($offer->success == "yes") {
         foreach (array('name', 'phone', 'email', 'passengerCount') as $fieldName) {
             ${$fieldName} = !empty($post[$fieldName]) ? $post[$fieldName] : '';
             if (!${$fieldName}) {
                 $response->errorText = "Fyll in alla felt";
                 print json_encode($response);
                 exit;
             }
         }
         $originCity = !empty($post['originCity']) ? $post['originCity'] : '';
         $destinationCity = !empty($post['destinationCity']) ? $post['destinationCity'] : '';
         // save to db
         $booking = new Booking();
         $booking->user_id = $userId;
         $booking->alphaId = "ZZZ" . substr("" + time(), 3, 7);
         $booking->origin = $offer->offerFrom;
         $booking->destination = $offer->offerTo;
         $booking->originCity = $originCity;
         $booking->destinationCity = $destinationCity;
         $booking->startUts = $offer->uts;
         $booking->endUts = $offer->uts + $offer->offerDurationValue;
         $booking->duration = $offer->offerDuration;
         $booking->distance = $offer->offerDistance;
         $booking->price = $offer->offerPrice;
         $booking->name = $name;
         $booking->email = $email;
         $booking->phone = $phone;
         $booking->passengerCount = $passengerCount;
         $booking->hash = md5($name . $email . $offer->offerFrom . time() . "38lx93øå");
         $response->bookingSaved = $booking->save();
         // mail to customer
         TaxiMail::sendBookingReceivedMail($booking, $userId);
         // mail to taxi company
         TaxiMail::sendNewBookingMail($booking, $userId);
         $response->success = "yes";
     }
     return $response;
 }
예제 #11
0
 /**
  * Store a newly created booking in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Booking::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $client = Client::findOrFail(Input::get('client_id'));
     $car = Car::findOrFail(Input::get('car_id'));
     $booking = new Booking();
     $booking->client()->associate($client);
     $booking->car()->associate($car);
     $booking->date = date('Y-m-d');
     $booking->destination = Input::get('destination');
     $booking->date_out = Input::get('date_out');
     $booking->date_back = Input::get('date_back');
     $booking->status = 'active';
     $booking->save();
     return Redirect::route('bookings.index');
 }
예제 #12
0
 public function insertBooking()
 {
     if (!Request::ajax()) {
         return "not a json request";
     }
     $post = Input::except('Notifees');
     $notifees = Input::get('Notifees');
     $booking = new Booking();
     $booking->fill($post);
     $booking->save();
     $bookingDetail = new BookingDetails();
     $bookingDetail->fill(array('BookingID' => $booking->ID, 'UserID' => Auth::user()->id, 'Email' => Auth::user()->email, 'Booker' => 1))->save();
     if (count($notifees) > 0) {
         foreach ($notifees as $notifee) {
             $temp = User::where('email', $notifee['Email'])->first();
             if ($temp != null) {
                 $bookingDetail = new BookingDetails();
                 $bookingDetail->fill(array('BookingID' => $booking->ID, 'UserID' => $temp->id, 'Email' => $temp->email, 'Booker' => 0));
                 $bookingDetail->save();
             } else {
                 $bookingDetail = new BookingDetails();
                 $bookingDetail->fill(array('BookingID' => $booking->ID, 'Email' => $notifee['Email'], 'Booker' => 0));
                 $bookingDetail->save();
             }
         }
     }
     /*
     Logs::BookingRequestCreated(
         $booking->ID,
         $post['KitID'],
         $post['ForBranch'],
         $post['StartDate'],
         $post['EndDate']
     ); 
     */
     return Response::json(array('success' => true, 'insert_id' => $booking->ID), 200);
 }
 protected function runPage()
 {
     if (WebRequest::wasPosted()) {
         if (!WebRequest::postInt("calroom")) {
             $this->showCal();
             return;
         }
         $startdate = new DateTime(WebRequest::post("qbCheckin"));
         $enddate = new DateTime(WebRequest::post("qbCheckout"));
         $room = Room::getById(WebRequest::postInt("calroom"));
         for ($date = $startdate; $date < $enddate; $date->modify("+1 day")) {
             if (!$room->isAvailable($date)) {
                 $this->error("room-not-available");
                 $this->showCal();
                 return;
             }
         }
         // search for customer
         if (!($customer = Customer::getByEmail(WebRequest::post("qbEmail")))) {
             $customer = new Customer();
             $suTitle = WebRequest::post("qbTitle");
             $suFirstname = WebRequest::post("qbFirstname");
             $suLastname = WebRequest::post("qbLastname");
             $suAddress = WebRequest::post("qbAddress");
             $suCity = WebRequest::post("qbCity");
             $suPostcode = WebRequest::post("qbPostcode");
             $suCountry = WebRequest::post("qbCountry");
             $suEmail = WebRequest::post("qbEmail");
             $customer->setPassword($suEmail);
             // set values
             $customer->setTitle($suTitle);
             $customer->setFirstname($suFirstname);
             $customer->setSurname($suLastname);
             $address = new Address();
             $address->setLine1($suAddress);
             $address->setCity($suCity);
             $address->setPostCode($suPostcode);
             $address->setCountry($suCountry);
             $address->save();
             $customer->setAddress($address);
             $customer->setEmail($suEmail);
             // save it
             $customer->save();
             $customer->sendMailConfirm();
             // save it again
             $customer->save();
         }
         $booking = new Booking();
         $booking->setStartDate(WebRequest::post("qbCheckin"));
         $booking->setEndDate(WebRequest::post("qbCheckout"));
         $booking->setAdults(WebRequest::post("qbAdults"));
         $booking->setChildren(WebRequest::post("qbChildren"));
         $booking->setPromocode(WebRequest::post("qbPromoCode"));
         $booking->setRoom($room->getId());
         $booking->setCustomer($customer->getId());
         $booking->save();
         $msg = Message::getMessage("booking-confirmation");
         $msg = str_replace("\$1", $booking->getStartDate(), $msg);
         $msg = str_replace("\$2", $booking->getEndDate(), $msg);
         $msg = str_replace("\$3", $booking->getAdults(), $msg);
         $msg = str_replace("\$4", $booking->getChildren(), $msg);
         $msg = str_replace("\$5", $booking->getRoom()->getName(), $msg);
         Mail::send($customer->getEmail(), Message::getMessage("booking-confimation-subject"), $msg);
         $this->mSmarty->assign("content", $msg);
         return;
     }
     throw new YouShouldntBeDoingThatException();
 }
 public function bookingStep2($id)
 {
     $i = Input::all();
     $i['checkin'] = $i['checkin'] . ' 12:00:00';
     //
     $i['checkout'] = $i['checkout'] . ' 11:59:00';
     $total_price = null;
     $tax = null;
     $booking_session = [];
     $count = 0;
     //for test
     $count1 = 0;
     //for test
     $booked_room = [];
     //all picked rooms from available rooms
     $booked_room_id = [];
     //foreach(Session::get('reservation')['reservation_room'] as $rooms){
     $count++;
     $room_id = $id;
     $available_rooms = [];
     $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
         $query->where(function ($query2) use($i, $room_id) {
             $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
         })->where(function ($query3) {
             $query3->where('status', '!=', 5)->where('status', '!=', 3);
         });
     }))->where('status', 1)->where('room_id', $room_id)->get();
     foreach ($room_qty as $available) {
         if (count($available->roomReserved) == 0) {
             array_push($available_rooms, $available);
         } else {
         }
     }
     if (!empty($available_rooms)) {
         for ($counter = 0; $counter < $i['quantity']; $counter++) {
             array_push($booked_room, $available_rooms[$counter]);
         }
     } else {
         return '0';
         //not available
     }
     //} //end of foreach
     $total_price = 0;
     if (!isset($_GET['bookingId'])) {
         $new_booking = new Booking();
         $new_booking->firstname = 'WALK-IN';
         $new_booking->lastname = 'WALK-IN';
         $new_booking->address = 'WALK-IN';
         $new_booking->contact_number = '000';
         $new_booking->check_in = $i['checkin'];
         $new_booking->check_out = $i['checkout'];
         $new_booking->email_address = 'WALK-IN';
         $new_booking->code = 'N/A';
         $new_booking->status = 0;
         $new_booking->save();
     }
     foreach ($booked_room as $b) {
         $ci = new Carbon($i['checkin']);
         $co = new Carbon($i['checkout']);
         $total_nights = $co->diff($ci)->days;
         $total_nights += 1;
         $total_price += $total_nights * $b->roomPrice->price;
         $total_price2 = $total_nights * $b->roomPrice->price;
         //$tax = $total_price2 * 0.12;
         //$total_price2+=$tax;
         $reserveRoom = new ReservedRoom();
         $reserveRoom->room_id = $b->id;
         $reserveRoom->room_type = $b->room_id;
         $reserveRoom->booking_id = isset($_GET['bookingId']) ? $_GET['bookingId'] : $new_booking->id;
         $reserveRoom->check_in = $i['checkin'];
         $reserveRoom->check_out = $i['checkout'];
         $reserveRoom->code = 'N/A';
         /*$reserveRoom->firstname = 'WALK-IN';
         		$reserveRoom->lastname = 'WALK-IN';*/
         $reserveRoom->price = $total_price2;
         /*$reserveRoom->address = 'WALK-IN';
         		$reserveRoom->contact_number = '000';
         		$reserveRoom->email_address = 'WALK-IN';*/
         $reserveRoom->status = '0';
         if ($reserveRoom->save()) {
             array_push($booked_room_id, $reserveRoom->id);
         }
     }
     if (isset($_GET['bookingId'])) {
         $existing_booking = Booking::where('id', $_GET['bookingId'])->first();
         if ($existing_booking) {
             $existing_booking->price = $total_price;
         }
     } else {
         $new_booking->price = $total_price;
         $new_booking->save();
     }
     //	return Session::get('reservation');
     //return $booked_room;
     //return $counter;
     //return $room_qty1;
     $booking_session['booking_id'] = isset($_GET['bookingId']) ? $_GET['bookingId'] : $new_booking->id;
     $booking_session['rooms'] = $booked_room_id;
     return $booking_session;
 }
 public function clientBookingStep5()
 {
     //return Session::get('reservation');
     $tax = null;
     $total_price = null;
     $i = [];
     $i['checkin'] = Session::get('reservation')['checkin'] . ' 12:00:00';
     $i['checkout'] = Session::get('reservation')['checkout'] . '11:59:00';
     $customerinformation = Session::get('reservation.customerinformation');
     $count = 0;
     //for test
     $count1 = 0;
     //for test
     $booked_room = [];
     //all picked rooms from available rooms
     $new_booking = new Booking();
     $new_booking->firstname = $customerinformation['firstname'];
     $new_booking->lastname = $customerinformation['lastname'];
     $new_booking->address = $customerinformation['address'];
     $new_booking->contact_number = $customerinformation['contact_no'];
     $new_booking->email_address = $customerinformation['email'];
     $new_booking->check_in = $i['checkin'];
     $new_booking->check_out = $i['checkout'];
     $new_booking->save();
     foreach (Session::get('reservation')['reservation_room'] as $rooms) {
         $count++;
         $room_id = $rooms['room_details']['id'];
         $available_rooms = [];
         $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
             $query->where(function ($query2) use($i, $room_id) {
                 $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
             })->where(function ($query3) {
                 $query3->where('status', '!=', 5)->where('status', '!=', 3);
             });
         }))->where('room_id', $room_id)->get();
         foreach ($room_qty as $available) {
             if ($available->roomReserved == '[]') {
                 array_push($available_rooms, $available);
             }
         }
         for ($counter = 0; $counter < $rooms['quantity']; $counter++) {
             array_push($booked_room, $available_rooms[$counter]);
         }
     }
     //end of foreach
     $total = 0;
     if (!empty($booked_room)) {
         foreach ($booked_room as $b) {
             $total += $b->roomPrice->price * Session::get('reservation.nights');
             $tax = $total * 0.12;
             $total = $total + $tax;
             $reserveRoom = new ReservedRoom();
             $reserveRoom->booking_id = $new_booking->id;
             $reserveRoom->room_id = $b->id;
             $reserveRoom->price = $total;
             /*$reserveRoom->check_in = $i['checkin'];
             		$reserveRoom->check_out = $i['checkout'];
             		$reserveRoom->firstname = $customerinformation['firstname'];
             		$reserveRoom->lastname = $customerinformation['lastname'];
             		$reserveRoom->address = $customerinformation['address'];
             		$reserveRoom->contact_number = $customerinformation['contact_no'];
             		$reserveRoom->email_address = $customerinformation['email'];*/
             $reserveRoom->save();
         }
     }
     $tax = $total * 0.12;
     $total = $total + $tax;
     $new_booking->price = $total;
     $new_booking->save();
     return Redirect::to('booking/step5');
 }
예제 #16
0
 public function create()
 {
     $messages = array();
     if (!preg_match('#^[0-9]{2}/[0-9]{2}/[0-9]{4}$#', Input::get('date'))) {
         $messages['date'] = 'La date doit être renseignée';
     }
     if (!preg_match('#^[0-9]{2}:[0-9]{2}$#', Input::get('start'))) {
         $messages['start'] = 'L\'heure de début doit être renseignée';
     }
     if (!preg_match('#^[0-9]{2}:[0-9]{2}$#', Input::get('end'))) {
         $messages['end'] = 'L\'heure de fin doit être renseignée';
     }
     $rooms = Input::get('rooms');
     if (empty($rooms)) {
         $messages['rooms'] = 'La salle doit être renseignée';
     } else {
         //            $start = newDateTime(Input::get('date'), Input::get('start'));
         //            $end = newDateTime(Input::get('date'), Input::get('start'));
         //            $end->modify(sprintf('+%d hours', getDuration(Input::get('start'), Input::get('end'))));
         //
         //            foreach (Input::get('rooms') as $ressource_id) {
         //                'SELECT count(*) FROM booking_item WHERE
         //                  start_at < :start AND DATE_ADD()
         //
         //'
         //            BookingItem::whereRessourceId($ressource_id)
         //                ->where('start_at', '<', $start->format('Y-m-d H:i:s'))
         //                ->where('start_at', '<', $start->format('Y-m-d H:i:s'))
         //                ;
         //            }
     }
     $start_at = newDateTime(Input::get('date'), Input::get('start'));
     if (!Auth::user()->isSuperAdmin() && $start_at->format('Y-m-d H:i:s') < (new \DateTime())->format('Y-m-d H:i:s')) {
         $messages['start'] = 'Vous ne pouvez pas réserver une salle dans le passé';
     }
     if (count($messages)) {
         return Response::json(array('status' => 'KO', 'messages' => $messages));
     }
     $id = Input::get('id');
     $booking_items = array();
     if ($id) {
         $booking_item = BookingItem::whereId($id)->with('booking')->first();
         if (!$booking_item) {
             App::abort(404);
         }
         $booking = $booking_item->booking;
         if (!Auth::user()->isSuperAdmin() && Auth::id() != $booking->user_id) {
             App::abort(403);
         }
         foreach ($booking->items()->where('start_at', '=', $booking_item->start_at)->get() as $item) {
             $booking_items[$item->ressource_id] = $item;
         }
         $is_new = false;
     } else {
         $booking = new Booking();
         $is_new = true;
     }
     $booking->title = Input::get('title');
     $booking->content = Input::get('description');
     if (Auth::user()->isSuperAdmin()) {
         $booking->user_id = Input::get('user_id');
         if (empty($booking->user_id)) {
             $booking->user_id = Auth::id();
         }
     } else {
         $booking->user_id = Auth::id();
     }
     $booking->is_private = Input::get('is_private', false);
     $booking->save();
     $result = array();
     foreach (Input::get('rooms') as $ressource_id) {
         if (isset($booking_items[$ressource_id])) {
             $booking_item = $booking_items[$ressource_id];
             unset($booking_items[$ressource_id]);
         } else {
             $booking_item = new BookingItem();
             $booking_item->booking_id = $booking->id;
             $booking_item->ressource_id = $ressource_id;
         }
         $booking_item->start_at = $start_at;
         $booking_item->duration = getDuration(Input::get('start'), Input::get('end'));
         $booking_item->is_open_to_registration = Input::get('is_open_to_registration', false);
         $booking_item->save();
         $result[] = $booking_item->toJsonEvent();
     }
     foreach ($booking_items as $booking_item) {
         $booking_item->delete();
     }
     try {
         $this->sendNewBookingNotification($booking, $is_new);
     } catch (\Exception $e) {
     }
     return Response::json(array('status' => 'OK', 'events' => $result));
 }
예제 #17
0
 public function actionRequestPickUp()
 {
     $req = Yii::app()->request;
     $shipment_id = $req->getQuery('shipment_id');
     if (!isset($_POST['Booking'])) {
         echo CJSON::encode($this->statusError('Must be in POST method'));
         Yii::app()->end();
     }
     $booking = new Booking();
     $booking->setAttributes($_POST['Booking']);
     $booking->setAttribute('booking_code', dechex(time()));
     if ($shipment_id != null) {
         $shipment = Shipment::model()->findByPk($shipment_id);
         if (!$shipment instanceof Shipment) {
             echo CJSON::encode($this->statusError('Your Shipment is invalid'));
             Yii::app()->end();
         }
     }
     $trans = Yii::app()->db->beginTransaction();
     try {
         if ($booking->save()) {
             if (isset($shipment) && $shipment instanceof Shipment) {
                 Booking::model()->updateByPk($booking->id, array('customer_id' => $shipment->customer_id));
                 $shipment->setAttribute('booking_id', $booking->id);
                 if (!$shipment->save()) {
                     throw ServiceControllerException($shipment->getErrors());
                 }
             } else {
                 if ($this->token instanceof Token) {
                     $customer = Customer::model()->findByPk($this->token->customer_id);
                     if (!$customer instanceof Customer) {
                         throw new ServiceControllerException('You have to login first');
                     } else {
                         Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id));
                     }
                 } else {
                     $customer = new Customer();
                     $customer->name = $booking->name;
                     $customer->type = 'personal';
                     $customer->accountnr = 'WEB' . time();
                     if ($customer->save()) {
                         $contact = new Contact();
                         $contact->parent_id = $customer->id;
                         $contact->parent_model = 'Customer';
                         $contact->full_name = $booking->name;
                         $contact->address = $booking->address;
                         $contact->country = $booking->country;
                         $contact->city = $booking->city;
                         $contact->postal = $booking->postal;
                         if ($contact->save()) {
                             Booking::model()->updateByPk($booking->id, array('customer_id' => $customer->id));
                         } else {
                             throw new ServiceControllerException($contact->getErrors());
                         }
                     } else {
                         throw new ServiceControllerException($customer->getErrors());
                     }
                 }
             }
             $data = array('booking_code' => $booking->booking_code);
         } else {
             throw ServiceControllerException($booking->getErrors());
         }
         $trans->commit();
     } catch (ServiceControllerException $e) {
         $errors = $e->errors;
         $trans->rollback();
         echo CJSON::encode($this->statusError($errors));
         Yii::app()->end();
     }
     echo CJSON::encode($this->statusSuccess($data));
     Yii::app()->end();
 }
 public function getPaymentStatus()
 {
     // Get the payment ID before session clear
     $payment_id = Session::get('paypal_payment_id');
     // clear the session payment ID
     Session::forget('paypal_payment_id');
     if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
         return Redirect::route('original.route')->with('error', 'Payment failed');
     }
     $payment = Payment::get($payment_id, $this->_api_context);
     // PaymentExecution object includes information necessary
     // to execute a PayPal account payment.
     // The payer_id is added to the request query parameters
     // when the user is redirected from paypal back to your site
     $execution = new PaymentExecution();
     $execution->setPayerId(Input::get('PayerID'));
     //Execute the payment
     $result = $payment->execute($execution, $this->_api_context);
     /*echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later*/
     if ($result->getState() == 'approved') {
         // payment made
         // $tax = null;
         $total_price = null;
         $i = [];
         $i['checkin'] = Session::get('reservation')['checkin'] . '12:00:00';
         $i['checkout'] = Session::get('reservation')['checkout'] . '11:59:00';
         $customerinformation = Session::get('reservation.customerinformation');
         $count = 0;
         //for test
         $count1 = 0;
         //for test
         $booked_room = [];
         //all picked rooms from available rooms
         $new_booking = new Booking();
         $new_booking->firstname = $customerinformation['firstname'];
         $new_booking->lastname = $customerinformation['lastname'];
         $new_booking->address = $customerinformation['address'];
         $new_booking->contact_number = $customerinformation['contact_no'];
         $new_booking->email_address = $customerinformation['email'];
         $new_booking->check_in = $i['checkin'];
         $new_booking->check_out = $i['checkout'];
         $new_booking->payment_type = 'paypal';
         $new_booking->paypal_paymentId = Input::get('PayerID');
         $new_booking->save();
         if (Session::has('hasMembershipDiscount')) {
             $booking_remarks = new BookingRemarksHistory();
             $booking_remarks->remarks = "Membership Discount";
             $booking_remarks->deduction = Session::get('hasMembershipDiscount');
             $booking_remarks->booking_id = $new_booking->id;
             $booking_remarks->save();
             Session::forget('hasMembershipDiscount');
         }
         if (Session::has('hasCouponDiscount')) {
             $booking_remarks = new BookingRemarksHistory();
             $booking_remarks->remarks = "Coupon Discount";
             $booking_remarks->deduction = Session::get('hasCouponDiscount');
             $booking_remarks->booking_id = $new_booking->id;
             $booking_remarks->save();
             Session::forget('hasCouponDiscount');
         }
         foreach (Session::get('reservation')['reservation_room'] as $rooms) {
             $count++;
             $room_id = $rooms['room_details']['id'];
             $available_rooms = [];
             $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) {
                 $query->where(function ($query2) use($i, $room_id) {
                     $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out');
                 })->where(function ($query3) {
                     $query3->where('status', '!=', 5)->orWhere('status', '!=', 3);
                 });
             }))->where('room_id', $room_id)->where('status', 1)->get();
             foreach ($room_qty as $available) {
                 if ($available->roomReserved == '[]') {
                     array_push($available_rooms, $available);
                 }
             }
             for ($counter = 0; $counter < $rooms['quantity']; $counter++) {
                 array_push($booked_room, $available_rooms[$counter]);
             }
         }
         $total = 0;
         if (!empty($booked_room)) {
             foreach ($booked_room as $b) {
                 $roomprice = $b->roomPrice->price * Session::get('reservation.nights');
                 $total += $b->roomPrice->price * Session::get('reservation.nights');
                 //$roomprice+=$tax;
                 //$total = $total + $tax;
                 $reserveRoom = new ReservedRoom();
                 $reserveRoom->booking_id = $new_booking->id;
                 $reserveRoom->room_id = $b->id;
                 $reserveRoom->room_type = $b->room_id;
                 $reserveRoom->price = $roomprice;
                 $reserveRoom->check_in = $i['checkin'];
                 $reserveRoom->check_out = $i['checkout'];
                 $reserveRoom->status = 1;
                 $reserveRoom->firstname = $customerinformation['firstname'];
                 $reserveRoom->lastname = $customerinformation['lastname'];
                 $reserveRoom->address = $customerinformation['address'];
                 $reserveRoom->contact_number = $customerinformation['contact_no'];
                 $reserveRoom->email_address = $customerinformation['email'];
                 $reserveRoom->save();
             }
         }
         //$tax = $total * 0.12;
         //$total = $total + $tax;
         $new_booking->price = Session::get('total_price');
         $new_booking->paid = Session::get('total_price');
         $new_booking->status = 1;
         $date = date('Ymd');
         $code = strtolower(Str::random(5) . $date);
         $new_booking->code = $code;
         $new_booking->save();
         Session::forget('reservation');
         Session::forget('total_price');
         return Redirect::to('booking/step5')->with('code', $code);
     }
     return 'error in payment';
 }