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 },
52 if($query->cookie("holdfor")){
53 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
55 holdfor => $query->cookie("holdfor"),
56 holdfor_surname => $holdfor_patron->surname,
57 holdfor_firstname => $holdfor_patron->firstname,
58 holdfor_cardnumber => $holdfor_patron->cardnumber,
62 if( $query->cookie("searchToOrder") ){
63 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
65 searchtoorder_basketno => $basketno,
66 searchtoorder_vendorid => $vendorid
72 my $biblionumber=$query->param('biblionumber');
73 $biblionumber = HTML::Entities::encode($biblionumber);
74 my $title=$query->param('title');
75 my $bi=$query->param('bi');
76 $bi = $biblionumber unless $bi;
77 my $itemnumber = $query->param('itemnumber');
78 my $data = &GetBiblioData($biblionumber);
79 my $dewey = $data->{'dewey'};
80 my $showallitems = $query->param('showallitems');
82 #coping with subscriptions
83 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
85 # FIXME Dewey is a string, not a number, & we should use a function
87 # if ($dewey eq "000.") { $dewey = "";};
88 # if ($dewey < 10){$dewey='00'.$dewey;}
89 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
94 # $data->{'dewey'}=$dewey;
96 my $fw = GetFrameworkCode($biblionumber);
97 my @all_items= GetItemsInfo($biblionumber);
99 my $patron = Koha::Patrons->find( $loggedinuser );
100 for my $itm (@all_items) {
101 push @items, $itm unless ( $itm->{itemlost} &&
102 $patron->category->hidelostitems &&
104 ($itemnumber != $itm->{itemnumber}));
107 my $record=GetMarcBiblio({ biblionumber => $biblionumber });
109 output_and_exit( $query, $cookie, $template, 'unknown_biblio')
113 # adding items linked via host biblios
114 my @hostitems = GetHostItemsInfo($record);
117 push (@items,@hostitems);
120 my $biblio = Koha::Biblios->find( $biblionumber );
122 my $totalcount=@all_items;
123 my $showncount=@items;
124 my $hiddencount = $totalcount - $showncount;
125 $data->{'count'}=$totalcount;
126 $data->{'showncount'}=$showncount;
127 $data->{'hiddencount'}=$hiddencount; # can be zero
130 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
132 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
134 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
136 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
137 if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
138 foreach ( keys %{$data} ) {
139 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
142 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
143 foreach my $item (@items){
144 $item->{object} = Koha::Items->find( $item->{itemnumber} );
145 $item->{'collection'} = $ccodes->{ $item->{ccode} } if $ccodes && $item->{ccode} && exists $ccodes->{ $item->{ccode} };
146 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
147 $item->{'replacementprice'} = $item->{'replacementprice'};
148 if ( defined $item->{'copynumber'} ) {
149 $item->{'displaycopy'} = 1;
150 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
151 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
154 $item->{'copyvol'} = $item->{'copynumber'};
158 # item has a host number if its biblio number does not match the current bib
159 if ($item->{biblionumber} ne $biblionumber){
160 $item->{hostbiblionumber} = $item->{biblionumber};
161 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
164 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
165 $item->{'ordernumber'} = $order->{'ordernumber'};
166 $item->{'basketno'} = $order->{'basketno'};
167 $item->{'orderdate'} = $order->{'entrydate'};
168 if ($item->{'basketno'}){
169 my $basket = GetBasket($item->{'basketno'});
170 my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
171 $item->{'vendor'} = $bookseller->name;
173 $item->{'invoiceid'} = $order->{'invoiceid'};
174 if($item->{invoiceid}) {
175 my $invoice = GetInvoice($item->{invoiceid});
176 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
178 $item->{'datereceived'} = $order->{'datereceived'};
180 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
181 $item->{status_advisory} = 1;
185 if ( $item->{itemlost} ) {
186 my $accountlines = Koha::Account::Lines->search(
188 itemnumber => $item->{itemnumber},
189 debit_type_code => 'LOST',
190 status => [ undef, { '<>' => 'RETURNED' } ],
191 amountoutstanding => 0
194 order_by => { '-desc' => 'date' },
199 if ( my $accountline = $accountlines->next ) {
200 my $payment_offsets = Koha::Account::Offsets->search(
202 debit_id => $accountline->id,
203 credit_id => { '!=' => undef }, # it is not the debit itself
204 type => { '!=' => [ 'Writeoff', 'Forgiven' ] },
205 amount => { '<' => 0 } # credits are negative on the DB
207 { order_by => { '-desc' => 'created_on' } }
210 if ($payment_offsets->count) {
211 my $patron = $accountline->patron;
212 my $payment_offset = $payment_offsets->next;
213 $item->{paidfor} = { patron => $patron, created_on => $payment_offset->created_on };
218 if (C4::Context->preference("IndependentBranches")) {
220 my $userenv = C4::Context->userenv();
221 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
225 if ($item->{'datedue'}) {
231 if ( $item->{'borrowernumber'} ) {
232 my $curr_borrower = Koha::Patrons->find( $item->{borrowernumber} );
233 $item->{patron} = $curr_borrower;
237 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
239 $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
241 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
243 $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
245 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
247 $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
250 $template->param(count => $data->{'count'},
251 subscriptionsnumber => $subscriptionsnumber,
252 subscriptiontitle => $data->{title},
253 C4::Search::enabled_staff_search_views,
257 ITEM_DATA => \@items,
259 loggedinuser => $loggedinuser,
260 biblionumber => $biblionumber,
261 biblioitemnumber => $bi,
262 itemnumber => $itemnumber,
263 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
264 biblio => $biblio->unblessed,
266 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
267 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
269 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
270 my @deletedorders_using_biblio;
271 my @orders_using_biblio;
273 my @baskets_deletedorders;
275 foreach my $myorder (@allorders_using_biblio) {
276 my $basket = $myorder->{'basketno'};
277 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
278 push @deletedorders_using_biblio, $myorder;
279 unless (grep{ $_ eq $basket } @baskets_deletedorders){
280 push @baskets_deletedorders,$myorder->{'basketno'};
284 push @orders_using_biblio, $myorder;
285 unless (grep { $_ eq $basket } @baskets_orders){
286 push @baskets_orders,$myorder->{'basketno'};
291 my $count_orders_using_biblio = scalar @orders_using_biblio ;
292 $template->param (countorders => $count_orders_using_biblio);
294 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
295 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
297 my $holds = $biblio->holds;
298 $template->param( holdcount => $holds->count );
300 output_html_with_http_headers $query, $cookie, $template->output;