示例#1
0
 public function refreshAction()
 {
     $em = $this->getDoctrine()->getManager();
     $session = $this->getRequest()->getSession();
     $config = $em->find('BackResaBookingBundle:Configuration', 1);
     if (!$config) {
         $session->getFlashBag()->add('info', " Vos paramétres de configuration sont vides ");
         return $this->redirect($this->generateUrl('back_resabooking_hotels_liste'));
     }
     $xmlProducts = simplexml_load_file($config->getLienProduit(), "SimpleXMLELement", LIBXML_NOCDATA);
     $json = json_encode($xmlProducts);
     $produits = json_decode($json, TRUE);
     $xmlPrix = simplexml_load_file($config->getLienPrix(), "SimpleXMLELement", LIBXML_NOCDATA);
     $json = json_encode($xmlPrix);
     $prix = json_decode($json, TRUE);
     foreach ($produits['produit'] as $produit) {
         $hotel = $em->find('BackResaBookingBundle:Hotel', $produit['id_hotel']);
         if (!$hotel) {
             $hotel = new Hotel();
             $hotel->setId($produit['id_hotel']);
         }
         $hotel->setLibelle($produit['libelle_hotel']);
         $hotel->setProduit($produit);
         $arrayPrix = array();
         foreach ($prix['produit'] as $p) {
             if ($p['id_hotel'] == $produit['id_hotel']) {
                 $arrayPrix[] = $p;
             }
         }
         $hotel->setPrix($arrayPrix);
         $em->persist($hotel);
         $em->flush();
     }
     $session->getFlashBag()->add('success', " les hôtels sont à jour ");
     return $this->redirect($this->generateUrl('back_resabooking_hotels_liste'));
 }
 public function devisAction($pension, Hotel $hotel, $debut, $fin, $room1, $room2, $room3, $room4, $room5)
 {
     $em = $this->getDoctrine()->getManager();
     $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();
     }
     $confPaiement = $em->find('BackHotelTunisieBundle:ConfigurationPayement', 1);
     if ($confPaiement) {
         $choices[2] = 'Paiement Total en ligne';
         if ($confPaiement->getAvance() != 0) {
             $choices[3] = 'Paiement avance de ' . $confPaiement->getAvance() . '% en ligne';
         }
     }
     $reponse = $this->container->get('resabookingservice')->availabilityHotel($hotel->getProduit()['region'], $debut, $fin, $this->container->get('resabookingservice')->getRooms($room1, $room2, $room3, $room4, $room5), $hotel->getId());
     if ($reponse->rep->statut == 'failure') {
         $this->getRequest()->getSession()->getFlashBag()->add('warning', $reponse->rep->detail_erreur);
         return $this->redirect($this->generateUrl('front_resabooking_initialise_date'));
     }
     $chambs = new chambs();
     foreach ($reponse->hots[0]->chambres[0]->chambre[0]->chamb as $chamb) {
         $chambs->addChamb($chamb);
     }
     $reponseDevis = $this->container->get('resabookingservice')->devis($reponse->session, $hotel->getId(), $pension, $chambs, null);
     if ($reponseDevis->rep->statut == 'failure') {
         $this->getRequest()->getSession()->getFlashBag()->add('warning', $reponseDevis->rep->detail_erreur);
         return $this->redirect($this->generateUrl('front_resabooking_initialise_date'));
     }
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         $travellerPrincipale = new Traveller('adult', null, null, null, $request->get("FirstName"), $request->get("LastName"), $request->get('civiliti'), $request->get('adresse'), $request->get('pays'), $request->get('ville'), $request->get('mail'), $request->get('tel'), $request->get('cp'));
         $travellers = new Travellers();
         $index = 1;
         foreach ($chambs->getChs() as $chamb) {
             for ($i = 1; $i <= $chamb->nombre_adult; $i++) {
                 $traveller = new Traveller('adult');
                 if ($i == 1 && $index == 1) {
                     $traveller = $travellerPrincipale;
                 } else {
                     $traveller->setFirstName($request->get($index . "_AdulteFirstName_" . $i));
                     $traveller->setLastName($request->get($index . "_AdulteLastName_" . $i));
                 }
                 $travellers->addTraveller($traveller);
             }
             for ($i = 1; $i <= $chamb->nombre_enfant; $i++) {
                 $traveller = new Traveller('enfant');
                 $traveller->setFirstName($request->get($index . "_EnfantFirstName_" . $i));
                 $traveller->setLastName($request->get($index . "_EnfantLastName_" . $i));
                 $travellers->addTraveller($traveller);
             }
             for ($i = 1; $i <= $chamb->nombre_bebe; $i++) {
                 $traveller = new Traveller('bebe');
                 $traveller->setFirstName($request->get($index . "_BeBeFirstName_" . $i));
                 $traveller->setLastName($request->get($index . "_BeBeLastName_" . $i));
                 $travellers->addTraveller($traveller);
             }
             $index++;
         }
         $reservation = new Reservation();
         $reservation->setClient($client)->setChambs($chambs)->setTraveller($travellerPrincipale)->setTravellers($travellers)->setHotel($hotel)->setPension($pension)->setReponseDevis($reponseDevis)->setTotalAchat($reponseDevis->price)->setTotal($this->get('resabookingservice')->margeResaBooking($reponseDevis->price))->setDateDebut(\DateTime::createFromFormat('Y-m-d', $debut))->setDateFin(\DateTime::createFromFormat('Y-m-d', $fin));
         if ($request->get('paiement') == 3 && $confPaiement->getAvance() != 0) {
             $montan = round($reservation->getTotal() * $confPaiement->getAvance() / 100);
         } else {
             $montan = $reservation->getTotal();
         }
         $em->persist($reservation->setTypePayement($request->get('paiement'))->setMontantPayementElectronique($montan));
         $em->flush();
         return $this->redirect($confPaiement->getUrl() . 'RB-' . $reservation->getId() . '&Montant=' . $montan . '&Devise=TND&sid=' . session_id() . '&affilie=' . $confPaiement->getNumeroAffiliation());
     }
     return $this->render('FrontGeneralBundle:resabooking:devis.html.twig', array('choinces' => $choices, 'hotel' => $hotel, 'chambs' => $chambs->getChs(), 'reponseDevis' => $reponseDevis, 'dateDebut' => \DateTime::createFromFormat('Y-m-d', $debut), 'dateFin' => \DateTime::createFromFormat('Y-m-d', $fin)));
 }