Bug 26352: Switch from using call() to call_recursive()
[koha.git] / circ / branchoverdues.pl
1 #!/usr/bin/perl
2
3 #
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20 use C4::Context;
21 use CGI qw ( -utf8 );
22 use C4::Output qw( output_html_with_http_headers );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Overdues qw( GetOverduesForBranch );
25 use C4::Biblio qw( GetMarcFromKohaField GetMarcStructure );
26 use C4::Koha qw( GetAuthorisedValues );
27 use Koha::DateUtils qw( dt_from_string output_pref );
28 use Koha::BiblioFrameworks;
29
30 =head1 branchoverdues.pl
31
32 This view is used to display all overdue items to the librarian.
33
34 It is automatically filtered by branch and can optionally be filtered
35 by item location.
36
37 =cut
38
39 my $input       = CGI->new;
40 my $dbh = C4::Context->dbh;
41
42 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
43         template_name   => "circ/branchoverdues.tt",
44         query           => $input,
45         type            => "intranet",
46         flagsrequired   => { circulate => "circulate_remaining_permissions" },
47 });
48
49 my $default = C4::Context->userenv->{'branch'};
50
51 # Deal with the vars recept from the template
52 my $borrowernumber = $input->param('borrowernumber');
53 my $itemnumber     = $input->param('itemnumber');
54 my $method         = $input->param('method');
55 my $overduelevel   = $input->param('overduelevel');
56 my $location       = $input->param('location');
57
58 # FIXME: better check that borrowernumber is defined and valid.
59 # FIXME: same for itemnumber and other variables passed in here.
60
61 my @overduesloop;
62 my @getoverdues = GetOverduesForBranch( $default, $location );
63 # search for location authorised value
64 my ($tag,$subfield) = GetMarcFromKohaField( 'items.location' );
65 my $tagslib = &GetMarcStructure(1,'');
66 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
67     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
68     for (@$values) { $_->{selected} = 1 if defined $location && $location eq $_->{authorised_value} }
69     $template->param(locationsloop => $values);
70 }
71 # now display infos
72 foreach my $num (@getoverdues) {
73     my %overdueforbranch;
74     my $dt = dt_from_string($num->{date_due}, 'sql');
75     $overdueforbranch{'date_due'}          = output_pref($dt);
76     $overdueforbranch{'title'}             = $num->{'title'};
77     $overdueforbranch{'subtitle'}          = $num->{'subtitle'};
78     $overdueforbranch{'medium'}            = $num->{'medium'};
79     $overdueforbranch{'part_number'}       = $num->{'part_number'};
80     $overdueforbranch{'part_name'}         = $num->{'part_name'};
81     $overdueforbranch{'description'}       = $num->{'description'};
82     $overdueforbranch{'barcode'}           = $num->{'barcode'};
83     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
84     $overdueforbranch{'author'}            = $num->{'author'};
85     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
86     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
87     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
88     $overdueforbranch{'borroweremail'}     = $num->{'email'};
89     $overdueforbranch{'homebranch'}        = $num->{'homebranch'};
90     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
91     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
92     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
93     $overdueforbranch{'cardnumber'}        = $num->{'cardnumber'};
94
95     push( @overduesloop, \%overdueforbranch );
96 }
97
98 # initiate the templates for the overdueloop
99 $template->param(
100     overduesloop => \@overduesloop,
101     location     => $location,
102 );
103
104 # Checking if there is a Fast Cataloging Framework
105 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
106
107 output_html_with_http_headers $input, $cookie, $template->output;