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>.
26 This script check what subscription will expire before C<$datenumber $datelimit>
33 To filter subscription on title
36 To filter subscription on issn
39 The date to filter on.
49 use C4::Serials; # GetExpirationDate
59 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user (
61 template_name => "serials/checkexpiration.tt",
65 flagsrequired => { serials => 'check_expiration' },
70 my $title = $query->param('title');
71 my $issn = $query->param('issn');
72 my $branch = $query->param('branch');
73 my $date = $query->param('date');
74 $date = eval { dt_from_string( $query->param('date') ) } if $date;
77 my @subscriptions = SearchSubscriptions({ title => $title, issn => $issn, orderby => 'title' });
78 my @subscriptions_loop;
80 foreach my $subscription ( @subscriptions ) {
81 my $subscriptionid = $subscription->{'subscriptionid'};
82 my $expirationdate = GetExpirationDate($subscriptionid);
84 $subscription->{expirationdate} = $expirationdate;
86 next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in ISO format.
88 next if $subscription->{closed};
89 if ( !C4::Context->preference("IndependentBranches")
90 or C4::Context->IsSuperLibrarian()
91 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
92 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
94 $subscription->{cannotedit} = 0;
96 next if $subscription->{cannotedit};
98 my $expirationdate_dt = dt_from_string( $expirationdate, 'iso' );
99 if ( DateTime->compare( $date, $expirationdate_dt ) == 1
100 && ( !$branch || ( $subscription->{'branchcode'} eq $branch ) ) ) {
101 push @subscriptions_loop, $subscription;
108 numsubscription => scalar @subscriptions_loop,
110 subscriptions_loop => \@subscriptions_loop,
111 "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
117 if ( !C4::Context->preference("IndependentBranches")
118 or C4::Context->IsSuperLibrarian()
119 or ( ref $flags->{serials} and $flags->{serials}->{superserials} )
120 or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
122 $branches_loop = C4::Branch::GetBranchesLoop( $branch );
126 (uc(C4::Context->preference("marcflavour"))) => 1,
127 branches_loop => $branches_loop,
130 output_html_with_http_headers $query, $cookie, $template->output;