Ejemplo n.º 1
0
 /**
  * 
  */
 public function getListResultsAction()
 {
     $storage = $this->getStorageService();
     $params = $this->getRequest()->getParams();
     $page = $params['page'];
     $productQuery = ProductQuery::create()->useFileCache()->filter($params);
     $colors = ColorQuery::create()->find();
     $brands = BrandQuery::create()->find();
     $productCollection = $productQuery->find();
     $freightFareCollection = FreightFareQuery::create()->find();
     $freightTypeCollection = FreightTypeQuery::create()->find();
     $customsTariffCodeCollection = CustomsTariffCodeQuery::create()->find();
     $incotermCollection = IncotermQuery::create()->useFileCache()->find();
     $products = $productQuery->findByPage($page, $this->getMaxPerPage());
     // 		if (!$productStorage)
     // 			$storage->saveValue($productQuery->find(), 'products');
     $productPrintingArea = ProductPrintingAreaQuery::create()->addColumn(ProductPrintingArea::ID_PRODUCT)->whereAdd(ProductPrintingArea::ID_PRODUCT, $products->getKeyMother(), ProductPrintingAreaQuery::IN)->fetchCol();
     //
     $arrayProducts = array();
     while ($products->valid()) {
         $product = $products->read();
         $hasPrintingArea = in_array($product->getKeyMother(), $productPrintingArea) ? 1 : 0;
         $arrayProducts[$product->getIndex()] = $product->toArrayForList() + array("has_printing_area" => $hasPrintingArea);
     }
     die(json_encode($arrayProducts));
 }
Ejemplo n.º 2
0
 public function npdKeyAction()
 {
     $this->view->setTpl('Npd-key');
     $this->view->contentTitle = 'NPD Key';
     $idNPDSheet = $this->getRequest()->getParam('id');
     $this->view->productNewKey = $this->getRequest()->getParam('product-new-key');
     if (!empty($idNPDSheet)) {
         $this->view->npdSheet = $npdSheet = NpdSheetQuery::create()->findByPK($idNPDSheet);
     }
     $params = $this->getRequest()->getParams();
     if ($this->getRequest()->isPost()) {
         $this->view->post = $post = $this->getRequest()->getParams();
         $this->view->subGroup = $subFamily = SubfamilyQuery::create()->findByPK($post['id_subfamily']);
         $this->view->family = $family = FamilyQuery::create()->findByPK($post['id_family']);
         $this->view->productGroup = $productGroup = ProductGroupQuery::create()->findByPK($post['id_product_group']);
         $this->view->idPg = $family->getIdFamily();
         $this->view->IdSd = $subFamily->getIdSubfamily();
     } else {
         if (!empty($npdSheet)) {
             if ($npdSheet->getIdSubfamily() > 0) {
                 $this->view->subGroup = $subFamily = SubfamilyQuery::create()->findByPK($npdSheet->getIdSubfamily());
             } else {
                 $this->view->subGroup = $subFamily = new Subfamily();
             }
             $this->view->family = $family = FamilyQuery::create()->findByPK($npdSheet->getIdFamily());
             $this->view->productGroup = $productGroup = ProductGroupQuery::create()->findByPK($family->getIdProductGroup());
             $this->view->idPg = $family->getIdFamily();
             /*if($subFamily > 0){
             		 $idSd = $subFamily->getIdSubfamily();
             		}
             		$this->view->IdSd = $idSd;*/
         }
     }
     // Get Product Groups
     $productGroupQuery = ProductGroupQuery::create();
     $productGroupQuery->where()->setOR();
     $productGroupQuery->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup(), ProductGroupQuery::EQUAL);
     $productGroupCombo = $productGroupQuery->actives()->find()->toCombo();
     $this->view->productGroups = $productGroupCombo;
     // Get Families
     $familyQuery = FamilyQuery::create();
     $familyQuery->where()->setOR();
     $familyQuery->whereAdd(Family::ID_PRODUCT_GROUP, $family->getIdProductGroup(), FamilyQuery::EQUAL);
     $familyQuery->where()->setAND();
     $familyQuery->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup());
     $familyCombo = $familyQuery->actives()->find()->toCombo();
     // Get subgfamilies
     $subfamiliesQuery = SubfamilyQuery::create();
     if ($subFamily->getIdSubfamily() > 0) {
         $subfamiliesQuery->where()->setOR();
         $subfamiliesQuery->whereAdd(Subfamily::ID_SUBFAMILY, $subFamily->getIdSubfamily(), SubfamilyQuery::EQUAL);
         $subfamiliesQuery->where()->setAND();
     }
     $subfamiliesQuery->whereAdd(Family::ID_FAMILY, $family->getIdFamily());
     $subGroupCombo = array("" => "Select Subfamily") + $subfamiliesQuery->actives()->find()->toCombo();
     // Get Colors NPD
     $colorsNpd = ColorQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.' . NpdSheet::ID_NPD_SHEET, $idNPDSheet)->find();
     $productColors = ColorQuery::create()->find()->toCombo();
     $select = array('' => $this->i18n->_('** Select **'));
     $this->view->colors = $select + $colorsNpd->toCombo();
     $this->view->brands = $brands = $select + \Application\Query\BrandQuery::create()->actives()->find()->toCombo();
     $this->view->productColors = $productColors;
     //search families for list products
     $idProductGroup = $this->getRequest()->getParam('id_product_group');
     $clvProductGroup = $this->getRequest()->getParam('clv_family');
     $idCategory = $this->getRequest()->getParam('clv_category');
     $clvSubcategory = $this->getRequest()->getParam('clv_subcategory');
     $clvcomposition = $this->getRequest()->getParam('clv_composition');
     $clvBrand = $this->getRequest()->getParam('clv_brand');
     $clvColor = $this->getRequest()->getParam('clv_color');
     $idColor = $this->getRequest()->getParam('id_color');
     if (isset($clvColor)) {
         $colorCode = $this->i18n->_("Not available");
     } else {
         $colorCode = $clvColor;
     }
     $productsFam = ProductQuery::create()->distinct()->addColumns(array('Product.' . Product::ID_PRODUCT_GROUP, 'ProductGroup.' . ProductGroup::CODE))->innerJoinProductGroup()->addAscendingOrderBy('Product.' . Product::ID_PRODUCT_GROUP)->fetchAll();
     foreach ($productsFam as $i => $productFam) {
         if ($productsFam[$i]["id_product_group"] == $idProductGroup) {
             $productGroupIds = array("prevFamily" => $productsFam[$i - 1]["id_product_group"], "productFamily" => $productsFam[$i]["id_product_group"], "nextFamily" => $productsFam[$i + 1]["id_product_group"]);
         }
     }
     $wantedProducts = ProductQuery::create();
     $wantedProducts->where()->setOR();
     $seachProducts = $wantedProducts->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['productFamily'])->addColumns(array('Product.' . Product::ITEM_CODE, 'Product.' . Product::ITEM_NAME, 'Product.' . Product::STATUS, 'Product.' . Product::KEY_MOTHER, 'Product.' . Product::ID_COLOR))->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['prevFamily'])->whereAdd('Product.' . Product::ID_PRODUCT_GROUP, $productGroupIds['nextFamily'])->fetchAll();
     $newProduct = array(array('item_code' => $clvProductGroup . $idCategory . $clvSubcategory . $clvcomposition . $clvBrand . $clvColor, 'item_name' => $npdSheet->getName(), 'status' => 'H', 'key_mother' => $clvProductGroup . $idCategory . $clvSubcategory . $clvcomposition, 'id_color' => $colorCode));
     //order total products
     $products = array_merge($seachProducts, $newProduct);
     array_multisort($products);
     //save index new product
     foreach ($products as $key => $val) {
         if ($newProduct[0]['item_code'] == $val['item_code']) {
             $index = $key;
         }
     }
     $parentKeys = ProductQuery::create()->whereAdd(Product::KEY_MOTHER, $newProduct[0]['key_mother'])->find()->count();
     $idSupplierAut = SupplierBudgetQuery::create()->innerJoinNpdSheetSupplier()->addColumn(NpdSheetSupplier::ID_SUPPLIER)->whereAdd('NpdSheetSupplier.' . NpdSheetSupplier::ID_NPD_SHEET, $idNPDSheet)->whereAdd('SupplierBudget.' . SupplierBudget::IS_AUTHORIZED, 1)->fetchAll();
     // die(print_r($idSupplierAut));
     if ($idSupplierAut) {
         $currency = CurrencyQuery::create()->whereAdd(Currency::ID_CURRENCY, SapSupplierQuery::create()->findByPK($idSupplierAut[0]['id_supplier'])->getIdCurrency())->findOne();
     } else {
         $this->setFlash('error', $this->i18n->_("there is no authorized supplier"));
         return $this->getHelper('redirector')->goto('list');
     }
     $this->view->new = $newProduct[0]['key_mother'];
     $this->view->families = $familyCombo;
     $this->view->subgroups = $subGroupCombo;
     $this->view->products = $products;
     $this->view->index = $index;
     $this->view->parentKeys = $parentKeys;
     $this->view->supplier = $idSupplierAut[0]['id_supplier'];
     $this->view->currency = $currency->getName();
 }
Ejemplo n.º 3
0
 /**
  * @return json
  */
 public function getListResultsAction()
 {
     $params = $this->getRequest()->getParams();
     $brands = BrandQuery::create()->filter($params)->findByPage($params['page'], $this->getMaxPerPage());
     die(json_encode($brands->toArray()));
 }
Ejemplo n.º 4
0
 /**
  *
  * Gets all Products from SAP, searches the DB for the itemcode, then updates or creates
  */
 public function syncProductsAction()
 {
     $r = SapProductQuery::create()->whereAdd(SapProduct::INVNTITEM, "Y")->find();
     $errors = 0;
     $new = 0;
     $updated = 0;
     echo "<pre>";
     echo "Name, itemcode, clave madre, resultado, mensaje \n";
     while ($r->valid()) {
         $save = 0;
         $sapProduct = $r->read();
         echo "\"" . trim($sapProduct->getItemname()) . "\", " . $sapProduct->getItemcode() . ", " . $sapProduct->getUMadre9() . ", ";
         if (strlen($sapProduct->getItemcode()) != 11) {
             echo "1, Error! ItemCode invalido: len " . strlen($sapProduct->getItemcode()) . "\n";
             $errors++;
             continue;
         }
         $product = ProductQuery::create()->whereAdd(Product::ITEM_CODE, $sapProduct->getItemcode(), ProductQuery::EQUAL)->findOne();
         if (!$product instanceof Product) {
             $product = new Product();
             $save = 1;
         }
         $brand = BrandQuery::create()->whereAdd(Brand::CODE, substr($sapProduct->getItemcode(), 7, 2))->findOne();
         if (!$brand instanceof Brand) {
             echo "2, Error! No Brand: " . substr($sapProduct->getItemcode(), 7, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdBrand($brand->getIdBrand());
         $color = ColorQuery::create()->whereAdd(Color::CODE, substr($sapProduct->getItemcode(), 9, 2))->findOne();
         if (!$color instanceof Color) {
             echo "3, Error! No Color: " . substr($sapProduct->getItemcode(), 9, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdColor($color->getIdColor());
         $customsTariffCode = CustomsTariffCodeQuery::create()->whereAdd(CustomsTariffCode::CODE, $sapProduct->getCstGrpCode())->findOne();
         if (!$customsTariffCode instanceof CustomsTariffCode) {
             echo "4, Error! No Tax Code: " . $sapProduct->getCstGrpCode() . "\n";
             $errors++;
             continue;
         }
         $product->setIdCustomsTariffCode($customsTariffCode->getIdCustomsTariffCode());
         $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::CODE, substr($sapProduct->getItemcode(), 0, 2))->findOne();
         if (!$productGroup instanceof ProductGroup) {
             echo "5, Error! No ProductGroup: " . substr($sapProduct->getItemcode(), 0, 2) . "\n";
             $errors++;
             continue;
         }
         $product->setIdProductGroup($productGroup->getIdProductGroup());
         $family = FamilyQuery::create()->whereAdd(Family::CODE, substr($sapProduct->getItemcode(), 2, 1))->whereAdd(Family::ID_PRODUCT_GROUP, $productGroup->getIdProductGroup())->findOne();
         if (!$family instanceof Family) {
             echo "6, Error! No Family: " . substr($sapProduct->getItemcode(), 2, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdFamily($family->getIdFamily());
         $subfamily = SubfamilyQuery::create()->whereAdd(Subfamily::CODE, substr($sapProduct->getItemcode(), 3, 1))->whereAdd(Subfamily::ID_FAMILY, $family->getIdFamily())->findOne();
         if (!$subfamily instanceof Subfamily) {
             echo "7, Error! No SubFamily: " . substr($sapProduct->getItemcode(), 3, 1) . "\n";
             $errors++;
             continue;
         }
         $product->setIdSubfamily($subfamily->getIdSubfamily());
         $product->setBuyUnit($sapProduct->getBuyUnitMsr());
         $product->setCost(0);
         $product->setIdCurrency(1);
         $product->setIdIncoterm(1);
         $product->setImportant(0);
         $product->setInventaryItem($sapProduct->getInvntItem() == 'Y' ? 1 : 0);
         $product->setInventoryUnit($sapProduct->getInvntryUom());
         $product->setItemCode($sapProduct->getItemcode());
         $product->setItemName($sapProduct->getItemname());
         $product->setKeyMother(substr($sapProduct->getItemcode(), 0, 7));
         $product->setMcDepth($sapProduct->getUMCProfundida());
         $product->setMcFront($sapProduct->getUMCFrente());
         $product->setMcHeight($sapProduct->getUMCAltura());
         $product->setMcParts($sapProduct->getUPzasXCaja());
         $product->setMcWeight($sapProduct->getUMCPeso());
         $product->setNumBuy($sapProduct->getNumInBuy());
         $product->setNumSales($sapProduct->getNumInSales());
         $product->setPurchaseItem($sapProduct->getPrchseItem() == 'Y' ? 1 : 0);
         $product->setPzaDepth($sapProduct->getUPzaprofu());
         $product->setPzaDiameter($sapProduct->getUPzadiametro());
         $product->setPzaFront($sapProduct->getUPzafrente());
         $product->setPzaHeight($sapProduct->getUPpzaaltura());
         $product->setPzaWeight($sapProduct->getUPesoXPza());
         $product->setRescue(0);
         $product->setSaiUnit($sapProduct->getSAlUnitMsr());
         $product->setSellItem($sapProduct->getSellItem() == 'Y' ? 1 : 0);
         $product->setStatus($sapProduct->getSWW());
         if ($save) {
             $this->getProductCatalog()->create($product);
             $new++;
         } else {
             $this->getProductCatalog()->update($product);
             $updated++;
         }
         echo "0, Ok! \n";
     }
     echo "\n\nTotals:\nErrors: " . $errors . "\nNew: " . $new . "\nUpdated: " . $updated;
     die;
 }