/**
  *
  */
 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');
 }
Exemple #2
0
 /**
  *
  * Enter description here ...
  */
 public function exportToExcelAction()
 {
     $post['id_product_group'] = urldecode($this->getRequest()->getParam('id_product_group'));
     $post['id_family'] = urldecode($this->getRequest()->getParam('id_family'));
     $post['status'] = $this->getRequest()->getParam('status');
     $families = FamilyQuery::create()->filter($post)->find();
     if (!$families->isEmpty()) {
         $i = 1;
         while ($family = $families->read()) {
             if (ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $family->getIdProductGroup())->count()) {
                 $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $family->getIdProductGroup())->findOne();
             } else {
                 $productGroup = new ProductGroup();
             }
             $data[$i] = array($productGroup->getCode() . '-' . $productGroup->getName(), $family->getName(), $family->getCode(), $family->getStatusName());
             $i++;
         }
         $header = array($this->i18n->_('Product Group'), $this->i18n->_('Family'), $this->i18n->_('Code'), $this->i18n->_('Status'));
         $title = $this->i18n->_('Family Report');
         $fileName = $this->i18n->_('Family_report');
         $tableColumnsWidth = array('medium', 'medium', 'mini');
         $report = new SimpleListReport();
         $report->setTableTitle($title);
         $report->setTableHeaders($header);
         $report->setTableContent($data);
         $report->setFilename($fileName);
         $report->setTableColumnsWidth($tableColumnsWidth);
         $report->createSpreadsheet();
     } else {
         $filter = $this->createFilterForUrl($post);
         $this->setFlash("error", $this->i18n->_('No records'));
         $this->_redirect('family/list');
     }
 }