fix for bug 2371: Change fine block message behavior...
[koha.git] / reports / reservereport.pl
blobfa389647f6decef80176553d4e89cfd51834acc0
1 #!/usr/bin/perl
3 #written 26/4/2000
4 #script to display reports
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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.
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.
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
23 # script now takes a branchcode arg
24 # eg: http://koha.rangitikei.katipo.co.nz/cgi-bin/koha/reports/reservereport.pl?branch=BL
26 use strict;
27 use C4::Stats;
28 use C4::Dates qw/format_date/;
29 use CGI;
30 use C4::Output;
31 use C4::Branch; # GetBranches
32 use C4::Auth;
33 use C4::Koha;
34 use C4::Items;
37 my $input = new CGI;
38 my $time = $input->param('time');
39 my $branch = $input->param('branch');
40 my $sort = $input->param('sort');
42 if (!$branch) {
43 $branch = "ALL";
46 my $branches=GetBranches();
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
50 template_name => "reports/reservereport.tmpl",
51 query => $input,
52 type => "intranet",
53 authnotrequired => 0,
54 flagsrequired => { reports => 1 },
55 debug => 1,
59 # building up branches dropdown box
61 my %branchall;
62 my $branchcount=0;
63 my @branchloop;
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);
73 my ( $count, $data ) = unfilledreserves($branch);
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' ) {
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 = GetItemsInfo($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';
106 else {
107 $line{'status'} = "On shelf at $item->{'branchname'}";
112 else {
113 $onissue = 1;
116 if ($onissue) {
117 $line{'status'} = 'On Issue';
120 else {
121 $line{'status'}="Waiting for pickup";
125 push( @dataloop, \%line );
128 if ($sort eq 'name'){
129 @dataloop = sort {$a->{'surname'} cmp $b->{'surname'}} @dataloop;
131 elsif ($sort eq 'date'){
132 @dataloop = sort {$a->{'sortdate'} cmp $b->{'sortdate'}} @dataloop;
134 elsif ($sort eq 'title'){
135 @dataloop = sort {$a->{'title'} cmp $b->{'title'}} @dataloop;
137 else {
138 @dataloop = sort {$a->{'status'} cmp $b->{'status'}} @dataloop;
142 $template->param(
143 count => $count,
144 dataloop => \@dataloop,
145 branchcode => $branch,
146 branchloop => \@branchloop
150 output_html_with_http_headers $input, $cookie, $template->output;