require 'pdv/version' require 'active_support' require 'active_support/number_helper' require 'i18n' require 'set' # Izbegni upozorenje I18n.enforce_available_locales = true module PDV TAX = 0.2 PRECISION = 2 RJUST = 20 # Za dati neto iznos prikazuje formatiran neto, pdv i bruto def za(neto) neto_amount = _round neto tax_amount = _round(neto_amount * TAX) bruto_amount = _round(neto_amount + tax_amount) puts puts " NETO: #{_format neto_amount}" puts " PDV: #{_format tax_amount}" puts " -------#{'-'*RJUST}" puts " BRUTO: #{_format bruto_amount}" puts end def _format(amount) format_options = {separator: ',', delimiter: '.', precision: PRECISION} ActiveSupport::NumberHelper.number_to_rounded(amount, format_options).rjust(RJUST) end def _round(amount) amount.round(PRECISION) end extend self end