Bug 14310 [QA Follow] - Remove FIXME, add explanation comment instead
[koha.git] / catalogue / moredetail.pl
blob1b33f75e861cb0f8b8a571b6e2569dc63c06f629
1 #!/usr/bin/perl
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>.
22 use strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Koha;
25 use CGI qw ( -utf8 );
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Branch;
29 use C4::Acquisition;
30 use C4::Output;
31 use C4::Auth;
32 use C4::Serials;
33 use C4::Circulation; # to use itemissues
34 use C4::Members; # to use GetMember
35 use C4::Search; # enabled_staff_search_views
36 use C4::Members qw/GetHideLostItemsPreference/;
37 use C4::Reserves qw(GetReservesFromBiblionumber);
39 use Koha::Acquisition::Bookseller;
40 use Koha::DateUtils;
41 use Koha::Items;
43 my $query=new CGI;
45 # FIXME subject is not exported to the template?
46 my $subject=$query->param('subject');
48 # if its a subject we need to use the subject.tt
49 my ($template, $loggedinuser, $cookie) = get_template_and_user(
51 template_name => ( $subject
52 ? 'catalogue/subject.tt'
53 : 'catalogue/moredetail.tt'),
54 query => $query,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => { catalogue => 1 },
61 if($query->cookie("holdfor")){
62 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
63 $template->param(
64 holdfor => $query->cookie("holdfor"),
65 holdfor_surname => $holdfor_patron->{'surname'},
66 holdfor_firstname => $holdfor_patron->{'firstname'},
67 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
71 my $hidepatronname = C4::Context->preference("HidePatronName");
73 # get variables
75 my $biblionumber=$query->param('biblionumber');
76 my $title=$query->param('title');
77 my $bi=$query->param('bi');
78 $bi = $biblionumber unless $bi;
79 my $itemnumber = $query->param('itemnumber');
80 my $data = &GetBiblioData($biblionumber);
81 my $dewey = $data->{'dewey'};
82 my $showallitems = $query->param('showallitems');
84 #coping with subscriptions
85 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
87 # FIXME Dewey is a string, not a number, & we should use a function
88 # $dewey =~ s/0+$//;
89 # if ($dewey eq "000.") { $dewey = "";};
90 # if ($dewey < 10){$dewey='00'.$dewey;}
91 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
92 # if ($dewey <= 0){
93 # $dewey='';
94 # }
95 # $dewey=~ s/\.$//;
96 # $data->{'dewey'}=$dewey;
98 my $fw = GetFrameworkCode($biblionumber);
99 my @all_items= GetItemsInfo($biblionumber);
100 my @items;
101 for my $itm (@all_items) {
102 push @items, $itm unless ( $itm->{itemlost} &&
103 GetHideLostItemsPreference($loggedinuser) &&
104 !$showallitems &&
105 ($itemnumber != $itm->{itemnumber}));
108 my $record=GetMarcBiblio($biblionumber);
110 my $hostrecords;
111 # adding items linked via host biblios
112 my @hostitems = GetHostItemsInfo($record);
113 if (@hostitems){
114 $hostrecords =1;
115 push (@items,@hostitems);
118 my $subtitle = GetRecordValue('subtitle', $record, $fw);
120 my $totalcount=@all_items;
121 my $showncount=@items;
122 my $hiddencount = $totalcount - $showncount;
123 $data->{'count'}=$totalcount;
124 $data->{'showncount'}=$showncount;
125 $data->{'hiddencount'}=$hiddencount; # can be zero
127 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
128 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
129 my $itemtypes = GetItemTypes;
131 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
132 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
133 foreach ( keys %{$data} ) {
134 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
137 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
138 foreach my $item (@items){
139 $item->{object} = Koha::Items->find( $item->{itemnumber} );
140 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
141 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
142 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
143 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'};
144 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
145 if ( defined $item->{'copynumber'} ) {
146 $item->{'displaycopy'} = 1;
147 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
148 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
150 else {
151 $item->{'copyvol'} = $item->{'copynumber'};
155 # item has a host number if its biblio number does not match the current bib
156 if ($item->{biblionumber} ne $biblionumber){
157 $item->{hostbiblionumber} = $item->{biblionumber};
158 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
161 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
162 $item->{'ordernumber'} = $order->{'ordernumber'};
163 $item->{'basketno'} = $order->{'basketno'};
164 $item->{'orderdate'} = $order->{'entrydate'};
165 if ($item->{'basketno'}){
166 my $basket = GetBasket($item->{'basketno'});
167 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
168 $item->{'vendor'} = $bookseller->{'name'};
170 $item->{'invoiceid'} = $order->{'invoiceid'};
171 if($item->{invoiceid}) {
172 my $invoice = GetInvoice($item->{invoiceid});
173 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
175 $item->{'datereceived'} = $order->{'datereceived'};
177 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
178 $item->{status_advisory} = 1;
181 if (C4::Context->preference("IndependentBranches")) {
182 #verifying rights
183 my $userenv = C4::Context->userenv();
184 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
185 $item->{'nomod'}=1;
188 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
189 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
190 if ($item->{'datedue'}) {
191 $item->{'issue'}= 1;
192 } else {
193 $item->{'issue'}= 0;
196 unless ($hidepatronname) {
197 if ( $item->{'borrowernumber'} ) {
198 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
199 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
200 $item->{borrowersurname} = $curr_borrower->{'surname'};
205 $template->param(count => $data->{'count'},
206 subscriptionsnumber => $subscriptionsnumber,
207 subscriptiontitle => $data->{title},
208 C4::Search::enabled_staff_search_views,
211 $template->param(
212 ITEM_DATA => \@items,
213 moredetailview => 1,
214 loggedinuser => $loggedinuser,
215 biblionumber => $biblionumber,
216 biblioitemnumber => $bi,
217 itemnumber => $itemnumber,
218 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
219 subtitle => $subtitle,
220 hidepatronname => $hidepatronname,
222 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
223 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
225 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
226 my @deletedorders_using_biblio;
227 my @orders_using_biblio;
228 my @baskets_orders;
229 my @baskets_deletedorders;
231 foreach my $myorder (@allorders_using_biblio) {
232 my $basket = $myorder->{'basketno'};
233 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
234 push @deletedorders_using_biblio, $myorder;
235 unless (grep(/^$basket$/, @baskets_deletedorders)){
236 push @baskets_deletedorders,$myorder->{'basketno'};
239 else {
240 push @orders_using_biblio, $myorder;
241 unless (grep(/^$basket$/, @baskets_orders)){
242 push @baskets_orders,$myorder->{'basketno'};
247 my $count_orders_using_biblio = scalar @orders_using_biblio ;
248 $template->param (countorders => $count_orders_using_biblio);
250 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
251 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
253 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
254 my $holdcount = scalar( @$holds );
255 $template->param( holdcount => scalar ( @$holds ) );
257 output_html_with_http_headers $query, $cookie, $template->output;