Bug 27920: Add ability to update patron expiration dates when importing patrons
[koha.git] / serials / subscription-history.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011-2013 Biblibre SARL
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 =head1 NAME
21
22 subscription-history.pl
23
24 =head1 DESCRIPTION
25
26 Modify subscription history
27
28 =cut
29
30 use Modern::Perl;
31
32 use CGI qw ( -utf8 );
33 use C4::Auth qw( get_template_and_user );
34 use C4::Output qw( output_html_with_http_headers );
35
36 use C4::Serials qw( ModSubscriptionHistory ModSubscription GetSubscriptionHistoryFromSubscriptionId GetSubscription );
37 use Koha::Biblios;
38 use Koha::DateUtils qw( output_pref );
39
40 my $input = CGI->new;
41 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
42     template_name   => 'serials/subscription-history.tt',
43     query           => $input,
44     type            => 'intranet',
45     flagsrequired   => { 'serials' => 'edit_subscription' },
46 } );
47
48 my $subscriptionid  = $input->param('subscriptionid');
49 my $op              = $input->param('op');
50
51 if(!defined $subscriptionid || $subscriptionid eq '') {
52     print $input->redirect('/cgi-bin/koha/serials/serials-home.pl');
53     exit;
54 }
55
56 if($op && $op eq 'mod') {
57     my $histstartdate   = $input->param('histstartdate');
58     my $histenddate     = $input->param('histenddate');
59     my $receivedlist    = $input->param('receivedlist');
60     my $missinglist     = $input->param('missinglist');
61     my $opacnote        = $input->param('opacnote');
62     my $librariannote   = $input->param('librariannote');
63
64     $histstartdate = output_pref( { str => $histstartdate, dateonly => 1, dateformat => 'iso' } );
65     $histenddate   = output_pref( { str => $histenddate,   dateonly => 1, dateformat => 'iso' } );
66
67     ModSubscriptionHistory( $subscriptionid, $histstartdate, $histenddate, $receivedlist, $missinglist, $opacnote, $librariannote );
68
69     print $input->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
70     exit;
71 } else {
72     my $history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
73     my $biblio  = Koha::Biblios->find( $history->{biblionumber} );
74
75     $template->param(
76         subscriptionid  => $subscriptionid,
77         title           => $biblio->title,
78         histstartdate   => $history->{'histstartdate'},
79         histenddate     => $history->{'histenddate'},
80         receivedlist    => $history->{'recievedlist'},
81         missinglist     => $history->{'missinglist'},
82         opacnote        => $history->{'opacnote'},
83         librariannote   => $history->{'librariannote'},
84     );
85
86     output_html_with_http_headers $input, $cookie, $template->output;
87 }