/** * * @return array */ public function createAction() { if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getParams(); try { $this->getNpdSheetSupplierCatalog()->beginTransaction(); foreach ($params["supplier"] as $index => $supplier) { $idSupplier = $supplier['id_supplier']; $idNpdSupplier = $supplier['id_npd_supplier']; // $supplierParams = Application\Query\SapSupplierQuery::create()->findByPKOrThrow($idSupplier,$this->i18n->_("It does not exist the supplier with id {$idSupplier}")); if ($idNpdSupplier > 0) { $npdSupplierParams = Application\Query\NpdSheetSupplierQuery::create()->findByPKOrElse($idNpdSupplier, new NpdSheetSupplier()); $npdSheetSupplier = NpdSheetSupplierFactory::populate($npdSupplierParams, $supplier); $this->getNpdSheetSupplierCatalog()->update($npdSupplierParams); foreach ($_FILES as $name => $value) { if (strstr($name, "image_" . $index . "_") != false && $value["name"] != "") { $fileUploader = new FileUploader($name); if (strstr($name, "image") != false) { $uploadPath = 'public/files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $fileUploader->saveFile($uploadPath, true); $type = File::$typeFile["typeImage"]; } $sheetFile = new File(); $sheetFile->setType($type)->setContent('files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier' . $fileUploader->getFileName()); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($idNpdSupplier, $sheetFile->getIdFile()); } } //Videos //search if npd supplier have videos $npdVideos = NpdSheetSupplierQuery::create()->addColumns(array("File.*"))->innerJoinFile()->whereAdd("NpdSheetSupplier." . NpdSheetSupplier::ID_NPD_SUPPLIER, $idNpdSupplier)->whereAdd("File." . File::TYPE, File::$typeFile["typeLink"])->fetchAll(); // if npd supplier have videos then delete it all foreach ($npdVideos as $npdVideo) { $this->getFileCatalog()->unlinkFromNpdSheetSupplier($npdVideo["id_file"], $idNpdSupplier); $this->getFileCatalog()->deleteById($npdVideo["id_file"]); } //die("<pre>".print_r($supplier, true)."</pre>"); // insert new videos $supplier["video"] = (array) $supplier["video"]; foreach ($supplier["video"] as $video) { if ($video != "") { //insert a new video with Type -> video $sheetFile = new File(); $sheetFile->setType(File::$typeFile["typeLink"])->setContent($video); //make relationship file - npdSupplier $this->getFileCatalog()->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($idNpdSupplier, $sheetFile->getIdFile()); } } //Moq and Price //search if npd supplier have moq and price $npdMoqPrices = SupplierBudgetQuery::create()->whereAdd(SupplierBudget::ID_NPD_SUPPLIER, $idNpdSupplier)->fetchAll(); //if npd supplier have moq and price then delete it all foreach ($npdMoqPrices as $npdMoqPrice) { $this->getSupplierBudgetCatalog()->deleteById($npdMoqPrice["id_supplier_budget"]); } //insert new moq and price foreach ($supplier["moqPrice"] as $moqprice) { $npdMoq = new SupplierBudget(); $npdMoq->setIdNpdSupplier($idNpdSupplier)->setMoq($moqprice["moq"])->setLeadTime($moqprice["leadtime"])->setPrice($moqprice["price"])->setIdCurrency($supplier["id_currency"]); $this->getSupplierBudgetCatalog()->create($npdMoq); } $this->getNpdSheetSupplierCatalog()->unlinkAllColor($idNpdSupplier); } else { $newSuppliers = $supplier; $npdSheetSupplier = NpdSheetSupplierFactory::createFromArray($newSuppliers); $this->getNpdSheetSupplierCatalog()->create($npdSheetSupplier); $newSupplier = $npdSheetSupplier->getIdNpdSupplier(); foreach ($_FILES as $name => $value) { if (strstr($name, "image_" . $index . "_") != false && $value["name"] != "") { $fileUploader = new FileUploader($name); if (strstr($name, "image") != false) { $uploadPath = 'public/files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $fileUploader->saveFile($uploadPath, true); $type = File::$typeFile["typeImage"]; } $uploadPath = 'files/npd/' . $supplier['id_npd_sheet'] . '/imagesSupplier'; $sheetFile = new File(); $sheetFile->setType($type)->setContent($uploadPath . $fileUploader->getFileName()); $this->getCatalog("FileCatalog")->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($newSupplier, $sheetFile->getIdFile()); } } foreach ($supplier["video"] as $video) { if ($video != "") { //insert a new video with Type -> video $sheetFile = new File(); $sheetFile->setType(File::$typeFile["typeLink"])->setContent($video); //make relationship file - npdSupplier $this->getFileCatalog()->create($sheetFile); $this->getNpdSheetSupplierCatalog()->linkToFile($newSupplier, $sheetFile->getIdFile()); } } //insert new moq and price foreach ($supplier["moqPrice"] as $moqprice) { $npdMoq = new SupplierBudget(); $npdMoq->setIdNpdSupplier($newSupplier)->setMoq($moqprice["moq"])->setLeadTime($moqprice["leadtime"])->setPrice($moqprice["price"])->setIdCurrency($supplier["id_currency"]); $this->getSupplierBudgetCatalog()->create($npdMoq); } } } $this->getNpdSheetSupplierCatalog()->commit(); $this->setFlash('ok', $this->i18n->_("The Supplier has been saved")); } catch (Exception $e) { // Roll back any change in database $this->getNpdSheetSupplierCatalog()->rollBack(); $this->setFlash('error', $this->i18n->_($e->getMessage())); throw $e; } } $this->_redirect('npd-sheet/list'); }
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'); } }