/**
  * @Route("/product/createProduct")
  */
 public function createProductAction(Request $request)
 {
     $json = json_encode(array("ok"));
     $asd = $this->getArticlesSearchByIds($request->request->get("ref"));
     $asd = $asd[0];
     $json = json_encode($asd);
     $em = $this->getDoctrine();
     $SoftoneSupplier = $this->getDoctrine()->getRepository("SoftoneBundle:SoftoneSupplier")->findOneBy(array('title' => $asd->brandName));
     //echo $asd->brandName . " " . @(int) $SoftoneSupplier->id;
     if (@$SoftoneSupplier->id == 0) {
         $TecdocSupplier = $em->getRepository("SoftoneBundle:TecdocSupplier")->findOneBy(array('supplier' => $asd->brandName));
         if (@$TecdocSupplier->id == 0) {
             $SoftoneSupplier = new \SoftoneBundle\Entity\SoftoneSupplier();
             $SoftoneSupplier->setTitle($asd->brandName);
             $SoftoneSupplier->setCode(' ');
             @$this->flushpersist($SoftoneSupplier);
             $SoftoneSupplier->setCode("S" . $SoftoneSupplier->getId());
             @$this->flushpersist($SoftoneSupplier);
             $SoftoneSupplier->toSoftone();
         } else {
             $SoftoneSupplier = new \SoftoneBundle\Entity\SoftoneSupplier();
             $SoftoneSupplier->setTitle($TecdocSupplier->getSupplier());
             $SoftoneSupplier->setCode("T" . $TecdocSupplier->id);
             @$this->flushpersist($SoftoneSupplier);
             $SoftoneSupplier->toSoftone();
         }
     } else {
     }
     $TecdocSupplier = $em->getRepository("SoftoneBundle:TecdocSupplier")->findOneBy(array('supplier' => $asd->brandName));
     $erpCode = $this->clearstring($asd->articleNo) . "-" . $SoftoneSupplier->getCode();
     $product = $em->getRepository("SoftoneBundle:Product")->findOneBy(array('erpCode' => $erpCode));
     $json = array("error" => 1);
     if (@$product->id > 0) {
         $json = json_encode(array("error" => 0, "id" => (int) $product->id, 'returnurl' => '/product/view/' . (int) $product->id));
         return new Response($json, 200, array('Content-Type' => 'application/json'));
     }
     $dt = new \DateTime("now");
     $product = new \SoftoneBundle\Entity\Product();
     $product->setSupplierCode($asd->articleNo);
     $product->setTitle($asd->genericArticleName);
     $product->setTecdocCode($asd->articleNo);
     $product->setItemMtrmark($TecdocSupplier->getId());
     $product->setTecdocSupplierId($TecdocSupplier);
     $product->setSupplierId($SoftoneSupplier);
     $product->setItemName($asd->genericArticleName);
     $product->setTecdocArticleId($asd->articleId);
     //$product->setItemCode($this->partno);
     $product->setItemApvcode($asd->articleNo);
     $product->setErpSupplier($asd->brand);
     $product->setItemMtrmanfctr($SoftoneSupplier->getId());
     $product->setErpCode($erpCode);
     $product->setItemCode($product->getErpCode());
     $product->setItemV5($dt);
     $product->setTs($dt);
     $product->setItemInsdate($dt);
     $product->setItemUpddate($dt);
     $product->setCreated($dt);
     $product->setModified($dt);
     @$this->flushpersist($product);
     $product->updatetecdoc();
     $product->setProductFreesearch();
     $product->toSoftone();
     $json = json_encode(array("error" => 0, "id" => (int) $product->id, 'returnurl' => '/product/view/' . (int) $product->id));
     return new Response($json, 200, array('Content-Type' => 'application/json'));
 }