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 +4 -4
- data/.travis.yml +3 -1
- data/README.md +2 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/tax.js +20 -11
- data/data/consumption_taxes.yml +4 -0
- data/features/step_definitions/consumption_tax.rb +1 -1
- data/features//346/266/210/350/262/273/347/250/216.feature +2 -1
- data/lib/tasks/build.rake +8 -0
- data/lib/tax_jp/const.rb +1 -3
- data/lib/tax_jp/consumption_tax.rb +9 -12
- data/lib/tax_jp/prefecture.rb +1 -3
- data/lib/tax_jp/rails/railtie.rb +5 -0
- data/lib/tax_jp/tasks.rb +5 -0
- data/lib/tax_jp/utils.rb +24 -0
- data/lib/tax_jp/version.rb +1 -1
- data/lib/tax_jp.rb +1 -0
- data/templates/app/assets/javascripts/tax.js.erb +51 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 583a0222e9b789e9c28edee7cbc0d58a1598d2e6
|
4
|
+
data.tar.gz: a7231e2900f894acec619d36880727656ff9d098
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d7a6d92ef6d8a4630d992ca61747ea017bd43692ac93fd8d18ec025346881fad3afaf6802688c832662fe38fed9531d9cee3ddb64de292c7fa49fddbe3b2bec
|
7
|
+
data.tar.gz: e59861c04859ad920ad15b85dd9aabbf05d9b3a22e98d0b7996aaf790ef47d5d08f0bd99dcdb95f87ce585c5e771989dc6cf21e3641da2647018c36315beb819
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -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.
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
35
|
+
return ret;
|
27
36
|
};
|
28
37
|
|
29
38
|
tax.calcTaxAmount = function(taxType, rate, amount) {
|
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
|
-
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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]
|
data/lib/tax_jp/prefecture.rb
CHANGED
@@ -10,9 +10,7 @@ module TaxJp
|
|
10
10
|
end
|
11
11
|
|
12
12
|
@@prefectures = {}
|
13
|
-
|
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
|
data/lib/tax_jp/rails/railtie.rb
CHANGED
data/lib/tax_jp/tasks.rb
ADDED
data/lib/tax_jp/utils.rb
ADDED
@@ -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
|
data/lib/tax_jp/version.rb
CHANGED
data/lib/tax_jp.rb
CHANGED
@@ -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
|
+
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
|
+
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
|