Example #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 */
 }