Bug 10403: (follow-up) fix test to use vendor created earlier during test
[koha.git] / acqui / parcel.pl
index 839c2a9..ad0e51d 100755 (executable)
@@ -67,6 +67,7 @@ use CGI;
 use C4::Output;
 use C4::Dates qw/format_date format_date_in_iso/;
 use C4::Suggestions;
+use C4::Reserves qw/GetReservesFromBiblionumber/;
 use JSON;
 
 my $input=new CGI;
@@ -148,8 +149,8 @@ my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
 my $datereceived = C4::Dates->new();
 
 my $cfstr         = "%.2f";                                                           # currency format string -- could get this from currency table.
-my @parcelitems   = @{ $invoice->{orders} };
-my $countlines    = scalar @parcelitems;
+my @orders        = @{ $invoice->{orders} };
+my $countlines    = scalar @orders;
 my $totalprice    = 0;
 my $totalquantity = 0;
 my $total;
@@ -160,18 +161,25 @@ my $total_quantity = 0;
 my $total_gste = 0;
 my $total_gsti = 0;
 
-for my $item ( @parcelitems ) {
-    $item->{unitprice} = get_value_with_gst_params( $item->{unitprice}, $item->{gstrate}, $bookseller );
-    $total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'};
-    $item->{'unitprice'} += 0;
-    my %line = %{ $item };
+for my $order ( @orders ) {
+    $order->{unitprice} = get_value_with_gst_params( $order->{unitprice}, $order->{gstrate}, $bookseller );
+    $total = ( $order->{unitprice} ) * $order->{quantityreceived};
+    $order->{'unitprice'} += 0;
+    my %line = %{ $order };
     my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller );
     $line{ecost} = sprintf( "%.2f", $ecost );
     $line{invoice} = $invoice->{invoicenumber};
     $line{total} = sprintf($cfstr, $total);
     $line{booksellerid} = $invoice->{booksellerid};
-    $totalprice += $item->{'unitprice'};
-    $line{unitprice} = sprintf( $cfstr, $item->{'unitprice'} );
+    $line{holds} = 0;
+    my @itemnumbers = GetItemnumbersFromOrder( $order->{ordernumber} );
+    for my $itemnumber ( @itemnumbers ) {
+        my ( $count ) = &GetReservesFromBiblionumber($line{biblionumber}, undef, $itemnumber);
+        $line{holds} += $count;
+    }
+    $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
+    $totalprice += $order->{unitprice};
+    $line{unitprice} = sprintf( $cfstr, $order->{unitprice} );
     my $gste = get_gste( $line{total}, $line{gstrate}, $bookseller );
     my $gst = get_gst( $line{total}, $line{gstrate}, $bookseller );
     $foot{$line{gstrate}}{gstrate} = $line{gstrate};
@@ -187,7 +195,8 @@ for my $item ( @parcelitems ) {
 
     if ( $line{parent_ordernumber} != $line{ordernumber} ) {
         if ( grep { $_->{ordernumber} == $line{parent_ordernumber} }
-            @parcelitems )
+            @orders
+            )
         {
             $line{cannot_cancel} = 1;
         }
@@ -197,7 +206,7 @@ for my $item ( @parcelitems ) {
     $line{budget_name} = $budget->{'budget_name'};
 
     push @loop_received, \%line;
-    $totalquantity += $item->{'quantityreceived'};
+    $totalquantity += $order->{quantityreceived};
 
 }
 push @book_foot_loop, map { $_ } values %foot;