• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/recurring/entity/item/invoiceexist.php
  • Класс: Bitrix\Crm\Recurring\Entity\Item\InvoiceExist
  • Вызов: InvoiceExist::expose
public function expose($recalculate = false)
{
	$result = new Main\Result();
	if ($this->isChanged())
	{
		$result->addError(new Main\Error('Error exposing. Recurring invoice was changed. Need to save changes before exposing.'));
		return $result;
	}

	if (empty($this->templateFields))
	{
		$r = $this->fillTemplateFields();
		if (!$r->isSuccess())
		{
			return $r;
		}
	}

	$fields = $this->prepareInvoiceFieldsBeforeExpose($this->templateFields);
	$addResult = $this->addExposingInvoice($fields, ['RESET_HISTORY_CREATOR_ID' => $recalculate]);
	if ($addResult->isSuccess())
	{
		$result->setData([
			'NEW_INVOICE_ID' => $addResult->getId()
		]);

		$this->onAfterInvoiceExpose( $addResult->getId(), $fields);

		$this->setFieldNoDemand('LAST_EXECUTION', new Date());
		$this->setFieldNoDemand('COUNTER_REPEAT', (int)$this->recurringFields['COUNTER_REPEAT'] + 1);

		if ($recalculate)
		{
			$today = new Date();
			$nextExecution = $this->calculateNextExecutionDate();
			if ($nextExecution && $today->getTimestamp() === $nextExecution->getTimestamp())
			{
				$nextExecution = $this->calculateNextExecutionDate($today->add('1 day'));
			}
			$this->setFieldNoDemand("NEXT_EXECUTION", $nextExecution);
			if (!$this->isActive())
			{
				$this->deactivate();
			}
			else
			{
				$this->setFieldNoDemand("ACTIVE", 'Y');
			}
		}

		$this->save();
	}
	else
	{
		$result->addErrors($addResult->getErrors());
	}

	return $result;
}