• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/lib/rest.php
  • Класс: BitrixTimemanRest
  • Вызов: Rest::timeControlReportsGet
static function timeControlReportsGet($query, $n, CRestServer $server)
{
	$query = static::prepareQuery($query);

	$userId = $query['USER_ID'];
	$month = $query['MONTH'];
	$year = $query['YEAR'];
	$idleMinutes = $query['IDLE_MINUTES'];
	$workdayHours = $query['WORKDAY_HOURS'];

	$currentUserId = $GLOBALS['USER']->GetId();

	if (BitrixTimemanAbsence::isHead())
	{
		$reportViewType = 'head';
	}
	else if (BitrixTimemanAbsence::isReportListFullEnableForUser($currentUserId))
	{
		$reportViewType = 'full';
	}
	else if (BitrixTimemanAbsence::isReportListSimpleEnableForUser($currentUserId))
	{
		$reportViewType = 'simple';
	}
	else
	{
		throw new BitrixRestRestException("You don't have access to this method", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
	}

	if (!BitrixTimemanAbsence::hasAccessToReport($userId))
	{
		throw new BitrixRestRestException("You don't have access to report for this user", "USER_ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
	}

	if ($reportViewType != 'head')
	{
		$idleMinutes = null;
	}

	$result = BitrixTimemanAbsence::getMonthReport($userId, $year, $month, $workdayHours, $idleMinutes);

	$fullTypesWhiteList = [
		BitrixTimemanAbsence::SOURCE_ONLINE_EVENT,
		BitrixTimemanAbsence::SOURCE_OFFLINE_AGENT,
		BitrixTimemanAbsence::SOURCE_IDLE_EVENT,
		BitrixTimemanAbsence::SOURCE_TM_EVENT,
	];

	if ($reportViewType != 'head')
	{
		foreach ($result['REPORT']['DAYS'] as $id => $entry)
		{
			if ($reportViewType == 'simple')
			{
				$result['REPORT']['DAYS'][$id]['REPORTS'] = [];
			}
			else
			{
				foreach ($entry['REPORTS'] as $reportId => $reportValue)
				{
					if (!in_array($reportValue['SOURCE_START'], $fullTypesWhiteList))
					{
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]);
					}
					else
					{
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]['IP_START']);
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]['IP_START_NETWORK']);
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]['IP_FINISH']);
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]['IP_FINISH_NETWORK']);
						unset($result['REPORT']['DAYS'][$id]['REPORTS'][$reportId]['SYSTEM_TEXT']);
					}
				}
			}
		}
	}

	return self::formatJsonAnswer($result);
}