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/;
42 serialsUpdate.pl - change status of serials that are late
46 serialsUpdate.pl [ -h | -m ][ -v ] -c ][ --note "you are late" ][ --no-note ]
49 --h --help -? Brief help message
50 --man Full documentation
51 --verbose -v Verbose mode
52 -c Confirm : without this option, the script will report the concerned serials
53 without modifying database
54 --note Note set to concerned serials, by default "Automatically set to late"
55 --no-note Do not set a note one concerned serials
59 my $dbh = C4::Context->dbh;
71 'v|verbose' => \$verbose,
74 'no-note' => \$nonote,
77 pod2usage(1) if $help;
78 pod2usage( -verbose => 2 ) if $man;
80 $verbose and !$confirm and print "### Database will not be modified ###\n";
82 if ($note && $nonote) {
85 if (!$note && !$nonote) {
86 $note = 'Automatically set to late';
88 $verbose and print $note ? "Note : $note\n" : "No note\n";
90 # select all serials with not "irregular" periodicity that are late
91 my $sth = $dbh->prepare("
94 LEFT JOIN subscription
95 ON (subscription.subscriptionid=serial.subscriptionid)
96 WHERE serial.status = 1
98 AND DATE_ADD(planneddate, INTERVAL CAST(graceperiod AS SIGNED) DAY) < NOW()
99 AND subscription.closed = 0
103 while ( my $issue = $sth->fetchrow_hashref ) {
105 my $subscription = &GetSubscription( $issue->{subscriptionid} );
106 my $planneddate = $issue->{planneddate};
108 if( $subscription && $planneddate && $planneddate ne "0000-00-00" ){
109 my $nextpublisheddate = GetNextDate( $planneddate, $subscription );
110 my $today = format_date_in_iso( C4::Dates->new()->output() );
112 if ($nextpublisheddate && $today){
113 my ( $year, $month, $day ) = split( /-/, $nextpublisheddate );
114 my ( $tyear, $tmonth, $tday ) = split( /-/, $today );
115 if ( check_date( $year, $month, $day )
116 && check_date( $tyear, $tmonth, $tday )
117 && Date_to_Days( $year, $month, $day ) <
118 Date_to_Days( $tyear, $tmonth, $tday ) )
121 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
122 $issue->{planneddate}, $issue->{publisheddate},
124 $verbose and print "Serial id=" . $issue->{serialid}." update\n";
127 $verbose and print "Error with serial(".$issue->{serialid}.") has no existent
128 subscription(".$issue->{subscriptionid}.") attached
129 or planneddate is wrong\n";