• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Field/TaxValue.php
  • Класс: Bitrix\Crm\Field\TaxValue
  • Вызов: TaxValue::processAfterSave
public function processAfterSave(Item $itemBeforeSave, Item $item, Context $context = null): FieldAfterSaveResult
{
	$result = new FieldAfterSaveResult();

	$products = $itemBeforeSave->getProductRows();
	$productsAreNotFetched = is_null($products) && !$itemBeforeSave->isNew();
	if ($productsAreNotFetched)
	{
		if ($itemBeforeSave->isChanged($this->getName()))
		{
			$result->addError(new Error(
				"Products are not fetched. Can't sync tax value",
				static::ERROR_CODE_PRODUCTS_NOT_FETCHED
			));
		}

		return $result;
	}

	$taxValue = Container::getInstance()->getAccounting()->calculateByItem($item)->getTaxValue();

	$result->setNewValue($this->getName(), $taxValue);
	if ($item->hasField(Item::FIELD_NAME_TAX_VALUE_ACCOUNT))
	{
		$taxValueAccount = Currency\Conversion::toAccountCurrency($taxValue, $item->getCurrencyId());
		$result->setNewValue(Item::FIELD_NAME_TAX_VALUE_ACCOUNT, $taxValueAccount);
	}

	return $result;
}