Your IP : 216.73.216.86


Current Path : /var/www/homesaver/www/bitrix/js/catalog/product-calculator/src/js/strategy/
Upload File :
Current File : /var/www/homesaver/www/bitrix/js/catalog/product-calculator/src/js/strategy/tax-for-sum-strategy.js

import {TaxForPriceStrategy} from "./tax-for-price-strategy";
import {FieldStorage} from "../field-storage";
import {DiscountType} from "../discount-type";

export class TaxForSumStrategy extends TaxForPriceStrategy
{
	calculatePriceWithoutTax(price, taxRate)
	{
		return price;
	}

	updateResultPrices(fieldStorage: FieldStorage): void
	{
		let exclusivePrice;

		if (fieldStorage.isDiscountPercentage())
		{
			exclusivePrice = this.calculatePriceWithoutDiscount(
				fieldStorage.getPriceNetto(),
				fieldStorage.getDiscountRate(),
				DiscountType.PERCENTAGE
			);
		}
		else if (fieldStorage.isDiscountMonetary())
		{
			exclusivePrice = this.calculatePriceWithoutDiscount(
				fieldStorage.getPriceNetto(),
				fieldStorage.getDiscountSum(),
				DiscountType.MONETARY
			);
		}
		else
		{
			exclusivePrice = fieldStorage.getPriceExclusive();
		}

		fieldStorage.setField('PRICE_EXCLUSIVE', exclusivePrice);
		
		if (fieldStorage.isTaxIncluded())
		{
			fieldStorage.setField('PRICE', exclusivePrice);
		}
		else
		{
			fieldStorage.setField(
				'PRICE',
				this.calculatePriceWithTax(exclusivePrice, fieldStorage.getTaxRate())
			);
		}
	}
}