accountability 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +60 -17
- data/app/assets/config/accountability_manifest.js +1 -0
- data/app/assets/stylesheets/{acts_as_billable → accountability}/application.css +1 -1
- data/app/controllers/accountability/accounts_controller.rb +19 -0
- data/app/controllers/accountability/application_controller.rb +45 -0
- data/app/controllers/accountability/order_groups_controller.rb +65 -0
- data/app/controllers/accountability/products_controller.rb +56 -0
- data/app/helpers/accountability/application_helper.rb +19 -0
- data/app/models/accountability/account.rb +28 -0
- data/app/models/accountability/account/transactions.rb +43 -0
- data/app/models/accountability/application_record.rb +3 -0
- data/app/models/accountability/coupon.rb +39 -0
- data/app/models/accountability/credit.rb +46 -0
- data/app/models/accountability/debit.rb +14 -0
- data/app/models/accountability/deduction.rb +17 -0
- data/app/models/accountability/discount.rb +36 -0
- data/app/models/accountability/offerable.rb +76 -0
- data/app/models/accountability/order_group.rb +52 -0
- data/app/models/accountability/order_item.rb +88 -0
- data/app/models/accountability/payment.rb +8 -0
- data/app/models/accountability/product.rb +53 -0
- data/app/views/accountability/accounts/index.html.haml +13 -0
- data/app/views/accountability/accounts/show.html.haml +12 -0
- data/app/views/accountability/order_groups/new.html.haml +1 -0
- data/app/views/accountability/order_groups/show.html.haml +16 -0
- data/app/views/accountability/products/edit.html.erb +1 -0
- data/app/views/accountability/products/index.html.haml +39 -0
- data/app/views/accountability/products/new.html.erb +40 -0
- data/app/views/accountability/products/show.html.erb +1 -0
- data/app/views/layouts/acts_as_billable/application.html.erb +2 -2
- data/config/routes.rb +1 -3
- data/db/migrate/20190814000455_create_accountability_tables.rb +117 -0
- data/lib/accountability.rb +10 -0
- data/lib/accountability/cartographer.rb +28 -0
- data/lib/accountability/configuration.rb +16 -0
- data/lib/accountability/engine.rb +9 -0
- data/lib/accountability/extensions.rb +15 -0
- data/lib/accountability/extensions/acts_as_billable.rb +14 -0
- data/lib/accountability/extensions/acts_as_offerable.rb +36 -0
- data/lib/accountability/version.rb +3 -0
- metadata +40 -14
- data/app/assets/config/acts_as_billable_manifest.js +0 -1
- data/app/controllers/acts_as_billable/application_controller.rb +0 -3
- data/app/controllers/acts_as_billable/pages_controller.rb +0 -5
- data/app/helpers/acts_as_billable/application_helper.rb +0 -2
- data/app/models/acts_as_billable/application_record.rb +0 -3
- data/app/models/acts_as_billable/product.rb +0 -2
- data/app/views/acts_as_billable/pages/dashboard.html.erb +0 -1
- data/db/migrate/20190814000455_create_acts_as_billable_tables.rb +0 -51
- data/lib/acts_as_billable.rb +0 -5
- data/lib/acts_as_billable/engine.rb +0 -3
- data/lib/acts_as_billable/version.rb +0 -3
@@ -0,0 +1,40 @@
|
|
1
|
+
<h1>Product#new</h1>
|
2
|
+
|
3
|
+
<% @product.errors.full_messages.each do |message| %>
|
4
|
+
<div class="alert alert-danger">
|
5
|
+
<%= message %>
|
6
|
+
</div>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<%= form_with model: [:accountability, @product], local: true do |f| %>
|
10
|
+
<div class="card my-3">
|
11
|
+
<div class="card-header">
|
12
|
+
<b>Info</b>
|
13
|
+
</div>
|
14
|
+
<div class="card-body">
|
15
|
+
<div class="form-row">
|
16
|
+
<div class="form-group col-md-8">
|
17
|
+
<%= f.label :name %>
|
18
|
+
<%= f.text_field :name, class: 'form-control' %>
|
19
|
+
</div>
|
20
|
+
<div class="form-group col-md-4">
|
21
|
+
<%= f.label :sku %>
|
22
|
+
<%= f.text_field :sku, class: 'form-control' %>
|
23
|
+
</div>
|
24
|
+
<div class="form-group col-md-4">
|
25
|
+
<%= f.label :price %>
|
26
|
+
<%= f.number_field :price, step: 2, class: 'form-control' %>
|
27
|
+
</div>
|
28
|
+
<div class="form-group col-md-12">
|
29
|
+
<%= f.label :description %>
|
30
|
+
<%= f.text_area :description, class: 'form-control' %>
|
31
|
+
</div>
|
32
|
+
<div class="form-group col-md-4">
|
33
|
+
<%= f.label :source_class, 'Category' %>
|
34
|
+
<%= f.select :source_class, Accountability::Offerable.collection.stringify_keys.keys.map(&:titleize), {}, {class: 'form-control' } %>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
<%= f.submit 'Submit', class: 'btn btn-success' %>
|
40
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Product#show</h1>
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
<html>
|
4
4
|
<head>
|
5
|
-
<title>
|
5
|
+
<title>Accountability</title>
|
6
6
|
<%= csrf_meta_tags %>
|
7
7
|
<%= csp_meta_tag %>
|
8
8
|
|
9
|
-
<%= stylesheet_link_tag "
|
9
|
+
<%= stylesheet_link_tag "accountability/application", media: "all" %>
|
10
10
|
</head>
|
11
11
|
<body>
|
12
12
|
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,117 @@
|
|
1
|
+
# rubocop:disable Metrics/AbcSize
|
2
|
+
# rubocop:disable Metrics/MethodLength
|
3
|
+
|
4
|
+
class CreateAccountabilityTables < ActiveRecord::Migration[6.0]
|
5
|
+
def change
|
6
|
+
create_table :accountability_accounts do |t|
|
7
|
+
t.belongs_to :billable, null: true, polymorphic: true
|
8
|
+
|
9
|
+
t.datetime :last_balanced_at, default: nil, null: true
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table :accountability_debits do |t|
|
15
|
+
t.belongs_to :account, null: false, index: { name: :index_account_on_debit }
|
16
|
+
t.belongs_to :payment, null: true, index: { name: :index_payment_on_debit }
|
17
|
+
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :accountability_credits do |t|
|
23
|
+
t.belongs_to :account, null: false, index: { name: :index_account_on_credit }
|
24
|
+
t.belongs_to :order_item, null: false, index: { name: :index_order_item_on_credit }
|
25
|
+
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
26
|
+
|
27
|
+
t.timestamps
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table :accountability_payments do |t|
|
31
|
+
t.belongs_to :account, null: false, index: { name: :index_account_on_payment }
|
32
|
+
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
33
|
+
t.integer :status, default: 0, null: false # Pending, Processing, Complete, Failed
|
34
|
+
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
38
|
+
create_table :accountability_order_groups do |t|
|
39
|
+
t.belongs_to :account, null: true, index: { name: :index_account_on_order_group }
|
40
|
+
|
41
|
+
t.integer :status, default: 0, null: false # Pending, Complete, Abandoned
|
42
|
+
t.text :notes, default: nil, null: true, limit: 10_000
|
43
|
+
|
44
|
+
t.timestamps
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table :accountability_order_items do |t|
|
48
|
+
t.belongs_to :order_group, null: false, index: { name: :index_order_group_on_order_iem }
|
49
|
+
t.belongs_to :product, null: false, index: { name: :index_product_on_order_iem }
|
50
|
+
|
51
|
+
t.text :source_scope, default: nil, null: true, limit: 1_000
|
52
|
+
t.datetime :termination_date, default: nil, null: true
|
53
|
+
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
|
57
|
+
create_table :accountability_deductions do |t|
|
58
|
+
t.belongs_to :credit, null: false, index: { name: :index_credit_on_deduction }
|
59
|
+
t.belongs_to :discount, null: false, index: { name: :index_discount_on_deduction }
|
60
|
+
|
61
|
+
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
62
|
+
|
63
|
+
t.timestamps
|
64
|
+
end
|
65
|
+
|
66
|
+
create_table :accountability_discounts do |t|
|
67
|
+
t.belongs_to :order_item, null: false, index: { name: :index_order_item_on_discount }
|
68
|
+
t.belongs_to :coupon, null: false, index: { name: :index_coupon_on_discount }
|
69
|
+
|
70
|
+
t.timestamps
|
71
|
+
end
|
72
|
+
|
73
|
+
create_table :accountability_products do |t|
|
74
|
+
t.boolean :public, default: true, null: false
|
75
|
+
t.decimal :price, default: 0.00, precision: 8, scale: 2, null: false
|
76
|
+
t.integer :quantity, default: 1, null: false
|
77
|
+
t.string :name, default: nil, null: false
|
78
|
+
t.string :sku, default: nil, null: true
|
79
|
+
t.text :description, default: nil, null: true, limit: 10_000
|
80
|
+
t.integer :schedule, default: 0, null: false # OneTime, Weekly, Monthly, Annually
|
81
|
+
t.string :offerable_category, default: nil, null: false
|
82
|
+
t.text :source_scope, default: nil, null: true, limit: 1_000
|
83
|
+
t.text :billing_configuration, default: nil, null: true, limit: 1_000
|
84
|
+
|
85
|
+
t.datetime :activation_date, default: nil, null: true
|
86
|
+
t.datetime :expiration_date, default: nil, null: true
|
87
|
+
t.datetime :termination_date, default: nil, null: true
|
88
|
+
|
89
|
+
t.timestamps
|
90
|
+
end
|
91
|
+
|
92
|
+
create_table :accountability_coupons do |t|
|
93
|
+
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
94
|
+
t.boolean :public, default: true, null: false
|
95
|
+
t.integer :limit, default: nil, null: true
|
96
|
+
t.string :name, default: nil, null: false
|
97
|
+
t.string :code, default: nil, null: true
|
98
|
+
|
99
|
+
t.integer :usage_cap, default: 1, null: false
|
100
|
+
|
101
|
+
t.datetime :activation_date, default: nil, null: true
|
102
|
+
t.datetime :expiration_date, default: nil, null: true
|
103
|
+
t.datetime :termination_date, default: nil, null: true
|
104
|
+
|
105
|
+
t.timestamps
|
106
|
+
end
|
107
|
+
|
108
|
+
create_table :accountability_coupons_products, id: false do |t|
|
109
|
+
t.belongs_to :product, index: { name: :index_product_on_product_coupon }
|
110
|
+
t.belongs_to :coupon, index: { name: :index_coupon_on_product_coupon }
|
111
|
+
end
|
112
|
+
|
113
|
+
create_table :accountability_identities do |t|
|
114
|
+
t.belongs_to :identifiable, polymorphic: true, index: { name: :index_identifiable_on_identity }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_dependency 'accountability/engine'
|
2
|
+
require_dependency 'accountability/configuration'
|
3
|
+
require_dependency 'accountability/cartographer'
|
4
|
+
require_dependency 'accountability/extensions'
|
5
|
+
|
6
|
+
module Accountability
|
7
|
+
def self.configure(_tenant = :default)
|
8
|
+
yield Configuration if block_given?
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# TODO: Rewrite cartographer logic to be less flaky (see Devise)
|
2
|
+
|
3
|
+
module ActionDispatch::Routing
|
4
|
+
class Mapper
|
5
|
+
def accountability_views_for(*tenants)
|
6
|
+
options = tenants.extract_options!
|
7
|
+
|
8
|
+
options[:path_prefix] ||= options[:path] if options[:path_prefix].nil?
|
9
|
+
|
10
|
+
cartographer = proc do
|
11
|
+
namespace :accountability, path: options[:path_prefix], as: :accountability do
|
12
|
+
resources :accounts, only: %i[index show]
|
13
|
+
resources :products
|
14
|
+
resources :order_groups, path: 'orders' do
|
15
|
+
member do
|
16
|
+
post :add_item
|
17
|
+
end
|
18
|
+
end
|
19
|
+
root to: 'products#index'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
cartographer.call
|
24
|
+
|
25
|
+
Accountability::Engine.routes.draw(&cartographer)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Accountability
|
2
|
+
class Configuration
|
3
|
+
class << self
|
4
|
+
attr_accessor :billable_identifier
|
5
|
+
attr_writer :admin_checker
|
6
|
+
|
7
|
+
def admin_checker
|
8
|
+
if @admin_checker.is_a? Proc
|
9
|
+
@admin_checker
|
10
|
+
else
|
11
|
+
-> { true }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_dependency 'accountability/extensions/acts_as_billable'
|
2
|
+
require_dependency 'accountability/extensions/acts_as_offerable'
|
3
|
+
|
4
|
+
module Accountability
|
5
|
+
module Extensions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class_attribute :acts_as, default: ActiveSupport::ArrayInquirer.new
|
10
|
+
end
|
11
|
+
|
12
|
+
include ActsAsBillable
|
13
|
+
include ActsAsOfferable
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Accountability
|
2
|
+
module Extensions
|
3
|
+
module ActsAsBillable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def acts_as_billable
|
8
|
+
has_many :accounts, as: :billable, class_name: 'Accountability::Account', dependent: :nullify
|
9
|
+
self.acts_as = acts_as.dup << :billable
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Accountability
|
2
|
+
module Extensions
|
3
|
+
module ActsAsOfferable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def has_offerable(category = name, **options)
|
8
|
+
tenants = options.values_at(:tenants, :tenant)
|
9
|
+
tenants.append(:default) if tenants.empty?
|
10
|
+
|
11
|
+
tenants.each do |tenant|
|
12
|
+
offerable_category = Offerable.add(category, tenant: tenant, class_name: name)
|
13
|
+
yield offerable_category if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
self.acts_as = acts_as.dup << :offerable
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :acts_as_offerable, :has_offerable
|
20
|
+
|
21
|
+
def has_offerable_trait(trait_name, **options)
|
22
|
+
tenants = options.values_at(:tenants, :tenant)
|
23
|
+
tenants.append(:default) if tenants.empty?
|
24
|
+
category = options[:category].presence || trait_name
|
25
|
+
|
26
|
+
tenants.each do |tenant|
|
27
|
+
offerable_category = Offerable.add(category, tenant: tenant, trait: trait_name, class_name: name)
|
28
|
+
yield offerable_category if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
self.acts_as = acts_as.dup << :offerable
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accountability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Stowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -41,26 +41,52 @@ dependencies:
|
|
41
41
|
description: In Development - Coming Soon
|
42
42
|
email:
|
43
43
|
- joshua.stowers@elevatesystems.com
|
44
|
+
- evan.gray@elevatesystems.com
|
44
45
|
executables: []
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
48
49
|
- MIT-LICENSE
|
49
50
|
- README.md
|
50
|
-
- app/assets/config/
|
51
|
-
- app/assets/stylesheets/
|
52
|
-
- app/controllers/
|
53
|
-
- app/controllers/
|
54
|
-
- app/
|
55
|
-
- app/
|
56
|
-
- app/
|
57
|
-
- app/
|
51
|
+
- app/assets/config/accountability_manifest.js
|
52
|
+
- app/assets/stylesheets/accountability/application.css
|
53
|
+
- app/controllers/accountability/accounts_controller.rb
|
54
|
+
- app/controllers/accountability/application_controller.rb
|
55
|
+
- app/controllers/accountability/order_groups_controller.rb
|
56
|
+
- app/controllers/accountability/products_controller.rb
|
57
|
+
- app/helpers/accountability/application_helper.rb
|
58
|
+
- app/models/accountability/account.rb
|
59
|
+
- app/models/accountability/account/transactions.rb
|
60
|
+
- app/models/accountability/application_record.rb
|
61
|
+
- app/models/accountability/coupon.rb
|
62
|
+
- app/models/accountability/credit.rb
|
63
|
+
- app/models/accountability/debit.rb
|
64
|
+
- app/models/accountability/deduction.rb
|
65
|
+
- app/models/accountability/discount.rb
|
66
|
+
- app/models/accountability/offerable.rb
|
67
|
+
- app/models/accountability/order_group.rb
|
68
|
+
- app/models/accountability/order_item.rb
|
69
|
+
- app/models/accountability/payment.rb
|
70
|
+
- app/models/accountability/product.rb
|
71
|
+
- app/views/accountability/accounts/index.html.haml
|
72
|
+
- app/views/accountability/accounts/show.html.haml
|
73
|
+
- app/views/accountability/order_groups/new.html.haml
|
74
|
+
- app/views/accountability/order_groups/show.html.haml
|
75
|
+
- app/views/accountability/products/edit.html.erb
|
76
|
+
- app/views/accountability/products/index.html.haml
|
77
|
+
- app/views/accountability/products/new.html.erb
|
78
|
+
- app/views/accountability/products/show.html.erb
|
58
79
|
- app/views/layouts/acts_as_billable/application.html.erb
|
59
80
|
- config/routes.rb
|
60
|
-
- db/migrate/
|
61
|
-
- lib/
|
62
|
-
- lib/
|
63
|
-
- lib/
|
81
|
+
- db/migrate/20190814000455_create_accountability_tables.rb
|
82
|
+
- lib/accountability.rb
|
83
|
+
- lib/accountability/cartographer.rb
|
84
|
+
- lib/accountability/configuration.rb
|
85
|
+
- lib/accountability/engine.rb
|
86
|
+
- lib/accountability/extensions.rb
|
87
|
+
- lib/accountability/extensions/acts_as_billable.rb
|
88
|
+
- lib/accountability/extensions/acts_as_offerable.rb
|
89
|
+
- lib/accountability/version.rb
|
64
90
|
homepage: https://elevatesystems.com
|
65
91
|
licenses:
|
66
92
|
- MIT
|
@@ -1 +0,0 @@
|
|
1
|
-
//= link_directory ../stylesheets/acts_as_billable .css
|
@@ -1 +0,0 @@
|
|
1
|
-
<h1>Billing Dashboard</h1>
|
@@ -1,51 +0,0 @@
|
|
1
|
-
class CreateActsAsBillableTables < ActiveRecord::Migration[6.0]
|
2
|
-
def change
|
3
|
-
create_table :acts_as_billable_products do |t|
|
4
|
-
# ProductOffering
|
5
|
-
t.integer :status, default: 0, null: false # Active, Disabled
|
6
|
-
t.string :scoped_ids, array: true
|
7
|
-
|
8
|
-
# LineItem
|
9
|
-
t.belongs_to :product, null: true
|
10
|
-
t.belongs_to :contract, null: true
|
11
|
-
t.belongs_to :ledger, null: false
|
12
|
-
t.integer :schedule, default: 0, null: false # Weekly, Biweekly, Monthly, Annually
|
13
|
-
|
14
|
-
# Shared
|
15
|
-
t.string :name, default: nil, null: false
|
16
|
-
t.text :description, default: nil, null: true
|
17
|
-
t.decimal :price, default: 0.00, precision: 8, scale: 2, null: false
|
18
|
-
|
19
|
-
t.timestamps
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table :acts_as_billable_adjustments do |t|
|
23
|
-
# Coupon
|
24
|
-
t.integer :status, default: 0, null: false # Active, Disabled
|
25
|
-
t.string :scoped_ids, array: true
|
26
|
-
|
27
|
-
# Discount
|
28
|
-
t.belongs_to :adjustment, null: true
|
29
|
-
t.belongs_to :ledger, null: false
|
30
|
-
t.belongs_to :contract, null: true
|
31
|
-
t.integer :schedule, default: 0, null: false # Weekly, Biweekly, Monthly, Annually
|
32
|
-
|
33
|
-
# Shared
|
34
|
-
t.string :name, default: nil, null: false
|
35
|
-
t.text :description, default: nil, null: true
|
36
|
-
t.decimal :amount, default: 0.00, precision: 8, scale: 2, null: false
|
37
|
-
end
|
38
|
-
|
39
|
-
create_table :acts_as_billable_ledgers do |t|
|
40
|
-
t.belongs_to :billable, polymorphic: true, index: true
|
41
|
-
end
|
42
|
-
|
43
|
-
create_table :acts_as_billable_payments do |t|
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
create_table :acts_as_billable_contracts do |t|
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|