Example #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');
 }
Example #2
0
 public function exportToExcelPendingProductAction()
 {
     $post['id_product_group'] = urldecode($this->getRequest()->getParam('id_product_group'));
     $post['reference'] = urldecode($this->getRequest()->getParam('reference'));
     $post['status'] = $this->getRequest()->getParam('status');
     $npdsheets = NpdSheetQuery::create()->filter($post)->addDescendingOrderBy(NpdSheet::ID_NPD_SHEET)->whereAdd(NpdSheet::STATUS, NpdSheet::$Status['Pending Product'])->find();
     if (!$npdsheets->isEmpty()) {
         $i = 1;
         while ($npdsheet = $npdsheets->read()) {
             $productGroup = ProductGroupQuery::create()->whereAdd(ProductGroup::ID_PRODUCT_GROUP, $npdsheet->getIdProductGroup())->findOne();
             $family = FamilyQuery::create()->whereAdd(Family::ID_FAMILY, $npdsheet->getIdFamily())->findOne();
             $subfamily = SubfamilyQuery::create()->whereAdd(Subfamily::ID_SUBFAMILY, $npdsheet->getIdSubfamily())->findOne();
             $npdSupplier = NpdSheetSupplierQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheetSupplier.id_npd_sheet', $npdsheet->getIdNpdSheet())->find()->getPrimaryKeys();
             if ($npdSupplier) {
                 $authorizedPrice = SupplierBudgetQuery::create()->innerJoinNpdSheetSupplier()->whereAdd('SupplierBudget.id_npd_supplier', $npdSupplier, Criteria::IN)->whereAdd('SupplierBudget.is_authorized', 1)->findOne();
             }
             if (!$authorizedPrice) {
                 $authorizedPrice = new SupplierBudget();
             }
             if (NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SUPPLIER, $authorizedPrice->getIdNpdSupplier())->count()) {
                 $npdSupplier = NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SUPPLIER, $authorizedPrice->getIdNpdSupplier())->findOne();
             } else {
                 $npdSupplier = null;
             }
             if ($npdSupplier) {
                 if (SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $npdSupplier->getIdSupplier())->count()) {
                     $supplier = SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $npdSupplier->getIdSupplier())->findOne()->getSupplierCardCodeWithCardName();
                 }
             }
             $data[$i] = array($npdsheet->getIdNpdSheet(), $npdsheet->getStatusName(), $npdsheet->getReference(), $npdsheet->getCreationDateAsZendDate()->get('YYYY-MM-dd'), $productGroup->getCode() . '-' . $productGroup->getName(), $family->getCode() . '-' . $family->getName(), $subfamily ? $subfamily->getCode() . '-' . $subfamily->getName() : $this->i18n->_('Not Available'), $npdsheet->getName(), $npdsheet->getPrice(), $authorizedPrice->getPrice(), $supplier ? $supplier : null);
             $i++;
         }
         $header = array($this->i18n->_('ID'), $this->i18n->_('Status'), $this->i18n->_('Reference'), $this->i18n->_('Creation date'), $this->i18n->_('Product Group'), $this->i18n->_('Family'), $this->i18n->_('Subfamily'), $this->i18n->_('Product'), $this->i18n->_('Target Price'), $this->i18n->_('Authorized Price'), $this->i18n->_('Prefered Supplier'));
         $title = $this->i18n->_('NPDs Report');
         $fileName = $this->i18n->_('Npds_report');
         $tableColumnsWidth = array('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("warning", $this->i18n->_('No records found'));
         $this->_redirect('npd-sheet/pending-product');
     }
 }
 public function addSupplierAction()
 {
     //view information NPD
     $this->view->id = $idNpdSheet = $this->getRequest()->getParam('id');
     $this->view->contentTitle = 'Add Supplier';
     $this->generateUrl('npd', 'create');
     $this->view->setTpl("Add-supplier");
     $this->view->npd = $npdSheet = NpdSheetQuery::create()->findByPKOrThrow($idNpdSheet, $this->i18n->_("It does not exist the NpdSheet with id {$idNpdSheet}"));
     $family = FamilyQuery::create()->findByPK($npdSheet->getIdFamily());
     $this->view->family = $family->getName();
     if ($npdSheet->getIdSubfamily()) {
         $this->view->subfamily = SubfamilyQuery::create()->findByPK($npdSheet->getIdSubfamily())->getName();
     } else {
         $this->view->subfamily = $this->i18n->_("Any");
     }
     $this->view->productGroup = ProductGroupQuery::create()->findByPK($family->getIdProductGroup())->getName();
     $this->view->videos = FileQuery::create()->innerJoinNpdSheet()->whereAdd('File2NpdSheet.id_npd_sheet', $npdSheet->getIdNpdSheet())->whereAdd(File::TYPE, File::$typeFile["typeLink"])->find();
     $this->view->npdColors = ColorQuery::create()->innerJoinNpdSheet()->whereAdd('Color2NpdSheet.id_npd_sheet', $npdSheet->getIdNpdSheet())->find();
     $this->view->country = CountryQuery::create()->find()->toCombo();
     $this->view->npdSheetImages = NpdSheetQuery::getNpdSheetFileObjects($npdSheet->getIdNpdSheet(), File::$typeFile["typeImage"]);
     $this->view->npdSheetFiles = NpdSheetQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheet." . NpdSheet::ID_NPD_SHEET, $npdSheet->getIdNpdSheet())->fetchAll();
     $this->view->file = $file = FileQuery::create()->innerJoinNpdSheet()->whereAdd('File2NpdSheet.id_npd_sheet', $npdSheet->getIdNpdSheet())->whereAdd(File::TYPE, File::$typeFile["typeFile"])->findOne();
     //Form add supplier
     $npdSuppliers = $npdSuppliers = NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SHEET, $idNpdSheet)->find();
     $allColors = array("" => "**  Select a Color  **") + ColorQuery::create()->actives()->find()->toCombo();
     //Videos from supplier
     foreach ($npdSuppliers as $npdSupplier) {
         //Get File Video for NPDSheetSupplier
         $NPDSheetSupplierFilesQuery = NpdSheetSupplierQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_NPD_SUPPLIER, $npdSupplier->getIdNpdSupplier())->fetchAll();
         $NPDSheetSupplierFiles[$npdSupplier->getIdNpdSupplier()] = $NPDSheetSupplierFilesQuery;
         $assignedColors = $this->getSupplierColors($npdSupplier->getIdNpdSupplier());
         $i = 0;
         foreach ($assignedColors->toCombo() as $idColor => $colorName) {
             $colors[$npdSupplier->getIdNpdSupplier()][$i]["options"] = $allColors + array($idColor => $colorName);
             $colors[$npdSupplier->getIdNpdSupplier()][$i]["selected"] = $idColor;
             $i++;
         }
         if (count($colors[$npdSupplier->getIdNpdSupplier()]) == 0) {
             $colors[$npdSupplier->getIdNpdSupplier()][0]["options"] = $allColors;
         }
         //Moq and price
         $npdMoqPriceQuery = SupplierBudgetQuery::create();
         $npdMoqPriceQuery->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $npdSupplier->getIdNpdSupplier());
         $npdMoqPrice[$npdSupplier->getIdNpdSupplier()] = $npdMoqPriceQuery->find();
     }
     if ($npdSuppliers->count() > 0) {
         $this->view->npdSuppliers = $npdSuppliers;
         $this->view->NPDSheetSupplierFiles = $NPDSheetSupplierFiles;
         //die(print_r($colors));
         $this->view->fileTypes = File::$typeFile;
         $this->view->colors = $colors;
         $this->view->npdMoqPrice = $npdMoqPrice;
     } else {
         $npdSuppliers = new stdClass();
         $npdSuppliers->couryard = new NpdSheetSupplier();
         $this->view->npdSuppliers = $npdSuppliers;
         $this->view->defaultColor = $allColors;
     }
     $suppliers = Application\Query\SapSupplierQuery::create()->find();
     $temporalSupplierQuery = TemporalSupplierQuery::create()->find();
     $temporalSupplierArray = array();
     $temporalSupplierNamesArray = array();
     while ($temporalSupplier = $temporalSupplierQuery->read()) {
         $temporalSupplierNamesArray[$temporalSupplier->getIdTemporalSap()] = $temporalSupplier->getIdTemporalSap() . ' - ' . $temporalSupplier->getName();
         $temporalSupplierArray[$temporalSupplier->getIdTemporalSap()] = $temporalSupplier->getName();
     }
     //     	$suppliersToAjax += $temporalSupplierArray;
     $this->view->supplierNames = $suppliers->toAutoCompleteCombo() + $temporalSupplierNamesArray;
     $this->view->supplierTabs = $suppliers->toCombo() + $temporalSupplierArray;
     $this->view->fobPorts = array("" => "Select Fob Port") + Application\Query\PortCustomQuery::create()->actives()->whereAdd('PortCustom.' . PortCustom::IS_DEPARTURE, 1)->find()->toCombo();
     $this->view->incoterms = array("" => "Select Incoterm") + \Application\Query\IncotermQuery::create()->find()->toCombo();
     $this->view->currencies = array("" => "Select Currency") + \Application\Query\CurrencyQuery::create()->find()->toCombo();
     $this->view->actionForm = 'create';
 }
Example #4
0
 function orderFormAction()
 {
     $this->view->page = $page = $this->getRequest()->getParam('page') ?: 1;
     $this->view->contentTitle = $this->i18n->_('New Sample Order');
     $npdSheets = NpdSheetQuery::create()->addDescendingOrderBy(NpdSheet::STATUS)->addDescendingOrderBy(NpdSheet::CREATION_DATE)->whereAdd(NpdSheet::STATUS, NpdSheet::$Status['Closed'], BaseQuery::NOT_EQUAL)->find();
     $colors = array();
     $npdSuppliers = array();
     while ($npdSheet = $npdSheets->read()) {
         $colors[$npdSheet->getIdNpdSheet()] = ColorQuery::create()->addColumns(array("Color.*"))->whereAdd("NpdSheet." . NpdSheet::ID_NPD_SHEET, $npdSheet->getIdNpdSheet())->innerJoinNpdSheet()->find();
         if (NpdSheetSupplierQuery::create()->addColumn(NpdSheetSupplier::ID_SUPPLIER)->innerJoinNpdSheet()->whereAdd('NpdSheetSupplier.id_npd_sheet', $npdSheet->getIdNpdSheet())->find()->count()) {
             $npdSupplierIds = NpdSheetSupplierQuery::create()->addColumn(NpdSheetSupplier::ID_SUPPLIER)->innerJoinNpdSheet()->whereAdd('NpdSheetSupplier.id_npd_sheet', $npdSheet->getIdNpdSheet())->fetchCol();
         } else {
             $npdSheets->remove($npdSheet->getIdNpdSheet());
         }
         $npdSuppliers[$npdSheet->getIdNpdSheet()] = SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $npdSupplierIds, SapSupplierQuery::IN)->find();
         $unitCost[$npdSheet->getIdNpdSheet()] = \Application\Query\SupplierBudgetQuery::create()->innerJoinNpdSheetSupplier()->whereAdd('NpdSheetSupplier.id_npd_sheet', $npdSheet->getIdNpdSheet())->whereAdd('SupplierBudget.is_authorized', 1)->addColumns(array('SupplierBudget.price', 'NpdSheetSupplier.id_supplier'))->fetchAll();
     }
     $this->view->npdSuppliers = array("Any") + $npdSuppliers;
     $this->view->npdSheets = $npdSheets;
     $this->view->colors = $colors;
     $this->view->unitCost = $unitCost;
 }