Bug 18276: Remove GetBiblioFromItemNumber - Easy ones
[srvgit] / catalogue / moredetail.pl
index f94c1ff..04a0e9d 100755 (executable)
@@ -23,34 +23,28 @@ use strict;
 #use warnings; FIXME - Bug 2505
 use C4::Koha;
 use CGI qw ( -utf8 );
+use HTML::Entities;
 use C4::Biblio;
 use C4::Items;
-use C4::Branch;
 use C4::Acquisition;
 use C4::Output;
 use C4::Auth;
 use C4::Serials;
-use C4::Circulation;  # to use itemissues
 use C4::Members; # to use GetMember
 use C4::Search;                # enabled_staff_search_views
-use C4::Members qw/GetHideLostItemsPreference/;
-use C4::Reserves qw(GetReservesFromBiblionumber);
 
-use Koha::Acquisition::Bookseller;
+use Koha::Acquisition::Booksellers;
+use Koha::AuthorisedValues;
+use Koha::Biblios;
 use Koha::DateUtils;
 use Koha::Items;
+use Koha::Patrons;
 
 my $query=new CGI;
 
-# FIXME  subject is not exported to the template?
-my $subject=$query->param('subject');
-
-# if its a subject we need to use the subject.tt
 my ($template, $loggedinuser, $cookie) = get_template_and_user(
     {
-        template_name   => ( $subject
-                                ? 'catalogue/subject.tt'
-                                : 'catalogue/moredetail.tt'),
+        template_name   => 'catalogue/moredetail.tt',
         query           => $query,
         type            => "intranet",
         authnotrequired => 0,
@@ -73,6 +67,7 @@ my $hidepatronname = C4::Context->preference("HidePatronName");
 # get variables
 
 my $biblionumber=$query->param('biblionumber');
+$biblionumber = HTML::Entities::encode($biblionumber);
 my $title=$query->param('title');
 my $bi=$query->param('bi');
 $bi = $biblionumber unless $bi;
@@ -98,9 +93,10 @@ my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
 my $fw = GetFrameworkCode($biblionumber);
 my @all_items= GetItemsInfo($biblionumber);
 my @items;
+my $patron = Koha::Patrons->find( $loggedinuser );
 for my $itm (@all_items) {
     push @items, $itm unless ( $itm->{itemlost} && 
-                               GetHideLostItemsPreference($loggedinuser) &&
+                               $patron->category->hidelostitems &&
                                !$showallitems && 
                                ($itemnumber != $itm->{itemnumber}));
 }
@@ -124,9 +120,12 @@ $data->{'count'}=$totalcount;
 $data->{'showncount'}=$showncount;
 $data->{'hiddencount'}=$hiddencount;  # can be zero
 
-my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
-my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
-my $itemtypes = GetItemTypes;
+my $ccodes =
+  { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
+my $copynumbers =
+  { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
+
+my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
 
 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
@@ -162,8 +161,8 @@ foreach my $item (@items){
     $item->{'orderdate'}               = $order->{'entrydate'};
     if ($item->{'basketno'}){
            my $basket = GetBasket($item->{'basketno'});
-        my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
-           $item->{'vendor'} = $bookseller->{'name'};
+        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
+        $item->{'vendor'} = $bookseller->name;
     }
     $item->{'invoiceid'}               = $order->{'invoiceid'};
     if($item->{invoiceid}) {
@@ -183,8 +182,6 @@ foreach my $item (@items){
                 $item->{'nomod'}=1;
         }
     }
-    $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
-    $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
     if ($item->{'datedue'}) {
         $item->{'issue'}= 1;
     } else {
@@ -201,14 +198,17 @@ foreach my $item (@items){
 
 }
 
-if ( my $lost_av = GetAuthValCode('items.itemlost', $fw) ) {
-    $template->param( itemlostloop => GetAuthorisedValues( $lost_av ) );
+my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => { not => undef } });
+if ( $mss->count ) {
+    $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
 }
-if ( my $damaged_av = GetAuthValCode('items.damaged', $fw) ) {
-    $template->param( itemdamagedloop => GetAuthorisedValues( $damaged_av ) );
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => { not => undef } });
+if ( $mss->count ) {
+    $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
 }
-if ( my $withdrawn_av = GetAuthValCode('items.withdrawn', $fw) ) {
-    $template->param( itemwithdrawnloop => GetAuthorisedValues( $withdrawn_av ) );
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => { not => undef } });
+if ( $mss->count ) {
+    $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
 }
 
 $template->param(count => $data->{'count'},
@@ -259,9 +259,9 @@ $template->param (countorders => $count_orders_using_biblio);
 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
 
-my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
-my $holdcount = scalar( @$holds );
-$template->param( holdcount => scalar ( @$holds ) );
+my $biblio = Koha::Biblios->find( $biblionumber );
+my $holds = $biblio->holds;
+$template->param( holdcount => $holds->count );
 
 output_html_with_http_headers $query, $cookie, $template->output;