killbill-avatax 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/application.js +24 -0
- data/app/assets/javascripts/avatax/avatax.js +7 -0
- data/app/assets/stylesheets/application.css +19 -0
- data/app/assets/stylesheets/avatax/avatax.css +6 -0
- data/app/assets/stylesheets/bootstrap_and_overrides.css +17 -0
- data/app/controllers/avatax/configuration_controller.rb +142 -0
- data/app/controllers/avatax/engine_controller.rb +18 -0
- data/app/helpers/avatax/application_helper.rb +4 -0
- data/app/views/avatax/configuration/_exemptions_form.html.erb +20 -0
- data/app/views/avatax/configuration/_exemptions_table.html.erb +34 -0
- data/app/views/avatax/configuration/_plugin_form.html.erb +43 -0
- data/app/views/avatax/configuration/_products_form.html.erb +20 -0
- data/app/views/avatax/configuration/_products_table.html.erb +34 -0
- data/app/views/avatax/configuration/index.html.erb +30 -0
- data/app/views/avatax/configuration/plugin_configuration.html.erb +7 -0
- data/app/views/avatax/configuration/set_exemption.html.erb +10 -0
- data/app/views/avatax/configuration/set_tax_code.html.erb +10 -0
- data/app/views/avatax/layouts/avatax_application.html.erb +31 -0
- data/config/routes.rb +20 -0
- data/lib/avatax.rb +22 -0
- data/lib/avatax/client.rb +63 -0
- data/lib/avatax/engine.rb +19 -0
- data/lib/avatax/version.rb +3 -0
- data/lib/tasks/avatax_tasks.rake +4 -0
- data/test/avatax_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +32 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +23 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/killbill_client.rb +3 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/test_helper.rb +21 -0
- metadata +411 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= form_tag do_set_tax_code_configuration_path, :class => 'form-horizontal' do %>
|
2
|
+
<div class="form-group">
|
3
|
+
<%= label_tag :product_name, 'Product name', :class => 'col-sm-2 control-label' %>
|
4
|
+
|
5
|
+
<div class="col-sm-10">
|
6
|
+
<%= select_tag :product_name, options_for_select(@products), :class => 'form-control' %>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
<div class="form-group">
|
10
|
+
<%= label_tag :tax_code, 'Tax code', :class => 'col-sm-2 control-label' %>
|
11
|
+
<div class="col-sm-10">
|
12
|
+
<%= text_field_tag :tax_code, nil, :class => 'form-control' %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<div class="form-group">
|
16
|
+
<div class="col-sm-offset-2 col-sm-10">
|
17
|
+
<%= submit_tag 'Save', :class => 'btn btn-default' %>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
<% end %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<table id="products-table" class="table table-condensed table-striped mobile-data">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th>Product name</th>
|
5
|
+
<th>Tax code</th>
|
6
|
+
<th></th>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% tax_codes.each do |tax_code| %>
|
11
|
+
<tr>
|
12
|
+
<td><%= tax_code[:productName] %></td>
|
13
|
+
<td><%= tax_code[:taxCode] %></td>
|
14
|
+
<td>
|
15
|
+
<%= link_to '<i class="fa fa-times"></i>'.html_safe, remove_tax_code_configuration_path(:product_name => tax_code[:productName]), :method => :delete %>
|
16
|
+
</td>
|
17
|
+
</tr>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<%= javascript_tag do %>
|
23
|
+
$(document).ready(function() {
|
24
|
+
$('#products-table').dataTable({
|
25
|
+
"dom": "t",
|
26
|
+
"paging": false,
|
27
|
+
"columns": [
|
28
|
+
null,
|
29
|
+
null,
|
30
|
+
{ "orderable": false }
|
31
|
+
]
|
32
|
+
});
|
33
|
+
});
|
34
|
+
<% end %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<div class="search">
|
2
|
+
|
3
|
+
<div class="column-block">
|
4
|
+
|
5
|
+
<h1>Configured products
|
6
|
+
<%= link_to ' <i class="fa fa-plus-square"></i>'.html_safe, set_tax_code_configuration_path %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<%= render :partial => 'avatax/configuration/products_table', :locals => {:tax_codes => @tax_codes} %>
|
10
|
+
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<hr/>
|
14
|
+
|
15
|
+
<div class="column-block">
|
16
|
+
|
17
|
+
<h1>Exempt accounts
|
18
|
+
<%= link_to ' <i class="fa fa-plus-square"></i>'.html_safe, set_exemption_configuration_path %>
|
19
|
+
</h1>
|
20
|
+
|
21
|
+
<%= render :partial => 'avatax/configuration/exemptions_table', :locals => {:exemptions => @exemptions} %>
|
22
|
+
|
23
|
+
</div>
|
24
|
+
|
25
|
+
|
26
|
+
<hr/>
|
27
|
+
|
28
|
+
<h1><%= link_to 'Plugin configuration', plugin_configuration_path %></h1>
|
29
|
+
|
30
|
+
</div>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Avatax</title>
|
5
|
+
<%= yield :scripts %>
|
6
|
+
<%= stylesheet_link_tag 'application', :media => 'all' %>
|
7
|
+
<%= javascript_include_tag 'application' %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<div class="container-fluid">
|
11
|
+
<%- # :alert used by devise -%>
|
12
|
+
<% [:error, :alert].each do |key| %>
|
13
|
+
<% if flash[key] %>
|
14
|
+
<div class="row">
|
15
|
+
<div class="col-md-10 col-md-offset-2">
|
16
|
+
<div class="alert alert-error"><%= flash[key] %></div>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
<% if flash[:notice] %>
|
22
|
+
<div class="row">
|
23
|
+
<div class="col-md-10 col-md-offset-2">
|
24
|
+
<div class="alert alert-info"><%= flash[:notice] %></div>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
<%= yield %>
|
29
|
+
</div>
|
30
|
+
</body>
|
31
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Avatax::Engine.routes.draw do
|
2
|
+
|
3
|
+
root to: 'configuration#index'
|
4
|
+
|
5
|
+
resources :configuration, :only => [:index]
|
6
|
+
|
7
|
+
scope '/configuration' do
|
8
|
+
match '/tax_code' => 'configuration#set_tax_code', :via => :get, :as => 'set_tax_code_configuration'
|
9
|
+
match '/tax_code' => 'configuration#do_set_tax_code', :via => :post, :as => 'do_set_tax_code_configuration'
|
10
|
+
match '/tax_code' => 'configuration#remove_tax_code', :via => :delete, :as => 'remove_tax_code_configuration'
|
11
|
+
|
12
|
+
match '/exemption' => 'configuration#set_exemption', :via => :get, :as => 'set_exemption_configuration'
|
13
|
+
match '/exemption' => 'configuration#do_set_exemption', :via => :post, :as => 'do_set_exemption_configuration'
|
14
|
+
match '/exemption' => 'configuration#remove_exemption', :via => :delete, :as => 'remove_exemption_configuration'
|
15
|
+
|
16
|
+
match '/plugin' => 'configuration#plugin_configuration', :via => :get, :as => 'plugin_configuration'
|
17
|
+
match '/plugin' => 'configuration#update_plugin_configuration', :via => :post, :as => 'update_plugin_configuration'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/avatax.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'avatax/engine'
|
2
|
+
|
3
|
+
module Avatax
|
4
|
+
|
5
|
+
mattr_accessor :current_tenant_user
|
6
|
+
mattr_accessor :layout
|
7
|
+
|
8
|
+
self.current_tenant_user = lambda { |session, user|
|
9
|
+
{:username => 'admin',
|
10
|
+
:password => 'password',
|
11
|
+
:session_id => nil,
|
12
|
+
:api_key => KillBillClient.api_key,
|
13
|
+
:api_secret => KillBillClient.api_secret}
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.config(&block)
|
17
|
+
{
|
18
|
+
:layout => layout || 'avatax/layouts/avatax_application',
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Killbill
|
2
|
+
module Avatax
|
3
|
+
|
4
|
+
class AvataxClient < KillBillClient::Model::Resource
|
5
|
+
|
6
|
+
KILLBILL_AVATAX_PREFIX = '/plugins/killbill-avatax'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def set_exemption(account_id, customer_usage_type, user, reason, comment, options = {})
|
11
|
+
exemptionCustomFieldName = 'customerUsageType'
|
12
|
+
|
13
|
+
account = KillBillClient::Model::Account.find_by_id(account_id, false, false, options)
|
14
|
+
|
15
|
+
# Remove existing exemption(s) first
|
16
|
+
account.custom_fields('NONE', options).each do |custom_field|
|
17
|
+
account.remove_custom_field(custom_field.custom_field_id, user, reason, comment, options) if custom_field.name == exemptionCustomFieldName
|
18
|
+
end
|
19
|
+
|
20
|
+
unless customer_usage_type.nil?
|
21
|
+
# Set the exemption
|
22
|
+
custom_field = KillBillClient::Model::CustomField.new
|
23
|
+
custom_field.name = exemptionCustomFieldName
|
24
|
+
custom_field.value = customer_usage_type
|
25
|
+
account.add_custom_field(custom_field, user, reason, comment, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_exemption(account_id, user, reason, comment, options = {})
|
30
|
+
set_exemption(account_id, nil, user, reason, comment, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_tax_codes(options = {})
|
34
|
+
path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes"
|
35
|
+
response = KillBillClient::API.get path, {}, options
|
36
|
+
JSON.parse(response.body).map(&:symbolize_keys)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_tax_code(product_name, options = {})
|
40
|
+
path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}"
|
41
|
+
response = KillBillClient::API.get path, {}, options
|
42
|
+
JSON.parse(response.body).symbolize_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_tax_code(product_name, tax_code, user, reason, comment, options = {})
|
46
|
+
body = {:productName => product_name, :taxCode => tax_code}.to_json
|
47
|
+
|
48
|
+
path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes"
|
49
|
+
response = KillBillClient::API.post path, body, {}, options
|
50
|
+
response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_tax_code(product_name, user, reason, comment, options= {})
|
54
|
+
path = "#{KILLBILL_AVATAX_PREFIX}/taxCodes/#{product_name}"
|
55
|
+
KillBillClient::API.delete path, nil, {}, options
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Dependencies
|
2
|
+
#
|
3
|
+
# Sigh. Rails autoloads the gems specified in the Gemfile and nothing else.
|
4
|
+
# We need to explicitly require all of our dependencies listed in avatax.gemspec
|
5
|
+
#
|
6
|
+
# See also https://github.com/carlhuda/bundler/issues/49
|
7
|
+
require 'jquery-rails'
|
8
|
+
require 'jquery-datatables-rails'
|
9
|
+
require 'bootstrap-datepicker-rails'
|
10
|
+
require 'd3_rails'
|
11
|
+
require 'momentjs-rails'
|
12
|
+
require 'spinjs-rails'
|
13
|
+
require 'killbill_client'
|
14
|
+
|
15
|
+
module Avatax
|
16
|
+
class Engine < ::Rails::Engine
|
17
|
+
isolate_namespace Avatax
|
18
|
+
end
|
19
|
+
end
|
data/test/avatax_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "avatax"
|
7
|
+
|
8
|
+
require "jquery-rails"
|
9
|
+
require "twitter-bootstrap-rails"
|
10
|
+
require "d3_rails"
|
11
|
+
|
12
|
+
require "js-routes"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
21
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
22
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
23
|
+
|
24
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
25
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
26
|
+
# config.i18n.default_locale = :de
|
27
|
+
|
28
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
29
|
+
config.active_record.raise_in_transactional_callbacks = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|