示例#1
0
 public static function convertPriceToValuesArray($pHPExcelObject)
 {
     if (!$pHPExcelObject) {
         return "";
     }
     $importPriceManager = ImportPriceManager::getInstance(null, null);
     $ret = array();
     $sheetCount = $pHPExcelObject->getSheetCount();
     for ($sheetIndex = 0; $sheetIndex < $sheetCount; $sheetIndex++) {
         $ret[$sheetIndex] = $importPriceManager->loadCompanyPrice($pHPExcelObject, $sheetIndex);
     }
     return $ret;
 }
 public function load()
 {
     ini_set('max_execution_time', '120');
     ini_set('memory_limit', "1G");
     $importPriceManager = ImportPriceManager::getInstance($this->config, $this->args);
     $company_id = $_REQUEST['company_id'];
     $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
     $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($company_id);
     $selectPriceIndex = 0;
     if (isset($_REQUEST['price_index'])) {
         $selectPriceIndex = intval($_REQUEST['price_index']);
     }
     $companyPriceNames = array();
     foreach ($companyLastPrices as $priceIndex => $priceDto) {
         $companyPriceNames[$priceIndex] = 'Price' . ($priceIndex + 1);
     }
     $this->addParam('price_names', $companyPriceNames);
     $this->addParam('selected_price_index', $selectPriceIndex);
     $companyPriceSheetsNames = $importPriceManager->getCompanyPriceSheetsNamesFromCache($company_id, $selectPriceIndex);
     $this->addParam('price_sheets_names', $companyPriceSheetsNames);
     $selectSheetIndex = 0;
     if (isset($_REQUEST['sheet_index'])) {
         $selectSheetIndex = intval($_REQUEST['sheet_index']);
     }
     $this->addParam('selected_sheet_index', $selectSheetIndex);
     $selected_rows_index = array();
     if (isset($_REQUEST['selected_rows_index']) && strlen($_REQUEST['selected_rows_index']) > 0) {
         $selected_rows_index = explode(',', $_REQUEST['selected_rows_index']);
     }
     $this->addParam('selected_rows_index', $selected_rows_index);
     $values = $importPriceManager->loadCompanyPriceFromCache($company_id, $selectPriceIndex, $selectSheetIndex);
     if (!$values) {
         $this->addParam('priceNotFound', true);
         return false;
     }
     $this->addParam('priceNotFound', false);
     /* foreach ($values as $rowKey => $row) {
        foreach ($row as $cellKey => $cellValue) {
        echo '[' . $rowKey . '][' . $cellKey . ']=' . $cellValue . ', ';
        }
        echo '<br>';
        }exit; */
     $this->addParam('priceColumnOptions', ImportPriceManager::$COLUMNS);
     $this->addParam('allColumns', array_keys($importPriceManager->getColumnsNamesMap()));
     $this->addParam('valuesByRows', $values);
     $itemModelColumnName = $importPriceManager->getItemModelColumnName();
     if (isset($itemModelColumnName)) {
         $this->addParam('modelColumnName', $itemModelColumnName);
     }
     $itemNameColumnName = $importPriceManager->getItemNameColumnName();
     $this->addParam('itemNameColumnName', $itemNameColumnName);
     $dealerPriceColumnName = $importPriceManager->getDealerPriceColumnName();
     if (isset($dealerPriceColumnName)) {
         $this->addParam('dealerPriceColumnName', $dealerPriceColumnName);
     }
     $dealerPriceAmdColumnName = $importPriceManager->getDealerPriceAmdColumnName();
     if (isset($dealerPriceAmdColumnName)) {
         $this->addParam('dealerPriceAmdColumnName', $dealerPriceAmdColumnName);
     }
     $vatPriceColumnName = $importPriceManager->getVatPriceColumnName();
     if (isset($vatPriceColumnName)) {
         $this->addParam('vatPriceColumnName', $vatPriceColumnName);
     }
     $vatPriceAmdColumnName = $importPriceManager->getVatPriceAmdColumnName();
     if (isset($vatPriceAmdColumnName)) {
         $this->addParam('vatPriceAmdColumnName', $vatPriceAmdColumnName);
     }
 }
 public function cachePriceInTables($companyId, $priceIndex)
 {
     $priceTextsManager = PriceTextsManager::getInstance($this->config, $this->args);
     $priceValuesManager = PriceValuesManager::getInstance($this->config, $this->args);
     $importPriceManager = ImportPriceManager::getInstance($this->config, $this->args);
     $priceSheetsManager = PriceSheetsManager::getInstance($this->config, $this->args);
     $companyLastPrices = $this->getCompanyLastPrices($companyId);
     if (empty($companyLastPrices) || !array_key_exists($priceIndex, $companyLastPrices)) {
         return false;
     }
     $companyLastPrice = $companyLastPrices[$priceIndex];
     $file = DATA_DIR . "/companies_prices/" . $companyId . '/' . $companyLastPrice->getFileName() . '.' . $companyLastPrice->getFileExt();
     if (!file_exists($file)) {
         return false;
     }
     $priceTextsManager->setCompanyPriceValuesReady($companyId, 0);
     $pHPExcelObject = ExcelUtils::getPHPExcelObject($file);
     $convertToText = ExcelUtils::convertToText($pHPExcelObject);
     if ($priceIndex == 0) {
         $priceTextsManager->setCompanyPriceText($companyId, $convertToText);
     } else {
         $priceTextsManager->appendCompanyPriceText($companyId, $convertToText);
     }
     $arrayValues = ExcelUtils::convertPriceToValuesArray($pHPExcelObject);
     if ($priceIndex == 0) {
         $priceValuesManager->setPriceValues($companyId, $priceIndex, $arrayValues);
     } else {
         $priceValuesManager->addPriceValues($companyId, $priceIndex, $arrayValues);
     }
     list($sheetNames, $sheetStates) = $importPriceManager->getCompanyPriceSheetsNames($pHPExcelObject);
     if ($priceIndex == 0) {
         $priceSheetsManager->deleteByField('company_id', $companyId);
     }
     foreach ($sheetNames as $sheetIndex => $sheetName) {
         $priceSheetsManager->addRow($companyId, $priceIndex, $sheetName, $sheetStates[$sheetIndex]);
     }
     $priceTextsManager->setCompanyPriceValuesReady($companyId, 1);
 }
 public function load()
 {
     ini_set('max_execution_time', '120');
     $itemManager = ItemManager::getInstance($this->config, $this->args);
     $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args);
     $importPriceManager = ImportPriceManager::getInstance($this->config, $this->args);
     $company_id = $_REQUEST['company_id'];
     $selectSheetIndex = intval($_REQUEST['sheet_index']);
     $selectPriceIndex = intval($_REQUEST['price_index']);
     if (!isset($_REQUEST['aceptable_simillarity_percent'])) {
         $acepableItemSimillarityPercent = 50;
     } else {
         $acepableItemSimillarityPercent = intval($_REQUEST['aceptable_simillarity_percent']);
     }
     $this->addParam('company_id', $company_id);
     $this->addParam('acepableItemSimillarityPercent', $acepableItemSimillarityPercent);
     $this->addParam('acepableItemSimillarityPercentOptions', array('20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70', '75', '80', '85', '90'));
     $customerLogin = $this->getCustomerLogin();
     $used_columns_indexes_array = explode(',', $_REQUEST['used_columns_indexes']);
     $this->addParam('used_columns_indexes_array', implode(',', $used_columns_indexes_array));
     if (!(isset($_REQUEST['dont_recalculate']) && $_REQUEST['dont_recalculate'] == 1)) {
         $values = $importPriceManager->loadCompanyPriceFromCache($company_id, $selectPriceIndex, $selectSheetIndex);
         $importItemsTempManager->deleteCustomerRows($customerLogin);
         $used_columns_ids_array = explode(',', $_REQUEST['used_columns_ids']);
         $selected_rows_index = array();
         //following strlen is important to accept "0" value
         if (isset($_REQUEST['selected_rows_index']) && strlen($_REQUEST['selected_rows_index']) > 0) {
             $selected_rows_index = explode(',', $_REQUEST['selected_rows_index']);
         }
         //            $itemNamesArray = array();
         //            foreach ($values as $index => $row) {
         //                if (!in_array($index, $selected_rows_index)) {
         //                    continue;
         //                }
         //                $nameColumn = "";
         //                foreach ($used_columns_ids_array as $key => $cellId) {
         //                    if ($used_columns_indexes_array[$key] == 2) {
         //                        $nameColumn .= ($row[$cellId] . ' ');
         //                    }
         //                }
         //                $itemNamesArray[$index] = $nameColumn;
         //            }
         //            $keys = array_keys($itemNamesArray);
         //            $itemNames = implode('!@<>?$#|', $itemNamesArray);
         //            $itemNames = LanguageManager::translateItemDisplayNameNonEnglishWordsToEnglish($itemNames);
         //            $itemNames = preg_replace('/[^(\x20-\x7F)]*/', '', $itemNames);
         //            if (count($keys) > 0) {
         //                $itemNamesArray = explode('!@<>?$#|', $itemNames);
         //            } else {
         //                $itemNamesArray = array();
         //            }
         //            $itemNamesArray = array_combine($keys, $itemNamesArray);
         $brand_model_name_concat_method = $_REQUEST['brand_model_name_concat_method'];
         $priceTranslationsManager = PriceTranslationsManager::getInstance($this->config, $this->args);
         foreach ($values as $index => $row) {
             if (!in_array($index, $selected_rows_index)) {
                 continue;
             }
             $nameColumn = "";
             foreach ($used_columns_ids_array as $key => $cellId) {
                 if ($used_columns_indexes_array[$key] == 1) {
                     $modelColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 2) {
                     $nameColumn .= $priceTranslationsManager->translateItemDisplayNameNonEnglishWordsToEnglish($row[$cellId]) . ' ';
                     $nameColumn = preg_replace('/[^(\\x20-\\x7F)]*/', '', $nameColumn);
                 }
                 if ($used_columns_indexes_array[$key] == 3) {
                     $dealerPriceColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 4) {
                     $dealerPriceAmdColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 5) {
                     $vatPriceColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 6) {
                     $vatPriceAmdColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 7) {
                     $warrantyMonthColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 8) {
                     $warrantyYearColumn = $row[$cellId];
                 }
                 if ($used_columns_indexes_array[$key] == 9) {
                     $brandColumn = $row[$cellId];
                 }
             }
             if ($brand_model_name_concat_method === 'bmn') {
                 $nameColumn = $brandColumn . ' ' . $modelColumn . ' ' . $nameColumn;
             } elseif ($brand_model_name_concat_method === 'bn') {
                 $nameColumn = $brandColumn . ' ' . $nameColumn;
             } elseif ($brand_model_name_concat_method === 'mn') {
                 $nameColumn = $modelColumn . ' ' . $nameColumn;
             }
             $importItemsTempManager->addRow($customerLogin, $modelColumn, $nameColumn, $dealerPriceColumn, $dealerPriceAmdColumn, $vatPriceColumn, $vatPriceAmdColumn, $warrantyMonthColumn, $warrantyYearColumn, $brandColumn);
         }
     }
     $priceRowsDtos = $importItemsTempManager->getUserCurrentRows($customerLogin);
     $columnNames = $importPriceManager->getColumnNamesMap($used_columns_indexes_array);
     $this->addParam('columnNames', $columnNames);
     $companyAllItems = $itemManager->getCompanyItems($company_id, true);
     $convertDtosArrayToArrayMapById = $this->convertDtosArrayToArrayMapById($companyAllItems);
     $this->addParam('stockItemsDtosMappedByIds', $convertDtosArrayToArrayMapById);
     //$t = microtime(true);
     if (!(isset($_REQUEST['dont_recalculate']) && $_REQUEST['dont_recalculate'] == 1)) {
         $stockAndPriceItemsMatchingMap = $this->getStockAndPriceItemsMatchingMap($priceRowsDtos, $companyAllItems, $acepableItemSimillarityPercent);
         $cycleCount = 0;
         while ($this->getStockAndPriceItemsMatchingMap($priceRowsDtos, $companyAllItems, $acepableItemSimillarityPercent, true, $stockAndPriceItemsMatchingMap)) {
             $cycleCount++;
         }
         foreach ($stockAndPriceItemsMatchingMap as $stockItemId => $priceItemIdAndSimilarPercentPairArray) {
             $rowId = $priceItemIdAndSimilarPercentPairArray[0];
             $importItemsTempManager->setMatchedItemId($rowId, $stockItemId);
             $shortSpec = $convertDtosArrayToArrayMapById[$stockItemId]->getShortDescription();
             $fullSpec = $convertDtosArrayToArrayMapById[$stockItemId]->getFullDescription();
             $importItemsTempManager->updateTextField($rowId, 'short_spec', $shortSpec);
             $importItemsTempManager->updateTextField($rowId, 'full_spec', $fullSpec);
         }
     }
     $priceRowsDtos = $importItemsTempManager->getUserCurrentRows($customerLogin);
     //getting metched stock items ids
     $matchedStockItemIdsArray = array();
     foreach ($priceRowsDtos as $priceRowDto) {
         $matchedItemId = $priceRowDto->getMatchedItemId();
         if (intval($matchedItemId) > 0) {
             $matchedStockItemIdsArray[] = intval($matchedItemId);
         }
     }
     //getting company items which are not matched to any item in price table
     $unmatchedCompanyStockItems = array();
     foreach ($companyAllItems as $stockItemDto) {
         $itemId = intval($stockItemDto->getId());
         if (!in_array($itemId, $matchedStockItemIdsArray)) {
             $unmatchedCompanyStockItems[$itemId] = $stockItemDto;
         }
     }
     $this->addParam('unmatchedCompanyItems', $unmatchedCompanyStockItems);
     $this->addParam('priceRowsDtos', $priceRowsDtos);
     $this->addParam('matched_price_items_count', count($stockAndPriceItemsMatchingMap));
     $this->addParam('unmatched_price_items_count', count($priceRowsDtos) - count($stockAndPriceItemsMatchingMap));
 }