Module: Easyship::SalesTax::Formula
- Defined in:
- lib/easyship/sales_tax/calculator/formula.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- NO_TAX =
{ shipment_charge_total: 0, insurance_fee: 0, pickup_fee: 0, residential_surcharge: 0 }.freeze
- DEFAULT_EFFECTIVE_TIMESTAMP =
Time.at(0).utc.freeze
- DOMESTIC =
{ 'AU' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'GST', sales_tax: {'_ALL': build_fee_struct(0.1, 0, 0.1, 0)}, provincial_sales_taxes: {'_ALL': NO_TAX} }], 'GB' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'VAT', sales_tax: {'_ALL': build_fee_struct(0.2, 0, 0.2, 0.2)}, # TBC provincial_sales_taxes: {'_ALL': NO_TAX} }], 'CA' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'Taxes', sales_tax: { 'AB' => build_fee_struct(0.05, 0, 0.05, 0.05), # Alberta 'BC' => build_fee_struct(0.05, 0, 0.05, 0.05), # British Columbia 'MB' => build_fee_struct(0.05, 0, 0.05, 0.05), # Manitoba 'NB' => build_fee_struct(0.15, 0, 0.15, 0.15), # New Brunswick 'NL' => build_fee_struct(0.15, 0, 0.15, 0.15), # Newfoundland and Labrador 'NT' => build_fee_struct(0.05, 0, 0.05, 0.05), # Northwest Territories 'NS' => build_fee_struct(0.15, 0, 0.15, 0.15), # Nova Scotia 'NU' => build_fee_struct(0.05, 0, 0.05, 0.05), # Nunavut 'ON' => build_fee_struct(0.13, 0, 0.13, 0.13), # Ontario 'PE' => build_fee_struct(0.15, 0, 0.15, 0.15), # Prince Edward Island 'QC' => build_fee_struct(0.05, 0, 0.05, 0.05), # Quebec 'SK' => build_fee_struct(0.05, 0, 0.05, 0.05), # Saskatchewan 'YT' => build_fee_struct(0.05, 0, 0.05, 0.05), # Yukon }, provincial_sales_taxes: { 'AB' => NO_TAX, # Alberta 'BC' => NO_TAX, # British Columbia 'MB' => NO_TAX, # Manitoba 'NB' => NO_TAX, # New Brunswick 'NL' => NO_TAX, # Newfoundland and Labrador 'NT' => NO_TAX, # Northwest Territories 'NS' => NO_TAX, # Nova Scotia 'NU' => NO_TAX, # Nunavut 'ON' => NO_TAX, # Ontario 'PE' => NO_TAX, # Prince Edward Island 'QC' => build_fee_struct(0.09975, 0, 0.09975, 0.09975), # Quebec 'SK' => NO_TAX, # Saskatchewan 'YT' => NO_TAX, # Yukon } }], 'SG' => [ { effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'GST', sales_tax: {'_ALL': build_fee_struct(0.07, 0.07, 0.07, 0.07)}, provincial_sales_taxes: {'_ALL': NO_TAX} }, { effective_timestamp: Time.utc(2023, 1, 1, 8), sales_tax_website_name: 'GST', sales_tax: {'_ALL': build_fee_struct(0.08, 0.08, 0.08, 0.08)}, provincial_sales_taxes: {'_ALL': NO_TAX} } ], 'HK' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: nil, sales_tax: {'_ALL': NO_TAX}, provincial_sales_taxes: {'_ALL': NO_TAX} }], # 'NL' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.21, 0, 0.21, 0.21) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, 'US' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: nil, sales_tax: {'_ALL': NO_TAX}, provincial_sales_taxes: {'_ALL': NO_TAX} }], # 'DE' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.19, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'FR' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'IT' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.22, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'BE' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.21, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'ES' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.21, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'PT' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'PL' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'RO' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.19, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'AT' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, 'AE' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'VAT', sales_tax: {'_ALL': build_fee_struct(0.05, 0, 0, 0)}, provincial_sales_taxes: {'_ALL': NO_TAX} }], 'IE' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'VAT', sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0.23, 0.23) }, provincial_sales_taxes: { '_ALL': NO_TAX } }], # 'DK' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'SE' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'FI' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.24, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'CN' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.06, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'NO' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'CH' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.077, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'MY' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'JP' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, 'NZ' => [{ effective_timestamp: DEFAULT_EFFECTIVE_TIMESTAMP, sales_tax_website_name: 'VAT', sales_tax: {'_ALL': build_fee_struct(0.15, 0.15, 0.15, 0.15)}, provincial_sales_taxes: {'_ALL': NO_TAX} }], # 'IN' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.15, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'KR' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # }, # 'MX' => { # sales_tax_website_name: 'VAT', # sales_tax: { '_ALL': build_fee_struct(0.16, 0, 0, 0) }, # provincial_sales_taxes: { '_ALL': no_taxes } # } }.transform_values { |value| value.sort_by { |rates| -rates[:effective_timestamp].to_i } }.freeze
- DEFAULT_EFFECTIVE_COUNTRY_ALPHA2S =
DOMESTIC.keys.freeze
Class Method Summary collapse
- .build_fee_struct(shipment_charge_total, insurance_fee, pickup_fee, residential_surcharge) ⇒ Object
- .effective_data(country_alpha2, effective_timestamp = nil, effective_country_alpha2s = []) ⇒ Object
Class Method Details
.build_fee_struct(shipment_charge_total, insurance_fee, pickup_fee, residential_surcharge) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/easyship/sales_tax/calculator/formula.rb', line 18 def build_fee_struct(shipment_charge_total, insurance_fee, pickup_fee, residential_surcharge) { shipment_charge_total: shipment_charge_total, insurance_fee: insurance_fee, pickup_fee: pickup_fee, residential_surcharge: residential_surcharge } end |
.effective_data(country_alpha2, effective_timestamp = nil, effective_country_alpha2s = []) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/easyship/sales_tax/calculator/formula.rb', line 27 def effective_data(country_alpha2, = nil, effective_country_alpha2s = []) DOMESTIC .slice(*(effective_country_alpha2s.empty? ? DEFAULT_EFFECTIVE_COUNTRY_ALPHA2S : effective_country_alpha2s)) .fetch(country_alpha2, []) .find { |rates| rates[:effective_timestamp] <= effective_time() } end |