Exemplo n.º 1
0
 /**
  * Creates a new LigneDQE entity.
  *
  */
 public function createAction(Request $request, $daoId, $consistanceId)
 {
     $form = $this->createCreateForm($daoId, $consistanceId);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $data = $form->getData();
         $affectationPrix = new AffectationPrix();
         $ligne = new LigneDQE();
         $marche = $em->getRepository("LaisoArmBundle:Marche")->findOneBy(array("lotissement" => $daoId));
         $avenants = $em->getRepository("LaisoArmBundle:Avenant")->findBy(array('marche' => $marche->getId()));
         $affectationPrix->setSerie($data['prix']);
         $affectationPrix->setConsistance($em->getRepository("LaisoArmBundle:Consistance")->find($consistanceId));
         $ligne->setQuantite($data['quantite']);
         $ligne->setPrix($affectationPrix);
         $ligne->setAvenant($avenants[0]);
         $em->persist($affectationPrix);
         $em->persist($ligne);
         $em->flush();
         if (null != $request->query->get('returnUrl')) {
             return $this->redirect($request->query->get('returnUrl'));
         }
         if ($request->isXmlHttpRequest()) {
             return $this->redirect($this->generateUrl('dao_show', array('id' => $daoId, 'action' => 'dqe')));
         }
         return $this->redirect($this->generateUrl('dao_show', array('id' => $daoId)));
     }
     return $this->render('LaisoArmBundle:LigneDQE:new.html.twig', array('form' => $form->createView()));
 }
Exemplo n.º 2
0
 /**
  * 
  * @param Request $request
  * @param $marcheId
  * @param $consistance
  * @param $numero
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function createLigneAction(Request $request, $marcheId, $consistance, $numero)
 {
     $em = $this->getDoctrine()->getManager();
     $avenant = $em->getRepository('LaisoArmBundle:Avenant')->findOneBy(array('marche' => $marcheId, 'libelle' => $em->getRepository('LaisoArmBundle:LibelleAvenant')->findOneBy(array('numero' => $numero))));
     $form = $this->createDqeCreateForm($avenant, $consistance, $request->query->get('returnUrl'));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $ligneDqe = $form->getData();
         $serie = $ligneDqe->getPrix();
         $do = true;
         foreach ($avenant->getLignes() as $dqe) {
             if ($dqe->getPrix()->getSerie()->getId() == $serie->getId()) {
                 $do = false;
                 break;
             }
         }
         if ($do) {
             $affectationPrix = new AffectationPrix();
             $affectationPrix->setConsistance($em->getRepository('LaisoArmBundle:Consistance')->find($consistance));
             $affectationPrix->setPrixUnitaire($serie->getPrixUnitaire());
             $affectationPrix->setSerie($serie->getSerie());
             $ligne = new LigneDQE();
             $ligne->setAvenant($avenant);
             $ligne->setQuantite($ligneDqe->getQuantite());
             $ligne->setPrix($affectationPrix);
             $em->persist($affectationPrix);
             $em->persist($ligne);
             $em->flush();
             return $this->redirect($this->generateUrl('avenant_show', array('numero' => $numero, 'marcheId' => $marcheId)));
         }
     }
     return $this->render('LaisoArmBundle:Avenant:new_ligne.html.twig', array('form' => $form->createView()));
 }