Revert "Bug 6554 - make Koha internally utf-8 clean"
[koha.git] / reports / reservereport.pl
1 #!/usr/bin/perl
2
3 #written 26/4/2000
4 #script to display reports
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 # script now takes a branchcode arg
24 # eg: http://koha.rangitikei.katipo.co.nz/cgi-bin/koha/reports/reservereport.pl?branch=BL
25
26 use strict;
27 #use warnings; FIXME - Bug 2505
28 use C4::Stats;
29 use C4::Dates qw/format_date/;
30 use CGI;
31 use C4::Output;
32 use C4::Branch; # GetBranches
33 use C4::Auth;
34 use C4::Koha;
35 use C4::Items;
36
37
38 my $input = new CGI;
39 my $time  = $input->param('time');
40 my $branch = $input->param('branch');
41 my $sort = $input->param('sort');
42
43 if (!$branch) {
44     $branch = "ALL";
45 }
46
47 my $branches=GetBranches();
48
49 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
50     {
51         template_name   => "reports/reservereport.tmpl",
52         query           => $input,
53         type            => "intranet",
54         authnotrequired => 0,
55         flagsrequired   => { reports => '*' },
56         debug           => 1,
57     }
58 );
59
60 # building up branches dropdown box
61
62 my %branchall;
63 my $branchcount=0;
64 my @branchloop;
65
66 foreach my $br (keys %$branches) {
67         $branchcount++;
68             my %branch1;
69             $branch1{name}=$branches->{$br}->{'branchname'};
70             $branch1{value}=$br;
71         push(@branchloop,\%branch1);
72     }  
73
74 my ( $count, $data ) = unfilledreserves($branch);
75
76 my @dataloop;
77 my $toggle;
78 for ( my $i = 0 ; $i < $count ; $i++ ) {
79     my %line;
80         $toggle = $i%2 ? 0 : 1;
81         $line{'borrowernumber'} = $data->[$i]->{'borrowernumber'};
82         $line{'surname'} = $data->[$i]->{'surname'};
83         $line{'firstname'} = $data->[$i]->{'firstname'};
84         $line{'sortdate'}       = $data->[$i]->{'reservedate'};
85         $line{'reservedate'}    = format_date($data->[$i]->{'reservedate'});
86         $line{'biblionumber'} = $data->[$i]->{'biblionumber'};
87         $line{'title'} = $data->[$i]->{'title'};
88         $line{'classification'} = $data->[$i]->{'classification'};
89         $line{'dewey'} = $data->[$i]->{'dewey'};
90         $line{'status'} = $data->[$i]->{'found'};
91         $line{'branchcode'} = $data->[$i]->{'branchcode'};
92         $line{'toggle'} = $toggle;
93      if ( $line{'status'} ne 'W' ) {
94          
95          # its not waiting, we need to find if its on issue, or on the shelf
96          # FIXME still need to shift the text to the template so its translateable
97          if ( $data->[$i]) {
98              # find if its on issue
99              my @items = GetItemsInfo( $line{biblionumber} );
100              my $onissue = 0;
101              foreach my $item (@items) {
102                  if ( $item->{'datedue'} eq 'Reserved' ) {
103                      $onissue = 0;
104                      if ($item->{'branchname'} eq ''){
105                          $line{'status'}='In Transit';
106                      }
107                      else {                      
108                          $line{'status'} = "On shelf at $item->{'branchname'}";
109                      }
110                      
111                  }
112                  
113                  else {
114                      $onissue = 1;
115                  }
116              }           
117              if ($onissue) {
118                  $line{'status'} = 'On Issue';
119              }
120          }
121          else {
122              $line{'status'}="Waiting for pickup";
123              
124          }
125      }
126     push( @dataloop, \%line );
127 }
128
129 if ($sort eq 'name'){ 
130     @dataloop = sort {$a->{'surname'} cmp $b->{'surname'}} @dataloop;                                                                                         
131 }                                                                                                                                                             
132 elsif ($sort eq 'date'){                                                                                                                                      
133     @dataloop = sort {$a->{'sortdate'} cmp $b->{'sortdate'}} @dataloop;                                                                                       
134 }                                                                                                                                                             
135 elsif ($sort eq 'title'){                                                                                                                                     
136     @dataloop = sort {$a->{'title'} cmp $b->{'title'}} @dataloop;                                                                                             
137 }                                                                                                                                                             
138 else {                                                                                                                                                        
139     @dataloop = sort {$a->{'status'} cmp $b->{'status'}} @dataloop;                                                                                           
140 }                                                                                                                                                             
141
142
143 $template->param(
144     count    => $count,
145     dataloop => \@dataloop,
146     branchcode => $branch,
147     branchloop => \@branchloop
148     
149 );
150
151 output_html_with_http_headers $input, $cookie, $template->output;