From b09b77e70117858f8344b915ef3a03e4ee93b2a6 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 28 Dec 2018 09:00:55 +0100 Subject: [PATCH] don't count clients and providers deleted the year they were created. #166 --- app/models/client.rb | 7 +++++-- app/models/provider.rb | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/client.rb b/app/models/client.rb index 8334462af..469807ddd 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -237,9 +237,12 @@ def year created_at.year if created_at.present? end + # count years account has been active. Ignore if deleted the same year as created def cumulative_years - if deleted_at - (created_at.year..[created_at.year, deleted_at.year - 1].max).to_a + if deleted_at && deleted_at.year > created_at.year + (created_at.year..deleted_at.year).to_a + elsif deleted_at + [] else (created_at.year..Date.today.year).to_a end diff --git a/app/models/provider.rb b/app/models/provider.rb index db1a18a0b..9d295b03d 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -160,9 +160,12 @@ def year joined.year if joined.present? end + # count years account has been active. Ignore if deleted the same year as created def cumulative_years - if deleted_at - (created_at.year..[created_at.year, deleted_at.year - 1].max).to_a + if deleted_at && deleted_at.year > created_at.year + (created_at.year..deleted_at.year).to_a + elsif deleted_at + [] else (created_at.year..Date.today.year).to_a end