Пример #1
0
 public function validerAction(Reservation $reservation)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $request = $this->getRequest();
     $session = $this->getRequest()->getSession();
     $periode = $reservation->getPack()->getPeriode();
     $pieces = $em->getRepository('BackCommercialBundle:Piece')->findBy(array('client' => $reservation->getClient(), 'regle' => FALSE));
     if ($user->getId() != $reservation->getResponsable()->getId() || $reservation->getEtat() == 2) {
         return $this->redirect($this->generateUrl("back_voyages_organises_reservation_consulter", array('id' => $reservation->getId())));
     }
     $form = $this->createFormBuilder()->add("piece", new PieceType());
     foreach ($pieces as $piece) {
         $form->add('piece' . $piece->getId(), 'checkbox', array('label' => $piece->getNumero(), 'required' => FALSE));
     }
     $form = $form->getForm();
     if ($request->isMethod("POST")) {
         $form->submit($request);
         $data = $form->getData();
         foreach ($pieces as $piece) {
             if ($data['piece' . $piece->getId()] && $reservation->getMontantRestant() > 0) {
                 $reglement = new Reglement();
                 if ($piece->getMontant() <= $reservation->getMontantRestant()) {
                     $reglement->setMontant($piece->getMontant());
                     $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                 } else {
                     $reglement->setMontant($reservation->getMontantRestant());
                     $em->persist($piece->setMontant($piece->getMontant() - $reservation->getMontantRestant()));
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservationVO($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
             }
         }
         if ($reservation->getMontantRestant() > 0 && !is_null($data['piece']->getModeReglement()) && !is_null($data['piece']->getMontantOrigine())) {
             if ($data['piece']->getMontantOrigine() > 0) {
                 $reglement = new Reglement();
                 $piece = new Piece();
                 $piece = $data['piece'];
                 $piece->setClient($reservation->getClient())->setDateCreation(new \DateTime());
                 if ($piece->getMontantOrigine() <= $reservation->getMontantRestant()) {
                     $reglement->setMontant($piece->getMontantOrigine());
                     $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                 } else {
                     $reglement->setMontant($reservation->getMontantRestant());
                     $em->persist($piece->setRegle(FALSE)->setMontant($piece->getMontantOrigine() - $reservation->getMontantRestant()));
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservationVO($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
                 $session->getFlashBag()->add('success', "Votre piéce a été ajoutée avec succès");
             } else {
                 $session->getFlashBag()->add('danger', "Le montant de la piéce doit étre suppérieure à 0");
             }
         }
         if ($reservation->getMontantRestant() == 0) {
             if (!$periode->getDepartGarantie()) {
                 $em->persist($periode->setNombreInscription($periode->getNombreInscription() + $reservation->getNombreOccupants()));
                 $session->getFlashBag()->add('info', 'Reste encore ' . ($periode->getMax() - $periode->getNombreInscription()) . ' places dans ' . $reservation->getVoyage()->getLibelle());
             }
             $em->persist($reservation->setEtat(2)->setValidated(new \DateTime()));
             $em->flush();
             $session->getFlashBag()->add('success', " Votre Réservation a été validée avec succès ");
             $this->container->get('mailerservice')->validation($reservation, 'VO');
             return $this->redirect($this->generateUrl("back_voyages_organises_reservation_consulter", array('id' => $reservation->getId())));
         } else {
             $session->getFlashBag()->add('info', " Votre Réservation n'a pas été encore validée, reste encore <strong>" . $reservation->getMontantRestant() . " DT </strong> a payé");
         }
         $em->flush();
         return $this->redirect($this->generateUrl("back_voyages_organises_reservation_validation", array('id' => $reservation->getId())));
     }
     if (!$reservation->getPack()->getPeriode()->getDepartGarantie() && $reservation->getPack()->getPeriode()->getMax() - $reservation->getPack()->getPeriode()->getNombreInscription() <= 0) {
         $session->getFlashBag()->add('info', 'Il y a plus de place dans cette Période <br><strong>Maximum d\'inscription : </strong>' . $reservation->getPack()->getPeriode()->getMax() . '<br><strong>Nombre de place</strong> : ' . $reservation->getPack()->getPeriode()->getNombreInscription());
     }
     return $this->render('BackVoyageOrganiseBundle:reservation:validation.html.twig', array('reservation' => $reservation, 'form' => $form->createView(), 'pieces' => $pieces));
 }
Пример #2
0
 public function validerAction(MaritimeReservation $reservation)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $request = $this->getRequest();
     $session = $this->getRequest()->getSession();
     $pieces = $em->getRepository('BackCommercialBundle:Piece')->findBy(array('client' => $reservation->getClient(), 'regle' => FALSE));
     if ($user->getId() != $reservation->getResponsable()->getId() || $reservation->getEtat() == 2) {
         return $this->redirect($this->generateUrl("back_maritime_reservation_consultation", array('id' => $reservation->getId())));
     }
     $form = $this->createFormBuilder()->add("piece", new PieceType());
     foreach ($pieces as $piece) {
         $form->add('piece' . $piece->getId(), 'checkbox', array('label' => $piece->getNumero(), 'required' => FALSE));
     }
     $form = $form->getForm();
     if ($request->isMethod("POST")) {
         $form->submit($request);
         $data = $form->getData();
         foreach ($pieces as $piece) {
             if ($data['piece' . $piece->getId()] && $reservation->getMontantRestant() > 0) {
                 $reglement = new Reglement();
                 if ($piece->getMontant() <= $reservation->getMontantRestant()) {
                     $reglement->setMontant($piece->getMontant());
                     $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                 } else {
                     $reglement->setMontant($reservation->getMontantRestant());
                     $em->persist($piece->setMontant($piece->getMontant() - $reservation->getMontantRestant()));
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservationMaritime($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
             }
         }
         if ($reservation->getMontantRestant() > 0 && !is_null($data['piece']->getModeReglement()) && !is_null($data['piece']->getMontantOrigine())) {
             if ($data['piece']->getMontantOrigine() > 0) {
                 $reglement = new Reglement();
                 $piece = $data['piece'];
                 $piece->setClient($reservation->getClient())->setDateCreation(new \DateTime());
                 if ($piece->getMontantOrigine() <= $reservation->getMontantRestant()) {
                     $reglement->setMontant($piece->getMontantOrigine());
                     $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                 } else {
                     $reglement->setMontant($reservation->getMontantRestant());
                     $em->persist($piece->setRegle(FALSE)->setMontant($piece->getMontantOrigine() - $reservation->getMontantRestant()));
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservationMaritime($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
                 $session->getFlashBag()->add('success', "Votre piéce a été ajoutée avec succès");
             } else {
                 $session->getFlashBag()->add('danger', "Le montant de la piéce doit étre suppérieure à 0");
             }
         }
         if ($reservation->getMontantRestant() == 0) {
             $em->persist($reservation->setEtat(2)->setValidated(new \DateTime()));
             $em->flush();
             $session->getFlashBag()->add('success', " Votre Réservation a été validée avec succès ");
             $this->container->get('mailerservice')->validation($reservation, 'M');
             return $this->redirect($this->generateUrl("back_maritime_reservation_consultation", array('id' => $reservation->getId())));
         } else {
             $session->getFlashBag()->add('info', " Votre Réservation n'a pas été encore validée, reste encore <strong>" . $reservation->getMontantRestant() . " DT </strong> a payé");
         }
         $em->flush();
         return $this->redirect($this->generateUrl("back_maritime_reservation_validation", array('id' => $reservation->getId())));
     }
     return $this->render('BackBilletterieMaritimeBundle:maritime:validation.html.twig', array('reservation' => $reservation, 'form' => $form->createView(), 'pieces' => $pieces));
 }
Пример #3
0
 public function validerAction(Reservation $reservation)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $request = $this->getRequest();
     $session = $this->getRequest()->getSession();
     $pieces = $em->getRepository('BackCommercialBundle:Piece')->findBy(array('client' => $reservation->getClient(), 'regle' => FALSE));
     if ($user->getId() != $reservation->getResponsable()->getId() || $reservation->getEtat() == 2) {
         return $this->redirect($this->generateUrl("consulter_reservation", array('id' => $reservation->getId())));
     }
     $form = $this->createFormBuilder()->add("piece", new PieceType());
     foreach ($pieces as $piece) {
         $form->add('piece' . $piece->getId(), 'checkbox', array('label' => $piece->getNumero(), 'required' => FALSE));
     }
     $form = $form->getForm();
     if ($request->isMethod("POST")) {
         $form->submit($request);
         $data = $form->getData();
         foreach ($pieces as $piece) {
             if ($data['piece' . $piece->getId()] && ($reservation->getSurDemande() || $reservation->getMontantRestant() > 0)) {
                 $reglement = new Reglement();
                 if ($reservation->getSurDemande()) {
                     $reglement->setMontant($piece->getMontant());
                     $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                 } else {
                     if ($piece->getMontant() <= $reservation->getMontantRestant()) {
                         $reglement->setMontant($piece->getMontant());
                         $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                     } else {
                         $reglement->setMontant($reservation->getMontantRestant());
                         $em->persist($piece->setMontant($piece->getMontant() - $reservation->getMontantRestant()));
                     }
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservation($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
             }
         }
         if (($reservation->getSurDemande() || $reservation->getMontantRestant() > 0) && !is_null($data['piece']->getModeReglement()) && !is_null($data['piece']->getMontantOrigine())) {
             if ($data['piece']->getMontantOrigine() > 0) {
                 $reglement = new Reglement();
                 $piece = $data['piece'];
                 $piece->setClient($reservation->getClient())->setDateCreation(new \DateTime());
                 if ($reservation->getSurDemande()) {
                     $reglement->setMontant($piece->getMontantOrigine());
                     $em->persist($piece->setRegle(TRUE)->setMontant(0)->setDateReglement(new \DateTime()));
                 } else {
                     if ($piece->getMontantOrigine() <= $reservation->getMontantRestant()) {
                         $reglement->setMontant($piece->getMontantOrigine());
                         $em->persist($piece->setRegle(TRUE)->setDateReglement(new \DateTime())->setMontant(0));
                     } else {
                         $reglement->setMontant($reservation->getMontantRestant());
                         $em->persist($piece->setRegle(FALSE)->setMontant($piece->getMontantOrigine() - $reservation->getMontantRestant()));
                     }
                 }
                 $reglement->setPiece($piece);
                 $reglement->setReservation($reservation);
                 $reglement->setDateCreation(new \DateTime());
                 $em->persist($reglement);
                 $reservation->addReglement($reglement);
                 $session->getFlashBag()->add('success', "Votre piéce a été ajoutée avec succès");
             } else {
                 $session->getFlashBag()->add('danger', "Le montant de la piéce doit étre suppérieure à 0");
             }
         }
         if ($reservation->getSurDemande() || $reservation->getMontantRestant() == 0) {
             if (!is_null($reservation->getClient()->getAmicale())) {
                 if ($reservation->getClient()->getAmicale()->getMontant() + $reservation->getTotal() > $reservation->getClient()->getAmicale()->getPlafond()) {
                     $session->getFlashBag()->add('warning', "Impossible de valider la réservation pour l'amicale " . $reservation->getClient()->getAmicale()->getLibelle() . "  Plafond insuffisant.   <br>Palfond : " . $reservation->getClient()->getAmicale()->getPlafond() . " DT et le  montant courrant est :" . $reservation->getClient()->getAmicale()->getMontant() . " DT");
                     return $this->redirect($this->generateUrl("valider_reservation", array('id' => $reservation->getId())));
                 }
                 $em->persist($reservation->getClient()->getAmicale()->setMontant($reservation->getClient()->getAmicale()->getMontant() + $reservation->getTotal()));
             }
             $em->persist($reservation->setEtat(2)->setValidated(new \DateTime())->setCode($this->container->get('reservation')->getCode()));
             $em->flush();
             $session->getFlashBag()->add('success', " Votre Réservation a été validée avec succès ");
             $this->container->get('mailerservice')->validation($reservation, 'SHT');
             return $this->redirect($this->generateUrl("consulter_reservation", array('id' => $reservation->getId())));
         } else {
             $session->getFlashBag()->add('info', " Votre Réservation n'a pas été encore validée, reste encore <strong>" . $reservation->getMontantRestant() . " DT </strong> à payer");
         }
         $em->flush();
         return $this->redirect($this->generateUrl("valider_reservation", array('id' => $reservation->getId())));
     }
     return $this->render('BackHotelTunisieBundle:Reservation:validation.html.twig', array('reservation' => $reservation, 'form' => $form->createView(), 'pieces' => $pieces));
 }