Bug 12970: Use the centralize VAT and prices calculation - basket.pl
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 19 Sep 2014 15:09:34 +0000 (17:09 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 19 Feb 2015 13:08:17 +0000 (10:08 -0300)
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 <paola.rossi@cineca.it>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
acqui/basket.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt

index 921c67e..bcd4177 100755 (executable)
@@ -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)';
index 9cc23bd..ef6d9d0 100644 (file)
@@ -1,4 +1,5 @@
 [% USE KohaDates %]
+[% USE Price %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo; [% UNLESS ( basketno ) %]New [% END %][% IF ( delete_confirm ) %]Delete [% END %]Basket [% basketname|html %] ([% basketno %]) for [% name|html %]</title>
 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
                 [% FOREACH foot_loo IN book_foot_loop %]
                     <tr>
                         <th></th>
-                        <th>Total (GST [% foot_loo.gstgsti %])</th>
+                        <th>Total (GST [% foot_loo.gstrate * 100 | $Price %])</th>
                         <th class="gste">&nbsp;</th>
                         <th class="gste">&nbsp;</th>
                         <th class="gsti">&nbsp;</th>
                         </td>
                         [% 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 %]
-                        <td class="number gste [% IF books_loo.rrpgste.search(zero_regex) %]error[% END %]">[% books_loo.rrpgste %]</td>
-                        <td class="number gste [% IF books_loo.ecostgste.search(zero_regex) %]error[% END %]">[% books_loo.ecostgste %]</td>
-                        <td class="number gsti [% IF books_loo.rrpgsti.search(zero_regex) %]error[% END %]">[% books_loo.rrpgsti %]</td>
-                        <td class="number gsti [% IF books_loo.ecostgsti.search(zero_regex) %]error[% END %]">[% books_loo.ecostgsti %]</td>
+                        <td class="number gste [% IF books_loo.rrpgste.search(zero_regex) %]error[% END %]">[% books_loo.rrpgste | $Price %]</td>
+                        <td class="number gste [% IF books_loo.ecostgste.search(zero_regex) %]error[% END %]">[% books_loo.ecostgste | $Price%]</td>
+                        <td class="number gsti [% IF books_loo.rrpgsti.search(zero_regex) %]error[% END %]">[% books_loo.rrpgsti | $Price %]</td>
+                        <td class="number gsti [% IF books_loo.ecostgsti.search(zero_regex) %]error[% END %]">[% books_loo.ecostgsti | $Price %]</td>
                         <td class="number [% IF books_loo.quantity.search(zero_regex) %]error[% END %]">[% books_loo.quantity %]</td>
-                        <td class="number gste [% IF books_loo.totalgste.search(zero_regex) %]error[% END %]">[% books_loo.totalgste %]</td>
-                        <td class="number gsti [% IF books_loo.totalgsti.search(zero_regex) %]error[% END %]">[% books_loo.totalgsti %]</td>
-                        <td class="number [% IF books_loo.gstgsti.search(zero_regex) %]error[% END %]">[% books_loo.gstgsti %]</td>
-                        <td class="number [% IF books_loo.gstvalue.search(zero_regex) %]error[% END %]">[% books_loo.gstvalue %]</td>
+                        <td class="number gste [% IF books_loo.totalgste.search(zero_regex) %]error[% END %]">[% books_loo.totalgste | $Price %]</td>
+                        <td class="number gsti [% IF books_loo.totalgsti.search(zero_regex) %]error[% END %]">[% books_loo.totalgsti | $Price %]</td>
+                        <td class="number">[% books_loo.gstrate * 100 | $Price %]</td>
+                        <td class="number [% IF books_loo.gstvalue.search(zero_regex) %]error[% END %]">[% books_loo.gstvalue | $Price %]</td>
                         <td>[% books_loo.budget_name %]</td>
                         [% IF ( active ) %]
                             [% UNLESS ( closedate ) %]
                     <td class="number">[% order.quantity %]</td>
                     <td class="number gste">[% order.totalgste %]</td>
                     <td class="number gsti">[% order.totalgsti %]</td>
-                    <td class="number">[% order.gstgsti %]</td>
+                    <td class="number">[% order.gstrate * 100 %]</td>
                     <td class="number">[% order.gstvalue %]</td>
                     <td>[% order.budget_name %]
                   </tr>