Bug 20088: Fix uninitialized warning from svc/holds
[koha.git] / svc / checkouts
index 119053c..e42f369 100755 (executable)
@@ -26,11 +26,12 @@ use JSON qw(to_json);
 use C4::Auth qw(check_cookie_auth haspermission get_session);
 use C4::Biblio qw(GetMarcBiblio GetFrameworkCode GetRecordValue );
 use C4::Circulation qw(GetIssuingCharges CanBookBeRenewed GetRenewCount GetSoonestRenewDate);
-use C4::Koha qw(GetAuthorisedValueByCode);
 use C4::Overdues qw(GetFine);
 use C4::Context;
 
+use Koha::AuthorisedValues;
 use Koha::DateUtils;
+use Koha::ItemTypes;
 
 my $input = new CGI;
 
@@ -148,15 +149,30 @@ while ( my $c = $sth->fetchrow_hashref() ) {
     my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
       GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
 
-    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
+    my $itemtype = Koha::ItemTypes->find( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
+    my $location;
+    if ( $c->{location} ) {
+        my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $c->{location} });
+        $location = $av->count ? $av->next->lib : '';
+    }
+    my $lost;
+    if ( $c->{itemlost} ) {
+        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $c->{itemlost} });
+        $lost = $av->count ? $av->next->lib : '';
+    }
+    my $damaged;
+    if ( $c->{damaged} ) {
+        my $av = Koha::AuthorisedValues->search({ category => 'DAMAGED', authorised_value => $c->{damaged} });
+        $damaged = $av->count ? $av->next->lib : '';
+    }
     my $checkout = {
         DT_RowId             => $c->{itemnumber} . '-' . $c->{borrowernumber},
         title                => $c->{title},
         author               => $c->{author},
         barcode              => $c->{barcode},
         itemtype             => $item_level_itypes ? $c->{itype} : $c->{itemtype},
-        itemtype_description => $itemtype->{translated_description},
-        location             => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
+        itemtype_description => $itemtype ? $itemtype->translated_description : q{},
+        location             => $location,
         homebranch           => $c->{homebranch},
         itemnotes            => $c->{itemnotes},
         itemnotes_nonpublic  => $c->{itemnotes_nonpublic},
@@ -193,10 +209,12 @@ while ( my $c = $sth->fetchrow_hashref() ) {
                 as_due_date => 1
             }
         ),
-        subtitle =>
-          GetRecordValue( 'subtitle', GetMarcBiblio( $c->{biblionumber} ), GetFrameworkCode( $c->{biblionumber} ) ),
-        lost    => $c->{itemlost} ? GetAuthorisedValueByCode( 'LOST',    $c->{itemlost} ) : undef,
-        damaged => $c->{damaged}  ? GetAuthorisedValueByCode( 'DAMAGED', $c->{damaged} )  : undef,
+        subtitle => GetRecordValue(
+            'subtitle',
+            GetMarcBiblio({ biblionumber => $c->{biblionumber} }),
+            GetFrameworkCode( $c->{biblionumber} ) ),
+        lost    => $lost,
+        damaged => $damaged,
         borrower => {
             surname    => $c->{surname},
             firstname  => $c->{firstname},