Delivery::addActivity

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Delivery
  4. addActivity
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/activity/provider/delivery.php
  • Класс: Bitrix\Crm\Activity\Provider\Delivery
  • Вызов: Delivery::addActivity
static function addActivity(Shipment $shipment): ?int
{
	$authorId =
		$shipment->getField('RESPONSIBLE_ID')
			? (int)$shipment->getField('RESPONSIBLE_ID')
			: (int)$shipment->getField('EMP_RESPONSIBLE_ID')
	;
	$typeId = self::PROVIDER_TYPE_DEFAULT;
	$deadlineTime = (new DateTime())->add('+1 day')->setTime(19, 0, 0);

	$fields = [
		'TYPE_ID' => \CCrmActivityType::Provider,
		'PROVIDER_ID' => 'CRM_DELIVERY',
		'PROVIDER_TYPE_ID' => $typeId,
		'START_TIME' => $deadlineTime,
		'END_TIME' => $deadlineTime,
		'DEADLINE' => $deadlineTime,
		'SUBJECT' => self::getActivitySubject($shipment, $typeId),
		'IS_HANDLEABLE' => 'Y',
		'COMPLETED' => 'N',
		'STATUS' => \CCrmActivityStatus::Waiting,
		'RESPONSIBLE_ID' => $authorId,
		'PRIORITY' => \CCrmActivityPriority::Medium,
		'AUTHOR_ID' => $authorId,
		'BINDINGS' => ActivityBindingsMaker::makeByShipment($shipment),
		'SETTINGS' => [
			'FIELDS' => [
				'SHIPMENT_ID' => $shipment->getId(),
			],
		],
	];

	$activityId = (int)\CCrmActivity::add($fields, false);
	if ($activityId)
	{
		$deliveryService = $shipment->getDelivery();
		if ($deliveryService)
		{
                $deliveryServiceName = $deliveryService->getName();
                if ($deliveryService->getParentService())
                {
                    $deliveryServiceName = implode(
                        ', ',
                        [
                            (string)$deliveryService->getParentService()->getName(),
                            (string)$deliveryService->getName(),
                        ],
                    );
                }

			DeliveryController::getInstance()->createShipmentMessage(
				[
					'TITLE' => Loc::getMessage('CRM_ACTIVITY_PROVIDER_DELIVERY_DELIVERY_CREATED'),
					'DESCRIPTION' => $deliveryServiceName . ' ' . '#PRICE#',
					'CURRENCY' => $shipment->getCurrency(),
					'MONEY_VALUES' => [
						'#PRICE#' => $shipment->getPrice(),
					],
				],
				$shipment
			);
		}

		AddEventToStatFile(
			'sale',
			'deliveryActivityCreation',
			$activityId,
			$deliveryService->getServiceCode(),
			'delivery_service_code'
		);
	}

	return $activityId ?? null;
}

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