CAllCrmQuote::CompareFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmQuote
  4. CompareFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_quote.php
  • Класс: \CAllCrmQuote
  • Вызов: CAllCrmQuote::CompareFields
static function CompareFields($arFieldsOrig, $arFieldsModif, $bCheckPerms = true, $arOptions = null)
{
	if(!is_array($arOptions))
	{
		$arOptions = array();
	}

	$arMsg = Array();

	if (array_key_exists('QUOTE_NUMBER', $arFieldsModif))
	{
		$origQuoteNumber = isset($arFieldsOrig['QUOTE_NUMBER']) ? $arFieldsOrig['QUOTE_NUMBER'] : '';
		$modifQuoteNumber = isset($arFieldsModif['QUOTE_NUMBER']) ? $arFieldsModif['QUOTE_NUMBER'] : '';
		if ($origQuoteNumber != $modifQuoteNumber)
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'QUOTE_NUMBER',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_QUOTE_NUMBER'),
				'EVENT_TEXT_1' => !empty($origQuoteNumber) ? $origQuoteNumber : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				'EVENT_TEXT_2' => !empty($modifQuoteNumber) ? $modifQuoteNumber : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY')
			);
		unset($origQuoteNumber, $modifQuoteNumber);
	}

	if (array_key_exists('TITLE', $arFieldsModif))
	{
		$origTitle = isset($arFieldsOrig['TITLE']) ? $arFieldsOrig['TITLE'] : '';
		$modifTitle = isset($arFieldsModif['TITLE']) ? $arFieldsModif['TITLE'] : '';
		if ($origTitle != $modifTitle)
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'TITLE',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TITLE'),
				'EVENT_TEXT_1' => !empty($origTitle) ? $origTitle : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				'EVENT_TEXT_2' => !empty($modifTitle) ? $modifTitle : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY')
			);
		unset($origTitle, $modifTitle);
	}

	if (array_key_exists('LEAD_ID', $arFieldsModif))
	{
		$origLeadId = isset($arFieldsOrig['LEAD_ID']) ? intval($arFieldsOrig['LEAD_ID']) : 0;
		$modifLeadId = isset($arFieldsModif['LEAD_ID']) ? intval($arFieldsModif['LEAD_ID']) : 0;
		if ($origLeadId != $modifLeadId)
		{
			$arLead = Array();

			$arFilterTmp = array('@ID' => array($origLeadId, $modifLeadId));
			if (!$bCheckPerms)
			{
				$arFilterTmp["CHECK_PERMISSIONS"] = "N";
			}

			$dbRes = CCrmLead::GetListEx(array('TITLE'=>'ASC'), $arFilterTmp);
			while ($arRes = $dbRes->Fetch())
			{
				$arLead[$arRes['ID']] = $arRes['TITLE'];
			}

			$arMsg[] = Array(
				'ENTITY_FIELD' => 'LEAD_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_LEAD_ID'),
				'EVENT_TEXT_1' => CrmCompareFieldsList($arLead, $origLeadId),
				'EVENT_TEXT_2' => CrmCompareFieldsList($arLead, $modifLeadId)
			);
		}
		unset($origLeadId, $modifLeadId);
	}

	if (array_key_exists('DEAL_ID', $arFieldsModif))
	{
		$origDealId = isset($arFieldsOrig['DEAL_ID']) ? intval($arFieldsOrig['DEAL_ID']) : 0;
		$modifDealId = isset($arFieldsModif['DEAL_ID']) ? intval($arFieldsModif['DEAL_ID']) : 0;
		if ($origDealId != $modifDealId)
		{
			$arDeal = Array();

			$arFilterTmp = array('ID' => array($origDealId, $modifDealId));
			if (!$bCheckPerms)
				$arFilterTmp["CHECK_PERMISSIONS"] = "N";

			$dbRes = CCrmDeal::GetList(Array('TITLE'=>'ASC'), $arFilterTmp);
			while ($arRes = $dbRes->Fetch())
				$arDeal[$arRes['ID']] = $arRes['TITLE'];

			$arMsg[] = Array(
				'ENTITY_FIELD' => 'DEAL_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_DEAL_ID'),
				'EVENT_TEXT_1' => CrmCompareFieldsList($arDeal, $origDealId),
				'EVENT_TEXT_2' => CrmCompareFieldsList($arDeal, $modifDealId)
			);
		}
		unset($origDealId, $modifDealId);
	}

	if (array_key_exists('COMPANY_ID', $arFieldsModif))
	{
		$origCompanyId = isset($arFieldsOrig['COMPANY_ID']) ? intval($arFieldsOrig['COMPANY_ID']) : 0;
		$modifCompanyId = isset($arFieldsModif['COMPANY_ID']) ? intval($arFieldsModif['COMPANY_ID']) : 0;
		if ($origCompanyId != $modifCompanyId)
		{
			$arCompany = Array();

			$arFilterTmp = array('ID' => array($origCompanyId, $modifCompanyId));
			if (!$bCheckPerms)
				$arFilterTmp["CHECK_PERMISSIONS"] = "N";

			$dbRes = CCrmCompany::GetList(Array('TITLE'=>'ASC'), $arFilterTmp);
			while ($arRes = $dbRes->Fetch())
				$arCompany[$arRes['ID']] = $arRes['TITLE'];

			$arMsg[] = Array(
				'ENTITY_FIELD' => 'COMPANY_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_COMPANY_ID'),
				'EVENT_TEXT_1' => CrmCompareFieldsList($arCompany, $origCompanyId),
				'EVENT_TEXT_2' => CrmCompareFieldsList($arCompany, $modifCompanyId)
			);
		}
		unset($origCompanyId, $modifCompanyId);
	}

	if(isset($arOptions['CONTACTS']) && is_array($arOptions['CONTACTS']))
	{
		$addedContactIDs = isset($arOptions['CONTACTS']['ADDED']) && is_array($arOptions['CONTACTS']['ADDED'])
			? $arOptions['CONTACTS']['ADDED'] : array();

		$removedContactIDs = isset($arOptions['CONTACTS']['REMOVED']) && is_array($arOptions['CONTACTS']['REMOVED'])
			? $arOptions['CONTACTS']['REMOVED'] : array();

		if(!empty($addedContactIDs) || !empty($removedContactIDs))
		{
			//region Preparation of contact names
			$dbResult = CCrmContact::GetListEx(
				array(),
				array(
					'CHECK_PERMISSIONS' => 'N',
					'@ID' => array_merge($addedContactIDs, $removedContactIDs)
				),
				false,
				false,
				array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME')
			);

			$contactNames = array();
			while ($ary = $dbResult->Fetch())
			{
				$contactNames[$ary['ID']] = CCrmContact::PrepareFormattedName($ary);
			}
			//endregion
			if(count($addedContactIDs) <= 1 && count($removedContactIDs) <= 1)
			{
				//region Single binding mode
				$arMsg[] = Array(
					'ENTITY_FIELD' => 'CONTACT_ID',
					'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTACT_ID'),
					'EVENT_TEXT_1' => CrmCompareFieldsList(
						$contactNames,
						isset($removedContactIDs[0]) ? $removedContactIDs[0] : 0
					),
					'EVENT_TEXT_2' => CrmCompareFieldsList(
						$contactNames,
						isset($addedContactIDs[0]) ? $addedContactIDs[0] : 0
					)
				);
				//endregion
			}
			else
			{
				//region Multiple binding mode
				//region Add contacts event
				$texts = array();
				foreach($addedContactIDs as $contactID)
				{
					if(isset($contactNames[$contactID]))
					{
						$texts[] = $contactNames[$contactID];
					}
				}

				$arMsg[] = Array(
					'ENTITY_FIELD' => 'CONTACT_ID',
					'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTACTS_ADDED'),
					'EVENT_TEXT_1' => implode(', ', $texts),
				);
				//endregion
				//region Remove companies event
				$texts = array();
				foreach($removedContactIDs as $contactID)
				{
					if(isset($contactNames[$contactID]))
					{
						$texts[] = $contactNames[$contactID];
					}
				}

				$arMsg[] = Array(
					'ENTITY_FIELD' => 'CONTACT_ID',
					'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTACTS_REMOVED'),
					'EVENT_TEXT_1' => implode(', ', $texts),
				);
				//endregion
				//endregion
			}
		}
	}

	if (array_key_exists('MYCOMPANY_ID', $arFieldsModif))
	{
		$origMyCompanyId = isset($arFieldsOrig['MYCOMPANY_ID']) ? intval($arFieldsOrig['MYCOMPANY_ID']) : 0;
		$modifMyCompanyId = isset($arFieldsModif['MYCOMPANY_ID']) ? intval($arFieldsModif['MYCOMPANY_ID']) : 0;
		if ($origMyCompanyId != $modifMyCompanyId)
		{
			$arMyCompany = array();

			$arFilterTmp = array('ID' => array($origMyCompanyId, $modifMyCompanyId));
			if (!$bCheckPerms)
				$arFilterTmp["CHECK_PERMISSIONS"] = "N";

			$dbRes = CCrmCompany::GetList(array('TITLE'=>'ASC'), $arFilterTmp);
			while ($arRes = $dbRes->Fetch())
				$arMyCompany[$arRes['ID']] = $arRes['TITLE'];

			$arMsg[] = array(
				'ENTITY_FIELD' => 'MYCOMPANY_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_MYCOMPANY_ID1'),
				'EVENT_TEXT_1' => CrmCompareFieldsList($arMyCompany, $origMyCompanyId),
				'EVENT_TEXT_2' => CrmCompareFieldsList($arMyCompany, $modifMyCompanyId)
			);
			unset($arMyCompany, $arFilterTmp, $dbRes, $arRes);
		}
		unset($origMyCompanyId, $modifMyCompanyId);
	}

	if (array_key_exists('ASSIGNED_BY_ID', $arFieldsModif))
	{
		$origAssignedById = isset($arFieldsOrig['ASSIGNED_BY_ID']) ? intval($arFieldsOrig['ASSIGNED_BY_ID']) : 0;
		$modifAssignedById = isset($arFieldsModif['ASSIGNED_BY_ID']) ? intval($arFieldsModif['ASSIGNED_BY_ID']) : 0;
		if ($origAssignedById != $modifAssignedById)
		{
			$arUser = Array();
			$dbUsers = CUser::GetList(
				'last_name', 'asc',
				array('ID' => implode('|', array(intval($origAssignedById), intval($modifAssignedById)))),
				array('FIELDS' => array('ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN', 'TITLE', 'EMAIL'))
			);
			while ($arRes = $dbUsers->Fetch())
				$arUser[$arRes['ID']] = CUser::FormatName(CSite::GetNameFormat(false), $arRes);

			$arMsg[] = Array(
				'ENTITY_FIELD' => 'ASSIGNED_BY_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_ASSIGNED_BY_ID'),
				'EVENT_TEXT_1' => CrmCompareFieldsList($arUser, $origAssignedById),
				'EVENT_TEXT_2' => CrmCompareFieldsList($arUser, $modifAssignedById)
			);
		}
		unset($origAssignedById, $modifAssignedById);
	}

	if (array_key_exists('STATUS_ID', $arFieldsModif))
	{
		$origStatusId = isset($arFieldsOrig['STATUS_ID']) ? $arFieldsOrig['STATUS_ID'] : '';
		$modifStatusId = isset($arFieldsModif['STATUS_ID']) ? $arFieldsModif['STATUS_ID'] : '';
		if ($origStatusId != $modifStatusId)
		{
			$arStatus = CCrmStatus::GetStatusList('QUOTE_STATUS');
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'STATUS_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_STATUS_ID_MSGVER_1'),
				'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $origStatusId)),
				'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $modifStatusId))
			);
		}
		unset($origStatusId, $modifStatusId);
	}

	if (array_key_exists('COMMENTS', $arFieldsModif))
	{
		$origComments = isset($arFieldsOrig['COMMENTS']) ? $arFieldsOrig['COMMENTS'] : '';
		$modifComments = isset($arFieldsModif['COMMENTS']) ? $arFieldsModif['COMMENTS'] : '';
		if ($origComments != $modifComments)
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'COMMENTS',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_COMMENTS'),
				'EVENT_TEXT_1' => !empty($origComments) ? TextHelper::convertBbCodeToHtml($origComments) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				'EVENT_TEXT_2' => !empty($modifComments) ? TextHelper::convertBbCodeToHtml($modifComments) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY')
			);
		unset($origComments, $modifComments);
	}

	if (array_key_exists('CONTENT', $arFieldsModif))
	{
		$origContent = isset($arFieldsOrig['CONTENT']) ? $arFieldsOrig['CONTENT'] : '';
		$modifContent = isset($arFieldsModif['CONTENT']) ? $arFieldsModif['CONTENT'] : '';
		if ($origContent != $modifContent)
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'CONTENT',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTENT'),
				'EVENT_TEXT_1' => !empty($origContent)? TextHelper::convertBbCodeToHtml($origContent) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				'EVENT_TEXT_2' => !empty($modifContent)? TextHelper::convertBbCodeToHtml($modifContent) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY')
			);
		unset($origContent, $modifContent);
	}

	if (array_key_exists('TERMS', $arFieldsModif))
	{
		$origTerms = isset($arFieldsOrig['TERMS']) ? $arFieldsOrig['TERMS'] : '';
		$modifTerms = isset($arFieldsModif['TERMS']) ? $arFieldsModif['TERMS'] : '';
		if ($origTerms != $modifTerms)
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'TERMS',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TERMS'),
				'EVENT_TEXT_1' => !empty($origTerms)? TextHelper::convertBbCodeToHtml($origTerms) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				'EVENT_TEXT_2' => !empty($modifTerms)? TextHelper::convertBbCodeToHtml($modifTerms) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
			);
		unset($origTerms, $modifTerms);
	}

	if (array_key_exists('OPPORTUNITY', $arFieldsModif) || array_key_exists('CURRENCY_ID', $arFieldsModif))
	{
		$origOpportunity = isset($arFieldsOrig['OPPORTUNITY']) ? round(doubleval($arFieldsOrig['OPPORTUNITY']), 2) : 0.0;
		$modifOpportunity = isset($arFieldsModif['OPPORTUNITY']) ? round(doubleval($arFieldsModif['OPPORTUNITY']), 2) : $origOpportunity;
		$origCurrencyId = isset($arFieldsOrig['CURRENCY_ID']) ? $arFieldsOrig['CURRENCY_ID'] : '';
		$modifCurrencyId = isset($arFieldsModif['CURRENCY_ID']) ? $arFieldsModif['CURRENCY_ID'] : $origCurrencyId;
		if ($origOpportunity != $modifOpportunity || $origCurrencyId != $modifCurrencyId)
		{
			$arStatus = CCrmCurrencyHelper::PrepareListItems();
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'OPPORTUNITY',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_OPPORTUNITY'),
				'EVENT_TEXT_1' => floatval($arFieldsOrig['OPPORTUNITY']).(($val = CrmCompareFieldsList($arStatus, $origCurrencyId, '')) != '' ? ' ('.$val.')' : ''),
				'EVENT_TEXT_2' => floatval($arFieldsModif['OPPORTUNITY']).(($val = CrmCompareFieldsList($arStatus, $modifCurrencyId, '')) != '' ? ' ('.$val.')' : '')
			);
		}
		unset($origOpportunity, $modifOpportunity, $origCurrencyId, $modifCurrencyId);
	}

	if (array_key_exists('TAX_VALUE', $arFieldsModif) || array_key_exists('CURRENCY_ID', $arFieldsModif))
	{
		if ((isset($arFieldsOrig['TAX_VALUE']) && isset($arFieldsModif['TAX_VALUE']) && $arFieldsOrig['TAX_VALUE'] != $arFieldsModif['TAX_VALUE'])
			|| (isset($arFieldsOrig['CURRENCY_ID']) && isset($arFieldsModif['CURRENCY_ID']) && $arFieldsOrig['CURRENCY_ID'] != $arFieldsModif['CURRENCY_ID']))
		{
			$arStatus = CCrmCurrencyHelper::PrepareListItems();
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'TAX_VALUE',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TAX_VALUE'),
				'EVENT_TEXT_1' => floatval($arFieldsOrig['TAX_VALUE']).(($val = CrmCompareFieldsList($arStatus, $arFieldsOrig['CURRENCY_ID'], '')) != '' ? ' ('.$val.')' : ''),
				'EVENT_TEXT_2' => floatval($arFieldsModif['TAX_VALUE']).(($val = CrmCompareFieldsList($arStatus, $arFieldsModif['CURRENCY_ID'], '')) != '' ? ' ('.$val.')' : '')
			);
		}
	}

	if (array_key_exists('BEGINDATE', $arFieldsOrig) && array_key_exists('BEGINDATE', $arFieldsModif) &&
		ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])) != $arFieldsModif['BEGINDATE'] && $arFieldsOrig['BEGINDATE'] != $arFieldsModif['BEGINDATE'])
	{
		$arMsg[] = Array(
			'ENTITY_FIELD' => 'BEGINDATE',
			'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_BEGINDATE'),
			'EVENT_TEXT_1' => !empty($arFieldsOrig['BEGINDATE'])? ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])): GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
			'EVENT_TEXT_2' => !empty($arFieldsModif['BEGINDATE'])? $arFieldsModif['BEGINDATE']: GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
		);
	}
	if (array_key_exists('CLOSEDATE', $arFieldsOrig) && array_key_exists('CLOSEDATE', $arFieldsModif) &&
		ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])) != $arFieldsModif['CLOSEDATE'] && $arFieldsOrig['CLOSEDATE'] != $arFieldsModif['CLOSEDATE'])
	{
		$arMsg[] = Array(
			'ENTITY_FIELD' => 'CLOSEDATE',
			'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CLOSEDATE'),
			'EVENT_TEXT_1' => !empty($arFieldsOrig['CLOSEDATE'])? ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])): GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
			'EVENT_TEXT_2' => !empty($arFieldsModif['CLOSEDATE'])? $arFieldsModif['CLOSEDATE']: GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
		);
	}

	if (array_key_exists('OPENED', $arFieldsModif))
	{
		if (isset($arFieldsOrig['OPENED']) && isset($arFieldsModif['OPENED'])
			&& $arFieldsOrig['OPENED'] != $arFieldsModif['OPENED'])
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'OPENED',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_OPENED'),
				'EVENT_TEXT_1' => $arFieldsOrig['OPENED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'),
				'EVENT_TEXT_2' => $arFieldsModif['OPENED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'),
			);
	}

	if (array_key_exists('CLOSED', $arFieldsModif))
	{
		if (isset($arFieldsOrig['CLOSED']) && isset($arFieldsModif['CLOSED'])
			&& $arFieldsOrig['CLOSED'] != $arFieldsModif['CLOSED'])
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'CLOSED',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CLOSED'),
				'EVENT_TEXT_1' => $arFieldsOrig['CLOSED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'),
				'EVENT_TEXT_2' => $arFieldsModif['CLOSED'] == 'Y'? GetMessage('MAIN_YES'): GetMessage('MAIN_NO'),
			);
	}

	// person type
	if (array_key_exists('PERSON_TYPE_ID', $arFieldsModif))
	{
		$bPersonTypeChanged = (isset($arFieldsOrig['PERSON_TYPE_ID']) && isset($arFieldsModif['PERSON_TYPE_ID'])
			&& intval($arFieldsOrig['PERSON_TYPE_ID']) !== intval($arFieldsModif['PERSON_TYPE_ID']));
		if ($bPersonTypeChanged)
		{
			$arPersonTypes = CCrmPaySystem::getPersonTypesList();

			if ($bPersonTypeChanged)
			{
				$arMsg[] = Array(
					'ENTITY_FIELD' => 'PERSON_TYPE_ID',
					'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_PERSON_TYPE_ID'),
					'EVENT_TEXT_1' => CrmCompareFieldsList($arPersonTypes, $arFieldsOrig['PERSON_TYPE_ID']),
					'EVENT_TEXT_2' => CrmCompareFieldsList($arPersonTypes, $arFieldsModif['PERSON_TYPE_ID'])
				);
			}
		}
	}

	if (array_key_exists('LOCATION_ID', $arFieldsModif))
	{
		$origLocationId = isset($arFieldsOrig['LOCATION_ID']) ? $arFieldsOrig['LOCATION_ID'] : '';
		$modifLocationId = isset($arFieldsModif['LOCATION_ID']) ? $arFieldsModif['LOCATION_ID'] : '';
		if ($origLocationId != $modifLocationId)
		{
			$origLocationString = $modifLocationString = '';
			if (IsModuleInstalled('sale') && CModule::IncludeModule('sale'))
			{
				$location = new CSaleLocation();
				$origLocationString = ($origLocationId > 0) ? $location->GetLocationString($origLocationId) : '';
				$modifLocationString = ($modifLocationId > 0) ? $location->GetLocationString($modifLocationId) : '';
			}
			if (empty($origLocationString) && intval($origLocationId) > 0)
				$origLocationString = '['.$origLocationId.']';
			if (empty($modifLocationString) && intval($modifLocationId) > 0)
				$modifLocationString = '['.$modifLocationId.']';
			$arMsg[] = Array(
				'ENTITY_FIELD' => 'LOCATION_ID',
				'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_LOCATION_ID'),
				'EVENT_TEXT_1' => $origLocationString,
				'EVENT_TEXT_2' => $modifLocationString,
			);
			unset($origLocationString, $modifLocationString);
		}
		unset($origLocationId, $modifLocationId);
	}

	$origClientFieldValue = $modifClientFieldValue = '';
	foreach (self::$clientFields as $fieldName)
	{
		if (array_key_exists($fieldName, $arFieldsModif))
		{
			$origClientFieldValue = isset($arFieldsOrig[$fieldName]) ? $arFieldsOrig[$fieldName] : '';
			$modifClientFieldValue = isset($arFieldsModif[$fieldName]) ? $arFieldsModif[$fieldName] : '';
			if ($origClientFieldValue != $modifClientFieldValue)
				$arMsg[] = Array(
					'ENTITY_FIELD' => $fieldName,
					'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_'.$fieldName.($fieldName === 'MYCOMPANY_ID' ? '1' : '')),
					'EVENT_TEXT_1' => !empty($origClientFieldValue)? $origClientFieldValue: GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
					'EVENT_TEXT_2' => !empty($modifClientFieldValue)? $modifClientFieldValue: GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'),
				);
		}
	}
	unset($fieldName, $origClientFieldValue, $modifClientFieldValue);

	// Processing of the files
	if (array_key_exists('STORAGE_TYPE_ID', $arFieldsModif)
		&& array_key_exists('STORAGE_ELEMENT_IDS', $arFieldsModif) && $arFieldsModif['STORAGE_ELEMENT_IDS'] <> '')
	{
		$newStorageTypeID = isset($arFieldsModif['STORAGE_TYPE_ID']) ? intval($arFieldsModif['STORAGE_TYPE_ID']) : CCrmQuoteStorageType::Undefined;
		$oldStorageTypeID = isset($arFieldsOrig['STORAGE_TYPE_ID']) ? intval($arFieldsOrig['STORAGE_TYPE_ID']) : CCrmQuoteStorageType::Undefined;

		self::PrepareStorageElementIDs($arFieldsModif);
		$newElementIDs = $arFieldsModif['STORAGE_ELEMENT_IDS'];

		self::PrepareStorageElementIDs($arFieldsOrig);
		$oldElementIDs = $arFieldsOrig['STORAGE_ELEMENT_IDS'];

		if($newStorageTypeID === $oldStorageTypeID && is_array($newElementIDs) && is_array($oldElementIDs))
		{
			$arRemovedElementIDs = array_values(array_diff($oldElementIDs, $newElementIDs));
			if(!empty($arRemovedElementIDs))
			{
				foreach($arRemovedElementIDs as $elementID)
				{
					self::PrepareFileEvent($oldStorageTypeID, $elementID, 'REMOVE', $arFieldsModif, $arMsg);
				}
				unset($elementID);
			}
			unset($arRemovedElementIDs);

			$arAddedElementIDs = array_values(array_diff($newElementIDs, $oldElementIDs));
			if(!empty($arAddedElementIDs))
			{
				foreach($arAddedElementIDs as $elementID)
				{
					self::PrepareFileEvent($newStorageTypeID, $elementID, 'ADD', $arFieldsModif, $arMsg);
				}
				unset($elementID);
			}
			unset($arAddedElementIDs);
		}
		else if ($newStorageTypeID !== $oldStorageTypeID && is_array($newElementIDs) && is_array($oldElementIDs))
		{
			foreach($oldElementIDs as $elementID)
			{
				self::PrepareFileEvent($oldStorageTypeID, $elementID, 'REMOVE', $arFieldsModif, $arMsg);
			}
			unset($elementID);

			foreach($newElementIDs as $elementID)
			{
				self::PrepareFileEvent($newStorageTypeID, $elementID, 'ADD', $arFieldsModif, $arMsg);
			}
			unset($elementID);
		}
		unset($newStorageTypeID, $oldStorageTypeID, $newElementIDs, $oldElementIDs);
	}

	return $arMsg;
}

Добавить комментарий