/**
  * getRegionsList
  * @return array regions (locations) list
  */
 public static function getRegionsList($countryId = 0, $bFlip = false)
 {
     static $arRegions = array();
     $flipIndex = intval($bFlip);
     if (isset($arRegions[$countryId][$flipIndex])) {
         return $arRegions[$countryId][$flipIndex];
     }
     if (CSaleLocation::isLocationProMigrated()) {
         $types = array();
         $res = \Bitrix\Sale\Location\TypeTable::getList(array('select' => array('ID', 'CODE')));
         while ($item = $res->fetch()) {
             $types[$item['CODE']] = $item['ID'];
         }
         $filter = array(array('LOGIC' => 'OR', array('=TYPE_ID' => $types['CITY'], '=NAME.LANGUAGE_ID' => LANGUAGE_ID, array('LOGIC' => 'OR', array('=PARENT.TYPE_ID' => $types['COUNTRY']), array('=PARENT.TYPE_ID' => $types['COUNTRY_DISTRICT']), array('=PARENT_ID' => '0'))), array('=TYPE_ID' => $types['REGION'])));
         if (intval($countryId)) {
             $filter['=PARENTS.TYPE_ID'] = $types['COUNTRY'];
             $filter['=PARENTS.ID'] = $countryId;
         }
         $dbRegionList = \Bitrix\Sale\Location\LocationTable::getList(array('filter' => $filter, 'select' => array('ID', 'CODE', 'NAME_LANG' => 'NAME.NAME'), 'order' => array('NAME.NAME' => 'asc')));
     } else {
         $arFilterRegion = array();
         if (intval($countryId) > 0) {
             $arFilterRegion["COUNTRY_ID"] = $countryId;
         }
         $dbRegionList = CSaleLocation::GetRegionList(array("NAME_LANG" => "ASC"), $arFilterRegion, LANGUAGE_ID);
     }
     $key = 'ID';
     while ($arRegionList = $dbRegionList->Fetch()) {
         if ($key == 'ID' && isset($arRegionList['CODE'])) {
             $key = 'CODE';
         }
         if ($key == 'CODE' && strlen($arRegionList['CODE']) <= 0) {
             continue;
         }
         $arRegions[$countryId][0][$arRegionList[$key]] = $arRegionList["NAME_LANG"];
         // $bFlip == false
         $arRegions[$countryId][1][$arRegionList["NAME_LANG"]] = $arRegionList[$key];
         // $bFlip == true
     }
     return isset($arRegions[$countryId][$flipIndex]) ? $arRegions[$countryId][$flipIndex] : array();
 }
Example #2
0
 public static function initializeData()
 {
     $locationTable = Location\LocationTable::getTableName();
     $groupLocationTable = Location\GroupLocationTable::getTableName();
     $siteLocationTable = Location\SiteLocationTable::getTableName();
     // ORACLE: OK, MSSQL: OK
     $sql = "\n\t\t\tinsert into " . static::getTableName() . " \n\t\t\t\t(LOCATION_ID, SITE_ID) \n\t\t\tselect LC.ID, LS.SITE_ID\n\t\t\t\tfrom " . $siteLocationTable . " LS\n\t\t\t\t\tinner join " . $locationTable . " L on LS.LOCATION_ID = L.ID and LS.LOCATION_TYPE = 'L'\n\t\t\t\t\tinner join " . $locationTable . " LC on LC.LEFT_MARGIN >= L.LEFT_MARGIN and LC.RIGHT_MARGIN <= L.RIGHT_MARGIN\n\t\t\tunion \n\t\t\tselect LC.ID, LS.SITE_ID\n\t\t\t\tfrom " . $siteLocationTable . " LS\n\t\t\t\t\tinner join " . $groupLocationTable . " LG on LS.LOCATION_ID = LG.LOCATION_GROUP_ID and LS.LOCATION_TYPE = 'G'\n\t\t\t\t\tinner join " . $locationTable . " L on LG.LOCATION_ID = L.ID\n\t\t\t\t\tinner join " . $locationTable . " LC on LC.LEFT_MARGIN >= L.LEFT_MARGIN and LC.RIGHT_MARGIN <= L.RIGHT_MARGIN\n\t\t";
     Main\HttpApplication::getConnection()->query($sql);
 }
Example #3
0
 protected static function getUpperCityId($locationId)
 {
     if (strlen($locationId) <= 0) {
         return 0;
     }
     $res = LocationTable::getList(array('filter' => array(array('LOGIC' => 'OR', '=CODE' => $locationId, '=ID' => $locationId), '=PARENTS.TYPE.CODE' => 'CITY'), 'select' => array('ID', 'CODE', 'PID' => 'PARENTS.ID')));
     if ($loc = $res->fetch()) {
         return $loc['PID'];
     }
     return 0;
 }
Example #4
0
 public static function isLocationsCreated()
 {
     if (CSaleLocation::isLocationProMigrated()) {
         $res = Location\LocationTable::getList(array('select' => array('CNT')))->fetch();
         return $res['CNT'] > 0;
     }
     $dbResultList = CSaleLocation::GetList();
     if ($dbResultList->Fetch()) {
         return true;
     }
     return false;
 }
Example #5
0
 public static function reInitData()
 {
     static::cleanUp();
     $offset = 0;
     $stat = array();
     $types = array();
     $typeSort = array();
     $res = Location\TypeTable::getList(array('select' => array('ID', 'CODE', 'SORT')));
     while ($item = $res->fetch()) {
         if ($item['CODE'] == 'CITY' || $item['CODE'] == 'VILLAGE' || $item['CODE'] == 'STREET') {
             $types[$item['CODE']] = $item['ID'];
         }
         $typeSort[$item['ID']] = $item['SORT'];
     }
     $typesBack = array_flip($types);
     //_print_r($types);
     //_print_r($typeSort);
     while (true) {
         $res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID'), 'filter' => array('=TYPE_ID' => array_values($types)), 'limit' => self::STEP_SIZE, 'offset' => $offset));
         $cnt = 0;
         while ($item = $res->fetch()) {
             $resPath = Location\LocationTable::getPathToNode($item['ID'], array('select' => array('ID', 'TYPE_ID'), 'filter' => array('=TYPE_ID' => array_values($types))));
             $path = array();
             while ($pItem = $resPath->fetch()) {
                 $path[$typesBack[$pItem['TYPE_ID']]] = $pItem['ID'];
             }
             //_print_r($path);
             $data = array('CITY_ID' => isset($path['CITY']) ? $path['CITY'] : 0, 'VILLAGE_ID' => isset($path['VILLAGE']) ? $path['VILLAGE'] : 0, 'STREET_ID' => isset($path['STREET']) ? $path['STREET'] : 0, 'TYPE_SORT' => $typeSort[$item['TYPE_ID']], 'LOCATION_ID' => $item['ID']);
             //_print_r($data);
             foreach ($data as &$value) {
                 $value = "'" . $value . "'";
             }
             //static::add($data);
             $GLOBALS['DB']->query("insert into " . static::getTableName() . " (CITY_ID, VILLAGE_ID, STREET_ID, TYPE_SORT, LOCATION_ID) values (" . implode(', ', $data) . ")");
             $cnt++;
         }
         if (!$cnt) {
             break;
         }
         $offset += self::STEP_SIZE;
     }
 }
Example #6
0
 protected static function processSearchRequestV2GetAdditional(&$data, $parameters)
 {
     if (!empty($data['ITEMS']) && is_array($parameters['additionals'])) {
         if (in_array('PATH', $parameters['additionals'])) {
             // show path to each found node
             static::processSearchRequestV2GetAdditionalPathNodes($data, $parameters);
         }
         // show common count of items by current filter
         if (in_array('CNT_BY_FILTER', $parameters['additionals']) && is_array($parameters['filter'])) {
             $item = Location\LocationTable::getList(array('select' => array('CNT'), 'filter' => $parameters['filter']))->fetch();
             $data['ETC']['CNT_BY_FILTER'] = $item['CNT'];
         }
         // show parent item in case of PARENT_ID condition in filter
         if (in_array('PARENT_ITEM', $parameters['additionals'])) {
             $id = false;
             if (intval($parameters['filter']['=PARENT_ID'])) {
                 $id = intval($parameters['filter']['=PARENT_ID']);
             } elseif (intval($parameters['filter']['PARENT_ID'])) {
                 $id = intval($parameters['filter']['PARENT_ID']);
             }
             if ($id !== false) {
                 $path = array();
                 $data['ETC']['PATH_ITEMS'] = array();
                 $res = Location\LocationTable::getPathToNode($id, array('select' => array('VALUE' => 'ID', 'CODE', 'TYPE_ID', 'DISPLAY' => 'NAME.NAME'), 'filter' => array('=NAME.LANGUAGE_ID' => strlen($parameters['filter']['=NAME.LANGUAGE_ID']) ? $parameters['filter']['=NAME.LANGUAGE_ID'] : LANGUAGE_ID)));
                 $node = array();
                 while ($item = $res->fetch()) {
                     $path[] = intval($item['VALUE']);
                     $data['ETC']['PATH_ITEMS'][$item['VALUE']] = $item;
                     $node = $item;
                 }
                 $node['PATH'] = array_reverse($path);
                 $data['ETC']['PARENT_ITEM'] = $node;
             }
         }
     }
     return $data;
 }
 private static function calculatePackPrice($arPackage, $profile, $arConfig, $arLocationTo)
 {
     $arDebug = array();
     /*1 Land price
     		1.1 Base Price less 10 kg*/
     $code = self::getRegionCodeByOldName($arLocationTo['REGION_NAME_LANG']);
     // old location
     if (strlen($code) <= 0 && CSaleLocation::isLocationProMigrated()) {
         $dbRes = Location\LocationTable::getList(array('filter' => array('=TYPE.CODE' => 'REGION', '=REGION_ID' => intval($arLocationTo["REGION_ID"]), '=CITY_ID' => false), 'select' => array('ID', 'CODE', 'NAME')));
         if ($locReg = $dbRes->fetch()) {
             $code = $locReg["CODE"];
         }
     }
     if (strlen($code) <= 0) {
         throw new \Bitrix\Main\SystemException(GetMessage("SALE_DH_RP_ERROR_LOCATION_NOT_FOUND"));
     }
     $zoneTo = self::getConfValue($arConfig, 'REG_' . $code);
     $basePrice = floatval(self::getConfValue($arConfig, 'ZONE_RATE_MAIN_' . $zoneTo));
     $arDebug[] = 'Base Price less 500 g: ' . $basePrice;
     if ($arPackage['WEIGHT'] > self::$BASE_WEIGHT) {
         $addWeight = ceil($arPackage['WEIGHT'] / self::$BASE_WEIGHT - 1);
         $addPrice = floatval(self::getConfValue($arConfig, 'ZONE_RATE_ADD_' . $zoneTo));
         $arDebug[] = 'Price for additional weight more than 500 g: ' . $addWeight * $addPrice;
         $basePrice += $addWeight * $addPrice;
     }
     $totalPrice = $basePrice;
     /* 1.2 Service "heavy weight" 10 - 20 kg*/
     $hwPrice = 0;
     if ($arPackage['WEIGHT'] >= self::$MAX_WEIGHT) {
         $hwTarif = floatval(self::getConfValue($arConfig, 'service_' . self::$TARIF_HEAVY_WEIGHT . '_value'));
         $hwPrice += $totalPrice * $hwTarif / 100;
         $arDebug[] = 'Heavy weight: ' . $hwPrice;
         $totalPrice += $hwPrice;
     }
     /* 1.5 Service "fragile" */
     $fPrice = 0;
     if (self::isConfCheckedVal($arConfig, 'service_' . self::$TARIF_FRAGILE . '_enabled')) {
         $fTarif = floatval(self::getConfValue($arConfig, 'service_' . self::$TARIF_FRAGILE . '_value'));
         $fPrice += $totalPrice * $fTarif / 100;
         $arDebug[] = 'Fragile: ' . $fPrice;
         $totalPrice += $fPrice;
     }
     /* 4. Service "declared value" */
     $dvPrice = 0;
     if (self::isConfCheckedVal($arConfig, 'service_' . self::$TARIF_DECLARED_VAL . '_enabled')) {
         $dvTarif = floatval(self::getConfValue($arConfig, 'service_' . self::$TARIF_DECLARED_VAL . '_value'));
         $dvPrice += ($arPackage['PRICE'] + $totalPrice) * $dvTarif;
         $arDebug[] = 'Declared value: ' . $dvPrice;
         $totalPrice += $dvPrice;
     }
     if ($profile == 'avia') {
         $aviaPrice = 0;
         $aviaPrice = floatval(self::getConfValue($arConfig, 'tarif_avia_' . self::$TARIF_AVIA_STANDART . '_value'));
         $arDebug[] = 'avia price: ' . $aviaPrice;
         $totalPrice += $aviaPrice;
         $aviaHeavyPrice = 0;
         if ($arPackage['WEIGHT'] > self::$MAX_WEIGHT) {
             $aviaHeavyPrice = floatval(self::getConfValue($arConfig, 'tarif_avia_' . self::$TARIF_AVIA_HEAVY . '_value'));
             $arDebug[] = 'avia heavy price: ' . $aviaHeavyPrice;
             $totalPrice += $aviaHeavyPrice;
         }
     }
     return $totalPrice;
 }
Example #8
0
	function DeleteAll()
	{
		global $DB;

		foreach (GetModuleEvents("sale", "OnBeforeLocationDeleteAll", true) as $arEvent)
			if (ExecuteModuleEventEx($arEvent)===false)
				return false;

		if(self::isLocationProMigrated())
		{
			//main
			$DB->Query("DELETE FROM ".Location\LocationTable::getTableName());
			$DB->Query("DELETE FROM ".Location\GroupTable::getTableName());
			$DB->Query("DELETE FROM ".Location\TypeTable::getTableName());

			//names
			$DB->Query("DELETE FROM ".Location\Name\LocationTable::getTableName());
			$DB->Query("DELETE FROM ".Location\Name\GroupTable::getTableName());
			$DB->Query("DELETE FROM ".Location\Name\TypeTable::getTableName());

			//links
			$DB->Query("DELETE FROM ".Location\GroupLocationTable::getTableName());
			$DB->Query("DELETE FROM ".Location\SiteLocationTable::getTableName());
			$DB->Query("DELETE FROM ".Delivery\DeliveryLocationTable::getTableName());
			
			//other
			$DB->Query("DELETE FROM ".Location\DefaultSiteTable::getTableName());
			$DB->Query("DELETE FROM ".Location\ExternalTable::getTableName());
			$DB->Query("DELETE FROM ".Location\ExternalServiceTable::getTableName());
		}

		$DB->Query("DELETE FROM b_sale_location2location_group");
		$DB->Query("DELETE FROM b_sale_location_group_lang");
		$DB->Query("DELETE FROM b_sale_location_group");

		$DB->Query("DELETE FROM b_sale_delivery2location");
		$DB->Query("DELETE FROM b_sale_location");

		$DB->Query("DELETE FROM b_sale_location_city_lang");
		$DB->Query("DELETE FROM b_sale_location_city");

		$DB->Query("DELETE FROM b_sale_location_country_lang");
		$DB->Query("DELETE FROM b_sale_location_country");

		$DB->Query("DELETE FROM b_sale_location_region_lang");
		$DB->Query("DELETE FROM b_sale_location_region");

		$DB->Query("DELETE FROM b_sale_location_zip");

		foreach (GetModuleEvents("sale", "OnLocationDeleteAll", true) as $arEvent)
			ExecuteModuleEventEx($arEvent);

	}
Example #9
0
 public static function reInitData($parameters = array())
 {
     static::createTables();
     $offset = 0;
     $stat = array();
     $types = array();
     $typeSort = array();
     $res = Location\TypeTable::getList(array('select' => array('ID', 'CODE', 'SORT')));
     $allowedTypes = array('REGION', 'SUBREGION', 'CITY', 'VILLAGE', 'STREET');
     while ($item = $res->fetch()) {
         if (in_array($item['CODE'], $allowedTypes)) {
             $types[$item['CODE']] = $item['ID'];
         }
         $typeSort[$item['ID']] = $item['SORT'];
     }
     $typesBack = array_flip($types);
     //print_r($types);
     //_print_r($typeSort);
     $wordChain = array();
     $pathChain = array();
     //_dump_r('GO!');
     $prevDepth = 0;
     while (true) {
         $res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID', 'LNAME' => 'NAME.NAME', 'DEPTH_LEVEL', 'SORT'), 'filter' => array('=TYPE_ID' => array_values($types), '=NAME.LANGUAGE_ID' => LANGUAGE_ID), 'order' => array('LEFT_MARGIN' => 'asc'), 'limit' => self::STEP_SIZE, 'offset' => $offset));
         $cnt = 0;
         while ($item = $res->fetch()) {
             if ($item['DEPTH_LEVEL'] < $prevDepth) {
                 //print('DROP to '.$item['DEPTH_LEVEL'].'<br />');
                 // drop chain to DEPTH_LEVEL inclusively
                 $newWC = array();
                 $newPC = array();
                 foreach ($wordChain as $dl => $name) {
                     if ($dl >= $item['DEPTH_LEVEL']) {
                         break;
                     }
                     $newWC[$dl] = $name;
                 }
                 $wordChain = $newWC;
                 foreach ($pathChain as $dl => $id) {
                     if ($dl >= $item['DEPTH_LEVEL']) {
                         break;
                     }
                     $newPC[$dl] = $id;
                 }
                 $pathChain = $newPC;
             }
             $wordChain[$item['DEPTH_LEVEL']] = $item['LNAME'];
             $pathChain[$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']);
             $prevDepth = $item['DEPTH_LEVEL'];
             //print($item['DEPTH_LEVEL'].' - '.implode(' ', WordStatTable::parseQuery(implode(' ', $wordChain))).'<br />');
             $parsed = WordStatTable::parseQuery(implode(' ', $wordChain));
             $wordMap = array();
             $i = 1;
             foreach ($parsed as $word) {
                 $wordMap['W_' . $i] = $word;
                 $i++;
             }
             $pathMap = array();
             foreach ($pathChain as $elem) {
                 $pathMap[$typesBack[$elem['TYPE']] . '_ID'] = $elem['ID'];
             }
             $data = array_merge($wordMap, $pathMap, array('LOCATION_ID' => $item['ID'], 'TYPE_ID' => $item['TYPE_ID'], 'TYPE_SORT' => $typeSort[$item['TYPE_ID']], 'SORT' => $item['SORT'], 'WORD_COUNT' => count($wordMap)));
             //print('<pre>');
             //print('</pre>');
             try {
                 static::add($data);
             } catch (\Exception $e) {
                 _dump_r('Cant add ' . implode(' ', $wordChain) . ' (' . count($wordMap) . ')<br />');
                 // duplicate or smth
             }
             $cnt++;
         }
         if (!$cnt) {
             break;
         }
         $offset += self::STEP_SIZE;
     }
 }
Example #10
0
	protected function stageConvertTree()
	{
		if($this->getStep() == 0)
		{
			$this->migrator->convertTree();
			$this->nextStep();
		}
		else
		{
			Location\LocationTable::resetLegacyPath();
			$this->nextStage();
		}
	}
Example #11
0
 protected static function getLocationStringByCondition($condition, $behaviour = array('INVERSE' => false, 'DELIMITER' => ', ', 'LANGUAGE_ID' => LANGUAGE_ID))
 {
     if (isset($behaviour) && !is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['DELIMITER'])) {
         $behaviour['DELIMITER'] = ', ';
     }
     if (!isset($behaviour['LANGUAGE_ID'])) {
         $behaviour['LANGUAGE_ID'] = LANGUAGE_ID;
     }
     try {
         $res = Location\LocationTable::getPathToNodeByCondition($condition, array('select' => array('LNAME' => 'NAME.NAME'), 'filter' => array('=NAME.LANGUAGE_ID' => $behaviour['LANGUAGE_ID'])));
         $path = array();
         while ($item = $res->fetch()) {
             $path[] = $item['LNAME'];
         }
         if ($behaviour['INVERSE']) {
             $path = array_reverse($path);
         }
         return implode($behaviour['DELIMITER'], $path);
     } catch (\Bitrix\Main\SystemException $e) {
         return '';
     }
 }
Example #12
0
 private function insertTreeInfo()
 {
     // We make temporal table, place margins, parent and lang data into it, then perform an update of the old table from the temporal one.
     $this->createTemporalTable(self::TABLE_TEMP_TREE, array('ID' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)')), 'PARENT_ID' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)')), 'TYPE_ID' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)')), 'DEPTH_LEVEL' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)')), 'LEFT_MARGIN' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)')), 'RIGHT_MARGIN' => array('TYPE' => array(self::DB_TYPE_MYSQL => 'int', self::DB_TYPE_MSSQL => 'int', self::DB_TYPE_ORACLE => 'NUMBER(18)'))));
     $handle = new BlockInserter(array('tableName' => self::TABLE_TEMP_TREE, 'exactFields' => array('ID' => array('data_type' => 'integer'), 'PARENT_ID' => array('data_type' => 'integer'), 'TYPE_ID' => array('data_type' => 'integer'), 'DEPTH_LEVEL' => array('data_type' => 'integer'), 'LEFT_MARGIN' => array('data_type' => 'integer'), 'RIGHT_MARGIN' => array('data_type' => 'integer')), 'parameters' => array('mtu' => 9999)));
     // fill temporal table
     if (is_array($this->data['TREE'])) {
         foreach ($this->data['TREE'] as $id => $node) {
             $handle->insert(array('ID' => $id, 'PARENT_ID' => $node['PARENT_ID'], 'TYPE_ID' => $node['TYPE_ID'], 'DEPTH_LEVEL' => $node['DEPTH_LEVEL'], 'LEFT_MARGIN' => $node['LEFT_MARGIN'], 'RIGHT_MARGIN' => $node['RIGHT_MARGIN']));
         }
     }
     $handle->flush();
     // merge temp table with location table
     Location\LocationTable::mergeRelationsFromTemporalTable(self::TABLE_TEMP_TREE, array('TYPE_ID', 'PARENT_ID'));
     $this->dropTable(self::TABLE_TEMP_TREE);
 }
Example #13
0
	protected static function processSearchGetAdditional($result)
	{
		$result = parent::processSearchGetAdditional($result);

		// get common path of parent
		if(isset($_REQUEST['FILTER']['PARENT_ID']))
		{
			$path = array();
			$result['ETC']['PATH_NAMES'] = array();

			if($pId = intval($_REQUEST['FILTER']['PARENT_ID']))
			{
				$res = Location\LocationTable::getPathToNode($pId, array(
					'select' => array(
						'ID',
						'CODE',
						'TYPE_ID',
						'LNAME' => 'NAME.NAME'
					),
					'filter' => array(
						'NAME.LANGUAGE_ID' => static::processSearchRequestGetLang()
					)
				));
				$res->addReplacedAliases(array('LNAME' => 'NAME'));

				$node = array();
				while($item = $res->fetch())
				{
					$path[] = intval($item['ID']);
					$result['ETC']['PATH_NAMES'][$item['ID']] = $item['NAME'];

					$node = $item;
				}

				$node['PATH'] = array_reverse($path);
				$result['ETC']['PARENT_ITEM'] = $node;
			}
		}

		return $result;
	}
Example #14
0
 protected static function RebindLocationTriplet($fields = array())
 {
     $country = intval($fields['COUNTRY_ID']);
     $region = intval($fields['REGION_ID']);
     $city = intval($fields['CITY_ID']);
     foreach (GetModuleEvents('sale', 'OnBeforeLocationAdd', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($fields)) === false) {
             return false;
         }
     }
     if ($region && $country) {
         $uRes = \Bitrix\Sale\Location\LocationTable::update($region, array('PARENT_ID' => $country));
     }
     if ($city) {
         if ($region) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID' => $region));
         } elseif ($country) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($city, array('PARENT_ID' => $country));
         }
     }
     if (intval($fields['SORT'])) {
         $loc2Update = $city ? $city : ($region ? $region : ($country ? $country : false));
         if ($loc2Update) {
             $uRes = \Bitrix\Sale\Location\LocationTable::update($loc2Update, array('SORT' => $fields['SORT']));
         }
     }
     foreach (GetModuleEvents('sale', 'OnLocationAdd', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($loc2Update, $fields));
     }
     return $loc2Update;
 }
Example #15
0
 static function convertOldToNew(array $property)
 {
     if (isset($property['REQUIED']) && !empty($property['REQUIED'])) {
         $property['REQUIRED'] = $property['REQUIED'];
     }
     $size1 = intval($property['SIZE1']);
     $size2 = intval($property['SIZE2']);
     $settings = array();
     // TODO remove sale/include.php - $GLOBALS["SALE_FIELD_TYPES"]
     switch ($property['TYPE']) {
         case 'TEXT':
             $property['TYPE'] = 'STRING';
             if ($size1 > 0) {
                 $settings['SIZE'] = $size1;
             }
             break;
         case 'TEXTAREA':
             $property['TYPE'] = 'STRING';
             $settings['MULTILINE'] = 'Y';
             if ($size1 > 0) {
                 $settings['COLS'] = $size1;
             }
             if ($size2 > 0) {
                 $settings['ROWS'] = $size2;
             }
             break;
         case 'CHECKBOX':
             $property['TYPE'] = 'Y/N';
             break;
         case 'RADIO':
             $property['TYPE'] = 'ENUM';
             $settings['MULTIELEMENT'] = 'Y';
             break;
         case 'SELECT':
             $property['TYPE'] = 'ENUM';
             if ($size1 > 0) {
                 $settings['SIZE'] = $size1;
             }
             break;
         case 'MULTISELECT':
             $property['TYPE'] = 'ENUM';
             $property['MULTIPLE'] = 'Y';
             if ($size1 > 0) {
                 $settings['SIZE'] = $size1;
             }
             break;
         case 'LOCATION':
             // ID came, should store CODE
             if (intval($property['DEFAULT_VALUE'])) {
                 $res = \Bitrix\Sale\Location\LocationTable::getList(array('filter' => array('=ID' => intval($property['DEFAULT_VALUE'])), 'select' => array('CODE')))->fetch();
                 if (is_array($res) && (string) $res['CODE'] != '') {
                     $property['DEFAULT_VALUE'] = $res['CODE'];
                 }
             }
             if ($size1 > 0) {
                 $settings['SIZE'] = $size1;
             }
             break;
     }
     $property['SETTINGS'] = $settings;
     return $property;
 }
Example #16
0
    function ExportOrders2Xml($arFilter = array(), $nTopCount = 0, $currency = "", $crmMode = false, $time_limit = 0, $version = false, $arOptions = array())
    {
        global $DB;
        $count = false;
        if (IntVal($nTopCount) > 0) {
            $count = array("nTopCount" => $nTopCount);
        }
        $bNewVersion = strlen($version) > 0;
        $bExportFromCrm = isset($arOptions["EXPORT_FROM_CRM"]) && $arOptions["EXPORT_FROM_CRM"] === "Y";
        if (IntVal($time_limit) > 0) {
            //This is an optimization. We assume than no step can take more than one year.
            if ($time_limit > 0) {
                $end_time = time() + $time_limit;
            } else {
                $end_time = time() + 365 * 24 * 3600;
            }
            // One year
            //$version
            $lastOrderPrefix = "LAST_ORDER_ID";
            if ($crmMode) {
                $lastOrderPrefix = md5(serialize($arFilter));
                if (!empty($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && IntVal($nTopCount) > 0) {
                    $count["nTopCount"] = $count["nTopCount"] + count($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]);
                }
            } else {
                if (IntVal($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) > 0) {
                    $arFilter["<ID"] = $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix];
                }
            }
        }
        $arResultStat = array("ORDERS" => 0, "CONTACTS" => 0, "COMPANIES" => 0);
        $accountNumberPrefix = COption::GetOptionString("sale", "1C_SALE_ACCOUNT_NUMBER_SHOP_PREFIX", "");
        $dbPaySystem = CSalePaySystem::GetList(array("ID" => "ASC"), array("ACTIVE" => "Y"), false, false, array("ID", "NAME", "ACTIVE"));
        while ($arPaySystem = $dbPaySystem->Fetch()) {
            $paySystems[$arPaySystem["ID"]] = $arPaySystem["NAME"];
        }
        $dbDelivery = CSaleDelivery::GetList(array("ID" => "ASC"), array("ACTIVE" => "Y"), false, false, array("ID", "NAME", "ACTIVE"));
        while ($arDelivery = $dbDelivery->Fetch()) {
            $delivery[$arDelivery["ID"]] = $arDelivery["NAME"];
        }
        $rsDeliveryHandlers = CSaleDeliveryHandler::GetAdminList(array("SID" => "ASC"));
        while ($arHandler = $rsDeliveryHandlers->Fetch()) {
            if (is_array($arHandler["PROFILES"])) {
                foreach ($arHandler["PROFILES"] as $k => $v) {
                    $delivery[$arHandler["SID"] . ":" . $k] = $v["TITLE"] . " (" . $arHandler["NAME"] . ")";
                }
            }
        }
        $arStore = array();
        $arMeasures = array();
        if (CModule::IncludeModule("catalog")) {
            $dbList = CCatalogStore::GetList(array("SORT" => "DESC", "ID" => "ASC"), array("ACTIVE" => "Y", "ISSUING_CENTER" => "Y"), false, false, array("ID", "SORT", "TITLE", "ADDRESS", "DESCRIPTION", "PHONE", "EMAIL", "XML_ID"));
            while ($arStoreTmp = $dbList->Fetch()) {
                if (strlen($arStoreTmp["XML_ID"]) <= 0) {
                    $arStoreTmp["XML_ID"] = $arStoreTmp["ID"];
                }
                $arStore[$arStoreTmp["ID"]] = $arStoreTmp;
            }
            $dbList = CCatalogMeasure::getList(array(), array(), false, false, array("CODE", "MEASURE_TITLE"));
            while ($arList = $dbList->Fetch()) {
                $arMeasures[$arList["CODE"]] = $arList["MEASURE_TITLE"];
            }
        }
        if (empty($arMeasures)) {
            $arMeasures[796] = GetMessage("SALE_EXPORT_SHTUKA");
        }
        $dbExport = CSaleExport::GetList();
        while ($arExport = $dbExport->Fetch()) {
            $arAgent[$arExport["PERSON_TYPE_ID"]] = unserialize($arExport["VARS"]);
        }
        $dateFormat = CSite::GetDateFormat("FULL");
        if ($crmMode) {
            echo "<" . "?xml version=\"1.0\" encoding=\"UTF-8\"?" . ">\n";
            $arCharSets = array();
            $dbSitesList = CSite::GetList($b = "", $o = "");
            while ($arSite = $dbSitesList->Fetch()) {
                $arCharSets[$arSite["ID"]] = $arSite["CHARSET"];
            }
        } else {
            echo "<" . "?xml version=\"1.0\" encoding=\"windows-1251\"?" . ">\n";
        }
        ?>
		<<?php 
        echo GetMessage("SALE_EXPORT_COM_INFORMATION");
        ?>
 <?php 
        echo GetMessage("SALE_EXPORT_SHEM_VERSION");
        ?>
="<?php 
        echo $bNewVersion ? "2.08" : "2.05";
        ?>
" <?php 
        echo GetMessage("SALE_EXPORT_SHEM_DATE_CREATE");
        ?>
="<?php 
        echo date("Y-m-d");
        ?>
T<?php 
        echo date("G:i:s");
        ?>
" <?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT");
        ?>
="<?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_DF");
        ?>
=yyyy-MM-dd; <?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_DLF");
        ?>
=DT" <?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_DATETIME");
        ?>
="<?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_DF");
        ?>
=<?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_TIME");
        ?>
; <?php 
        echo GetMessage("SALE_EXPORT_DATE_FORMAT_DLF");
        ?>
=T" <?php 
        echo GetMessage("SALE_EXPORT_DEL_DT");
        ?>
="T" <?php 
        echo GetMessage("SALE_EXPORT_FORM_SUMM");
        ?>
="<?php 
        echo GetMessage("SALE_EXPORT_FORM_CC");
        ?>
=18; <?php 
        echo GetMessage("SALE_EXPORT_FORM_CDC");
        ?>
=2; <?php 
        echo GetMessage("SALE_EXPORT_FORM_CRD");
        ?>
=." <?php 
        echo GetMessage("SALE_EXPORT_FORM_QUANT");
        ?>
="<?php 
        echo GetMessage("SALE_EXPORT_FORM_CC");
        ?>
=18; <?php 
        echo GetMessage("SALE_EXPORT_FORM_CDC");
        ?>
=2; <?php 
        echo GetMessage("SALE_EXPORT_FORM_CRD");
        ?>
=.">
		<?php 
        $arOrder = array("ID" => "DESC");
        if ($crmMode) {
            $arOrder = array("DATE_UPDATE" => "ASC");
        }
        $arSelect = array("ID", "LID", "PERSON_TYPE_ID", "PAYED", "DATE_PAYED", "EMP_PAYED_ID", "CANCELED", "DATE_CANCELED", "EMP_CANCELED_ID", "REASON_CANCELED", "STATUS_ID", "DATE_STATUS", "PAY_VOUCHER_NUM", "PAY_VOUCHER_DATE", "EMP_STATUS_ID", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "EMP_ALLOW_DELIVERY_ID", "PRICE", "CURRENCY", "DISCOUNT_VALUE", "SUM_PAID", "USER_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DATE_INSERT", "DATE_INSERT_FORMAT", "DATE_UPDATE", "USER_DESCRIPTION", "ADDITIONAL_INFO", "PS_STATUS", "PS_STATUS_CODE", "PS_STATUS_DESCRIPTION", "PS_STATUS_MESSAGE", "PS_SUM", "PS_CURRENCY", "PS_RESPONSE_DATE", "COMMENTS", "TAX_VALUE", "STAT_GID", "RECURRING_ID", "ACCOUNT_NUMBER", "SUM_PAID", "DELIVERY_DOC_DATE", "DELIVERY_DOC_NUM", "TRACKING_NUMBER", "STORE_ID", "ID_1C", "VERSION");
        $bCrmModuleIncluded = false;
        if ($bExportFromCrm) {
            $arSelect[] = "UF_COMPANY_ID";
            $arSelect[] = "UF_CONTACT_ID";
            if (IsModuleInstalled("crm") && CModule::IncludeModule("crm")) {
                $bCrmModuleIncluded = true;
            }
        }
        $dbOrderList = CSaleOrder::GetList($arOrder, $arFilter, false, $count, $arSelect);
        while ($arOrder = $dbOrderList->Fetch()) {
            if ($crmMode) {
                if ($bNewVersion && is_array($_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && in_array($arOrder["ID"], $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix]) && empty($arFilter["ID"])) {
                    continue;
                }
                ob_start();
            }
            $arResultStat["ORDERS"]++;
            $agentParams = $arAgent[$arOrder["PERSON_TYPE_ID"]];
            $arProp = array();
            $arProp["ORDER"] = $arOrder;
            if (IntVal($arOrder["USER_ID"]) > 0) {
                $dbUser = CUser::GetByID($arOrder["USER_ID"]);
                if ($arUser = $dbUser->Fetch()) {
                    $arProp["USER"] = $arUser;
                }
            }
            if ($bExportFromCrm) {
                $arProp["CRM"] = array();
                $companyID = isset($arOrder["UF_COMPANY_ID"]) ? intval($arOrder["UF_COMPANY_ID"]) : 0;
                $contactID = isset($arOrder["UF_CONTACT_ID"]) ? intval($arOrder["UF_CONTACT_ID"]) : 0;
                if ($companyID > 0) {
                    $arProp["CRM"]["CLIENT_ID"] = "CRMCO" . $companyID;
                } else {
                    $arProp["CRM"]["CLIENT_ID"] = "CRMC" . $contactID;
                }
                $clientInfo = array("LOGIN" => "", "NAME" => "", "LAST_NAME" => "", "SECOND_NAME" => "");
                if ($bCrmModuleIncluded) {
                    if ($companyID > 0) {
                        $arCompanyFilter = array('=ID' => $companyID);
                        $dbCompany = CCrmCompany::GetListEx(array(), $arCompanyFilter, false, array("nTopCount" => 1), array("TITLE"));
                        $arCompany = $dbCompany->Fetch();
                        unset($dbCompany, $arCompanyFilter);
                        if (is_array($arCompany)) {
                            if (isset($arCompany["TITLE"])) {
                                $clientInfo["NAME"] = $arCompany["TITLE"];
                            }
                        }
                        unset($arCompany);
                    } else {
                        if ($contactID > 0) {
                            $arContactFilter = array('=ID' => $contactID);
                            $dbContact = CCrmContact::GetListEx(array(), $arContactFilter, false, array("nTopCount" => 1), array("NAME", "LAST_NAME", "SECOND_NAME"));
                            $arContact = $dbContact->Fetch();
                            unset($dbContact, $arContactFilter);
                            if (is_array($arContact)) {
                                if (isset($arContact["NAME"])) {
                                    $clientInfo["NAME"] = $arContact["NAME"];
                                }
                                if (isset($arContact["LAST_NAME"])) {
                                    $clientInfo["LAST_NAME"] = $arContact["LAST_NAME"];
                                }
                                if (isset($arContact["SECOND_NAME"])) {
                                    $clientInfo["SECOND_NAME"] = $arContact["SECOND_NAME"];
                                }
                            }
                            unset($arContact);
                        }
                    }
                }
                $arProp["CRM"]["CLIENT"] = $clientInfo;
                unset($clientInfo);
            }
            if (IntVal($arOrder["PAY_SYSTEM_ID"]) > 0) {
                $arProp["ORDER"]["PAY_SYSTEM_NAME"] = $paySystems[$arOrder["PAY_SYSTEM_ID"]];
            }
            if (strlen($arOrder["DELIVERY_ID"]) > 0) {
                $arProp["ORDER"]["DELIVERY_NAME"] = $delivery[$arOrder["DELIVERY_ID"]];
            }
            $dbOrderPropVals = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $arOrder["ID"]), false, false, array("ID", "CODE", "VALUE", "ORDER_PROPS_ID", "PROP_TYPE"));
            $locationStreetPropertyValue = '';
            while ($arOrderPropVals = $dbOrderPropVals->Fetch()) {
                if ($arOrderPropVals["PROP_TYPE"] == "CHECKBOX") {
                    if ($arOrderPropVals["VALUE"] == "Y") {
                        $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = "true";
                    } else {
                        $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = "false";
                    }
                } elseif ($arOrderPropVals["PROP_TYPE"] == "TEXT" || $arOrderPropVals["PROP_TYPE"] == "TEXTAREA") {
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arOrderPropVals["VALUE"];
                } elseif ($arOrderPropVals["PROP_TYPE"] == "SELECT" || $arOrderPropVals["PROP_TYPE"] == "RADIO") {
                    $arVal = CSaleOrderPropsVariant::GetByValue($arOrderPropVals["ORDER_PROPS_ID"], $arOrderPropVals["VALUE"]);
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arVal["NAME"];
                } elseif ($arOrderPropVals["PROP_TYPE"] == "MULTISELECT") {
                    $curVal = explode(",", $arOrderPropVals["VALUE"]);
                    foreach ($curVal as $vm) {
                        $arVal = CSaleOrderPropsVariant::GetByValue($arOrderPropVals["ORDER_PROPS_ID"], $vm);
                        $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] .= ", " . $arVal["NAME"];
                    }
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = substr($arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]], 2);
                } elseif ($arOrderPropVals["PROP_TYPE"] == "LOCATION") {
                    $arVal = CSaleLocation::GetByID($arOrderPropVals["VALUE"], LANGUAGE_ID);
                    if (CSaleLocation::isLocationProEnabled()) {
                        if (intval($arVal['ID'])) {
                            try {
                                $res = \Bitrix\Sale\Location\LocationTable::getPathToNode($arVal['ID'], array('select' => array('LNAME' => 'NAME.NAME', 'TYPE_ID'), 'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)));
                                $types = \Bitrix\Sale\Location\Admin\TypeHelper::getTypeCodeIdMapCached();
                                $path = array();
                                while ($item = $res->fetch()) {
                                    // copy street to STREET property
                                    if ($types['ID2CODE'][$item['TYPE_ID']] == 'STREET') {
                                        $locationStreetPropertyValue = $item['LNAME'];
                                    }
                                    $path[] = $item['LNAME'];
                                }
                                $locationString = implode(' - ', $path);
                            } catch (\Bitrix\Main\SystemException $e) {
                                $locationString = '';
                            }
                        } else {
                            $locationString = '';
                        }
                    } else {
                        $locationString = $arVal["COUNTRY_NAME"] . (strlen($arVal["COUNTRY_NAME"]) <= 0 || strlen($arVal["REGION_NAME"]) <= 0 ? "" : " - ") . $arVal["REGION_NAME"] . (strlen($arVal["COUNTRY_NAME"]) <= 0 || strlen($arVal["CITY_NAME"]) <= 0 ? "" : " - ") . $arVal["CITY_NAME"];
                    }
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $locationString;
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_CITY"] = $arVal["CITY_NAME"];
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_COUNTRY"] = $arVal["COUNTRY_NAME"];
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_REGION"] = $arVal["REGION_NAME"];
                } else {
                    $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arOrderPropVals["VALUE"];
                }
            }
            $resShipment = \Bitrix\Sale\Internals\ShipmentTable::getList(array('select' => array('DELIVERY_ID', 'ALLOW_DELIVERY', 'DEDUCTED', 'DATE_ALLOW_DELIVERY', 'DATE_DEDUCTED'), 'filter' => array('ORDER_ID' => $arOrder['ID'], '=SYSTEM' => 'N'), 'limit' => array(1)));
            $arShipment = $resShipment->fetch();
            $resPayment = \Bitrix\Sale\Internals\PaymentTable::getList(array('select' => array('PAY_VOUCHER_NUM', 'PAY_SYSTEM_ID', 'PAY_VOUCHER_DATE'), 'filter' => array('ORDER_ID' => $arOrder['ID'], '!PAY_SYSTEM_ID' => \Bitrix\Sale\Internals\PaySystemInner::getId()), 'limit' => array(1)));
            $arPayment = $resPayment->fetch();
            foreach ($agentParams as $k => $v) {
                if (strpos($k, "REKV_") !== false) {
                    if (!is_array($v)) {
                        $agent["REKV"][$k] = $v;
                    } else {
                        if (strlen($v["TYPE"]) <= 0) {
                            $agent["REKV"][$k] = $v["VALUE"];
                        } else {
                            $agent["REKV"][$k] = $arProp[$v["TYPE"]][$v["VALUE"]];
                        }
                    }
                } else {
                    if (!is_array($v)) {
                        $agent[$k] = $v;
                    } else {
                        if (strlen($v["TYPE"]) <= 0) {
                            $agent[$k] = $v["VALUE"];
                        } else {
                            $agent[$k] = $arProp[$v["TYPE"]][$v["VALUE"]];
                        }
                        if ($k == 'STREET' && strlen($locationStreetPropertyValue)) {
                            $agent[$k] = $locationStreetPropertyValue . (strlen($agent[$k]) ? ', ' : '') . $agent[$k];
                        }
                    }
                }
            }
            ?>
			<<?php 
            echo GetMessage("SALE_EXPORT_DOCUMENT");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_ID");
            ?>
><?php 
            echo $arOrder["ID"];
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ID");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_NUMBER");
            ?>
><?php 
            echo $accountNumberPrefix . $arOrder["ACCOUNT_NUMBER"];
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_NUMBER");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_DATE");
            ?>
><?php 
            echo $DB->FormatDate($arOrder["DATE_INSERT_FORMAT"], $dateFormat, "YYYY-MM-DD");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_DATE");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_HOZ_OPERATION");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_ITEM_ORDER");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_HOZ_OPERATION");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_ROLE");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_SELLER");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ROLE");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_CURRENCY");
            ?>
><?php 
            echo htmlspecialcharsbx(strlen($currency) > 0 ? substr($currency, 0, 3) : substr($arOrder["CURRENCY"], 0, 3));
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_CURRENCY");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_CURRENCY_RATE");
            ?>
>1</<?php 
            echo GetMessage("SALE_EXPORT_CURRENCY_RATE");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_AMOUNT");
            ?>
><?php 
            echo $arOrder["PRICE"];
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_AMOUNT");
            ?>
>
				<?php 
            if ($bNewVersion) {
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_VERSION");
                ?>
><?php 
                echo IntVal($arOrder["VERSION"]) > 0 ? $arOrder["VERSION"] : 0;
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VERSION");
                ?>
>
					<?php 
                if (strlen($arOrder["ID_1C"]) > 0) {
                    ?>
<<?php 
                    echo GetMessage("SALE_EXPORT_ID_1C");
                    ?>
><?php 
                    echo htmlspecialcharsbx($arOrder["ID_1C"]);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_ID_1C");
                    ?>
><?php 
                }
            }
            if ($crmMode) {
                ?>
<DateUpdate><?php 
                echo $DB->FormatDate($arOrder["DATE_UPDATE"], $dateFormat, "YYYY-MM-DD HH:MI:SS");
                ?>
</DateUpdate><?php 
            }
            $deliveryAdr = CSaleExport::ExportContragents($arOrder, $arProp, $agent, $arResultStat, $bNewVersion, $bExportFromCrm ? array("EXPORT_FROM_CRM" => "Y") : array());
            ?>
				<<?php 
            echo GetMessage("SALE_EXPORT_TIME");
            ?>
><?php 
            echo $DB->FormatDate($arOrder["DATE_INSERT_FORMAT"], $dateFormat, "HH:MI:SS");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_TIME");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_COMMENTS");
            ?>
><?php 
            echo htmlspecialcharsbx($arOrder["COMMENTS"]);
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_COMMENTS");
            ?>
>
				<?php 
            $dbOrderTax = CSaleOrderTax::GetList(array(), array("ORDER_ID" => $arOrder["ID"]), false, false, array("ID", "TAX_NAME", "VALUE", "VALUE_MONEY", "CODE", "IS_IN_PRICE"));
            $i = -1;
            $orderTax = 0;
            while ($arOrderTax = $dbOrderTax->Fetch()) {
                $arOrderTax["VALUE_MONEY"] = roundEx($arOrderTax["VALUE_MONEY"], 2);
                $orderTax += $arOrderTax["VALUE_MONEY"];
                $i++;
                if ($i == 0) {
                    echo "<" . GetMessage("SALE_EXPORT_TAXES") . ">";
                }
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_TAX");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo htmlspecialcharsbx($arOrderTax["TAX_NAME"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_IN_PRICE");
                ?>
><?php 
                echo $arOrderTax["IS_IN_PRICE"] == "Y" ? "true" : "false";
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_IN_PRICE");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
><?php 
                echo $arOrderTax["VALUE_MONEY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
>
					</<?php 
                echo GetMessage("SALE_EXPORT_TAX");
                ?>
>
					<?php 
            }
            if ($i != -1) {
                echo "</" . GetMessage("SALE_EXPORT_TAXES") . ">";
            }
            ?>
				<?php 
            if (DoubleVal($arOrder["DISCOUNT_VALUE"]) > 0) {
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_DISCOUNTS");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_DISCOUNT");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_ORDER_DISCOUNT");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
><?php 
                echo $arOrder["DISCOUNT_VALUE"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_IN_PRICE");
                ?>
>false</<?php 
                echo GetMessage("SALE_EXPORT_IN_PRICE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_DISCOUNT");
                ?>
>
					</<?php 
                echo GetMessage("SALE_EXPORT_DISCOUNTS");
                ?>
>
					<?php 
            }
            $storeBasket = "";
            if (IntVal($arOrder["STORE_ID"]) > 0 && !empty($arStore[$arOrder["STORE_ID"]])) {
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_STORIES");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_STORY");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
><?php 
                echo $arStore[$arOrder["STORE_ID"]]["XML_ID"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo htmlspecialcharsbx($arStore[$arOrder["STORE_ID"]]["TITLE"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ADDRESS");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_PRESENTATION");
                ?>
><?php 
                echo htmlspecialcharsbx($arStore[$arOrder["STORE_ID"]]["ADDRESS"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_PRESENTATION");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_ADDRESS_FIELD");
                ?>
>
									<<?php 
                echo GetMessage("SALE_EXPORT_TYPE");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_STREET");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_TYPE");
                ?>
>
									<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arStore[$arOrder["STORE_ID"]]["ADDRESS"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
								</<?php 
                echo GetMessage("SALE_EXPORT_ADDRESS_FIELD");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_ADDRESS");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_CONTACTS");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_CONTACT");
                ?>
>
									<<?php 
                echo GetMessage("SALE_EXPORT_TYPE");
                ?>
><?php 
                echo $bNewVersion ? GetMessage("SALE_EXPORT_WORK_PHONE_NEW") : GetMessage("SALE_EXPORT_WORK_PHONE");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_TYPE");
                ?>
>
									<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arStore[$arOrder["STORE_ID"]]["PHONE"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
								</<?php 
                echo GetMessage("SALE_EXPORT_CONTACT");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_CONTACTS");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_STORY");
                ?>
>
					</<?php 
                echo GetMessage("SALE_EXPORT_STORIES");
                ?>
>
					<?php 
                /*
                $storeBasket = "				
                	<".GetMessage("SALE_EXPORT_STORIES").">
                		<".GetMessage("SALE_EXPORT_STORY").">
                			<".GetMessage("SALE_EXPORT_ID").">".$arStore[$arOrder["STORE_ID"]]["XML_ID"]."</".GetMessage("SALE_EXPORT_ID").">
                			<".GetMessage("SALE_EXPORT_ITEM_NAME").">".htmlspecialcharsbx($arStore[$arOrder["STORE_ID"]]["TITLE"])."</".GetMessage("SALE_EXPORT_ITEM_NAME").">
                		</".GetMessage("SALE_EXPORT_STORY").">
                	</".GetMessage("SALE_EXPORT_STORIES").">
                	";
                */
            }
            ?>
				<<?php 
            echo GetMessage("SALE_EXPORT_ITEMS");
            ?>
>
				<?php 
            $dbBasket = \Bitrix\Sale\Internals\BasketTable::getList(array('select' => array("ID", "NOTES", "PRODUCT_XML_ID", "CATALOG_XML_ID", "NAME", "PRICE", "QUANTITY", "DISCOUNT_PRICE", "VAT_RATE", "MEASURE_CODE"), 'filter' => array("ORDER_ID" => $arOrder["ID"]), 'order' => array("NAME" => "ASC")));
            $basketSum = 0;
            $priceType = "";
            $bVat = false;
            $vatRate = 0;
            $vatSum = 0;
            while ($arBasket = $dbBasket->fetch()) {
                if (strlen($priceType) <= 0) {
                    $priceType = $arBasket["NOTES"];
                }
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
><?php 
                echo htmlspecialcharsbx($arBasket["PRODUCT_XML_ID"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_CATALOG_ID");
                ?>
><?php 
                echo htmlspecialcharsbx($arBasket["CATALOG_XML_ID"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_CATALOG_ID");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo htmlspecialcharsbx($arBasket["NAME"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
						<?php 
                if ($bNewVersion) {
                    if (IntVal($arBasket["MEASURE_CODE"]) <= 0) {
                        $arBasket["MEASURE_CODE"] = 796;
                    }
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_UNIT");
                    ?>
>
								<<?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
><?php 
                    echo $arBasket["MEASURE_CODE"];
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
>
								<<?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
><?php 
                    echo htmlspecialcharsbx($arMeasures[$arBasket["MEASURE_CODE"]]);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
>
							</<?php 
                    echo GetMessage("SALE_EXPORT_UNIT");
                    ?>
>
							<<?php 
                    echo GetMessage("SALE_EXPORT_KOEF");
                    ?>
>1</<?php 
                    echo GetMessage("SALE_EXPORT_KOEF");
                    ?>
>
							<?php 
                } else {
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_BASE_UNIT");
                    ?>
 <?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
="796" <?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
="<?php 
                    echo GetMessage("SALE_EXPORT_SHTUKA");
                    ?>
" <?php 
                    echo GetMessage("SALE_EXPORT_INTERNATIONAL_ABR");
                    ?>
="<?php 
                    echo GetMessage("SALE_EXPORT_RCE");
                    ?>
"><?php 
                    echo GetMessage("SALE_EXPORT_SHT");
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_BASE_UNIT");
                    ?>
>
							<?php 
                }
                if (DoubleVal($arBasket["DISCOUNT_PRICE"]) > 0) {
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_DISCOUNTS");
                    ?>
>
								<<?php 
                    echo GetMessage("SALE_EXPORT_DISCOUNT");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
><?php 
                    echo GetMessage("SALE_EXPORT_ITEM_DISCOUNT");
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_AMOUNT");
                    ?>
><?php 
                    echo $arBasket["DISCOUNT_PRICE"];
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_AMOUNT");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_IN_PRICE");
                    ?>
>true</<?php 
                    echo GetMessage("SALE_EXPORT_IN_PRICE");
                    ?>
>
								</<?php 
                    echo GetMessage("SALE_EXPORT_DISCOUNT");
                    ?>
>
							</<?php 
                    echo GetMessage("SALE_EXPORT_DISCOUNTS");
                    ?>
>
							<?php 
                }
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PRICE_PER_ITEM");
                ?>
><?php 
                echo $arBasket["PRICE"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_PRICE_PER_ITEM");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_QUANTITY");
                ?>
><?php 
                echo $arBasket["QUANTITY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_QUANTITY");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
><?php 
                echo $arBasket["PRICE"] * $arBasket["QUANTITY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_TYPE_NOMENKLATURA");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_TYPE_OF_NOMENKLATURA");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<?php 
                $dbProp = CSaleBasket::GetPropsList(array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arBasket["ID"], "!CODE" => array("CATALOG.XML_ID", "PRODUCT.XML_ID")), false, false, array("NAME", "VALUE", "CODE"));
                while ($arProp = $dbProp->Fetch()) {
                    ?>
								<<?php 
                    echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
><?php 
                    echo htmlspecialcharsbx($arProp["NAME"]);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_VALUE");
                    ?>
><?php 
                    echo htmlspecialcharsbx($arProp["VALUE"]);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_VALUE");
                    ?>
>
								</<?php 
                    echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                    ?>
>
								<?php 
                }
                ?>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
                ?>
>
						<?php 
                if (DoubleVal($arBasket["VAT_RATE"]) > 0) {
                    $bVat = true;
                    $vatRate = DoubleVal($arBasket["VAT_RATE"]);
                    $basketVatSum = $arBasket["PRICE"] / ($arBasket["VAT_RATE"] + 1) * $arBasket["VAT_RATE"];
                    $vatSum += roundEx($basketVatSum * $arBasket["QUANTITY"], 2);
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_TAX_RATES");
                    ?>
>
								<<?php 
                    echo GetMessage("SALE_EXPORT_TAX_RATE");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
><?php 
                    echo GetMessage("SALE_EXPORT_VAT");
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_RATE");
                    ?>
><?php 
                    echo $arBasket["VAT_RATE"] * 100;
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_RATE");
                    ?>
>
								</<?php 
                    echo GetMessage("SALE_EXPORT_TAX_RATE");
                    ?>
>
							</<?php 
                    echo GetMessage("SALE_EXPORT_TAX_RATES");
                    ?>
>
							<<?php 
                    echo GetMessage("SALE_EXPORT_TAXES");
                    ?>
>
								<<?php 
                    echo GetMessage("SALE_EXPORT_TAX");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
><?php 
                    echo GetMessage("SALE_EXPORT_VAT");
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_ITEM_NAME");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_IN_PRICE");
                    ?>
>true</<?php 
                    echo GetMessage("SALE_EXPORT_IN_PRICE");
                    ?>
>
									<<?php 
                    echo GetMessage("SALE_EXPORT_AMOUNT");
                    ?>
><?php 
                    echo roundEx($basketVatSum, 2);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_AMOUNT");
                    ?>
>
								</<?php 
                    echo GetMessage("SALE_EXPORT_TAX");
                    ?>
>
							</<?php 
                    echo GetMessage("SALE_EXPORT_TAXES");
                    ?>
>
							<?php 
                }
                ?>
						<?php 
                echo $storeBasket;
                ?>
					</<?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
>
					<?php 
                $basketSum += $arBasket["PRICE"] * $arBasket["QUANTITY"];
            }
            if (IntVal($arOrder["PRICE_DELIVERY"]) > 0) {
                ?>
					<<?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
>ORDER_DELIVERY</<?php 
                echo GetMessage("SALE_EXPORT_ID");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_ORDER_DELIVERY");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
						<?php 
                if ($bNewVersion) {
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_UNIT");
                    ?>
>
							<<?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
>796</<?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
>
							<<?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
><?php 
                    echo htmlspecialcharsbx($arMeasures[796]);
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
>
							</<?php 
                    echo GetMessage("SALE_EXPORT_UNIT");
                    ?>
>
							<<?php 
                    echo GetMessage("SALE_EXPORT_KOEF");
                    ?>
>1</<?php 
                    echo GetMessage("SALE_EXPORT_KOEF");
                    ?>
>
						<?php 
                } else {
                    ?>
							<<?php 
                    echo GetMessage("SALE_EXPORT_BASE_UNIT");
                    ?>
 <?php 
                    echo GetMessage("SALE_EXPORT_CODE");
                    ?>
="796" <?php 
                    echo GetMessage("SALE_EXPORT_FULL_NAME_UNIT");
                    ?>
="<?php 
                    echo GetMessage("SALE_EXPORT_SHTUKA");
                    ?>
" <?php 
                    echo GetMessage("SALE_EXPORT_INTERNATIONAL_ABR");
                    ?>
="<?php 
                    echo GetMessage("SALE_EXPORT_RCE");
                    ?>
"><?php 
                    echo GetMessage("SALE_EXPORT_SHT");
                    ?>
</<?php 
                    echo GetMessage("SALE_EXPORT_BASE_UNIT");
                    ?>
>
						<?php 
                }
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PRICE_PER_ITEM");
                ?>
><?php 
                echo $arOrder["PRICE_DELIVERY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_PRICE_PER_ITEM");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_QUANTITY");
                ?>
>1</<?php 
                echo GetMessage("SALE_EXPORT_QUANTITY");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
><?php 
                echo $arOrder["PRICE_DELIVERY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_AMOUNT");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_TYPE_NOMENKLATURA");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_SERVICE");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_TYPE_OF_NOMENKLATURA");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
								<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_SERVICE");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
							</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
                ?>
>
						<?php 
                if ($bVat) {
                    $deliveryTax = roundEx($arOrder["PRICE_DELIVERY"] / ($vatRate + 1) * $vatRate, 2);
                    if ($orderTax > $vatSum && $orderTax == roundEx($vatSum + $deliveryTax, 2)) {
                        ?>
								<<?php 
                        echo GetMessage("SALE_EXPORT_TAX_RATES");
                        ?>
>
									<<?php 
                        echo GetMessage("SALE_EXPORT_TAX_RATE");
                        ?>
>
										<<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
><?php 
                        echo GetMessage("SALE_EXPORT_VAT");
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
>
										<<?php 
                        echo GetMessage("SALE_EXPORT_RATE");
                        ?>
><?php 
                        echo $vatRate * 100;
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_RATE");
                        ?>
>
									</<?php 
                        echo GetMessage("SALE_EXPORT_TAX_RATE");
                        ?>
>
								</<?php 
                        echo GetMessage("SALE_EXPORT_TAX_RATES");
                        ?>
>
								<<?php 
                        echo GetMessage("SALE_EXPORT_TAXES");
                        ?>
>
									<<?php 
                        echo GetMessage("SALE_EXPORT_TAX");
                        ?>
>
										<<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
><?php 
                        echo GetMessage("SALE_EXPORT_VAT");
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
>
										<<?php 
                        echo GetMessage("SALE_EXPORT_IN_PRICE");
                        ?>
>true</<?php 
                        echo GetMessage("SALE_EXPORT_IN_PRICE");
                        ?>
>
										<<?php 
                        echo GetMessage("SALE_EXPORT_AMOUNT");
                        ?>
><?php 
                        echo $deliveryTax;
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_AMOUNT");
                        ?>
>
									</<?php 
                        echo GetMessage("SALE_EXPORT_TAX");
                        ?>
>
								</<?php 
                        echo GetMessage("SALE_EXPORT_TAXES");
                        ?>
>
								<?php 
                    }
                }
                ?>
					</<?php 
                echo GetMessage("SALE_EXPORT_ITEM");
                ?>
>
					<?php 
            }
            ?>
				</<?php 
            echo GetMessage("SALE_EXPORT_ITEMS");
            ?>
>
				<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
            ?>
>
					<?php 
            if (strlen($arOrder["DATE_PAYED"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DATE_PAID");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo $arOrder["DATE_PAYED"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (strlen($arPayment["PAY_VOUCHER_NUM"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_PAY_NUMBER");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arPayment["PAY_VOUCHER_NUM"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (IntVal($arPayment["PAY_SYSTEM_ID"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_PAY_SYSTEM");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($paySystems[$arPayment["PAY_SYSTEM_ID"]]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_PAY_SYSTEM_ID");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arPayment["PAY_SYSTEM_ID"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (strlen($arShipment["DATE_ALLOW_DELIVERY"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DATE_ALLOW_DELIVERY");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo $arShipment["DATE_ALLOW_DELIVERY"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (strlen($arShipment["DELIVERY_ID"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DELIVERY_SERVICE");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($delivery[$arShipment["DELIVERY_ID"]]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            ?>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_ORDER_PAID");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            echo $arOrder["PAYED"] == "Y" ? "true" : "false";
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_ALLOW_DELIVERY");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            echo $arShipment["ALLOW_DELIVERY"] == "Y" ? "true" : "false";
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_CANCELED");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            echo $arOrder["CANCELED"] == "Y" ? "true" : "false";
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_FINAL_STATUS");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            echo $arOrder["STATUS_ID"] == "F" ? "true" : "false";
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_ORDER_STATUS");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            $arStatus = CSaleStatus::GetLangByID($arOrder["STATUS_ID"]);
            echo htmlspecialcharsbx("[" . $arOrder["STATUS_ID"] . "] " . $arStatus["NAME"]);
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_ORDER_STATUS_ID");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
					<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
><?php 
            echo htmlspecialcharsbx($arOrder["STATUS_ID"]);
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<?php 
            if (strlen($arOrder["DATE_CANCELED"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DATE_CANCEL");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo $arOrder["DATE_CANCELED"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_CANCEL_REASON");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arOrder["REASON_CANCELED"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (strlen($arOrder["DATE_STATUS"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DATE_STATUS");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo $arOrder["DATE_STATUS"];
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            if (strlen($arOrder["USER_DESCRIPTION"]) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_USER_DESCRIPTION");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
							<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($arOrder["USER_DESCRIPTION"]);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<?php 
            }
            $dbSite = CSite::GetByID($arOrder["LID"]);
            $arSite = $dbSite->Fetch();
            ?>
					<<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
><?php 
            echo GetMessage("SALE_EXPORT_SITE_NAME");
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_ITEM_NAME");
            ?>
>
						<<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>[<?php 
            echo $arOrder["LID"];
            ?>
] <?php 
            echo htmlspecialcharsbx($arSite["NAME"]);
            ?>
</<?php 
            echo GetMessage("SALE_EXPORT_VALUE");
            ?>
>
					</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
            ?>
>
					<?php 
            if (!empty($agent["REKV"])) {
                foreach ($agent["REKV"] as $k => $v) {
                    if (strlen($agentParams[$k]["NAME"]) > 0 && strlen($v) > 0) {
                        ?>
								<<?php 
                        echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                        ?>
>
									<<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
><?php 
                        echo htmlspecialcharsbx($agentParams[$k]["NAME"]);
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_ITEM_NAME");
                        ?>
>
									<<?php 
                        echo GetMessage("SALE_EXPORT_VALUE");
                        ?>
><?php 
                        echo htmlspecialcharsbx($v);
                        ?>
</<?php 
                        echo GetMessage("SALE_EXPORT_VALUE");
                        ?>
>
								</<?php 
                        echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                        ?>
>
								<?php 
                    }
                }
            }
            if (strlen($deliveryAdr) > 0) {
                ?>
						<<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
><?php 
                echo GetMessage("SALE_EXPORT_DELIVERY_ADDRESS");
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_ITEM_NAME");
                ?>
>
						<<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
><?php 
                echo htmlspecialcharsbx($deliveryAdr);
                ?>
</<?php 
                echo GetMessage("SALE_EXPORT_VALUE");
                ?>
>
						</<?php 
                echo GetMessage("SALE_EXPORT_PROPERTY_VALUE");
                ?>
>

						<?php 
            }
            ?>
				</<?php 
            echo GetMessage("SALE_EXPORT_PROPERTIES_VALUES");
            ?>
>
			</<?php 
            echo GetMessage("SALE_EXPORT_DOCUMENT");
            ?>
>
			<?php 
            if ($crmMode) {
                $c = ob_get_clean();
                $c = CharsetConverter::ConvertCharset($c, $arCharSets[$arOrder["LID"]], "utf-8");
                echo $c;
                $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix][] = $arOrder["ID"];
            } else {
                $_SESSION["BX_CML2_EXPORT"][$lastOrderPrefix] = $arOrder["ID"];
            }
            if (IntVal($time_limit) > 0 && time() > $end_time) {
                break;
            }
        }
        ?>
		</<?php 
        echo GetMessage("SALE_EXPORT_COM_INFORMATION");
        ?>
>
		<?php 
        return $arResultStat;
    }
Example #17
0
 public static function checkConnectionExists($entityPrimary, $locationPrimary)
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_PRIMARY_FLD_NAME'));
     $locationPrimary = Assert::expectIntegerPositive($locationPrimary, Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_LOCATION_PRIMARY_FLD_NAME'));
     if (!static::checkLinkUsageAny($entityPrimary)) {
         // if there are no links at all, connection virtually exists
         return true;
     }
     // todo: here we can rewrite this to make it to do just one query
     $node = LocationTable::getById($locationPrimary)->fetch();
     $result = static::getLinkStatusForMultipleNodes(array($node), $entityPrimary);
     return $result[$locationPrimary] == self::LSTAT_IS_CONNECTOR || $result[$locationPrimary] == self::LSTAT_BELOW_CONNECTOR;
 }
Example #18
0
 /**
  *
  *
  * @param
  *
  * @return
  */
 protected static function findNoIndex($parameters)
 {
     $dbConnection = Main\HttpApplication::getConnection();
     $dbHelper = $dbConnection->getSqlHelper();
     // tables
     $locationTable = Location\LocationTable::getTableName();
     $locationNameTable = Location\Name\LocationTable::getTableName();
     $locationGroupTable = Location\GroupLocationTable::getTableName();
     $locationSiteTable = Location\SiteLocationTable::getTableName();
     $locationTypeTable = Location\TypeTable::getTableName();
     //////////////////////////////////
     // sql parameters prepare
     //////////////////////////////////
     $filter = static::parseFilter($parameters['filter']);
     if (strlen($filter['SITE_ID']['VALUE'])) {
         $filterSite = $dbHelper->forSql(substr($filter['SITE_ID']['VALUE'], 0, 2));
         $hasLocLinks = Location\SiteLocationTable::checkLinkUsage($filterSite, Location\SiteLocationTable::DB_LOCATION_FLAG);
         $hasGrpLinks = Location\SiteLocationTable::checkLinkUsage($filterSite, Location\SiteLocationTable::DB_GROUP_FLAG);
         $doFilterBySite = true;
     }
     if (strlen($filter['PHRASE']['VALUE'])) {
         $doFilterByName = true;
         $filterName = ToUpper($dbHelper->forSql($filter['PHRASE']['VALUE']));
     }
     if (intval($filter['ID']['VALUE'])) {
         $doFilterById = true;
         $filterId = intval($filter['ID']['VALUE']);
     }
     if (intval($filter['CODE']['VALUE'])) {
         $doFilterByCode = true;
         $filterCode = $dbHelper->forSql($filter['CODE']['VALUE']);
     }
     $doFilterByLang = true;
     if (strlen($filter['NAME.LANGUAGE_ID']['VALUE'])) {
         $filterLang = $dbHelper->forSql(substr($filter['NAME.LANGUAGE_ID']['VALUE'], 0, 2));
     } else {
         $filterLang = LANGUAGE_ID;
     }
     if (isset($filter['PARENT_ID']) && intval($filter['PARENT_ID']['VALUE']) >= 0) {
         $doFilterByParent = true;
         $filterParentId = intval($filter['PARENT_ID']['VALUE']);
     }
     if (intval($filter['TYPE_ID']['VALUE'])) {
         $doFilterByType = true;
         $filterTypeId = intval($filter['TYPE_ID']['VALUE']);
     }
     // filter select fields
     if (!is_array($parameters['select'])) {
         $parameters['select'] = array();
     }
     $map = Location\LocationTable::getMap();
     $nameAlias = false;
     foreach ($parameters['select'] as $alias => $field) {
         if ($field == 'CHILD_CNT') {
             $doCountChildren = true;
         }
         if ($field == 'NAME.NAME') {
             $nameAlias = $alias;
         }
         if (!isset($map[$field]) || !in_array($map[$field]['data_type'], array('integer', 'string', 'float', 'boolean')) || isset($map[$field]['expression'])) {
             unset($parameters['select'][$alias]);
         }
     }
     //////////////////////////////////
     // sql query build
     //////////////////////////////////
     // mandatory fields to be selected anyway
     // alias => field
     $fields = array('L.ID' => 'L.ID', 'L.CODE' => 'L.CODE', 'L.SORT' => 'L.SORT', 'LT_SORT' => 'LT.DISPLAY_SORT');
     if ($nameAlias === false || !preg_match('#^[a-zA-Z0-9]+$#', $nameAlias)) {
         $fields['NAME'] = 'LN.NAME';
     } else {
         $fields[$nameAlias] = 'LN.NAME';
     }
     $fields = array_merge($fields, array('L.LEFT_MARGIN' => 'L.LEFT_MARGIN', 'L.RIGHT_MARGIN' => 'L.RIGHT_MARGIN'));
     $groupFields = $fields;
     // additional fields to select
     foreach ($parameters['select'] as $alias => $fld) {
         $lFld = 'L.' . $fld;
         // check if field is already selected
         if ((string) $alias === (string) intval($alias)) {
             // already selected
             if (in_array($lFld, $fields)) {
                 continue;
             }
             $fields[$lFld] = $lFld;
             //$groupFields[$lFld] = $lFld;
         } else {
             if (isset($fields[$alias])) {
                 continue;
             }
             $fields[$alias] = $lFld;
             //$groupFields[$alias] = $lFld;
         }
         $groupFields[$lFld] = $lFld;
     }
     if ($doCountChildren) {
         $fields['CHILD_CNT'] = 'COUNT(LC.ID)';
     }
     // make select sql
     $selectSql = array();
     foreach ($fields as $alias => $fld) {
         if ($fld == $alias) {
             $selectSql[] = $fld;
         } else {
             $selectSql[] = $fld . ' as ' . $alias;
         }
     }
     $selectSql = implode(', ', $selectSql);
     //$groupSql = implode(', ', array_keys($groupFields));
     $groupSql = implode(', ', $groupFields);
     $mainSql = "select {$selectSql}\n\t\t\t\t\t\tfrom {$locationTable} L \n\t\t\t\t\t\t\tinner join {$locationNameTable} LN on L.ID = LN.LOCATION_ID\n\t\t\t\t\t\t\tinner join {$locationTypeTable} LT on L.TYPE_ID = LT.ID " . ($doCountChildren ? "\n\t\t\t\t\t\t\t\tleft join {$locationTable} LC on L.ID = LC.PARENT_ID\n\t\t\t\t\t\t\t" : "") . " \n\n\t\t\t\t\t\t%SITE_FILTER_CONDITION%\n\n\t\t\t\t\t\twhere \n\n\t\t\t\t\t\t\t%MAIN_FILTER_CONDITION%\n\n\t\t\t\t\t\t\t%GROUP_BY%\n\t\t\t\t\t\t\t";
     $where = array();
     if ($doFilterByLang) {
         $where[] = "LN.LANGUAGE_ID = '" . $filterLang . "'";
     }
     if ($doFilterByParent) {
         $where[] = "L.PARENT_ID = '" . $filterParentId . "'";
     }
     if ($doFilterById) {
         $where[] = "L.ID = '" . $filterId . "'";
     }
     if ($doFilterByCode) {
         $where[] = "L.CODE = '" . $filterCode . "'";
     }
     if ($doFilterByType) {
         $where[] = "L.TYPE_ID = '" . $filterTypeId . "'";
     }
     if ($doFilterByName) {
         $where[] = "LN.NAME_UPPER like '" . $filterName . "%'";
     }
     $mainSql = str_replace('%MAIN_FILTER_CONDITION%', implode(' and ', $where), $mainSql);
     $needDistinct = false;
     $unionized = false;
     $artificialNav = false;
     if (!$doFilterBySite) {
         $sql = str_replace('%SITE_FILTER_CONDITION%', '', $mainSql);
     } else {
         $sql = array();
         if ($hasLocLinks) {
             $sql[] = str_replace('%SITE_FILTER_CONDITION%', "\n\n\t\t\t\t\tinner join {$locationTable} L2 on L2.LEFT_MARGIN <= L.LEFT_MARGIN and L2.RIGHT_MARGIN >= L.RIGHT_MARGIN\n\t\t\t\t\tinner join {$locationSiteTable} LS2 on L2.ID = LS2.LOCATION_ID and LS2.LOCATION_TYPE = 'L' and LS2.SITE_ID = '{$filterSite}'\n\n\t\t\t\t", $mainSql);
         }
         if ($hasGrpLinks) {
             $sql[] = str_replace('%SITE_FILTER_CONDITION%', "\n\n\t\t\t\t\tinner join {$locationTable} L2 on L2.LEFT_MARGIN <= L.LEFT_MARGIN and L2.RIGHT_MARGIN >= L.RIGHT_MARGIN\n\t\t\t\t\tinner join {$locationGroupTable} LG on LG.LOCATION_ID = L2.ID\n\t\t\t\t\tinner join {$locationSiteTable} LS2 on LG.LOCATION_GROUP_ID = LS2.LOCATION_ID and LS2.LOCATION_TYPE = 'G' and LS2.SITE_ID = '{$filterSite}'\n\n\t\t\t\t", $mainSql);
             $useDistinct = true;
         }
         $cnt = count($sql);
         if ($cnt == 1) {
             $needDistinct = true;
         } else {
             // UNION removes duplicates, so distinct is required only when no union here
             $unionized = true;
         }
         $sql = ($cnt > 1 ? '(' : '') . implode(') union (', $sql) . ($cnt > 1 ? ')' : '');
     }
     // set groupping if needed
     $sql = str_replace('%GROUP_BY%', $needDistinct || $doCountChildren ? "group by {$groupSql}" : '', $sql);
     if (!is_array($parameters['order'])) {
         $sql .= " order by 3, 4 asc, 5";
     } else {
         // currenly spike
         if (isset($parameters['order']['NAME.NAME'])) {
             $sql .= " order by 5 " . ($parameters['order']['NAME.NAME'] == 'asc' ? 'asc' : 'desc');
         }
     }
     $offset = intval($parameters['offset']);
     $limit = intval($parameters['limit']);
     if ($limit) {
         if ($dbConnection->getType() == 'mssql') {
             // due to huge amount of limitations of windowed functions in transact, using artificial nav here
             // (does not support UNION and integer indices in ORDER BY)
             $artificialNav = true;
         } else {
             $sql = $dbHelper->getTopSql($sql, $limit, $offset);
         }
     }
     $res = $dbConnection->query($sql);
     if ($artificialNav) {
         $result = array();
         $i = -1;
         while ($item = $res->fetch()) {
             $i++;
             if ($i < $offset) {
                 continue;
             }
             if ($i >= $offset + $limit) {
                 break;
             }
             $result[] = $item;
         }
         return new DB\ArrayResult($result);
     } else {
         return $res;
     }
 }
Example #19
0
foreach ($fields as $field) {
    $select[] = $field['FIELD_NAME'];
}
$params = array('select' => $select, 'filter' => $filter, 'order' => array($by => $order));
$company = CompanyTable::getList($params);
$dbResultList = new CAdminResult($company, $sTableID);
$dbResultList->NavStart();
$lAdmin->NavText($dbResultList->GetNavPrint(Loc::getMessage("SALE_COMPANY")));
$headers = array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "ACTIVE", "content" => Loc::getMessage("SALE_COMPANY_ACTIVE"), "sort" => "ACTIVE", "default" => true), array("id" => "NAME", "content" => Loc::getMessage("SALE_COMPANY_NAME"), "sort" => "NAME", "default" => true), array("id" => "LOCATION_ID", "content" => Loc::getMessage("SALE_COMPANY_LOCATION_ID"), "sort" => "LOCATION_ID", "default" => true), array("id" => "CODE", "content" => Loc::getMessage("SALE_COMPANY_CODE"), "sort" => "CODE", "default" => true));
$USER_FIELD_MANAGER->AdminListAddHeaders(CompanyTable::getUfId(), $headers);
$lAdmin->AddHeaders($headers);
$allSelectedFields = array("ID" => false, "ACTIVE" => false, "NAME" => false, "LOCATION_ID" => false, "CODE" => false);
$selectedFields = $lAdmin->GetVisibleHeaderColumns();
$allSelectedFields = array_merge($allSelectedFields, array_fill_keys($selectedFields, true));
while ($company = $dbResultList->NavNext(true, "f_")) {
    $res = \Bitrix\Sale\Location\LocationTable::getPathToNodeByCode($company['LOCATION_ID'], array('select' => array('CHAIN' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => Application::getInstance()->getContext()->getLanguage())));
    $path = array();
    while ($item = $res->fetch()) {
        $path[] = $item['CHAIN'];
    }
    $company['LOCATION_ID'] = implode(', ', array_reverse($path));
    $row =& $lAdmin->AddRow($f_ID, $company, "sale_company_edit.php?ID=" . $f_ID . "&lang=" . $lang, Loc::getMessage("SALE_COMPANY_EDIT_DESCR"));
    $row->AddField("ID", "<a href=\"sale_company_edit.php?ID=" . $f_ID . "&lang=" . $lang . GetFilterParams("filter_") . "\">" . $f_ID . "</a>");
    $row->AddCheckField("ACTIVE");
    $row->AddInputField("NAME");
    $row->AddField("LOCATION_ID", $company['LOCATION_ID']);
    $row->AddInputField("CODE");
    $USER_FIELD_MANAGER->AddUserFields(CompanyTable::getUfId(), $company, $row);
    $arActions = array(array("ICON" => "edit", "TEXT" => Loc::getMessage("SALE_COMPANY_EDIT"), "TITLE" => Loc::getMessage("SALE_COMPANY_EDIT_DESCR"), "ACTION" => $lAdmin->ActionRedirect("sale_company_edit.php?ID=" . $f_ID . "&lang=" . $lang), "DEFAULT" => true));
    if ($saleModulePermissions >= "W") {
        $arActions[] = array("SEPARATOR" => true);
Example #20
0
	protected static function getPathToNodes($list)
	{
		$res = Location\LocationTable::getPathToMultipleNodes(
			$list, 
			array(
				'select' => (
					!!$_REQUEST['BEHAVIOUR']['PREFORMAT'] ? 
					array('ID', 'VALUE' => 'ID', 'DISPLAY' => 'NAME.NAME', 'CODE') : 
					array('ID', 'LNAME' => 'NAME.NAME', 'CODE')
				),
				'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)
			)
		);

		$pathItems = array();
		$result = array();

		while($path = $res->fetch())
		{
			// format path as required for JSON responce
			$chain = array();
			$itemId = false;

			$i = -1;
			foreach($path['PATH'] as $id => $pItem)
			{
				$i++;

				if(!$i) // we dont need for an item itself in the path chain
				{
					$itemId = $id;
					continue;
				}

				$pathItems[$pItem['ID']] = $pItem;
				$chain[] = intval($pItem['ID']);
			}

			$result['PATH'][$itemId] = $chain;
		}

		$result['PATH_ITEMS'] = $pathItems;

		return $result;
	}
Example #21
0
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_LOC_ADD'), 'TITLE' => GetMessage('CRM_LOC_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LOCATIONS_ADD'], array()) . ($filterParentId ? '?PARENT_ID=' . $filterParentId : ''), 'ICON' => 'btn-new');
    }
    // IMPORT IN LIST
    if ($locImport) {
        if (CSaleLocation::isLocationProEnabled()) {
            $link = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LOCATIONS_IMPORT'], array());
        } else {
            $link = "javascript:(new BX.CDialog({\n\t\t\t\t\t\t\t\t'content_url':'/bitrix/components/bitrix/crm.config.locations.import/box.php',\n\t\t\t\t\t\t\t\t'width':'540',\n\t\t\t\t\t\t\t\t'height':'275',\n\t\t\t\t\t\t\t\t'resizable':false })).Show();";
        }
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_LOCATIONS_IMPORT'), 'TITLE' => GetMessage('CRM_LOCATIONS_IMPORT_TITLE'), 'LINK' => $link, 'ICON' => 'btn-new');
    }
} elseif ($arParams['TYPE'] == 'edit') {
    $parentId = false;
    if (CSaleLocation::isLocationProEnabled()) {
        if ($locID) {
            $res = Location\LocationTable::getByID($locID)->fetch();
            if (!!$res['ID']) {
                $parentId = $res['PARENT_ID'];
            }
        } elseif (isset($_REQUEST['PARENT_ID'])) {
            $parentId = intval($_REQUEST['PARENT_ID']);
        }
    }
    // GO TO PARENT LIST IN EDIT
    $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_LOC_LIST'), 'TITLE' => GetMessage('CRM_LOC_LIST_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LOCATIONS_LIST'], array()), 'ICON' => 'btn-list');
    // ADD IN EDIT
    if ($locAdd) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_LOC_ADD'), 'TITLE' => GetMessage('CRM_LOC_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LOCATIONS_ADD'], array()) . ($parentId !== false ? '?PARENT_ID=' . $parentId : ''), 'ICON' => 'btn-new');
    }
} elseif ($arParams['TYPE'] == 'show') {
}
Example #22
0
 private static function checkLocationIsInLinkedPart($locationId, $siteId)
 {
     $types = \CSaleLocation::getTypes();
     $class = self::CONN_ENTITY_NAME . 'Table';
     if (!$class::checkLinkUsageAny($siteId)) {
         return true;
     }
     if ((string) $locationId == '') {
         return false;
     }
     $node = \Bitrix\Sale\Location\LocationTable::getList(array('filter' => array('=ID' => $locationId), 'select' => array('ID', 'LEFT_MARGIN', 'RIGHT_MARGIN')))->fetch();
     if (!is_array($node)) {
         return false;
     }
     $stat = $class::getLinkStatusForMultipleNodes(array($node), $siteId);
     return $stat[$node['ID']] !== $class::LSTAT_IN_NOT_CONNECTED_BRANCH;
 }
	public static function getLocationPathDisplay($code)
	{
		if(!strlen($code))
			return '';

		$parameters = array(
			'select' => array('LNAME' => 'NAME.NAME'),
			'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
		);

		try
		{
			$res = Location\LocationTable::getPathToNodeByCode($code, $parameters);
		}
		catch(\Exception $e)
		{
			return $code;
		}

		$path = array();
		while($item = $res->fetch())
			$path[] = $item['LNAME'];

		return implode(', ', array_reverse($path));
	}
Example #24
0
 /**
  * Check if location is connected with entity
  * 
  * @param $entityPrimary mixed Entity being checked
  * @param $locationPrimary mixed Location being checked. Could be a value of ID or CODE depending on what connection type is selected (see below)
  * @param $behaviour mixed[] A set of flags that modify function behaviour
  * 		<li> LOCATION_LINK_TYPE string One of: ID, CODE, AUTO. 
  * 			If ID, than match by ID is used (default, for compatibility), if CODE than match by CODE. 
  * 			In case of AUTO the target field value depends on entity connect type.
  * 
  * @return boolean
  */
 public static function checkConnectionExists($entityPrimary, $locationPrimary, array $behaviour = array('LOCATION_LINK_TYPE' => 'ID'))
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, '$entityPrimary');
     $locationPrimary = Assert::expectStringNotNull($locationPrimary, '$locationPrimary');
     if (!isset($behaviour['LOCATION_LINK_TYPE'])) {
         $behaviour['LOCATION_LINK_TYPE'] = 'ID';
     } else {
         $behaviour['LOCATION_LINK_TYPE'] = Assert::expectEnumerationMember($behaviour['LOCATION_LINK_TYPE'], array('AUTO', 'ID', 'CODE'), '$behaviour[LOCATION_LINK_TYPE]');
     }
     if (!static::checkLinkUsageAny($entityPrimary)) {
         return true;
     }
     if ($behaviour['LOCATION_LINK_TYPE'] == 'AUTO') {
         $field = static::getUseCodes() ? 'CODE' : 'ID';
     } else {
         $field = $behaviour['LOCATION_LINK_TYPE'];
     }
     $node = LocationTable::getList(array('filter' => array('=' . $field => $locationPrimary), 'select' => array('ID', 'LEFT_MARGIN', 'RIGHT_MARGIN'), 'limit' => 1))->fetch();
     if (!intval($node['ID'])) {
         throw new \Bitrix\Sale\Location\Tree\NodeNotFoundException(false, array('INFO' => array($field => $locationPrimary)));
     }
     $result = static::getLinkStatusForMultipleNodes(array($node), $entityPrimary);
     return $result[$node['ID']] == self::LSTAT_IS_CONNECTOR || $result[$node['ID']] == self::LSTAT_BELOW_CONNECTOR;
 }
Example #25
0
					}
				}
			}
		}
		elseif($_REQUEST['ACT'] == 'GET_ZIP_BY_LOC')
		{
			if(!intval($_REQUEST['LOC']))
				$result['ERRORS'] = array('No location id passed');
			else
			{
				$item = \Bitrix\Sale\Location\LocationTable::getList(
					array(
						'filter' => array(
							'=ID' => intval($_REQUEST['LOC']),
							'=EXTERNAL.SERVICE.CODE' => 'ZIP'
						),
						'select' => array(
							'ZIP' => 'EXTERNAL.XML_ID'
						)
					)
				)->fetch();

				if(strlen($item['ZIP']))
					$result['DATA']['ZIP'] = $item['ZIP'];
				else
					$result['ERRORS'] = array('None were found');
			}
		}

		header('Content-Type: application/x-javascript; charset='.LANG_CHARSET);
		print(CUtil::PhpToJSObject(array(
Example #26
0
			$paySystem = $arGeneralInfo["paySystem"]["sber"][$personType];
		elseif(IntVal($arGeneralInfo["paySystem"]["paypal"][$personType]) > 0 )
			$paySystem = $arGeneralInfo["paySystem"]["paypal"][$personType];
		else
		{
			$dbPS = CSalePaySystem::GetList(Array(), Array("LID" => WIZARD_SITE_ID));
			if($arPS = $dbPS->Fetch())
				$paySystem = $arPS["ID"];
		}

		if(\Bitrix\Main\Config\Option::get('sale', 'sale_locationpro_migrated', '') == 'Y')
		{
			if(!strlen($location))
			{
				// get first found
				$item = \Bitrix\Sale\Location\LocationTable::getList(array('limit' => 1, 'select' => array('CODE')))->fetch();
				if($item)
					$location = $item['CODE'];
			}
		}
		else
		{
			if(IntVal($location) <= 0)
			{
				$dbLocation = CSaleLocation::GetList(Array("ID" => "ASC"), Array("LID" => $lang));
				if($arLocation = $dbLocation->Fetch())
				{
					$location = $arLocation["ID"];
				}
			}
		}
Example #27
0
if ($saleModulePermissions >= 'W') {
    ?>
	<tr>
		<td><strong><?php 
    echo GetMessage("COMPANY_LOCATION_ID");
    ?>
</strong></td>
		<td>
			<?php 
    $APPLICATION->IncludeComponent("bitrix:sale.location.selector." . \Bitrix\Sale\Location\Admin\LocationHelper::getWidgetAppearance(), "", array("ID" => "", "CODE" => $fields['LOCATION_ID'], "INPUT_NAME" => "LOCATION_ID", "PROVIDE_LINK_BY" => "code", "SHOW_ADMIN_CONTROLS" => 'Y', "SELECT_WHEN_SINGLE" => 'N', "FILTER_BY_SITE" => 'Y', "FILTER_SITE_ID" => Application::getInstance()->getContext()->getSite(), "SHOW_DEFAULT_LOCATIONS" => 'N', "SEARCH_BY_PRIMARY" => 'Y'), false);
    ?>
		</td>
	</tr>
<?php 
} else {
    $res = \Bitrix\Sale\Location\LocationTable::getPathToNodeByCode($fields['LOCATION_ID'], array('select' => array('CHAIN' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => $lang)));
    $path = array();
    while ($item = $res->fetch()) {
        $path[] = $item['CHAIN'];
    }
    $path = implode(', ', array_reverse($path));
    ?>
	<tr>
		<td><?php 
    echo GetMessage("COMPANY_LOCATION");
    ?>
</td>
		<td><?php 
    echo $path;
    ?>
</td>
Example #28
0
 public function initializeData()
 {
     $dbConnection = Main\HttpApplication::getConnection();
     $res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID', 'DEPTH_LEVEL', 'SORT'), 'order' => array('LEFT_MARGIN' => 'asc'), 'limit' => self::STEP_SIZE, 'offset' => $this->procData['OFFSET']));
     $this->procData['TYPE_SORT'] = $this->rarefact($this->procData['TYPE_SORT']);
     $cnt = 0;
     while ($item = $res->fetch()) {
         // tmp!!!!
         //$name = Location\Name\LocationTable::getList(array('select' => array('NAME'), 'filter' => array('=LOCATION_ID' => $item['ID'], '=LANGUAGE_ID' => 'ru')))->fetch();
         if ($item['DEPTH_LEVEL'] < $this->procData['DEPTH']) {
             $newPC = array();
             foreach ($this->procData['PATH'] as $dl => $id) {
                 if ($dl >= $item['DEPTH_LEVEL']) {
                     break;
                 }
                 $newPC[$dl] = $id;
             }
             $this->procData['PATH'] = $newPC;
         }
         $this->procData['PATH'][$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']);
         if (is_array($this->procData['ALLOWED_TYPES']) && in_array($item['TYPE_ID'], $this->procData['ALLOWED_TYPES'])) {
             $data = array('LOCATION_ID' => $item['ID'], 'RELEVANCY' => $this->procData['TYPE_SORT'][$item['TYPE_ID']] + $item['SORT']);
             $wordsAdded = array();
             /*
             _dump_r('############################');
             _dump_r('LOCATION: '.$name['NAME']);
             _dump_r('TYPE RELEVANCY: '.$data['RELEVANCY']);
             _dump_r('PATH:');
             _dump_r($this->procData['PATH']);
             */
             $this->procData['DEPTH'] = $item['DEPTH_LEVEL'];
             // pre-load missing words
             $wordCount = 0;
             foreach ($this->procData['PATH'] as &$pathItem) {
                 if (!isset($pathItem['WORDS'])) {
                     $sql = "\n\t\t\t\t\t\t\tselect WS.POSITION from " . WordTable::getTableNameWord2Location() . " WL\n\t\t\t\t\t\t\t\tinner join " . WordTable::getTableName() . " WS on WL.WORD_ID = WS.ID\n\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\tWL.LOCATION_ID = '" . intval($pathItem['ID']) . "'\n\t\t\t\t\t\t";
                     $wordRes = $dbConnection->query($sql);
                     $pathItem['WORDS'] = array();
                     while ($wordItem = $wordRes->fetch()) {
                         $pathItem['WORDS'][] = $wordItem['POSITION'];
                     }
                     $pathItem['WORDS'] = array_unique($pathItem['WORDS']);
                 }
                 $wordCount += count($pathItem['WORDS']);
             }
             // count words
             //_dump_r('Words total: '.$wordCount);
             $wOffset = 0;
             foreach ($this->procData['PATH'] as &$pathItem) {
                 foreach ($pathItem['WORDS'] as $i => $position) {
                     $wordWeight = $wordCount - $wOffset;
                     $tmpData = $data;
                     $tmpData['RELEVANCY'] += $wordWeight;
                     //_dump_r('	Word relevancy: '.$data['RELEVANCY'].' ==>> '.$tmpData['RELEVANCY']);
                     if (!isset($wordsAdded[$position])) {
                         $this->indexInserter->insert(array_merge(array('POSITION' => $position), $tmpData));
                         $wordsAdded[$position] = true;
                     }
                     $wOffset++;
                 }
             }
             unset($pathItem);
         }
         $cnt++;
     }
     $this->indexInserter->flush();
     $this->procData['OFFSET'] += self::STEP_SIZE;
     return !$cnt;
 }
Example #29
0
 public static function importFile(&$descriptior)
 {
     $timeLimit = ini_get('max_execution_time');
     if ($timeLimit < $descriptior['TIME_LIMIT']) {
         set_time_limit($descriptior['TIME_LIMIT'] + 5);
     }
     $endTime = time() + $descriptior['TIME_LIMIT'];
     if ($descriptior['STEP'] == 'rebalance') {
         Location\LocationTable::resort();
         Location\LocationTable::resetLegacyPath();
         $descriptior['STEP'] = 'done';
     }
     if ($descriptior['STEP'] == 'import') {
         if (!isset($descriptior['DO_SYNC'])) {
             $res = \Bitrix\Sale\Location\LocationTable::getList(array('select' => array('CNT')))->fetch();
             $descriptior['DO_SYNC'] = intval($res['CNT'] > 0);
         }
         if (!isset($descriptior['TYPES'])) {
             $descriptior['TYPE_MAP'] = static::getTypeMap($descriptior['TYPE_FILE']);
             $descriptior['TYPES'] = static::createTypes($descriptior['TYPE_MAP']);
             $descriptior['SERVICE_MAP'] = static::getServiceMap($descriptior['SERVICE_FILE']);
             $descriptior['SERVICES'] = static::getExistedServices();
         }
         $csvReader = new CSVReader();
         $csvReader->LoadFile($descriptior['FILE']);
         while (time() < $endTime) {
             $block = $csvReader->ReadBlockLowLevel($descriptior['POS'], 100);
             if (!count($block)) {
                 break;
             }
             foreach ($block as $item) {
                 if ($descriptior['DO_SYNC']) {
                     $id = static::checkLocationCodeExists($item['CODE']);
                     if ($id) {
                         $descriptior['CODES'][$item['CODE']] = $id;
                         continue;
                     }
                 }
                 // type
                 $item['TYPE_ID'] = $descriptior['TYPES'][$item['TYPE_CODE']];
                 unset($item['TYPE_CODE']);
                 // parent id
                 if (strlen($item['PARENT_CODE'])) {
                     if (!isset($descriptior['CODES'][$item['PARENT_CODE']])) {
                         $descriptior['CODES'][$item['PARENT_CODE']] = static::checkLocationCodeExists($item['PARENT_CODE']);
                     }
                     $item['PARENT_ID'] = $descriptior['CODES'][$item['PARENT_CODE']];
                 }
                 unset($item['PARENT_CODE']);
                 // ext
                 if (is_array($item['EXT'])) {
                     foreach ($item['EXT'] as $code => $values) {
                         if (is_array($values) && !empty($values)) {
                             if (!isset($descriptior['SERVICES'][$code])) {
                                 $descriptior['SERVICES'][$code] = static::createService(array('CODE' => $code));
                             }
                             foreach ($values as $value) {
                                 if (!strlen($value)) {
                                     continue;
                                 }
                                 $item['EXTERNAL'][] = array('SERVICE_ID' => $descriptior['SERVICES'][$code], 'XML_ID' => $value);
                             }
                         }
                     }
                 }
                 unset($item['EXT']);
                 $res = Location\LocationTable::add($item, array('REBALANCE' => false, 'RESET_LEGACY' => false));
                 if (!$res->isSuccess()) {
                     throw new Main\SystemException('Cannot create location');
                 }
                 $descriptior['CODES'][$item['CODE']] = $res->getId();
             }
         }
         if (!count($block)) {
             unset($descriptior['CODES']);
             $descriptior['STEP'] = 'rebalance';
         }
     }
     return $descriptior['STEP'] == 'done';
 }
Example #30
0
 protected static function getErrorSingle(array $input, $value)
 {
     return \Bitrix\Sale\Location\LocationTable::getByCode($value)->fetch() ? array() : array('INVALID' => Loc::getMessage('INPUT_INVALID_ERROR'));
 }