Bug 17583: Make sure we are comparing 2 dates
[koha.git] / catalogue / moredetail.pl
blob1d50d504b6534daa5c8a78153703e66de59a54e4
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 HTML::Entities;
27 use C4::Biblio;
28 use C4::Items;
29 use C4::Acquisition;
30 use C4::Output;
31 use C4::Auth;
32 use C4::Serials;
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;
39 use Koha::AuthorisedValues;
40 use Koha::DateUtils;
41 use Koha::Items;
43 my $query=new CGI;
45 my ($template, $loggedinuser, $cookie) = get_template_and_user(
47 template_name => 'catalogue/moredetail.tt',
48 query => $query,
49 type => "intranet",
50 authnotrequired => 0,
51 flagsrequired => { catalogue => 1 },
55 if($query->cookie("holdfor")){
56 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
57 $template->param(
58 holdfor => $query->cookie("holdfor"),
59 holdfor_surname => $holdfor_patron->{'surname'},
60 holdfor_firstname => $holdfor_patron->{'firstname'},
61 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
65 my $hidepatronname = C4::Context->preference("HidePatronName");
67 # get variables
69 my $biblionumber=$query->param('biblionumber');
70 $biblionumber = HTML::Entities::encode($biblionumber);
71 my $title=$query->param('title');
72 my $bi=$query->param('bi');
73 $bi = $biblionumber unless $bi;
74 my $itemnumber = $query->param('itemnumber');
75 my $data = &GetBiblioData($biblionumber);
76 my $dewey = $data->{'dewey'};
77 my $showallitems = $query->param('showallitems');
79 #coping with subscriptions
80 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
82 # FIXME Dewey is a string, not a number, & we should use a function
83 # $dewey =~ s/0+$//;
84 # if ($dewey eq "000.") { $dewey = "";};
85 # if ($dewey < 10){$dewey='00'.$dewey;}
86 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
87 # if ($dewey <= 0){
88 # $dewey='';
89 # }
90 # $dewey=~ s/\.$//;
91 # $data->{'dewey'}=$dewey;
93 my $fw = GetFrameworkCode($biblionumber);
94 my @all_items= GetItemsInfo($biblionumber);
95 my @items;
96 for my $itm (@all_items) {
97 push @items, $itm unless ( $itm->{itemlost} &&
98 GetHideLostItemsPreference($loggedinuser) &&
99 !$showallitems &&
100 ($itemnumber != $itm->{itemnumber}));
103 my $record=GetMarcBiblio($biblionumber);
105 my $hostrecords;
106 # adding items linked via host biblios
107 my @hostitems = GetHostItemsInfo($record);
108 if (@hostitems){
109 $hostrecords =1;
110 push (@items,@hostitems);
113 my $subtitle = GetRecordValue('subtitle', $record, $fw);
115 my $totalcount=@all_items;
116 my $showncount=@items;
117 my $hiddencount = $totalcount - $showncount;
118 $data->{'count'}=$totalcount;
119 $data->{'showncount'}=$showncount;
120 $data->{'hiddencount'}=$hiddencount; # can be zero
122 my $ccodes =
123 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
124 my $copynumbers =
125 { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
126 my $itemtypes = GetItemTypes;
128 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
129 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
130 foreach ( keys %{$data} ) {
131 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
134 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
135 foreach my $item (@items){
136 $item->{object} = Koha::Items->find( $item->{itemnumber} );
137 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
138 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'};
139 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
140 if ( defined $item->{'copynumber'} ) {
141 $item->{'displaycopy'} = 1;
142 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
143 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
145 else {
146 $item->{'copyvol'} = $item->{'copynumber'};
150 # item has a host number if its biblio number does not match the current bib
151 if ($item->{biblionumber} ne $biblionumber){
152 $item->{hostbiblionumber} = $item->{biblionumber};
153 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
156 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
157 $item->{'ordernumber'} = $order->{'ordernumber'};
158 $item->{'basketno'} = $order->{'basketno'};
159 $item->{'orderdate'} = $order->{'entrydate'};
160 if ($item->{'basketno'}){
161 my $basket = GetBasket($item->{'basketno'});
162 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
163 $item->{'vendor'} = $bookseller->{'name'};
165 $item->{'invoiceid'} = $order->{'invoiceid'};
166 if($item->{invoiceid}) {
167 my $invoice = GetInvoice($item->{invoiceid});
168 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
170 $item->{'datereceived'} = $order->{'datereceived'};
172 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
173 $item->{status_advisory} = 1;
176 if (C4::Context->preference("IndependentBranches")) {
177 #verifying rights
178 my $userenv = C4::Context->userenv();
179 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
180 $item->{'nomod'}=1;
183 if ($item->{'datedue'}) {
184 $item->{'issue'}= 1;
185 } else {
186 $item->{'issue'}= 0;
189 unless ($hidepatronname) {
190 if ( $item->{'borrowernumber'} ) {
191 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
192 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
193 $item->{borrowersurname} = $curr_borrower->{'surname'};
199 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => { not => undef } });
200 if ( $mss->count ) {
201 $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
203 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => { not => undef } });
204 if ( $mss->count ) {
205 $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
207 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => { not => undef } });
208 if ( $mss->count ) {
209 $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
212 $template->param(count => $data->{'count'},
213 subscriptionsnumber => $subscriptionsnumber,
214 subscriptiontitle => $data->{title},
215 C4::Search::enabled_staff_search_views,
218 $template->param(
219 ITEM_DATA => \@items,
220 moredetailview => 1,
221 loggedinuser => $loggedinuser,
222 biblionumber => $biblionumber,
223 biblioitemnumber => $bi,
224 itemnumber => $itemnumber,
225 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
226 subtitle => $subtitle,
227 hidepatronname => $hidepatronname,
229 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
230 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
232 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
233 my @deletedorders_using_biblio;
234 my @orders_using_biblio;
235 my @baskets_orders;
236 my @baskets_deletedorders;
238 foreach my $myorder (@allorders_using_biblio) {
239 my $basket = $myorder->{'basketno'};
240 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
241 push @deletedorders_using_biblio, $myorder;
242 unless (grep(/^$basket$/, @baskets_deletedorders)){
243 push @baskets_deletedorders,$myorder->{'basketno'};
246 else {
247 push @orders_using_biblio, $myorder;
248 unless (grep(/^$basket$/, @baskets_orders)){
249 push @baskets_orders,$myorder->{'basketno'};
254 my $count_orders_using_biblio = scalar @orders_using_biblio ;
255 $template->param (countorders => $count_orders_using_biblio);
257 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
258 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
260 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
261 my $holdcount = scalar( @$holds );
262 $template->param( holdcount => scalar ( @$holds ) );
264 output_html_with_http_headers $query, $cookie, $template->output;