|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl -w |
|
|
2 |
|
| 3 |
# Copyright 2008 SARL Biblibre |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 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. |
| 11 |
# |
| 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. |
| 15 |
# |
| 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 |
| 19 |
|
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
|
| 23 |
BEGIN { |
| 24 |
|
| 25 |
# find Koha's Perl modules |
| 26 |
# test carefully before changing this |
| 27 |
use FindBin; |
| 28 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
| 29 |
} |
| 30 |
|
| 31 |
use C4::Context; |
| 32 |
use C4::Dates qw/format_date format_date_in_iso/; |
| 33 |
use C4::Debug; |
| 34 |
use C4::Serials; |
| 35 |
|
| 36 |
use Date::Calc qw/Date_to_Days check_date/; |
| 37 |
use Getopt::Long; |
| 38 |
use Pod::Usage; |
| 39 |
|
| 40 |
my $dbh = C4::Context->dbh; |
| 41 |
|
| 42 |
my $man = 0; |
| 43 |
my $help = 0; |
| 44 |
my $confirm = 0; |
| 45 |
|
| 46 |
GetOptions( |
| 47 |
'help|?' => \$help, |
| 48 |
'c' => \$confirm, |
| 49 |
) or pod2usage(2); |
| 50 |
|
| 51 |
pod2usage(1) if $help; |
| 52 |
pod2usage( -verbose => 2 ) if $man; |
| 53 |
|
| 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(); |
| 65 |
|
| 66 |
while ( my $issue = $sth->fetchrow_hashref ) { |
| 67 |
|
| 68 |
my $subscription = &GetSubscription( $issue->{subscriptionid} ); |
| 69 |
my $planneddate = $issue->{planneddate}; |
| 70 |
|
| 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() ); |
| 74 |
|
| 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 ) ) |
| 82 |
{ |
| 83 |
|
| 84 |
ModSerialStatus( $issue->{serialid}, $issue->{serialseq}, |
| 85 |
$issue->{planneddate}, $issue->{publisheddate}, |
| 86 |
3, "Automatically set to late" ); |
| 87 |
print $issue->{serialid}." update\n"; |
| 88 |
} |
| 89 |
}else{ |
| 90 |
print "Error with serial(".$issue->{serialid}.") has no existent |
| 91 |
subscription(".$issue->{subscriptionid}.") attached |
| 92 |
or planneddate is "; |
| 93 |
} |
| 94 |
} |
| 95 |
} |