#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
=head1 NAME
use C4::Members::Messaging;
use C4::Overdues;
use Koha::DateUtils;
+use C4::Log;
+use Koha::Items;
+use Koha::Libraries;
+use Koha::Patrons;
=head1 NAME
comma separated list of fields that get substituted into templates in
places of the E<lt>E<lt>items.contentE<gt>E<gt> placeholder. This
-defaults to due date,title,author,barcode
+defaults to date_due,title,author,barcode
Other possible values come from fields in the biblios, items and
issues tables.
=item E<lt>E<lt>items.contentE<gt>E<gt>
one line for each item, each line containing a tab separated list of
-title, author, barcode, issuedate
+date due, title, author, barcode
=item E<lt>E<lt>borrowers.*E<gt>E<gt>
The F<misc/cronjobs/overdue_notices.pl> program allows you to send
messages to patrons when their messages are overdue.
+
=cut
+binmode( STDOUT, ':encoding(UTF-8)' );
+
# These are defaults for command line options.
my $confirm; # -c: Confirm that the user has read and configured this script.
my $nomail; # -n: No mail. Will not send any emails.
'itemscontent=s' => \$itemscontent,
)or pod2usage(2);
pod2usage(1) if $help;
-pod2usage( -verbose => 2 ) if $man;;
+pod2usage( -verbose => 2 ) if $man;
# Since advance notice options are not visible in the web-interface
# unless EnhancedMessagingPreferences is on, let the user know that
unless ($confirm) {
pod2usage(1);
}
+
+cronlogaction();
+
# The fields that will be substituted into <<items.content>>
my @item_content_fields = split(/,/,$itemscontent);
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
@letters = ();
warn 'examining ' . $upcoming->{'itemnumber'} . ' upcoming due items' if $verbose;
- # warn( Data::Dumper->Dump( [ $upcoming ], [ 'overdue' ] ) );
my $from_address = $upcoming->{branchemail} || $admin_adress;
# This item is due today. Send an 'item due' message.
$borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $upcoming->{'borrowernumber'},
message_name => 'item_due' } );
- # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) );
next unless $borrower_preferences;
if ( $borrower_preferences->{'wants_digest'} ) {
# cache this one to process after we've run through all of the items.
- my $digest = $due_digest->{$upcoming->{'borrowernumber'}} ||= {};
- $digest->{email} ||= $from_address;
- $digest->{count}++;
+ $due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
+ $due_digest->{ $upcoming->{borrowernumber} }->{count}++;
} else {
- my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} );
+ my $item = Koha::Items->find( $upcoming->{itemnumber} );
my $letter_type = 'DUE';
$sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0');
my $titles = "";
while ( my $item_info = $sth->fetchrow_hashref()) {
- my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
- $titles .= join("\t",@item_info) . "\n";
+ $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
}
## Get branch info for borrowers home library.
my $letter = parse_letter( { letter_code => $letter_type,
borrowernumber => $upcoming->{'borrowernumber'},
branchcode => $upcoming->{'branchcode'},
- biblionumber => $biblio->{'biblionumber'},
+ biblionumber => $item->biblionumber,
itemnumber => $upcoming->{'itemnumber'},
substitute => { 'items.content' => $titles },
message_transport_type => $transport,
} )
- or warn "no letter of type '$letter_type' found. Please see sample_notices.sql";
- push @letters, $letter;
+ or warn "no letter of type '$letter_type' found for borrowernumber ".$upcoming->{'borrowernumber'}.". Please see sample_notices.sql";
+ push @letters, $letter if $letter;
}
}
} else {
$borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $upcoming->{'borrowernumber'},
message_name => 'advance_notice' } );
- # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) );
next UPCOMINGITEM unless $borrower_preferences && exists $borrower_preferences->{'days_in_advance'};
next UPCOMINGITEM unless $borrower_preferences->{'days_in_advance'} == $upcoming->{'days_until_due'};
if ( $borrower_preferences->{'wants_digest'} ) {
# cache this one to process after we've run through all of the items.
- my $digest = $upcoming_digest->{$upcoming->{'borrowernumber'}} ||= {};
- $digest->{email} ||= $from_address;
- $digest->{count}++;
+ $upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address;
+ $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++;
} else {
- my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} );
+ my $item = Koha::Items->find( $upcoming->{itemnumber} );
my $letter_type = 'PREDUE';
$sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'});
my $titles = "";
while ( my $item_info = $sth->fetchrow_hashref()) {
- my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
- $titles .= join("\t",@item_info) . "\n";
+ $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
}
## Get branch info for borrowers home library.
my $letter = parse_letter( { letter_code => $letter_type,
borrowernumber => $upcoming->{'borrowernumber'},
branchcode => $upcoming->{'branchcode'},
- biblionumber => $biblio->{'biblionumber'},
+ biblionumber => $item->biblionumber,
itemnumber => $upcoming->{'itemnumber'},
substitute => { 'items.content' => $titles },
message_transport_type => $transport,
} )
- or warn "no letter of type '$letter_type' found. Please see sample_notices.sql";
- push @letters, $letter;
+ or warn "no letter of type '$letter_type' found for borrowernumber ".$upcoming->{'borrowernumber'}.". Please see sample_notices.sql";
+ push @letters, $letter if $letter;
}
}
}
}
-# warn( Data::Dumper->Dump( [ $upcoming_digest ], [ 'upcoming_digest' ] ) );
# Now, run through all the people that want digests and send them
AND issues.borrowernumber = ?
AND (TO_DAYS(date_due)-TO_DAYS(NOW()) = ?)
END_SQL
-@letters = ();
PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) {
+ @letters = ();
my $count = $digest->{count};
my $from_address = $digest->{email};
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber,
message_name => 'advance_notice' } );
- # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) );
next PATRON unless $borrower_preferences; # how could this happen?
$sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'});
my $titles = "";
while ( my $item_info = $sth->fetchrow_hashref()) {
- my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
- $titles .= join("\t",@item_info) . "\n";
+ $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
}
## Get branch info for borrowers home library.
message_transport_type => $transport,
}
)
- or die "no letter of type '$letter_type' found. Please see sample_notices.sql";
- push @letters, $letter;
+ or warn "no letter of type '$letter_type' found for borrowernumber $borrowernumber. Please see sample_notices.sql";
+ push @letters, $letter if $letter;
}
if ( @letters ) {
}
# Now, run through all the people that want digests and send them
-@letters = ();
PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) {
+ @letters = ();
my $count = $digest->{count};
my $from_address = $digest->{email};
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber,
message_name => 'item_due' } );
- # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) );
next PATRON unless $borrower_preferences; # how could this happen?
my $letter_type = 'DUEDGST';
$sth->execute($borrowernumber,'0');
my $titles = "";
while ( my $item_info = $sth->fetchrow_hashref()) {
- my @item_info = map { $_ =~ /^date|date$/ ? format_date($item_info->{$_}) : $item_info->{$_} || '' } @item_content_fields;
- $titles .= join("\t",@item_info) . "\n";
+ $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } );
}
## Get branch info for borrowers home library.
message_transport_type => $transport,
}
)
- or die "no letter of type '$letter_type' found. Please see sample_notices.sql";
- push @letters, $letter;
+ or warn "no letter of type '$letter_type' found for borrowernumber $borrowernumber. Please see sample_notices.sql";
+ push @letters, $letter if $letter;
}
if ( @letters ) {
foreach my $required ( qw( letter_code borrowernumber ) ) {
return unless exists $params->{$required};
}
+ my $patron = Koha::Patrons->find( $params->{borrowernumber} );
my %table_params = ( 'borrowers' => $params->{'borrowernumber'} );
module => 'circulation',
letter_code => $params->{'letter_code'},
branchcode => $table_params{'branches'},
+ lang => $patron->lang,
substitute => $params->{'substitute'},
tables => \%table_params,
message_transport_type => $params->{message_transport_type},
);
}
-sub format_date {
- my $date_string = shift;
- my $dt=dt_from_string($date_string);
- return output_pref($dt);
-}
-
=head2 get_branch_info
=cut
my ( $borrowernumber ) = @_;
## Get branch info for borrowers home library.
- my $borrower_details = C4::Members::GetMember( borrowernumber => $borrowernumber );
- my $borrower_branchcode = $borrower_details->{'branchcode'};
- my $branch = C4::Branch::GetBranchDetail( $borrower_branchcode );
+ my $patron = Koha::Patrons->find( $borrowernumber );
+ my $branch = $patron->library->unblessed;
my %branch_info;
foreach my $key( keys %$branch ) {
$branch_info{"branches.$key"} = $branch->{$key};