Bug 21777: Add a regression test
[koha.git] / circ / branchoverdues.pl
blobd4c20cbb1861fe26b0c2ba588ec6cac4f9b609e5
1 #!/usr/bin/perl
4 # This file is part of Koha.
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.
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.
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>.
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 C4::Debug;
28 use Koha::DateUtils;
29 use Koha::BiblioFrameworks;
30 use Data::Dumper;
32 =head1 branchoverdues.pl
34 this module is a new interface, allow to the librarian to check all items on overdues (based on the acountlines type 'FU' )
35 this interface is filtered by branches (automatically), and by location (optional) ....
37 =cut
39 my $input = new CGI;
40 my $dbh = C4::Context->dbh;
42 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
43 template_name => "circ/branchoverdues.tt",
44 query => $input,
45 type => "intranet",
46 authnotrequired => 0,
47 flagsrequired => { circulate => "circulate_remaining_permissions" },
48 debug => 1,
49 });
51 my $default = C4::Context->userenv->{'branch'};
53 # Deal with the vars recept from the template
54 my $borrowernumber = $input->param('borrowernumber');
55 my $itemnumber = $input->param('itemnumber');
56 my $method = $input->param('method');
57 my $overduelevel = $input->param('overduelevel');
58 my $location = $input->param('location');
60 # FIXME: better check that borrowernumber is defined and valid.
61 # FIXME: same for itemnumber and other variables passed in here.
63 my @overduesloop;
64 my @getoverdues = GetOverduesForBranch( $default, $location );
65 $debug and warn "HERE : $default / $location" . Dumper(@getoverdues);
66 # search for location authorised value
67 my ($tag,$subfield) = GetMarcFromKohaField('items.location','');
68 my $tagslib = &GetMarcStructure(1,'');
69 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
70 my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
71 for (@$values) { $_->{selected} = 1 if $location eq $_->{authorised_value} }
72 $template->param(locationsloop => $values);
74 # now display infos
75 foreach my $num (@getoverdues) {
76 my %overdueforbranch;
77 my $record = GetMarcBiblio({ biblionumber => $num->{biblionumber} });
78 if ($record){
79 $overdueforbranch{'subtitle'} = GetRecordValue('subtitle',$record,'')->[0]->{subfield};
81 my $dt = dt_from_string($num->{date_due}, 'sql');
82 $overdueforbranch{'date_due'} = output_pref($dt);
83 $overdueforbranch{'title'} = $num->{'title'};
84 $overdueforbranch{'description'} = $num->{'description'};
85 $overdueforbranch{'barcode'} = $num->{'barcode'};
86 $overdueforbranch{'biblionumber'} = $num->{'biblionumber'};
87 $overdueforbranch{'author'} = $num->{'author'};
88 $overdueforbranch{'borrowersurname'} = $num->{'surname'};
89 $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
90 $overdueforbranch{'borrowerphone'} = $num->{'phone'};
91 $overdueforbranch{'borroweremail'} = $num->{'email'};
92 $overdueforbranch{'homebranch'} = $num->{'homebranch'};
93 $overdueforbranch{'itemcallnumber'} = $num->{'itemcallnumber'};
94 $overdueforbranch{'borrowernumber'} = $num->{'borrowernumber'};
95 $overdueforbranch{'itemnumber'} = $num->{'itemnumber'};
96 $overdueforbranch{'cardnumber'} = $num->{'cardnumber'};
98 push( @overduesloop, \%overdueforbranch );
101 # initiate the templates for the overdueloop
102 $template->param(
103 overduesloop => \@overduesloop,
104 location => $location,
107 # Checking if there is a Fast Cataloging Framework
108 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
110 output_html_with_http_headers $input, $cookie, $template->output;