vat-gst-calculator 0.6.0 → 0.7.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: f39992ff401d87c4d256cbbe7da9ef39e03e134b9e21ca5f4ba258d9ad613497
4
- data.tar.gz: 118ee1b247f9536cdaf16aad6246ba8d61d48ee817a02ba7510c1245ccf4d52d
3
+ metadata.gz: 4c0b1547695777a69f063993628affe4eaf28498180236ca0bd2e5902d5bd7d7
4
+ data.tar.gz: 5f7fd7051a155b3f5c0187ec2ebde52df83991a35491e0d8abf780d93ff94aed
5
5
  SHA512:
6
- metadata.gz: 8ba20e1380d4264138c446a675d5e1a6b5147e39713dcf7d441b706d09295214a0661f75e47411136f459dbf38843a38443d400d98cfc29e3d748e39ef426199
7
- data.tar.gz: 490338962e3e8146c6a851aaa4c027a491cc6bb9f276206a00d8687af5b80ab2e7891565d3308086cbd099e5cd71913441124e5590e851519622f211824f531b
6
+ metadata.gz: 444a34ccad4d894adca304083e25cc4baae48ae6a6abb7d1aabcd0c074a87d790120f0c6abd6ff2bfa242174c9939a00957c53a399151d68fe1acc0a551d7fbb
7
+ data.tar.gz: a7b0bcf732ca7a34da47c703e6b9f85fdae33461ad2602c73058f5770284b0e50204a3938b6674fd30a46317ab5481971a2d5d282665fccc70e713f1c9c8a28c
data/README.md CHANGED
@@ -26,7 +26,9 @@ Easyship::SalesTax::Calculator.calculate(
26
26
  destination_country_alpha2: destination_country_alpha2,
27
27
  origin_state: origin_state,
28
28
  destination_state: destination_state,
29
- fees: Easyship::SalesTax::Fee.new(10, 20, 30, 40) # (shipment_charge_total, insurance_fee, pickup_fee, residential_surcharge)
29
+ fees: Easyship::SalesTax::Fee.new(10, 20, 30, 40), # (shipment_charge_total, insurance_fee, pickup_fee, residential_surcharge)
30
+ effective_timestamp: "2023-01-01", # String and Time instances are supported. Default to current time (utc)
31
+ effective_country_alpha2s: ["HK", "US"] # when empty or not specified, all avalilable country data is used
30
32
  )
31
33
  ```
32
34
 
@@ -11,6 +11,7 @@ module Easyship
11
11
  pickup_fee: 0,
12
12
  residential_surcharge: 0
13
13
  }.freeze
14
+
14
15
  DEFAULT_EFFECTIVE_TIMESTAMP = Time.at(0).utc.freeze
15
16
 
16
17
  class << self
@@ -23,10 +24,11 @@ module Easyship
23
24
  }
24
25
  end
25
26
 
26
- def effective_data(country_alpha2, effective_timestamp = nil)
27
- data = DOMESTIC.fetch(country_alpha2, [])
28
-
29
- data.find { |rates| rates[:effective_timestamp] <= effective_time(effective_timestamp) }
27
+ def effective_data(country_alpha2, effective_timestamp = nil, effective_country_alpha2s = [])
28
+ DOMESTIC
29
+ .slice(*(effective_country_alpha2s.empty? ? DEFAULT_EFFECTIVE_COUNTRY_ALPHA2S : effective_country_alpha2s))
30
+ .fetch(country_alpha2, [])
31
+ .find { |rates| rates[:effective_timestamp] <= effective_time(effective_timestamp) }
30
32
  end
31
33
 
32
34
  private
@@ -172,11 +174,12 @@ module Easyship
172
174
  sales_tax: {'_ALL': build_fee_struct(0.05, 0, 0, 0)},
173
175
  provincial_sales_taxes: {'_ALL': NO_TAX}
174
176
  }],
175
- # 'IE' => {
176
- # sales_tax_website_name: 'VAT',
177
- # sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) },
178
- # provincial_sales_taxes: { '_ALL': no_taxes }
179
- # },
177
+ 'IE' => [{
178
+ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP,
179
+ sales_tax_website_name: 'VAT',
180
+ sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0.23, 0.23) },
181
+ provincial_sales_taxes: { '_ALL': NO_TAX }
182
+ }],
180
183
  # 'DK' => {
181
184
  # sales_tax_website_name: 'VAT',
182
185
  # sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) },
@@ -239,6 +242,8 @@ module Easyship
239
242
  # provincial_sales_taxes: { '_ALL': no_taxes }
240
243
  # }
241
244
  }.transform_values { |value| value.sort_by { |rates| -rates[:effective_timestamp].to_i } }.freeze
245
+
246
+ DEFAULT_EFFECTIVE_COUNTRY_ALPHA2S = DOMESTIC.keys.freeze
242
247
  end
243
248
  end
244
249
  end
@@ -1,7 +1,7 @@
1
1
  module Easyship
2
2
  module SalesTax
3
3
  module Calculator
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
6
6
  end
7
7
  end
@@ -8,12 +8,19 @@ module Easyship
8
8
 
9
9
  FALLBACK_VALUE = {sales_tax: 0, provincial_sales_tax: 0}.freeze
10
10
 
11
- def self.calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil)
11
+ def self.calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil, effective_country_alpha2s: [])
12
12
  return FALLBACK_VALUE if origin_country_alpha2.nil? || origin_country_alpha2.empty? || destination_country_alpha2.nil? || destination_country_alpha2.empty?
13
13
  return FALLBACK_VALUE unless fees.is_a?(Fee)
14
14
 
15
15
  if domestic?(origin_country_alpha2, destination_country_alpha2) || within_eu?(origin_country_alpha2, destination_country_alpha2)
16
- domestic_value(origin_country_alpha2: origin_country_alpha2, origin_state: origin_state, destination_state: destination_state, fees: fees, effective_timestamp: effective_timestamp)
16
+ domestic_value(
17
+ origin_country_alpha2: origin_country_alpha2,
18
+ origin_state: origin_state,
19
+ destination_state: destination_state,
20
+ fees: fees,
21
+ effective_timestamp: effective_timestamp,
22
+ effective_country_alpha2s: effective_country_alpha2s
23
+ )
17
24
  else
18
25
  FALLBACK_VALUE
19
26
  end
@@ -28,8 +35,8 @@ module Easyship
28
35
 
29
36
  private
30
37
 
31
- def self.domestic_value(origin_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil)
32
- rates = Formula.effective_data(origin_country_alpha2, effective_timestamp)
38
+ def self.domestic_value(origin_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil, effective_timestamp: nil, effective_country_alpha2s: [])
39
+ rates = Formula.effective_data(origin_country_alpha2, effective_timestamp, effective_country_alpha2s)
33
40
  return FALLBACK_VALUE if rates.nil?
34
41
 
35
42
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vat-gst-calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aloha Chen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-12-14 00:00:00.000000000 Z
12
+ date: 2023-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec