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 warnings; FIXME - Bug 2505
33 use C4::Members; # to use GetMember
34 use C4::Search; # enabled_staff_search_views
35 use C4::Members qw/GetHideLostItemsPreference/;
36 use C4::Reserves qw(GetReservesFromBiblionumber);
38 use Koha::Acquisition::Bookseller;
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 = GetMember('borrowernumber' => $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'},
63 my $hidepatronname = C4::Context->preference("HidePatronName");
67 my $biblionumber=$query->param('biblionumber');
68 my $title=$query->param('title');
69 my $bi=$query->param('bi');
70 $bi = $biblionumber unless $bi;
71 my $itemnumber = $query->param('itemnumber');
72 my $data = &GetBiblioData($biblionumber);
73 my $dewey = $data->{'dewey'};
74 my $showallitems = $query->param('showallitems');
76 #coping with subscriptions
77 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
79 # FIXME Dewey is a string, not a number, & we should use a function
81 # if ($dewey eq "000.") { $dewey = "";};
82 # if ($dewey < 10){$dewey='00'.$dewey;}
83 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
88 # $data->{'dewey'}=$dewey;
90 my $fw = GetFrameworkCode($biblionumber);
91 my @all_items= GetItemsInfo($biblionumber);
93 for my $itm (@all_items) {
94 push @items, $itm unless ( $itm->{itemlost} &&
95 GetHideLostItemsPreference($loggedinuser) &&
97 ($itemnumber != $itm->{itemnumber}));
100 my $record=GetMarcBiblio($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
119 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
120 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
121 my $itemtypes = GetItemTypes;
123 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
124 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
125 foreach ( keys %{$data} ) {
126 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
129 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
130 foreach my $item (@items){
131 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
132 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
133 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
134 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'};
135 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
136 if ( defined $item->{'copynumber'} ) {
137 $item->{'displaycopy'} = 1;
138 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
139 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
142 $item->{'copyvol'} = $item->{'copynumber'};
146 # item has a host number if its biblio number does not match the current bib
147 if ($item->{biblionumber} ne $biblionumber){
148 $item->{hostbiblionumber} = $item->{biblionumber};
149 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
152 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
153 $item->{'ordernumber'} = $order->{'ordernumber'};
154 $item->{'basketno'} = $order->{'basketno'};
155 $item->{'orderdate'} = $order->{'entrydate'};
156 if ($item->{'basketno'}){
157 my $basket = GetBasket($item->{'basketno'});
158 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
159 $item->{'vendor'} = $bookseller->{'name'};
161 $item->{'invoiceid'} = $order->{'invoiceid'};
162 if($item->{invoiceid}) {
163 my $invoice = GetInvoice($item->{invoiceid});
164 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
166 $item->{'datereceived'} = $order->{'datereceived'};
168 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
169 $item->{status_advisory} = 1;
172 if (C4::Context->preference("IndependentBranches")) {
174 my $userenv = C4::Context->userenv();
175 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
179 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
180 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
181 if ($item->{'datedue'}) {
187 unless ($hidepatronname) {
188 if ( $item->{'borrowernumber'} ) {
189 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
190 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
191 $item->{borrowersurname} = $curr_borrower->{'surname'};
196 $template->param(count => $data->{'count'},
197 subscriptionsnumber => $subscriptionsnumber,
198 subscriptiontitle => $data->{title},
199 C4::Search::enabled_staff_search_views,
203 ITEM_DATA => \@items,
205 loggedinuser => $loggedinuser,
206 biblionumber => $biblionumber,
207 biblioitemnumber => $bi,
208 itemnumber => $itemnumber,
209 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
210 subtitle => $subtitle,
211 hidepatronname => $hidepatronname,
213 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
214 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
216 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
217 my @deletedorders_using_biblio;
218 my @orders_using_biblio;
220 my @baskets_deletedorders;
222 foreach my $myorder (@allorders_using_biblio) {
223 my $basket = $myorder->{'basketno'};
224 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
225 push @deletedorders_using_biblio, $myorder;
226 unless (grep(/^$basket$/, @baskets_deletedorders)){
227 push @baskets_deletedorders,$myorder->{'basketno'};
231 push @orders_using_biblio, $myorder;
232 unless (grep(/^$basket$/, @baskets_orders)){
233 push @baskets_orders,$myorder->{'basketno'};
238 my $count_orders_using_biblio = scalar @orders_using_biblio ;
239 $template->param (countorders => $count_orders_using_biblio);
241 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
242 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
244 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
245 my $holdcount = scalar( @$holds );
246 $template->param( holdcount => scalar ( @$holds ) );
248 output_html_with_http_headers $query, $cookie, $template->output;