3 # Copyright 2000-2003 Katipo Communications
4 # parts copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
32 use C4
::Search
; # enabled_staff_search_views
34 use Koha
::Acquisition
::Booksellers
;
35 use Koha
::AuthorisedValues
;
43 my ($template, $loggedinuser, $cookie) = get_template_and_user
(
45 template_name
=> 'catalogue/moredetail.tt',
49 flagsrequired
=> { catalogue
=> 1 },
53 if($query->cookie("holdfor")){
54 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
56 holdfor
=> $query->cookie("holdfor"),
57 holdfor_surname
=> $holdfor_patron->surname,
58 holdfor_firstname
=> $holdfor_patron->firstname,
59 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
65 my $biblionumber=$query->param('biblionumber');
66 $biblionumber = HTML
::Entities
::encode
($biblionumber);
67 my $title=$query->param('title');
68 my $bi=$query->param('bi');
69 $bi = $biblionumber unless $bi;
70 my $itemnumber = $query->param('itemnumber');
71 my $data = &GetBiblioData
($biblionumber);
72 my $dewey = $data->{'dewey'};
73 my $showallitems = $query->param('showallitems');
75 #coping with subscriptions
76 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
78 # FIXME Dewey is a string, not a number, & we should use a function
80 # if ($dewey eq "000.") { $dewey = "";};
81 # if ($dewey < 10){$dewey='00'.$dewey;}
82 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
87 # $data->{'dewey'}=$dewey;
89 my $fw = GetFrameworkCode
($biblionumber);
90 my @all_items= GetItemsInfo
($biblionumber);
92 my $patron = Koha
::Patrons
->find( $loggedinuser );
93 for my $itm (@all_items) {
94 push @items, $itm unless ( $itm->{itemlost
} &&
95 $patron->category->hidelostitems &&
97 ($itemnumber != $itm->{itemnumber
}));
100 my $record=GetMarcBiblio
({ biblionumber
=> $biblionumber });
103 # adding items linked via host biblios
104 my @hostitems = GetHostItemsInfo
($record);
107 push (@items,@hostitems);
110 my $subtitle = GetRecordValue
('subtitle', $record, $fw);
112 my $totalcount=@all_items;
113 my $showncount=@items;
114 my $hiddencount = $totalcount - $showncount;
115 $data->{'count'}=$totalcount;
116 $data->{'showncount'}=$showncount;
117 $data->{'hiddencount'}=$hiddencount; # can be zero
120 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
122 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
124 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
126 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
127 if $data->{itemtype
} && exists $itemtypes->{ $data->{itemtype
} };
128 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} || 0); # Price formatting should be done template-side
129 foreach ( keys %{$data} ) {
130 $template->param( "$_" => defined $data->{$_} ?
$data->{$_} : '' );
133 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
134 foreach my $item (@items){
135 $item->{object
} = Koha
::Items
->find( $item->{itemnumber
} );
136 $item->{'collection'} = $ccodes->{ $item->{ccode
} } if $ccodes && $item->{ccode
} && exists $ccodes->{ $item->{ccode
} };
137 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
138 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} || 0 ); # Price formatting should be done template-side
139 if ( defined $item->{'copynumber'} ) {
140 $item->{'displaycopy'} = 1;
141 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
142 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
145 $item->{'copyvol'} = $item->{'copynumber'};
149 # item has a host number if its biblio number does not match the current bib
150 if ($item->{biblionumber
} ne $biblionumber){
151 $item->{hostbiblionumber
} = $item->{biblionumber
};
152 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
155 my $order = GetOrderFromItemnumber
( $item->{'itemnumber'} );
156 $item->{'ordernumber'} = $order->{'ordernumber'};
157 $item->{'basketno'} = $order->{'basketno'};
158 $item->{'orderdate'} = $order->{'entrydate'};
159 if ($item->{'basketno'}){
160 my $basket = GetBasket
($item->{'basketno'});
161 my $bookseller = Koha
::Acquisition
::Booksellers
->find( $basket->{booksellerid
} );
162 $item->{'vendor'} = $bookseller->name;
164 $item->{'invoiceid'} = $order->{'invoiceid'};
165 if($item->{invoiceid
}) {
166 my $invoice = GetInvoice
($item->{invoiceid
});
167 $item->{invoicenumber
} = $invoice->{invoicenumber
} if $invoice;
169 $item->{'datereceived'} = $order->{'datereceived'};
171 if ($item->{notforloantext
} or $item->{itemlost
} or $item->{damaged
} or $item->{withdrawn
}) {
172 $item->{status_advisory
} = 1;
175 if (C4
::Context
->preference("IndependentBranches")) {
177 my $userenv = C4
::Context
->userenv();
178 unless (C4
::Context
->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
182 if ($item->{'datedue'}) {
188 if ( $item->{'borrowernumber'} ) {
189 my $curr_borrower = Koha
::Patrons
->find( $item->{borrowernumber
} );
190 $item->{patron
} = $curr_borrower;
194 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
196 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
198 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
200 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
202 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.withdrawn', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
204 $template->param( itemwithdrawnloop
=> GetAuthorisedValues
( $mss->next->authorised_value) );
207 $template->param(count
=> $data->{'count'},
208 subscriptionsnumber
=> $subscriptionsnumber,
209 subscriptiontitle
=> $data->{title
},
210 C4
::Search
::enabled_staff_search_views
,
214 ITEM_DATA
=> \
@items,
216 loggedinuser
=> $loggedinuser,
217 biblionumber
=> $biblionumber,
218 biblioitemnumber
=> $bi,
219 itemnumber
=> $itemnumber,
220 z3950_search_params
=> C4
::Search
::z3950_search_args
(GetBiblioData
($biblionumber)),
221 subtitle
=> $subtitle,
223 $template->param(ONLY_ONE
=> 1) if ( $itemnumber && $showncount != @items );
224 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
226 my @allorders_using_biblio = GetOrdersByBiblionumber
($biblionumber);
227 my @deletedorders_using_biblio;
228 my @orders_using_biblio;
230 my @baskets_deletedorders;
232 foreach my $myorder (@allorders_using_biblio) {
233 my $basket = $myorder->{'basketno'};
234 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
235 push @deletedorders_using_biblio, $myorder;
236 unless (grep(/^$basket$/, @baskets_deletedorders)){
237 push @baskets_deletedorders,$myorder->{'basketno'};
241 push @orders_using_biblio, $myorder;
242 unless (grep(/^$basket$/, @baskets_orders)){
243 push @baskets_orders,$myorder->{'basketno'};
248 my $count_orders_using_biblio = scalar @orders_using_biblio ;
249 $template->param (countorders
=> $count_orders_using_biblio);
251 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
252 $template->param (countdeletedorders
=> $count_deletedorders_using_biblio);
254 my $biblio = Koha
::Biblios
->find( $biblionumber );
255 my $holds = $biblio->holds;
256 $template->param( holdcount
=> $holds->count );
258 output_html_with_http_headers
$query, $cookie, $template->output;