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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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()
63 AND subscription.closed = 0
67 while ( my $issue = $sth->fetchrow_hashref ) {
69 my $subscription = &GetSubscription( $issue->{subscriptionid} );
70 my $planneddate = $issue->{planneddate};
72 if( $subscription && $planneddate && $planneddate ne "0000-00-00" ){
73 my $nextpublisheddate = GetNextDate( $planneddate, $subscription );
74 my $today = format_date_in_iso( C4::Dates->new()->output() );
76 if ($nextpublisheddate && $today){
77 my ( $year, $month, $day ) = split( /-/, $nextpublisheddate );
78 my ( $tyear, $tmonth, $tday ) = split( /-/, $today );
79 if ( check_date( $year, $month, $day )
80 && check_date( $tyear, $tmonth, $tday )
81 && Date_to_Days( $year, $month, $day ) <
82 Date_to_Days( $tyear, $tmonth, $tday ) )
85 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
86 $issue->{planneddate}, $issue->{publisheddate},
87 3, "Automatically set to late" );
88 print $issue->{serialid}." update\n";
91 print "Error with serial(".$issue->{serialid}.") has no existent
92 subscription(".$issue->{subscriptionid}.") attached