Bug 21467: Add subscription's info when ordering
[koha.git] / acqui / orderreceive.pl
index 4dbb5f0..ebf29f7 100755 (executable)
@@ -73,6 +73,7 @@ use C4::Suggestions;
 use C4::Koha;
 
 use Koha::Acquisition::Booksellers;
+use Koha::Acquisition::Currencies;
 use Koha::Acquisition::Orders;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::ItemTypes;
@@ -111,7 +112,9 @@ unless ( $results and @$results) {
 
 # prepare the form for receiving
 my $order = $results->[0];
-my $basket = Koha::Acquisition::Orders->find( $ordernumber )->basket;
+my $order_object = Koha::Acquisition::Orders->find( $ordernumber );
+my $basket = $order_object->basket;
+my $active_currency = Koha::Acquisition::Currencies->get_active;
 
 # Check if ACQ framework exists
 my $acq_fw = GetMarcStructure( 1, 'ACQ', { unsafe => 1 } );
@@ -127,10 +130,10 @@ if ($AcqCreateItem eq 'receiving') {
     );
 } elsif ($AcqCreateItem eq 'ordering') {
     my $fw = ($acq_fw) ? 'ACQ' : '';
-    my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber});
+    my @itemnumbers = $order_object->items->get_column('itemnumber');
     my @items;
     foreach (@itemnumbers) {
-        my $item = GetItem($_);
+        my $item = GetItem($_); # FIXME We do not need this call, we already have the Koha::Items
         my $descriptions;
         $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
         $item->{notforloan} = $descriptions->{lib} // '';
@@ -194,6 +197,18 @@ my @gst_values = map {
     option => $_ + 0.0
 }, split( '\|', C4::Context->preference("gist") );
 
+if ( $order->{subscriptionid} ) {
+    # Order from a subscription, we will display an history of what has been received
+    my $orders = Koha::Acquisition::Orders->search(
+        {
+            subscriptionid     => $order->{subscriptionid},
+            parent_ordernumber => $order->{ordernumber},
+            ordernumber        => { '!=' => $order->{ordernumber} }
+        }
+    );
+    $template->param( orders => $orders );
+}
+
 $template->param(
     AcqCreateItem         => $AcqCreateItem,
     count                 => 1,
@@ -203,6 +218,10 @@ $template->param(
     booksellerid          => $order->{'booksellerid'},
     freight               => $freight,
     name                  => $bookseller->name,
+    cur_active_sym        => $active_currency->symbol,
+    cur_active            => $active_currency->currency,
+    listincgst            => $bookseller->listincgst,
+    invoiceincgst         => $bookseller->invoiceincgst,
     title                 => $order->{'title'},
     author                => $order->{'author'},
     copyrightdate         => $order->{'copyrightdate'},
@@ -213,6 +232,7 @@ $template->param(
     quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
     quantityreceived      => $order->{'quantityreceived'},
     rrp                   => $rrp,
+    replacementprice      => $order->{'replacementprice'},
     ecost                 => $ecost,
     unitprice             => $unitprice,
     tax_rate              => $tax_rate,