422b32cda6045d66ac5a55a3d63f6b1a2919074b
[srvgit] / 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;
23 use C4::Auth;
24 use C4::Overdues;
25 use C4::Biblio;
26 use C4::Koha;
27 use Koha::DateUtils;
28 use Koha::BiblioFrameworks;
29 use Data::Dumper;
30
31 =head1 branchoverdues.pl
32
33 This view is used to display all overdue items to the librarian.
34
35 It is automatically filtered by branch and can optionally be filtered
36 by item location.
37
38 =cut
39
40 my $input       = CGI->new;
41 my $dbh = C4::Context->dbh;
42
43 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
44         template_name   => "circ/branchoverdues.tt",
45         query           => $input,
46         type            => "intranet",
47         flagsrequired   => { circulate => "circulate_remaining_permissions" },
48 });
49
50 my $default = C4::Context->userenv->{'branch'};
51
52 # Deal with the vars recept from the template
53 my $borrowernumber = $input->param('borrowernumber');
54 my $itemnumber     = $input->param('itemnumber');
55 my $method         = $input->param('method');
56 my $overduelevel   = $input->param('overduelevel');
57 my $location       = $input->param('location');
58
59 # FIXME: better check that borrowernumber is defined and valid.
60 # FIXME: same for itemnumber and other variables passed in here.
61
62 my @overduesloop;
63 my @getoverdues = GetOverduesForBranch( $default, $location );
64 # search for location authorised value
65 my ($tag,$subfield) = GetMarcFromKohaField( 'items.location' );
66 my $tagslib = &GetMarcStructure(1,'');
67 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
68     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
69     for (@$values) { $_->{selected} = 1 if defined $location && $location eq $_->{authorised_value} }
70     $template->param(locationsloop => $values);
71 }
72 # now display infos
73 foreach my $num (@getoverdues) {
74     my %overdueforbranch;
75     my $dt = dt_from_string($num->{date_due}, 'sql');
76     $overdueforbranch{'date_due'}          = output_pref($dt);
77     $overdueforbranch{'title'}             = $num->{'title'};
78     $overdueforbranch{'subtitle'}          = $num->{'subtitle'};
79     $overdueforbranch{'medium'}            = $num->{'medium'};
80     $overdueforbranch{'part_number'}       = $num->{'part_number'};
81     $overdueforbranch{'part_name'}         = $num->{'part_name'};
82     $overdueforbranch{'description'}       = $num->{'description'};
83     $overdueforbranch{'barcode'}           = $num->{'barcode'};
84     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
85     $overdueforbranch{'author'}            = $num->{'author'};
86     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
87     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
88     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
89     $overdueforbranch{'borroweremail'}     = $num->{'email'};
90     $overdueforbranch{'homebranch'}        = $num->{'homebranch'};
91     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
92     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
93     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
94     $overdueforbranch{'cardnumber'}        = $num->{'cardnumber'};
95
96     push( @overduesloop, \%overdueforbranch );
97 }
98
99 # initiate the templates for the overdueloop
100 $template->param(
101     overduesloop => \@overduesloop,
102     location     => $location,
103 );
104
105 # Checking if there is a Fast Cataloging Framework
106 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
107
108 output_html_with_http_headers $input, $cookie, $template->output;