Bug 17132 - Availability search broken when using Elastic
[koha.git] / serials / checkexpiration.pl
blob7e2eed483c4e39b55c61b6baebc9c080f382cb49
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>.
20 =head1 NAME
22 checkexpiration.pl
24 =head1 DESCRIPTION
26 This script check what subscription will expire before C<$datenumber $datelimit>
28 =head1 PARAMETERS
30 =over 4
32 =item title
33 To filter subscription on title
35 =item issn
36 To filter subscription on issn
38 =item date
39 The date to filter on.
41 =back
43 =cut
45 use strict;
46 use warnings;
47 use CGI qw ( -utf8 );
48 use C4::Auth;
49 use C4::Serials; # GetExpirationDate
50 use C4::Output;
51 use C4::Context;
52 use Koha::DateUtils;
54 use DateTime;
56 my $query = new CGI;
58 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user (
60 template_name => "serials/checkexpiration.tt",
61 query => $query,
62 type => "intranet",
63 authnotrequired => 0,
64 flagsrequired => { serials => 'check_expiration' },
65 debug => 1,
69 my $title = $query->param('title');
70 my $issn = $query->param('issn');
71 my $branch = $query->param('branch');
72 my $date = $query->param('date');
73 $date = eval { dt_from_string( scalar $query->param('date') ) } if $date;
75 if ($date) {
76 my @subscriptions = SearchSubscriptions({ title => $title, issn => $issn, orderby => 'title' });
77 my @subscriptions_loop;
79 foreach my $subscription ( @subscriptions ) {
80 my $subscriptionid = $subscription->{'subscriptionid'};
81 my $expirationdate = GetExpirationDate($subscriptionid);
83 $subscription->{expirationdate} = $expirationdate;
85 next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in ISO format.
87 next if $subscription->{closed};
88 if ( !C4::Context->preference("IndependentBranches")
89 or C4::Context->IsSuperLibrarian()
90 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
91 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
93 $subscription->{cannotedit} = 0;
95 next if $subscription->{cannotedit};
97 my $expirationdate_dt = dt_from_string( $expirationdate, 'iso' );
98 if ( DateTime->compare( $date, $expirationdate_dt ) == 1
99 && ( !$branch || ( $subscription->{'branchcode'} eq $branch ) ) ) {
100 push @subscriptions_loop, $subscription;
104 $template->param (
105 title => $title,
106 issn => $issn,
107 numsubscription => scalar @subscriptions_loop,
108 date => $date,
109 subscriptions_loop => \@subscriptions_loop,
110 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
111 searched => 1,
115 my $can_change_library;;
116 if ( !C4::Context->preference("IndependentBranches")
117 or C4::Context->IsSuperLibrarian()
118 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
119 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
121 $can_change_library = 1;
124 $template->param (
125 (uc(C4::Context->preference("marcflavour"))) => 1,
126 can_change_library => $can_change_library,
127 branch => $branch,
130 output_html_with_http_headers $query, $cookie, $template->output;