From c2854ad51dc80b2d92da6befdbab978cf1687d6e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 23 Jan 2023 23:07:52 +0100 Subject: [PATCH] Bug 32705: Display invoice price On bug 25655 we are storing the unit price and currency used for invoicing. Here we are displaying them on the invoice page. Test plan: Reuse the test plan from 25655 and go to the invoice page Notice that a new 'Invoice price' column is displayed if at least one order of the invoice had a price given in a foreign currency We could discuss the display of the prices here, I've decided to format them but they are not accurate to the currency. We cannot do better for now as we are not storing the format along with the currency. Sponsored-by: The Research University in the Helmholtz Association (KIT) --- Koha/Number/Price.pm | 7 ++++++- acqui/invoice.pl | 3 +++ .../prog/en/modules/acqui/invoice.tt | 19 +++++++++++++++++++ t/Number/Price.t | 15 ++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index e9a6aa748e3..1e0f9e80c4a 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -95,7 +95,12 @@ sub _format_params { my ( $self, $params ) = @_; my $with_symbol = $params->{with_symbol} || 0; my $p_cs_precedes = $params->{p_cs_precedes}; - my $currency = Koha::Acquisition::Currencies->get_active; + + my $currency = + $params->{currency} + ? Koha::Acquisition::Currencies->find( $params->{currency} ) + : Koha::Acquisition::Currencies->get_active; + my $currency_format = C4::Context->preference("CurrencyFormat"); my $int_curr_symbol = ( $with_symbol and $currency ) ? $currency->symbol : q||; diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 0e21a20c117..5f5a9345e3e 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -262,6 +262,7 @@ my $total_quantity = 0; my $total_tax_excluded = 0; my $total_tax_included = 0; my $total_tax_value = 0; +my $has_invoice_unitprice; foreach my $order (@$orders) { my $line = get_infos( $order, $bookseller); @@ -282,6 +283,7 @@ foreach my $order (@$orders) { $total_tax_included += get_rounded_price($$line{total_tax_included}); $line->{orderline} = $line->{parent_ordernumber}; + $has_invoice_unitprice = 1 if defined $line->{invoice_unitprice}; push @orders_loop, $line; } @@ -344,6 +346,7 @@ $template->param( currency => Koha::Acquisition::Currencies->get_active, budgets => $budget_loop, budget => GetBudget( $shipmentcost_budgetid ), + has_invoice_unitprice => $has_invoice_unitprice, ); defined( $invoice_files ) && $template->param( files => $invoice_files->GetFilesInfo() ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt index 534f07d4f26..fcf1203eedb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -355,6 +355,9 @@ Summary Library + [% IF has_invoice_unitprice %] + Invoice price + [% END %] Actual cost tax exc. Actual cost tax inc. Replacement price @@ -386,6 +389,13 @@ [% END %]

[% order.branchcode | html %]

+ [% IF has_invoice_unitprice %] + + [% IF order.invoice_unitprice %] + [% order.invoice_unitprice | $Price with_symbol => 1, currency => order.invoice_currency %] [% order.invoice_currency %] + [% END %] + + [% END %] [% order.unitprice_tax_excluded | $Price %] [% order.unitprice_tax_included | $Price %] [% order.replacementprice | $Price %] [% IF ( order.uncertainprice ) %] (Uncertain) [% END %] @@ -405,6 +415,9 @@ [% FOR tf IN foot_loop %] Total (GST [% tf.tax_rate * 100 | html %] %) + [% IF has_invoice_unitprice %] + + [% END %] @@ -418,6 +431,9 @@ [% END %] Total ([% currency.symbol | html %]) + [% IF has_invoice_unitprice %] + + [% END %] @@ -430,6 +446,9 @@ Total + adjustments + shipment cost ([% currency.symbol | html %]) + [% IF has_invoice_unitprice %] + + [% END %] diff --git a/t/Number/Price.t b/t/Number/Price.t index ce607a83a12..40d83b0ff21 100755 --- a/t/Number/Price.t +++ b/t/Number/Price.t @@ -1,6 +1,6 @@ use Modern::Perl; -use Test::More tests => 35; +use Test::More tests => 37; use Test::MockModule; use t::lib::Mocks; @@ -105,6 +105,19 @@ is( Koha::Number::Price->new(3)->unformat, '3', 'FR: unformat 3' ); is( Koha::Number::Price->new(1234567890)->unformat, '1234567890', 'FR: unformat 1234567890' ); +# FIXME This is not ideal, we would like to have the format options at currency level +is( + Koha::Number::Price->new(42)->format( { %$format, with_symbol => 1 } ), + '€42,00', + 'The default currency is picked if none passed' +); +is( + Koha::Number::Price->new(42) + ->format( { %$format, with_symbol => 1, currency => 'USD' } ), + '$42,00', + 'The specified currency is used' +); + # Price formatting for Switzerland: 1'234'567.89 t::lib::Mocks::mock_preference( 'CurrencyFormat', 'CH' ); $currency = Koha::Acquisition::Currency->new({ -- 2.25.1