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 );
71 'send-notices' => \$send_notices,
74 pod2usage(0) if $help;
78 my $dbh = C4::Context->dbh();
79 my $sth = $dbh->prepare( <<"END_SQL" );
81 issues.borrowernumber,
82 reserves.biblionumber,
85 join items on reserves.biblionumber=items.biblionumber
86 join issues on issues.itemnumber=items.itemnumber
87 join borrowers on borrowers.borrowernumber=issues.borrowernumber
91 categorycode = 'N1' or
92 categorycode = 'POC' or
93 categorycode = 'KNJIZ' or
94 categorycode = 'Z1' or
97 datediff(reservedate,issuedate) > 30
99 categorycode like 'S%' and datediff(reservedate,issuedate) > 14
101 ) and reservedate > now() - interval 1 day
102 order by reserves.biblionumber ;
107 while ( my $row = $sth->fetchrow_hashref ) {
108 warn "# row = ",dump($row),$/;
110 if ( $send_notices ) {
111 my $patron = Koha::Patrons->find($row->{borrowernumber});
113 my $letter = C4::Letters::GetPreparedLetter(
114 module => 'circulation',
115 letter_code => 'FFZG_RECALL',
117 borrowers => $row->{borrowernumber},
118 issues => $row->{itemnumber},
119 items => $row->{itemnumber},
120 biblio => $row->{biblionumber},
124 my $library = Koha::Libraries->find( $patron->branchcode );
125 my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
127 C4::Letters::EnqueueLetter(
129 borrowernumber => $row->{borrowernumber},
130 message_transport_type => 'email',
131 from_address => $admin_email_address,