Sha256: 0c138cd1532eb6a9f68af9fe873452cc6826ddd06b427e36d69d36269480bd65

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 KB

Contents

if (typeof tax === "undefined") {
  var tax = {};
}

tax.NONTAXABLE = <%= TaxJp::TAX_TYPE_NONTAXABLE %>; // 非課税
tax.INCLUSIVE = <%= TaxJp::TAX_TYPE_INCLUSIVE %>; // 内税
tax.EXCLUSIVE = <%= TaxJp::TAX_TYPE_EXCLUSIVE %>; // 外税

tax.consumptionTaxes = [
  <%- TaxJp::Utils.load_yaml('消費税.yml').reverse_each do |start_date, rate| -%>
    {date: Date.parse('<%= start_date.strftime('%Y-%m-%d') %>'), rate: <%= rate %>},
  <%- end -%>
];

tax.getRateOn = function(date, options) {
  if (typeof date === 'string') {
    date = Date.parse(date);
  }
  options = options || {};

  var ret = 0;
  for (var i = 0; this.consumptionTaxes.length; i ++) {
    ret = this.consumptionTaxes[i].rate;
    if (date >= this.consumptionTaxes[i].date) {
      break;
    }
  }

  if (options.percent) {
    ret *= 100;
  }
  
  return ret;
};

tax.calcTaxAmount = function(taxType, rate, amount) {
  if ( isNaN( amount ) ) {
    return '';
  }

  if ( taxType == tax.INCLUSIVE ) {
    return parseInt(amount * rate / (1 + rate));
  }
  else if ( taxType == tax.EXCLUSIVE ) {
    return parseInt(amount * rate); 
  }

  return '';
};

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tax_jp-0.3.3 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.3.2 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.3.1 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.3.0 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.9 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.8 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.7 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.6 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.5 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.4 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.3 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.2 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.1 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.2.0 templates/app/assets/javascripts/tax.js.erb
tax_jp-0.1.0 templates/app/assets/javascripts/tax.js.erb