예제 #1
0
 public function saveReservation(Pack $pack, Client $client, $data, $source)
 {
     $periode = $pack->getPeriode();
     $supplements = array();
     $circuits = array();
     $frais = array();
     $chambres = array(array('single', 1, $pack->getSingleAchat(), $pack->getSingleVente()), array('double', 2, $pack->getDoubleAchat(), $pack->getDoubleVente()), array('triple', 3, $pack->getTripleAchat(), $pack->getTripleVente()), array('quadruple', 4, $pack->getQuadrupleAchat(), $pack->getQuadrupleVente()));
     $coordoonnes = array($client->getNomPrenom(), $client->getTel1(), $client->getTel2(), $client->getAdresse());
     $tarifCommercial = $this->em->getRepository('BackCommercialBundle:Tarif')->find(1);
     $reservation = new Reservation();
     $reservation->setClient($client)->setCoordonnees($coordoonnes)->setEtat(1)->setPack($pack)->setVoyage($periode->getVoyage());
     if ($tarifCommercial && $tarifCommercial->getTimbre()) {
         $reservation->setTimbre($tarifCommercial->getMontantTimbre());
     }
     if ($source == 'frontoffice') {
         $reservation->setFrontOffice(TRUE);
     } else {
         $reservation->setResponsable($this->container->get('security.context')->getToken()->getUser());
     }
     $this->em->persist($reservation);
     $x = 0;
     foreach ($chambres as $ch) {
         for ($i = 1; $i <= $data['chambre' . $ch[0]]; $i++) {
             $reservationChambre = new ReservationChambre();
             $reservationChambre->setReservation($reservation)->setType($ch[1]);
             $this->em->persist($reservationChambre);
             for ($p = 1; $p <= $ch[1]; $p++) {
                 $x++;
                 $reservationPersonne = new ReservationPersonne();
                 $reservationPersonne->setChambre($reservationChambre)->setNomPrenom($data[$ch[0] . '_nom_' . $i . '_' . $p])->setPassport($data[$ch[0] . '_passport_' . $i . '_' . $p]);
                 if ($data[$ch[0] . '_age_' . $i . '_' . $p] != 'adulte') {
                     $reservationPersonne->setAge($data[$ch[0] . '_age_' . $i . '_' . $p])->setEnfant(TRUE);
                 } else {
                     $reservationPersonne->setAge(NULL)->setEnfant(FALSE);
                 }
                 $this->em->persist($reservationPersonne);
                 $reservationLigne = new ReservationLigne();
                 $reservationLigne->setPersonne($reservationPersonne)->setLibelle('Logement chambre ' . $ch[0])->setCode('chambre_' . $ch[0])->setAchat($ch[2])->setVente($ch[3]);
                 $this->em->persist($reservationLigne);
                 foreach ($pack->getSupplements() as $supp) {
                     if ($supp->getObligatoire() || isset($data['supplement' . $supp->getId()])) {
                         if ($x == 1) {
                             $supplements[] = $supp->getId();
                         }
                         $reservationLigne = new ReservationLigne();
                         $reservationLigne->setPersonne($reservationPersonne)->setLibelle($supp->getLibelle())->setCode('Supplement')->setAchat($supp->getAdulteAchat())->setVente($supp->getAdulteVente());
                         $this->em->persist($reservationLigne);
                     }
                 }
                 foreach ($periode->getCircuits() as $supp) {
                     if ($supp->getObligatoire() || isset($data['circuit' . $supp->getId()])) {
                         if ($x == 1) {
                             $circuits[] = $supp->getId();
                         }
                         $reservationLigne = new ReservationLigne();
                         $reservationLigne->setPersonne($reservationPersonne);
                         if (!$reservationPersonne->getEnfant()) {
                             $reservationLigne->setAchat($supp->getAdulteAchat())->setVente($supp->getAdulteVente())->setCode('CircuitAdl')->setLibelle($supp->getLibelle() . ' adulte');
                         } else {
                             $reservationLigne->setAchat($supp->getEnfantAchat())->setVente($supp->getEnfantVente())->setCode('CircuitEnf')->setLibelle($supp->getLibelle() . ' enfant');
                         }
                         $this->em->persist($reservationLigne);
                     }
                 }
                 foreach ($periode->getFrais() as $supp) {
                     if ($supp->getObligatoire() || isset($data['frai' . $supp->getId()])) {
                         if ($x == 1) {
                             $frais[] = $supp->getId();
                         }
                         $reservationLigne = new ReservationLigne();
                         $reservationLigne->setPersonne($reservationPersonne);
                         if (!$reservationPersonne->getEnfant()) {
                             $reservationLigne->setAchat($supp->getAdulteAchat())->setVente($supp->getAdulteVente())->setCode('FraisDiversAdl')->setLibelle($supp->getLibelle() . ' adulte');
                         } else {
                             $reservationLigne->setAchat($supp->getEnfantAchat())->setVente($supp->getEnfantVente())->setCode('FraisDiversEnf')->setLibelle($supp->getLibelle() . ' enfant');
                         }
                         $this->em->persist($reservationLigne);
                     }
                 }
             }
         }
     }
     $this->em->persist($reservation->setSupplements($supplements)->setCircuits($circuits)->setFrais($frais));
     $this->em->flush();
     return $reservation->getId();
 }
 public function reservationAction($slug, Pack $pack)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     $request = $this->getRequest();
     $user = $this->get('security.context')->getToken()->getUser();
     if ($this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') && !is_null($user->getClient())) {
         $client = $user->getClient();
     } else {
         $client = $this->container->get('users')->getPassager();
     }
     $form = $this->createFormBuilder()->add("client", new ClientType(), array('data' => $client));
     $form = $form->getForm();
     if ($request->isMethod('POST')) {
         $form->submit($request);
         $data = $request->request->all();
         $nbrPassagers = 0;
         if (isset($data['chambresingle'])) {
             $nbrPassagers += $data['chambresingle'];
         } else {
             $data['chambresingle'] = 0;
         }
         if (isset($data['chambredouble'])) {
             $nbrPassagers += $data['chambredouble'] * 2;
         } else {
             $data['chambredouble'] = 0;
         }
         if (isset($data['chambretriple'])) {
             $nbrPassagers += $data['chambretriple'] * 3;
         } else {
             $data['chambretriple'] = 0;
         }
         if (isset($data['chambrequadruple'])) {
             $nbrPassagers += $data['chambrequadruple'] * 4;
         } else {
             $data['chambrequadruple'] = 0;
         }
         if ($nbrPassagers == 0) {
             $session->getFlashBag()->add('Erreur', "Vous devrez choisir au moin une chambre.");
             return $this->redirect($this->generateUrl('front_voyageorganise_reservation', array('slug' => $slug, 'pack' => $pack->getId())));
         } elseif ($pack->getPeriode()->getDepartGarantie() && $nbrPassagers < $pack->getPeriode()->getMin()) {
             $session->getFlashBag()->add('Erreur', "Vous devrez choisir au moin " . $pack->getPeriode()->getMin() . " personnes.");
             return $this->redirect($this->generateUrl('front_voyageorganise_reservation', array('slug' => $slug, 'pack' => $pack->getId())));
         }
         return $this->redirect($this->generateUrl('front_voyageorganise_thankyou', array('slug' => $slug, 'reservation' => $this->container->get('reservationVO')->saveReservation($pack, $client, $data, 'frontoffice'))));
     }
     return $this->render('FrontGeneralBundle:voyageorganise:reservation.html.twig', array('form' => $form->createView(), 'csrf_token' => $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate'), 'periode' => $pack->getPeriode(), 'pack' => $pack));
 }