From 3cbd3d76e094e1c8160c684922517431bcf10370 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 30 Jun 2020 15:33:23 -0400 Subject: [PATCH] LP#1885759: Count months and quarters across year boundaries We need to add year-multiples of months or quarters when using the months_ago or quarters_ago transforms in the reporter. Signed-off-by: Mike Rylander Signed-off-by: Rogan Hamby Signed-off-by: Galen Charlton --- Open-ILS/src/perlmods/lib/OpenILS/Reporter/SQLBuilder.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Reporter/SQLBuilder.pm b/Open-ILS/src/perlmods/lib/OpenILS/Reporter/SQLBuilder.pm index 0117d98bad..69eab42c24 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Reporter/SQLBuilder.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Reporter/SQLBuilder.pm @@ -740,7 +740,8 @@ package OpenILS::Reporter::SQLBuilder::Column::Transform::months_ago; sub toSQL { my $self = shift; - return 'EXTRACT(MONTH FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '"))'; + return '(EXTRACT(YEAR FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '")) * 12) +'. + ' EXTRACT(MONTH FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '"))'; } sub is_aggregate { return 0 } @@ -762,7 +763,8 @@ package OpenILS::Reporter::SQLBuilder::Column::Transform::quarters_ago; sub toSQL { my $self = shift; - return 'EXTRACT(QUARTER FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '"))'; + return '(EXTRACT(YEAR FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '")) * 4) +'. + ' EXTRACT(QUARTER FROM AGE(NOW(),"' . $self->{_relation} . '"."' . $self->name . '"))'; } sub is_aggregate { return 0 } -- 2.11.0