tax_jp 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 650a1d550ed212642954cfc87463138f4ff34275
4
- data.tar.gz: a4b87be4557e715d1070cd51d6392de237954f8a
3
+ metadata.gz: 583a0222e9b789e9c28edee7cbc0d58a1598d2e6
4
+ data.tar.gz: a7231e2900f894acec619d36880727656ff9d098
5
5
  SHA512:
6
- metadata.gz: dae8cc37ae36fc305c658db858bc8aae8d0bb27552d2156b4a0c4eeb378c3bbf8471cf1abb954749141acc65d5db91ae328bae62e17ed88df3d68fa4e5b9a3f0
7
- data.tar.gz: 48208ad895ed83d4533a3b84eacd08431fe066e6c4855e00e61e25eacf6430652a79831ab0f30eacb637512f8be8893f70e1f4378ce20ad2eeb710d479dc7788
6
+ metadata.gz: 9d7a6d92ef6d8a4630d992ca61747ea017bd43692ac93fd8d18ec025346881fad3afaf6802688c832662fe38fed9531d9cee3ddb64de292c7fa49fddbe3b2bec
7
+ data.tar.gz: e59861c04859ad920ad15b85dd9aabbf05d9b3a22e98d0b7996aaf790ef47d5d08f0bd99dcdb95f87ce585c5e771989dc6cf21e3641da2647018c36315beb819
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
+ sudo: false
1
2
  language: ruby
2
- cache: bundler
3
3
  rvm:
4
4
  - 2.1.0
5
5
  - 2.0.0
6
+ before_install:
7
+ gem install bundler --version '1.7.9'
6
8
  script:
7
9
  - bundle exec rake close
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # TaxJp
2
2
 
3
3
  税金計算ライブラリ
4
+ * 消費税
5
+ * 健康保険
4
6
 
5
7
  ## Installation
6
8
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'closer/tasks'
3
+ require 'tax_jp/tasks'
3
4
 
4
5
  task :test do
5
6
  Rake::Task['close'].invoke
@@ -7,23 +7,32 @@ tax.INCLUSIVE = 2; // 内税
7
7
  tax.EXCLUSIVE = 3; // 外税
8
8
 
9
9
  tax.RATE_3 = Date.parse('1989-04-01');
10
- tax.RATE_5 = Date.parse('1997-04-01');
11
- tax.RATE_8 = Date.parse('2014-04-01');
12
10
 
13
- tax.getRateOn = function(date) {
11
+ tax.consumptionTaxes = [
12
+ {date: Date.parse('2014-04-01'), rate: 0.08},
13
+ {date: Date.parse('1997-04-01'), rate: 0.05},
14
+ {date: Date.parse('1989-04-01'), rate: 0.03},
15
+ ];
16
+
17
+ tax.getRateOn = function(date, options) {
14
18
  if (typeof date === 'string') {
15
19
  date = Date.parse(date);
16
20
  }
17
-
18
- if (date >= tax.RATE_3 && date < tax.RATE_5) {
19
- return 0.03;
20
- } else if (date >= tax.RATE_5 && date < tax.RATE_8) {
21
- return 0.05;
22
- } else if (date >= tax.RATE_8) {
23
- return 0.08;
21
+ options = options || {};
22
+
23
+ var ret = 0;
24
+ for (var i = 0; this.consumptionTaxes.length; i ++) {
25
+ ret = this.consumptionTaxes[i].rate;
26
+ if (date >= this.consumptionTaxes[i].date) {
27
+ break;
28
+ }
29
+ }
30
+
31
+ if (options.percent) {
32
+ ret *= 100;
24
33
  }
25
34
 
26
- return 0;
35
+ return ret;
27
36
  };
28
37
 
29
38
  tax.calcTaxAmount = function(taxType, rate, amount) {
@@ -0,0 +1,4 @@
1
+ consumption_taxes:
2
+ 1989-04-01: 0.03
3
+ 1997-04-01: 0.05
4
+ 2014-04-01: 0.08
@@ -1,4 +1,4 @@
1
1
  もし /^(.*?)における、(.*?)円に対する消費税額は、(.*?)円です$/ do |date, amount, tax_amount|
2
- rate = TaxJp.get_rate_on(date)
2
+ rate = TaxJp.rate_on(date)
3
3
  assert_equal tax_amount.to_i, amount.to_i * rate
4
4
  end
@@ -6,6 +6,7 @@
6
6
  * <年月日>における、<金額>円に対する消費税額は、<消費税>円です
7
7
  例:
8
8
  | 年月日 | 金額 | 消費税 |
9
+ | 1997-03-31 | 1000 | 30 |
10
+ | 1997-04-01 | 1000 | 50 |
9
11
  | 2014-03-31 | 1000 | 50 |
10
12
  | 2014-04-01 | 1000 | 80 |
11
-
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+
3
+ namespace :taxjp do
4
+ task :build do
5
+ js_dir = 'app/assets/javascripts'
6
+ TaxJp::Utils.render 'app/assets/javascripts/tax.js.erb'
7
+ end
8
+ end
data/lib/tax_jp/const.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module TaxJp
2
+
2
3
  # 消費税区分
3
4
  TAX_TYPES = {
4
5
  TAX_TYPE_NONTAXABLE = 1 => '非課税',
@@ -6,7 +7,4 @@ module TaxJp
6
7
  TAX_TYPE_EXCLUSIVE = 3 => '外税',
7
8
  }
8
9
 
9
- RATE_3 = Date.parse('1989-04-01');
10
- RATE_5 = Date.parse('1997-04-01');
11
- RATE_8 = Date.parse('2014-04-01');
12
10
  end
@@ -1,19 +1,16 @@
1
1
  module TaxJp
2
2
  module ConsumptionTax
3
-
4
- def get_rate_on(date, options = {})
5
- if (date.is_a?(String))
3
+ @@consumption_taxes = TaxJp::Utils.load_yaml('consumption_taxes.yml')['consumption_taxes']
4
+
5
+ def rate_on(date, options = {})
6
+ if date.is_a?(String)
6
7
  date = Date.parse(date)
7
8
  end
8
-
9
- if (date >= RATE_3 && date < RATE_5)
10
- ret = 0.03;
11
- elsif (date >= RATE_5 && date < RATE_8)
12
- ret = 0.05;
13
- elsif (date >= RATE_8)
14
- ret = 0.08;
15
- else
16
- ret = 0
9
+
10
+ ret = 0
11
+ @@consumption_taxes.reverse_each do |start_date, rate|
12
+ ret = rate
13
+ break if date >= start_date
17
14
  end
18
15
 
19
16
  if options[:percent]
@@ -10,9 +10,7 @@ module TaxJp
10
10
  end
11
11
 
12
12
  @@prefectures = {}
13
- gem_dir = File.dirname(File.dirname(File.dirname(__FILE__)))
14
- prefectures = YAML.load_file(File.join(gem_dir, 'data', 'prefectures.yml'))['prefectures']
15
- prefectures.each do |key, value|
13
+ TaxJp::Utils.load_yaml('prefectures.yml')['prefectures'].each do |key, value|
16
14
  code = "%02d" % key.to_i
17
15
  @@prefectures[code] = Prefecture.new(code, value)
18
16
  end
@@ -1,6 +1,11 @@
1
1
  module TaxJp
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
+
5
+ rake_tasks do
6
+ require 'tax_jp/tasks'
7
+ end
8
+
4
9
  end
5
10
  end
6
11
  end
@@ -0,0 +1,5 @@
1
+ require 'tax_jp'
2
+
3
+ Dir[File.join(TaxJp::Utils.gem_dir, 'lib', 'tasks', '*.rake')].each do |f|
4
+ load f
5
+ end
@@ -0,0 +1,24 @@
1
+ require 'erb'
2
+
3
+ module TaxJp
4
+ class Utils
5
+ class << self
6
+
7
+ def gem_dir
8
+ File.expand_path('../../..', __FILE__)
9
+ end
10
+
11
+ def load_yaml(filename)
12
+ YAML.load_file(File.join(gem_dir, 'data', filename))
13
+ end
14
+
15
+ def render(template)
16
+ src = File.join(gem_dir, 'templates', template)
17
+ dest = File.join(gem_dir, template[0..-5])
18
+ FileUtils.mkdir_p(File.dirname(dest))
19
+ File.write(dest, ERB.new(File.read(src), 0, '-').result)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module TaxJp
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/tax_jp.rb CHANGED
@@ -6,6 +6,7 @@ if defined?(Rails)
6
6
  require 'tax_jp/rails/railtie'
7
7
  end
8
8
 
9
+ require 'tax_jp/utils'
9
10
  require 'tax_jp/prefecture'
10
11
 
11
12
  module TaxJp
@@ -0,0 +1,51 @@
1
+ if (typeof tax === "undefined") {
2
+ var tax = {};
3
+ }
4
+
5
+ tax.NONTAXABLE = <%= TaxJp::TAX_TYPE_NONTAXABLE %>; // 非課税
6
+ tax.INCLUSIVE = <%= TaxJp::TAX_TYPE_INCLUSIVE %>; // 内税
7
+ tax.EXCLUSIVE = <%= TaxJp::TAX_TYPE_EXCLUSIVE %>; // 外税
8
+
9
+ tax.RATE_3 = Date.parse('1989-04-01');
10
+
11
+ tax.consumptionTaxes = [
12
+ <%- TaxJp::Utils.load_yaml('consumption_taxes.yml')['consumption_taxes'].reverse_each do |start_date, rate| -%>
13
+ {date: Date.parse('<%= start_date.strftime('%Y-%m-%d') %>'), rate: <%= rate %>},
14
+ <%- end -%>
15
+ ];
16
+
17
+ tax.getRateOn = function(date, options) {
18
+ if (typeof date === 'string') {
19
+ date = Date.parse(date);
20
+ }
21
+ options = options || {};
22
+
23
+ var ret = 0;
24
+ for (var i = 0; this.consumptionTaxes.length; i ++) {
25
+ ret = this.consumptionTaxes[i].rate;
26
+ if (date >= this.consumptionTaxes[i].date) {
27
+ break;
28
+ }
29
+ }
30
+
31
+ if (options.percent) {
32
+ ret *= 100;
33
+ }
34
+
35
+ return ret;
36
+ };
37
+
38
+ tax.calcTaxAmount = function(taxType, rate, amount) {
39
+ if ( isNaN( amount ) ) {
40
+ return '';
41
+ }
42
+
43
+ if ( taxType == tax.INCLUSIVE ) {
44
+ return parseInt(amount * rate / (1 + rate));
45
+ }
46
+ else if ( taxType == tax.EXCLUSIVE ) {
47
+ return parseInt(amount * rate);
48
+ }
49
+
50
+ return '';
51
+ };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tax_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ichylinux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-12 00:00:00.000000000 Z
12
+ date: 2014-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -69,6 +69,7 @@ files:
69
69
  - Rakefile
70
70
  - app/assets/javascripts/tax.js
71
71
  - app/assets/javascripts/tax_jp.js
72
+ - data/consumption_taxes.yml
72
73
  - data/prefectures.yml
73
74
  - features/.gitignore
74
75
  - features/step_definitions/consumption_tax.rb
@@ -76,14 +77,18 @@ files:
76
77
  - features/support/env.rb
77
78
  - features/消費税.feature
78
79
  - features/都道府県.feature
80
+ - lib/tasks/build.rake
79
81
  - lib/tax_jp.rb
80
82
  - lib/tax_jp/const.rb
81
83
  - lib/tax_jp/consumption_tax.rb
82
84
  - lib/tax_jp/prefecture.rb
83
85
  - lib/tax_jp/rails/engine.rb
84
86
  - lib/tax_jp/rails/railtie.rb
87
+ - lib/tax_jp/tasks.rb
88
+ - lib/tax_jp/utils.rb
85
89
  - lib/tax_jp/version.rb
86
90
  - tax_jp.gemspec
91
+ - templates/app/assets/javascripts/tax.js.erb
87
92
  homepage: https://github.com/hybitz/tax_jp
88
93
  licenses:
89
94
  - MIT