ProductsDataProvider::calculateTotalFields

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. ProductsDataProvider
  4. calculateTotalFields
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/documentgenerator/dataprovider/productsdataprovider.php
  • Класс: Bitrix\Crm\Integration\DocumentGenerator\DataProvider\ProductsDataProvider
  • Вызов: ProductsDataProvider::calculateTotalFields
protected function calculateTotalFields()
{
	$currencyID = $this->getCurrencyId();
	if(empty($this->products))
	{
		$sum = $this->data['OPPORTUNITY'] ?? 0;
		$this->data['TOTAL_RAW'] = $this->data['TOTAL_SUM'] = $sum;
		return;
	}
	$crmProducts = [];
	foreach($this->getTotalFields() as $placeholder => $field)
	{
		if(isset($field['FORMAT']) && (!isset($field['FORMAT']['WORDS']) || $field['FORMAT']['WORDS'] !== true))
		{
			$this->data[$placeholder] = 0;
		}
	}
	foreach($this->products as $product)
	{
		$this->data['TOTAL_DISCOUNT'] += $product->getRawValue('QUANTITY') * $product->getRawValue('DISCOUNT_SUM');
		$this->data['TOTAL_QUANTITY'] += $product->getRawValue('QUANTITY');
		$this->data['TOTAL_RAW'] += $product->getRawValue('PRICE_RAW_SUM');
		$this->data['TOTAL_RAW_BEFORE_DISCOUNT'] += $product->getRawValue('QUANTITY') * $product->getRawValue('PRICE_RAW_NETTO');
		$crmProducts[] = DataProviderManager::getInstance()->getArray($product, ['rawValue' => true]);
	}
	$calcOptions = [];
	if(\CCrmTax::isTaxMode())
	{
		$calcOptions = [
			'LOCATION_ID' => $this->getLocationId(),
			'ALLOW_LD_TAX' => 'Y',
		];
	}
	$calculate = \CCrmSaleHelper::Calculate($crmProducts, $currencyID, $this->getPersonTypeID(), false, 's1', $calcOptions);

	if (
		isset($calculate['TAX_LIST'])
		&& is_array($calculate['TAX_LIST'])
		&& \CCrmTax::isTaxMode()
	)
	{
		foreach($calculate['TAX_LIST'] as $taxInfo)
		{
			$tax = new Tax([
				'NAME' => $taxInfo['NAME'],
				'VALUE' => new Money($taxInfo['VALUE_MONEY'], ['CURRENCY_ID' => $currencyID, 'WITH_ZEROS' => true]),
				'NETTO' => 0,
				'BRUTTO' => 0,
				'RATE' => (float)$taxInfo['VALUE'],
				'TAX_INCLUDED' => $taxInfo['IS_IN_PRICE'],
				'MODE' => Tax::MODE_TAX,
			]);
			$tax->setParentProvider($this);
			$this->taxes[] = $tax;
		}
	}
	$this->data['TOTAL_SUM'] = $calculate['PRICE'];
	$this->data['TOTAL_TAX'] = $calculate['TAX_VALUE'];
	$this->data['TOTAL_BEFORE_TAX'] = $this->data['TOTAL_SUM'] - $this->data['TOTAL_TAX'];
	$this->data['TOTAL_BEFORE_DISCOUNT'] = $this->data['TOTAL_BEFORE_TAX'] + $this->data['TOTAL_DISCOUNT'];
}

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