예제 #1
0
 /**
  *
  * @return array
  */
 public function newAction()
 {
     $params = $this->getRequest()->getParams();
     $product['key'] = $params['composition'];
     $product['id_product_group'] = $params['id_product_group'];
     $product['id_family'] = $params['id_family'];
     $product['id_subfamily'] = $params['id_subfamily'];
     $product['id_brand'] = $params['id_brand'];
     $product['brand_code'] = $params['id_brand'] ? BrandQuery::create()->findByPK($product['id_brand'])->getName() : null;
     $product['productGroupCode'] = $productGroupCode = $product['id_product_group'] ? ProductGroupQuery::create()->findByPK($product['id_product_group'])->getCode() : null;
     $product['familyCode'] = $familyCode = $product['id_family'] ? FamilyQuery::create()->findByPK($product['id_family'])->getCode() : null;
     $product['subfamilyCode'] = $subfamilyCode = $product['id_subfamily'] ? SubfamilyQuery::create()->findByPK($product['id_subfamily'])->getCode() : "";
     $idNpd = $params['id_npd_sheet'];
     $pendingProduct = $params['pendingProduct'];
     if ($idNpd) {
         $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($idNpd, $this->i18n->_("Npd with id {$idNpd} does no exist"));
         $npdSuppliersQuery = \Application\Query\NpdSheetSupplierQuery::create()->whereAdd(\Application\Model\Bean\NpdSheetSupplier::ID_NPD_SHEET, $idNpd);
         //obtiene el precio autorizado del npd
         $authorizedBudget = \Application\Query\SupplierBudgetQuery::create()->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $npdSuppliersQuery->fetchIds(), BaseQuery::IN)->whereAdd(SupplierBudget::IS_AUTHORIZED, 1)->findOne();
         //obtiene el supplier autorizado
         $authorizedSupplier = $npdSuppliersQuery->addColumn("NpdSheetSupplier.*")->whereAdd(\Application\Model\Bean\NpdSheetSupplier::ID_NPD_SUPPLIER, $authorizedBudget->getIdNpdSupplier())->findOne();
         if (SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $authorizedSupplier->getIdSupplier())->count()) {
             $supplier = SapSupplierQuery::create()->findByPK($authorizedSupplier->getIdSupplier());
         } else {
             $supplier = new SapSupplier();
         }
         $currency = CurrencyQuery::create()->whereAdd(Currency::CURRCODE, $npdSheet->getIdCurrency())->findOne();
         $product['id_npd_sheet'] = $npdSheet->getIdNpdSheet();
         if (!$this->getRequest()->isPost()) {
             $product['id_product_group'] = $npdSheet->getIdProductGroup();
             $product['id_family'] = $npdSheet->getIdFamily();
             $product['id_subfamily'] = $npdSheet->getIdSubfamily();
             $product['id_brand'] = $npdSheet->getIdBrand();
         }
         $product['target_price'] = $npdSheet->getPrice();
         $product['long_description'] = $npdSheet->getLongDescription();
         $pendingProduct ? $pendingProduct : ($npdProduct = true);
         $npdFileQuery = \Application\Query\FileQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.id_npd_sheet', $params["id_npd_sheet"])->whereAdd('File.Type', file::$typeFile["typeFile"])->findOne();
         if ($product['id_brand']) {
             $product['brand_code'] = BrandQuery::create()->findByPK($product['id_brand'])->getName();
         }
         if ($product['id_color']) {
             $product['colorCode'] = ColorQuery::create()->findByPK($product['id_color'])->getCode();
         }
         if ($npdFileQuery) {
             $filePath = $npdFileQuery->getContent();
             $idFile = $npdFileQuery->getIdFile();
         }
         $itemsQuery = \Application\Query\ColorQuery::create()->innerJoinNpdSheet()->whereAdd("Color2NpdSheet.id_npd_sheet", $idNpd)->find();
         $itemCode = $product['productGroupCode'] . $product['subfamilyCode'] . $product['familyCode'] . $product['key'] . $product['brand_code'];
         $i = 0;
         while ($item = $itemsQuery->read()) {
             $npdItem = NpdSheetItemQuery::create()->findByColor($item->getIdColor(), $npdSheet->getIndex());
             $items[$i]['idColor'] = $item->getIdColor();
             $items[$i]['colorCode'] = $item->getCode();
             $items[$i]['itemName'] = $npdItem ? $npdItem->getName() : $npdSheet->getName();
             $items[$i]['itemCode'] = $itemCode . $item->getCode();
             $items[$i]['vim'] = $npdItem ? $npdItem->getVim() : "";
             $items[$i]['idNpdSheetItem'] = $npdItem ? $npdItem->getIndex() : "";
             $i++;
         }
         if ($pendingProduct) {
             $controller = "product";
             $action = "create";
         } else {
             $controller = "npd-sheet";
             $action = "new-product";
         }
         $product['itemName'] = $npdSheet->getName();
     } else {
         $npSheet = new NpdSheet();
         $authorizedBudget = new SupplierBudget();
         $authorizedSupplier = new NpdSheetSupplier();
         $supplier = new Supplier();
         $currency = new Currency();
         $npdProduct = false;
         $controller = "product";
         $action = "create";
     }
     $this->view->npdSheetFile = $filePath;
     $this->view->product = $product;
     $this->view->incoterms = $this->getIncoterms();
     $this->view->years = $this->getLastYears();
     $this->view->brands = $this->getBrands();
     $this->view->countries = $this->getCountries();
     $this->view->currencies = $this->getCurrencies();
     $this->view->productGroups = $this->getProductGroup();
     $this->view->families = $this->getFamilies($product['id_product_group']);
     $this->view->subfamilies = $this->getSubFamilies($product['id_family']);
     $this->view->defaultShipping = $this->getDefaultShipping();
     $this->view->customsTariffCodes = $this->getCustomsTariffCode();
     $this->view->colors = $this->getColors();
     $this->view->status = $this->getStatus();
     $this->view->authorizedBudget = $authorizedBudget;
     $this->view->authorizedSupplier = $authorizedSupplier;
     $this->view->supplier = $supplier->toArray();
     $this->view->currency = $currency->getCurrCode();
     $this->view->contentTitle = $this->i18n->_('New Product');
     $this->view->edit = false;
     $this->view->new = "ok";
     $this->view->controller = $controller;
     $this->view->action = $action;
     $this->view->npdProduct = $npdProduct;
     $this->view->items = $items;
     $this->view->pendingProduct = $pendingProduct;
     $this->view->setTpl('Form');
 }
예제 #2
0
 public function newProductAction()
 {
     //     			echo '<pre>';
     //     			print_r(print_r($this->getRequest()->getParams()).'dgdfg');
     //     			die;
     $params = $this->getRequest()->getParams();
     $idNpd = $params['idNpd'];
     $idAuthorizedSupplier = $params['authorizeSupplier'];
     $colors = $params["colors"];
     $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($idNpd, $this->i18n->_("Npd with id {$idNpd} does not esxist"));
     $supplierBudget = SupplierBudgetQuery::create()->findByPKOrThrow($idAuthorizedSupplier, $this->i18n->_("supplier with id {$idAuthorizedSupplier} does not esxist"));
     $npdSheetSupplier = NpdSheetSupplierQuery::create()->findByPKOrThrow($supplierBudget->getIdNpdSupplier(), $this->i18n->_("NPD supplier with id {$idAuthorizedSupplier} does not esxist"));
     try {
         $this->getNpdSheetCatalog()->beginTransaction();
         NpdSheetFactory::populate($npdSheet, $params);
         $npdSheet->setStatus(NpdSheet::$Status['Pending Product']);
         if ($this->getRequest()->getParam('id_subfamily') == '') {
             $npdSheet->setIdSubfamily(null);
         }
         $this->getNpdSheetCatalog()->update($npdSheet);
         supplierBudgetFactory::populate($supplierBudget, $params);
         $this->getSupplierBudgetCatalog()->update($supplierBudget);
         NpdSheetSupplierFactory::populate($npdSheetSupplier, $params);
         $this->getNPDSupplierCatalog()->update($npdSheetSupplier);
         $this->getCatalog("NpdSheetCatalog")->unlinkAllColor($npdSheet->getIdNpdSheet());
         if ($colors) {
             foreach ($colors as $color) {
                 if ($color) {
                     $this->getCatalog("NpdSheetCatalog")->linkToColor($npdSheet->getIdNpdSheet(), $color['idColor']);
                 }
                 if ($color['idNpdSheetItem']) {
                     $npdSheetItem = NpdSheetItemQuery::create()->findByPK($color['idNpdSheetItem']);
                     $fields = array(NpdSheetItem::ID_NPD_SHEET => $npdSheet->getIdNpdSheet(), NpdSheetItem::ID_COLOR => $color['idColor'], NpdSheetItem::VIM => $color['vim'], NpdSheetItem::NAME => $color['itemName']);
                     //die(print_r($npdSheetItem));
                     NpdSheetItemFactory::populate($npdSheetItem, $fields);
                     $this->getCatalog("NpdSheetItemCatalog")->update($npdSheetItem);
                 } else {
                     $npdsheetItem = new NpdSheetItem();
                     $npdsheetItem->setIdColor($color['idColor']);
                     $npdsheetItem->setIdNpdSheet($npdSheet->getIdNpdSheet());
                     $npdsheetItem->setVim($color['vim']);
                     $npdsheetItem->setName($color['itemName']);
                     $this->getCatalog("NpdSheetItemCatalog")->create($npdsheetItem);
                 }
             }
         }
         $this->getNpdSheetCatalog()->commit();
         $this->setFlash('ok', $this->i18n->_("Information was successfully saved, pending product code"));
     } catch (Exception $e) {
         $this->getNpdSheetCatalog()->rollBack();
         $this->setFlash('error', $this->i18n->_($e->getMessage()));
     }
     $this->_redirect('npd-sheet/list');
 }