|
|
|
@ -22,6 +22,7 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
has_paper_trail |
|
|
|
|
|
|
|
|
|
validates_with CaseLogValidator |
|
|
|
|
before_validation :recalculate_start_year!, if: :startdate_changed? |
|
|
|
|
before_validation :process_postcode_changes!, if: :postcode_full_changed? |
|
|
|
|
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? |
|
|
|
|
before_validation :reset_invalidated_dependent_fields! |
|
|
|
@ -66,10 +67,16 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def collection_start_year |
|
|
|
|
return @start_year if @start_year |
|
|
|
|
return unless startdate |
|
|
|
|
|
|
|
|
|
window_end_date = Time.zone.local(startdate.year, 4, 1) |
|
|
|
|
startdate < window_end_date ? startdate.year - 1 : startdate.year |
|
|
|
|
@start_year = startdate < window_end_date ? startdate.year - 1 : startdate.year |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def recalculate_start_year! |
|
|
|
|
@start_year = nil |
|
|
|
|
collection_start_year |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def form_name |
|
|
|
|