/** * @Route("/examen/new", name="cotizador_examen_new") * @Template() * * @param Request $request * @return array */ public function newExamenAction(Request $request) { try { $user = $this->getCurrenUser(); $seller = $this->getDoctrine()->getManager()->getRepository('TSCYABundle:Seller')->getByUser($user->getId()); $quotation = new Quotation(); $quotation->setClient(new Client()); $quotation->setSeller($seller); $quotation->setType(Quotation::EXAM); $form = $this->createForm(QuotationExamType::class, $quotation); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $quotation = $this->calculateValues($quotation, Quotation::EXAM); $em = $this->getDoctrine()->getManager(); $em->persist($quotation); $em->flush(); $this->setFlashInfo('Registro agregado correctamente'); return $this->redirectToRoute('preview_invoice', ['id' => $quotation->getId()]); } } catch (\Exception $e) { $this->setFlashError(sprintf("Error: %s", $e->getMessage())); return $this->redirectToRoute('main'); } return ['form' => $form->createView()]; }