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 <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2021-02-03 14:48:37 +00:00 committed by Jonathan Druart
parent 07150a0a85
commit 1f3152d453
3 changed files with 18 additions and 33 deletions

View File

@ -145,11 +145,7 @@
</td>
<td>[% Branches.GetName( loop_budge.budget_branchcode ) | html %]</td>
<td class="data">
[% IF loop_budge.budget_parent_id %]
[% loop_budge.budget_amount | $Price %]
[% ELSE %]
<span class="total_amount">[% loop_budge.budget_amount | $Price %]</span>
[% END %]
<span class="total_amount" data-parent_id="[% loop_budge.budget_parent_id | html %]" data-self_id="[% loop_budge.budget_id | html %]">[% loop_budge.budget_amount | $Price %]</span>
</td>
<td class="data">
<a href="ordered.pl?fund=[% loop_budge.budget_id | uri %]&amp;fund_code=[% loop_budge.budget_code | uri %]">
@ -162,11 +158,7 @@
</a>
</td>
<td class="data">
[% IF loop_budge.budget_parent_id %]
[% loop_budge.budget_avail | $Price %]
[% ELSE %]
<span class="total_amount">[% loop_budge.budget_avail | $Price %]</span>
[% END %]
<span class="total_amount" data-parent_id="[% loop_budge.budget_parent_id | html %]" data-self_id="[% loop_budge.budget_id | html %]">[% loop_budge.budget_avail | $Price %]</span>
</td>
</tr>
[% END %]

View File

@ -103,11 +103,7 @@
<td>[% budget.budget_code | html %]</td>
<td>[% budget.budget_name | html %]</td>
<td class="data">
[% IF budget.budget_parent_id %]
<span class="child_fund_amount">[% budget.budget_amount | $Price %]</span>
[% ELSE %]
<span class="total_amount">[% budget.budget_amount | $Price %]</span>
[% END %]
<span class="total_amount" data-parent_id="[% budget.budget_parent_id | html %]" data-self_id="[% budget.budget_id | html %]">[% budget.budget_amount | $Price %]</span>
</td>
<td class="data">
[% IF budget.budget_parent_id %]
@ -140,24 +136,14 @@
[% BLOCK colorcellvalue %]
[% IF parent %]
[% IF (value > 0) %]
<span class="child_fund_amount" style="color: green;">
[% ELSIF (value < 0) %]
<span class="child_fund_amount" style="color: red;">
[% ELSE %]
<span class="child_fund_amount">
[% END %]
[% ELSE %]
[% IF (value > 0) %]
<span class="total_amount" style="color: green;">
[% ELSIF (value < 0) %]
<span class="total_amount" style="color: red;">
[% ELSE %]
<span class="totalamount">
[% END %]
[% IF (value > 0) %]
<span class="total_amount" data-parent_id="[% budget.budget_parent_id | html %]" data-self_id="[% budget.budget_id | html %]" style="color: green;">
[% ELSIF (value < 0) %]
<span class="total_amount" style="color: red;">
[% ELSE %]
<span class="totalamount">
[% END %]
[% value | $Price %]
[% value | $Price %]
</span>
[% END %]
<td class="data">

View File

@ -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