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 GetMarcBiblio );
27 use C4::Items qw( GetHostItemsInfo GetItemsInfo );
28 use C4::Acquisition qw( GetOrderFromItemnumber GetBasket GetInvoice );
29 use C4::Output qw( output_and_exit output_html_with_http_headers );
30 use C4::Auth qw( get_template_and_user );
31 use C4::Serials qw( CountSubscriptionFromBiblionumber );
32 use C4::Search qw( enabled_staff_search_views z3950_search_args );
34 use Koha::Acquisition::Booksellers;
35 use Koha::AuthorisedValues;
42 my ($template, $loggedinuser, $cookie) = get_template_and_user(
44 template_name => 'catalogue/moredetail.tt',
47 flagsrequired => { catalogue => 1 },
52 updated_exclude_from_local_holds_priority => scalar($query->param('updated_exclude_from_local_holds_priority'))
55 if($query->cookie("holdfor")){
56 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
58 holdfor => $query->cookie("holdfor"),
59 holdfor_patron => $holdfor_patron,
63 if( $query->cookie("searchToOrder") ){
64 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
66 searchtoorder_basketno => $basketno,
67 searchtoorder_vendorid => $vendorid
74 if( $query->param('itemnumber') && !$query->param('biblionumber') ){
75 $itemnumber = $query->param('itemnumber');
76 my $item = Koha::Items->find( $itemnumber );
77 $biblionumber = $item->biblionumber;
79 $biblionumber = $query->param('biblionumber');
82 $biblionumber = HTML::Entities::encode($biblionumber);
83 my $title=$query->param('title');
84 my $bi=$query->param('bi');
85 $bi = $biblionumber unless $bi;
86 $itemnumber = $query->param('itemnumber');
87 my $data = &GetBiblioData($biblionumber);
88 my $dewey = $data->{'dewey'};
89 my $showallitems = $query->param('showallitems');
91 #coping with subscriptions
92 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
94 # FIXME Dewey is a string, not a number, & we should use a function
96 # if ($dewey eq "000.") { $dewey = "";};
97 # if ($dewey < 10){$dewey='00'.$dewey;}
98 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
103 # $data->{'dewey'}=$dewey;
105 my $fw = GetFrameworkCode($biblionumber);
106 my @all_items= GetItemsInfo($biblionumber);
108 my $patron = Koha::Patrons->find( $loggedinuser );
109 for my $itm (@all_items) {
110 push @items, $itm unless ( $itm->{itemlost} &&
111 $patron->category->hidelostitems &&
113 ($itemnumber != $itm->{itemnumber}));
116 my $record=GetMarcBiblio({ biblionumber => $biblionumber });
118 output_and_exit( $query, $cookie, $template, 'unknown_biblio')
122 # adding items linked via host biblios
123 my @hostitems = GetHostItemsInfo($record);
126 push (@items,@hostitems);
129 my $biblio = Koha::Biblios->find( $biblionumber );
131 my $totalcount=@all_items;
132 my $showncount=@items;
133 my $hiddencount = $totalcount - $showncount;
134 $data->{'count'}=$totalcount;
135 $data->{'showncount'}=$showncount;
136 $data->{'hiddencount'}=$hiddencount; # can be zero
139 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
141 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
143 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
145 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
146 if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
147 foreach ( keys %{$data} ) {
148 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
151 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
152 foreach my $item (@items){
153 $item->{object} = Koha::Items->find( $item->{itemnumber} );
154 $item->{'collection'} = $ccodes->{ $item->{ccode} } if $ccodes && $item->{ccode} && exists $ccodes->{ $item->{ccode} };
155 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
156 $item->{'replacementprice'} = $item->{'replacementprice'};
157 if ( defined $item->{'copynumber'} ) {
158 $item->{'displaycopy'} = 1;
159 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
160 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
163 $item->{'copyvol'} = $item->{'copynumber'};
167 # item has a host number if its biblio number does not match the current bib
168 if ($item->{biblionumber} ne $biblionumber){
169 $item->{hostbiblionumber} = $item->{biblionumber};
170 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
173 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
174 $item->{'ordernumber'} = $order->{'ordernumber'};
175 $item->{'basketno'} = $order->{'basketno'};
176 $item->{'orderdate'} = $order->{'entrydate'};
177 if ($item->{'basketno'}){
178 my $basket = GetBasket($item->{'basketno'});
179 my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
180 $item->{'vendor'} = $bookseller->name;
182 $item->{'invoiceid'} = $order->{'invoiceid'};
183 if($item->{invoiceid}) {
184 my $invoice = GetInvoice($item->{invoiceid});
185 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
187 $item->{'datereceived'} = $order->{'datereceived'};
189 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
190 $item->{status_advisory} = 1;
194 if ( $item->{itemlost} ) {
195 my $accountlines = Koha::Account::Lines->search(
197 itemnumber => $item->{itemnumber},
198 debit_type_code => 'LOST',
199 status => [ undef, { '<>' => 'RETURNED' } ],
200 amountoutstanding => 0
203 order_by => { '-desc' => 'date' },
208 if ( my $accountline = $accountlines->next ) {
209 my $payment_offsets = $accountline->debit_offsets(
211 credit_id => { '!=' => undef }, # it is not the debit itself
212 'credit.credit_type_code' =>
213 { '!=' => [ 'Writeoff', 'Forgiven' ] },
215 { join => 'credit', order_by => { '-desc' => 'created_on' } }
218 if ($payment_offsets->count) {
219 my $patron = $accountline->patron;
220 my $payment_offset = $payment_offsets->next;
221 $item->{paidfor} = { patron => $patron, created_on => $payment_offset->created_on };
226 if (C4::Context->preference("IndependentBranches")) {
228 my $userenv = C4::Context->userenv();
229 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
233 if ($item->{'datedue'}) {
239 if ( $item->{'borrowernumber'} ) {
240 my $curr_borrower = Koha::Patrons->find( $item->{borrowernumber} );
241 $item->{patron} = $curr_borrower;
245 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
247 $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
249 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
251 $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
253 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
255 $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
258 $template->param(count => $data->{'count'},
259 subscriptionsnumber => $subscriptionsnumber,
260 subscriptiontitle => $data->{title},
261 C4::Search::enabled_staff_search_views,
264 # get biblionumbers stored in the cart
267 if($query->cookie("intranet_bib_list")){
268 my $cart_list = $query->cookie("intranet_bib_list");
269 @cart_list = split(/\//, $cart_list);
270 if ( grep {$_ eq $biblionumber} @cart_list) {
271 $template->param( incart => 1 );
275 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
277 borrowernumber => $loggedinuser,
282 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
284 borrowernumber => $loggedinuser,
292 add_to_some_private_shelves => $some_private_shelves,
293 add_to_some_public_shelves => $some_public_shelves,
297 ITEM_DATA => \@items,
299 loggedinuser => $loggedinuser,
300 biblionumber => $biblionumber,
301 biblioitemnumber => $bi,
302 itemnumber => $itemnumber,
303 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
306 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
307 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
309 my $holds = $biblio->holds;
310 $template->param( holdcount => $holds->count );
312 output_html_with_http_headers $query, $cookie, $template->output;