• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/cashbox/checkmanager.php
  • Класс: BitrixSaleCashboxCheckManager
  • Вызов: CheckManager::collatePaySystemWithFFD105
static function collatePaySystemWithFFD105($entity): array
{
	$map = [];
	$entities = [];
	$relatedEntities = [];
	$type = SellCheck::getType();

	$option = MainConfigOption::get('sale', 'check_type_on_pay', 'sell');

	if ($entity instanceof SalePayment)
	{
		$fields = $entity->getFields();
		$originalFields = $fields->getOriginalValues();
		if ($originalFields['PAID'] === 'Y' || $fields->get('IS_RETURN') === 'Y')
		{
			return $map;
		}

		$order = $entity->getOrder();

		$entities[] = $entity;

		$isShipped = false;
		/** @var SaleShipment $shipment */
		foreach ($order->getShipmentCollection()->getNotSystemItems() as $shipment)
		{
			$isShipped = $shipment->isShipped();
			if (!$isShipped)
			{
				$relatedEntities = [];
				break;
			}

			$relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
		}

		if (!$isShipped)
		{
			$order = $entity->getOrder();
			if ($option === 'prepayment')
			{
				$type = (SalePriceMaths::roundPrecision($entity->getSum()) === SalePriceMaths::roundPrecision($order->getPrice()))
					? FullPrepaymentCheck::getType()
					: PrepaymentCheck::getType();

				$shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
				/** @var SaleShipment $shipment */
				foreach ($shipmentCollection as $shipment)
				{
					$relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
				}
			}
			elseif ($option === 'advance')
			{
				$type = AdvancePaymentCheck::getType();
			}
			else
			{
				$shipmentCollection = $order->getShipmentCollection()->getNotSystemItems();
				/** @var SaleShipment $shipment */
				foreach ($shipmentCollection as $shipment)
				{
					$relatedEntities[Check::SHIPMENT_TYPE_NONE][] = $shipment;
				}
			}
		}
	}
	elseif ($entity instanceof SaleShipment)
	{
		$fields = $entity->getFields();
		$originalFields = $fields->getOriginalValues();
		if ($originalFields['DEDUCTED'] === 'Y' || $fields->get('DEDUCTED') !== 'Y')
		{
			return $map;
		}

		$order = $entity->getOrder();
		if ($order->isPaid() && $entity->isShipped())
		{
			if ($option === 'sell')
			{
				return $map;
			}

			$entities[] = $entity;

			/** @var SalePayment $payment */
			foreach ($order->getPaymentCollection() as $payment)
			{
				if ($payment->isInner())
				{
					continue;
				}

				$relatedEntities[Check::PAYMENT_TYPE_CASHLESS][] = $payment;
			}
		}
	}

	if ($entities)
	{
		$map[] = [
			'TYPE' => $type,
			'ENTITIES' => $entities,
			'RELATED_ENTITIES' => $relatedEntities,
		];
	}

	return $map;
}