示例#1
0
 /**
  * 
  */
 public function getListResultsAction()
 {
     $storage = $this->getStorageService();
     $params = $this->getRequest()->getParams();
     $page = $params['page'];
     $productQuery = ProductQuery::create()->useFileCache()->filter($params);
     $colors = ColorQuery::create()->find();
     $brands = BrandQuery::create()->find();
     $productCollection = $productQuery->find();
     $freightFareCollection = FreightFareQuery::create()->find();
     $freightTypeCollection = FreightTypeQuery::create()->find();
     $customsTariffCodeCollection = CustomsTariffCodeQuery::create()->find();
     $incotermCollection = IncotermQuery::create()->useFileCache()->find();
     $products = $productQuery->findByPage($page, $this->getMaxPerPage());
     // 		if (!$productStorage)
     // 			$storage->saveValue($productQuery->find(), 'products');
     $productPrintingArea = ProductPrintingAreaQuery::create()->addColumn(ProductPrintingArea::ID_PRODUCT)->whereAdd(ProductPrintingArea::ID_PRODUCT, $products->getKeyMother(), ProductPrintingAreaQuery::IN)->fetchCol();
     //
     $arrayProducts = array();
     while ($products->valid()) {
         $product = $products->read();
         $hasPrintingArea = in_array($product->getKeyMother(), $productPrintingArea) ? 1 : 0;
         $arrayProducts[$product->getIndex()] = $product->toArrayForList() + array("has_printing_area" => $hasPrintingArea);
     }
     die(json_encode($arrayProducts));
 }
示例#2
0
 public function exportToExcelAction()
 {
     $params = $this->getRequest()->getParams();
     $incoterms = IncotermQuery::create()->filter($params)->find();
     $report = new SimpleListReport();
     $i = 0;
     while ($incoterm = $incoterms->read()) {
         $content[$i][] = $incoterm->getIdIncoterm();
         $content[$i][] = $incoterm->getName();
         $content[$i][] = $incoterm->getStatusName();
         $i++;
     }
     $headers = array('Id Incoterm', 'Name', 'Status');
     $tableTitle = $this->i18n->_('Incoterm Report');
     $filename = 'incoterm_report';
     $report->setTableContent($content);
     $report->setTableHeaders($headers);
     $report->setTableTitle($tableTitle);
     $report->setFilename($filename);
     $report->createSpreadsheet();
 }
示例#3
0
 /**
  * @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');
 }
 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';
 }
示例#5
0
 /**
  * This action display the view to china agents
  *
  * @author Erick Guevara Martínez
  */
 public function entriesAction()
 {
     // Get criteria to filter requisition entries
     if ($this->getRequest()->isPost()) {
         $post[RequisitionEntry::ID_REQUISITION] = $this->getRequest()->getParam(RequisitionEntry::ID_REQUISITION);
         $post[RequisitionEntry::STATUS] = $this->getRequest()->getParam(RequisitionEntry::STATUS);
         $post["id_supplier"] = $this->getRequest()->getParam("id_supplier", "");
         $post["id_destination_country"] = $this->getRequest()->getParam("id_destination_country", "");
         $post["startDate"] = $this->getRequest()->getParam("startDate", "");
         $post["endDate"] = $this->getRequest()->getParam("endDate", "");
         $post["key_mother"] = $this->getRequest()->getParam("key_mother", "");
         $post["order"] = $this->getRequest()->getParam("order", "");
     }
     $accessRole = $this->getUser()->getAccessRole();
     $accessRoleManager = new AccessRoleManager();
     $suppliers = $accessRoleManager->getAssociateSuppliers($accessRole);
     $products = ProductQuery::create()->whereAdd(Product::ID_SUPPLIER, $suppliers->getPrimaryKeys())->find();
     // Creates an array with the status can be displayed in this view
     $allowedStatus = array("Pending Price" => RequisitionEntry::$Status["Pending Price"], "Pending Price Auth" => RequisitionEntry::$Status["Pending Price Auth"], "PI Requested" => RequisitionEntry::$Status["PI Requested"]);
     // If don't have a status filter then search by allowed status
     $requisitionEntriesQuery = RequisitionEntryQuery::create()->filter($post)->whereAdd(RequisitionEntry::ID_PRODUCT, $products->getPrimaryKeys());
     if ($post[RequisitionEntry::STATUS] == "") {
         $requisitionEntriesQuery->whereAdd("RequisitionEntry." . RequisitionEntry::STATUS, $allowedStatus, BaseQuery::IN);
     }
     // Filter all requisition entries belonging to a requisition with the same
     if ($post["id_destination_country"] != "") {
         $requisitionEntriesQuery->innerJoinRequisition()->whereAdd("Requisition." . Requisition::ID_DESTINATION_COUNTRY, $post["id_destination_country"]);
     }
     // Filter all requisition entries with a supplier default or a bentchmarcking that equal to id_supplier filter param
     if ($post["id_supplier"] != "") {
         $requisitionEntriesQuery->innerJoinKeyMotherSupplierBudget()->whereAdd("KeyMotherSupplierBudget." . KeyMotherSupplierBudget::ID_SUPPLIER, $post["id_supplier"]);
     }
     // Filter all requisition entries with a supplier default or a bentchmarcking that equal to id_supplier filter param
     if ($post["key_mother"] != "") {
         $requisitionEntriesQuery->whereAdd("RequisitionEntry." . RequisitionEntry::ID_PRODUCT, $post["key_mother"], RequisitionEntryQuery::LIKE);
     }
     if ($post["order"] == "date_asc" || $post["order"] == "date_desc") {
         $requisitionEntriesQuery->addAscendingOrderBy("RequisitionEntry." . RequisitionEntry::CREATION_DATE);
     } else {
         $requisitionEntriesQuery->addAscendingOrderBy("RequisitionEntry." . RequisitionEntry::ID_PRODUCT);
     }
     $requisitionEntries = $requisitionEntriesQuery->find();
     // If have more than 1 requisition entry then get extra info to requisition
     $parentKeys = array();
     $requisitions = new RequisitionCollection();
     $budgets = new KeyMotherSupplierBudgetCollection();
     if ($requisitionEntries->count() > 0) {
         $products = $products->filterByPks($requisitionEntries->getDistinctProducts())->orderByArrayPks($requisitionEntries->getDistinctProducts());
         $parentKeys = $products->getKeyMother();
         $requisitions = RequisitionQuery::create()->whereAdd(Requisition::ID_REQUISITION, $requisitionEntries->getDistinctRequisitions(), RequisitionQuery::IN)->find();
         if (count($parentKeys) > 0) {
             $budgets = KeyMotherSupplierBudgetQuery::create()->whereAdd(KeyMotherSupplierBudget::KEY_MOTHER, $parentKeys, KeyMotherSupplierBudgetQuery::IN)->actives()->find();
         }
     }
     // Proccess and group all requisition entries by parent key
     $requisitionEntriesGroupByParentKey = array();
     foreach ($parentKeys as $parentKey) {
         // Get all products belonging to current parent key
         $parentKeyProducts = $products->filterByKeyMother($parentKey);
         // Get all requisition entries belonging to products of a current parent key
         $parentKeyRequisitionEntries = $requisitionEntries->filterByIdProduct($parentKeyProducts->getPrimaryKeys());
         // Set Headers to group
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["parentKey"] = $parentKey;
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["description"] = $parentKeyProducts->current()->getItemName();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["idDefaultProduct"] = $parentKeyProducts->current()->getItemCode();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["firstRequisitionDate"] = $parentKeyRequisitionEntries->getFirstCreationDate();
         // Set a current supplier default name, in case of this don't have suppliers then set "-"
         if ($parentKeyRequisitionEntries->getRecurrentSupplierDefault() == null) {
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierSapBussinessCode"] = "-";
         } else {
             $supplier = $suppliers->getByPK($parentKeyRequisitionEntries->getRecurrentSupplierDefault());
             if (!$supplier) {
                 $supplier = new SapSupplier();
             }
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierSapBussinessCode"] = $supplier ? $supplier->getCardCode() : 'Error';
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierName"] = $supplier->getName();
         }
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["totalQuantity"] = $parentKeyRequisitionEntries->getTotalQuantity();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["targetPrice"] = $parentKeyProducts->current()->getCost();
         // Check if the min open price is less than target price, then set the lower of two
         if ($parentKeyProducts->current()->getCost() > 0) {
             $minPrice = $parentKeyProducts->current()->getCost() < $parentKeyRequisitionEntries->getMinOpenPrice() ? $parentKeyProducts->current()->getCost() : $parentKeyRequisitionEntries->getMinOpenPrice();
         } else {
             $minPrice = $parentKeyRequisitionEntries->getMinOpenPrice();
         }
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["minOpenPrice"] = $minPrice;
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["MOPTotalImport"] = $parentKeyRequisitionEntries->getTotalQuantity() * $minPrice;
         // Check if the parent key have budgets then set true or if it don't have budgets then set false
         $parentKeyBudgets = $budgets->filterByKeyMother($parentKey);
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["hasBudgets"] = $parentKeyBudgets->count() > 0 ? true : false;
         // Check if a key mother budget is autorized (prevent to no save more budgets when one key mother budget is autoprized)
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["hasAutorizedBudget"] = $parentKeyBudgets->checkAutorized();
         // Set all requisition entries of the parent key
         $requisitionEntriesGroupByParentKey[$parentKey]["requisitionEntries"] = $parentKeyRequisitionEntries;
         $requisitionEntriesGroupByParentKey[$parentKey]["autorizedBudget"] = $parentKeyBudgets->getAutorizedOrElse(new KeyMotherSupplierBudget());
     }
     if ($post["order"] == "date_desc") {
         $requisitionEntriesGroupByParentKey = array_reverse($requisitionEntriesGroupByParentKey);
     }
     // Assign all information to view
     $this->view->requisitions = $requisitions;
     $this->view->contentTitle = $this->i18n->_("Open Requisition by Item");
     $this->view->emptySupplier = new SapSupplier();
     $this->view->requisitionEntriesGroupByParentKey = $requisitionEntriesGroupByParentKey;
     $this->view->products = $products;
     $this->view->suppliers = $suppliers;
     $this->view->incoterms = array("" => $this->i18n->_("Select a Incoterm")) + IncotermQuery::create()->find()->toCombo();
     $this->view->currencies = $currencies = CurrencyQuery::create()->find();
     $this->view->currenciesToCombo = array("" => $this->i18n->_("Select a Currency")) + $currencies->toCombo();
     $this->view->status = array("" => $this->i18n->_("All")) + array_flip($allowedStatus);
     $this->view->allowedStatus = $allowedStatus;
     $this->view->countries = array("" => $this->i18n->_("All")) + CountryQuery::create()->find()->toCombo();
     $this->view->forwarders = array("" => $this->i18n->_("Select a Forwarder")) + ForwarderQuery::create()->actives()->find()->toCombo();
     $this->view->special = Requisition::$Type['Quick'];
     $this->view->portsCustom = array("" => $this->i18n->_("Select a Port Custom"));
     $this->view->courtyards = array("" => $this->i18n->_("Select a Courtyard"));
     $this->view->order = array("" => $this->i18n->_("Select a Order"), "date_asc" => $this->i18n->_("By First Date"), "date_desc" => $this->i18n->_("By Last Date"), "product" => $this->i18n->_("By Product"));
     $this->view->setTpl("Entries");
 }