Exemplo n.º 1
0
 public function setOrderDetails($order)
 {
     /* Auto assign details */
     $order = $this->stateEffect($order);
     //        $wcId;
     //        $updatedAt;
     //        $postedAt;
     //        $deletedAt;
     //        $completedAt;
     /* Order Customer */
     $this->setCustomer($order);
     /* Order Details */
     // TODO: State machine
     //        $productsTotal;
     //        $adjustmentTotal;
     //        $total;
     //        $people;
     //        $arrival;
     //        $departure;
     /* Order Products */
     $orderProducts = $order->getOrderProducts();
     foreach ($orderProducts as $orderProduct) {
         if (empty($orderProduct->getId())) {
             $productPrice = $orderProduct->getProduct()->getPricing()->last();
             $orderProduct->setUnitCost($productPrice->getCost());
             $order->addOrderProduct($orderProduct);
         }
     }
     /* Order Payments */
     $orderPayments = $order->getOrderPayments();
     foreach ($orderPayments as $payment) {
         if ("paid" == $payment->getState()) {
             $payment->setCreatedAt(new \DateTime());
         }
         if (empty($payment->getId())) {
             $order->addOrderPayment($payment);
         }
     }
     /* Order Companions */
     $orderCompanions = $order->getOrderCompanions();
     // TODO: Check Order Companions
     foreach ($orderCompanions as $companion) {
         $order->addOrderCompanion($companion);
     }
     /* Order Docs */
     $orderDocuments = $order->getOrderDocuments();
     foreach ($orderDocuments as $document) {
         if (empty($document->getId())) {
             $order->addOrderDocument($document);
         }
     }
     /* Order Notes */
     $orderComments = $order->getOrderComments();
     foreach ($orderComments as $comment) {
         if (empty($comment->getId())) {
             if (null == $comment->getComment() || "" == trim($comment->getComment())) {
                 $order->removeOrderComment($comment);
                 $this->em->remove($comment);
             } else {
                 $newComment = new \MeVisa\ERPBundle\Entity\OrderComments();
                 $newComment->setCreatedAt(new \DateTime());
                 $newComment->setComment($comment->getComment());
                 $this->securityContext->getToken()->getUser()->addComment($newComment);
                 $order->addOrderComment($newComment);
             }
         } else {
             $this->em->refresh($comment);
         }
     }
     /* Order Invoice */
     $invoices = $order->getInvoices();
     foreach ($invoices as $invoice) {
         if (empty($invoice->getId())) {
             $order->addInvoice($invoice);
         }
     }
     /* Order Receipt */
 }
Exemplo n.º 2
0
 /**
  * Edits an existing Orders entity.
  *
  * @Route("/{id}/companion_status", name="orders_companion_status_update")
  * @Method("PUT")
  * @Template("MeVisaERPBundle:Orders:show.html.twig")
  */
 public function updateCompanionStateAction(Request $request, $id)
 {
     $order = $this->get('erp.order')->getOrder($id);
     if (!$order) {
         throw $this->createNotFoundException('Unable to find Orders entity.');
     }
     $em = $this->getDoctrine()->getManager();
     $companionForm = $this->createCompanionSatausForm($order);
     $companionForm->handleRequest($request);
     if ($companionForm->isSubmitted()) {
         if ($companionForm->isValid()) {
             if (empty($order->getUpdatedAt())) {
                 $order->setUpdatedAt(new \DateTime());
             }
             $orderComplete = true;
             $companions = $order->getOrderCompanions();
             foreach ($companions as $companion) {
                 if (!$companion->getState()) {
                     $orderComplete = false;
                 }
             }
             if ($orderComplete) {
                 $order->setState($order->getOrderCompanions()->first()->getState());
             }
             $this->get('erp.order')->stateEffect($order);
             $em->flush();
             return $this->redirect($this->generateUrl('orders_show', array('id' => $id)));
         }
     }
     $orderComment = new \MeVisa\ERPBundle\Entity\OrderComments();
     $orderComment->setOrderRef($order->getId());
     return array('order' => $order, 'logs' => $this->get('erp.order')->getOrderLog($id), 'documents' => $this->getThumbnails($order), 'status_form' => $this->createStatusForm($order)->createView(), 'comment_form' => $this->createCommentForm($orderComment)->createView(), 'companions_form' => $companionForm->createView());
 }