Bug 15184: Change permission (+x) on .pl
[koha.git] / acqui / orderreceive.pl
index 837a117..4ce2dd0 100755 (executable)
@@ -58,8 +58,7 @@ The biblionumber of this order.
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Context;
@@ -74,7 +73,11 @@ 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;
+use Koha::Patrons;
 
 my $input      = new CGI;
 
@@ -109,6 +112,8 @@ unless ( $results and @$results) {
 
 # prepare the form for receiving
 my $order = $results->[0];
+my $basket = Koha::Acquisition::Orders->find( $ordernumber )->basket;
+my $active_currency = Koha::Acquisition::Currencies->get_active;
 
 # Check if ACQ framework exists
 my $acq_fw = GetMarcStructure( 1, 'ACQ', { unsafe => 1 } );
@@ -116,7 +121,7 @@ unless($acq_fw) {
     $template->param('NoACQframework' => 1);
 }
 
-my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
+my $AcqCreateItem = $basket->effective_create_items;
 if ($AcqCreateItem eq 'receiving') {
     $template->param(
         AcqCreateItemReceiving => 1,
@@ -144,8 +149,10 @@ if ($AcqCreateItem eq 'receiving') {
         $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
         $item->{materials} = $descriptions->{lib} // '';
 
-        my $itemtype = getitemtypeinfo($item->{itype});
-        $item->{itemtype} = $itemtype->{description};
+        my $itemtype = Koha::ItemTypes->find( $item->{itype} );
+        if (defined $itemtype) {
+            $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
+        }
         push @items, $item;
     }
     $template->param(items => \@items);
@@ -178,8 +185,7 @@ if( defined $order->{tax_rate_on_receiving} ) {
 
 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
 
-my $authorisedby = $order->{authorisedby};
-my $member = GetMember( borrowernumber => $authorisedby );
+my $creator = Koha::Patrons->find( $order->{created_by} );
 
 my $budget = GetBudget( $order->{budget_id} );
 
@@ -199,6 +205,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'},
@@ -209,11 +219,11 @@ $template->param(
     quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
     quantityreceived      => $order->{'quantityreceived'},
     rrp                   => $rrp,
+    replacementprice      => $order->{'replacementprice'},
     ecost                 => $ecost,
     unitprice             => $unitprice,
     tax_rate              => $tax_rate,
-    memberfirstname       => $member->{firstname} || "",
-    membersurname         => $member->{surname} || "",
+    creator               => $creator,
     invoiceid             => $invoice->{invoiceid},
     invoice               => $invoice->{invoicenumber},
     datereceived          => $datereceived,
@@ -225,7 +235,7 @@ $template->param(
     gst_values            => \@gst_values,
 );
 
-my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
+my $patron = Koha::Patrons->find( $loggedinuser )->unblessed;
 my @budget_loop;
 my $periods = GetBudgetPeriods( );
 foreach my $period (@$periods) {
@@ -236,7 +246,7 @@ foreach my $period (@$periods) {
     my $budget_hierarchy = GetBudgetHierarchy( $period->{'budget_period_id'} );
     my @funds;
     foreach my $r ( @{$budget_hierarchy} ) {
-        next unless ( CanUserUseBudget( $borrower, $r, $userflags ) );
+        next unless ( CanUserUseBudget( $patron, $r, $userflags ) );
         if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) {
             next;
         }