/** * @author Pablo */ public function benchmarkingAction() { $npd = NpdSheetQuery::create()->findByPKOrThrow($npdId = $this->getRequest()->getParam('id'), $this->i18n->_("The NPD Sheet with ID {$npdId} wasn't found")); $npdSuppliers = NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet())->find(); $npdSuppliersIds = NpdSheetSupplierQuery::create()->whereAdd(NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet())->addColumn(NpdSheetSupplier::ID_SUPPLIER)->fetchCol(); $supplierBudgets = SupplierBudgetQuery::create()->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $npdSuppliers->getPrimaryKeys(), SupplierBudgetQuery::IN)->find(); $benchmarking = array(); foreach ($supplierBudgets as $supplierBudget) { $moq = $supplierBudget->getMoq(); $npdSupplierId = $supplierBudget->getIdNpdSupplier(); $leadTime = $supplierBudget->getLeadTime(); if (!is_array($benchmarking[$moq])) { $benchmarking[$moq] = array(); } $benchmarking[$moq][$npdSupplierId] = array('price' => $supplierBudget->getPrice(), 'leadTime' => $supplierBudget->getLeadTime(), 'percent' => $supplierBudget->getPrice() / $npd->getPrice() * 100 - 100 . '%', 'favorite' => $supplierBudget->getFavorite(), 'isAuthorized' => $supplierBudget->getIsAuthorized(), 'supplierBudgetId' => $supplierBudget->getIdSupplierBudget()); ksort($benchmarking); } //die(print_r($benchmarking)); // echo '<pre>'; $supplierImages = array(); foreach ($npdSuppliers as $npdSupplier) { $supplierImages[$npdSupplier->getIdNpdSheet()] = FileQuery::create()->innerJoinNpdSheetSupplier()->whereAdd('NpdSheetSupplier.' . NpdSheetSupplier::ID_NPD_SHEET, $npd->getIdNpdSheet())->whereAdd('NpdSheetSupplier.' . NpdSheetSupplier::ID_NPD_SUPPLIER, $npdSupplier->getIdNpdSupplier())->whereAdd(File::TYPE, File::$typeFile['typeImage'])->find(); $NPDSheetSupplierFilesQuery = NpdSheetSupplierQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_NPD_SUPPLIER, $npdSupplier->getIdNpdSupplier())->fetchAll(); $supplierImages2[$npdSupplier->getIdNpdSheet()] = $NPDSheetSupplierFilesQuery; } // print_r($supplierImages); // print_r($supplierImages2); // die; $files = FileQuery::create()->innerJoinNpdSheet()->whereAdd('NpdSheet.' . NpdSheet::ID_NPD_SHEET, $npd->getIdNpdSheet())->find(); $npdImages = array(); $npdFiles = array(); $npdLinks = array(); foreach ($files as $file) { switch ($file->getType()) { case File::$typeFile['typeImage']: $npdImages[] = $file; break; case File::$typeFile['typeFile']: $npdFiles[] = $file; break; case File::$typeFile['typeLink']: $npdLinks[] = $file; break; } } if ($npd->getIdSubfamily()) { $subFamily = SubFamilyQuery::create()->findByPK($npd->getIdSubfamily())->getName(); } else { $subFamily = $this->i18n->_("Any"); } $suppliers = SapSupplierQuery::create()->whereAdd(SapSupplier::ID_SUPPLIER, $npdSuppliersIds, SapSupplierQuery::IN)->find(); $temporalSuppliers = array(); $temporalSuppliersQuery = TemporalSupplierQuery::create()->whereAdd(TemporalSupplier::ID_TEMPORAL_SAP, $npdSuppliersIds, TemporalSupplierQuery::IN)->find(); while ($temporalSupplier = $temporalSuppliersQuery->read()) { $supplier = new SapSupplier(); $supplier->setCardCode($temporalSupplier->getIdTemporalSap()); $supplier->setCardname($temporalSupplier->getName()); $suppliers->append($supplier); } // echo '<pre>'; // print_r($suppliers); // die; $this->view->subFamily = $subFamily; $this->view->family = $family = FamilyQuery::create()->findByPK($npd->getIdFamily()); $this->view->productGroup = ProductGroupQuery::create()->findByPK($family->getIdProductGroup()); $this->view->suppliers = $suppliers->toObjectArray(); $this->view->npd = $npd; $this->view->benchmarking = $benchmarking; $this->view->npdSuppliers = $npdSuppliers; $this->view->supplierBudgets = $supplierBudgets; $this->view->supplierImages = $supplierImages; $this->view->npdImages = $npdImages; $this->view->npdFiles = $npdFiles; $this->view->npdLinks = $npdLinks; $this->view->incoterms = \Application\Query\IncotermQuery::create()->find()->toCombo(); $this->view->ports = \Application\Query\PortCustomQuery::create()->find()->toCombo(); $this->view->contentTitle = $this->i18n->_('NPD Benchmarking'); }