Last active
September 18, 2019 18:45
-
-
Save gregblass/4d5db346219aae408e256a79b66f18dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flag the task if its service hits a service frequency guideline limit | |
def self.service_hits_frequency_guideline_limit(task) | |
service = task.service | |
if service.has_frequency_guidelines? | |
frequency = service.frequency | |
customer_jobs = @old_job.customer.jobs.completed | |
year = @old_job.year | |
count = 1 | |
if service.x_years_in_a_row? | |
while count <= frequency | |
if customer_jobs.by_year(year - count).joins(tasks: :invoice_item). | |
where(tasks: { service: service }).any? # => Test that this works (tasks: :invoice_item) instead of invoiced: true | |
count += 1 | |
else | |
return false | |
end | |
end | |
@flags[:cancelled_frequency] = true | |
return true | |
elsif service.every_x_years? | |
while count < frequency | |
if customer_jobs.by_year(year - count).joins(tasks: :invoice_item). # => Test that this works (tasks: :invoice_item) | |
where(tasks: { service: service }).any? | |
@flags[:cancelled_frequency] = true | |
return true | |
else | |
count += 1 | |
end | |
end | |
return false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment