3 # Copyright 2008 SARL Biblibre
5 # This file is part of Koha.
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.
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.
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>.
23 use Koha::Script -cron;
25 use C4::Serials qw( GetSubscription GetNextDate ModSerialStatus );
26 use C4::Serials::Frequency;
27 use C4::Log qw( cronlogaction );
28 use Koha::DateUtils qw( dt_from_string );
30 use Date::Calc qw( check_date Date_to_Days );
31 use Getopt::Long qw( GetOptions );
32 use Pod::Usage qw( pod2usage );
36 serialsUpdate.pl - change status of serial issues that are late
40 serialsUpdate.pl [ -h | -m ][ -v ] -c ][ --note "you are late" ][ --no-note ]
43 --h --help -? Brief help message
44 --man Full documentation
45 --verbose -v Verbose mode
46 -c Confirm: without this option, the script will report on affected serial
47 issues without modifying database
48 --note Note set on affected serial issues, by default "Automatically set to late"
49 --no-note Do not set a note on affected serial issues
53 my $dbh = C4::Context->dbh;
62 my $command_line_options = join(" ",@ARGV);
67 'v|verbose' => \$verbose,
70 'no-note' => \$nonote,
73 pod2usage(1) if $help;
74 pod2usage( -verbose => 2 ) if $man;
76 cronlogaction({ info => $command_line_options });
78 $verbose and !$confirm and print "### Database will not be modified ###\n";
80 if ( $note && $nonote ) {
83 if ( !$note && !$nonote ) {
84 $note = 'Automatically set to late';
86 $verbose and print $note ? "Note : $note\n" : "No note\n";
88 # select all serials with not "irregular" periodicity that are late
89 my $sth = $dbh->prepare(
96 subscription.subscriptionid
99 ON (subscription.subscriptionid=serial.subscriptionid)
100 LEFT JOIN subscription_frequencies
101 ON (subscription.periodicity = subscription_frequencies.id)
102 WHERE serial.status = 1
103 AND subscription_frequencies.unit IS NOT NULL
104 AND DATE_ADD(planneddate, INTERVAL CAST(graceperiod AS SIGNED) DAY) < NOW()
105 AND subscription.closed = 0
106 AND publisheddate IS NOT NULL
111 while ( my $issue = $sth->fetchrow_hashref ) {
113 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
114 $issue->{planneddate}, $issue->{publisheddate}, $issue->{publisheddatetext},
116 $verbose and print "Serial issue with id=" . $issue->{serialid} . " marked late\n";
118 print "Serial issue with id=" . $issue->{serialid} . " would have been marked late\n";
122 cronlogaction({ action => 'End', info => "COMPLETED" });