Bug 19532: Recalls on intranet
[koha.git] / recalls / recalls_waiting.pl
1 #!/usr/bin/perl
2
3 # Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
4 #
5 # 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.
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 CGI qw ( -utf8 );
21 use C4::Auth qw( get_template_and_user );
22 use C4::Output qw( output_html_with_http_headers );
23 use Koha::Recalls;
24 use Koha::BiblioFrameworks;
25 use Koha::DateUtils;
26 use Koha::Patrons;
27
28 my $query = new CGI;
29 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
30     {
31         template_name   => "recalls/recalls_waiting.tt",
32         query           => $query,
33         type            => "intranet",
34         authnotrequired => 0,
35         flagsrequired   => { recalls => "manage_recalls" },
36         debug           => 1,
37     }
38 );
39
40 my $op = $query->param('op') || 'list';
41
42 if ( $op eq 'modify' ) {
43     my $expire = $query->param('expire') || '';
44     my $revert = $query->param('revert') || '';
45     my $recall_id = $query->param('recall_id');
46     if ( $expire ) {
47         Koha::Recalls->find( $recall_id )->set_expired({ interface => 'INTRANET' });
48     } elsif ( $revert ) {
49         Koha::Recalls->find( $recall_id )->revert_waiting;
50     }
51     $op = 'list';
52 }
53
54 if ( $op eq 'list' ) {
55     my @recalls = Koha::Recalls->search({ status => 'W' });
56     my $borrower = Koha::Patrons->find( $loggedinuser );
57     my @over;
58     my $maxdelay = C4::Context->preference('RecallsMaxPickUpDelay') || 7;
59     my $today = dt_from_string();
60     foreach my $r ( @recalls ){
61         my $lastwaitingday = dt_from_string( $r->waitingdate )->add( days => $maxdelay );
62         if ( $today > $lastwaitingday ){
63             push @over, $r;
64         }
65     }
66     $template->param(
67         recalls => \@recalls,
68         over => \@over,
69     );
70 }
71
72 # Checking if there is a Fast Cataloging Framework
73 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
74
75 # writing the template
76 output_html_with_http_headers $query, $cookie, $template->output;