TransportBase::getLastDeal

  1. Bitrix24 API (v. 23.675.0)
  2. sender
  3. TransportBase
  4. getLastDeal
  • Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/integration/crm/returncustomer/transportbase.php
  • Класс: Bitrix\Sender\Integration\Crm\ReturnCustomer\TransportBase
  • Вызов: TransportBase::getLastDeal
protected function getLastDeal(EntityManageFacility $facility, $days)
{
	$categoryId = null;
	$dealFilters = [];
	if ($facility->getSelector()->getCompanyId())
	{
		$dealFilters[] = [
			'=COMPANY_ID' => $facility->getSelector()->getCompanyId()
		];
	}
	if ($facility->getSelector()->getContactId())
	{
		$dealFilters[] = [
			'=CONTACT_ID' => $facility->getSelector()->getContactId()
		];
	}
	foreach ($dealFilters as $dealFilter)
	{
		$dealFilter['=STAGE_SEMANTIC_ID'] = [
			PhaseSemantics::SUCCESS
		];
		$days = (int) $days;

		$dateCreate = (new \DateTime())->modify("-$days days");

		$beginningOfTheDay = DateTime::createFromPhp($dateCreate->setTime(0,0,0));
		$endOfTheDay = DateTime::createFromPhp($dateCreate->setTime(23,59,59));

		$dealFilter['DATE_CREATE'] = $beginningOfTheDay;

		$dealFilter['=HAS_PRODUCTS'] = 1;

		$dealRow = DealTable::getRow([
			'select' => ['ID', 'CURRENCY_ID', 'RECEIVED_AMOUNT'],
			'filter' => $dealFilter,
			'limit' => 1,
			'order' => ['DATE_CREATE' => 'DESC']
		]);

		if (!$dealRow)
		{
			break;
		}

		return $dealRow;
	}

	return null;
}

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