• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_invoice.php
  • Класс: \CAllCrmInvoice
  • Вызов: CAllCrmInvoice::__GetCompanyAndContactFromPost
static function __GetCompanyAndContactFromPost(&$post)
{
	//TODO: Move this method to crm.invoice edit

	$result = array('COMPANY' => 0, 'CONTACT' => 0, 'COMPANY_ISSET' => false, 'CONTACT_ISSET' => false);

	$primaryEntityTypeName = isset($post['PRIMARY_ENTITY_TYPE']) ? $post['PRIMARY_ENTITY_TYPE'] : '';
	$primaryEntityTypeID = CCrmOwnerType::ResolveID($primaryEntityTypeName);
	$primaryEntityIsSet = isset($post['PRIMARY_ENTITY_ID']);
	$primaryEntityID = $primaryEntityIsSet ? (int)$post['PRIMARY_ENTITY_ID'] : 0;

	if($primaryEntityTypeID === CCrmOwnerType::Contact)
	{
		$result['CONTACT'] = $primaryEntityID;
		$result['CONTACT_ISSET'] = $primaryEntityIsSet;
	}
	elseif($primaryEntityTypeID === CCrmOwnerType::Company)
	{
		$result['COMPANY'] = $primaryEntityID;
		$result['COMPANY_ISSET'] = $primaryEntityIsSet;
		if(isset($post['SECONDARY_ENTITY_IDS']))
		{
			$secondaryEntityIDs = explode(',', $post['SECONDARY_ENTITY_IDS']);
			if(!empty($secondaryEntityIDs))
			{
				$result['CONTACT'] = (int)$secondaryEntityIDs[0];
				$result['CONTACT_ISSET'] = true;
			}
		}
	}

	return $result;
}