From a53c352ab7b535fe82817e272f4b2684d2eb1f08 Mon Sep 17 00:00:00 2001 From: Didier Gautheron Date: Fri, 11 Dec 2020 10:46:04 +0100 Subject: [PATCH] Bug 22038: Fix excel export if CurrencyFormat is FR DataTables excel export is broken if number decimal separator is a comma. Test plan: 1 - Set syspref CurrencyFormat to US 2 - Export as excel a table with decimal numbers, patrons list with fines for example. 3 - Open in libreoffice or excel, numbers are ok. 4 - Set syspref CurrencyFormat to FR 5 - Export and open again, number are wrong 25,10 is imported as 2510 6 - Apply patch 7 - Redo 1 to 4 8 - Excel export, number is 25,10 Signed-off-by: hakam Signed-off-by: Florian Bontemps Signed-off-by: Tomas Cohen Arazi --- .../prog/en/includes/columns_settings.inc | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc index 0e21d84011..7cbfa976a0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/columns_settings.inc @@ -1,3 +1,4 @@ +[% USE Koha %] [% USE TablesSettings %] @@ -41,15 +42,21 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { } } + var export_numeric = { + body: function ( data, row, column, node ) { + var newnode = $(node); + + if ( newnode.find(".noExport").length > 0 ) { + newnode = newnode.clone(); + newnode.find(".noExport").remove(); + } + let tp = newnode.text().replace( /\n/g, ' ' ).trim(); + tp = $('

' + tp + '

').text(); + return $.isNumeric(tp.replace(',', '.')) ? tp.replace(',', '.') : tp; + } + } + var export_buttons = [ - { - extend: 'excelHtml5', - text: _("Excel"), - exportOptions: { - columns: exportColumns, - format: export_format - }, - }, { extend: 'csvHtml5', text: _("CSV"), @@ -76,6 +83,30 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) { } ]; + [% IF Koha.Preference("CurrencyFormat") != 'FR' %] + export_buttons.unshift ( + { + extend: 'excelHtml5', + text: _("Excel"), + exportOptions: { + columns: exportColumns, + format: export_format + }, + } + ); + [% ELSE %] + export_buttons.unshift ( + { + extend: 'excelHtml5', + text: _("Excel"), + exportOptions: { + columns: exportColumns, + format: export_numeric + }, + } + ); + [% END %] + dt_parameters[ "buttons" ] = [ { fade: 100, -- 2.35.1