public function ligneSuppWeekend(Saison $saison, $arr, $ch, $date, $nuitee) { $saisonWeekend = $saison->getSaisonWeekend(); if (!is_null($saisonWeekend)) { $date = \DateTime::createFromFormat('Y-m-d', $date); if ($nuitee >= $saisonWeekend->getNbNuitMin() && $nuitee <= $saisonWeekend->getNbNuitMax() && ($date->format("w") == 4 && $saisonWeekend->getJeudi() || $date->format("w") == 5 && $saisonWeekend->getVendredi() || $date->format("w") == 6 && $saisonWeekend->getSamedi() || $date->format("w") == 0 && $saisonWeekend->getDimanche())) { foreach ($saisonWeekend->getLignes() as $ligne) { if ($ch == $ligne->getChambre()->getId()) { return array('code' => 'SUPP-REDUC-WEEKEND', 'name' => 'Supp ou reduction Weekend ' . $date->format("l"), 'achat' => $ligne->getReducSuppAchat($arr), 'vente' => $ligne->getReducSuppVente($arr)); } } } } }
public function weekendAction(Saison $saison) { $em = $this->getDoctrine()->getManager(); $session = $this->getRequest()->getSession(); if ($saison->getSaisonWeekend() == NULL) { $saisonWeekend = new SaisonWeekend(); } else { $saisonWeekend = $saison->getSaisonWeekend(); } foreach ($saison->getHotel()->getChambres() as $chambre) { $verif = $em->getRepository("BackHotelTunisieBundle:SaisonWeekendLigne")->findBy(array('saisonWeekend' => $saisonWeekend, 'chambre' => $chambre)); if (count($verif) == 0) { $saisonWeekendLigne = new SaisonWeekendLigne(); $saisonWeekendLigne->setChambre($chambre); $saisonWeekend->addLigne($saisonWeekendLigne); } } $form = $this->createForm(new SaisonWeekendType(), $saisonWeekend); $form->add('lignes', 'collection', array('type' => new SaisonWeekendLigneType($saison->getHotel()->getId()))); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { $saisonWeekend = $form->getData(); $em->persist($saisonWeekend); foreach ($saisonWeekend->getLignes() as $ligne) { $em->persist($ligne->setSaisonWeekend($saisonWeekend)); } $em->persist($saison->setSaisonWeekend($saisonWeekend)); $em->flush(); $session->getFlashBag()->add('success', " Votre saison de base a été modifié avec succées "); return $this->redirect($this->generateUrl("WeekendSaison", array('id' => $saison->getId()))); } } return $this->render("BackHotelTunisieBundle:Saisons:weekend.html.twig", array('saison' => $saison, 'hotel' => $saison->getHotel(), 'form' => $form->createView())); }