/**
  * @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'));
 }
 public function gettabs($id)
 {
     $entity = $this->getDoctrine()->getRepository('SoftoneBundle:Product')->find($id);
     if ($id == 0 and @$entity->id == 0) {
         $entity = new Product();
     }
     $customer = $this->getDoctrine()->getRepository('SoftoneBundle:Customer')->find(1);
     echo $entity->getGroupedDiscount($customer);
     $entity->updatetecdoc();
     $fields["title"] = array("label" => "Title", "required" => true, "className" => "col-md-6 col-sm-6");
     $fields["erpCode"] = array("label" => "Erp Code", "required" => true, "className" => "col-md-6 col-sm-6");
     $fields["tecdocSupplierId"] = array("label" => "Tecdoc Supplier", "required" => true, "className" => "col-md-6", 'type' => "select", 'datasource' => array('repository' => 'SoftoneBundle:TecdocSupplier', 'name' => 'supplier', 'value' => 'id'));
     $fields["tecdocCode"] = array("label" => "Tecdoc Code", "required" => true, "className" => "col-md-6");
     $fields["supplierId"] = array("label" => "Supplier", "className" => "col-md-6", 'type' => "select", "required" => true, 'datasource' => array('repository' => 'SoftoneBundle:SoftoneSupplier', 'name' => 'title', 'value' => 'id'));
     $fields["supplierCode"] = array("label" => "Supplier Code", "className" => "col-md-6", "required" => true);
     $fields["itemPricew"] = array("label" => "Wholesale Price", "className" => "col-md-3", "required" => true);
     $fields["itemPricer"] = array("label" => "Retail Price", "className" => "col-md-3", "required" => true);
     $fields["itemMarkupw"] = array("label" => "Wholesale Markup", "className" => "col-md-3", "required" => true);
     $fields["itemMarkupr"] = array("label" => "Retail Markup", "className" => "col-md-3", "required" => true);
     $forms = $this->getFormLyFields($entity, $fields);
     if ($id > 0 and count($entity) > 0) {
         $entity2 = $this->getDoctrine()->getRepository('SoftoneBundle:Product')->find($id);
         $entity2->setReference("");
         $fields2["reference"] = array("label" => "Erp Code", "className" => "synafiacode col-md-12");
         $forms2 = $this->getFormLyFields($entity2, $fields2);
         $dtparams[] = array("name" => "ID", "index" => 'id', "active" => "active");
         $dtparams[] = array("name" => "Title", "index" => 'title');
         $dtparams[] = array("name" => "Code", "index" => 'erpCode');
         $dtparams[] = array("name" => "Price", "index" => 'itemPricew01');
         $params['dtparams'] = $dtparams;
         $params['id'] = $dtparams;
         $params['url'] = '/product/getrelation/' . $id;
         $params['key'] = 'gettabs_' . $id;
         $params["ctrl"] = 'ctrlgettabs';
         $params["app"] = 'appgettabs';
         $datatables[] = $this->contentDatatable($params);
     }
     $tabs[] = array("title" => "General", "datatables" => array(), "form" => $forms, "content" => '', "index" => $this->generateRandomString(), 'search' => 'text', "active" => true);
     if ($id > 0 and count($entity) > 0) {
         $tabs[] = array("title" => "Retaltions", "datatables" => $datatables, "form" => $forms2, "content" => '', "index" => $this->generateRandomString(), 'search' => 'text', "active" => true);
     }
     foreach ($tabs as $tab) {
         $this->addTab($tab);
     }
     $json = $this->tabs();
     return $json;
 }