/** * Returns an singleton instance of this class * * @param object $config * @param object $args * @return */ public static function getInstance($config, $args) { if (self::$instance == null) { self::$instance = new ImportPriceManager($config, $args); } return self::$instance; }
public function load() { $company_id = $_REQUEST['company_id']; $used_columns_indexes_array = array(2, 1, 9, 3, 4, 5, 6, 7); //explode(',', $_REQUEST['used_columns_indexes']); $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); $categoryHierarchyManager = CategoryHierarchyManager::getInstance($this->config, $this->args); $categoryManager = CategoryManager::getInstance($this->config, $this->args); $customerLogin = $this->getCustomerLogin(); $priceRowsDtos = $importItemsTempManager->getUserCurrentPriceChangedRows($customerLogin); $columnNames = ImportPriceManager::getColumnNamesMap($used_columns_indexes_array); $rootDto = $categoryManager->getRoot(); $firstLevelCategoriesHierarchyDtos = $categoryHierarchyManager->getCategoryChildren($rootDto->getId()); $firstLevelCategoriesNamesDtos = $categoryHierarchyManager->getCategoriesNamesByParentCategoryId($rootDto->getId()); $firstLevelCategoriesIds = array(); foreach ($firstLevelCategoriesHierarchyDtos as $key => $category) { $firstLevelCategoriesIds[] = $category->getChildId(); } $firstLevelCategoriesNames = array(); foreach ($firstLevelCategoriesNamesDtos as $key => $category) { $firstLevelCategoriesNames[] = $category->getDisplayName(); } $itemManager = ItemManager::getInstance($this->config, $this->args); $companyAllItems = $itemManager->getCompanyItems($company_id, true); $convertDtosArrayToArrayMapById = $this->convertDtosArrayToArrayMapById($companyAllItems); $this->addParam('stockItemsDtosMappedByIds', $convertDtosArrayToArrayMapById); $this->addParam('columnNames', $columnNames); $this->addParam('priceRowsDtos', $priceRowsDtos); $this->addParam('firstLevelCategoriesNames', $firstLevelCategoriesNames); $this->addParam('firstLevelCategoriesIds', $firstLevelCategoriesIds); list($changedRowIds, $changedFields) = $this->findChanges($priceRowsDtos, $convertDtosArrayToArrayMapById, $columnNames); $this->addParam('changedRowsIds', $changedRowIds); $this->addParam('changedFields', $changedFields); }
public function load() { //new items import level $company_id = $_REQUEST['company_id']; $used_columns_indexes_array = array(2, 1, 9, 3, 4, 5, 6, 7); //explode(',', $_REQUEST['used_columns_indexes']); $importItemsTempManager = ImportItemsTempManager::getInstance($this->config, $this->args); $categoryHierarchyManager = CategoryHierarchyManager::getInstance($this->config, $this->args); $categoryManager = CategoryManager::getInstance($this->config, $this->args); $customerLogin = $this->getCustomerLogin(); $priceRowsDtos = $importItemsTempManager->getUserCurrentPriceNewRows($customerLogin); foreach ($priceRowsDtos as $dto) { $itemModel = $dto->getModel(); if (empty($itemModel)) { $model = $importItemsTempManager->findModelFromItemTitle($dto->getDisplayName()); if (!empty($model)) { $dto->setSupposedModel($model); } } else { $dto->setSupposedModel($itemModel); } } $columnNames = ImportPriceManager::getColumnNamesMap($used_columns_indexes_array); $rootDto = $categoryManager->getRoot(); $firstLevelCategoriesHierarchyDtos = $categoryHierarchyManager->getCategoryChildren($rootDto->getId()); $firstLevelCategoriesNamesDtos = $categoryHierarchyManager->getCategoriesNamesByParentCategoryId($rootDto->getId()); $firstLevelCategoriesIds = array(); foreach ($firstLevelCategoriesHierarchyDtos as $key => $category) { $firstLevelCategoriesIds[] = $category->getChildId(); } $firstLevelCategoriesNames = array(); foreach ($firstLevelCategoriesNamesDtos as $key => $category) { $firstLevelCategoriesNames[] = $category->getDisplayName(); } $this->addParam('columnNames', $columnNames); $this->addParam('priceRowsDtos', $priceRowsDtos); $this->addParam('firstLevelCategoriesNames', $firstLevelCategoriesNames); $this->addParam('firstLevelCategoriesIds', $firstLevelCategoriesIds); if (isset($_REQUEST['new_items_row_ids'])) { $this->addParam('new_items_row_ids', explode(',', $_REQUEST['new_items_row_ids'])); } //$json_parsed_price = $_REQUEST['json_parsed_price']; //$parsed_price_array = json_decode($json_parsed_price); /* $companyItems = $itemManager->getCompanyItems($company_id, true); $stockItemModels = array(); $stockItemNames = array(); $stockItemDealerPrices = array(); $stockItemVatPrices = array(); $stockItemIsHidden = array(); foreach ($companyItems as $itemDto) { $stockItemModels[] = } */ }
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 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 addRow($customerLogin, $modelColumn, $nameColumn, $dealerPriceColumn, $dealerPriceAmdColumn, $vatPriceColumn, $vatPriceAmdColumn, $warrantyMonthColumn, $warrantyYearColumn, $brandColumn) { $itemManager = ItemManager::getInstance($this->config, $this->args); $modelColumn = trim(preg_replace('/\\s+/', ' ', $modelColumn)); $nameColumn = trim(preg_replace('/\\s+/', ' ', $nameColumn)); $warrantyMonthColumn = trim(preg_replace('/\\s+/', ' ', $warrantyMonthColumn)); $warrantyYearColumn = trim(preg_replace('/\\s+/', ' ', $warrantyYearColumn)); $brandColumn = trim(preg_replace('/\\s+/', ' ', $brandColumn)); $dto = $this->mapper->createDto(); $dto->setLogin($customerLogin); $dto->setDisplayName($nameColumn); $dto->setOriginalDisplayName($nameColumn); if (isset($modelColumn)) { $dto->setModel($modelColumn); $dto->setOriginalModel($modelColumn); } if (isset($dealerPriceColumn)) { $dto->setDealerPrice(ImportPriceManager::convertCurrencyToDollar($dealerPriceColumn)); $dto->setOriginalDealerPrice($dealerPriceColumn); } if (isset($dealerPriceAmdColumn)) { $AMDprice = ImportPriceManager::convertCurrencyToAmd($dealerPriceAmdColumn); $dto->setDealerPriceAmd($AMDprice); $dto->setOriginalDealerPriceAmd($dealerPriceAmdColumn); if (!isset($dealerPriceColumn)) { $dealerPriceUSD = $itemManager->exchangeFromAMDToUSD($AMDprice); $dto->setDealerPrice($dealerPriceUSD); } } if (isset($vatPriceColumn)) { $usdPrice = ImportPriceManager::convertCurrencyToDollar($vatPriceColumn); $dto->setVatPrice($usdPrice); $dto->setOriginalVatPrice($vatPriceColumn); if (!isset($dealerPriceColumn)) { $dto->setDealerPrice($usdPrice); $dto->setOriginalDealerPrice($vatPriceColumn); } } if (isset($vatPriceAmdColumn)) { $ADMprice = ImportPriceManager::convertCurrencyToAmd($vatPriceAmdColumn); $dto->setVatPriceAmd($ADMprice); $dto->setOriginalVatPriceAmd($vatPriceAmdColumn); if (!isset($dealerPriceAmdColumn)) { $dto->setDealerPriceAmd($ADMprice); $dto->setOriginalDealerPriceAmd($vatPriceAmdColumn); } if (!isset($vatPriceColumn) && !isset($dealerPriceColumn)) { $dealerPriceUSD = $itemManager->exchangeFromAMDToUSD($ADMprice); $dto->setDealerPrice($dealerPriceUSD); $dto->setVatPrice($dealerPriceUSD); } } if (!empty($brandColumn)) { $brand = $this->findBrandFromItemTitle($brandColumn); $dto->setBrand($brand); $dto->setOriginalBrand($brandColumn); } else { $brand = $this->findBrandFromItemTitle($nameColumn); $dto->setBrand($brand); } if (isset($warrantyMonthColumn)) { $dto->setWarrantyMonths(ImportPriceManager::convertWarrantyMonthsFieldToWarrantyMonths($warrantyMonthColumn)); $dto->setOriginalWarranty($warrantyMonthColumn); } if (isset($warrantyYearColumn)) { $dto->setWarrantyMonths(ImportPriceManager::convertWarrantyYearsFieldToWarrantyMonths($warrantyYearColumn)); $dto->setOriginalWarranty($warrantyYearColumn); } $this->mapper->insertDto($dto, false); }
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); } }
private function getStockAndPriceItemsMatchingMap($priceItemsDtos, $stockItemsDtos, $acepableItemSimillarityPercent, $checkDuplication = false, &$matchItemsIdsMap = null) { if (!isset($matchItemsIdsMap)) { $matchItemsIdsMap = array(); } $atLeastOneMatched = false; foreach ($priceItemsDtos as $priceItemDto) { if ($checkDuplication && $this->isPriceItemAlreadyMatechedToStockItem($priceItemDto->getId(), $matchItemsIdsMap)) { //checks if item already matched then skip this item continue; } $maxSimilarItemPercent = 0; foreach ($stockItemsDtos as $stockItemDto) { if ($checkDuplication && array_key_exists($stockItemDto->getId(), $matchItemsIdsMap)) { continue; } $similarItemsPercent = ImportPriceManager::getSimilarItemsPercent($stockItemDto, $priceItemDto); if ($similarItemsPercent > $maxSimilarItemPercent) { $maxSimilarItemPercent = $similarItemsPercent; $maxSimilarStockItemDto = $stockItemDto; } } if ($maxSimilarItemPercent > $acepableItemSimillarityPercent) { if (!array_key_exists($maxSimilarStockItemDto->getId(), $matchItemsIdsMap)) { $atLeastOneMatched = true; $matchItemsIdsMap[$maxSimilarStockItemDto->getId()] = array($priceItemDto->getId(), $maxSimilarItemPercent); } else { if ($maxSimilarItemPercent > $matchItemsIdsMap[$maxSimilarStockItemDto->getId()][1]) { $atLeastOneMatched = true; $matchItemsIdsMap[$maxSimilarStockItemDto->getId()] = array($priceItemDto->getId(), $maxSimilarItemPercent); } } } } if ($checkDuplication) { return $atLeastOneMatched; } return $matchItemsIdsMap; }