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>.
23 use C4::Koha qw( GetAuthorisedValues );
26 use C4::Biblio qw( GetBiblioData GetFrameworkCode );
27 use C4::Acquisition qw( GetOrderFromItemnumber GetBasket GetInvoice );
28 use C4::Output qw( output_and_exit output_html_with_http_headers );
29 use C4::Auth qw( get_template_and_user );
30 use C4::Serials qw( CountSubscriptionFromBiblionumber );
31 use C4::Search qw( enabled_staff_search_views z3950_search_args );
33 use Koha::Acquisition::Booksellers;
34 use Koha::AuthorisedValues;
41 my ($template, $loggedinuser, $cookie) = get_template_and_user(
43 template_name => 'catalogue/moredetail.tt',
46 flagsrequired => { catalogue => 1 },
51 updated_exclude_from_local_holds_priority => scalar($query->param('updated_exclude_from_local_holds_priority'))
54 if($query->cookie("holdfor")){
55 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
57 holdfor => $query->cookie("holdfor"),
58 holdfor_patron => $holdfor_patron,
62 if( $query->cookie("searchToOrder") ){
63 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
65 searchtoorder_basketno => $basketno,
66 searchtoorder_vendorid => $vendorid
73 if( $query->param('itemnumber') && !$query->param('biblionumber') ){
74 $itemnumber = $query->param('itemnumber');
75 my $item = Koha::Items->find( $itemnumber );
76 $biblionumber = $item->biblionumber;
78 $biblionumber = $query->param('biblionumber');
81 $biblionumber = HTML::Entities::encode($biblionumber);
82 my $title=$query->param('title');
83 my $bi=$query->param('bi');
84 $bi = $biblionumber unless $bi;
85 $itemnumber = $query->param('itemnumber');
86 my $data = &GetBiblioData($biblionumber);
87 my $dewey = $data->{'dewey'};
88 my $showallitems = $query->param('showallitems');
90 #coping with subscriptions
91 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
93 # FIXME Dewey is a string, not a number, & we should use a function
95 # if ($dewey eq "000.") { $dewey = "";};
96 # if ($dewey < 10){$dewey='00'.$dewey;}
97 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
102 # $data->{'dewey'}=$dewey;
104 my $biblio = Koha::Biblios->find( $biblionumber );
105 my $record = $biblio ? $biblio->metadata->record : undef;
107 output_and_exit( $query, $cookie, $template, 'unknown_biblio')
108 unless $biblio && $record;
110 my $fw = GetFrameworkCode($biblionumber);
111 my $all_items = $biblio->items->search_ordered;
114 my $patron = Koha::Patrons->find( $loggedinuser );
115 while ( my $item = $all_items->next ) {
117 unless $item->itemlost
118 && $patron->category->hidelostitems
123 my $hostitems = $biblio->host_items;
124 if ( $hostitems->count ) {
126 push @items, $hostitems->as_list;
129 my $totalcount = $all_items->count;
130 my $showncount = scalar @items;
131 my $hiddencount = $totalcount - $showncount;
132 $data->{'count'}=$totalcount;
133 $data->{'showncount'}=$showncount;
134 $data->{'hiddencount'}=$hiddencount; # can be zero
137 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
139 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
141 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
143 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
144 if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
145 foreach ( keys %{$data} ) {
146 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
150 @items = (grep {$_->itemnumber == $itemnumber} @items);
153 foreach my $item (@items){
155 my $item_info = $item->unblessed;
156 $item_info->{object} = $item;
157 $item_info->{itype} = $itemtypes->{ $item->itype }->{'translated_description'} if exists $itemtypes->{ $item->itype };
158 $item_info->{effective_itemtype} = $itemtypes->{$item->effective_itemtype};
159 $item_info->{'ccode'} = $ccodes->{ $item->ccode } if $ccodes && $item->ccode && exists $ccodes->{ $item->ccode };
160 if ( defined $item->copynumber ) {
161 $item_info->{'displaycopy'} = 1;
162 if ( defined $copynumbers->{ $item_info->{'copynumber'} } ) {
163 $item_info->{'copyvol'} = $copynumbers->{ $item_info->{'copynumber'} }
166 $item_info->{'copyvol'} = $item_info->{'copynumber'};
170 # item has a host number if its biblio number does not match the current bib
171 if ($item->biblionumber ne $biblionumber){
172 $item_info->{hostbiblionumber} = $item->biblionumber;
173 $item_info->{hosttitle} = $item->biblio->title;
176 # FIXME The acquisition code below could be improved using methods from Koha:: objects
177 my $order = GetOrderFromItemnumber( $item->itemnumber );
178 $item_info->{'basketno'} = $order->{'basketno'};
179 $item_info->{'orderdate'} = $order->{'entrydate'};
180 if ($item_info->{'basketno'}){
181 my $basket = GetBasket($item_info->{'basketno'});
182 my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
183 $item_info->{'vendor'} = $bookseller->name;
185 $item_info->{'invoiceid'} = $order->{'invoiceid'};
186 if($item_info->{invoiceid}) {
187 my $invoice = GetInvoice($item_info->{invoiceid});
188 $item_info->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
190 $item_info->{'datereceived'} = $order->{'datereceived'};
192 if ( $item->notforloan
193 || $item->itemtype->notforloan
196 || $item->withdrawn )
198 $item_info->{status_advisory} = 1;
202 if ( $item->itemlost ) {
203 my $accountlines = Koha::Account::Lines->search(
205 itemnumber => $item->itemnumber,
206 debit_type_code => 'LOST',
207 status => [ undef, { '<>' => 'RETURNED' } ],
208 amountoutstanding => 0
211 order_by => { '-desc' => 'date' },
216 if ( my $accountline = $accountlines->next ) {
217 my $payment_offsets = $accountline->debit_offsets(
219 credit_id => { '!=' => undef }, # it is not the debit itself
220 'credit.credit_type_code' =>
221 { '!=' => [ 'Writeoff', 'Forgiven' ] },
223 { join => 'credit', order_by => { '-desc' => 'created_on' } }
226 if ($payment_offsets->count) {
227 my $patron = $accountline->patron;
228 my $payment_offset = $payment_offsets->next;
229 $item_info->{paidfor} = { patron => $patron, created_on => $payment_offset->created_on };
234 if (C4::Context->preference("IndependentBranches")) {
236 my $userenv = C4::Context->userenv();
237 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->homebranch)) {
238 $item_info->{'nomod'}=1;
242 $item_info->{old_issues} = Koha::Old::Checkouts->search(
243 { itemnumber => $item->itemnumber },
245 order_by => { '-desc' => 'returndate' },
250 push @item_data, $item_info;
253 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
255 $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
257 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
259 $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
261 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
263 $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
266 $template->param(count => $data->{'count'},
267 subscriptionsnumber => $subscriptionsnumber,
268 subscriptiontitle => $data->{title},
269 C4::Search::enabled_staff_search_views,
272 # get biblionumbers stored in the cart
275 if($query->cookie("intranet_bib_list")){
276 my $cart_list = $query->cookie("intranet_bib_list");
277 @cart_list = split(/\//, $cart_list);
278 if ( grep {$_ eq $biblionumber} @cart_list) {
279 $template->param( incart => 1 );
283 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
285 borrowernumber => $loggedinuser,
290 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
292 borrowernumber => $loggedinuser,
300 add_to_some_private_shelves => $some_private_shelves,
301 add_to_some_public_shelves => $some_public_shelves,
305 ITEM_DATA => \@item_data,
307 loggedinuser => $loggedinuser,
308 biblionumber => $biblionumber,
309 biblioitemnumber => $bi,
310 itemnumber => $itemnumber,
311 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
314 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
315 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
317 my $holds = $biblio->holds;
318 $template->param( holdcount => $holds->count );
320 output_html_with_http_headers $query, $cookie, $template->output;