Sha256: 58d45f965b1c040b4f3b7bd909461e7f508756f8fa8b942425da56cbecf1b4ed

Contents?: true

Size: 994 Bytes

Versions: 2

Compression:

Stored size: 994 Bytes

Contents

module SpreeAvataxOfficial
  module TaxAdjustmentLabelHelper
    include ActionView::Helpers::NumberHelper

    STRIP_INSIGNIFICANT_ZEROS  = true
    PRECISION_OF_PERCENT_VALUE = 10

    def tax_adjustment_label(item, rate)
      item_class = item.class.name.demodulize.underscore

      format_adjustment_label(
        ::Spree.t("spree_avatax_official.create_tax_adjustments.#{item_class}_tax_adjustment_default_label", included_label: included_label(item)),
        rate
      )
    end

    def included_label(item)
      item.included_in_price ? 'Included ' : ''
    end

    def format_adjustment_label(adjustment_default_label, rate)
      rate_in_percents = number_to_percentage(
        rate * 100.0,
        precision:                 PRECISION_OF_PERCENT_VALUE,
        strip_insignificant_zeros: STRIP_INSIGNIFICANT_ZEROS
      )
      SpreeAvataxOfficial::Config.show_rate_in_label ? "#{adjustment_default_label} (#{rate_in_percents})" : adjustment_default_label
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_avatax_official-1.8.0 app/helpers/spree_avatax_official/tax_adjustment_label_helper.rb
spree_avatax_official-1.7.1 app/helpers/spree_avatax_official/tax_adjustment_label_helper.rb