Bug 15705: Notify the user on auto renewing
When an issue is auto renewed, a notice will be sent to the patron. The notice will tell if the renewed has been successfully done. Note that this patch is not ready to be pushed yet, as it has some defects: - 1 notice per issue - no way to disable the notice generation - no way to specify patron categories to enable/disable the notifications Test plan: Use the automatic_renewals.pl script to auto renew issues. If the auto renew has failed or succeeded, a notice will be generated in the message_queue table. If the error is "too_soon" or is the same as the previous error, the notice won't be generated (we do not want to spam the patron). Signed-off-by: Janet McGowan <janet.mcgowan@ptfs-europe.com> Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
115d4f7d2f
commit
14fb70aa01
1 changed files with 54 additions and 12 deletions
|
@ -45,21 +45,63 @@ use Modern::Perl;
|
||||||
use C4::Circulation;
|
use C4::Circulation;
|
||||||
use C4::Context;
|
use C4::Context;
|
||||||
use C4::Log;
|
use C4::Log;
|
||||||
|
use C4::Letters;
|
||||||
|
use Koha::Checkouts;
|
||||||
|
use Koha::Libraries;
|
||||||
|
use Koha::Patrons;
|
||||||
|
|
||||||
cronlogaction();
|
cronlogaction();
|
||||||
|
|
||||||
my $dbh = C4::Context->dbh;
|
my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 });
|
||||||
my ( $borrowernumber, $itemnumber, $branch, $ok, $error );
|
|
||||||
|
|
||||||
my $query =
|
my %report;
|
||||||
"SELECT borrowernumber, itemnumber, branchcode FROM issues WHERE auto_renew = 1";
|
while ( my $auto_renew = $auto_renews->next ) {
|
||||||
my $sth = $dbh->prepare($query);
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
while ( ( $borrowernumber, $itemnumber, $branch ) = $sth->fetchrow_array ) {
|
|
||||||
|
|
||||||
# CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
|
# CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
|
||||||
( $ok, $error ) = CanBookBeRenewed( $borrowernumber, $itemnumber );
|
my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
|
||||||
AddRenewal( $borrowernumber, $itemnumber, $branch )
|
if ( $error eq 'auto_renew' ) {
|
||||||
if ( $error eq "auto_renew" );
|
my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
|
||||||
|
push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew;
|
||||||
|
} elsif ( $error eq 'too_many'
|
||||||
|
or $error eq 'on_reserve'
|
||||||
|
or $error eq 'restriction'
|
||||||
|
or $error eq 'overdue'
|
||||||
|
or $error eq 'auto_too_late'
|
||||||
|
or $error eq 'auto_too_much_oweing'
|
||||||
|
or $error eq 'auto_too_soon' ) {
|
||||||
|
if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) {
|
||||||
|
$auto_renew->auto_renew_error($error)->store;
|
||||||
|
push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
|
||||||
|
if $error ne 'auto_too_soon'; # Do not notify if it's too soon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $borrowernumber ( keys %report ) {
|
||||||
|
my $patron = Koha::Patrons->find($borrowernumber);
|
||||||
|
my @issues;
|
||||||
|
for my $issue ( @{ $report{$borrowernumber} } ) {
|
||||||
|
my $item = Koha::Items->find( $issue->itemnumber );
|
||||||
|
my $letter = C4::Letters::GetPreparedLetter(
|
||||||
|
module => 'circulation',
|
||||||
|
letter_code => 'AUTO_RENEWALS',
|
||||||
|
tables => {
|
||||||
|
borrowers => $patron->borrowernumber,
|
||||||
|
issues => $issue->itemnumber,
|
||||||
|
items => $issue->itemnumber,
|
||||||
|
biblio => $item->biblionumber,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
my $library = Koha::Libraries->find( $patron->branchcode );
|
||||||
|
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
|
||||||
|
|
||||||
|
C4::Letters::EnqueueLetter(
|
||||||
|
{ letter => $letter,
|
||||||
|
borrowernumber => $borrowernumber,
|
||||||
|
message_transport_type => 'email',
|
||||||
|
from_address => $admin_email_address,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue