vat-gst-calculator 0.1.0 → 0.2.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef8d215f45467ecd5763e3b9fe214096f83e4f7d84ffa7009224bf3c77a85c39
|
4
|
+
data.tar.gz: 63a30ff1ee4e9fddf812684191f57c6315fe7bb2441bb7c8081fbf053720e9b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72020eb1ffe54a6851bbb2d385088925b936a68fc39e04bb5bec87227a2672a03e0a87b072c3cc7a01fea2b5e755d6a133efecbe47dc2be36b4fad7aaf9a42de
|
7
|
+
data.tar.gz: 2588c15b22de2b5d594b187236f2119e6c68cb13d2d0f6f47c8c70c656a01ea49f5e7716837c67ff0598470c316e52c85395dfb127f8358b3740c10c0538d45c
|
@@ -1,25 +1,32 @@
|
|
1
1
|
require "easyship/sales_tax/calculator/version"
|
2
2
|
require "easyship/sales_tax/calculator/formula"
|
3
3
|
require "easyship/sales_tax/calculator/fee"
|
4
|
-
|
5
4
|
module Easyship
|
6
5
|
module SalesTax
|
7
6
|
module Calculator
|
8
7
|
class Error < StandardError; end
|
8
|
+
|
9
9
|
def self.calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil)
|
10
10
|
return fallback_value if origin_country_alpha2.nil? || origin_country_alpha2.empty? || destination_country_alpha2.nil? || destination_country_alpha2.empty?
|
11
11
|
return fallback_value unless fees.is_a?(Fee)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
if domestic?(origin_country_alpha2, destination_country_alpha2) || within_eu?(origin_country_alpha2, destination_country_alpha2)
|
14
|
+
domestic_value(origin_country_alpha2: origin_country_alpha2, origin_state: origin_state, destination_state: destination_state, fees: fees)
|
15
|
+
else
|
16
|
+
fallback_value
|
17
|
+
end
|
18
|
+
rescue
|
19
|
+
fallback_value
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.domestic_value(origin_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil)
|
23
|
+
domestic_rates = Formula::DOMESTIC[origin_country_alpha2.to_s]
|
24
|
+
return fallback_value if domestic_rates.nil? || domestic_rates.empty?
|
16
25
|
|
17
26
|
{
|
18
|
-
sales_tax: tax_calculate(
|
19
|
-
provincial_sales_tax: tax_calculate(
|
27
|
+
sales_tax: tax_calculate(domestic_rates[:sales_tax], nil, destination_state, fees, false),
|
28
|
+
provincial_sales_tax: tax_calculate(domestic_rates[:provincial_sales_taxes], origin_state, destination_state, fees, true)
|
20
29
|
}
|
21
|
-
rescue
|
22
|
-
fallback_value
|
23
30
|
end
|
24
31
|
|
25
32
|
def self.fallback_value
|
@@ -40,9 +47,21 @@ module Easyship
|
|
40
47
|
end
|
41
48
|
|
42
49
|
def self.sales_tax_website_name(country_alpha2)
|
43
|
-
return
|
50
|
+
return if Formula::DOMESTIC[country_alpha2.to_s].nil? || Formula::DOMESTIC[country_alpha2.to_s].empty?
|
44
51
|
Formula::DOMESTIC[country_alpha2][:sales_tax_website_name]
|
45
52
|
end
|
53
|
+
|
54
|
+
def self.in_eu?(country_alpha2)
|
55
|
+
%w(NL LU EE LT HU BE PT GB SK HR CZ IT FI PL MT DE SI RO BG AT SE CY DK FR IE ES GR LV).include?(country_alpha2)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.domestic?(origin_country_alpha2 = nil, destination_country_alpha2 = nil)
|
59
|
+
!origin_country_alpha2.nil? && !origin_country_alpha2.empty? && origin_country_alpha2 == destination_country_alpha2
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.within_eu?(origin_country_alpha2 = nil, destination_country_alpha2 = nil)
|
63
|
+
in_eu?(origin_country_alpha2) && in_eu?(destination_country_alpha2)
|
64
|
+
end
|
46
65
|
end
|
47
66
|
end
|
48
67
|
end
|
data/vat-gst-calculator.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "easyship/sales_tax/calculator/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "vat-gst-calculator"
|
8
8
|
spec.version = Easyship::SalesTax::Calculator::VERSION
|
9
|
-
spec.authors = ["Aloha Chen"]
|
10
|
-
spec.email = ["y.alohac@gmail.com"]
|
9
|
+
spec.authors = ["Aloha Chen", "Paul LD"]
|
10
|
+
spec.email = ["y.alohac@gmail.com", "paul.lugagnedelpon@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Calculate Sales Tax}
|
13
13
|
spec.description = %q{Calculating VAT/GST/PST based on shipping rate, insurance fee, pickup_fee...etc}
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vat-gst-calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aloha Chen
|
8
|
+
- Paul LD
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -69,6 +70,7 @@ dependencies:
|
|
69
70
|
description: Calculating VAT/GST/PST based on shipping rate, insurance fee, pickup_fee...etc
|
70
71
|
email:
|
71
72
|
- y.alohac@gmail.com
|
73
|
+
- paul.lugagnedelpon@gmail.com
|
72
74
|
executables: []
|
73
75
|
extensions: []
|
74
76
|
extra_rdoc_files: []
|