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