Bug 14861: Accession date comparison does not work in advanced search
[koha.git] / acqui / invoice.pl
index 33e5592..026fd13 100755 (executable)
@@ -3,18 +3,18 @@
 # Copyright 2011 BibLibre SARL
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -29,12 +29,13 @@ Invoice details
 use strict;
 use warnings;
 
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Output;
 use C4::Acquisition;
-use C4::Bookseller qw/GetBookSellerFromId/;
 use C4::Budgets;
+
+use Koha::Acquisition::Bookseller;
 use Koha::Misc::Files;
 
 my $input = new CGI;
@@ -109,7 +110,7 @@ elsif ( $op && $op eq 'delete' ) {
 
 
 my $details = GetInvoiceDetails($invoiceid);
-my $bookseller = GetBookSellerFromId($details->{booksellerid});
+my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $details->{booksellerid} });
 my @orders_loop = ();
 my $orders = $details->{'orders'};
 my $qty_total;
@@ -120,16 +121,23 @@ my $total_gste = 0;
 my $total_gsti = 0;
 my $total_gstvalue = 0;
 foreach my $order (@$orders) {
+    $order = C4::Acquisition::populate_order_with_prices(
+        {
+            order        => $order,
+            booksellerid => $bookseller->{id},
+            receiving    => 1,
+        }
+    );
     my $line = get_infos( $order, $bookseller);
 
-    $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti};
-    $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
+    $foot{$$line{gstrate}}{gstrate} = $$line{gstrate};
+    $foot{$$line{gstrate}}{gstvalue} += $$line{gstvalue};
     $total_gstvalue += $$line{gstvalue};
-    $foot{$$line{gstgsti}}{quantity}  += $$line{quantity};
+    $foot{$$line{gstrate}}{quantity}  += $$line{quantity};
     $total_quantity += $$line{quantity};
-    $foot{$$line{gstgsti}}{totalgste} += $$line{totalgste};
+    $foot{$$line{gstrate}}{totalgste} += $$line{totalgste};
     $total_gste += $$line{totalgste};
-    $foot{$$line{gstgsti}}{totalgsti} += $$line{totalgsti};
+    $foot{$$line{gstrate}}{totalgsti} += $$line{totalgsti};
     $total_gsti += $$line{totalgsti};
 
     $line->{orderline} = $line->{parent_ordernumber};
@@ -192,23 +200,6 @@ sub get_infos {
     my %line = %{ $order };
     $line{order_received} = ( $qty == $order->{'quantityreceived'} );
     $line{budget_name}    = $budget->{budget_name};
-    if ( $bookseller->{'listincgst'} ) {
-        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
-        $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
-        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} );
-        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) );
-        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
-        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
-        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
-    } else {
-        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
-        $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
-        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) );
-        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} );
-        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
-        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
-        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
-    }
 
     if ( $line{uncertainprice} ) {
         $template->param( uncertainprices => 1 );
@@ -219,8 +210,6 @@ sub get_infos {
         my $seriestitle = $order->{'seriestitle'};
         $line{'title'} .= " / $seriestitle" if $seriestitle;
         $line{'title'} .= " / $volume"      if $volume;
-    } else {
-        $line{'title'} = "Deleted bibliographic notice, can't find title.";
     }
 
     return \%line;