caboose-cms 0.8.78 → 0.8.79
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/caboose/admin_edit_invoice.js +45 -18
- data/app/controllers/caboose/invoices_controller.rb +20 -10
- data/app/controllers/caboose/subscriptions_controller.rb +60 -58
- data/app/controllers/caboose/variants_controller.rb +80 -97
- data/app/models/caboose/core_plugin.rb +1 -2
- data/app/models/caboose/line_item.rb +2 -1
- data/app/models/caboose/schema.rb +64 -67
- data/app/models/caboose/subscription.rb +130 -20
- data/app/models/caboose/variant.rb +21 -1
- data/app/views/caboose/invoices/admin_edit.html.erb +11 -3
- data/app/views/caboose/invoices/admin_index.html.erb +26 -13
- data/app/views/caboose/invoices/admin_user_edit.html.erb +60 -0
- data/app/views/caboose/subscriptions/admin_edit.html.erb +25 -60
- data/app/views/caboose/subscriptions/admin_index.html.erb +17 -18
- data/app/views/caboose/subscriptions/admin_user_index.html.erb +41 -0
- data/app/views/caboose/users/_admin_header.html.erb +3 -1
- data/app/views/caboose/variants/admin_edit.html.erb +26 -1
- data/lib/caboose/version.rb +1 -1
- data/lib/tasks/caboose.rake +4 -0
- metadata +4 -7
- data/app/controllers/caboose/user_subscriptions_controller.rb +0 -146
- data/app/models/caboose/user_subscription.rb +0 -144
- data/app/views/caboose/user_subscriptions/admin_edit.html.erb +0 -38
- data/app/views/caboose/user_subscriptions/admin_index.html.erb +0 -38
- data/app/views/caboose/user_subscriptions/admin_user_index.html.erb +0 -39
@@ -1,144 +0,0 @@
|
|
1
|
-
|
2
|
-
module Caboose
|
3
|
-
class UserSubscription < ActiveRecord::Base
|
4
|
-
self.table_name = 'store_user_subscriptions'
|
5
|
-
self.primary_key = 'id'
|
6
|
-
|
7
|
-
belongs_to :subscription
|
8
|
-
belongs_to :user
|
9
|
-
has_many :line_items
|
10
|
-
attr_accessible :id ,
|
11
|
-
:subscription_id ,
|
12
|
-
:user_id ,
|
13
|
-
:date_started ,
|
14
|
-
:date_started_full ,
|
15
|
-
:status
|
16
|
-
|
17
|
-
STATUS_ACTIVE = 'active'
|
18
|
-
STATUS_INACTIVE = 'inactive'
|
19
|
-
|
20
|
-
def calculate_date_started_full
|
21
|
-
|
22
|
-
s = self.subscription
|
23
|
-
if !s.start_on_day
|
24
|
-
self.date_started_full = self.date_started
|
25
|
-
self.save
|
26
|
-
end
|
27
|
-
|
28
|
-
s = self.subscription
|
29
|
-
d = nil
|
30
|
-
if s.interval == Subscription::INTERVAL_YEARLY
|
31
|
-
d = Date.new(self.date_started.year, s.start_month, s.start_day)
|
32
|
-
d = d + 1.year if d < self.date_started
|
33
|
-
elsif s.interval == Subscription::INTERVAL_MONTHLY
|
34
|
-
d = Date.new(self.date_started.year, s.start_month, s.start_day)
|
35
|
-
d = d + 1.month if d < self.date_started
|
36
|
-
end
|
37
|
-
self.date_started_full = d
|
38
|
-
self.save
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def custom_prorate
|
43
|
-
return eval(self.subscription.prorate_function)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Verify invoices exist for the entire subscription period up until today
|
47
|
-
def create_invoices
|
48
|
-
|
49
|
-
self.calculate_date_started_full if self.date_started_full.nil?
|
50
|
-
|
51
|
-
interval = case self.subscription.interval
|
52
|
-
when Subscription::INTERVAL_MONTHLY then 1.month
|
53
|
-
when Subscription::INTERVAL_YEARLY then 1.year
|
54
|
-
end
|
55
|
-
sc = self.subscription.site.store_config
|
56
|
-
v = self.subscription.variant
|
57
|
-
unit_price = v.clearance && v.clearance_price ? v.clearance_price : (v.on_sale? ? v.sale_price : v.price)
|
58
|
-
|
59
|
-
# Special case if the subscription starts on specific day
|
60
|
-
if self.subscription.start_on_day && (Date.today > self.date_started_full)
|
61
|
-
li = self.line_items.where("date_starts = ? date_ends = ?", self.date_started, self.date_started_full - 1.day).first
|
62
|
-
if li.nil?
|
63
|
-
prorated_unit_price = unit_price + 0.00
|
64
|
-
if self.subscription.prorate
|
65
|
-
prorated_unit_price = case self.subscription.prorate_method
|
66
|
-
when Subscription::PRORATE_METHOD_FLAT then self.subscription.prorate_flat_amount
|
67
|
-
when Subscription::PRORATE_METHOD_PERCENTAGE then unit_price * ((self.date_started_full - self.date_started).to_f / ((self.date_started_full + interval) - self.date_started_full).to_f)
|
68
|
-
when Subscription::PRORATE_METHOD_CUSTOM then self.subscription.custom_prorate(self)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
invoice = Caboose::Invoice.create(
|
72
|
-
:site_id => self.subscription.site_id,
|
73
|
-
:status => Caboose::Invoice::STATUS_PENDING,
|
74
|
-
:financial_status => Caboose::Invoice::STATUS_PENDING,
|
75
|
-
:date_created => DateTime.now,
|
76
|
-
:payment_terms => sc.default_payment_terms,
|
77
|
-
:invoice_number => sc.next_invoice_number
|
78
|
-
)
|
79
|
-
LineItem.create(
|
80
|
-
:invoice_id => invoice.id,
|
81
|
-
:variant_id => v.id,
|
82
|
-
:quantity => 1,
|
83
|
-
:unit_price => prorated_unit_price,
|
84
|
-
:subtotal => prorated_unit_price,
|
85
|
-
:status => 'pending',
|
86
|
-
:user_subscription_id => self.id,
|
87
|
-
:date_starts => d,
|
88
|
-
:date_ends => d + interval - 1.day
|
89
|
-
)
|
90
|
-
invoice.calculate
|
91
|
-
invoice.save
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
d2 = self.date_started_full + 1.day - 1.day
|
96
|
-
while d2 <= Date.today do
|
97
|
-
d2 = d2 + interval
|
98
|
-
end
|
99
|
-
d = self.date_started + 1.day - 1.day
|
100
|
-
while d <= d2 do
|
101
|
-
# See if an invoice has already been created for today
|
102
|
-
li = self.line_items.where("date_starts = ? AND date_ends = ?", d, d + interval - 1.day).first
|
103
|
-
if li.nil?
|
104
|
-
invoice = Caboose::Invoice.create(
|
105
|
-
:site_id => self.subscription.site_id,
|
106
|
-
:customer_id => self.user_id,
|
107
|
-
:status => Caboose::Invoice::STATUS_PENDING,
|
108
|
-
:financial_status => Caboose::Invoice::STATUS_PENDING,
|
109
|
-
:date_created => DateTime.now,
|
110
|
-
:payment_terms => sc.default_payment_terms,
|
111
|
-
:invoice_number => sc.next_invoice_number
|
112
|
-
)
|
113
|
-
LineItem.create(
|
114
|
-
:invoice_id => invoice.id,
|
115
|
-
:variant_id => v.id,
|
116
|
-
:quantity => 1,
|
117
|
-
:unit_price => unit_price,
|
118
|
-
:subtotal => unit_price,
|
119
|
-
:status => 'pending',
|
120
|
-
:user_subscription_id => self.id,
|
121
|
-
:date_starts => d,
|
122
|
-
:date_ends => d + interval - 1.day
|
123
|
-
)
|
124
|
-
invoice.calculate
|
125
|
-
invoice.save
|
126
|
-
end
|
127
|
-
d = d + interval
|
128
|
-
end
|
129
|
-
return true
|
130
|
-
end
|
131
|
-
|
132
|
-
#===========================================================================
|
133
|
-
# Static methods
|
134
|
-
#===========================================================================
|
135
|
-
|
136
|
-
def UserSubscription.create_invoices
|
137
|
-
UserSubscription.where(:status => UserSubscription::STATUS_ACTIVE).all.each do |us|
|
138
|
-
us.create_invoices
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
<%= render :partial => 'caboose/users/admin_header' %>
|
3
|
-
|
4
|
-
<p><div id='usersubscription_<%= @user_subscription.id %>_subscription_id' ></div></p>
|
5
|
-
<p><div id='usersubscription_<%= @user_subscription.id %>_user_id' ></div></p>
|
6
|
-
<p><div id='usersubscription_<%= @user_subscription.id %>_date_started' ></div></p>
|
7
|
-
<p><div id='usersubscription_<%= @user_subscription.id %>_date_started_full' ></div></p>
|
8
|
-
<p><div id='usersubscription_<%= @user_subscription.id %>_status' ></div></p>
|
9
|
-
|
10
|
-
<%= render :partial => 'caboose/users/admin_footer' %>
|
11
|
-
|
12
|
-
<% content_for :caboose_css do %>
|
13
|
-
<style type='text/css'>
|
14
|
-
#content input[type=checkbox] { position: relative; }
|
15
|
-
#roles { height: 200px; overflow-y: scroll; margin-bottom: 20px; }
|
16
|
-
</style>
|
17
|
-
<% end %>
|
18
|
-
<% content_for :caboose_js do %>
|
19
|
-
<%= javascript_include_tag "caboose/model/all" %>
|
20
|
-
<script type="text/javascript">
|
21
|
-
|
22
|
-
$(document).ready(function() {
|
23
|
-
new ModelBinder({
|
24
|
-
name: 'UserSubcription',
|
25
|
-
id: <%= @edituser.id %>,
|
26
|
-
update_url: '/admin/users/<%= @edituser.id %>/subscriptions/<%= @user_subscription.id %>',
|
27
|
-
authenticity_token: '<%= form_authenticity_token %>',
|
28
|
-
attributes: [
|
29
|
-
{ name: 'subscription_id' , nice_name: 'Subcription' , type: 'select' , value: <%= raw Caboose.json(@edituser.subscription_id ) %>, width: 400, options_url '/admin/users/<%= @edituser.id %>/subscriptions/subscription-options' },
|
30
|
-
{ name: 'date_started' , nice_name: 'Date Started' , type: 'date' , value: <%= raw Caboose.json(@edituser.date_started ) %>, width: 400 },
|
31
|
-
{ name: 'date_started_full' , nice_name: 'Date Started Full' , type: 'date' , value: <%= raw Caboose.json(@edituser.date_started_full ) %>, width: 400 },
|
32
|
-
{ name: 'status' , nice_name: 'Status' , type: 'select' , value: <%= raw Caboose.json(@edituser.status ) %>, width: 400, options_url '/admin/users/<%= @edituser.id %>/subscriptions/status-options' }
|
33
|
-
]
|
34
|
-
});
|
35
|
-
});
|
36
|
-
|
37
|
-
</script>
|
38
|
-
<% end %>
|
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
<h1>User Subcriptions</h1>
|
3
|
-
|
4
|
-
<div id='usersubscriptions'></div>
|
5
|
-
|
6
|
-
<% content_for :caboose_js do %>
|
7
|
-
<%= javascript_include_tag 'caboose/model/all' %>
|
8
|
-
<script type='text/javascript'>
|
9
|
-
|
10
|
-
$(document).ready(function() {
|
11
|
-
var that = this;
|
12
|
-
var table = new IndexTable({
|
13
|
-
form_authenticity_token: '<%= form_authenticity_token %>',
|
14
|
-
container: 'usersubscriptions',
|
15
|
-
base_url: '/admin/user-subscriptions',
|
16
|
-
allow_bulk_edit: true,
|
17
|
-
allow_bulk_delete: true,
|
18
|
-
allow_duplicate: false,
|
19
|
-
allow_advanced_edit: true,
|
20
|
-
fields: [
|
21
|
-
{ show: true, bulk_edit: true, name: 'subscription_id' , nice_name: 'Subscription' , sort: 'subscription_id' , type: 'select' , value: function(us) { return us.subscription_id }, text: function(us) { return us.subscription ? us.subscription.name : us.subscription_id; }, width: 75, align: 'left', options_url: '/admin/user-subscriptions/subscription-options' },
|
22
|
-
{ show: true, bulk_edit: true, name: 'user_id' , nice_name: 'User' , sort: 'user_id' , type: 'select' , value: function(us) { return us.user_id }, text: function(us) { return us.user ? us.user.first_name + ' ' + us.user.last_name : us.user_id; }, width: 75, align: 'left', options_url: '/admin/user-subscriptions/user-options' },
|
23
|
-
{ show: true, bulk_edit: true, name: 'date_started' , nice_name: 'Date Started' , sort: 'date_started' , type: 'date' , value: function(us) { return us.date_started }, width: 75, align: 'left' },
|
24
|
-
{ show: true, bulk_edit: true, name: 'date_started_full' , nice_name: 'Date Started Full' , sort: 'date_started_full' , type: 'date' , value: function(us) { return us.date_started_full }, width: 75, align: 'left' },
|
25
|
-
{ show: true, bulk_edit: true, name: 'status' , nice_name: 'Status' , sort: 'status' , type: 'select' , value: function(us) { return us.status }, width: 75, align: 'left', options_url: '/admin/user-subscriptions/status-options' }
|
26
|
-
],
|
27
|
-
new_model_text: 'New User Subscription',
|
28
|
-
no_models_text: "This user doesn't have any subscriptions right now.",
|
29
|
-
new_model_fields: [
|
30
|
-
{ name: 'subscription_id', nice_name: 'Subscription', type: 'select', width: 400, options_url: '/admin/user-subscriptions/subscription-options' }
|
31
|
-
],
|
32
|
-
bulk_import_fields: ['subscription_id', 'user_id', 'date_started', 'date_started_full', 'status'],
|
33
|
-
bulk_import_url: '/admin/user-subscriptions/bulk'
|
34
|
-
});
|
35
|
-
});
|
36
|
-
|
37
|
-
</script>
|
38
|
-
<% end %>
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
<%= render :partial => 'caboose/users/admin_header' %>
|
3
|
-
|
4
|
-
<div id='usersubscriptions'></div>
|
5
|
-
|
6
|
-
<%= render :partial => 'caboose/users/admin_footer' %>
|
7
|
-
|
8
|
-
<% content_for :caboose_js do %>
|
9
|
-
<%= javascript_include_tag 'caboose/model/all' %>
|
10
|
-
<script type='text/javascript'>
|
11
|
-
|
12
|
-
$(document).ready(function() {
|
13
|
-
var that = this;
|
14
|
-
var table = new IndexTable({
|
15
|
-
form_authenticity_token: '<%= form_authenticity_token %>',
|
16
|
-
container: 'usersubscriptions',
|
17
|
-
base_url: '/admin/users/<%= @edituser.id %>/subscriptions',
|
18
|
-
allow_bulk_edit: true,
|
19
|
-
allow_bulk_delete: true,
|
20
|
-
allow_duplicate: false,
|
21
|
-
allow_advanced_edit: true,
|
22
|
-
fields: [
|
23
|
-
{ show: true, bulk_edit: true, name: 'subscription_id' , nice_name: 'Subscription' , sort: 'subscription_id' , type: 'select' , value: function(us) { return us.subscription_id }, text: function(us) { return us.subscription ? us.subscription.name : us.subscription_id; }, width: 75, align: 'left', options_url: '/admin/users<%= @edituser.id %>/subscriptions/subscription-options' },
|
24
|
-
{ show: true, bulk_edit: true, name: 'date_started' , nice_name: 'Date Started' , sort: 'date_started' , type: 'date' , value: function(us) { return us.date_started }, width: 75, align: 'left' },
|
25
|
-
{ show: true, bulk_edit: true, name: 'date_started_full' , nice_name: 'Date Started Full' , sort: 'date_started_full' , type: 'date' , value: function(us) { return us.date_started_full }, width: 75, align: 'left' },
|
26
|
-
{ show: true, bulk_edit: true, name: 'status' , nice_name: 'Status' , sort: 'status' , type: 'select' , value: function(us) { return us.status }, width: 75, align: 'left', options_url: '/admin/users<%= @edituser.id %>/subscriptions/status-options' }
|
27
|
-
],
|
28
|
-
new_model_text: 'New User Subscription',
|
29
|
-
no_models_text: "This user doesn't have any subscriptions right now.",
|
30
|
-
new_model_fields: [
|
31
|
-
{ name: 'subscription_id', nice_name: 'Subscription', type: 'select', width: 400, options_url: '/admin/users<%= @edituser.id %>/subscriptions/subscription-options' }
|
32
|
-
],
|
33
|
-
bulk_import_fields: ['subscription_id', 'date_started', 'date_started_full', 'status'],
|
34
|
-
bulk_import_url: '/admin/users/<%= @edituser.id %>/subscriptions/bulk'
|
35
|
-
});
|
36
|
-
});
|
37
|
-
|
38
|
-
</script>
|
39
|
-
<% end %>
|