CCrmUserCounter::IsReckoned

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmUserCounter
  4. IsReckoned
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/user_counter.php
  • Класс: \CCrmUserCounter
  • Вызов: CCrmUserCounter::IsReckoned
static function IsReckoned($typeID, &$data)
{
	$userID = isset($data['CURRENT_USER_ID']) ? intval($data['CURRENT_USER_ID']) : 0;

	$typeID = intval($typeID);
	if($typeID === self::CurrentDealActivies)
	{
		$activity = isset($data['ACTIVITY']) ? $data['ACTIVITY'] : null;
		$entity = isset($data['ENTITY']) ? $data['ENTITY'] : null;

		if(!is_array($entity))
		{
			return false;
		}

		$assignedByID = isset($entity['ASSIGNED_BY_ID']) ? $entity['ASSIGNED_BY_ID'] : 0;

		$stageID = isset($entity['STAGE_ID']) ? $entity['STAGE_ID'] : '';
		$categoryID = isset($entity['CATEGORY_ID']) ? (int)$entity['CATEGORY_ID'] : 0;
		$stageSemanticID = isset($entity['STAGE_SEMANTIC_ID']) ? $entity['STAGE_SEMANTIC_ID'] : '';
		if($stageSemanticID === PhaseSemantics::UNDEFINED)
		{
			$stageSemanticID = CCrmDeal::GetSemanticID($stageID, $categoryID);
		}
		$isCompleted = PhaseSemantics::isFinal($stageSemanticID);
		if(!is_array($activity))
		{
			return !$isCompleted && $userID === $assignedByID
				&& CCrmUserCounterSettings::GetValue(CCrmUserCounterSettings::ReckonActivitylessItems, true);
		}

		$activityResponsibleID = isset($activity['RESPONSIBLE_ID']) ? intval($activity['RESPONSIBLE_ID']) : 0;
		if($userID !== $activityResponsibleID)
		{
			return false;
		}

		$isActivityCompleted = isset($activity['IS_COMPLETED']) ? $activity['IS_COMPLETED'] : false;
		$isActivityForCurrentDay = isset($activity['IS_CURRENT_DAY']) ? $activity['IS_CURRENT_DAY'] : false;
		return !$isActivityCompleted &&  $isActivityForCurrentDay;
	}
	elseif($typeID === self::CurrentQuoteActivies)
	{
		$entity = isset($data['ENTITY']) ? $data['ENTITY'] : null;

		if(!is_array($entity) || empty($entity['CLOSEDATE']))
		{
			return false;
		}

		$assignedByID = isset($entity['ASSIGNED_BY_ID']) ? $entity['ASSIGNED_BY_ID'] : 0;
		$statusID = isset($entity['STATUS_ID']) ? $entity['STATUS_ID'] : '';
		$statuses = self::GetStatusList('QUOTE_STATUS');

		$statusSort = 0;
		if($statusID !== '' && isset($statuses[$statusID]))
		{
			$statusSort = intval($statuses[$statusID]['SORT']);
		}
		$finalSort = isset($statuses['APPROVED']) ? intval($statuses['APPROVED']['SORT']) : 0;
		$isCompleted = $statusSort > 0 && $finalSort > 0 && $statusSort >= $finalSort;

		$tsCloseDate = MakeTimeStamp($entity['CLOSEDATE']);
		$tsNow = time() + CTimeZone::GetOffset();
		$tsMax = mktime(23, 59, 59, date('m',$tsNow), date('d',$tsNow), date('Y',$tsNow));

		return (!$isCompleted && $userID === $assignedByID && $tsCloseDate <= $tsMax
			&& CCrmUserCounterSettings::GetValue(CCrmUserCounterSettings::ReckonActivitylessItems, true));
	}
	elseif($typeID === self::CurrentLeadActivies)
	{
		$activity = isset($data['ACTIVITY']) ? $data['ACTIVITY'] : null;
		$entity = isset($data['ENTITY']) ? $data['ENTITY'] : null;

		if(!is_array($entity))
		{
			return false;
		}

		$assignedByID = isset($entity['ASSIGNED_BY_ID']) ? $entity['ASSIGNED_BY_ID'] : 0;
		$statusID = isset($entity['STATUS_ID']) ? $entity['STATUS_ID'] : '';
		$statuses = self::GetStatusList('STATUS');

		$statusSort = 0;
		if($statusID !== '' && isset($statuses[$statusID]))
		{
			$statusSort = intval($statuses[$statusID]['SORT']);
		}
		$finalSort = isset($statuses['CONVERTED']) ? intval($statuses['CONVERTED']['SORT']) : 0;
		$isCompleted = $statusSort > 0 && $finalSort > 0 && $statusSort >= $finalSort;
		if(!is_array($activity))
		{
			return !$isCompleted && $userID === $assignedByID
				&& CCrmUserCounterSettings::GetValue(CCrmUserCounterSettings::ReckonActivitylessItems, true);
		}

		$activityResponsibleID = isset($activity['RESPONSIBLE_ID']) ? intval($activity['RESPONSIBLE_ID']) : 0;
		if($userID !== $activityResponsibleID)
		{
			return false;
		}

		$isActivityCompleted = isset($activity['IS_COMPLETED']) ? $activity['IS_COMPLETED'] : false;
		$isActivityForCurrentDay = isset($activity['IS_CURRENT_DAY']) ? $activity['IS_CURRENT_DAY'] : false;
		return !$isActivityCompleted &&  $isActivityForCurrentDay;
	}
	elseif($typeID === self::CurrentContactActivies || $typeID === self::CurrentCompanyActivies)
	{
		$activity = isset($data['ACTIVITY']) ? $data['ACTIVITY'] : null;
		$entity = isset($data['ENTITY']) ? $data['ENTITY'] : null;

		if(!is_array($entity) || !is_array($activity))
		{
			return false;
		}

		$activityResponsibleID = isset($activity['RESPONSIBLE_ID']) ? intval($activity['RESPONSIBLE_ID']) : 0;
		if($userID !== $activityResponsibleID)
		{
			return false;
		}

		$isActivityCompleted = isset($activity['IS_COMPLETED']) ? $activity['IS_COMPLETED'] : false;
		$isActivityForCurrentDay = isset($activity['IS_CURRENT_DAY']) ? $activity['IS_CURRENT_DAY'] : false;
		return !$isActivityCompleted &&  $isActivityForCurrentDay;
	}
	return false;
}

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