Bug 4920 - neworderempty.tmpl shouldn't call calcNeworderTotal() onload
[koha.git] / misc / cronjobs / serialsUpdate.pl
blob1de5a48436298977e6fca9f203995a5927a0f2a1
1 #!/usr/bin/perl
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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 BEGIN {
25 # find Koha's Perl modules
26 # test carefully before changing this
27 use FindBin;
28 eval { require "$FindBin::Bin/../kohalib.pl" };
31 use C4::Context;
32 use C4::Dates qw/format_date format_date_in_iso/;
33 use C4::Debug;
34 use C4::Serials;
36 use Date::Calc qw/Date_to_Days check_date/;
37 use Getopt::Long;
38 use Pod::Usage;
40 my $dbh = C4::Context->dbh;
42 my $man = 0;
43 my $help = 0;
44 my $confirm = 0;
46 GetOptions(
47 'help|?' => \$help,
48 'c' => \$confirm,
49 ) or pod2usage(2);
51 pod2usage(1) if $help;
52 pod2usage( -verbose => 2 ) if $man;
54 # select all serials with not "irregular" periodicity that are late
55 my $sth = $dbh->prepare("
56 SELECT *
57 FROM serial
58 LEFT JOIN subscription
59 ON (subscription.subscriptionid=serial.subscriptionid)
60 WHERE serial.status = 1
61 AND periodicity <> 32
62 AND DATE_ADD(planneddate, INTERVAL CAST(graceperiod AS SIGNED) DAY) < NOW()
63 ");
64 $sth->execute();
66 while ( my $issue = $sth->fetchrow_hashref ) {
68 my $subscription = &GetSubscription( $issue->{subscriptionid} );
69 my $planneddate = $issue->{planneddate};
71 if( $subscription && $planneddate && $planneddate ne "0000-00-00" ){
72 my $nextpublisheddate = GetNextDate( $planneddate, $subscription );
73 my $today = format_date_in_iso( C4::Dates->new()->output() );
75 if ($nextpublisheddate && $today){
76 my ( $year, $month, $day ) = split( /-/, $nextpublisheddate );
77 my ( $tyear, $tmonth, $tday ) = split( /-/, $today );
78 if ( check_date( $year, $month, $day )
79 && check_date( $tyear, $tmonth, $tday )
80 && Date_to_Days( $year, $month, $day ) <
81 Date_to_Days( $tyear, $tmonth, $tday ) )
84 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
85 $issue->{planneddate}, $issue->{publisheddate},
86 3, "Automatically set to late" );
87 print $issue->{serialid}." update\n";
89 }else{
90 print "Error with serial(".$issue->{serialid}.") has no existent
91 subscription(".$issue->{subscriptionid}.") attached
92 or planneddate is ";