Skip to content

Commit 1a918f5

Browse files
committed
Add last_representative_date column, invoice event dropdown use current year helper
1 parent 2cd92fd commit 1a918f5

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

app/models/event.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Event < ActiveRecord::Base
2121
attr_accessor :org_type, :org_new, :created_email
2222

2323
before_validation :prune_attachments, :prune_roles
24-
before_save :handle_organization, :ensure_tic, :sort_roles, :synchronize_representative_date
24+
before_save :handle_organization, :ensure_tic, :sort_roles, :synchronize_representative_dates
2525
after_initialize :default_values
2626
after_save :set_eventdate_delta_flags, :set_created_email
2727

@@ -71,7 +71,7 @@ class Event < ActiveRecord::Base
7171
# validate :eventdate_valid?
7272
validate :textable_social_valid?
7373

74-
scope :current_year, -> { where("representative_date >= ?", Account.magic_date) }
74+
scope :current_year, -> { where("representative_date >= ? or last_representative_date > ?", Account.magic_date, Account.magic_date) }
7575

7676
ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :deltas]) # associated via eventdate
7777

@@ -117,8 +117,9 @@ def tic_and_stic_only
117117
event_roles.where(role: [EventRole::Role_sTiC, EventRole::Role_TiC]).where.not(member: nil).all.map(&:member)
118118
end
119119

120-
def synchronize_representative_date
120+
def synchronize_representative_dates
121121
self.representative_date = self.eventdates[0].startdate
122+
self.last_representative_date = eventdates.last.enddate
122123
end
123124

124125
def has_run_position?(member)
@@ -157,7 +158,7 @@ def current_year?
157158
# a part of both years (i.e. Precollege). Otherwise Tracker does not allow
158159
# certain functions (like invoicing) for the now previous year's event. So,
159160
# we considered an event by start and end.
160-
(representative_date >= Account.magic_date) or (self.eventdates.last.enddate > Account.magic_date)
161+
(representative_date >= Account.magic_date) or (self.last_representative_date > Account.magic_date)
161162
end
162163

163164
private

app/models/eventdate.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Eventdate < ApplicationRecord
1616
validate :dates, :validate_call, :validate_strike
1717

1818
before_validation :prune_roles
19-
after_save :synchronize_representative_date
19+
after_save :synchronize_representative_dates
2020

2121
Event_Span_Days = 2;
2222
Event_Span_Seconds = Event_Span_Days * 24 * 60 * 60;
@@ -110,8 +110,8 @@ def total_gross
110110
timecard_entries.map(&:gross_amount).reduce(0.0, &:+)
111111
end
112112

113-
def synchronize_representative_date
114-
self.event.synchronize_representative_date
113+
def synchronize_representative_dates
114+
self.event.synchronize_representative_dates
115115
end
116116

117117
def full_roles

app/views/invoices/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<tr>
2020
<td class="subheading"><%= f.label :event_id, "Event" %>:</td>
21-
<% if not f.object.event.nil? and f.object.event.representative_date < Account.magic_date %>
21+
<% if not f.object.event.nil? and not f.object.event.current_year? %>
2222
<td><%= f.object.event.title %></td>
2323
<% else %>
2424
<td><%= f.select :event_id, options_from_collection_for_select(Event.current_year.order("title ASC"), "id", "title", f.object.event_id) %></td>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class AddLastRepresentativeDateToEvents < ActiveRecord::Migration[6.1]
2+
def up
3+
add_column :events, :last_representative_date, :datetime
4+
add_index :events, :last_representative_date
5+
Event.all.each do |event|
6+
event.save
7+
end
8+
end
9+
def down
10+
remove_index :events, name: "index_events_on_last_representative_date"
11+
remove_column :events, :last_representative_date
12+
end
13+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)