3 # This file is part of Koha.
5 # Copyright (C) 2018 Dobrica Pavlinusic <dpavlin@rot13.org>
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>.
22 recall_notices.pl - cron script to generate and send recall notices
26 ./recall_notices.pl [--send-notices]
29 0 3 * * * recall_notices.pl
33 This script searches for reserves issued in last day.
35 It is B<NOT> related to Koha's recall feature which is under development
36 L<https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19532>
42 =item B<--send-notices>
44 Send FFZG_RECALL notices to patrons.
46 Note that this option does not support digest yet.
56 use lib '/srv/koha_ffzg';
66 use Data::Dump qw(dump);
68 my ( $help, $send_notices );
69 my $interval = 'now() - interval 1 day';
73 'send-notices' => \$send_notices,
74 'interval=s' => \$interval,
78 pod2usage(0) if $help;
83 # XXX quote iso date correctly for insertion into SQL
84 $interval = qq{'$interval'} if $interval =~ m/^\d\d\d\d-\d+-\d+$/;
86 my $sql = <<"END_SQL";
88 issues.borrowernumber,
89 reserves.biblionumber,
94 join items on reserves.biblionumber=items.biblionumber
95 join issues on issues.itemnumber=items.itemnumber
96 join borrowers on borrowers.borrowernumber=issues.borrowernumber
100 categorycode = 'N1' or
101 categorycode = 'POC' or
102 categorycode = 'KNJIZ' or
103 categorycode = 'Z1' or
106 datediff(reservedate,issuedate) > 30
108 categorycode like 'S%' and datediff(reservedate,issuedate) > 14
110 ) and reservedate > $interval
116 and borrowers.borrowernumber not in (
117 select message_queue.borrowernumber
119 where letter_code = 'FFZG_RECALL' and time_queued >= $interval
125 order by reservedate;
128 warn "## << SQL\n$sql\n## >> SQL\n";
130 my $dbh = C4::Context->dbh();
131 my $sth = $dbh->prepare( $sql );
133 print "$0 dedup:$dedup interval [$interval] got ",$sth->rows,$/;
135 while ( my $row = $sth->fetchrow_hashref ) {
136 print "# recall_notice = ",dump($row),$/;
138 if ( $send_notices ) {
139 my $patron = Koha::Patrons->find($row->{borrowernumber});
141 my $letter = C4::Letters::GetPreparedLetter(
142 module => 'circulation',
143 letter_code => 'FFZG_RECALL',
145 borrowers => $row->{borrowernumber},
146 issues => $row->{itemnumber},
147 items => $row->{itemnumber},
148 biblio => $row->{biblionumber},
152 my $library = Koha::Libraries->find( $patron->branchcode );
153 my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
155 C4::Letters::EnqueueLetter(
157 borrowernumber => $row->{borrowernumber},
158 message_transport_type => 'email',
159 from_address => $admin_email_address,