From 7a1d9250bb72aa3f2fc9744d2e7ff2bd106d456f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 19 Sep 2014 17:09:34 +0200 Subject: [PATCH] Bug 12970: Use the centralize VAT and prices calculation - basket.pl Bug 12969 introduces a subroutine to centralize VAT and prices calculation. It should be use in the acqui/basket.pl script. Test plan: 0/ Don't apply the patch 1/ Create 4 suppliers with the different configurations 2/ Create a basket and create several orders 3/ Go on the basket page 4/ Apply the patch 5/ Verify you don't see any difference before and after applying the patch Signed-off-by: Paola Rossi Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- acqui/basket.pl | 34 ++++--------------- .../prog/en/modules/acqui/basket.tt | 21 ++++++------ 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/acqui/basket.pl b/acqui/basket.pl index 921c67e79c..bcd4177206 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -334,7 +334,7 @@ if ( $op eq 'delete_confirm' ) { my $cur = GetCurrency(); - my @results = GetOrders( $basketno ); + my @orders = GetOrders( $basketno ); my @books_loop; my @book_foot_loop; @@ -343,7 +343,8 @@ if ( $op eq 'delete_confirm' ) { my $total_gste = 0; my $total_gsti = 0; my $total_gstvalue = 0; - for my $order (@results) { + for my $order (@orders) { + $order = C4::Acquisition::populate_order_with_prices({ order => $order, booksellerid => $booksellerid, ordering => 1 }); my $line = get_order_infos( $order, $bookseller); if ( $line->{uncertainprice} ) { $template->param( uncertainprices => 1 ); @@ -351,7 +352,7 @@ if ( $op eq 'delete_confirm' ) { push @books_loop, $line; - $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti}; + $foot{$$line{gstgsti}}{gstrate} = $$line{gstrate}; $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue}; $total_gstvalue += $$line{gstvalue}; $foot{$$line{gstgsti}}{quantity} += $$line{quantity}; @@ -365,9 +366,9 @@ if ( $op eq 'delete_confirm' ) { push @book_foot_loop, map {$_} values %foot; # Get cancelled orders - @results = GetCancelledOrders($basketno); + my @cancelledorders = GetCancelledOrders($basketno); my @cancelledorders_loop; - for my $order (@results) { + for my $order (@cancelledorders) { my $line = get_order_infos( $order, $bookseller); push @cancelledorders_loop, $line; } @@ -375,7 +376,6 @@ if ( $op eq 'delete_confirm' ) { my $contract = GetContract({ contractnumber => $basket->{contractnumber} }); - my @orders = GetOrders($basketno); if ($basket->{basketgroupid}){ $basketgroup = GetBasketgroup($basket->{basketgroupid}); @@ -446,28 +446,6 @@ sub get_order_infos { $line{order_received} = ( $qty == $order->{'quantityreceived'} ); $line{basketno} = $basketno; $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} ); - } 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} ); - } if ( $line{uncertainprice} ) { $line{rrpgste} .= ' (Uncertain)'; 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 9cc23bd2b8..ef6d9d0303 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 Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › [% UNLESS ( basketno ) %]New [% END %][% IF ( delete_confirm ) %]Delete [% END %]Basket [% basketname|html %] ([% basketno %]) for [% name|html %] @@ -415,7 +416,7 @@ [% FOREACH foot_loo IN book_foot_loop %] - Total (GST [% foot_loo.gstgsti %]) + Total (GST [% foot_loo.gstrate * 100 | $Price %])       @@ -502,15 +503,15 @@ [% SET zero_regex = "^0{1,}\.?0{1,}[^1-9]" %] [%# 0 or 0.0 or 0.00 or 00 or 00.0 or 00.00 or 0.000 ... %] [%# FIXME: use of a regexp is not ideal; bugs 9410 and 10929 suggest better way of handling this %] - [% books_loo.rrpgste %] - [% books_loo.ecostgste %] - [% books_loo.rrpgsti %] - [% books_loo.ecostgsti %] + [% books_loo.rrpgste | $Price %] + [% books_loo.ecostgste | $Price%] + [% books_loo.rrpgsti | $Price %] + [% books_loo.ecostgsti | $Price %] [% books_loo.quantity %] - [% books_loo.totalgste %] - [% books_loo.totalgsti %] - [% books_loo.gstgsti %] - [% books_loo.gstvalue %] + [% books_loo.totalgste | $Price %] + [% books_loo.totalgsti | $Price %] + [% books_loo.gstrate * 100 | $Price %] + [% books_loo.gstvalue | $Price %] [% books_loo.budget_name %] [% IF ( active ) %] [% UNLESS ( closedate ) %] @@ -620,7 +621,7 @@ [% order.quantity %] [% order.totalgste %] [% order.totalgsti %] - [% order.gstgsti %] + [% order.gstrate * 100 %] [% order.gstvalue %] [% order.budget_name %] -- 2.39.5