From ac3a2c095ec2df04113ec6d36583629745d34c16 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 24 Sep 2014 17:07:18 +0200 Subject: [PATCH] Bug 12987: Update table footer with the visible rows This patch is the preparation step for others. On acqui/acqui-home.pl and admin/aqbudgets.pl, it will be possible to see the totals in the footer updated with the filtered rows. Test plan: This cannot be tested alone, you have to apply it with others (see the "Blocked" bug reports). --- .../prog/en/includes/format_price.inc | 27 +++++++++++ koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 32 +++++++++++++ .../prog/en/modules/acqui/acqui-home.tt | 53 ++++++++++++++++------ .../prog/en/modules/admin/aqbudgets.tt | 31 ++++++++----- 4 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc new file mode 100644 index 0000000..b0e5a8d --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc @@ -0,0 +1,27 @@ +[% USE Koha %] + diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index 49ccb74..838f27e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -607,3 +607,35 @@ function parse_callnumber ( html ) { return ""; } } + +// see http://www.datatables.net/examples/advanced_init/footer_callback.html +function footer_column_sum( api, column_numbers ) { + // Remove the formatting to get integer data for summation + var intVal = function ( i ) { + if ( typeof i === 'number' ) { + if ( isNaN(i) ) return 0; + return i; + } else if ( typeof i === 'string' ) { + var value = i.replace(/[a-zA-Z ,.]/g, '')*1; + if ( isNaN(value) ) return 0; + return value; + } + return 0; + }; + + + for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) { + var column_number = column_numbers[indice]; + + var total = 0; + var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount"); + $(cells).each(function(){ + total += intVal( $(this).html() ); + }); + total /= 100; // Hard-coded decimal precision + + // Update footer + $( api.column( column_number ).footer() ).html(total.format_price()); + }; +} + 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 6c3b3eb..08b6f89 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 @@ -13,11 +13,6 @@ dt_overwrite_html_sorting_localeCompare(); $(document).ready(function() { - var inactive = $(".b_inactive,.bu_active"); - var active = $(".bu_inactive"); - inactive.hide(); - active.show(); - var oTable = $("#accounts").dataTable($.extend(true, {}, dataTablesDefaults, { "fnDrawCallback": function ( oSettings ) { if ( oSettings.aiDisplay.length == 0 ) @@ -45,6 +40,10 @@ $(document).ready(function() { } } }, + "footerCallback": function ( row, data, start, end, display ) { + var api = this.api(), data; + footer_column_sum( api, [ 6, 7, 8, 9 ] ); + }, "aoColumnDefs": [ { "bVisible": false, "aTargets": [ 0, 1 ] }, { "bSortable": false, "aTargets": ["_all"] } @@ -168,10 +167,10 @@ $(document).ready(function() { Total - [% total %][% total_active %] - [% totordered %][% totordered_active %] - [% totspent %][% totspent_active %] - [% totavail %][% totavail_active %] + + + + @@ -199,10 +198,38 @@ $(document).ready(function() { [% END %] [% loop_budge.budget_branchname %] - [% loop_budge.formatted_budget_amount %] - [% loop_budge.formatted_budget_ordered %] - [% loop_budge.formatted_budget_spent %] - [% loop_budge.formatted_budget_avail %] + + [% IF loop_budge.budget_parent_id %] + [% loop_budge.formatted_budget_amount %] + [% ELSE %] + [% loop_budge.formatted_budget_amount %] + [% END %] + + + + [% IF loop_budge.budget_parent_id %] + [% loop_budge.formatted_budget_ordered %] + [% ELSE %] + [% loop_budge.formatted_budget_ordered %] + [% END %] + + + + + [% IF loop_budge.budget_parent_id %] + [% loop_budge.formatted_budget_spent %] + [% ELSE %] + [% loop_budge.formatted_budget_spent %] + [% END %] + + + + [% IF loop_budge.budget_parent_id %] + [% loop_budge.formatted_budget_avail %] + [% ELSE %] + [% loop_budge.formatted_budget_avail %] + [% END %] + [% 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 b0c4344..50566a0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -152,6 +152,8 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") // Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %] - [% period_alloc_total %] + - [% ordered_total %] + - [% spent_total %] + - [% available_total %] + @@ -320,35 +327,35 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% IF budget.budget_parent_id %] [% budget.budget_amount %] [% ELSE %] - [% budget.budget_amount %] + [% budget.budget_amount %] [% END %] [% IF budget.budget_parent_id %] [% budget.budget_ordered %] [% ELSE %] - [% budget.budget_ordered %] + [% budget.budget_ordered %] [% END %] [% IF budget.budget_parent_id %] [% budget.total_ordered %] [% ELSE %] - [% budget.total_ordered %] + [% budget.total_ordered %] [% END %] [% IF budget.budget_parent_id %] [% budget.budget_spent %] [% ELSE %] - [% budget.budget_spent %] + [% budget.budget_spent %] [% END %] [% IF budget.budget_parent_id %] [% budget.total_spent %] [% ELSE %] - [% budget.total_spent %] + [% budget.total_spent %] [% END %] @@ -364,11 +371,11 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") [% END %] [% ELSE %] [% IF (value > 0) %] - + [% ELSIF (value < 0) %] - + [% ELSE %] - + [% END %] [% END %] [% text %] -- 2.1.0