예제 #1
0
 /**
  * Displays a form to create a new Orders entity.
  *
  * @Route("/new", name="orders_new")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function newAction(Request $request)
 {
     $order = new Orders();
     $order->setChannel('POS');
     $order->setState('backoffice');
     $order->setCreatedAt(new \DateTime("now"));
     //Generate Form
     $form = $this->createForm(new OrdersType(), $order, array('action' => $this->generateUrl('orders_new'), 'method' => 'POST'));
     $form->add('save', 'submit', array('label' => null, 'attr' => array('class' => 'btn-success pull-right')));
     //Handle Form
     $form->handleRequest($request);
     if ($form->isSubmitted()) {
         if ($form->isValid()) {
             //Validations
             // Arrival & Departure
             // Post & arrival
             // at least1 Order Product
             $orderProducts = $order->getOrderProducts();
             if ($orderProducts->count() < 1) {
                 $this->addFlash('error', 'Order must have at least 1 product');
             }
             // 1 Person travelling
             $this->get('erp.order')->createNewPOSOrder($order);
             return $this->redirect($this->generateUrl('orders_show', array('id' => $order->getId())));
         }
     }
     return array('order' => $order, 'productPrices' => $this->getAvailableProducts(), 'form' => $form->createView());
 }