Bug 14045: DBRev 3.21.00.035
[koha.git] / misc / cronjobs / automatic_renewals.pl
blob73aad5fb6cec56194d37653d85c162f8d55a225b
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright (C) 2014 Hochschule für Gesundheit (hsg), Germany
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 =head1 NAME
22 automatic_renewals.pl - cron script to renew loans
24 =head1 SYNOPSIS
26 ./automatic_renewals.pl
28 or, in crontab:
29 0 3 * * * automatic_renewals.pl
31 =head1 DESCRIPTION
33 This script searches for issues scheduled for automatic renewal
34 (issues.auto_renew). If there are still renews left (Renewals allowed)
35 and the renewal isn't premature (No Renewal before) the issue is renewed.
37 =head1 OPTIONS
39 No options.
41 =cut
43 use Modern::Perl;
45 use C4::Circulation;
46 use C4::Context;
47 use C4::Log;
49 cronlogaction();
51 my $dbh = C4::Context->dbh;
52 my ( $borrowernumber, $itemnumber, $branch, $ok, $error );
54 my $query =
55 "SELECT borrowernumber, itemnumber, branchcode FROM issues WHERE auto_renew = 1";
56 my $sth = $dbh->prepare($query);
57 $sth->execute();
59 while ( ( $borrowernumber, $itemnumber, $branch ) = $sth->fetchrow_array ) {
61 # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
62 ( $ok, $error ) = CanBookBeRenewed( $borrowernumber, $itemnumber );
63 AddRenewal( $borrowernumber, $itemnumber, $branch )
64 if ( $error eq "auto_renew" );