Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/cvetdv.ru/bitrix/js/catalog/product-calculator/src/js/ |
Upload File : |
import type {FieldScheme} from './field-scheme'; import type {DiscountTypes} from './discount-type'; import {TaxForPriceStrategy} from './strategy/tax-for-price-strategy'; export class ProductCalculator { #fields: FieldScheme = {}; #strategy: TaxForPriceStrategy = {}; #settings = {}; static DEFAULT_PRECISION: number = 2; constructor(fields: FieldScheme = {}, settings = {}) { this.setFields(fields); this.setSettings(settings); this.setCalculationStrategy(new TaxForPriceStrategy(this)); } setField(name, value): ProductCalculator { this.#fields[name] = value; return this; } setCalculationStrategy(strategy: TaxForPriceStrategy = {}): ProductCalculator { this.#strategy = strategy; return this; } setFields(fields: FieldScheme): ProductCalculator { for (const name in fields) { if (fields.hasOwnProperty(name)) { this.setField(name, fields[name]); } } return this; } getFields(): FieldScheme { return {...this.#fields}; } setSettings(settings = {}): ProductCalculator { this.#settings = {...settings}; return this; } getSettings(): {} { return {...this.#settings}; } #getSetting(name, defaultValue) { return this.#settings.hasOwnProperty(name) ? this.#settings[name] : defaultValue; } getPricePrecision() { return this.#getSetting('pricePrecision', ProductCalculator.DEFAULT_PRECISION); } getCommonPrecision() { return this.#getSetting('commonPrecision', ProductCalculator.DEFAULT_PRECISION); } getQuantityPrecision() { return this.#getSetting('quantityPrecision', ProductCalculator.DEFAULT_PRECISION); } calculateBasePrice(value: number): FieldScheme { return this.#strategy.calculateBasePrice(value); } calculatePrice(value: number): FieldScheme { return this.#strategy.calculatePrice(value); } calculateQuantity(value: number): FieldScheme { return this.#strategy.calculateQuantity(value); } calculateDiscount(value: number): FieldScheme { return this.#strategy.calculateDiscount(value); } calculateDiscountType(value: DiscountTypes): FieldScheme { return this.#strategy.calculateDiscountType(value); } calculateRowDiscount(value: number): FieldScheme { return this.#strategy.calculateRowDiscount(value); } calculateTax(value: number | null): FieldScheme { return this.#strategy.calculateTax(value); } calculateTaxIncluded(value: 'Y' | 'N'): FieldScheme { return this.#strategy.calculateTaxIncluded(value); } calculateRowSum(value: number): FieldScheme { return this.#strategy.calculateRowSum(value); } }