-#!/usr/bin/perl -w
+#!/usr/bin/perl
# Copyright 2008 Liblime
#
# 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., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# 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.
use strict;
use warnings;
-use utf8;
BEGIN {
sent to standard out or to a filename if provided. Otherwise, only
overdues that could not be emailed are sent in CSV format to the admin.
+=item B<-html>
+
+Produces html data. if patron does not have a mail address or
+-n (no mail) flag is set, an html file is generated in the specified
+directory. This can be downloaded or futher processed by library staff.
+
=item B<-itemscontent>
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 issuedate,title,barcode,author
+defaults to due date,title,barcode,author
-Other possible values come from fields in the biblios, items, and
+Other possible values come from fields in the biblios, items and
issues tables.
=item B<-borcat>
my $htmlfilename;
my $triggered = 0;
my $listall = 0;
-my $itemscontent = join( ',', qw( issuedate title barcode author biblionumber ) );
+my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) );
my @myborcat;
my @myborcatout;
if ( $htmlfilename eq '' ) {
$html_fh = *STDOUT;
} else {
- open $html_fh, ">", $htmlfilename or die "unable to open $htmlfilename: $!";
+ my $today = C4::Dates->new();
+ open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->output('iso').".html");
}
print $html_fh "<html>\n";
$verbose and warn "debarring $borrowernumber $firstname $lastname\n";
}
my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays ));
+ $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays";
$sth2->execute(@params);
my $itemcount = 0;
my $titles = "";
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields;
$titles .= join("\t", @item_info) . "\n";
$itemcount++;
- push (@items, $item_info->{'biblionumber'});
+ push @items, { itemnumber => $item_info->{'itemnumber'}, biblionumber => $item_info->{'biblionumber'} };
}
$sth2->finish;
$letter = parse_letter(
{ letter => $letter,
borrowernumber => $borrowernumber,
branchcode => $branchcode,
- biblionumber => \@items,
+ items => \@items,
substitute => { # this appears to be a hack to overcome incomplete features in this code.
bib => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'?
'items.content' => $titles
}
if (@output_chunks) {
- if ($nomail) {
- if ( defined $csvfilename ) {
- print $csv_fh @output_chunks;
- } elsif ( defined $htmlfilename ) {
- print $html_fh @output_chunks;
- } else {
- local $, = "\f"; # pagebreak
- print @output_chunks;
- }
- }
+ if ( defined $csvfilename ) {
+ print $csv_fh @output_chunks;
+ }
elsif ( defined $htmlfilename ) {
print $html_fh @output_chunks;
}
- else {
- my $attachment = {
- filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt',
- type => 'text/plain',
- content => join( "\n", @output_chunks )
- };
-
- my $letter = {
- title => 'Overdue Notices',
- content => 'These messages were not sent directly to the patrons.',
- };
- C4::Letters::EnqueueLetter(
- { letter => $letter,
- borrowernumber => undef,
- message_transport_type => 'email',
- attachments => [$attachment],
- to_address => $admin_email_address,
- }
- );
+ elsif ($nomail){
+ local $, = "\f"; # pagebreak
+ print @output_chunks;
}
+ my $attachment = {
+ filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt',
+ type => 'text/plain',
+ content => join( "\n", @output_chunks )
+ };
+
+ my $letter = {
+ title => 'Overdue Notices',
+ content => 'These messages were not sent directly to the patrons.',
+ };
+ C4::Letters::EnqueueLetter(
+ { letter => $letter,
+ borrowernumber => undef,
+ message_transport_type => 'email',
+ attachments => [$attachment],
+ to_address => $admin_email_address,
+ }
+ );
}
}
$params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'branches', $params->{'branchcode'} );
}
- if ( $params->{'biblionumber'} ) {
+ if ( $params->{'items'} ) {
my $item_format = '';
PROCESS_ITEMS:
- while (scalar(@{$params->{'biblionumber'}}) > 0) {
- my $item = shift @{$params->{'biblionumber'}};
- my $fine = GetFine($item, $params->{'borrowernumber'});
+ while (scalar(@{$params->{'items'}}) > 0) {
+ my $item = shift @{$params->{'items'}};
+ my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
if (!$item_format) {
$params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
$item_format = $1;
}
if ($params->{'letter'}->{'content'} =~ m/<fine>(.*)<\/fine>/) { # process any fine tags...
- no strict; # currency_format behaves badly if we quote the bareword for some reason...
my $formatted_fine = currency_format("$1", "$fine", FMT_SYMBOL);
- use strict;
- $formatted_fine = Encode::encode("utf8", $formatted_fine);
$params->{'letter'}->{'content'} =~ s/<fine>.*<\/fine>/$formatted_fine/;
}
- $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'biblio', $item );
- $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'biblioitems', $item );
- $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'items', $item );
- $params->{'letter'}->{'content'} =~ s/(<item>.*<\/item>)/$1\n$item_format/ if scalar(@{$params->{'biblionumber'}} > 0);
+ $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'biblio', $item->{'biblionumber'} );
+ $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'biblioitems', $item->{'biblionumber'} );
+ $params->{'letter'} = C4::Letters::parseletter( $params->{'letter'}, 'items', $item->{'itemnumber'} );
+ $params->{'letter'}->{'content'} =~ s/(<item>.*<\/item>)/$1\n$item_format/ if scalar(@{$params->{'items'}} > 0);
}
}