X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=misc%2Fcronjobs%2Foverdue_notices.pl;h=6e723b20e69cb48b5e3835eaab18a0375c578915;hb=3b9722c7dd08009a7baabdb84ad108462a1ba3c4;hp=671368eab0acfd9e9a51a7b19d5adb043c9c8f5f;hpb=36d64bd18c5695d773c9d956796c605fd7ae25c9;p=koha.git diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 671368eab0..6e723b20e6 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # Copyright 2008 Liblime +# Copyright 2010 BibLibre # # This file is part of Koha. # @@ -304,7 +305,7 @@ if (@branchcodes) { @branches = grep { $seen{$_} } @overduebranches; - if (@overduebranches) { + if (@branches) { my $branch_word = scalar @branches > 1 ? 'branches' : 'branch'; $verbose and warn "$branch_word @branches have overdue rules\n"; @@ -329,6 +330,7 @@ our $csv; # the Text::CSV_XS object our $csv_fh; # the filehandle to the CSV file. if ( defined $csvfilename ) { my $sep_char = C4::Context->preference('delimiter') || ','; + $sep_char = "\t" if ($sep_char eq 'tabulation'); $csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); if ( $csvfilename eq '' ) { $csv_fh = *STDOUT; @@ -374,10 +376,11 @@ foreach my $branchcode (@branches) { $verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $admin_email_address; my $sth2 = $dbh->prepare( <<'END_SQL' ); -SELECT biblio.*, items.*, issues.*, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue - FROM issues,items,biblio +SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue + FROM issues,items,biblio, biblioitems WHERE items.itemnumber=issues.itemnumber AND biblio.biblionumber = items.biblionumber + AND biblio.biblionumber = biblioitems.biblionumber AND issues.borrowernumber = ? AND TO_DAYS(NOW())-TO_DAYS(date_due) BETWEEN ? and ? END_SQL @@ -471,7 +474,7 @@ END_SQL if ( $overdue_rules->{"debarred$i"} ) { #action taken is debarring - C4::Members::DebarMember($borrowernumber); + C4::Members::DebarMember($borrowernumber, '9999-12-31'); $verbose and warn "debarring $borrowernumber $firstname $lastname\n"; } my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); @@ -502,7 +505,8 @@ END_SQL 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'? - 'items.content' => $titles + 'items.content' => $titles, + 'count' => $itemcount, } } ); @@ -582,10 +586,14 @@ END_SQL local $, = "\f"; # pagebreak print @output_chunks; } + # Generate the content of the csv with headers + my $content = join(";", qw(title name surname address1 address2 zipcode city email itemcount itemsinfo due_date issue_date)) . "\n"; + $content .= join( "\n", @output_chunks ); + my $attachment = { filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', type => 'text/plain', - content => join( "\n", @output_chunks ) + content => $content, }; my $letter = { @@ -642,6 +650,9 @@ sub parse_letter { # FIXME: this code should probably be moved to C4::Letters:pa return unless exists $params->{$required}; } + my $todaysdate = C4::Dates->new()->output("syspref"); + $params->{'letter'}->{title} =~ s/<>/$todaysdate/g; + $params->{'letter'}->{content} =~ s/<>/$todaysdate/g; if ( $params->{'substitute'} ) { while ( my ( $key, $replacedby ) = each %{ $params->{'substitute'} } ) {