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
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 # find Koha's Perl modules
26 # test carefully before changing this
28 eval { require "$FindBin::Bin/../kohalib.pl" };
32 use C4::Dates qw/format_date format_date_in_iso/;
36 use Date::Calc qw/Date_to_Days check_date/;
40 my $dbh = C4::Context->dbh;
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("
58 LEFT JOIN subscription
59 ON (subscription.subscriptionid=serial.subscriptionid)
60 WHERE serial.status = 1
62 AND DATE_ADD(planneddate, INTERVAL CAST(graceperiod AS SIGNED) DAY) < NOW()
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";
90 print "Error with serial(".$issue->{serialid}.") has no existent
91 subscription(".$issue->{subscriptionid}.") attached