Example #1
0
 protected function setOrderDetails($wcOrder, $order, $timezone, $em)
 {
     foreach ($wcOrder['line_items'] as $lineItem) {
         $product = $em->getRepository('MeVisaERPBundle:Products')->findOneBy(array('wcId' => $lineItem['product_id']));
         if (!$product) {
             $product = new Products();
             $product->setEnabled(true);
             $product->setName($lineItem['name']);
             $product->setWcId($lineItem['product_id']);
             $product->setRequiredDocuments(array());
             $productPrice = new ProductPrices();
             $productPrice->setCost(0);
             $productPrice->setPrice($lineItem['price'] * 100);
             $product->addPricing($productPrice);
             $em->persist($product);
         }
         $orderProduct = new OrderProducts();
         $orderProduct->setProduct($product);
         $orderProduct->setQuantity($lineItem['quantity']);
         $orderProduct->setUnitPrice($lineItem['price'] * 100);
         $orderProduct->setTotal($lineItem['total'] * 100);
         $order->addOrderProduct($orderProduct);
         $order->setPeople($lineItem['meta'][0]['value']);
         $order->setDeparture(\DateTime::createFromFormat("d/m/Y", $lineItem['meta'][4]['value'], $timezone));
         $order->setArrival(\DateTime::createFromFormat("d/m/Y", $lineItem['meta'][5]['value']), $timezone);
         //FIXME: check available docs first
         $docs = explode(',', $lineItem['meta'][6]['value']);
         foreach ($docs as $doc) {
             $document = new \MeVisa\ERPBundle\Entity\OrderDocuments();
             $document->setName($doc);
             // http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/3975-915-img_9996.jpg
             $document->setPath('http://www.mevisa.ru/wp-content/uploads/product_files/confirmed/' . $wcOrder['order_number'] . '-' . $lineItem['product_id'] . '-' . $doc);
             $order->addOrderDocument($document);
         }
     }
     $orderPayment = new OrderPayments();
     // method_id method_title
     $orderPayment->setMethod($wcOrder['payment_details']['method_id']);
     $orderPayment->setAmount($wcOrder['total'] * 100);
     $orderPayment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
     if ("true" == $wcOrder['payment_details']['paid']) {
         $orderPayment->setState("paid");
     } else {
         $orderPayment->setState("not_paid");
     }
     $order->addOrderPayment($orderPayment);
     if ("" != $wcOrder['note']) {
         $orderComment = new OrderComments();
         $orderComment->setComment($wcOrder['note'] . "-- Customer: " . $order->getCustomer()->getName());
         $orderComment->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
         $order->addOrderComment($orderComment);
     }
     $order->setNumber($wcOrder['order_number']);
     $order->setWcId($wcOrder['order_number']);
     //FIXME: Dynamic channel
     $order->setChannel("MeVisa.ru");
     $order->setAdjustmentTotal($wcOrder['total_discount'] * 100);
     $order->setProductsTotal($wcOrder['subtotal'] * 100);
     $order->setTotal($wcOrder['total'] * 100);
     $order->setState($wcOrder['status']);
     $order->setCreatedAt(new \DateTime($wcOrder['created_at'], $timezone));
 }
Example #2
0
 protected function setOrderDetails($modxOrder, $order, $timezone, $em)
 {
     $order->setWcId($modxOrder['id']);
     $order->setNumber('UV' . $modxOrder['id']);
     $order->setCreatedAt(new \DateTime($modxOrder['createdon'], $timezone));
     $order->setState("backoffice");
     $order->setPeople($modxOrder['kolchel']);
     $order->setTotal($modxOrder['cost'] * 100);
     $order->setProductsTotal($modxOrder['cost'] * 100);
     $order->setAdjustmentTotal(0);
     $product = $em->getRepository('MeVisaERPBundle:Products')->findOneBy(array('name' => $modxOrder['namezakaz']));
     if (!$product) {
         $product = new Products();
         $product->setEnabled(true);
         $product->setName($modxOrder['namezakaz']);
         $product->setRequiredDocuments(array());
         $product->setUrgent(false);
         $productPrice = new ProductPrices();
         $productPrice->setCost(0);
         $productPrice->setPrice($modxOrder['cost'] * 100 / $modxOrder['kolchel']);
         $product->addPricing($productPrice);
         $em->persist($product);
     }
     $productPrice = $product->getPricing()->last();
     $orderProduct = new OrderProducts();
     $orderProduct->setProduct($product);
     $orderProduct->setQuantity($modxOrder['kolchel']);
     $orderProduct->setUnitPrice($modxOrder['cost'] * 100 / $modxOrder['kolchel']);
     $orderProduct->setUnitCost($productPrice->getCost());
     $orderProduct->setVendor($product->getVendor());
     $orderProduct->setTotal($modxOrder['cost'] * 100);
     $order->addOrderProduct($orderProduct);
     $order->setPeople($modxOrder['kolchel']);
     $arrival = \DateTime::createFromFormat('Y-m-d G:i:s', $modxOrder['datet'], $timezone);
     if ($arrival) {
         $order->setArrival($arrival);
     } else {
         //TODO: Report issue
         dump('Invalid arrival for Order: ' . $order->getNumber());
     }
     $departure = \DateTime::createFromFormat("Y-m-d G:i:s", $modxOrder['dateo'], $timezone);
     if ($departure) {
         $order->setDeparture($departure);
     } else {
         //TODO: Report issue
         dump('Invalid departure for Order: ' . $order->getNumber());
     }
     $accessBasePath = 'http://uaevisa.ru/assets/uploads/';
     $uploadBasePath = $this->getContainer()->getParameter('uaevc_path');
     $fs = new Filesystem();
     if ($fs->exists($uploadBasePath . $order->getWcId())) {
         $finder = new Finder();
         $finder->files()->in($uploadBasePath . $order->getWcId());
         foreach ($finder as $file) {
             $document = new \MeVisa\ERPBundle\Entity\OrderDocuments();
             $document->setName($file->getFileName());
             // http://uaevisa.ru/assets/uploads/74/0/contact_pasp_2016-09-06_12-54-15.png
             $document->setPath($accessBasePath . $order->getWcId() . '/' . $file->getRelativePathname());
             $order->addOrderDocument($document);
         }
     }
     $orderPayment = new OrderPayments();
     // method_id method_title
     $orderPayment->setMethod('payu');
     $orderPayment->setAmount($modxOrder['cost'] * 100);
     $orderPayment->setCreatedAt(new \DateTime($modxOrder['editedon'], $timezone));
     if (1 == $modxOrder['active']) {
         $orderPayment->setState("paid");
     } else {
         $orderPayment->setState("not_paid");
     }
     $order->addOrderPayment($orderPayment);
     if ("" != $modxOrder['description']) {
         $orderComment = new OrderComments();
         $orderComment->setComment($modxOrder['note'] . "-- Customer: " . $order->getCustomer()->getName());
         $orderComment->setCreatedAt(new \DateTime($modxOrder['created_at'], $timezone));
         $order->addOrderComment($orderComment);
     }
     if ("" != $modxOrder["name1"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name1"] . $modxOrder["famil1"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name2"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name2"] . $modxOrder["famil2"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name3"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name3"] . $modxOrder["famil3"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name4"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name4"] . $modxOrder["famil4"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name5"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name5"] . $modxOrder["famil5"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name6"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name6"] . $modxOrder["famil6"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name7"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name7"] . $modxOrder["famil7"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name8"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name8"] . $modxOrder["famil8"]);
         $order->addOrderCompanion($orderCompanion);
     }
     if ("" != $modxOrder["name9"]) {
         $orderCompanion = new OrderCompanions();
         $orderCompanion->setName($modxOrder["name9"] . $modxOrder["famil9"]);
         $order->addOrderCompanion($orderCompanion);
     }
     //FIXME: Dynamic channel
     $order->setChannel("uaevisa.ru");
     $order->setTicketRequired(false);
 }
Example #3
0
 /**
  * Add comments
  *
  * @param \MeVisa\ERPBundle\Entity\OrderComments $comments
  * @return User
  */
 public function addComment(\MeVisa\ERPBundle\Entity\OrderComments $comments)
 {
     $this->comments[] = $comments;
     $comments->setAuthor($this);
     return $this;
 }
Example #4
0
 public function updateOrderNotes($em, $order, $wcOrderNotes)
 {
     $timezone = new \DateTimeZone('UTC');
     foreach ($wcOrderNotes as $note) {
         $ExistingOrderComment = $em->getRepository('MeVisaERPBundle:OrderComments')->findOneBy(array('wcId' => $note['id']));
         if (!$ExistingOrderComment) {
             $orderComment = new OrderComments();
             $orderComment->setWcId($note['id']);
             if ($note['customer_note']) {
                 $orderComment->setComment($note['note'] . "-- Customer: " . $order->getCustomer()->getName());
             } else {
                 $orderComment->setComment($note['note']);
             }
             $orderComment->setCreatedAt(new \DateTime($note['created_at'], $timezone));
             $order->addOrderComment($orderComment);
         }
     }
 }
Example #5
0
 /**
  * Add orderComments
  *
  * @param \MeVisa\ERPBundle\Entity\OrderComments $orderComments
  * @return Orders
  */
 public function addOrderComment(\MeVisa\ERPBundle\Entity\OrderComments $orderComments)
 {
     $this->orderComments[] = $orderComments;
     $orderComments->setOrderRef($this);
     return $this;
 }
Example #6
0
 /**
  * Creates a form to update a Orders Status entity.
  *
  * @param Orders $entity The entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createCommentForm(\MeVisa\ERPBundle\Entity\OrderComments $entity)
 {
     $form = $this->createFormBuilder()->setAction($this->generateUrl('orders_comments_new', array('id' => $entity->getOrderRef())))->setMethod('POST');
     $form->add('comment', 'textarea', array('data' => $entity->getComment(), 'required' => true, 'label' => false));
     $form->add('save', 'submit', array('label' => false, 'attr' => array('class' => 'pull-right btn-default')));
     return $form->getForm();
 }