Bug 32482: (follow-up) Add markup comments
[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 qw( dt_from_string );
26 use Koha::Patrons;
27
28 my $query = CGI->new;
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         flagsrequired   => { recalls => "manage_recalls" },
35         debug           => 1,
36     }
37 );
38
39 my $op = $query->param('op') || 'list';
40
41 if ( $op eq 'modify' ) {
42     my $expire = $query->param('expire') || '';
43     my $revert = $query->param('revert') || '';
44     my $recall_id = $query->param('recall_id');
45     if ( $expire ) {
46         Koha::Recalls->find( $recall_id )->set_expired({ interface => 'INTRANET' });
47     } elsif ( $revert ) {
48         Koha::Recalls->find( $recall_id )->revert_waiting;
49     }
50     $op = 'list';
51 }
52
53 if ( $op eq 'list' ) {
54     my @recalls = Koha::Recalls->search({ status => 'waiting' })->as_list;
55     my $borrower = Koha::Patrons->find( $loggedinuser );
56     my @over;
57     my $maxdelay = C4::Context->preference('RecallsMaxPickUpDelay') || 7;
58     my $today = dt_from_string();
59     foreach my $r ( @recalls ){
60         my $lastwaitingday = dt_from_string( $r->waiting_date )->add( days => $maxdelay );
61         if ( $today > $lastwaitingday ){
62             push @over, $r;
63         }
64     }
65     $template->param(
66         recalls => \@recalls,
67         over => \@over,
68     );
69 }
70
71 # Checking if there is a Fast Cataloging Framework
72 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
73
74 # writing the template
75 output_html_with_http_headers $query, $cookie, $template->output;