From e365ab856b73ef541262bcb2b9ddae60255e973a Mon Sep 17 00:00:00 2001
From: Jonathan Druart
Date: Fri, 19 Jul 2013 12:50:03 +0200
Subject: [PATCH] Bug 9410: Draft: TT Plugin for formatting prices, etc.
---
Koha/Prices.pm | 8 ++++
acqui/basket.pl | 44 ++++++++++----------
acqui/basketgroup.pl | 36 ++++++++--------
acqui/neworderempty.pl | 10 ++---
.../intranet-tmpl/prog/en/modules/acqui/basket.tt | 35 ++++++++--------
.../prog/en/modules/acqui/neworderempty.tt | 33 ++++++++-------
6 files changed, 87 insertions(+), 79 deletions(-)
create mode 100644 Koha/Prices.pm
diff --git a/Koha/Prices.pm b/Koha/Prices.pm
new file mode 100644
index 0000000..654dd98
--- /dev/null
+++ b/Koha/Prices.pm
@@ -0,0 +1,8 @@
+package Koha::Prices;
+
+use Modern::Perl;
+
+sub format {
+ my ( $value ) = @_;
+ return sprintf( "%.2f", $value ); # Should be in a syspref
+}
diff --git a/acqui/basket.pl b/acqui/basket.pl
index 06d4d1a..5f8a408 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -306,7 +306,7 @@ if ( $op eq 'delete_confirm' ) {
my @cancelledorders = GetCancelledOrders($basketno);
foreach (@cancelledorders) {
- $_->{'line_total'} = sprintf("%.2f", $_->{'ecost'} * $_->{'quantity'});
+ $_->{'line_total'} = $_->{'ecost'} * $_->{'quantity'};
}
$template->param(
@@ -330,9 +330,9 @@ if ( $op eq 'delete_confirm' ) {
book_foot_loop => \@book_foot_loop,
cancelledorders_loop => \@cancelledorders,
total_quantity => $total_quantity,
- total_gste => sprintf( "%.2f", $total_gste ),
- total_gsti => sprintf( "%.2f", $total_gsti ),
- total_gstvalue => sprintf( "%.2f", $total_gstvalue ),
+ total_gste => $total_gste,
+ total_gsti => $total_gsti,
+ total_gstvalue => $total_gstvalue,
currency => $cur->{'currency'},
listincgst => $bookseller->{listincgst},
basketgroups => $basketgroups,
@@ -358,25 +358,25 @@ sub get_order_infos {
$line{budget_name} = $budget->{budget_name};
$line{rrp} = ConvertCurrency( $order->{'currency'}, $line{rrp} ); # FIXME from comm
if ( $bookseller->{'listincgst'} ) {
- $line{rrpgsti} = sprintf( "%.2f", $line{rrp} );
- $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{rrpgste} = sprintf( "%.2f", $line{rrp} / ( 1 + ( $line{gstgsti} / 100 ) ) );
- $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
- $line{ecostgsti} = sprintf( "%.2f", $line{ecost} );
- $line{ecostgste} = sprintf( "%.2f", $line{ecost} / ( 1 + ( $line{gstgsti} / 100 ) ) );
- $line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity});
- $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} );
- $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} );
+ $line{rrpgsti} = $line{rrp};
+ $line{gstgsti} = $line{gstrate} * 100;
+ $line{rrpgste} = $line{rrp} / ( 1 + ( $line{gstgsti} / 100 ) );
+ $line{gstgste} = $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) );
+ $line{ecostgsti} = $line{ecost};
+ $line{ecostgste} = $line{ecost} / ( 1 + ( $line{gstgsti} / 100 ) );
+ $line{gstvalue} = ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity};
+ $line{totalgste} = $order->{quantity} * $line{ecostgste};
+ $line{totalgsti} = $order->{quantity} * $line{ecostgsti};
} else {
- $line{rrpgsti} = sprintf( "%.2f", $line{rrp} * ( 1 + ( $line{gstrate} ) ) );
- $line{rrpgste} = sprintf( "%.2f", $line{rrp} );
- $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
- $line{ecostgsti} = sprintf( "%.2f", $line{ecost} * ( 1 + ( $line{gstrate} ) ) );
- $line{ecostgste} = sprintf( "%.2f", $line{ecost} );
- $line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity});
- $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} );
- $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} );
+ $line{rrpgsti} = $line{rrp} * ( 1 + ( $line{gstrate} ) );
+ $line{rrpgste} = $line{rrp};
+ $line{gstgsti} = $line{gstrate} * 100;
+ $line{gstgste} = $line{gstrate} * 100;
+ $line{ecostgsti} = $line{ecost} * ( 1 + ( $line{gstrate} ) );
+ $line{ecostgste} = $line{ecost};
+ $line{gstvalue} = ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity};
+ $line{totalgste} = $order->{quantity} * $line{ecostgste};
+ $line{totalgsti} = $order->{quantity} * $line{ecostgsti};
}
if ( $line{uncertainprice} ) {
diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl
index 398980c..79ca9a0 100755
--- a/acqui/basketgroup.pl
+++ b/acqui/basketgroup.pl
@@ -233,25 +233,25 @@ sub printbasketgrouppdf{
$ord->{rrp} = ConvertCurrency( $ord->{'currency'}, $ord->{rrp} );
if ( $bookseller->{'listincgst'} ) {
- $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} );
- $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 );
- $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
- $ord->{gstgste} = sprintf( "%.2f", $ord->{gstgsti} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
- $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} );
- $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
- $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
- $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} );
- $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} );
+ $ord->{rrpgsti} = Koha::Prices::format( $ord->{rrp} );
+ $ord->{gstgsti} = Koha::Prices::format( $ord->{gstrate} * 100 );
+ $ord->{rrpgste} = Koha::Prices::format( $ord->{rrp} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
+ $ord->{gstgste} = Koha::Prices::format( $ord->{gstgsti} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
+ $ord->{ecostgsti} = Koha::Prices::format( $ord->{ecost} );
+ $ord->{ecostgste} = Koha::Prices::format( $ord->{ecost} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
+ $ord->{gstvalue} = Koha::Prices::format( ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
+ $ord->{totalgste} = Koha::Prices::format( $ord->{quantity} * $ord->{ecostgste} );
+ $ord->{totalgsti} = Koha::Prices::format( $ord->{quantity} * $ord->{ecostgsti} );
} else {
- $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} * ( 1 + ( $ord->{gstrate} ) ) );
- $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} );
- $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 );
- $ord->{gstgste} = sprintf( "%.2f", $ord->{gstrate} * 100 );
- $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} * ( 1 + ( $ord->{gstrate} ) ) );
- $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} );
- $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
- $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} );
- $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} );
+ $ord->{rrpgsti} = Koha::Prices::format( $ord->{rrp} * ( 1 + ( $ord->{gstrate} ) ) );
+ $ord->{rrpgste} = Koha::Prices::format( $ord->{rrp} );
+ $ord->{gstgsti} = Koha::Prices::format( $ord->{gstrate} * 100 );
+ $ord->{gstgste} = Koha::Prices::format( $ord->{gstrate} * 100 );
+ $ord->{ecostgsti} = Koha::Prices::format( $ord->{ecost} * ( 1 + ( $ord->{gstrate} ) ) );
+ $ord->{ecostgste} = Koha::Prices::format( $ord->{ecost} );
+ $ord->{gstvalue} = Koha::Prices::format( ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
+ $ord->{totalgste} = Koha::Prices::format( $ord->{quantity} * $ord->{ecostgste} );
+ $ord->{totalgsti} = Koha::Prices::format( $ord->{quantity} * $ord->{ecostgsti} );
}
my $bib = GetBiblioData($ord->{biblionumber});
my $itemtypes = GetItemTypes();
diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl
index 9c9eed3..2fc529b 100755
--- a/acqui/neworderempty.pl
+++ b/acqui/neworderempty.pl
@@ -379,9 +379,7 @@ $template->param(
biblionumber => $biblionumber,
uncertainprice => $data->{'uncertainprice'},
authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'},
- discount_2dp => sprintf( "%.2f", $bookseller->{'discount'} ) , # for display
discount => $bookseller->{'discount'},
- orderdiscount_2dp => sprintf( "%.2f", $data->{'discount'} || 0 ),
orderdiscount => $data->{'discount'},
listincgst => $bookseller->{'listincgst'},
invoiceincgst => $bookseller->{'invoiceincgst'},
@@ -405,10 +403,10 @@ $template->param(
gst_values => \@gst_values,
gstrate => $data->{gstrate} ? $data->{gstrate}+0.0 : $bookseller->{gstrate} ? $bookseller->{gstrate}+0.0 : 0,
gstreg => $bookseller->{'gstreg'},
- listprice => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice),
- total => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ),
- ecost => sprintf( "%.2f", $data->{ecost} || 0),
- unitprice => sprintf( "%.2f", $data->{unitprice} || 0),
+ listprice => $data->{listprice} || $data->{price} || $listprice,
+ total => ($data->{ecost} || 0) * ($data->{'quantity'} || 0),
+ ecost => $data->{ecost} || 0,
+ unitprice => $data->{unitprice} || 0,
publishercode => $data->{'publishercode'},
barcode_subfield => $barcode_subfield,
import_batch_id => $import_batch_id,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
index 84df886..60d69fb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -1,4 +1,5 @@
[% USE KohaDates %]
+[% USE FormatNum %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Acquisitions › [% UNLESS ( basketno ) %]New [% END %][% IF ( delete_confirm ) %]Delete [% END %]Basket [% basketname|html %] ([% basketno %]) for [% name|html %]
@@ -346,15 +347,15 @@
[Add note]
[% END %]
- [% books_loo.rrpgste %] |
- [% books_loo.ecostgste %] |
- [% books_loo.rrpgsti %] |
- [% books_loo.ecostgsti %] |
- [% books_loo.quantity %] |
- [% books_loo.totalgste %] |
- [% books_loo.totalgsti %] |
- [% books_loo.gstgsti %] |
- [% books_loo.gstvalue %] |
+ [% FormatNum.Price( books_loo.rrpgste ) %] |
+ [% FormatNum.Price( bbooks_loo.ecostgste ) %] |
+ [% FormatNum.Price( bbooks_loo.rrpgsti ) %] |
+ [% FormatNum.Price( bbooks_loo.ecostgsti ) %] |
+ [% bbooks_loo.quantity%] |
+ [% FormatNum.Price( bbooks_loo.totalgste ) %] |
+ [% FormatNum.Price( bbooks_loo.totalgsti ) %] |
+ [% FormatNum.Price( bbooks_loo.gstgsti ) %] |
+ [% FormatNum.Price( bbooks_loo.gstvalue ) %] |
[% books_loo.budget_name %] |
[% IF ( active ) %]
[% UNLESS ( closedate ) %]
@@ -433,15 +434,15 @@
[% IF ( books_loo.editionstatement ) %], [% books_loo.editionstatement %][% END %]
- [% order.rrpgste %] |
- [% order.ecostgste %] |
- [% order.rrpgsti %] |
- [% order.ecostgsti %] |
+ [% FormatNum.Price( border.rrpgste ) %] |
+ [% FormatNum.Price( border.ecostgste ) %] |
+ [% FormatNum.Price( border.rrpgsti ) %] |
+ [% FormatNum.Price( border.ecostgsti ) %] |
[% order.quantity %] |
- [% order.totalgste %] |
- [% order.totalgsti %] |
- [% order.gstgsti %] |
- [% order.gstvalue %] |
+ [% FormatNum.Price( border.totalgste ) %] |
+ [% FormatNum.Price( border.totalgsti ) %] |
+ [% FormatNum.Price( border.gstgsti ) %] |
+ [% FormatNum.Price( border.gstvalue ) %] |
[% order.budget_name %]
[% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
index bbcd4e8..c45f5a0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt
@@ -1,4 +1,5 @@
[% USE KohaDates %]
+[% USE FormatNum %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Acquisitions › Basket [% basketno %] › [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %]
[% INCLUDE 'doc-head-close.inc' %]
@@ -450,10 +451,10 @@ $(document).ready(function()
[% IF ( close ) %]
Vendor price:
- [% listprice %]
+ [% FormatNum.Price( listprice ) %]
[% ELSE %]
-
+
[% END %]
[% UNLESS ( close ) %]
@@ -476,9 +477,9 @@ $(document).ready(function()
@@ -491,52 +492,52 @@ $(document).ready(function()
[% IF ( close ) %]
[% IF ( orderdiscount ) %]
- [% orderdiscount_2dp %]%
+ [% FormatNum.Percent( orderdiscount ) %]%
[% ELSE %]
- [% discount_2dp %]%
+ [% FormatNum.Percent( discount ) %]%
[% END %]
[% ELSE %]
[% IF ( orderdiscount ) %]
- %
+ %
[% ELSE %]
- %
+ %
[% END %]
[% END %]
[% IF ( close ) %]
Replacement cost:
- [% rrp %]
+ [% FormatNum.Price( rrp ) %]
[% ELSE %]
- (adjusted for [% cur_active %])
+ (adjusted for [% cur_active %])
[% END %]
[% IF ( close ) %]
-
+
[% ELSE %]
-
+
[% END %]
[% IF ( close ) %]
-
+
[% ELSE %]
- (budgeted cost * quantity)
+ (budgeted cost * quantity)
[% END %]
[% IF ( close ) %]
-
+
[% ELSE %]
-
+
[% END %]
--
1.7.10.4 |