effective_memberships 0.4.2 → 0.4.5
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/app/controllers/effective/applicant_references_controller.rb +1 -1
- data/app/datatables/admin/effective_applicants_datatable.rb +1 -1
- data/app/datatables/admin/effective_categories_datatable.rb +4 -0
- data/app/models/concerns/effective_memberships_category.rb +0 -5
- data/app/models/concerns/effective_memberships_owner.rb +12 -0
- data/app/models/concerns/effective_memberships_registrar.rb +42 -6
- data/app/models/effective/membership.rb +13 -12
- data/app/views/admin/memberships/_form_membership.html.haml +6 -0
- data/app/views/effective/membership_cards/index.html.haml +1 -1
- data/lib/effective_memberships/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 940bfa04e965ae36e054add85ac673260b5fa11f2ff3939ec0f00a3732b6bba1
|
4
|
+
data.tar.gz: c3d94b16860a507b64e75bc7b156e6ce96f79845e5561a25a52ae48c57f3951b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ba80b0314968331c9bc85a2a021be327780daf44854379f52f4f9f64d8e6c0a3b816871129610b953d2b6d29f8eca22aa4699cc5fc5aceee3fbf86b72e87e2
|
7
|
+
data.tar.gz: 7671e32ba29f5540b90bbd250e5f78503033af257702a01caccfb93064c5e8a111e95cff7212f64c7b0ef2d0d8872131b76cef7ee10a800700f157fd3e8258d1
|
@@ -25,7 +25,7 @@ module Effective
|
|
25
25
|
def permitted_params
|
26
26
|
permitted = params.require(:effective_applicant_reference).permit!.except(:token, :last_notified_at, :status, :status_steps)
|
27
27
|
|
28
|
-
if current_user && current_user.
|
28
|
+
if current_user && current_user.memberships_owners.include?(resource.applicant&.owner)
|
29
29
|
permitted.except(:reservations, :reservations_reason, :work_history, :accept_declaration)
|
30
30
|
else
|
31
31
|
permitted
|
@@ -17,6 +17,10 @@ module Admin
|
|
17
17
|
col :tax_exempt
|
18
18
|
col :qb_item_name, visible: false
|
19
19
|
|
20
|
+
col :create_renewal_fees, visible: false
|
21
|
+
col :create_late_fees, visible: false
|
22
|
+
col :create_bad_standing, visible: false
|
23
|
+
|
20
24
|
col :category_type, search: EffectiveMemberships.Category.category_types
|
21
25
|
|
22
26
|
col :optional_applicant_wizard_steps, label: 'Applicant Steps'
|
@@ -110,11 +110,6 @@ module EffectiveMembershipsCategory
|
|
110
110
|
.or(where(can_apply_restricted: true))
|
111
111
|
}
|
112
112
|
|
113
|
-
# For the create_fees rake task
|
114
|
-
scope :create_renewal_fees, -> { where(create_renewal_fees: true) }
|
115
|
-
scope :create_late_fees, -> { where(create_late_fees: true) }
|
116
|
-
scope :create_bad_standing, -> { where(create_bad_standing: true) }
|
117
|
-
|
118
113
|
validates :title, presence: true, uniqueness: true
|
119
114
|
validates :category_type, presence: true
|
120
115
|
validates :position, presence: true
|
@@ -160,9 +160,21 @@ module EffectiveMembershipsOwner
|
|
160
160
|
fee
|
161
161
|
end
|
162
162
|
|
163
|
+
# These should be singular fees anyway.
|
164
|
+
def membership_period_fee(category:, period:, except: nil)
|
165
|
+
raise('expected except to be a string like Renewal') if except.present? && !except.kind_of?(String)
|
166
|
+
fees.find { |fee| fee.membership_period_fee? && fee.period == period && fee.category_id == category.id && fee.category_type == category.class.name && (except.blank? || fee.fee_type != except) }
|
167
|
+
end
|
168
|
+
|
163
169
|
def build_renewal_fee(category:, period:, late_on: nil, bad_standing_on: nil)
|
164
170
|
raise('must have an existing membership') unless membership.present?
|
165
171
|
|
172
|
+
# Sanity check.
|
173
|
+
# If there's already a purchased or unpurchased Prorated (or other membership period advancing fee) in this period
|
174
|
+
# We shouldn't be building renewal fees for the same period a prorated fee is purcahsed in
|
175
|
+
prorated = membership_period_fee(category: category, period: period, except: 'Renewal')
|
176
|
+
raise('must not have an existing membership_period (prorated) fee in this period') if prorated.present?
|
177
|
+
|
166
178
|
fee = fees.find { |fee| fee.fee_type == 'Renewal' && fee.period == period && fee.category_id == category.id && fee.category_type == category.class.name }
|
167
179
|
return fee if fee&.purchased?
|
168
180
|
|
@@ -33,6 +33,15 @@ module EffectiveMembershipsRegistrar
|
|
33
33
|
raise('to be implemented by app registrar')
|
34
34
|
end
|
35
35
|
|
36
|
+
# Should two could be overridden if we do non 1-year periods
|
37
|
+
def advance_period(period:, number:)
|
38
|
+
period.advance(years: number).beginning_of_year
|
39
|
+
end
|
40
|
+
|
41
|
+
def period_end_on(date:)
|
42
|
+
period(date: date).end_of_year
|
43
|
+
end
|
44
|
+
|
36
45
|
def assign!(owner, categories:, date: nil, number: nil)
|
37
46
|
categories = Array(categories)
|
38
47
|
|
@@ -243,18 +252,41 @@ module EffectiveMembershipsRegistrar
|
|
243
252
|
period(date: Time.zone.now)
|
244
253
|
end
|
245
254
|
|
255
|
+
def last_period
|
256
|
+
advance_period(period: current_period, number: -1)
|
257
|
+
end
|
258
|
+
|
246
259
|
# Returns a date of Jan 1, Year
|
247
260
|
def period(date:)
|
248
261
|
cutoff = renewal_fee_date(date: date) # period_end_on
|
249
|
-
period = (date < cutoff) ? date
|
262
|
+
period = (date < cutoff) ? advance_period(period: date, number: 0) : advance_period(period: date, number: 1)
|
250
263
|
period.to_date
|
251
264
|
end
|
252
265
|
|
253
|
-
|
254
|
-
|
266
|
+
# This is only used for a form collection on admin memberships
|
267
|
+
def periods(from:, to: nil)
|
268
|
+
to ||= Time.zone.now
|
269
|
+
|
270
|
+
raise('expected to date') unless to.respond_to?(:strftime)
|
271
|
+
raise('expected from date') unless from.respond_to?(:strftime)
|
272
|
+
|
273
|
+
from = period(date: from)
|
274
|
+
to = period(date: to)
|
275
|
+
|
276
|
+
retval = []
|
277
|
+
|
278
|
+
loop do
|
279
|
+
retval << from
|
280
|
+
from = advance_period(period: from, number: 1)
|
281
|
+
break if from > to
|
282
|
+
end
|
283
|
+
|
284
|
+
retval
|
255
285
|
end
|
256
286
|
|
287
|
+
|
257
288
|
# This is intended to be run once per day in a rake task
|
289
|
+
# rake effective_memberships:create_fees
|
258
290
|
# Create Renewal and Late fees
|
259
291
|
def create_fees!(period: nil, late_on: nil, bad_standing_on: nil)
|
260
292
|
# The current period, based on Time.zone.now
|
@@ -263,13 +295,17 @@ module EffectiveMembershipsRegistrar
|
|
263
295
|
bad_standing_on ||= bad_standing_date(period: period)
|
264
296
|
|
265
297
|
# Create Renewal Fees
|
266
|
-
Effective::Membership.
|
267
|
-
|
298
|
+
Effective::Membership.deep.with_unpaid_fees_through(period).find_each do |membership|
|
268
299
|
membership.categories.select(&:create_renewal_fees?).map do |category|
|
300
|
+
existing = membership.owner.membership_period_fee(category: category, period: period, except: 'Renewal')
|
301
|
+
next if existing.present? # This might be an existing Prorated fee
|
302
|
+
|
269
303
|
fee = membership.owner.build_renewal_fee(category: category, period: period, late_on: late_on, bad_standing_on: bad_standing_on)
|
270
304
|
raise("expected build_renewal_fee to return a fee for period #{period}") unless fee.kind_of?(Effective::Fee)
|
271
305
|
next if fee.purchased?
|
272
306
|
|
307
|
+
puts("Created renewal fee for #{membership.owner}") if fee.new_record? && !Rails.env.test?
|
308
|
+
|
273
309
|
fee.save!
|
274
310
|
end
|
275
311
|
end
|
@@ -277,7 +313,7 @@ module EffectiveMembershipsRegistrar
|
|
277
313
|
GC.start
|
278
314
|
|
279
315
|
# Create Late Fees
|
280
|
-
Effective::Membership.
|
316
|
+
Effective::Membership.deep.with_unpaid_fees_through(period).find_each do |membership|
|
281
317
|
membership.categories.select(&:create_late_fees?).map do |category|
|
282
318
|
fee = membership.owner.build_late_fee(category: category, period: period)
|
283
319
|
next if fee.blank? || fee.purchased?
|
@@ -42,18 +42,6 @@ module Effective
|
|
42
42
|
.or(where(fees_paid_period: nil))
|
43
43
|
}
|
44
44
|
|
45
|
-
scope :create_renewal_fees, -> (period = nil) {
|
46
|
-
deep.with_unpaid_fees_through(period).where.not(fees_paid_period: nil) # Must have purchased a Prorated or Renewal Fee before
|
47
|
-
}
|
48
|
-
|
49
|
-
scope :create_late_fees, -> (period = nil) {
|
50
|
-
deep.with_unpaid_fees_through(period).where.not(fees_paid_period: nil) # Must have purchased a Prorated or Renewal Fee before
|
51
|
-
}
|
52
|
-
|
53
|
-
scope :create_bad_standing, -> (period = nil) {
|
54
|
-
deep.with_unpaid_fees_through(period).where.not(fees_paid_period: nil) # Must have purchased a Prorated or Renewal Fee before
|
55
|
-
}
|
56
|
-
|
57
45
|
before_validation do
|
58
46
|
self.registration_on ||= joined_on
|
59
47
|
end
|
@@ -134,5 +122,18 @@ module Effective
|
|
134
122
|
fees_paid_period == EffectiveMemberships.Registrar.current_period
|
135
123
|
end
|
136
124
|
|
125
|
+
def change_fees_paid_period
|
126
|
+
fees_paid_period
|
127
|
+
end
|
128
|
+
|
129
|
+
def change_fees_paid_period=(date)
|
130
|
+
date = (date.respond_to?(:strftime) ? date : Date.parse(date))
|
131
|
+
|
132
|
+
period = EffectiveMemberships.Registrar.period(date: date)
|
133
|
+
period_end_on = EffectiveMemberships.Registrar.period_end_on(date: date)
|
134
|
+
|
135
|
+
assign_attributes(fees_paid_period: period, fees_paid_through_period: period_end_on)
|
136
|
+
end
|
137
|
+
|
137
138
|
end
|
138
139
|
end
|
@@ -17,6 +17,12 @@
|
|
17
17
|
= f.date_field :registration_on, label: 'Registered', hint: 'When the membership category last changed'
|
18
18
|
= f.text_field :number, hint: 'The membership number. Must be unique.'
|
19
19
|
|
20
|
+
- registrar = EffectiveMemberships.Registrar
|
21
|
+
- periods = registrar.periods(from: f.object.joined_on)
|
22
|
+
- collection = periods.reverse.map { |period| [registrar.period_end_on(date: period), period] }
|
23
|
+
|
24
|
+
= f.select :change_fees_paid_period, collection, label: 'Fees Paid Through', hint: 'Which period this user has fees paid through. Can change how renewal fees are created.'
|
25
|
+
|
20
26
|
%p.text-muted To update the current membership categories, use the 'Assign' or 'Reclassify' actions below
|
21
27
|
|
22
28
|
= f.submit 'Update Membership', border: false, center: true, 'data-confirm': "Really update #{f.object.owner}?"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_memberships
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|