コード例 #1
0
ファイル: -ProductController.php プロジェクト: Eximagen/sochi
 /**
  *
  */
 public function newKeyAction()
 {
     $post['NPD'] = $this->getRequest()->getParam('npd', '');
     $post['idProductGroup'] = $this->getRequest()->getParam('id_product_group', '');
     $post['idFamily'] = $this->getRequest()->getParam('id_family', '');
     $post['idSubfamily'] = $this->getRequest()->getParam('id_subfamily', '');
     $post['clvcomposition'] = $this->getRequest()->getParam('composition', '');
     $post['idBrand'] = $this->getRequest()->getParam('id_brand', '');
     $this->view->contentTitle = $this->i18n->_('Item Code');
     $this->view->NPDSheet = $NPDSheet = !empty($post['NPD']) ? NpdSheetQuery::create()->findByPKOrThrow($post['NPD'], $this->i18n->_("The NPDSheet with Id {$post['NPD']} does not exist.")) : new NpdSheet();
     $this->view->proceed = false;
     if ($this->getRequest()->isPost()) {
         $this->view->productGroup = $produtGroup = ProductGroupQuery::create()->findByPKOrThrow($post['idProductGroup'], $this->i18n->_("The ProductGroup with Id {$post['idProductGroup']} does not exist."));
         $this->view->family = $family = FamilyQuery::create()->findByPKOrThrow($post['idFamily'], $this->i18n->_("The Family with Id {$post['idFamily']} does not exist."));
         $this->view->subfamily = $subfamily = SubfamilyQuery::create()->findByPKOrThrow($post['idSubfamily'], $this->i18n->_("The Subfamily with Id {$post['idSubfamily']} does not exist."));
         $this->view->brand = $brand = BrandQuery::create()->findByPKOrThrow($post['idBrand'], $this->i18n->_("The Brand with Id {$post['idBrand']} does not exist."));
         $this->view->proceed = true;
     } else {
         if ($NPDSheet->getIdNpdSheet() > 0) {
             $this->view->productGroup = $produtGroup = ProductGroupQuery::create()->findByPKOrThrow($NPDSheet->getIdProductGroup(), $this->i18n->_("The ProductGroup with Id {$NPDSheet->getIdProductGroup()} does not exist."));
             //die("<pre>".print_r($produtGroup, true)."</pre>");
             $this->view->family = $family = $NPDSheet->getIdFamily() > 0 ? FamilyQuery::create()->findByPKOrThrow($NPDSheet->getIdFamily(), $this->i18n->_("The Family with Id {$NPDSheet->getIdFamily()} does not exist.")) : new Family();
             $this->view->subfamily = $subfamily = $NPDSheet->getIdSubfamily() > 0 ? SubfamilyQuery::create()->findByPKOrThrow($NPDSheet->getIdSubfamily(), $this->i18n->_("The Subfamily with Id {$NPDSheet->getIdSubfamily()} does not exist.")) : new Subfamily();
             //die($NPDSheet->getIdBrand());
             $this->view->brand = $brand = $NPDSheet->getIdBrand() > 0 ? BrandQuery::create()->findByPKOrThrow($NPDSheet->getIdBrand(), $this->i18n->_("The Brand with Id {$NPDSheet->getIdBrand()} does not exist.")) : new Brand();
         } else {
             $this->view->productGroup = $produtGroup = new ProductGroup();
             $this->view->family = $family = new Family();
             $this->view->subfamily = $subfamily = new Subfamily();
             $this->view->brand = $brand = new Brand();
         }
     }
     $productsFam = ProductQuery::create()->distinct()->addColumn(Product::ID_PRODUCT_GROUP)->fetchCol();
     $productGroupQuery = ProductGroupQuery::create();
     $productGroupQuery->where()->setOr();
     $productsFam = $productGroupQuery->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $productsFam, ProductGroupQuery::IN)->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $post['idProductGroup'])->addAscendingOrderBy(ProductGroup::CODE)->fetchAll();
     foreach ($productsFam as $key => $productFam) {
         if ($productFam['id_product_group'] == $post['idProductGroup']) {
             $productGroupIds = array("prevFamily" => $productsFam[$key - 1]['id_product_group'], "productFamily" => $productsFam[$key]['id_product_group'], "nextFamily" => $productsFam[$key + 1]['id_product_group']);
             break;
         }
     }
     //die("<pre>".print_r($productGroupIds, true)."</pre>");
     $wantedProducts = ProductQuery::create();
     $wantedProducts->where()->setOR();
     $seachProducts = $wantedProducts->addColumns(array(Product::ITEM_CODE, Product::ITEM_NAME, Product::STATUS, "U_Madre_09" => 'SUBSTRING(' . Product::ITEM_CODE . ', 0, 8)', Product::ID_COLOR, Product::ID_COLOR))->whereAdd(Product::ID_PRODUCT_GROUP, $productGroupIds['productFamily'])->whereAdd(Product::ID_PRODUCT_GROUP, $productGroupIds['prevFamily'])->whereAdd(Product::ID_PRODUCT_GROUP, $productGroupIds['nextFamily'])->addAscendingOrderBy(Product::ITEM_CODE)->fetchAll();
     $newProduct = array(array('ItemCode' => $produtGroup->getCode() . $family->getCode() . $subfamily->getCode() . $post['clvcomposition'] . $brand->getName(), 'ItemName' => $NPDSheet->getName() ? $NPDSheet->getName() : $this->i18n->_('Not set'), 'SWW' => 'H', 'U_Madre_09' => $produtGroup->getCode() . $family->getCode() . $subfamily->getCode() . $post['clvcomposition'], 'U_Color' => $colorCode, 'index' => true));
     //order total products
     $products = array_merge($seachProducts, $newProduct);
     usort($products, function ($a, $b) {
         return strcmp($a['ItemCode'], $b['ItemCode']);
     });
     // 		echo '<pre>';
     // 		print_r($seachProducts);
     // 		die;
     //die("<pre>".print_r($products, true)."</pre>");
     $prepend = $produtGroup->getCode() . $family->getCode() . $subfamily->getCode();
     $lastItem = $newProduct[0]['U_Madre_09'];
     $nextComposition = $post['clvcomposition'];
     foreach ($seachProducts as $key => $val) {
         if (strstr($val['U_Madre_09'], $newProduct[0]['U_Madre_09'])) {
             $this->view->proceed = false;
         }
         if (strstr($val['U_Madre_09'], $lastItem)) {
             $nextComposition += 1;
             if ($nextComposition % 2 == 0) {
                 $nextComposition += 1;
             }
             $lastItem = $prepend . $nextComposition;
         }
     }
     // 		echo $lastItem;die;
     foreach ($products as $key => $product) {
         if ($product['ItemCode'] == $newProduct[0]['ItemCode']) {
             $this->view->index = $key;
         }
     }
     $this->view->productGroups = $this->getProductGroup();
     $families = array("" => $this->i18n->_("Select a Family"));
     if ($family->getIdFamily() > 0) {
         $families += FamilyQuery::create()->whereAdd(Family::ID_PRODUCT_GROUP, $family->getIdProductGroup())->find()->toCombo();
     }
     $this->view->families = $families;
     $subfamilies = array("" => $this->i18n->_("Select a Subfamily"));
     if ($subfamily->getIdSubfamily() > 0) {
         $subfamilies += SubfamilyQuery::create()->whereAdd(Subfamily::ID_FAMILY, $subfamily->getIdFamily())->find()->toComboUTF8();
     } else {
         $subfamilies += SubfamilyQuery::create()->whereAdd(Subfamily::ID_FAMILY, $family->getIdFamily())->find()->toComboUTF8();
     }
     $this->getRequest()->getParam("pending_product") == true ? $pendingProduct = true : ($pendingProduct = false);
     $this->view->nextComposition = $nextComposition;
     $this->view->pendingProduct = $pendingProduct;
     $this->view->subfamilies = $subfamilies;
     $this->view->brands = $this->getBrands();
     $this->view->products = $products;
     $this->view->colors = ColorQuery::create()->find();
     $this->view->setTpl('../npd-sheet/Npd-key');
 }
コード例 #2
0
ファイル: NpdSheetController.php プロジェクト: Eximagen/sochi
 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();
 }