From 1782e96cb989d429866abf91575014952bd35f2e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 3 Feb 2021 14:48:37 +0000 Subject: [PATCH] Bug 23767: Total children only if parents not visible This patch changes the way to calculate the footer. It adds the budget and parent ids to the cell as custom data elements. When totaling we grab a list of all the rows we are showing - if a row has a parent and the parent is showing then we skip adding its value to the total. As the function is used on both acqui-home and aqbudgets I adjusted both templates To test: 1 - Follow the test plan on previous patch 2 - Try filtering the table so you see only the child funds 3 - Confirm the totals show the child alone when it is visible 4 - Confirm the child total is excluded when the parent is visible Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Martin Renvoize --- .../prog/en/modules/acqui/acqui-home.tt | 12 ++------ .../prog/en/modules/admin/aqbudgets.tt | 30 +++++-------------- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 9 +++++- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt index af67b5abac..3f9d38c9ba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt @@ -145,11 +145,7 @@ [% Branches.GetName( loop_budge.budget_branchcode ) | html %] - [% IF loop_budge.budget_parent_id %] - [% loop_budge.budget_amount | $Price %] - [% ELSE %] - [% loop_budge.budget_amount | $Price %] - [% END %] + [% loop_budge.budget_amount | $Price %] @@ -162,11 +158,7 @@ - [% IF loop_budge.budget_parent_id %] - [% loop_budge.budget_avail | $Price %] - [% ELSE %] - [% loop_budge.budget_avail | $Price %] - [% END %] + [% loop_budge.budget_avail | $Price %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index eea28784ea..9b7487a691 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -103,11 +103,7 @@ [% budget.budget_code | html %] [% budget.budget_name | html %] - [% IF budget.budget_parent_id %] - [% budget.budget_amount | $Price %] - [% ELSE %] - [% budget.budget_amount | $Price %] - [% END %] + [% budget.budget_amount | $Price %] [% IF budget.budget_parent_id %] @@ -140,24 +136,14 @@ [% BLOCK colorcellvalue %] - [% IF parent %] - [% IF (value > 0) %] - - [% ELSIF (value < 0) %] - - [% ELSE %] - - [% END %] - [% ELSE %] - [% IF (value > 0) %] - - [% ELSIF (value < 0) %] - - [% ELSE %] - - [% END %] + [% IF (value > 0) %] + + [% ELSIF (value < 0) %] + + [% ELSE %] + [% END %] - [% value | $Price %] + [% value | $Price %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 8b6d18d85e..da01ac8ba0 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -486,8 +486,15 @@ function footer_column_sum( api, column_numbers ) { var total = 0; var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount"); + var budgets_totaled = []; + $(cells).each(function(){ budgets_totaled.push( $(this).data('self_id') ); }); $(cells).each(function(){ - total += intVal( $(this).html() ); + if( $(this).data('parent_id') && $.inArray( $(this).data('parent_id'), budgets_totaled) > -1 ){ + return; + } else { + total += intVal( $(this).html() ); + } + }); total /= 100; // Hard-coded decimal precision -- 2.20.1