sub getbranches renamed to GetBranches according to the coding guidelines
[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 with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 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 C4::Stats;
28 use C4::Date;
29 use CGI;
30 use C4::Output;
31 use HTML::Template;
32 use C4::Auth;
33 use C4::Interface::CGI::Output;
34 use C4::Koha;
35
36
37 my $input = new CGI;
38 my $time  = $input->param('time');
39 my $branch = $input->param('branch');
40 my $sort = $input->param('sort');
41
42 if (!$branch) {
43     $branch = "ALL";
44 }
45
46 my $branches=GetBranches();
47
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49     {
50         template_name   => "reports/reservereport.tmpl",
51         query           => $input,
52         type            => "intranet",
53         authnotrequired => 0,
54         flagsrequired   => { editcatalogue => 1 },
55         debug           => 1,
56     }
57 );
58
59 # building up branches dropdown box
60
61 my %branchall;
62 my $branchcount=0;
63 my @branchloop;
64
65 foreach my $br (keys %$branches) {
66         $branchcount++;
67             my %branch1;
68             $branch1{name}=$branches->{$br}->{'branchname'};
69             $branch1{value}=$br;
70         push(@branchloop,\%branch1);
71     }  
72
73 my ( $count, $data ) = unfilledreserves($branch);
74
75 my @dataloop;
76 my $toggle;
77 for ( my $i = 0 ; $i < $count ; $i++ ) {
78     my %line;
79         $toggle = $i%2 ? 0 : 1;
80         $line{'borrowernumber'} = $data->[$i]->{'borrowernumber'};
81         $line{'surname'} = $data->[$i]->{'surname'};
82         $line{'firstname'} = $data->[$i]->{'firstname'};
83         $line{'sortdate'}       = $data->[$i]->{'reservedate'};
84         $line{'reservedate'}    = format_date($data->[$i]->{'reservedate'});
85         $line{'biblionumber'} = $data->[$i]->{'biblionumber'};
86         $line{'title'} = $data->[$i]->{'title'};
87         $line{'classification'} = $data->[$i]->{'classification'};
88         $line{'dewey'} = $data->[$i]->{'dewey'};
89         $line{'status'} = $data->[$i]->{'found'};
90         $line{'branchcode'} = $data->[$i]->{'branchcode'};
91         $line{'toggle'} = $toggle;
92      if ( $line{'status'} ne 'W' ) {
93          
94          # its not waiting, we need to find if its on issue, or on the shelf
95          # FIXME still need to shift the text to the template so its translateable
96          if ( $data->[$i]) {
97              # find if its on issue
98              my @items = &ItemInfo( undef, $line{'biblionumber'}, 'intra' );
99              my $onissue = 0;
100              foreach my $item (@items) {
101                  if ( $item->{'datedue'} eq 'Reserved' ) {
102                      $onissue = 0;
103                      if ($item->{'branchname'} eq ''){
104                          $line{'status'}='In Transit';
105                      }
106                      else {                      
107                          $line{'status'} = "On shelf at $item->{'branchname'}";
108                      }
109                      
110                  }
111                  
112                  else {
113                      $onissue = 1;
114                  }
115              }           
116              if ($onissue) {
117                  $line{'status'} = 'On Issue';
118              }
119          }
120          else {
121              $line{'status'}="Waiting for pickup";
122              
123          }
124      }
125     push( @dataloop, \%line );
126 }
127
128 if ($sort eq 'name'){ 
129     @dataloop = sort {$a->{'surname'} cmp $b->{'surname'}} @dataloop;                                                                                         
130 }                                                                                                                                                             
131 elsif ($sort eq 'date'){                                                                                                                                      
132     @dataloop = sort {$a->{'sortdate'} cmp $b->{'sortdate'}} @dataloop;                                                                                       
133 }                                                                                                                                                             
134 elsif ($sort eq 'title'){                                                                                                                                     
135     @dataloop = sort {$a->{'title'} cmp $b->{'title'}} @dataloop;                                                                                             
136 }                                                                                                                                                             
137 else {                                                                                                                                                        
138     @dataloop = sort {$a->{'status'} cmp $b->{'status'}} @dataloop;                                                                                           
139 }                                                                                                                                                             
140
141
142 $template->param(
143     count    => $count,
144     dataloop => \@dataloop,
145     branchcode => $branch,
146     branchloop => \@branchloop
147     
148 );
149
150 output_html_with_http_headers $input, $cookie, $template->output;