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',
48 flagsrequired
=> { catalogue
=> 1 },
53 updated_exclude_from_local_holds_priority
=> scalar($query->param('updated_exclude_from_local_holds_priority'))
56 if($query->cookie("holdfor")){
57 my $holdfor_patron = Koha
::Patrons
->find( $query->cookie("holdfor") );
59 holdfor
=> $query->cookie("holdfor"),
60 holdfor_surname
=> $holdfor_patron->surname,
61 holdfor_firstname
=> $holdfor_patron->firstname,
62 holdfor_cardnumber
=> $holdfor_patron->cardnumber,
66 if( $query->cookie("searchToOrder") ){
67 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
69 searchtoorder_basketno
=> $basketno,
70 searchtoorder_vendorid
=> $vendorid
76 my $biblionumber=$query->param('biblionumber');
77 $biblionumber = HTML
::Entities
::encode
($biblionumber);
78 my $title=$query->param('title');
79 my $bi=$query->param('bi');
80 $bi = $biblionumber unless $bi;
81 my $itemnumber = $query->param('itemnumber');
82 my $data = &GetBiblioData
($biblionumber);
83 my $dewey = $data->{'dewey'};
84 my $showallitems = $query->param('showallitems');
86 #coping with subscriptions
87 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
89 # FIXME Dewey is a string, not a number, & we should use a function
91 # if ($dewey eq "000.") { $dewey = "";};
92 # if ($dewey < 10){$dewey='00'.$dewey;}
93 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
98 # $data->{'dewey'}=$dewey;
100 my $fw = GetFrameworkCode
($biblionumber);
101 my @all_items= GetItemsInfo
($biblionumber);
103 my $patron = Koha
::Patrons
->find( $loggedinuser );
104 for my $itm (@all_items) {
105 push @items, $itm unless ( $itm->{itemlost
} &&
106 $patron->category->hidelostitems &&
108 ($itemnumber != $itm->{itemnumber
}));
111 my $record=GetMarcBiblio
({ biblionumber
=> $biblionumber });
113 output_and_exit
( $query, $cookie, $template, 'unknown_biblio')
117 # adding items linked via host biblios
118 my @hostitems = GetHostItemsInfo
($record);
121 push (@items,@hostitems);
124 my $biblio = Koha
::Biblios
->find( $biblionumber );
126 my $totalcount=@all_items;
127 my $showncount=@items;
128 my $hiddencount = $totalcount - $showncount;
129 $data->{'count'}=$totalcount;
130 $data->{'showncount'}=$showncount;
131 $data->{'hiddencount'}=$hiddencount; # can be zero
134 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.ccode' } ) };
136 { map { $_->{authorised_value
} => $_->{lib
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $fw, kohafield
=> 'items.copynumber' } ) };
138 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
140 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
141 if $data->{itemtype
} && exists $itemtypes->{ $data->{itemtype
} };
142 foreach ( keys %{$data} ) {
143 $template->param( "$_" => defined $data->{$_} ?
$data->{$_} : '' );
146 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
147 foreach my $item (@items){
148 $item->{object
} = Koha
::Items
->find( $item->{itemnumber
} );
149 $item->{'collection'} = $ccodes->{ $item->{ccode
} } if $ccodes && $item->{ccode
} && exists $ccodes->{ $item->{ccode
} };
150 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
151 $item->{'replacementprice'} = $item->{'replacementprice'};
152 if ( defined $item->{'copynumber'} ) {
153 $item->{'displaycopy'} = 1;
154 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
155 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
158 $item->{'copyvol'} = $item->{'copynumber'};
162 # item has a host number if its biblio number does not match the current bib
163 if ($item->{biblionumber
} ne $biblionumber){
164 $item->{hostbiblionumber
} = $item->{biblionumber
};
165 $item->{hosttitle
} = GetBiblioData
($item->{biblionumber
})->{title
};
168 my $order = GetOrderFromItemnumber
( $item->{'itemnumber'} );
169 $item->{'ordernumber'} = $order->{'ordernumber'};
170 $item->{'basketno'} = $order->{'basketno'};
171 $item->{'orderdate'} = $order->{'entrydate'};
172 if ($item->{'basketno'}){
173 my $basket = GetBasket
($item->{'basketno'});
174 my $bookseller = Koha
::Acquisition
::Booksellers
->find( $basket->{booksellerid
} );
175 $item->{'vendor'} = $bookseller->name;
177 $item->{'invoiceid'} = $order->{'invoiceid'};
178 if($item->{invoiceid
}) {
179 my $invoice = GetInvoice
($item->{invoiceid
});
180 $item->{invoicenumber
} = $invoice->{invoicenumber
} if $invoice;
182 $item->{'datereceived'} = $order->{'datereceived'};
184 if ($item->{notforloantext
} or $item->{itemlost
} or $item->{damaged
} or $item->{withdrawn
}) {
185 $item->{status_advisory
} = 1;
189 if ( $item->{itemlost
} ) {
190 my $accountlines = Koha
::Account
::Lines
->search(
192 itemnumber
=> $item->{itemnumber
},
193 debit_type_code
=> 'LOST',
194 status
=> [ undef, { '<>' => 'RETURNED' } ],
195 amountoutstanding
=> 0
198 order_by
=> { '-desc' => 'date' },
203 if ( my $accountline = $accountlines->next ) {
204 my $payment_offsets = Koha
::Account
::Offsets
->search(
206 debit_id
=> $accountline->id,
207 credit_id
=> { '!=' => undef }, # it is not the debit itself
208 type
=> { '!=' => [ 'Writeoff', 'Forgiven' ] },
209 amount
=> { '<' => 0 } # credits are negative on the DB
211 { order_by
=> { '-desc' => 'created_on' } }
214 if ($payment_offsets->count) {
215 my $patron = $accountline->patron;
216 my $payment_offset = $payment_offsets->next;
217 $item->{paidfor
} = { patron
=> $patron, created_on
=> $payment_offset->created_on };
222 if (C4
::Context
->preference("IndependentBranches")) {
224 my $userenv = C4
::Context
->userenv();
225 unless (C4
::Context
->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
229 if ($item->{'datedue'}) {
235 if ( $item->{'borrowernumber'} ) {
236 my $curr_borrower = Koha
::Patrons
->find( $item->{borrowernumber
} );
237 $item->{patron
} = $curr_borrower;
241 my $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.itemlost', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
243 $template->param( itemlostloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
245 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.damaged', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
247 $template->param( itemdamagedloop
=> GetAuthorisedValues
( $mss->next->authorised_value ) );
249 $mss = Koha
::MarcSubfieldStructures
->search({ frameworkcode
=> $fw, kohafield
=> 'items.withdrawn', authorised_value
=> [ -and => {'!=' => undef }, {'!=' => ''}] });
251 $template->param( itemwithdrawnloop
=> GetAuthorisedValues
( $mss->next->authorised_value) );
254 $template->param(count
=> $data->{'count'},
255 subscriptionsnumber
=> $subscriptionsnumber,
256 subscriptiontitle
=> $data->{title
},
257 C4
::Search
::enabled_staff_search_views
,
261 ITEM_DATA
=> \
@items,
263 loggedinuser
=> $loggedinuser,
264 biblionumber
=> $biblionumber,
265 biblioitemnumber
=> $bi,
266 itemnumber
=> $itemnumber,
267 z3950_search_params
=> C4
::Search
::z3950_search_args
(GetBiblioData
($biblionumber)),
270 $template->param(ONLY_ONE
=> 1) if ( $itemnumber && $showncount != @items );
271 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
273 my $holds = $biblio->holds;
274 $template->param( holdcount
=> $holds->count );
276 output_html_with_http_headers
$query, $cookie, $template->output;