/**
  * Saphir room page.
  */
 public function blueRoomAction(Request $request)
 {
     // Prepare the booking form.
     $booking = new Booking();
     $booking->setRoom('blue');
     $form = $this->createForm(BookingType::class, $booking, array('action' => $this->generateUrl('booking'), 'method' => 'POST'));
     // Prepare the contact form.
     $contact = $this->createForm(ContactType::class, null, array('action' => $this->generateUrl('contact'), 'method' => 'POST'));
     return $this->render('rooms/blue.html.twig', array('form' => $form->createView(), 'contact' => $contact->createView()));
 }
Beispiel #2
0
 /**
  * Change status of booking with commision
  * @param Request $request
  * @param Booking $booking
  * @param $status
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function bookingCommisionStatusAction(Request $request, Booking $booking, $status)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $accommodation = $booking->getUnit()->getAccommodation();
     $status = $status == 'null' ? NULL : $status;
     try {
         $booking->setCommision($status);
         $em->persist($booking);
         $em->flush();
         $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('change_status_success'));
     } catch (\Exception $e) {
         $session->getFlashBag()->add('msgError', $this->get('translator')->trans('change_status_error'));
     }
     return $this->redirect($this->generateUrl('admin_bookings_commision_accommodation', array('id' => $accommodation->getId())));
 }
 /**
  * Booking Action
  * @param Request $request
  * @param Accommodation $accommodation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function bookingAction(Request $request, Accommodation $accommodation)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     try {
         # User
         $role = $em->getRepository('UserBundle:Role')->findOneByName('guest');
         $unit = $em->getRepository('AppBundle:Unit')->find($request->request->get('unit'));
         $checkIn = new \DateTime($request->request->get('checkIn'));
         $checkOut = new \DateTime($request->request->get('checkOut'));
         $price = $request->request->get('price');
         $bookingForm = $this->createForm(new RegistrationType(array()));
         $bookingForm->handleRequest($request);
         # Array with form fields
         $data = $bookingForm->getData();
         if (!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
             $user = new User();
             $user->setRoles($role);
             $user->setUsername($data['username']);
             $user->setName($data['name']);
             $user->setSurename($data['surename']);
             $user->setEmail($data['email']);
             $user->setPassword($data['password']);
             $user->setIsActive(0);
             $user->encryptPassword();
             # User validation
             $validator = $this->get('validator');
             $errors = $validator->validate($user);
             $errorsString = (string) $errors;
             if (count($errors) > 0) {
                 $response = array();
                 $response['error'] = $errorsString;
                 $session->getFlashBag()->add('formErrors', (string) $errorsString);
                 return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId())));
             }
         } else {
             $user = $this->getUser();
         }
         # Booking
         $booking = new Booking();
         $booking->setUnit($unit);
         $booking->setStatus(0);
         $booking->setPrice($price);
         $booking->setUser($user);
         $booking->setFromDate($checkIn);
         $booking->setToDate($checkOut);
         # Booking validation
         $validator = $this->get('validator');
         $errorsBooking = $validator->validate($booking);
         $errorsString = (string) $errorsBooking;
         if (count($errorsBooking) > 0) {
             $response = array();
             $response['error'] = $errorsString;
             $session->getFlashBag()->add('formErrors', (string) $errorsString);
             return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId())));
         }
         # Booking not allowed
         if (!$this->get('bookingService')->bookingAllowed($booking)) {
             return $this->redirect($this->generateUrl('user_403'));
         }
         $em->persist($user);
         $em->flush();
         $em->persist($booking);
         $em->flush();
         $session->getFlashBag()->add('formSuccess', $this->get('translator')->trans('booking_success'));
         $this->bookingRequestEmail($accommodation->getUser(), $booking, 'host');
         $this->bookingRequestEmail($user, $booking, 'guest');
         if ($user->getIsActive()) {
             return $this->redirect($this->generateUrl('app_profile'));
         } else {
             return $this->redirect($this->generateUrl('app_home'));
         }
     } catch (ExportException $e) {
         $session->getFlashBag()->add('formError', $e->getMessage());
         return $this->redirect($this->generateUrl('app_home'));
     }
 }
 /**
  * @Route("/booking/confirmation/{uuid}", name="booking-confirmation")
  */
 public function confirmationAction(Request $request, $uuid)
 {
     $inq = $this->getDoctrineRepo('AppBundle:Inquiry')->findOneByUuid($uuid);
     // sanity check
     if ($inq == null) {
         throw $this->createNotFoundException();
     }
     if ($inq->getBooking() !== null) {
         // booking already confirmed
         return new Response('', 403);
         // TODO: display a nice message to the user?
     }
     $data = array('uuid' => $uuid);
     $form = $this->createFormBuilder($data, array('constraints' => array(new Callback(array($this, 'validateDiscountCode')))))->add('agree', 'checkbox', array('required' => false, 'constraints' => array(new NotBlank())))->add('discountCode', 'text', array('required' => false))->add('uuid', 'hidden')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $bk = new Booking();
         $bk->setInquiry($inq);
         $bk->setStatus(Booking::STATUS_BOOKED);
         // save booking
         $em = $this->getDoctrine()->getManager();
         $em->persist($bk);
         $em->flush();
         // calcualte discount
         if (!empty($data['discountCode'])) {
             $dcode = $this->getDoctrineRepo('AppBundle:DiscountCode')->findOneByCode($data['discountCode']);
             $dcode->setStatus(DiscountCode::STATUS_USED);
             $dcode->setInquiry($inq);
             $p = $inq->getPrice() - 5;
             $inq->setPrice($p);
             $this->getDoctrine()->getManager()->flush();
         }
         // send email to provider & user
         //<editor-fold>
         $provider = $inq->getEquipment()->getUser();
         $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname'));
         $emailHtml = $this->renderView('Emails/booking_confirmation_provider.html.twig', array('mailer_image_url_prefix' => $this->getParameter('mailer_image_url_prefix'), 'provider' => $provider, 'inquiry' => $inq, 'equipment' => $inq->getEquipment()));
         $message = Swift_Message::newInstance()->setSubject('Du hast soeben eine Anfrage erhalten')->setFrom($from)->setTo($provider->getEmail())->setBody($emailHtml, 'text/html');
         $this->get('mailer')->send($message);
         if ($inq->getUser() !== null) {
             $email = $inq->getUser()->getEmail();
         } else {
             $email = $inq->getEmail();
         }
         $emailHtml = $this->renderView('Emails/booking_confirmation_user.html.twig', array('mailer_image_url_prefix' => $this->getParameter('mailer_image_url_prefix'), 'provider' => $provider, 'inquiry' => $inq, 'equipment' => $inq->getEquipment()));
         $message = Swift_Message::newInstance()->setSubject('Du hast soeben eine Anfrage erhalten')->setFrom($from)->setTo($email)->setBody($emailHtml, 'text/html');
         $this->get('mailer')->send($message);
         //</editor-fold>
         return $this->redirectToRoute('rentme');
     }
     return $this->render('booking/confirmation.html.twig', array('inquiry' => $inq, 'form' => $form->createView()));
 }
 /**
  * @Route("/add-booking/{pageId}")
  * @Method("POST")
  * @param Request $request
  * @throws \Exception
  * @return JsonResponse
  */
 public function addBookingAction($pageId, Request $request)
 {
     /**
      * @var Pages $page
      */
     $page = $this->getDoctrine()->getRepository('AppBundle:Pages')->find($pageId);
     if (!$page) {
         throw $this->createNotFoundException('No page found for request param ' . $pageId);
     }
     $response = new JsonResponse();
     $bookingEntity = new Booking();
     $bookingEntity->setPage($page);
     $form = $this->createForm(new BookingForm('/add-booking/' . $page->getId()), $bookingEntity);
     $form->handleRequest($request);
     $validatorBuilder = new BookingValidatorChainBuilder();
     $validatorChain = $validatorBuilder->buildChain();
     $values = $request->request->all();
     $bookingEntity->setPriceString($page->getPrice());
     if (isset($values['appbundle_booking'])) {
         $values = $values['appbundle_booking'];
     } else {
         $values = array();
     }
     $values['priceString'] = $page->getPrice();
     if ($validatorChain->validateContext($values) === null) {
         $calculator = new Calculator();
         $calcRequest = new CalculationContext();
         $calcRequest->setPricePerNight($values['priceString']);
         $calcRequest->setGuestsCount($values['guestsCount']);
         $calcRequest->setCheckOutDate($values['checkoutDate']);
         $calcRequest->setCheckInDate($values['checkinDate']);
         $calcResult = $calculator->calculate($calcRequest);
         $bookingEntity->setNightsCount($calcResult['nightsCount']);
         $bookingEntity->setTotal($calcResult['total']);
         $em = $this->getDoctrine()->getManager();
         $em->persist($bookingEntity);
         $em->flush();
         try {
             $this->sendBookingEmail($bookingEntity);
         } catch (\Exception $e) {
         }
         $response->setData(array('success' => true));
     } else {
         $response->setData(array('errors' => $validatorChain->getFlatenErrors()));
     }
     return $response;
 }
 /**
  * Find bookings for given room and dates.
  *
  * @param Booking $booking
  *   The booking to get data from.
  * @param boolean $validated
  *   Only check for validated bookings if true.
  *
  * @return array
  *   All bookings for given room and dates.
  */
 public function findExisting(Booking $booking, $validated = true)
 {
     return $this->findExistingExplicit($booking->getRoom(), $booking->getFromDate(), $booking->getToDate(), $validated, array($booking->getId()));
 }