Bug 21467: Allow several receipts for a given subscription
[koha.git] / acqui / orderreceive.pl
index e876942..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} // '';
@@ -183,8 +186,7 @@ if( defined $order->{tax_rate_on_receiving} ) {
 
 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
 
-my $authorisedby = $order->{authorisedby};
-my $authorised_patron = Koha::Patrons->find( $authorisedby );
+my $creator = Koha::Patrons->find( $order->{created_by} );
 
 my $budget = GetBudget( $order->{budget_id} );
 
@@ -195,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,
@@ -204,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'},
@@ -214,11 +232,11 @@ $template->param(
     quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
     quantityreceived      => $order->{'quantityreceived'},
     rrp                   => $rrp,
+    replacementprice      => $order->{'replacementprice'},
     ecost                 => $ecost,
     unitprice             => $unitprice,
     tax_rate              => $tax_rate,
-    memberfirstname       => $authorised_patron->firstname || "",
-    membersurname         => $authorised_patron->surname || "",
+    creator               => $creator,
     invoiceid             => $invoice->{invoiceid},
     invoice               => $invoice->{invoicenumber},
     datereceived          => $datereceived,