billing 0.0.4 → 0.0.5a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/billing/{account.rb → bill.rb} +40 -34
  3. data/app/models/billing/charge.rb +25 -11
  4. data/app/models/billing/modifier.rb +5 -5
  5. data/app/models/billing/origin.rb +7 -2
  6. data/app/models/billing/payment.rb +8 -11
  7. data/app/models/billing/payment_with_type.rb +3 -9
  8. data/app/models/billing/report.rb +29 -13
  9. data/app/models/billing/room_transfer.rb +4 -0
  10. data/app/models/concerns/billing/{account_item.rb → bill_item.rb} +5 -6
  11. data/app/models/concerns/billing/bill_text_parser.rb +18 -0
  12. data/config/initializers/money.rb +67 -0
  13. data/config/routes.rb +1 -6
  14. data/db/migrate/20140803073707_rename_billing_account_to_bill.rb +8 -0
  15. data/db/migrate/20140804065726_add_qty_to_billing_charge.rb +5 -0
  16. data/db/migrate/20140804070517_add_tax_ratio_to_billing_charge.rb +5 -0
  17. data/db/migrate/20141001185321_add_transfer_device_to_billing_origin.rb +5 -0
  18. data/db/migrate/20141027235427_add_f_amount_to_billing_report.rb +7 -0
  19. data/lib/billing.rb +0 -2
  20. data/lib/billing/billable.rb +3 -3
  21. data/lib/billing/engine.rb +3 -0
  22. data/lib/billing/version.rb +1 -1
  23. data/lib/collection_proxy_wild.rb +9 -0
  24. data/test/dummy/config/routes.rb +1 -3
  25. data/test/dummy/db/development.sqlite3 +0 -0
  26. data/test/dummy/db/schema.rb +23 -17
  27. data/test/dummy/db/test.sqlite3 +0 -0
  28. data/test/dummy/log/development.log +8144 -0
  29. data/test/dummy/log/test.log +64325 -0
  30. data/test/fixtures/billing/{accounts.yml → bills.yml} +0 -0
  31. data/test/fixtures/billing/charges.yml +2 -2
  32. data/test/fixtures/billing/modifiers.yml +2 -2
  33. data/test/fixtures/billing/payments.yml +2 -2
  34. data/test/models/billing/bill_test.rb +76 -0
  35. data/test/models/billing/charge_test.rb +13 -6
  36. data/test/models/billing/modifier_test.rb +2 -2
  37. data/test/models/billing/payment_test.rb +12 -12
  38. metadata +20 -58
  39. data/app/assets/javascripts/billing/accounts.js +0 -2
  40. data/app/assets/javascripts/billing/application.js +0 -13
  41. data/app/assets/javascripts/billing/charges.js +0 -2
  42. data/app/assets/javascripts/billing/modifiers.js +0 -2
  43. data/app/assets/stylesheets/billing/accounts.css +0 -4
  44. data/app/assets/stylesheets/billing/application.css +0 -15
  45. data/app/assets/stylesheets/billing/charges.css +0 -4
  46. data/app/assets/stylesheets/billing/modifiers.css +0 -4
  47. data/app/assets/stylesheets/billing/payments.css +0 -4
  48. data/app/controllers/billing/accounts_controller.rb +0 -29
  49. data/app/controllers/billing/application_controller.rb +0 -22
  50. data/app/controllers/billing/charges_controller.rb +0 -29
  51. data/app/controllers/billing/modifiers_controller.rb +0 -29
  52. data/app/controllers/billing/payments_controller.rb +0 -29
  53. data/app/helpers/billing/accounts_helper.rb +0 -4
  54. data/app/helpers/billing/application_helper.rb +0 -4
  55. data/app/helpers/billing/charges_helper.rb +0 -4
  56. data/app/helpers/billing/modifiers_helper.rb +0 -4
  57. data/app/helpers/billing/payments_helper.rb +0 -4
  58. data/app/views/billing/accounts/index.html.erb +0 -7
  59. data/app/views/billing/accounts/new.html.erb +0 -8
  60. data/app/views/billing/accounts/show.html.erb +0 -29
  61. data/app/views/billing/application/index.html.erb +0 -3
  62. data/app/views/billing/charges/new.html.erb +0 -12
  63. data/app/views/billing/modifiers/new.html.erb +0 -18
  64. data/app/views/billing/payments/new.html.erb +0 -11
  65. data/app/views/layouts/billing/application.html.erb +0 -14
  66. data/lib/billing/mapping.rb +0 -32
  67. data/lib/billing/routes.rb +0 -16
  68. data/test/controllers/billing/accounts_controller_test.rb +0 -19
  69. data/test/controllers/billing/charges_controller_test.rb +0 -16
  70. data/test/controllers/billing/modifiers_controller_test.rb +0 -16
  71. data/test/controllers/billing/payments_controller_test.rb +0 -16
  72. data/test/helpers/billing/accounts_helper_test.rb +0 -6
  73. data/test/helpers/billing/charges_helper_test.rb +0 -6
  74. data/test/helpers/billing/modifiers_helper_test.rb +0 -6
  75. data/test/helpers/billing/payments_helper_test.rb +0 -6
  76. data/test/integration/navigation_test.rb +0 -10
  77. data/test/models/billing/account_test.rb +0 -56
@@ -1,4 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
@@ -1,29 +0,0 @@
1
- require_dependency "billing/application_controller"
2
-
3
- module Billing
4
- class AccountsController < ApplicationController
5
- before_action :set_account, except: [:index, :new, :create]
6
-
7
- def index
8
- @accounts = billable.billing_accounts
9
- end
10
-
11
- def new
12
- @account = billable.billing_accounts.new
13
- end
14
-
15
- def create
16
- @account = billable.billing_accounts.new
17
- if @account.save
18
- redirect_to @account
19
- else
20
- render action: :new
21
- end
22
- end
23
-
24
- private
25
- def set_account
26
- @account = billable.billing_accounts.find(params[:id])
27
- end
28
- end
29
- end
@@ -1,22 +0,0 @@
1
- module Billing
2
- class ApplicationController < ActionController::Base
3
- prepend_before_filter :include_extra_module
4
- helper_method :billable
5
-
6
- def index
7
- end
8
-
9
- def billable
10
- @billable ||= billing_mapping.i_klass.find_by(billing_mapping.i_find_key => params[billing_mapping.i_param])
11
- end
12
-
13
- private
14
- def billing_mapping
15
- @billing_mapping ||= Billing::Mapping.find(request.fullpath)
16
- end
17
-
18
- def include_extra_module
19
- self.class.send(:include, billing_mapping.i_extra_module) if billing_mapping.i_extra_module.present?
20
- end
21
- end
22
- end
@@ -1,29 +0,0 @@
1
- require_dependency "billing/application_controller"
2
-
3
- module Billing
4
- class ChargesController < ApplicationController
5
- before_action :set_account
6
-
7
- def new
8
- @charge = @account.charges.new
9
- end
10
-
11
- def create
12
- @charge = @account.charges.new(charge_params)
13
- if @charge.save
14
- redirect_to @account
15
- else
16
- render action: :new
17
- end
18
- end
19
-
20
- private
21
- def set_account
22
- @account = billable.billing_accounts.find(params[:account_id])
23
- end
24
-
25
- def charge_params
26
- params.require(:charge).permit(:price)
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- require_dependency "billing/application_controller"
2
-
3
- module Billing
4
- class ModifiersController < ApplicationController
5
- before_action :set_account
6
-
7
- def new
8
- @modifier = @account.modifiers.new
9
- end
10
-
11
- def create
12
- @modifier = @account.modifiers.new(modifier_params)
13
- if @modifier.save
14
- redirect_to @account
15
- else
16
- render action: :new
17
- end
18
- end
19
-
20
- private
21
- def set_account
22
- @account = billable.billing_accounts.find(params[:account_id])
23
- end
24
-
25
- def modifier_params
26
- params.require(:modifier).permit(:percent_ratio, :fixed_value, :charge_id)
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- require_dependency "billing/application_controller"
2
-
3
- module Billing
4
- class PaymentsController < ApplicationController
5
- before_action :set_account
6
-
7
- def new
8
- @payment = @account.payments.new(value: @account.total)
9
- end
10
-
11
- def create
12
- @payment = @account.payments.new(payment_params)
13
- if @payment.save
14
- redirect_to @account
15
- else
16
- render action: :new
17
- end
18
- end
19
-
20
- private
21
- def set_account
22
- @account = billable.billing_accounts.find(params[:account_id])
23
- end
24
-
25
- def payment_params
26
- params.require(:payment).permit(:value)
27
- end
28
- end
29
- end
@@ -1,4 +0,0 @@
1
- module Billing
2
- module AccountsHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Billing
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Billing
2
- module ChargesHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Billing
2
- module ModifiersHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Billing
2
- module PaymentsHelper
3
- end
4
- end
@@ -1,7 +0,0 @@
1
- <h1>Accounts#index</h1>
2
- <p>Find me in app/views/billing/accounts/index.html.erb</p>
3
- <%= link_to :new, new_account_path %>
4
- <hr />
5
- <% @accounts.each do |account| %>
6
- <%= link_to account.inspect, account %>
7
- <% end %>
@@ -1,8 +0,0 @@
1
- <h1>
2
- New account
3
- <small><%= billable %></small>
4
- </h1>
5
- <%= form_for @account do |f| %>
6
- <%= @account.inspect %>
7
- <%= f.submit %>
8
- <% end %>
@@ -1,29 +0,0 @@
1
- <%= @account.inspect %>
2
- <h2>
3
- total: <%= @account.total %>
4
- <br />
5
- balance: <%= @account.balance %>
6
- </h2>
7
- <hr />
8
- Charges:<br />
9
- <% @account.charges.each do |charge| %>
10
- <%= charge.inspect %>
11
- <% end %>
12
- <%= link_to :charge, [:new, @account, :charge] %>
13
- <hr />
14
- Modifiers:<br />
15
- <% @account.modifiers.each do |modifier| %>
16
- <%= modifier.inspect %>
17
- <% end %>
18
- <%= link_to :modifier, [:new, @account, :modifier] %>
19
- <div>
20
- <% @account.modifier_items.each do |mi| %>
21
- <%= mi.inspect %><br />
22
- <% end %>
23
- </div>
24
- <hr />
25
- Payments:<br />
26
- <% @account.payments.each do |payment| %>
27
- <%= payment.inspect %>
28
- <% end %>
29
- <%= link_to :pay, [:new, @account, :payment] %>
@@ -1,3 +0,0 @@
1
- <%= link_to :accounts, accounts_path %>
2
- <br />
3
- <%= link_to :new_account, new_account_path %>
@@ -1,12 +0,0 @@
1
- <h1>
2
- New charge
3
- <small><%= @account %></small>
4
- </h1>
5
- <%= form_for [@account, @charge] do |f| %>
6
- <%= @charge.inspect %>
7
- <br />
8
- <%= f.number_field :price, step: 0.01 %>
9
- <br />
10
- <%= f.submit %>
11
- <% end %>
12
-
@@ -1,18 +0,0 @@
1
- <h1>
2
- New Modifier
3
- <small><%= @account %></small>
4
- </h1>
5
- <div>
6
- <%= @modifier.errors.full_messages.join(', ') %>
7
- </div>
8
- <%= form_for [@account, @modifier] do |f| %>
9
- <%= @modifier.inspect %>
10
- <br />
11
- percent ratio <%= f.number_field :percent_ratio, step: 0.001 %>
12
- <br />
13
- fixed value <%= f.number_field :fixed_value, step: 0.01 %>
14
- <br />
15
- <%= f.select :charge_id, @account.charges.collect(&:id), { include_blank: true } %>
16
- <br />
17
- <%= f.submit %>
18
- <% end %>
@@ -1,11 +0,0 @@
1
- <h1>
2
- New payment
3
- <small><%= @account %></small>
4
- </h1>
5
- <%= form_for [@account, @payment] do |f| %>
6
- <%= @payment.inspect %>
7
- <br />
8
- <%= f.number_field :value, step: 0.01 %>
9
- <br />
10
- <%= f.submit %>
11
- <% end %>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Billing</title>
5
- <%= stylesheet_link_tag "billing/application", media: "all" %>
6
- <%= javascript_include_tag "billing/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,32 +0,0 @@
1
- module Billing
2
- class Mapping
3
- attr_reader :name, :i_klass, :i_param, :i_find_key, :i_extra_module
4
- def initialize(resource, options)
5
- @name = (options[:as] || resource).to_s
6
-
7
- @i_klass = (options[:billable_type] || name.to_s.classify).to_s.constantize
8
-
9
- @i_param = options[:billable_param] || "#{name.singularize}_id" #default #{resource}_id
10
-
11
- # key to find interfaceable in controller, when
12
- # :uuid then find_by! :uuid => params[:uuid]
13
- # :shop_uuid then find_by! :uuid => params[:shop_uuid]
14
- # :shop_id then find_by! :id => params[:shop_id]
15
- @i_find_key = @i_param[/^(#{resource}_|)(\w+)/,2]
16
- # FIXME not before schema load
17
- #raise "#{@i_klass.name} has no method #{@i_find_key}" unless @i_klass.new.respond_to? @i_find_key
18
- #raise "Did you forget to add 'has_extface_devices' in #{@i_klass.name} ?" unless @i_klass.new.respond_to? :extface_devices
19
- @i_extra_module = options[:controller_include].to_s.constantize if options[:controller_include].present?
20
- end
21
-
22
- def mount_point
23
- "#{name}_billing"
24
- end
25
-
26
- class << self
27
- def find(fullpath)
28
- Billing.mappings[fullpath[%r{/(\w+)_billing\/}, 1]]
29
- end
30
- end
31
- end
32
- end
@@ -1,16 +0,0 @@
1
- module ActionDispatch::Routing
2
- class Mapper
3
- def billing_for(resource, options = {})
4
- mapping = Billing.add_mapping(resource, options)
5
- mount Billing::Engine, at: mapping.mount_point, as: [options[:as],:billing].compact.join('_')
6
- get "#{mapping.mount_point}/accounts", to: "billing/accounts#index", as: options[:as] ? options[:as].to_s.pluralize.intern : :billing_accounts
7
- get "#{mapping.mount_point}/accounts/:account_id", to: "billing/accounts#show", as: options[:as] ? options[:as].to_s.singularize.intern : :billing_account
8
- get "#{mapping.mount_point}/accounts/:account_id/charges", to: "billing/charges#index", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_charges" : :billing_account_charges
9
- get "#{mapping.mount_point}/accounts/:account_id/charges/new", to: "billing/charges#new", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_new_charge" : :billing_account_new_charge
10
- get "#{mapping.mount_point}/accounts/:account_id/charges/:charge_id", to: "billing/charges#show", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_charge" : :billing_account_charge
11
- get "#{mapping.mount_point}/accounts/:account_id/payments", to: "billing/payments#index", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_payments" : :billing_account_payments
12
- get "#{mapping.mount_point}/accounts/:account_id/payments/new", to: "billing/payments#new", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_new_payment" : :billing_account_new_payment
13
- get "#{mapping.mount_point}/accounts/:account_id/payments/:payment_id", to: "billing/payments#show", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_payment" : :billing_account_payment
14
- end
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class AccountsControllerTest < ActionController::TestCase
5
- setup do
6
- @account = billing_accounts(:one)
7
- end
8
-
9
- test "should get index" do
10
- get :index
11
- assert_response :success
12
- end
13
-
14
- test "new" do
15
- get :new
16
- assert_response :success
17
- end
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class ChargesControllerTest < ActionController::TestCase
5
- setup do
6
- @charge = billing_charges(:one)
7
- @account = @charge.account
8
- end
9
-
10
- test "should get new" do
11
- get :new, account_id: @account
12
- assert_response :success
13
- end
14
-
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class ModifiersControllerTest < ActionController::TestCase
5
- setup do
6
- @modifier = billing_modifiers(:one)
7
- @account = @modifier.account
8
- end
9
-
10
- test "should get new" do
11
- get :new, account_id: @account
12
- assert_response :success
13
- end
14
-
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class PaymentsControllerTest < ActionController::TestCase
5
- setup do
6
- @payment = billing_payments(:one)
7
- @account = @payment.account
8
- end
9
-
10
- test "should get new" do
11
- get :new, account_id: @account
12
- assert_response :success
13
- end
14
-
15
- end
16
- end
@@ -1,6 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class AccountsHelperTest < ActionView::TestCase
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Billing
4
- class ChargesHelperTest < ActionView::TestCase
5
- end
6
- end