rel_3_0 moved to HEAD (introducing new files)
[koha-equinox.git] / serials / checkexpiration.pl
1 #!/usr/bin/perl
2
3 #
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA  02111-1307 USA
18
19 # $Id$
20
21 =head1 NAME
22
23 checkexpiration.pl
24
25 =head1 DESCRIPTION
26
27 This script check what subscription will expire before C<$datenumber $datelimit>
28
29 =head1 PARAMETERS
30
31 =over 4
32
33 =item title
34     To filter subscription on title
35
36 =item issn
37     To filter subscription on issn
38
39 =item date
40 The date to filter on.
41
42 =back
43
44 =cut
45
46 use strict;
47 use CGI;
48 use C4::Auth;
49 use C4::Serials; # GetExpirationDate
50 use C4::Output;
51 use C4::Interface::CGI::Output;
52 use C4::Context;
53 use Date::Calc qw/Today Date_to_Days/;
54
55 my $query = new CGI;
56
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
58     {
59         template_name   => "serials/checkexpiration.tmpl",
60         query           => $query,
61         type            => "intranet",
62         authnotrequired => 0,
63         flagsrequired   => { serials => 1 },
64         debug           => 1,
65     }
66 );
67
68 my $title = $query->param('title');
69 my $issn  = $query->param('issn');
70 my $date  = $query->param('date');
71 my $today = join "-",&Today;
72
73 if ($date) {
74
75     my @subscriptions = GetSubscriptions( $title, $issn );
76     my @subscriptions_loop;
77
78     foreach my $subscription ( @subscriptions ) {
79         my $subscriptionid = $subscription->{'subscriptionid'};
80         my $expirationdate = GetExpirationDate($subscriptionid);
81
82         $subscription->{expirationdate} = $expirationdate;
83         next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in good format.
84         if ( Date_to_Days(split "-",$expirationdate) < Date_to_Days(split "-",$date) &&
85              Date_to_Days(split "-",$expirationdate) > Date_to_Days(split "-",$today) ) {
86             push @subscriptions_loop,$subscription;             
87         }
88     }
89     
90     $template->param (
91         title           => $title,
92         issn            => $issn,
93         numsubscription => scalar @subscriptions_loop,
94         date => $date,
95         subscriptions_loop => \@subscriptions_loop,
96         "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
97     );
98 }
99
100 output_html_with_http_headers $query, $cookie, $template->output;