• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_invoice.php
  • Класс: \CAllCrmInvoice
  • Вызов: CAllCrmInvoice::GetPropertyValues
static function GetPropertyValues($invoiceId, $personTypeId)
{
	$invoiceId = (int)$invoiceId;
	$personTypeId = (int)$personTypeId;
	$result = [];

	if (!Bitrix\Main\Loader::includeModule('sale'))
	{
		return $result;
	}

	$query = new Bitrix\Main\Entity\Query(Bitrix\Crm\Invoice\Internals\InvoicePropsValueTable::getEntity());
	$query->registerRuntimeField(
		'',
		new Bitrix\Main\Entity\ReferenceField('LOCATION',
			Bitrix\Sale\Location\LocationTable::getEntity(),
			[
				'=this.PROPERTY.TYPE' => ['?', 'LOCATION'],
				'=this.VALUE' => 'ref.CODE'
			],
			['join_type' => 'LEFT']
		)
	);
	$query->setSelect(
		[
			'ID',
			'CODE',
			'ORDER_PROPS_ID',
			'VALUE',
			'PROPERTY_TYPE' => 'PROPERTY.TYPE',
			'LOCATION_ID' => 'LOCATION.ID'
		]
	);
	$query->setFilter(['=ORDER_ID' => $invoiceId]);
	$res = $query->exec();
	$propertyIds = [];
	$propertyValues = [];
	while ($row = $res->fetch())
	{
		if ($row['PROPERTY_TYPE'] === 'LOCATION')
		{
			$row['VALUE'] = $row['LOCATION_ID'];
		}
		unset($row['PROPERTY_TYPE'], $row['LOCATION_ID']);
		$propertyValues[] = $row;
		$propertyIds[] = $row['ORDER_PROPS_ID'];
	}

	$dbRes = \Bitrix\Crm\Invoice\Property::getList([
		'select' => ['ID', 'TYPE'],
		'filter' => ['ID' => $propertyIds],
	]);
	$propertyTypes = [];
	while ($row = $dbRes->Fetch())
	{
		$row = CSaleOrderPropsAdapter::convertNewToOld($row);
		$propertyTypes[$row['ID']] = $row['TYPE'];
	}
	$orderProps = new CSaleOrderProps();
	$allowedPropertiesInfo = CCrmInvoice::_getAllowedPropertiesInfo();
	foreach ($propertyValues as $propertyValue)
	{
		if (isset($propertyTypes[$propertyValue['ORDER_PROPS_ID']]))
		{
			$curOrderProps = $orderProps->GetRealValue(
				$propertyValue['ORDER_PROPS_ID'],
				$propertyValue['CODE'],
				$propertyTypes[$propertyValue['ORDER_PROPS_ID']],
				$propertyValue['VALUE'],
				LANGUAGE_ID
			);

			foreach ($curOrderProps as $key => $value)
			{
				if (isset($allowedPropertiesInfo[$personTypeId][$key]))
					$result[$key] = $value;
			}
		}
	}

	return $result;
}